Completed
Pull Request — release-2.1 (#4090)
by Rick
08:07
created
Sources/Notify.php 1 patch
Braces   +23 added lines, -20 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Turn off/on notification for a particular board.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	is_not_guest();
35 36
 
36 37
 	// You have to specify a board to turn notifications on!
37
-	if (empty($board))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($board)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// No subaction: find out what to do.
41 43
 	if (isset($_GET['mode']))
@@ -48,16 +50,16 @@  discard block
 block discarded – undo
48 50
 		require_once($sourcedir . '/Subs-Notify.php');
49 51
 		setNotifyPrefs($user_info['id'], array('board_notify_' . $board => $alertPref));
50 52
 
51
-		if ($mode > 1)
52
-			// Turn notification on.  (note this just blows smoke if it's already on.)
53
+		if ($mode > 1) {
54
+					// Turn notification on.  (note this just blows smoke if it's already on.)
53 55
 			$smcFunc['db_insert']('ignore',
54 56
 				'{db_prefix}log_notify',
55 57
 				array('id_member' => 'int', 'id_board' => 'int'),
56 58
 				array($user_info['id'], $board),
57 59
 				array('id_member', 'id_board')
58 60
 			);
59
-		else
60
-			$smcFunc['db_query']('', '
61
+		} else {
62
+					$smcFunc['db_query']('', '
61 63
 				DELETE FROM {db_prefix}log_notify
62 64
 				WHERE id_member = {int:current_member}
63 65
 				AND id_board = {int:current_board}',
@@ -66,6 +68,7 @@  discard block
 block discarded – undo
66 68
 					'current_member' => $user_info['id'],
67 69
 				)
68 70
 			);
71
+		}
69 72
 
70 73
 	}
71 74
 
@@ -81,10 +84,10 @@  discard block
 block discarded – undo
81 84
 			),
82 85
 		);
83 86
 		$context['sub_template'] = 'generic_xml';
87
+	} else {
88
+			redirectexit('board=' . $board . '.' . $_REQUEST['start']);
89
+	}
84 90
 	}
85
-	else
86
-		redirectexit('board=' . $board . '.' . $_REQUEST['start']);
87
-}
88 91
 
89 92
 /**
90 93
  * Turn off/on unread replies subscription for a topic as well as sets individual topic's alert preferences
@@ -108,8 +111,9 @@  discard block
 block discarded – undo
108 111
 			$mode = (int) $_GET['mode'];
109 112
 			$alertPref = $mode <= 1 ? 0 : ($mode == 2 ? 1 : 3);
110 113
 
111
-			if (empty($mode))
112
-				$mode = 1;
114
+			if (empty($mode)) {
115
+							$mode = 1;
116
+			}
113 117
 
114 118
 			$request = $smcFunc['db_query']('', '
115 119
 				SELECT id_member, id_topic, id_msg, unwatched
@@ -132,8 +136,7 @@  discard block
 block discarded – undo
132 136
 					'id_msg' => 0,
133 137
 					'unwatched' => empty($mode) ? 1 : 0,
134 138
 				);
135
-			}
136
-			else
139
+			} else
137 140
 			{
138 141
 				$insert = false;
139 142
 				$log['unwatched'] = empty($mode) ? 1 : 0;
@@ -160,9 +163,8 @@  discard block
 block discarded – undo
160 163
 					array($user_info['id'], $log['id_topic']),
161 164
 					array('id_member', 'id_board')
162 165
 				);
163
-			}
164
-			else
165
-				$smcFunc['db_query']('', '
166
+			} else {
167
+							$smcFunc['db_query']('', '
166 168
 					DELETE FROM {db_prefix}log_notify
167 169
 					WHERE id_topic = {int:topic}
168 170
 						AND id_member = {int:member}',
@@ -170,6 +172,7 @@  discard block
 block discarded – undo
170 172
 						'topic' => $log['id_topic'],
171 173
 						'member' => $user_info['id'],
172 174
 					));
175
+			}
173 176
 
174 177
 		}
175 178
 	}
@@ -186,9 +189,9 @@  discard block
 block discarded – undo
186 189
 			),
187 190
 		);
188 191
 		$context['sub_template'] = 'generic_xml';
192
+	} else {
193
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
194
+	}
189 195
 	}
190
-	else
191
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
192
-}
193 196
 
194 197
 ?>
195 198
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs.php 4 patches
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -5265,7 +5265,6 @@  discard block
 block discarded – undo
5265 5265
 
5266 5266
 /**
5267 5267
  * Tries different modes to make file/dirs writable. Wrapper function for chmod()
5268
-
5269 5268
  * @param string $file The file/dir full path.
5270 5269
  * @param int $value Not needed, added for legacy reasons.
5271 5270
  * @return boolean  true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable.
@@ -5305,7 +5304,6 @@  discard block
 block discarded – undo
5305 5304
 
5306 5305
 /**
5307 5306
  * Wrapper function for json_decode() with error handling.
5308
-
5309 5307
  * @param string $json The string to decode.
5310 5308
  * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default.
5311 5309
  * @param bool $logIt To specify if the error will be logged if theres any.
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 					'height' => array('optional' => true, 'match' => '(\d+)'),
1098 1098
 				),
1099 1099
 				'content' => '$1',
1100
-				'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1100
+				'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1101 1101
 				{
1102 1102
 					$returnContext = '';
1103 1103
 
@@ -1132,7 +1132,7 @@  discard block
 block discarded – undo
1132 1132
 						}
1133 1133
 
1134 1134
 						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1135
+							$returnContext .= '<a href="' . $currentAttachment['href'] . ';image" id="link_' . $currentAttachment['id'] . '" onclick="' . $currentAttachment['thumbnail']['javascript'] . '"><img src="' . $currentAttachment['thumbnail']['href'] . '"' . $alt . $title . ' id="thumb_' . $currentAttachment['id'] . '" class="atc_img"></a>';
1136 1136
 						else
1137 1137
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1138 1138
 					}
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
 				'type' => 'unparsed_content',
1162 1162
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1163 1163
 				// @todo Maybe this can be simplified?
1164
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1164
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1165 1165
 				{
1166 1166
 					if (!isset($disabled['code']))
1167 1167
 					{
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 				'type' => 'unparsed_equals_content',
1199 1199
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1200 1200
 				// @todo Maybe this can be simplified?
1201
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1201
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1202 1202
 				{
1203 1203
 					if (!isset($disabled['code']))
1204 1204
 					{
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 				'type' => 'unparsed_content',
1243 1243
 				'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
1244 1244
 				// @todo Should this respect guest_hideContacts?
1245
-				'validate' => function (&$tag, &$data, $disabled)
1245
+				'validate' => function(&$tag, &$data, $disabled)
1246 1246
 				{
1247 1247
 					$data = strtr($data, array('<br>' => ''));
1248 1248
 				},
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
 				'type' => 'unparsed_commas_content',
1262 1262
 				'test' => '\d+,\d+\]',
1263 1263
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264
-				'validate' => function (&$tag, &$data, $disabled)
1264
+				'validate' => function(&$tag, &$data, $disabled)
1265 1265
 				{
1266 1266
 					if (isset($disabled['url']))
1267 1267
 						$tag['content'] = '$1';
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
 				'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]',
1278 1278
 				'before' => '<div $1>',
1279 1279
 				'after' => '</div>',
1280
-				'validate' => function (&$tag, &$data, $disabled)
1280
+				'validate' => function(&$tag, &$data, $disabled)
1281 1281
 				{
1282 1282
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1283 1283
 
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1327 1327
 				),
1328 1328
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1329
-				'validate' => function (&$tag, &$data, $disabled)
1329
+				'validate' => function(&$tag, &$data, $disabled)
1330 1330
 				{
1331 1331
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1332 1332
 
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
 				'tag' => 'img',
1350 1350
 				'type' => 'unparsed_content',
1351 1351
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1352
-				'validate' => function (&$tag, &$data, $disabled)
1352
+				'validate' => function(&$tag, &$data, $disabled)
1353 1353
 				{
1354 1354
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1355 1355
 
@@ -1372,7 +1372,7 @@  discard block
 block discarded – undo
1372 1372
 				'tag' => 'iurl',
1373 1373
 				'type' => 'unparsed_content',
1374 1374
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1375
-				'validate' => function (&$tag, &$data, $disabled)
1375
+				'validate' => function(&$tag, &$data, $disabled)
1376 1376
 				{
1377 1377
 					$data = strtr($data, array('<br>' => ''));
1378 1378
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
 				'quoted' => 'optional',
1387 1387
 				'before' => '<a href="$1" class="bbc_link">',
1388 1388
 				'after' => '</a>',
1389
-				'validate' => function (&$tag, &$data, $disabled)
1389
+				'validate' => function(&$tag, &$data, $disabled)
1390 1390
 				{
1391 1391
 					if (substr($data, 0, 1) == '#')
1392 1392
 						$data = '#post_' . substr($data, 1);
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
 				'tag' => 'php',
1467 1467
 				'type' => 'unparsed_content',
1468 1468
 				'content' => '<span class="phpcode">$1</span>',
1469
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1469
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1470 1470
 				{
1471 1471
 					if (!isset($disabled['php']))
1472 1472
 					{
@@ -1564,7 +1564,7 @@  discard block
 block discarded – undo
1564 1564
 				'test' => '[1-7]\]',
1565 1565
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1566 1566
 				'after' => '</span>',
1567
-				'validate' => function (&$tag, &$data, $disabled)
1567
+				'validate' => function(&$tag, &$data, $disabled)
1568 1568
 				{
1569 1569
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1570 1570
 					$data = $sizes[$data] . 'em';
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
 				'tag' => 'time',
1603 1603
 				'type' => 'unparsed_content',
1604 1604
 				'content' => '$1',
1605
-				'validate' => function (&$tag, &$data, $disabled)
1605
+				'validate' => function(&$tag, &$data, $disabled)
1606 1606
 				{
1607 1607
 					if (is_numeric($data))
1608 1608
 						$data = timeformat($data);
@@ -1630,7 +1630,7 @@  discard block
 block discarded – undo
1630 1630
 				'tag' => 'url',
1631 1631
 				'type' => 'unparsed_content',
1632 1632
 				'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
1633
-				'validate' => function (&$tag, &$data, $disabled)
1633
+				'validate' => function(&$tag, &$data, $disabled)
1634 1634
 				{
1635 1635
 					$data = strtr($data, array('<br>' => ''));
1636 1636
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1644,7 +1644,7 @@  discard block
 block discarded – undo
1644 1644
 				'quoted' => 'optional',
1645 1645
 				'before' => '<a href="$1" class="bbc_link" target="_blank">',
1646 1646
 				'after' => '</a>',
1647
-				'validate' => function (&$tag, &$data, $disabled)
1647
+				'validate' => function(&$tag, &$data, $disabled)
1648 1648
 				{
1649 1649
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1650 1650
 					if (empty($scheme))
@@ -1670,7 +1670,7 @@  discard block
 block discarded – undo
1670 1670
 		{
1671 1671
 			if (isset($temp_bbc))
1672 1672
 				$bbc_codes = $temp_bbc;
1673
-			usort($codes, function ($a, $b) {
1673
+			usort($codes, function($a, $b) {
1674 1674
 				return strcmp($a['tag'], $b['tag']);
1675 1675
 			});
1676 1676
 			return $codes;
@@ -1908,7 +1908,7 @@  discard block
 block discarded – undo
1908 1908
 										# a run of Unicode domain name characters and a dot
1909 1909
 										[\p{L}\p{M}\p{N}\-.:@]+\.
1910 1910
 										# and then a TLD valid in the DNS or the reserved "local" TLD
1911
-										(?:'. $modSettings['tld_regex'] .'|local)
1911
+										(?:'. $modSettings['tld_regex'] . '|local)
1912 1912
 									)
1913 1913
 									# followed by a non-domain character or end of line
1914 1914
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -1976,7 +1976,7 @@  discard block
 block discarded – undo
1976 1976
 						)?
1977 1977
 						';
1978 1978
 
1979
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
1979
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
1980 1980
 							$url = array_shift($matches);
1981 1981
 
1982 1982
 							$scheme = parse_url($url, PHP_URL_SCHEME);
@@ -2713,7 +2713,7 @@  discard block
 block discarded – undo
2713 2713
 		for ($i = 0, $n = count($smileysfrom); $i < $n; $i++)
2714 2714
 		{
2715 2715
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2716
-			$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">';
2716
+			$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">';
2717 2717
 
2718 2718
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2719 2719
 
@@ -2730,7 +2730,7 @@  discard block
 block discarded – undo
2730 2730
 
2731 2731
 	// Replace away!
2732 2732
 	$message = preg_replace_callback($smileyPregSearch,
2733
-		function ($matches) use ($smileyPregReplacements)
2733
+		function($matches) use ($smileyPregReplacements)
2734 2734
 		{
2735 2735
 			return $smileyPregReplacements[$matches[1]];
2736 2736
 		}, $message);
@@ -2796,13 +2796,13 @@  discard block
 block discarded – undo
2796 2796
 	{
2797 2797
 		if (defined('SID') && SID != '')
2798 2798
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2799
-				function ($m) use ($scripturl)
2799
+				function($m) use ($scripturl)
2800 2800
 				{
2801
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2801
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
2802 2802
 				}, $setLocation);
2803 2803
 		else
2804 2804
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2805
-				function ($m) use ($scripturl)
2805
+				function($m) use ($scripturl)
2806 2806
 				{
2807 2807
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2808 2808
 				}, $setLocation);
@@ -3125,7 +3125,7 @@  discard block
 block discarded – undo
3125 3125
 
3126 3126
 	// Add a generic "Are you sure?" confirmation message.
3127 3127
 	addInlineJavaScript('
3128
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3128
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3129 3129
 
3130 3130
 	// Now add the capping code for avatars.
3131 3131
 	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
@@ -3486,7 +3486,7 @@  discard block
 block discarded – undo
3486 3486
 
3487 3487
 		else
3488 3488
 			echo '
3489
-	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3489
+	<script src="', $settings['theme_url'], '/scripts/minified', ($do_deferred ? '_deferred' : ''), '.js', $minSeed, '"></script>';
3490 3490
 	}
3491 3491
 
3492 3492
 	// Inline JavaScript - Actually useful some times!
@@ -3564,14 +3564,14 @@  discard block
 block discarded – undo
3564 3564
 
3565 3565
 		else
3566 3566
 			echo '
3567
-	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3567
+	<link rel="stylesheet" href="', $settings['theme_url'], '/css/minified.css', $minSeed, '">';
3568 3568
 	}
3569 3569
 
3570 3570
 	// Print the rest after the minified files.
3571 3571
 	if (!empty($normal))
3572 3572
 		foreach ($normal as $nf)
3573 3573
 			echo '
3574
-	<link rel="stylesheet" href="', $nf ,'">';
3574
+	<link rel="stylesheet" href="', $nf, '">';
3575 3575
 
3576 3576
 	if ($db_show_debug === true)
3577 3577
 	{
@@ -3587,7 +3587,7 @@  discard block
 block discarded – undo
3587 3587
 	<style>';
3588 3588
 
3589 3589
 		foreach ($context['css_header'] as $css)
3590
-			echo $css .'
3590
+			echo $css . '
3591 3591
 	';
3592 3592
 
3593 3593
 		echo'
@@ -3616,27 +3616,27 @@  discard block
 block discarded – undo
3616 3616
 		return false;
3617 3617
 
3618 3618
 	// Did we already did this?
3619
-	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3619
+	$toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type, 86400);
3620 3620
 
3621 3621
 	// Already done?
3622 3622
 	if (!empty($toCache))
3623 3623
 		return true;
3624 3624
 
3625 3625
 	// No namespaces, sorry!
3626
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3626
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3627 3627
 
3628 3628
 	// Temp path.
3629
-	$cTempPath = $settings['theme_dir'] .'/'. ($type == 'css' ? 'css' : 'scripts') .'/';
3629
+	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
3630 3630
 
3631 3631
 	// What kind of file are we going to create?
3632
-	$toCreate = $cTempPath .'minified'. ($do_deferred ? '_deferred' : '') .'.'. $type;
3632
+	$toCreate = $cTempPath . 'minified' . ($do_deferred ? '_deferred' : '') . '.' . $type;
3633 3633
 
3634 3634
 	// File has to exists, if it isn't try to create it.
3635 3635
 	if ((!file_exists($toCreate) && @fopen($toCreate, 'w') === false) || !smf_chmod($toCreate))
3636 3636
 	{
3637 3637
 		loadLanguage('Errors');
3638 3638
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3639
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3639
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3640 3640
 
3641 3641
 		// The process failed so roll back to print each individual file.
3642 3642
 		return $data;
@@ -3671,14 +3671,14 @@  discard block
 block discarded – undo
3671 3671
 	{
3672 3672
 		loadLanguage('Errors');
3673 3673
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3674
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3674
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3675 3675
 
3676 3676
 		// The process failed so roll back to print each individual file.
3677 3677
 		return $data;
3678 3678
 	}
3679 3679
 
3680 3680
 	// And create a long lived cache entry.
3681
-	cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, $toCreate, 86400);
3681
+	cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, $toCreate, 86400);
3682 3682
 
3683 3683
 	return true;
3684 3684
 }
@@ -3738,7 +3738,7 @@  discard block
 block discarded – undo
3738 3738
 	else
3739 3739
 		$path = $modSettings['attachmentUploadDir'];
3740 3740
 
3741
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3741
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
3742 3742
 }
3743 3743
 
3744 3744
 /**
@@ -3782,10 +3782,10 @@  discard block
 block discarded – undo
3782 3782
 		$valid_low = isValidIP($ip_parts[0]);
3783 3783
 		$valid_high = isValidIP($ip_parts[1]);
3784 3784
 		$count = 0;
3785
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
3785
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
3786 3786
 		$max = ($mode == ':' ? 'ffff' : '255');
3787 3787
 		$min = 0;
3788
-		if(!$valid_low)
3788
+		if (!$valid_low)
3789 3789
 		{
3790 3790
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
3791 3791
 			$valid_low = isValidIP($ip_parts[0]);
@@ -3799,7 +3799,7 @@  discard block
 block discarded – undo
3799 3799
 		}
3800 3800
 
3801 3801
 		$count = 0;
3802
-		if(!$valid_high)
3802
+		if (!$valid_high)
3803 3803
 		{
3804 3804
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
3805 3805
 			$valid_high = isValidIP($ip_parts[1]);
@@ -3812,7 +3812,7 @@  discard block
 block discarded – undo
3812 3812
 			}
3813 3813
 		}
3814 3814
 
3815
-		if($valid_high && $valid_low)
3815
+		if ($valid_high && $valid_low)
3816 3816
 		{
3817 3817
 			$ip_array['low'] = $ip_parts[0];
3818 3818
 			$ip_array['high'] = $ip_parts[1];
@@ -3994,7 +3994,7 @@  discard block
 block discarded – undo
3994 3994
 		addInlineJavaScript('
3995 3995
 	var user_menus = new smc_PopupMenu();
3996 3996
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3997
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3997
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
3998 3998
 		if ($context['allow_pm'])
3999 3999
 			addInlineJavaScript('
4000 4000
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -4619,7 +4619,7 @@  discard block
 block discarded – undo
4619 4619
 		// No? try a fallback to $sourcedir
4620 4620
 		else
4621 4621
 		{
4622
-			$absPath = $sourcedir .'/'. $file;
4622
+			$absPath = $sourcedir . '/' . $file;
4623 4623
 
4624 4624
 			if (file_exists($absPath))
4625 4625
 				require_once($absPath);
@@ -4700,15 +4700,15 @@  discard block
 block discarded – undo
4700 4700
 
4701 4701
 	// UTF-8 occurences of MS special characters
4702 4702
 	$findchars_utf8 = array(
4703
-		"\xe2\x80\x9a",	// single low-9 quotation mark
4704
-		"\xe2\x80\x9e",	// double low-9 quotation mark
4705
-		"\xe2\x80\xa6",	// horizontal ellipsis
4706
-		"\xe2\x80\x98",	// left single curly quote
4707
-		"\xe2\x80\x99",	// right single curly quote
4708
-		"\xe2\x80\x9c",	// left double curly quote
4709
-		"\xe2\x80\x9d",	// right double curly quote
4710
-		"\xe2\x80\x93",	// en dash
4711
-		"\xe2\x80\x94",	// em dash
4703
+		"\xe2\x80\x9a", // single low-9 quotation mark
4704
+		"\xe2\x80\x9e", // double low-9 quotation mark
4705
+		"\xe2\x80\xa6", // horizontal ellipsis
4706
+		"\xe2\x80\x98", // left single curly quote
4707
+		"\xe2\x80\x99", // right single curly quote
4708
+		"\xe2\x80\x9c", // left double curly quote
4709
+		"\xe2\x80\x9d", // right double curly quote
4710
+		"\xe2\x80\x93", // en dash
4711
+		"\xe2\x80\x94", // em dash
4712 4712
 	);
4713 4713
 
4714 4714
 	// windows 1252 / iso equivalents
@@ -4726,15 +4726,15 @@  discard block
 block discarded – undo
4726 4726
 
4727 4727
 	// safe replacements
4728 4728
 	$replacechars = array(
4729
-		',',	// &sbquo;
4730
-		',,',	// &bdquo;
4731
-		'...',	// &hellip;
4732
-		"'",	// &lsquo;
4733
-		"'",	// &rsquo;
4734
-		'"',	// &ldquo;
4735
-		'"',	// &rdquo;
4736
-		'-',	// &ndash;
4737
-		'--',	// &mdash;
4729
+		',', // &sbquo;
4730
+		',,', // &bdquo;
4731
+		'...', // &hellip;
4732
+		"'", // &lsquo;
4733
+		"'", // &rsquo;
4734
+		'"', // &ldquo;
4735
+		'"', // &rdquo;
4736
+		'-', // &ndash;
4737
+		'--', // &mdash;
4738 4738
 	);
4739 4739
 
4740 4740
 	if ($context['utf8'])
@@ -5097,7 +5097,7 @@  discard block
 block discarded – undo
5097 5097
  */
5098 5098
 function inet_dtop($bin)
5099 5099
 {
5100
-	if(empty($bin))
5100
+	if (empty($bin))
5101 5101
 		return '';
5102 5102
 
5103 5103
 	global $db_type;
@@ -5128,28 +5128,28 @@  discard block
 block discarded – undo
5128 5128
  */
5129 5129
 function _safe_serialize($value)
5130 5130
 {
5131
-	if(is_null($value))
5131
+	if (is_null($value))
5132 5132
 		return 'N;';
5133 5133
 
5134
-	if(is_bool($value))
5135
-		return 'b:'. (int) $value .';';
5134
+	if (is_bool($value))
5135
+		return 'b:' . (int) $value . ';';
5136 5136
 
5137
-	if(is_int($value))
5138
-		return 'i:'. $value .';';
5137
+	if (is_int($value))
5138
+		return 'i:' . $value . ';';
5139 5139
 
5140
-	if(is_float($value))
5141
-		return 'd:'. str_replace(',', '.', $value) .';';
5140
+	if (is_float($value))
5141
+		return 'd:' . str_replace(',', '.', $value) . ';';
5142 5142
 
5143
-	if(is_string($value))
5144
-		return 's:'. strlen($value) .':"'. $value .'";';
5143
+	if (is_string($value))
5144
+		return 's:' . strlen($value) . ':"' . $value . '";';
5145 5145
 
5146
-	if(is_array($value))
5146
+	if (is_array($value))
5147 5147
 	{
5148 5148
 		$out = '';
5149
-		foreach($value as $k => $v)
5149
+		foreach ($value as $k => $v)
5150 5150
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5151 5151
 
5152
-		return 'a:'. count($value) .':{'. $out .'}';
5152
+		return 'a:' . count($value) . ':{' . $out . '}';
5153 5153
 	}
5154 5154
 
5155 5155
 	// safe_serialize cannot serialize resources or objects.
@@ -5191,7 +5191,7 @@  discard block
 block discarded – undo
5191 5191
 function _safe_unserialize($str)
5192 5192
 {
5193 5193
 	// Input  is not a string.
5194
-	if(empty($str) || !is_string($str))
5194
+	if (empty($str) || !is_string($str))
5195 5195
 		return false;
5196 5196
 
5197 5197
 	$stack = array();
@@ -5205,40 +5205,40 @@  discard block
 block discarded – undo
5205 5205
 	 *   3 - in array, expecting value or another array
5206 5206
 	 */
5207 5207
 	$state = 0;
5208
-	while($state != 1)
5208
+	while ($state != 1)
5209 5209
 	{
5210 5210
 		$type = isset($str[0]) ? $str[0] : '';
5211
-		if($type == '}')
5211
+		if ($type == '}')
5212 5212
 			$str = substr($str, 1);
5213 5213
 
5214
-		else if($type == 'N' && $str[1] == ';')
5214
+		else if ($type == 'N' && $str[1] == ';')
5215 5215
 		{
5216 5216
 			$value = null;
5217 5217
 			$str = substr($str, 2);
5218 5218
 		}
5219
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5219
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5220 5220
 		{
5221 5221
 			$value = $matches[1] == '1' ? true : false;
5222 5222
 			$str = substr($str, 4);
5223 5223
 		}
5224
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5224
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5225 5225
 		{
5226
-			$value = (int)$matches[1];
5226
+			$value = (int) $matches[1];
5227 5227
 			$str = $matches[2];
5228 5228
 		}
5229
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5229
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5230 5230
 		{
5231
-			$value = (float)$matches[1];
5231
+			$value = (float) $matches[1];
5232 5232
 			$str = $matches[3];
5233 5233
 		}
5234
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5234
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5235 5235
 		{
5236
-			$value = substr($matches[2], 0, (int)$matches[1]);
5237
-			$str = substr($matches[2], (int)$matches[1] + 2);
5236
+			$value = substr($matches[2], 0, (int) $matches[1]);
5237
+			$str = substr($matches[2], (int) $matches[1] + 2);
5238 5238
 		}
5239
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5239
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5240 5240
 		{
5241
-			$expectedLength = (int)$matches[1];
5241
+			$expectedLength = (int) $matches[1];
5242 5242
 			$str = $matches[2];
5243 5243
 		}
5244 5244
 
@@ -5246,10 +5246,10 @@  discard block
 block discarded – undo
5246 5246
 		else
5247 5247
 			return false;
5248 5248
 
5249
-		switch($state)
5249
+		switch ($state)
5250 5250
 		{
5251 5251
 			case 3: // In array, expecting value or another array.
5252
-				if($type == 'a')
5252
+				if ($type == 'a')
5253 5253
 				{
5254 5254
 					$stack[] = &$list;
5255 5255
 					$list[$key] = array();
@@ -5258,7 +5258,7 @@  discard block
 block discarded – undo
5258 5258
 					$state = 2;
5259 5259
 					break;
5260 5260
 				}
5261
-				if($type != '}')
5261
+				if ($type != '}')
5262 5262
 				{
5263 5263
 					$list[$key] = $value;
5264 5264
 					$state = 2;
@@ -5269,29 +5269,29 @@  discard block
 block discarded – undo
5269 5269
 				return false;
5270 5270
 
5271 5271
 			case 2: // in array, expecting end of array or a key
5272
-				if($type == '}')
5272
+				if ($type == '}')
5273 5273
 				{
5274 5274
 					// Array size is less than expected.
5275
-					if(count($list) < end($expected))
5275
+					if (count($list) < end($expected))
5276 5276
 						return false;
5277 5277
 
5278 5278
 					unset($list);
5279
-					$list = &$stack[count($stack)-1];
5279
+					$list = &$stack[count($stack) - 1];
5280 5280
 					array_pop($stack);
5281 5281
 
5282 5282
 					// Go to terminal state if we're at the end of the root array.
5283 5283
 					array_pop($expected);
5284 5284
 
5285
-					if(count($expected) == 0)
5285
+					if (count($expected) == 0)
5286 5286
 						$state = 1;
5287 5287
 
5288 5288
 					break;
5289 5289
 				}
5290 5290
 
5291
-				if($type == 'i' || $type == 's')
5291
+				if ($type == 'i' || $type == 's')
5292 5292
 				{
5293 5293
 					// Array size exceeds expected length.
5294
-					if(count($list) >= end($expected))
5294
+					if (count($list) >= end($expected))
5295 5295
 						return false;
5296 5296
 
5297 5297
 					$key = $value;
@@ -5304,7 +5304,7 @@  discard block
 block discarded – undo
5304 5304
 
5305 5305
 			// Expecting array or value.
5306 5306
 			case 0:
5307
-				if($type == 'a')
5307
+				if ($type == 'a')
5308 5308
 				{
5309 5309
 					$data = array();
5310 5310
 					$list = &$data;
@@ -5313,7 +5313,7 @@  discard block
 block discarded – undo
5313 5313
 					break;
5314 5314
 				}
5315 5315
 
5316
-				if($type != '}')
5316
+				if ($type != '}')
5317 5317
 				{
5318 5318
 					$data = $value;
5319 5319
 					$state = 1;
@@ -5326,7 +5326,7 @@  discard block
 block discarded – undo
5326 5326
 	}
5327 5327
 
5328 5328
 	// Trailing data in input.
5329
-	if(!empty($str))
5329
+	if (!empty($str))
5330 5330
 		return false;
5331 5331
 
5332 5332
 	return $data;
@@ -5380,7 +5380,7 @@  discard block
 block discarded – undo
5380 5380
 	// Set different modes.
5381 5381
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5382 5382
 
5383
-	foreach($chmodValues as $val)
5383
+	foreach ($chmodValues as $val)
5384 5384
 	{
5385 5385
 		// If it's writable, break out of the loop.
5386 5386
 		if (is_writable($file))
@@ -5415,13 +5415,13 @@  discard block
 block discarded – undo
5415 5415
 	$returnArray = @json_decode($json, $returnAsArray);
5416 5416
 
5417 5417
 	// PHP 5.3 so no json_last_error_msg()
5418
-	switch(json_last_error())
5418
+	switch (json_last_error())
5419 5419
 	{
5420 5420
 		case JSON_ERROR_NONE:
5421 5421
 			$jsonError = false;
5422 5422
 			break;
5423 5423
 		case JSON_ERROR_DEPTH:
5424
-			$jsonError =  'JSON_ERROR_DEPTH';
5424
+			$jsonError = 'JSON_ERROR_DEPTH';
5425 5425
 			break;
5426 5426
 		case JSON_ERROR_STATE_MISMATCH:
5427 5427
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -5449,10 +5449,10 @@  discard block
 block discarded – undo
5449 5449
 		loadLanguage('Errors');
5450 5450
 
5451 5451
 		if (!empty($jsonDebug))
5452
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5452
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5453 5453
 
5454 5454
 		else
5455
-			log_error($txt['json_'. $jsonError], 'critical');
5455
+			log_error($txt['json_' . $jsonError], 'critical');
5456 5456
 
5457 5457
 		// Everyone expects an array.
5458 5458
 		return array();
@@ -5556,7 +5556,7 @@  discard block
 block discarded – undo
5556 5556
 		});
5557 5557
 
5558 5558
 		// Convert Punycode to Unicode
5559
-		$tlds = array_map(function ($input) {
5559
+		$tlds = array_map(function($input) {
5560 5560
 			$prefix = 'xn--';
5561 5561
 			$safe_char = 0xFFFC;
5562 5562
 			$base = 36;
@@ -5572,7 +5572,7 @@  discard block
 block discarded – undo
5572 5572
 
5573 5573
 			foreach ($enco_parts as $encoded)
5574 5574
 			{
5575
-				if (strpos($encoded,$prefix) !== 0 || strlen(trim(str_replace($prefix,'',$encoded))) == 0)
5575
+				if (strpos($encoded, $prefix) !== 0 || strlen(trim(str_replace($prefix, '', $encoded))) == 0)
5576 5576
 				{
5577 5577
 					$output_parts[] = $encoded;
5578 5578
 					continue;
@@ -5583,7 +5583,7 @@  discard block
 block discarded – undo
5583 5583
 				$idx = 0;
5584 5584
 				$char = 0x80;
5585 5585
 				$decoded = array();
5586
-				$output='';
5586
+				$output = '';
5587 5587
 				$delim_pos = strrpos($encoded, '-');
5588 5588
 
5589 5589
 				if ($delim_pos > strlen($prefix))
@@ -5599,7 +5599,7 @@  discard block
 block discarded – undo
5599 5599
 
5600 5600
 				for ($enco_idx = $delim_pos ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len)
5601 5601
 				{
5602
-					for ($old_idx = $idx, $w = 1, $k = $base; 1 ; $k += $base)
5602
+					for ($old_idx = $idx, $w = 1, $k = $base; 1; $k += $base)
5603 5603
 					{
5604 5604
 						$cp = ord($encoded{$enco_idx++});
5605 5605
 						$digit = ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $base));
@@ -5640,15 +5640,15 @@  discard block
 block discarded – undo
5640 5640
 
5641 5641
 					// 2 bytes
5642 5642
 					elseif ($v < (1 << 11))
5643
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5643
+						$output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
5644 5644
 
5645 5645
 					// 3 bytes
5646 5646
 					elseif ($v < (1 << 16))
5647
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5647
+						$output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5648 5648
 
5649 5649
 					// 4 bytes
5650 5650
 					elseif ($v < (1 << 21))
5651
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5651
+						$output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5652 5652
 
5653 5653
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5654 5654
 					else
@@ -5755,7 +5755,7 @@  discard block
 block discarded – undo
5755 5755
 	}
5756 5756
 
5757 5757
 	// This recursive function creates the index array from the strings
5758
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5758
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5759 5759
 	{
5760 5760
 		static $depth = 0;
5761 5761
 		$depth++;
@@ -5782,7 +5782,7 @@  discard block
 block discarded – undo
5782 5782
 	};
5783 5783
 
5784 5784
 	// This recursive function turns the index array into a regular expression
5785
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
5785
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
5786 5786
 	{
5787 5787
 		static $depth = 0;
5788 5788
 		$depth++;
@@ -5806,11 +5806,11 @@  discard block
 block discarded – undo
5806 5806
 
5807 5807
 				if (count(array_keys($value)) == 1)
5808 5808
 				{
5809
-					$new_key_array = explode('(?'.'>', $sub_regex);
5809
+					$new_key_array = explode('(?' . '>', $sub_regex);
5810 5810
 					$new_key .= $new_key_array[0];
5811 5811
 				}
5812 5812
 				else
5813
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5813
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
5814 5814
 			}
5815 5815
 
5816 5816
 			if ($depth > 1)
@@ -5850,7 +5850,7 @@  discard block
 block discarded – undo
5850 5850
 		$index = $add_string_to_index($string, $index);
5851 5851
 
5852 5852
 	while (!empty($index))
5853
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
5853
+		$regexes[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
5854 5854
 
5855 5855
 	// Restore PHP's internal character encoding to whatever it was originally
5856 5856
 	if (!empty($current_encoding))
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
  * - caches the formatting data from the setting for optimization.
677 677
  *
678 678
  * @param float $number A number
679
- * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
679
+ * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
680 680
  * @return string A formatted number
681 681
  */
682 682
 function comma_format($number, $override_decimal_count = false)
@@ -5530,7 +5530,7 @@  discard block
 block discarded – undo
5530 5530
  * It assumes the data is already a string.
5531 5531
  * @param string $data The data to print
5532 5532
  * @param string $type The content type. Defaults to Json.
5533
- * @return void
5533
+ * @return false|null
5534 5534
  */
5535 5535
 function smf_serverResponse($data = '', $type = 'Content-Type: application/json')
5536 5536
 {
Please login to merge, or discard this patch.
Braces   +1287 added lines, -957 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($type == 'int' && ($val === '+' || $val === '-'))
@@ -390,8 +399,9 @@  discard block
 block discarded – undo
390 399
 		{
391 400
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
392 401
 			{
393
-				if ($match[1] != '+ ')
394
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
402
+				if ($match[1] != '+ ') {
403
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
404
+				}
395 405
 				$type = 'raw';
396 406
 			}
397 407
 		}
@@ -412,8 +422,9 @@  discard block
 block discarded – undo
412 422
 	// Clear any caching?
413 423
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
414 424
 	{
415
-		if (!is_array($members))
416
-			$members = array($members);
425
+		if (!is_array($members)) {
426
+					$members = array($members);
427
+		}
417 428
 
418 429
 		foreach ($members as $member)
419 430
 		{
@@ -446,29 +457,32 @@  discard block
 block discarded – undo
446 457
 {
447 458
 	global $modSettings, $smcFunc;
448 459
 
449
-	if (empty($changeArray) || !is_array($changeArray))
450
-		return;
460
+	if (empty($changeArray) || !is_array($changeArray)) {
461
+			return;
462
+	}
451 463
 
452 464
 	$toRemove = array();
453 465
 
454 466
 	// Go check if there is any setting to be removed.
455
-	foreach ($changeArray as $k => $v)
456
-		if ($v === null)
467
+	foreach ($changeArray as $k => $v) {
468
+			if ($v === null)
457 469
 		{
458 470
 			// Found some, remove them from the original array and add them to ours.
459 471
 			unset($changeArray[$k]);
472
+	}
460 473
 			$toRemove[] = $k;
461 474
 		}
462 475
 
463 476
 	// Proceed with the deletion.
464
-	if (!empty($toRemove))
465
-		$smcFunc['db_query']('', '
477
+	if (!empty($toRemove)) {
478
+			$smcFunc['db_query']('', '
466 479
 			DELETE FROM {db_prefix}settings
467 480
 			WHERE variable IN ({array_string:remove})',
468 481
 			array(
469 482
 				'remove' => $toRemove,
470 483
 			)
471 484
 		);
485
+	}
472 486
 
473 487
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
474 488
 	if ($update)
@@ -497,19 +511,22 @@  discard block
 block discarded – undo
497 511
 	foreach ($changeArray as $variable => $value)
498 512
 	{
499 513
 		// Don't bother if it's already like that ;).
500
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
501
-			continue;
514
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
515
+					continue;
516
+		}
502 517
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
503
-		elseif (!isset($modSettings[$variable]) && empty($value))
504
-			continue;
518
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
519
+					continue;
520
+		}
505 521
 
506 522
 		$replaceArray[] = array($variable, $value);
507 523
 
508 524
 		$modSettings[$variable] = $value;
509 525
 	}
510 526
 
511
-	if (empty($replaceArray))
512
-		return;
527
+	if (empty($replaceArray)) {
528
+			return;
529
+	}
513 530
 
514 531
 	$smcFunc['db_insert']('replace',
515 532
 		'{db_prefix}settings',
@@ -555,14 +572,17 @@  discard block
 block discarded – undo
555 572
 	$start_invalid = $start < 0;
556 573
 
557 574
 	// Make sure $start is a proper variable - not less than 0.
558
-	if ($start_invalid)
559
-		$start = 0;
575
+	if ($start_invalid) {
576
+			$start = 0;
577
+	}
560 578
 	// Not greater than the upper bound.
561
-	elseif ($start >= $max_value)
562
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
579
+	elseif ($start >= $max_value) {
580
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
581
+	}
563 582
 	// And it has to be a multiple of $num_per_page!
564
-	else
565
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
583
+	else {
584
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
585
+	}
566 586
 
567 587
 	$context['current_page'] = $start / $num_per_page;
568 588
 
@@ -592,77 +612,87 @@  discard block
 block discarded – undo
592 612
 
593 613
 		// Show all the pages.
594 614
 		$display_page = 1;
595
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
596
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
615
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
616
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
617
+		}
597 618
 
598 619
 		// Show the right arrow.
599 620
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
600
-		if ($start != $counter - $max_value && !$start_invalid)
601
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
602
-	}
603
-	else
621
+		if ($start != $counter - $max_value && !$start_invalid) {
622
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
623
+		}
624
+	} else
604 625
 	{
605 626
 		// If they didn't enter an odd value, pretend they did.
606 627
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
607 628
 
608 629
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
609
-		if (!empty($start) && $show_prevnext)
610
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
611
-		else
612
-			$pageindex .= '';
630
+		if (!empty($start) && $show_prevnext) {
631
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
632
+		} else {
633
+					$pageindex .= '';
634
+		}
613 635
 
614 636
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
615
-		if ($start > $num_per_page * $PageContiguous)
616
-			$pageindex .= sprintf($base_link, 0, '1');
637
+		if ($start > $num_per_page * $PageContiguous) {
638
+					$pageindex .= sprintf($base_link, 0, '1');
639
+		}
617 640
 
618 641
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
619
-		if ($start > $num_per_page * ($PageContiguous + 1))
620
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
642
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
643
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
621 644
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
622 645
 				'{FIRST_PAGE}' => $num_per_page,
623 646
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
624 647
 				'{PER_PAGE}' => $num_per_page,
625 648
 			));
649
+		}
626 650
 
627 651
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
628
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
629
-			if ($start >= $num_per_page * $nCont)
652
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
653
+					if ($start >= $num_per_page * $nCont)
630 654
 			{
631 655
 				$tmpStart = $start - $num_per_page * $nCont;
656
+		}
632 657
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
633 658
 			}
634 659
 
635 660
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
636
-		if (!$start_invalid)
637
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
638
-		else
639
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
661
+		if (!$start_invalid) {
662
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
663
+		} else {
664
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
665
+		}
640 666
 
641 667
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
642 668
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
643
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
644
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
669
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
670
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
645 671
 			{
646 672
 				$tmpStart = $start + $num_per_page * $nCont;
673
+		}
647 674
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
648 675
 			}
649 676
 
650 677
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
651
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
652
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
679
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
653 680
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
654 681
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
655 682
 				'{LAST_PAGE}' => $tmpMaxPages,
656 683
 				'{PER_PAGE}' => $num_per_page,
657 684
 			));
685
+		}
658 686
 
659 687
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
660
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
661
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
688
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
689
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
690
+		}
662 691
 
663 692
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
664
-		if ($start != $tmpMaxPages && $show_prevnext)
665
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
693
+		if ($start != $tmpMaxPages && $show_prevnext) {
694
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
695
+		}
666 696
 	}
667 697
 	$pageindex .= $settings['page_index']['extra_after'];
668 698
 
@@ -688,8 +718,9 @@  discard block
 block discarded – undo
688 718
 	if ($decimal_separator === null)
689 719
 	{
690 720
 		// Not set for whatever reason?
691
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
692
-			return $number;
721
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
722
+					return $number;
723
+		}
693 724
 
694 725
 		// Cache these each load...
695 726
 		$thousands_separator = $matches[1];
@@ -721,17 +752,20 @@  discard block
 block discarded – undo
721 752
 	static $non_twelve_hour;
722 753
 
723 754
 	// Offset the time.
724
-	if (!$offset_type)
725
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
755
+	if (!$offset_type) {
756
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
757
+	}
726 758
 	// Just the forum offset?
727
-	elseif ($offset_type == 'forum')
728
-		$time = $log_time + $modSettings['time_offset'] * 3600;
729
-	else
730
-		$time = $log_time;
759
+	elseif ($offset_type == 'forum') {
760
+			$time = $log_time + $modSettings['time_offset'] * 3600;
761
+	} else {
762
+			$time = $log_time;
763
+	}
731 764
 
732 765
 	// We can't have a negative date (on Windows, at least.)
733
-	if ($log_time < 0)
734
-		$log_time = 0;
766
+	if ($log_time < 0) {
767
+			$log_time = 0;
768
+	}
735 769
 
736 770
 	// Today and Yesterday?
737 771
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -748,46 +782,53 @@  discard block
 block discarded – undo
748 782
 		{
749 783
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
750 784
 			$today_fmt = $h . ':%M' . $s . ' %p';
785
+		} else {
786
+					$today_fmt = '%H:%M' . $s;
751 787
 		}
752
-		else
753
-			$today_fmt = '%H:%M' . $s;
754 788
 
755 789
 		// Same day of the year, same year.... Today!
756
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
757
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
790
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
791
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
792
+		}
758 793
 
759 794
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
760
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
761
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
795
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
796
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
797
+		}
762 798
 	}
763 799
 
764 800
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
765 801
 
766 802
 	if (setlocale(LC_TIME, $txt['lang_locale']))
767 803
 	{
768
-		if (!isset($non_twelve_hour))
769
-			$non_twelve_hour = trim(strftime('%p')) === '';
770
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
771
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
804
+		if (!isset($non_twelve_hour)) {
805
+					$non_twelve_hour = trim(strftime('%p')) === '';
806
+		}
807
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
808
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
809
+		}
772 810
 
773
-		foreach (array('%a', '%A', '%b', '%B') as $token)
774
-			if (strpos($str, $token) !== false)
811
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
812
+					if (strpos($str, $token) !== false)
775 813
 				$str = str_replace($token, strftime($token, $time), $str);
776
-	}
777
-	else
814
+		}
815
+	} else
778 816
 	{
779 817
 		// Do-it-yourself time localization.  Fun.
780
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
781
-			if (strpos($str, $token) !== false)
818
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
819
+					if (strpos($str, $token) !== false)
782 820
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
821
+		}
783 822
 
784
-		if (strpos($str, '%p') !== false)
785
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
823
+		if (strpos($str, '%p') !== false) {
824
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
825
+		}
786 826
 	}
787 827
 
788 828
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
789
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
790
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
829
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
830
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
831
+	}
791 832
 
792 833
 	// Format any other characters..
793 834
 	return strftime($str, $time);
@@ -809,16 +850,19 @@  discard block
 block discarded – undo
809 850
 	static $translation = array();
810 851
 
811 852
 	// Determine the character set... Default to UTF-8
812
-	if (empty($context['character_set']))
813
-		$charset = 'UTF-8';
853
+	if (empty($context['character_set'])) {
854
+			$charset = 'UTF-8';
855
+	}
814 856
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
815
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
816
-		$charset = 'ISO-8859-1';
817
-	else
818
-		$charset = $context['character_set'];
857
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
858
+			$charset = 'ISO-8859-1';
859
+	} else {
860
+			$charset = $context['character_set'];
861
+	}
819 862
 
820
-	if (empty($translation))
821
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
863
+	if (empty($translation)) {
864
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
865
+	}
822 866
 
823 867
 	return strtr($string, $translation);
824 868
 }
@@ -840,8 +884,9 @@  discard block
 block discarded – undo
840 884
 	global $smcFunc;
841 885
 
842 886
 	// It was already short enough!
843
-	if ($smcFunc['strlen']($subject) <= $len)
844
-		return $subject;
887
+	if ($smcFunc['strlen']($subject) <= $len) {
888
+			return $subject;
889
+	}
845 890
 
846 891
 	// Shorten it by the length it was too long, and strip off junk from the end.
847 892
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -860,10 +905,11 @@  discard block
 block discarded – undo
860 905
 {
861 906
 	global $user_info, $modSettings;
862 907
 
863
-	if ($timestamp === null)
864
-		$timestamp = time();
865
-	elseif ($timestamp == 0)
866
-		return 0;
908
+	if ($timestamp === null) {
909
+			$timestamp = time();
910
+	} elseif ($timestamp == 0) {
911
+			return 0;
912
+	}
867 913
 
868 914
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
869 915
 }
@@ -892,8 +938,9 @@  discard block
 block discarded – undo
892 938
 		$array[$i] = $array[$j];
893 939
 		$array[$j] = $temp;
894 940
 
895
-		for ($i = 1; $p[$i] == 0; $i++)
896
-			$p[$i] = 1;
941
+		for ($i = 1; $p[$i] == 0; $i++) {
942
+					$p[$i] = 1;
943
+		}
897 944
 
898 945
 		$orders[] = $array;
899 946
 	}
@@ -925,12 +972,14 @@  discard block
 block discarded – undo
925 972
 	static $disabled;
926 973
 
927 974
 	// Don't waste cycles
928
-	if ($message === '')
929
-		return '';
975
+	if ($message === '') {
976
+			return '';
977
+	}
930 978
 
931 979
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
932
-	if (!isset($context['utf8']))
933
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
980
+	if (!isset($context['utf8'])) {
981
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
982
+	}
934 983
 
935 984
 	// Clean up any cut/paste issues we may have
936 985
 	$message = sanitizeMSCutPaste($message);
@@ -942,13 +991,15 @@  discard block
 block discarded – undo
942 991
 		return $message;
943 992
 	}
944 993
 
945
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
946
-		$smileys = (bool) $smileys;
994
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
995
+			$smileys = (bool) $smileys;
996
+	}
947 997
 
948 998
 	if (empty($modSettings['enableBBC']) && $message !== false)
949 999
 	{
950
-		if ($smileys === true)
951
-			parsesmileys($message);
1000
+		if ($smileys === true) {
1001
+					parsesmileys($message);
1002
+		}
952 1003
 
953 1004
 		return $message;
954 1005
 	}
@@ -961,8 +1012,9 @@  discard block
 block discarded – undo
961 1012
 	}
962 1013
 
963 1014
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
964
-	if (!empty($modSettings['autoLinkUrls']))
965
-		set_tld_regex();
1015
+	if (!empty($modSettings['autoLinkUrls'])) {
1016
+			set_tld_regex();
1017
+	}
966 1018
 
967 1019
 	// Allow mods access before entering the main parse_bbc loop
968 1020
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -976,12 +1028,14 @@  discard block
 block discarded – undo
976 1028
 
977 1029
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
978 1030
 
979
-			foreach ($temp as $tag)
980
-				$disabled[trim($tag)] = true;
1031
+			foreach ($temp as $tag) {
1032
+							$disabled[trim($tag)] = true;
1033
+			}
981 1034
 		}
982 1035
 
983
-		if (empty($modSettings['enableEmbeddedFlash']))
984
-			$disabled['flash'] = true;
1036
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1037
+					$disabled['flash'] = true;
1038
+		}
985 1039
 
986 1040
 		/* The following bbc are formatted as an array, with keys as follows:
987 1041
 
@@ -1102,8 +1156,9 @@  discard block
 block discarded – undo
1102 1156
 					$returnContext = '';
1103 1157
 
1104 1158
 					// BBC or the entire attachments feature is disabled
1105
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1106
-						return $data;
1159
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1160
+											return $data;
1161
+					}
1107 1162
 
1108 1163
 					// Save the attach ID.
1109 1164
 					$attachID = $data;
@@ -1114,8 +1169,9 @@  discard block
 block discarded – undo
1114 1169
 					$currentAttachment = parseAttachBBC($attachID);
1115 1170
 
1116 1171
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1117
-					if (is_string($currentAttachment))
1118
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1172
+					if (is_string($currentAttachment)) {
1173
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1174
+					}
1119 1175
 
1120 1176
 					if (!empty($currentAttachment['is_image']))
1121 1177
 					{
@@ -1131,15 +1187,17 @@  discard block
 block discarded – undo
1131 1187
 							$height = ' height="' . $currentAttachment['height'] . '"';
1132 1188
 						}
1133 1189
 
1134
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1136
-						else
1137
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1190
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1191
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1192
+						} else {
1193
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1194
+						}
1138 1195
 					}
1139 1196
 
1140 1197
 					// No image. Show a link.
1141
-					else
1142
-						$returnContext .= $currentAttachment['link'];
1198
+					else {
1199
+											$returnContext .= $currentAttachment['link'];
1200
+					}
1143 1201
 
1144 1202
 					// Gotta append what we just did.
1145 1203
 					$data = $returnContext;
@@ -1170,8 +1228,9 @@  discard block
 block discarded – undo
1170 1228
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1171 1229
 						{
1172 1230
 							// Do PHP code coloring?
1173
-							if ($php_parts[$php_i] != '&lt;?php')
1174
-								continue;
1231
+							if ($php_parts[$php_i] != '&lt;?php') {
1232
+															continue;
1233
+							}
1175 1234
 
1176 1235
 							$php_string = '';
1177 1236
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1188 1247
 
1189 1248
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1190
-						if ($context['browser']['is_opera'])
1191
-							$data .= '&nbsp;';
1249
+						if ($context['browser']['is_opera']) {
1250
+													$data .= '&nbsp;';
1251
+						}
1192 1252
 					}
1193 1253
 				},
1194 1254
 				'block_level' => true,
@@ -1207,8 +1267,9 @@  discard block
 block discarded – undo
1207 1267
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1208 1268
 						{
1209 1269
 							// Do PHP code coloring?
1210
-							if ($php_parts[$php_i] != '&lt;?php')
1211
-								continue;
1270
+							if ($php_parts[$php_i] != '&lt;?php') {
1271
+															continue;
1272
+							}
1212 1273
 
1213 1274
 							$php_string = '';
1214 1275
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1224,8 +1285,9 @@  discard block
 block discarded – undo
1224 1285
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1225 1286
 
1226 1287
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1227
-						if ($context['browser']['is_opera'])
1228
-							$data[0] .= '&nbsp;';
1288
+						if ($context['browser']['is_opera']) {
1289
+													$data[0] .= '&nbsp;';
1290
+						}
1229 1291
 					}
1230 1292
 				},
1231 1293
 				'block_level' => true,
@@ -1263,11 +1325,13 @@  discard block
 block discarded – undo
1263 1325
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264 1326
 				'validate' => function (&$tag, &$data, $disabled)
1265 1327
 				{
1266
-					if (isset($disabled['url']))
1267
-						$tag['content'] = '$1';
1328
+					if (isset($disabled['url'])) {
1329
+											$tag['content'] = '$1';
1330
+					}
1268 1331
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1269
-					if (empty($scheme))
1270
-						$data[0] = '//' . ltrim($data[0], ':/');
1332
+					if (empty($scheme)) {
1333
+											$data[0] = '//' . ltrim($data[0], ':/');
1334
+					}
1271 1335
 				},
1272 1336
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1273 1337
 			),
@@ -1281,10 +1345,11 @@  discard block
 block discarded – undo
1281 1345
 				{
1282 1346
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1283 1347
 
1284
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1285
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1286
-					else
1287
-						$css = '';
1348
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1349
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1350
+					} else {
1351
+											$css = '';
1352
+					}
1288 1353
 
1289 1354
 					$data = $class . $css;
1290 1355
 				},
@@ -1334,14 +1399,16 @@  discard block
 block discarded – undo
1334 1399
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1335 1400
 					if ($image_proxy_enabled)
1336 1401
 					{
1337
-						if (empty($scheme))
1338
-							$data = 'http://' . ltrim($data, ':/');
1402
+						if (empty($scheme)) {
1403
+													$data = 'http://' . ltrim($data, ':/');
1404
+						}
1339 1405
 
1340
-						if ($scheme != 'https')
1341
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1406
+						if ($scheme != 'https') {
1407
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1408
+						}
1409
+					} elseif (empty($scheme)) {
1410
+											$data = '//' . ltrim($data, ':/');
1342 1411
 					}
1343
-					elseif (empty($scheme))
1344
-						$data = '//' . ltrim($data, ':/');
1345 1412
 				},
1346 1413
 				'disabled_content' => '($1)',
1347 1414
 			),
@@ -1357,14 +1424,16 @@  discard block
 block discarded – undo
1357 1424
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1358 1425
 					if ($image_proxy_enabled)
1359 1426
 					{
1360
-						if (empty($scheme))
1361
-							$data = 'http://' . ltrim($data, ':/');
1427
+						if (empty($scheme)) {
1428
+													$data = 'http://' . ltrim($data, ':/');
1429
+						}
1362 1430
 
1363
-						if ($scheme != 'https')
1364
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1431
+						if ($scheme != 'https') {
1432
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1433
+						}
1434
+					} elseif (empty($scheme)) {
1435
+											$data = '//' . ltrim($data, ':/');
1365 1436
 					}
1366
-					elseif (empty($scheme))
1367
-						$data = '//' . ltrim($data, ':/');
1368 1437
 				},
1369 1438
 				'disabled_content' => '($1)',
1370 1439
 			),
@@ -1376,8 +1445,9 @@  discard block
 block discarded – undo
1376 1445
 				{
1377 1446
 					$data = strtr($data, array('<br>' => ''));
1378 1447
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1379
-					if (empty($scheme))
1380
-						$data = '//' . ltrim($data, ':/');
1448
+					if (empty($scheme)) {
1449
+											$data = '//' . ltrim($data, ':/');
1450
+					}
1381 1451
 				},
1382 1452
 			),
1383 1453
 			array(
@@ -1388,13 +1458,14 @@  discard block
 block discarded – undo
1388 1458
 				'after' => '</a>',
1389 1459
 				'validate' => function (&$tag, &$data, $disabled)
1390 1460
 				{
1391
-					if (substr($data, 0, 1) == '#')
1392
-						$data = '#post_' . substr($data, 1);
1393
-					else
1461
+					if (substr($data, 0, 1) == '#') {
1462
+											$data = '#post_' . substr($data, 1);
1463
+					} else
1394 1464
 					{
1395 1465
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1396
-						if (empty($scheme))
1397
-							$data = '//' . ltrim($data, ':/');
1466
+						if (empty($scheme)) {
1467
+													$data = '//' . ltrim($data, ':/');
1468
+						}
1398 1469
 					}
1399 1470
 				},
1400 1471
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1472,8 +1543,9 @@  discard block
 block discarded – undo
1472 1543
 					{
1473 1544
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1474 1545
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1475
-						if ($add_begin)
1476
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1546
+						if ($add_begin) {
1547
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1548
+						}
1477 1549
 					}
1478 1550
 				},
1479 1551
 				'block_level' => false,
@@ -1604,10 +1676,11 @@  discard block
 block discarded – undo
1604 1676
 				'content' => '$1',
1605 1677
 				'validate' => function (&$tag, &$data, $disabled)
1606 1678
 				{
1607
-					if (is_numeric($data))
1608
-						$data = timeformat($data);
1609
-					else
1610
-						$tag['content'] = '[time]$1[/time]';
1679
+					if (is_numeric($data)) {
1680
+											$data = timeformat($data);
1681
+					} else {
1682
+											$tag['content'] = '[time]$1[/time]';
1683
+					}
1611 1684
 				},
1612 1685
 			),
1613 1686
 			array(
@@ -1634,8 +1707,9 @@  discard block
 block discarded – undo
1634 1707
 				{
1635 1708
 					$data = strtr($data, array('<br>' => ''));
1636 1709
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1637
-					if (empty($scheme))
1638
-						$data = '//' . ltrim($data, ':/');
1710
+					if (empty($scheme)) {
1711
+											$data = '//' . ltrim($data, ':/');
1712
+					}
1639 1713
 				},
1640 1714
 			),
1641 1715
 			array(
@@ -1647,8 +1721,9 @@  discard block
 block discarded – undo
1647 1721
 				'validate' => function (&$tag, &$data, $disabled)
1648 1722
 				{
1649 1723
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1650
-					if (empty($scheme))
1651
-						$data = '//' . ltrim($data, ':/');
1724
+					if (empty($scheme)) {
1725
+											$data = '//' . ltrim($data, ':/');
1726
+					}
1652 1727
 				},
1653 1728
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1654 1729
 				'disabled_after' => ' ($1)',
@@ -1668,8 +1743,9 @@  discard block
 block discarded – undo
1668 1743
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1669 1744
 		if ($message === false)
1670 1745
 		{
1671
-			if (isset($temp_bbc))
1672
-				$bbc_codes = $temp_bbc;
1746
+			if (isset($temp_bbc)) {
1747
+							$bbc_codes = $temp_bbc;
1748
+			}
1673 1749
 			usort($codes, function ($a, $b) {
1674 1750
 				return strcmp($a['tag'], $b['tag']);
1675 1751
 			});
@@ -1689,8 +1765,9 @@  discard block
 block discarded – undo
1689 1765
 		);
1690 1766
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1691 1767
 		{
1692
-			foreach ($itemcodes as $c => $dummy)
1693
-				$bbc_codes[$c] = array();
1768
+			foreach ($itemcodes as $c => $dummy) {
1769
+							$bbc_codes[$c] = array();
1770
+			}
1694 1771
 		}
1695 1772
 
1696 1773
 		// Shhhh!
@@ -1711,12 +1788,14 @@  discard block
 block discarded – undo
1711 1788
 		foreach ($codes as $code)
1712 1789
 		{
1713 1790
 			// Make it easier to process parameters later
1714
-			if (!empty($code['parameters']))
1715
-				ksort($code['parameters'], SORT_STRING);
1791
+			if (!empty($code['parameters'])) {
1792
+							ksort($code['parameters'], SORT_STRING);
1793
+			}
1716 1794
 
1717 1795
 			// If we are not doing every tag only do ones we are interested in.
1718
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1719
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1796
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1797
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1798
+			}
1720 1799
 		}
1721 1800
 		$codes = null;
1722 1801
 	}
@@ -1727,8 +1806,9 @@  discard block
 block discarded – undo
1727 1806
 		// It's likely this will change if the message is modified.
1728 1807
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1729 1808
 
1730
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1731
-			return $temp;
1809
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1810
+					return $temp;
1811
+		}
1732 1812
 
1733 1813
 		$cache_t = microtime();
1734 1814
 	}
@@ -1760,8 +1840,9 @@  discard block
 block discarded – undo
1760 1840
 		$disabled['flash'] = true;
1761 1841
 
1762 1842
 		// @todo Change maybe?
1763
-		if (!isset($_GET['images']))
1764
-			$disabled['img'] = true;
1843
+		if (!isset($_GET['images'])) {
1844
+					$disabled['img'] = true;
1845
+		}
1765 1846
 
1766 1847
 		// @todo Interface/setting to add more?
1767 1848
 	}
@@ -1785,8 +1866,9 @@  discard block
 block discarded – undo
1785 1866
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1786 1867
 
1787 1868
 		// Failsafe.
1788
-		if ($pos === false || $last_pos > $pos)
1789
-			$pos = strlen($message) + 1;
1869
+		if ($pos === false || $last_pos > $pos) {
1870
+					$pos = strlen($message) + 1;
1871
+		}
1790 1872
 
1791 1873
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1792 1874
 		if ($last_pos < $pos - 1)
@@ -1805,8 +1887,9 @@  discard block
 block discarded – undo
1805 1887
 
1806 1888
 				// <br> should be empty.
1807 1889
 				$empty_tags = array('br', 'hr');
1808
-				foreach ($empty_tags as $tag)
1809
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1890
+				foreach ($empty_tags as $tag) {
1891
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1892
+				}
1810 1893
 
1811 1894
 				// b, u, i, s, pre... basic tags.
1812 1895
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1815,8 +1898,9 @@  discard block
 block discarded – undo
1815 1898
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1816 1899
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1817 1900
 
1818
-					if ($diff > 0)
1819
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1901
+					if ($diff > 0) {
1902
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1903
+					}
1820 1904
 				}
1821 1905
 
1822 1906
 				// Do <img ...> - with security... action= -> action-.
@@ -1829,8 +1913,9 @@  discard block
 block discarded – undo
1829 1913
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1830 1914
 
1831 1915
 						// Remove action= from the URL - no funny business, now.
1832
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1833
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1916
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1917
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1918
+						}
1834 1919
 
1835 1920
 						// Check if the image is larger than allowed.
1836 1921
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1851,9 +1936,9 @@  discard block
 block discarded – undo
1851 1936
 
1852 1937
 							// Set the new image tag.
1853 1938
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1939
+						} else {
1940
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1854 1941
 						}
1855
-						else
1856
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1857 1942
 					}
1858 1943
 
1859 1944
 					$data = strtr($data, $replaces);
@@ -1866,16 +1951,18 @@  discard block
 block discarded – undo
1866 1951
 				$no_autolink_area = false;
1867 1952
 				if (!empty($open_tags))
1868 1953
 				{
1869
-					foreach ($open_tags as $open_tag)
1870
-						if (in_array($open_tag['tag'], $no_autolink_tags))
1954
+					foreach ($open_tags as $open_tag) {
1955
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1871 1956
 							$no_autolink_area = true;
1957
+					}
1872 1958
 				}
1873 1959
 
1874 1960
 				// Don't go backwards.
1875 1961
 				// @todo Don't think is the real solution....
1876 1962
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1877
-				if ($pos < $lastAutoPos)
1878
-					$no_autolink_area = true;
1963
+				if ($pos < $lastAutoPos) {
1964
+									$no_autolink_area = true;
1965
+				}
1879 1966
 				$lastAutoPos = $pos;
1880 1967
 
1881 1968
 				if (!$no_autolink_area)
@@ -1984,17 +2071,19 @@  discard block
 block discarded – undo
1984 2071
 							if ($scheme == 'mailto')
1985 2072
 							{
1986 2073
 								$email_address = str_replace('mailto:', '', $url);
1987
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
1988
-									return '[email=' . $email_address . ']' . $url . '[/email]';
1989
-								else
1990
-									return $url;
2074
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2075
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2076
+								} else {
2077
+																	return $url;
2078
+								}
1991 2079
 							}
1992 2080
 
1993 2081
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
1994
-							if (empty($scheme))
1995
-								$fullUrl = '//' . ltrim($url, ':/');
1996
-							else
1997
-								$fullUrl = $url;
2082
+							if (empty($scheme)) {
2083
+															$fullUrl = '//' . ltrim($url, ':/');
2084
+							} else {
2085
+															$fullUrl = $url;
2086
+							}
1998 2087
 
1999 2088
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2000 2089
 						}, $data);
@@ -2043,16 +2132,18 @@  discard block
 block discarded – undo
2043 2132
 		}
2044 2133
 
2045 2134
 		// Are we there yet?  Are we there yet?
2046
-		if ($pos >= strlen($message) - 1)
2047
-			break;
2135
+		if ($pos >= strlen($message) - 1) {
2136
+					break;
2137
+		}
2048 2138
 
2049 2139
 		$tags = strtolower($message[$pos + 1]);
2050 2140
 
2051 2141
 		if ($tags == '/' && !empty($open_tags))
2052 2142
 		{
2053 2143
 			$pos2 = strpos($message, ']', $pos + 1);
2054
-			if ($pos2 == $pos + 2)
2055
-				continue;
2144
+			if ($pos2 == $pos + 2) {
2145
+							continue;
2146
+			}
2056 2147
 
2057 2148
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2058 2149
 
@@ -2062,8 +2153,9 @@  discard block
 block discarded – undo
2062 2153
 			do
2063 2154
 			{
2064 2155
 				$tag = array_pop($open_tags);
2065
-				if (!$tag)
2066
-					break;
2156
+				if (!$tag) {
2157
+									break;
2158
+				}
2067 2159
 
2068 2160
 				if (!empty($tag['block_level']))
2069 2161
 				{
@@ -2077,10 +2169,11 @@  discard block
 block discarded – undo
2077 2169
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2078 2170
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2079 2171
 					{
2080
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2081
-							if ($temp['tag'] == $look_for)
2172
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2173
+													if ($temp['tag'] == $look_for)
2082 2174
 							{
2083 2175
 								$block_level = !empty($temp['block_level']);
2176
+						}
2084 2177
 								break;
2085 2178
 							}
2086 2179
 					}
@@ -2102,15 +2195,15 @@  discard block
 block discarded – undo
2102 2195
 			{
2103 2196
 				$open_tags = $to_close;
2104 2197
 				continue;
2105
-			}
2106
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2198
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2107 2199
 			{
2108 2200
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2109 2201
 				{
2110
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2111
-						if ($temp['tag'] == $look_for)
2202
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2203
+											if ($temp['tag'] == $look_for)
2112 2204
 						{
2113 2205
 							$block_level = !empty($temp['block_level']);
2206
+					}
2114 2207
 							break;
2115 2208
 						}
2116 2209
 				}
@@ -2118,8 +2211,9 @@  discard block
 block discarded – undo
2118 2211
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2119 2212
 				if (!$block_level)
2120 2213
 				{
2121
-					foreach ($to_close as $tag)
2122
-						array_push($open_tags, $tag);
2214
+					foreach ($to_close as $tag) {
2215
+											array_push($open_tags, $tag);
2216
+					}
2123 2217
 					continue;
2124 2218
 				}
2125 2219
 			}
@@ -2132,14 +2226,17 @@  discard block
 block discarded – undo
2132 2226
 
2133 2227
 				// See the comment at the end of the big loop - just eating whitespace ;).
2134 2228
 				$whitespace_regex = '';
2135
-				if (!empty($tag['block_level']))
2136
-					$whitespace_regex .= '(&nbsp;|\s)*<br>';
2229
+				if (!empty($tag['block_level'])) {
2230
+									$whitespace_regex .= '(&nbsp;|\s)*<br>';
2231
+				}
2137 2232
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2138
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2139
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2233
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2234
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2235
+				}
2140 2236
 
2141
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2142
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2237
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2238
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2239
+				}
2143 2240
 			}
2144 2241
 
2145 2242
 			if (!empty($to_close))
@@ -2152,8 +2249,9 @@  discard block
 block discarded – undo
2152 2249
 		}
2153 2250
 
2154 2251
 		// No tags for this character, so just keep going (fastest possible course.)
2155
-		if (!isset($bbc_codes[$tags]))
2156
-			continue;
2252
+		if (!isset($bbc_codes[$tags])) {
2253
+					continue;
2254
+		}
2157 2255
 
2158 2256
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2159 2257
 		$tag = null;
@@ -2162,44 +2260,52 @@  discard block
 block discarded – undo
2162 2260
 			$pt_strlen = strlen($possible['tag']);
2163 2261
 
2164 2262
 			// Not a match?
2165
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2166
-				continue;
2263
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2264
+							continue;
2265
+			}
2167 2266
 
2168 2267
 			$next_c = $message[$pos + 1 + $pt_strlen];
2169 2268
 
2170 2269
 			// A test validation?
2171
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2172
-				continue;
2270
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2271
+							continue;
2272
+			}
2173 2273
 			// Do we want parameters?
2174 2274
 			elseif (!empty($possible['parameters']))
2175 2275
 			{
2176
-				if ($next_c != ' ')
2177
-					continue;
2178
-			}
2179
-			elseif (isset($possible['type']))
2276
+				if ($next_c != ' ') {
2277
+									continue;
2278
+				}
2279
+			} elseif (isset($possible['type']))
2180 2280
 			{
2181 2281
 				// Do we need an equal sign?
2182
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2183
-					continue;
2282
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2283
+									continue;
2284
+				}
2184 2285
 				// Maybe we just want a /...
2185
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2186
-					continue;
2286
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2287
+									continue;
2288
+				}
2187 2289
 				// An immediate ]?
2188
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2189
-					continue;
2290
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2291
+									continue;
2292
+				}
2190 2293
 			}
2191 2294
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2192
-			elseif ($next_c != ']')
2193
-				continue;
2295
+			elseif ($next_c != ']') {
2296
+							continue;
2297
+			}
2194 2298
 
2195 2299
 			// Check allowed tree?
2196
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2197
-				continue;
2198
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2199
-				continue;
2300
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2301
+							continue;
2302
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2303
+							continue;
2304
+			}
2200 2305
 			// If this is in the list of disallowed child tags, don't parse it.
2201
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2202
-				continue;
2306
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2307
+							continue;
2308
+			}
2203 2309
 
2204 2310
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2205 2311
 
@@ -2211,8 +2317,9 @@  discard block
 block discarded – undo
2211 2317
 				foreach ($open_tags as $open_quote)
2212 2318
 				{
2213 2319
 					// Every parent quote this quote has flips the styling
2214
-					if ($open_quote['tag'] == 'quote')
2215
-						$quote_alt = !$quote_alt;
2320
+					if ($open_quote['tag'] == 'quote') {
2321
+											$quote_alt = !$quote_alt;
2322
+					}
2216 2323
 				}
2217 2324
 				// Add a class to the quote to style alternating blockquotes
2218 2325
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2223,8 +2330,9 @@  discard block
 block discarded – undo
2223 2330
 			{
2224 2331
 				// Build a regular expression for each parameter for the current tag.
2225 2332
 				$preg = array();
2226
-				foreach ($possible['parameters'] as $p => $info)
2227
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2333
+				foreach ($possible['parameters'] as $p => $info) {
2334
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2335
+				}
2228 2336
 
2229 2337
 				// Extract the string that potentially holds our parameters.
2230 2338
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2244,24 +2352,27 @@  discard block
 block discarded – undo
2244 2352
 
2245 2353
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2246 2354
 
2247
-					if ($match)
2248
-						$blob_counter = count($blobs) + 1;
2355
+					if ($match) {
2356
+											$blob_counter = count($blobs) + 1;
2357
+					}
2249 2358
 				}
2250 2359
 
2251 2360
 				// Didn't match our parameter list, try the next possible.
2252
-				if (!$match)
2253
-					continue;
2361
+				if (!$match) {
2362
+									continue;
2363
+				}
2254 2364
 
2255 2365
 				$params = array();
2256 2366
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2257 2367
 				{
2258 2368
 					$key = strtok(ltrim($matches[$i]), '=');
2259
-					if (isset($possible['parameters'][$key]['value']))
2260
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2261
-					elseif (isset($possible['parameters'][$key]['validate']))
2262
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2263
-					else
2264
-						$params['{' . $key . '}'] = $matches[$i + 1];
2369
+					if (isset($possible['parameters'][$key]['value'])) {
2370
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2371
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2372
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2373
+					} else {
2374
+											$params['{' . $key . '}'] = $matches[$i + 1];
2375
+					}
2265 2376
 
2266 2377
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2267 2378
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2269,23 +2380,26 @@  discard block
 block discarded – undo
2269 2380
 
2270 2381
 				foreach ($possible['parameters'] as $p => $info)
2271 2382
 				{
2272
-					if (!isset($params['{' . $p . '}']))
2273
-						$params['{' . $p . '}'] = '';
2383
+					if (!isset($params['{' . $p . '}'])) {
2384
+											$params['{' . $p . '}'] = '';
2385
+					}
2274 2386
 				}
2275 2387
 
2276 2388
 				$tag = $possible;
2277 2389
 
2278 2390
 				// Put the parameters into the string.
2279
-				if (isset($tag['before']))
2280
-					$tag['before'] = strtr($tag['before'], $params);
2281
-				if (isset($tag['after']))
2282
-					$tag['after'] = strtr($tag['after'], $params);
2283
-				if (isset($tag['content']))
2284
-					$tag['content'] = strtr($tag['content'], $params);
2391
+				if (isset($tag['before'])) {
2392
+									$tag['before'] = strtr($tag['before'], $params);
2393
+				}
2394
+				if (isset($tag['after'])) {
2395
+									$tag['after'] = strtr($tag['after'], $params);
2396
+				}
2397
+				if (isset($tag['content'])) {
2398
+									$tag['content'] = strtr($tag['content'], $params);
2399
+				}
2285 2400
 
2286 2401
 				$pos1 += strlen($given_param_string);
2287
-			}
2288
-			else
2402
+			} else
2289 2403
 			{
2290 2404
 				$tag = $possible;
2291 2405
 				$params = array();
@@ -2296,8 +2410,9 @@  discard block
 block discarded – undo
2296 2410
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2297 2411
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2298 2412
 		{
2299
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2300
-				continue;
2413
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2414
+							continue;
2415
+			}
2301 2416
 
2302 2417
 			$tag = $itemcodes[$message[$pos + 1]];
2303 2418
 
@@ -2318,9 +2433,9 @@  discard block
 block discarded – undo
2318 2433
 			{
2319 2434
 				array_pop($open_tags);
2320 2435
 				$code = '</li>';
2436
+			} else {
2437
+							$code = '';
2321 2438
 			}
2322
-			else
2323
-				$code = '';
2324 2439
 
2325 2440
 			// Now we open a new tag.
2326 2441
 			$open_tags[] = array(
@@ -2367,12 +2482,14 @@  discard block
 block discarded – undo
2367 2482
 		}
2368 2483
 
2369 2484
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2370
-		if ($tag === null)
2371
-			continue;
2485
+		if ($tag === null) {
2486
+					continue;
2487
+		}
2372 2488
 
2373 2489
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2374
-		if (isset($inside['disallow_children']))
2375
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2490
+		if (isset($inside['disallow_children'])) {
2491
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2492
+		}
2376 2493
 
2377 2494
 		// Is this tag disabled?
2378 2495
 		if (isset($disabled[$tag['tag']]))
@@ -2382,14 +2499,13 @@  discard block
 block discarded – undo
2382 2499
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2383 2500
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2384 2501
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2385
-			}
2386
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2502
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2387 2503
 			{
2388 2504
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2389 2505
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2506
+			} else {
2507
+							$tag['content'] = $tag['disabled_content'];
2390 2508
 			}
2391
-			else
2392
-				$tag['content'] = $tag['disabled_content'];
2393 2509
 		}
2394 2510
 
2395 2511
 		// we use this a lot
@@ -2399,8 +2515,9 @@  discard block
 block discarded – undo
2399 2515
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2400 2516
 		{
2401 2517
 			$n = count($open_tags) - 1;
2402
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2403
-				$n--;
2518
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2519
+							$n--;
2520
+			}
2404 2521
 
2405 2522
 			// Close all the non block level tags so this tag isn't surrounded by them.
2406 2523
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2412,12 +2529,15 @@  discard block
 block discarded – undo
2412 2529
 
2413 2530
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2414 2531
 				$whitespace_regex = '';
2415
-				if (!empty($tag['block_level']))
2416
-					$whitespace_regex .= '(&nbsp;|\s)*<br>';
2417
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2418
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2419
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2420
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2532
+				if (!empty($tag['block_level'])) {
2533
+									$whitespace_regex .= '(&nbsp;|\s)*<br>';
2534
+				}
2535
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2536
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2537
+				}
2538
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2539
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2540
+				}
2421 2541
 
2422 2542
 				array_pop($open_tags);
2423 2543
 			}
@@ -2435,16 +2555,19 @@  discard block
 block discarded – undo
2435 2555
 		elseif ($tag['type'] == 'unparsed_content')
2436 2556
 		{
2437 2557
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2438
-			if ($pos2 === false)
2439
-				continue;
2558
+			if ($pos2 === false) {
2559
+							continue;
2560
+			}
2440 2561
 
2441 2562
 			$data = substr($message, $pos1, $pos2 - $pos1);
2442 2563
 
2443
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2444
-				$data = substr($data, 4);
2564
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2565
+							$data = substr($data, 4);
2566
+			}
2445 2567
 
2446
-			if (isset($tag['validate']))
2447
-				$tag['validate']($tag, $data, $disabled, $params);
2568
+			if (isset($tag['validate'])) {
2569
+							$tag['validate']($tag, $data, $disabled, $params);
2570
+			}
2448 2571
 
2449 2572
 			$code = strtr($tag['content'], array('$1' => $data));
2450 2573
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2460,34 +2583,40 @@  discard block
 block discarded – undo
2460 2583
 			if (isset($tag['quoted']))
2461 2584
 			{
2462 2585
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2463
-				if ($tag['quoted'] != 'optional' && !$quoted)
2464
-					continue;
2586
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2587
+									continue;
2588
+				}
2465 2589
 
2466
-				if ($quoted)
2467
-					$pos1 += 6;
2590
+				if ($quoted) {
2591
+									$pos1 += 6;
2592
+				}
2593
+			} else {
2594
+							$quoted = false;
2468 2595
 			}
2469
-			else
2470
-				$quoted = false;
2471 2596
 
2472 2597
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2473
-			if ($pos2 === false)
2474
-				continue;
2598
+			if ($pos2 === false) {
2599
+							continue;
2600
+			}
2475 2601
 
2476 2602
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2477
-			if ($pos3 === false)
2478
-				continue;
2603
+			if ($pos3 === false) {
2604
+							continue;
2605
+			}
2479 2606
 
2480 2607
 			$data = array(
2481 2608
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2482 2609
 				substr($message, $pos1, $pos2 - $pos1)
2483 2610
 			);
2484 2611
 
2485
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2486
-				$data[0] = substr($data[0], 4);
2612
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2613
+							$data[0] = substr($data[0], 4);
2614
+			}
2487 2615
 
2488 2616
 			// Validation for my parking, please!
2489
-			if (isset($tag['validate']))
2490
-				$tag['validate']($tag, $data, $disabled, $params);
2617
+			if (isset($tag['validate'])) {
2618
+							$tag['validate']($tag, $data, $disabled, $params);
2619
+			}
2491 2620
 
2492 2621
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2493 2622
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2504,23 +2633,27 @@  discard block
 block discarded – undo
2504 2633
 		elseif ($tag['type'] == 'unparsed_commas_content')
2505 2634
 		{
2506 2635
 			$pos2 = strpos($message, ']', $pos1);
2507
-			if ($pos2 === false)
2508
-				continue;
2636
+			if ($pos2 === false) {
2637
+							continue;
2638
+			}
2509 2639
 
2510 2640
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2511
-			if ($pos3 === false)
2512
-				continue;
2641
+			if ($pos3 === false) {
2642
+							continue;
2643
+			}
2513 2644
 
2514 2645
 			// We want $1 to be the content, and the rest to be csv.
2515 2646
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2516 2647
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2517 2648
 
2518
-			if (isset($tag['validate']))
2519
-				$tag['validate']($tag, $data, $disabled, $params);
2649
+			if (isset($tag['validate'])) {
2650
+							$tag['validate']($tag, $data, $disabled, $params);
2651
+			}
2520 2652
 
2521 2653
 			$code = $tag['content'];
2522
-			foreach ($data as $k => $d)
2523
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2654
+			foreach ($data as $k => $d) {
2655
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2656
+			}
2524 2657
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2525 2658
 			$pos += strlen($code) - 1 + 2;
2526 2659
 		}
@@ -2528,24 +2661,28 @@  discard block
 block discarded – undo
2528 2661
 		elseif ($tag['type'] == 'unparsed_commas')
2529 2662
 		{
2530 2663
 			$pos2 = strpos($message, ']', $pos1);
2531
-			if ($pos2 === false)
2532
-				continue;
2664
+			if ($pos2 === false) {
2665
+							continue;
2666
+			}
2533 2667
 
2534 2668
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2535 2669
 
2536
-			if (isset($tag['validate']))
2537
-				$tag['validate']($tag, $data, $disabled, $params);
2670
+			if (isset($tag['validate'])) {
2671
+							$tag['validate']($tag, $data, $disabled, $params);
2672
+			}
2538 2673
 
2539 2674
 			// Fix after, for disabled code mainly.
2540
-			foreach ($data as $k => $d)
2541
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2675
+			foreach ($data as $k => $d) {
2676
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2677
+			}
2542 2678
 
2543 2679
 			$open_tags[] = $tag;
2544 2680
 
2545 2681
 			// Replace them out, $1, $2, $3, $4, etc.
2546 2682
 			$code = $tag['before'];
2547
-			foreach ($data as $k => $d)
2548
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2683
+			foreach ($data as $k => $d) {
2684
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2685
+			}
2549 2686
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2550 2687
 			$pos += strlen($code) - 1 + 2;
2551 2688
 		}
@@ -2556,28 +2693,33 @@  discard block
 block discarded – undo
2556 2693
 			if (isset($tag['quoted']))
2557 2694
 			{
2558 2695
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2559
-				if ($tag['quoted'] != 'optional' && !$quoted)
2560
-					continue;
2696
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2697
+									continue;
2698
+				}
2561 2699
 
2562
-				if ($quoted)
2563
-					$pos1 += 6;
2700
+				if ($quoted) {
2701
+									$pos1 += 6;
2702
+				}
2703
+			} else {
2704
+							$quoted = false;
2564 2705
 			}
2565
-			else
2566
-				$quoted = false;
2567 2706
 
2568 2707
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2569
-			if ($pos2 === false)
2570
-				continue;
2708
+			if ($pos2 === false) {
2709
+							continue;
2710
+			}
2571 2711
 
2572 2712
 			$data = substr($message, $pos1, $pos2 - $pos1);
2573 2713
 
2574 2714
 			// Validation for my parking, please!
2575
-			if (isset($tag['validate']))
2576
-				$tag['validate']($tag, $data, $disabled, $params);
2715
+			if (isset($tag['validate'])) {
2716
+							$tag['validate']($tag, $data, $disabled, $params);
2717
+			}
2577 2718
 
2578 2719
 			// For parsed content, we must recurse to avoid security problems.
2579
-			if ($tag['type'] != 'unparsed_equals')
2580
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2720
+			if ($tag['type'] != 'unparsed_equals') {
2721
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2722
+			}
2581 2723
 
2582 2724
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2583 2725
 
@@ -2589,34 +2731,40 @@  discard block
 block discarded – undo
2589 2731
 		}
2590 2732
 
2591 2733
 		// If this is block level, eat any breaks after it.
2592
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2593
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2734
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2735
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2736
+		}
2594 2737
 
2595 2738
 		// Are we trimming outside this tag?
2596
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2597
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2739
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2740
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2741
+		}
2598 2742
 	}
2599 2743
 
2600 2744
 	// Close any remaining tags.
2601
-	while ($tag = array_pop($open_tags))
2602
-		$message .= "\n" . $tag['after'] . "\n";
2745
+	while ($tag = array_pop($open_tags)) {
2746
+			$message .= "\n" . $tag['after'] . "\n";
2747
+	}
2603 2748
 
2604 2749
 	// Parse the smileys within the parts where it can be done safely.
2605 2750
 	if ($smileys === true)
2606 2751
 	{
2607 2752
 		$message_parts = explode("\n", $message);
2608
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2609
-			parsesmileys($message_parts[$i]);
2753
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2754
+					parsesmileys($message_parts[$i]);
2755
+		}
2610 2756
 
2611 2757
 		$message = implode('', $message_parts);
2612 2758
 	}
2613 2759
 
2614 2760
 	// No smileys, just get rid of the markers.
2615
-	else
2616
-		$message = strtr($message, array("\n" => ''));
2761
+	else {
2762
+			$message = strtr($message, array("\n" => ''));
2763
+	}
2617 2764
 
2618
-	if ($message !== '' && $message[0] === ' ')
2619
-		$message = '&nbsp;' . substr($message, 1);
2765
+	if ($message !== '' && $message[0] === ' ') {
2766
+			$message = '&nbsp;' . substr($message, 1);
2767
+	}
2620 2768
 
2621 2769
 	// Cleanup whitespace.
2622 2770
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2625,15 +2773,16 @@  discard block
 block discarded – undo
2625 2773
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2626 2774
 
2627 2775
 	// Cache the output if it took some time...
2628
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2629
-		cache_put_data($cache_key, $message, 240);
2776
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2777
+			cache_put_data($cache_key, $message, 240);
2778
+	}
2630 2779
 
2631 2780
 	// If this was a force parse revert if needed.
2632 2781
 	if (!empty($parse_tags))
2633 2782
 	{
2634
-		if (empty($temp_bbc))
2635
-			$bbc_codes = array();
2636
-		else
2783
+		if (empty($temp_bbc)) {
2784
+					$bbc_codes = array();
2785
+		} else
2637 2786
 		{
2638 2787
 			$bbc_codes = $temp_bbc;
2639 2788
 			unset($temp_bbc);
@@ -2660,8 +2809,9 @@  discard block
 block discarded – undo
2660 2809
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2661 2810
 
2662 2811
 	// No smiley set at all?!
2663
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2664
-		return;
2812
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2813
+			return;
2814
+	}
2665 2815
 
2666 2816
 	// If smileyPregSearch hasn't been set, do it now.
2667 2817
 	if (empty($smileyPregSearch))
@@ -2672,8 +2822,7 @@  discard block
 block discarded – undo
2672 2822
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2673 2823
 			$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
2674 2824
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2675
-		}
2676
-		else
2825
+		} else
2677 2826
 		{
2678 2827
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2679 2828
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2697,9 +2846,9 @@  discard block
 block discarded – undo
2697 2846
 				$smcFunc['db_free_result']($result);
2698 2847
 
2699 2848
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2849
+			} else {
2850
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2700 2851
 			}
2701
-			else
2702
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2703 2852
 		}
2704 2853
 
2705 2854
 		// The non-breaking-space is a complex thing...
@@ -2776,35 +2925,41 @@  discard block
 block discarded – undo
2776 2925
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2777 2926
 
2778 2927
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2779
-	if (!empty($context['flush_mail']))
2780
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2928
+	if (!empty($context['flush_mail'])) {
2929
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2781 2930
 		AddMailQueue(true);
2931
+	}
2782 2932
 
2783 2933
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2784 2934
 
2785
-	if ($add)
2786
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2935
+	if ($add) {
2936
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2937
+	}
2787 2938
 
2788 2939
 	// Put the session ID in.
2789
-	if (defined('SID') && SID != '')
2790
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2940
+	if (defined('SID') && SID != '') {
2941
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2942
+	}
2791 2943
 	// Keep that debug in their for template debugging!
2792
-	elseif (isset($_GET['debug']))
2793
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2944
+	elseif (isset($_GET['debug'])) {
2945
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2946
+	}
2794 2947
 
2795 2948
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2796 2949
 	{
2797
-		if (defined('SID') && SID != '')
2798
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2950
+		if (defined('SID') && SID != '') {
2951
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2799 2952
 				function ($m) use ($scripturl)
2800 2953
 				{
2801 2954
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2955
+		}
2802 2956
 				}, $setLocation);
2803
-		else
2804
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2957
+		else {
2958
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2805 2959
 				function ($m) use ($scripturl)
2806 2960
 				{
2807 2961
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2962
+		}
2808 2963
 				}, $setLocation);
2809 2964
 	}
2810 2965
 
@@ -2815,8 +2970,9 @@  discard block
 block discarded – undo
2815 2970
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2816 2971
 
2817 2972
 	// Debugging.
2818
-	if (isset($db_show_debug) && $db_show_debug === true)
2819
-		$_SESSION['debug_redirect'] = $db_cache;
2973
+	if (isset($db_show_debug) && $db_show_debug === true) {
2974
+			$_SESSION['debug_redirect'] = $db_cache;
2975
+	}
2820 2976
 
2821 2977
 	obExit(false);
2822 2978
 }
@@ -2835,51 +2991,60 @@  discard block
 block discarded – undo
2835 2991
 
2836 2992
 	// Attempt to prevent a recursive loop.
2837 2993
 	++$level;
2838
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2839
-		exit;
2840
-	if ($from_fatal_error)
2841
-		$has_fatal_error = true;
2994
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
2995
+			exit;
2996
+	}
2997
+	if ($from_fatal_error) {
2998
+			$has_fatal_error = true;
2999
+	}
2842 3000
 
2843 3001
 	// Clear out the stat cache.
2844 3002
 	trackStats();
2845 3003
 
2846 3004
 	// If we have mail to send, send it.
2847
-	if (!empty($context['flush_mail']))
2848
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3005
+	if (!empty($context['flush_mail'])) {
3006
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2849 3007
 		AddMailQueue(true);
3008
+	}
2850 3009
 
2851 3010
 	$do_header = $header === null ? !$header_done : $header;
2852
-	if ($do_footer === null)
2853
-		$do_footer = $do_header;
3011
+	if ($do_footer === null) {
3012
+			$do_footer = $do_header;
3013
+	}
2854 3014
 
2855 3015
 	// Has the template/header been done yet?
2856 3016
 	if ($do_header)
2857 3017
 	{
2858 3018
 		// Was the page title set last minute? Also update the HTML safe one.
2859
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2860
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3019
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3020
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3021
+		}
2861 3022
 
2862 3023
 		// Start up the session URL fixer.
2863 3024
 		ob_start('ob_sessrewrite');
2864 3025
 
2865
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2866
-			$buffers = explode(',', $settings['output_buffers']);
2867
-		elseif (!empty($settings['output_buffers']))
2868
-			$buffers = $settings['output_buffers'];
2869
-		else
2870
-			$buffers = array();
3026
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3027
+					$buffers = explode(',', $settings['output_buffers']);
3028
+		} elseif (!empty($settings['output_buffers'])) {
3029
+					$buffers = $settings['output_buffers'];
3030
+		} else {
3031
+					$buffers = array();
3032
+		}
2871 3033
 
2872
-		if (isset($modSettings['integrate_buffer']))
2873
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3034
+		if (isset($modSettings['integrate_buffer'])) {
3035
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3036
+		}
2874 3037
 
2875
-		if (!empty($buffers))
2876
-			foreach ($buffers as $function)
3038
+		if (!empty($buffers)) {
3039
+					foreach ($buffers as $function)
2877 3040
 			{
2878 3041
 				$call = call_helper($function, true);
3042
+		}
2879 3043
 
2880 3044
 				// Is it valid?
2881
-				if (!empty($call))
2882
-					ob_start($call);
3045
+				if (!empty($call)) {
3046
+									ob_start($call);
3047
+				}
2883 3048
 			}
2884 3049
 
2885 3050
 		// Display the screen in the logical order.
@@ -2891,8 +3056,9 @@  discard block
 block discarded – undo
2891 3056
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2892 3057
 
2893 3058
 		// Anything special to put out?
2894
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2895
-			echo $context['insert_after_template'];
3059
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3060
+					echo $context['insert_after_template'];
3061
+		}
2896 3062
 
2897 3063
 		// Just so we don't get caught in an endless loop of errors from the footer...
2898 3064
 		if (!$footer_done)
@@ -2901,14 +3067,16 @@  discard block
 block discarded – undo
2901 3067
 			template_footer();
2902 3068
 
2903 3069
 			// (since this is just debugging... it's okay that it's after </html>.)
2904
-			if (!isset($_REQUEST['xml']))
2905
-				displayDebug();
3070
+			if (!isset($_REQUEST['xml'])) {
3071
+							displayDebug();
3072
+			}
2906 3073
 		}
2907 3074
 	}
2908 3075
 
2909 3076
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2910
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2911
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3077
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3078
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3079
+	}
2912 3080
 
2913 3081
 	// For session check verification.... don't switch browsers...
2914 3082
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2917,9 +3085,10 @@  discard block
 block discarded – undo
2917 3085
 	call_integration_hook('integrate_exit', array($do_footer));
2918 3086
 
2919 3087
 	// Don't exit if we're coming from index.php; that will pass through normally.
2920
-	if (!$from_index)
2921
-		exit;
2922
-}
3088
+	if (!$from_index) {
3089
+			exit;
3090
+	}
3091
+	}
2923 3092
 
2924 3093
 /**
2925 3094
  * Get the size of a specified image with better error handling.
@@ -2938,8 +3107,9 @@  discard block
 block discarded – undo
2938 3107
 	$url = str_replace(' ', '%20', $url);
2939 3108
 
2940 3109
 	// Can we pull this from the cache... please please?
2941
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2942
-		return $temp;
3110
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3111
+			return $temp;
3112
+	}
2943 3113
 	$t = microtime();
2944 3114
 
2945 3115
 	// Get the host to pester...
@@ -2949,12 +3119,10 @@  discard block
 block discarded – undo
2949 3119
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2950 3120
 	{
2951 3121
 		return false;
2952
-	}
2953
-	elseif (!isset($match[1]))
3122
+	} elseif (!isset($match[1]))
2954 3123
 	{
2955 3124
 		$size = @getimagesize($url);
2956
-	}
2957
-	else
3125
+	} else
2958 3126
 	{
2959 3127
 		// Try to connect to the server... give it half a second.
2960 3128
 		$temp = 0;
@@ -2993,12 +3161,14 @@  discard block
 block discarded – undo
2993 3161
 	}
2994 3162
 
2995 3163
 	// If we didn't get it, we failed.
2996
-	if (!isset($size))
2997
-		$size = false;
3164
+	if (!isset($size)) {
3165
+			$size = false;
3166
+	}
2998 3167
 
2999 3168
 	// If this took a long time, we may never have to do it again, but then again we might...
3000
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3001
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3169
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3170
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3171
+	}
3002 3172
 
3003 3173
 	// Didn't work.
3004 3174
 	return $size;
@@ -3016,8 +3186,9 @@  discard block
 block discarded – undo
3016 3186
 
3017 3187
 	// Under SSI this function can be called more then once.  That can cause some problems.
3018 3188
 	//   So only run the function once unless we are forced to run it again.
3019
-	if ($loaded && !$forceload)
3020
-		return;
3189
+	if ($loaded && !$forceload) {
3190
+			return;
3191
+	}
3021 3192
 
3022 3193
 	$loaded = true;
3023 3194
 
@@ -3029,14 +3200,16 @@  discard block
 block discarded – undo
3029 3200
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3030 3201
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3031 3202
 	{
3032
-		if (trim($context['news_lines'][$i]) == '')
3033
-			continue;
3203
+		if (trim($context['news_lines'][$i]) == '') {
3204
+					continue;
3205
+		}
3034 3206
 
3035 3207
 		// Clean it up for presentation ;).
3036 3208
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3037 3209
 	}
3038
-	if (!empty($context['news_lines']))
3039
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3210
+	if (!empty($context['news_lines'])) {
3211
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3212
+	}
3040 3213
 
3041 3214
 	if (!$user_info['is_guest'])
3042 3215
 	{
@@ -3045,40 +3218,48 @@  discard block
 block discarded – undo
3045 3218
 		$context['user']['alerts'] = &$user_info['alerts'];
3046 3219
 
3047 3220
 		// Personal message popup...
3048
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3049
-			$context['user']['popup_messages'] = true;
3050
-		else
3051
-			$context['user']['popup_messages'] = false;
3221
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3222
+					$context['user']['popup_messages'] = true;
3223
+		} else {
3224
+					$context['user']['popup_messages'] = false;
3225
+		}
3052 3226
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3053 3227
 
3054
-		if (allowedTo('moderate_forum'))
3055
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3228
+		if (allowedTo('moderate_forum')) {
3229
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3230
+		}
3056 3231
 
3057 3232
 		$context['user']['avatar'] = array();
3058 3233
 
3059 3234
 		// Check for gravatar first since we might be forcing them...
3060 3235
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3061 3236
 		{
3062
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3063
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3064
-			else
3065
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3237
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3238
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3239
+			} else {
3240
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3241
+			}
3066 3242
 		}
3067 3243
 		// Uploaded?
3068
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3069
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3244
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3245
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3246
+		}
3070 3247
 		// Full URL?
3071
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3072
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3248
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3249
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3250
+		}
3073 3251
 		// Otherwise we assume it's server stored.
3074
-		elseif ($user_info['avatar']['url'] != '')
3075
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3252
+		elseif ($user_info['avatar']['url'] != '') {
3253
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3254
+		}
3076 3255
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3077
-		else
3078
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3256
+		else {
3257
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3258
+		}
3079 3259
 
3080
-		if (!empty($context['user']['avatar']))
3081
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3260
+		if (!empty($context['user']['avatar'])) {
3261
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3262
+		}
3082 3263
 
3083 3264
 		// Figure out how long they've been logged in.
3084 3265
 		$context['user']['total_time_logged_in'] = array(
@@ -3086,8 +3267,7 @@  discard block
 block discarded – undo
3086 3267
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3087 3268
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3088 3269
 		);
3089
-	}
3090
-	else
3270
+	} else
3091 3271
 	{
3092 3272
 		$context['user']['messages'] = 0;
3093 3273
 		$context['user']['unread_messages'] = 0;
@@ -3095,12 +3275,14 @@  discard block
 block discarded – undo
3095 3275
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3096 3276
 		$context['user']['popup_messages'] = false;
3097 3277
 
3098
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3099
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3278
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3279
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3280
+		}
3100 3281
 
3101 3282
 		// If we've upgraded recently, go easy on the passwords.
3102
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3103
-			$context['disable_login_hashing'] = true;
3283
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3284
+					$context['disable_login_hashing'] = true;
3285
+		}
3104 3286
 	}
3105 3287
 
3106 3288
 	// Setup the main menu items.
@@ -3113,8 +3295,8 @@  discard block
 block discarded – undo
3113 3295
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3114 3296
 
3115 3297
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3116
-	if ($context['show_pm_popup'])
3117
-		addInlineJavaScript('
3298
+	if ($context['show_pm_popup']) {
3299
+			addInlineJavaScript('
3118 3300
 		jQuery(document).ready(function($) {
3119 3301
 			new smc_Popup({
3120 3302
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3122,15 +3304,17 @@  discard block
 block discarded – undo
3122 3304
 				icon_class: \'generic_icons mail_new\'
3123 3305
 			});
3124 3306
 		});');
3307
+	}
3125 3308
 
3126 3309
 	// Add a generic "Are you sure?" confirmation message.
3127 3310
 	addInlineJavaScript('
3128 3311
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3129 3312
 
3130 3313
 	// Now add the capping code for avatars.
3131
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3132
-		addInlineCss('
3314
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3315
+			addInlineCss('
3133 3316
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3317
+	}
3134 3318
 
3135 3319
 	// This looks weird, but it's because BoardIndex.php references the variable.
3136 3320
 	$context['common_stats']['latest_member'] = array(
@@ -3147,11 +3331,13 @@  discard block
 block discarded – undo
3147 3331
 	);
3148 3332
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3149 3333
 
3150
-	if (empty($settings['theme_version']))
3151
-		addJavaScriptVar('smf_scripturl', $scripturl);
3334
+	if (empty($settings['theme_version'])) {
3335
+			addJavaScriptVar('smf_scripturl', $scripturl);
3336
+	}
3152 3337
 
3153
-	if (!isset($context['page_title']))
3154
-		$context['page_title'] = '';
3338
+	if (!isset($context['page_title'])) {
3339
+			$context['page_title'] = '';
3340
+	}
3155 3341
 
3156 3342
 	// Set some specific vars.
3157 3343
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3161,21 +3347,23 @@  discard block
 block discarded – undo
3161 3347
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3162 3348
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3163 3349
 
3164
-	if (!empty($context['meta_keywords']))
3165
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3350
+	if (!empty($context['meta_keywords'])) {
3351
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3352
+	}
3166 3353
 
3167
-	if (!empty($context['canonical_url']))
3168
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3354
+	if (!empty($context['canonical_url'])) {
3355
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3356
+	}
3169 3357
 
3170
-	if (!empty($settings['og_image']))
3171
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3358
+	if (!empty($settings['og_image'])) {
3359
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3360
+	}
3172 3361
 
3173 3362
 	if (!empty($context['meta_description']))
3174 3363
 	{
3175 3364
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3176 3365
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3177
-	}
3178
-	else
3366
+	} else
3179 3367
 	{
3180 3368
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3181 3369
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3200,8 +3388,9 @@  discard block
 block discarded – undo
3200 3388
 	$memory_needed = memoryReturnBytes($needed);
3201 3389
 
3202 3390
 	// should we account for how much is currently being used?
3203
-	if ($in_use)
3204
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3391
+	if ($in_use) {
3392
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3393
+	}
3205 3394
 
3206 3395
 	// if more is needed, request it
3207 3396
 	if ($memory_current < $memory_needed)
@@ -3224,8 +3413,9 @@  discard block
 block discarded – undo
3224 3413
  */
3225 3414
 function memoryReturnBytes($val)
3226 3415
 {
3227
-	if (is_integer($val))
3228
-		return $val;
3416
+	if (is_integer($val)) {
3417
+			return $val;
3418
+	}
3229 3419
 
3230 3420
 	// Separate the number from the designator
3231 3421
 	$val = trim($val);
@@ -3261,10 +3451,11 @@  discard block
 block discarded – undo
3261 3451
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3262 3452
 
3263 3453
 		// Are we debugging the template/html content?
3264
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3265
-			header('Content-Type: application/xhtml+xml');
3266
-		elseif (!isset($_REQUEST['xml']))
3267
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3454
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3455
+					header('Content-Type: application/xhtml+xml');
3456
+		} elseif (!isset($_REQUEST['xml'])) {
3457
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3458
+		}
3268 3459
 	}
3269 3460
 
3270 3461
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3273,8 +3464,9 @@  discard block
 block discarded – undo
3273 3464
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3274 3465
 	{
3275 3466
 		$position = array_search('body', $context['template_layers']);
3276
-		if ($position === false)
3277
-			$position = array_search('main', $context['template_layers']);
3467
+		if ($position === false) {
3468
+					$position = array_search('main', $context['template_layers']);
3469
+		}
3278 3470
 
3279 3471
 		if ($position !== false)
3280 3472
 		{
@@ -3302,23 +3494,25 @@  discard block
 block discarded – undo
3302 3494
 
3303 3495
 			foreach ($securityFiles as $i => $securityFile)
3304 3496
 			{
3305
-				if (!file_exists($boarddir . '/' . $securityFile))
3306
-					unset($securityFiles[$i]);
3497
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3498
+									unset($securityFiles[$i]);
3499
+				}
3307 3500
 			}
3308 3501
 
3309 3502
 			// We are already checking so many files...just few more doesn't make any difference! :P
3310
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3311
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3312
-
3313
-			else
3314
-				$path = $modSettings['attachmentUploadDir'];
3503
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3504
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3505
+			} else {
3506
+							$path = $modSettings['attachmentUploadDir'];
3507
+			}
3315 3508
 
3316 3509
 			secureDirectory($path, true);
3317 3510
 			secureDirectory($cachedir);
3318 3511
 
3319 3512
 			// If agreement is enabled, at least the english version shall exists
3320
-			if ($modSettings['requireAgreement'])
3321
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3513
+			if ($modSettings['requireAgreement']) {
3514
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3515
+			}
3322 3516
 
3323 3517
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3324 3518
 			{
@@ -3333,18 +3527,21 @@  discard block
 block discarded – undo
3333 3527
 					echo '
3334 3528
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3335 3529
 
3336
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3337
-						echo '
3530
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3531
+											echo '
3338 3532
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3533
+					}
3339 3534
 				}
3340 3535
 
3341
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3342
-					echo '
3536
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3537
+									echo '
3343 3538
 				<strong>', $txt['cache_writable'], '</strong><br>';
3539
+				}
3344 3540
 
3345
-				if (!empty($agreement))
3346
-					echo '
3541
+				if (!empty($agreement)) {
3542
+									echo '
3347 3543
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3544
+				}
3348 3545
 
3349 3546
 				echo '
3350 3547
 			</p>
@@ -3359,16 +3556,18 @@  discard block
 block discarded – undo
3359 3556
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3360 3557
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3361 3558
 
3362
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3363
-				echo '
3559
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3560
+							echo '
3364 3561
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3562
+			}
3365 3563
 
3366
-			if (!empty($_SESSION['ban']['expire_time']))
3367
-				echo '
3564
+			if (!empty($_SESSION['ban']['expire_time'])) {
3565
+							echo '
3368 3566
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3369
-			else
3370
-				echo '
3567
+			} else {
3568
+							echo '
3371 3569
 					<div>', $txt['your_ban_expires_never'], '</div>';
3570
+			}
3372 3571
 
3373 3572
 			echo '
3374 3573
 				</div>';
@@ -3384,8 +3583,9 @@  discard block
 block discarded – undo
3384 3583
 	global $forum_copyright, $software_year, $forum_version;
3385 3584
 
3386 3585
 	// Don't display copyright for things like SSI.
3387
-	if (!isset($forum_version) || !isset($software_year))
3388
-		return;
3586
+	if (!isset($forum_version) || !isset($software_year)) {
3587
+			return;
3588
+	}
3389 3589
 
3390 3590
 	// Put in the version...
3391 3591
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3403,9 +3603,10 @@  discard block
 block discarded – undo
3403 3603
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3404 3604
 	$context['load_queries'] = $db_count;
3405 3605
 
3406
-	foreach (array_reverse($context['template_layers']) as $layer)
3407
-		loadSubTemplate($layer . '_below', true);
3408
-}
3606
+	foreach (array_reverse($context['template_layers']) as $layer) {
3607
+			loadSubTemplate($layer . '_below', true);
3608
+	}
3609
+	}
3409 3610
 
3410 3611
 /**
3411 3612
  * Output the Javascript files
@@ -3436,8 +3637,7 @@  discard block
 block discarded – undo
3436 3637
 			{
3437 3638
 				echo '
3438 3639
 		var ', $key, ';';
3439
-			}
3440
-			else
3640
+			} else
3441 3641
 			{
3442 3642
 				echo '
3443 3643
 		var ', $key, ' = ', $value, ';';
@@ -3452,26 +3652,27 @@  discard block
 block discarded – undo
3452 3652
 	foreach ($context['javascript_files'] as $id => $js_file)
3453 3653
 	{
3454 3654
 		// Last minute call! allow theme authors to disable single files.
3455
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3456
-			continue;
3655
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3656
+					continue;
3657
+		}
3457 3658
 
3458 3659
 		// By default all files don't get minimized unless the file explicitly says so!
3459 3660
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3460 3661
 		{
3461
-			if ($do_deferred && !empty($js_file['options']['defer']))
3462
-				$toMinifyDefer[] = $js_file;
3463
-
3464
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3465
-				$toMinify[] = $js_file;
3662
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3663
+							$toMinifyDefer[] = $js_file;
3664
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3665
+							$toMinify[] = $js_file;
3666
+			}
3466 3667
 
3467 3668
 			// Grab a random seed.
3468
-			if (!isset($minSeed))
3469
-				$minSeed = $js_file['options']['seed'];
3470
-		}
3471
-
3472
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3473
-			echo '
3669
+			if (!isset($minSeed)) {
3670
+							$minSeed = $js_file['options']['seed'];
3671
+			}
3672
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3673
+					echo '
3474 3674
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3675
+		}
3475 3676
 	}
3476 3677
 
3477 3678
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3479,14 +3680,14 @@  discard block
 block discarded – undo
3479 3680
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3480 3681
 
3481 3682
 		// Minify process couldn't work, print each individual files.
3482
-		if (!empty($result) && is_array($result))
3483
-			foreach ($result as $minFailedFile)
3683
+		if (!empty($result) && is_array($result)) {
3684
+					foreach ($result as $minFailedFile)
3484 3685
 				echo '
3485 3686
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3486
-
3487
-		else
3488
-			echo '
3687
+		} else {
3688
+					echo '
3489 3689
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3690
+		}
3490 3691
 	}
3491 3692
 
3492 3693
 	// Inline JavaScript - Actually useful some times!
@@ -3497,8 +3698,9 @@  discard block
 block discarded – undo
3497 3698
 			echo '
3498 3699
 <script>';
3499 3700
 
3500
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3501
-				echo $js_code;
3701
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3702
+							echo $js_code;
3703
+			}
3502 3704
 
3503 3705
 			echo '
3504 3706
 </script>';
@@ -3509,8 +3711,9 @@  discard block
 block discarded – undo
3509 3711
 			echo '
3510 3712
 	<script>';
3511 3713
 
3512
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3513
-				echo $js_code;
3714
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3715
+							echo $js_code;
3716
+			}
3514 3717
 
3515 3718
 			echo '
3516 3719
 	</script>';
@@ -3535,8 +3738,9 @@  discard block
 block discarded – undo
3535 3738
 	foreach ($context['css_files'] as $id => $file)
3536 3739
 	{
3537 3740
 		// Last minute call! allow theme authors to disable single files.
3538
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3539
-			continue;
3741
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3742
+					continue;
3743
+		}
3540 3744
 
3541 3745
 		// By default all files don't get minimized unless the file explicitly says so!
3542 3746
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3544,12 +3748,12 @@  discard block
 block discarded – undo
3544 3748
 			$toMinify[] = $file;
3545 3749
 
3546 3750
 			// Grab a random seed.
3547
-			if (!isset($minSeed))
3548
-				$minSeed = $file['options']['seed'];
3751
+			if (!isset($minSeed)) {
3752
+							$minSeed = $file['options']['seed'];
3753
+			}
3754
+		} else {
3755
+					$normal[] = $file['fileUrl'];
3549 3756
 		}
3550
-
3551
-		else
3552
-			$normal[] = $file['fileUrl'];
3553 3757
 	}
3554 3758
 
3555 3759
 	if (!empty($toMinify))
@@ -3557,28 +3761,30 @@  discard block
 block discarded – undo
3557 3761
 		$result = custMinify($toMinify, 'css');
3558 3762
 
3559 3763
 		// Minify process couldn't work, print each individual files.
3560
-		if (!empty($result) && is_array($result))
3561
-			foreach ($result as $minFailedFile)
3764
+		if (!empty($result) && is_array($result)) {
3765
+					foreach ($result as $minFailedFile)
3562 3766
 				echo '
3563 3767
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3564
-
3565
-		else
3566
-			echo '
3768
+		} else {
3769
+					echo '
3567 3770
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3771
+		}
3568 3772
 	}
3569 3773
 
3570 3774
 	// Print the rest after the minified files.
3571
-	if (!empty($normal))
3572
-		foreach ($normal as $nf)
3775
+	if (!empty($normal)) {
3776
+			foreach ($normal as $nf)
3573 3777
 			echo '
3574 3778
 	<link rel="stylesheet" href="', $nf ,'">';
3779
+	}
3575 3780
 
3576 3781
 	if ($db_show_debug === true)
3577 3782
 	{
3578 3783
 		// Try to keep only what's useful.
3579 3784
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3580
-		foreach ($context['css_files'] as $file)
3581
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3785
+		foreach ($context['css_files'] as $file) {
3786
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3787
+		}
3582 3788
 	}
3583 3789
 
3584 3790
 	if (!empty($context['css_header']))
@@ -3586,9 +3792,10 @@  discard block
 block discarded – undo
3586 3792
 		echo '
3587 3793
 	<style>';
3588 3794
 
3589
-		foreach ($context['css_header'] as $css)
3590
-			echo $css .'
3795
+		foreach ($context['css_header'] as $css) {
3796
+					echo $css .'
3591 3797
 	';
3798
+		}
3592 3799
 
3593 3800
 		echo'
3594 3801
 	</style>';
@@ -3612,15 +3819,17 @@  discard block
 block discarded – undo
3612 3819
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3613 3820
 	$data = !empty($data) ? $data : false;
3614 3821
 
3615
-	if (empty($type) || empty($data))
3616
-		return false;
3822
+	if (empty($type) || empty($data)) {
3823
+			return false;
3824
+	}
3617 3825
 
3618 3826
 	// Did we already did this?
3619 3827
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3620 3828
 
3621 3829
 	// Already done?
3622
-	if (!empty($toCache))
3623
-		return true;
3830
+	if (!empty($toCache)) {
3831
+			return true;
3832
+	}
3624 3833
 
3625 3834
 	// No namespaces, sorry!
3626 3835
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3702,8 +3911,9 @@  discard block
 block discarded – undo
3702 3911
 	global $modSettings, $smcFunc;
3703 3912
 
3704 3913
 	// Just make up a nice hash...
3705
-	if ($new)
3706
-		return sha1(md5($filename . time()) . mt_rand());
3914
+	if ($new) {
3915
+			return sha1(md5($filename . time()) . mt_rand());
3916
+	}
3707 3917
 
3708 3918
 	// Just make sure that attachment id is only a int
3709 3919
 	$attachment_id = (int) $attachment_id;
@@ -3720,23 +3930,25 @@  discard block
 block discarded – undo
3720 3930
 				'id_attach' => $attachment_id,
3721 3931
 			));
3722 3932
 
3723
-		if ($smcFunc['db_num_rows']($request) === 0)
3724
-			return false;
3933
+		if ($smcFunc['db_num_rows']($request) === 0) {
3934
+					return false;
3935
+		}
3725 3936
 
3726 3937
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3727 3938
 		$smcFunc['db_free_result']($request);
3728 3939
 	}
3729 3940
 
3730 3941
 	// Still no hash? mmm...
3731
-	if (empty($file_hash))
3732
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3942
+	if (empty($file_hash)) {
3943
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3944
+	}
3733 3945
 
3734 3946
 	// Are we using multiple directories?
3735
-	if (is_array($modSettings['attachmentUploadDir']))
3736
-		$path = $modSettings['attachmentUploadDir'][$dir];
3737
-
3738
-	else
3739
-		$path = $modSettings['attachmentUploadDir'];
3947
+	if (is_array($modSettings['attachmentUploadDir'])) {
3948
+			$path = $modSettings['attachmentUploadDir'][$dir];
3949
+	} else {
3950
+			$path = $modSettings['attachmentUploadDir'];
3951
+	}
3740 3952
 
3741 3953
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3742 3954
 }
@@ -3751,8 +3963,9 @@  discard block
 block discarded – undo
3751 3963
 function ip2range($fullip)
3752 3964
 {
3753 3965
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3754
-	if ($fullip == 'unknown')
3755
-		$fullip = '255.255.255.255';
3966
+	if ($fullip == 'unknown') {
3967
+			$fullip = '255.255.255.255';
3968
+	}
3756 3969
 
3757 3970
 	$ip_parts = explode('-', $fullip);
3758 3971
 	$ip_array = array();
@@ -3776,10 +3989,11 @@  discard block
 block discarded – undo
3776 3989
 		$ip_array['low'] = $ip_parts[0];
3777 3990
 		$ip_array['high'] = $ip_parts[1];
3778 3991
 		return $ip_array;
3779
-	}
3780
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
3992
+	} elseif (count($ip_parts) == 2) {
3993
+		// if ip 22.22.*-22.22.*
3781 3994
 	{
3782 3995
 		$valid_low = isValidIP($ip_parts[0]);
3996
+	}
3783 3997
 		$valid_high = isValidIP($ip_parts[1]);
3784 3998
 		$count = 0;
3785 3999
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3794,7 +4008,9 @@  discard block
 block discarded – undo
3794 4008
 				$ip_parts[0] .= $mode . $min;
3795 4009
 				$valid_low = isValidIP($ip_parts[0]);
3796 4010
 				$count++;
3797
-				if ($count > 9) break;
4011
+				if ($count > 9) {
4012
+					break;
4013
+				}
3798 4014
 			}
3799 4015
 		}
3800 4016
 
@@ -3808,7 +4024,9 @@  discard block
 block discarded – undo
3808 4024
 				$ip_parts[1] .= $mode . $max;
3809 4025
 				$valid_high = isValidIP($ip_parts[1]);
3810 4026
 				$count++;
3811
-				if ($count > 9) break;
4027
+				if ($count > 9) {
4028
+					break;
4029
+				}
3812 4030
 			}
3813 4031
 		}
3814 4032
 
@@ -3833,46 +4051,54 @@  discard block
 block discarded – undo
3833 4051
 {
3834 4052
 	global $modSettings;
3835 4053
 
3836
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3837
-		return $host;
4054
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4055
+			return $host;
4056
+	}
3838 4057
 	$t = microtime();
3839 4058
 
3840 4059
 	// Try the Linux host command, perhaps?
3841 4060
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3842 4061
 	{
3843
-		if (!isset($modSettings['host_to_dis']))
3844
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3845
-		else
3846
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4062
+		if (!isset($modSettings['host_to_dis'])) {
4063
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4064
+		} else {
4065
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4066
+		}
3847 4067
 
3848 4068
 		// Did host say it didn't find anything?
3849
-		if (strpos($test, 'not found') !== false)
3850
-			$host = '';
4069
+		if (strpos($test, 'not found') !== false) {
4070
+					$host = '';
4071
+		}
3851 4072
 		// Invalid server option?
3852
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3853
-			updateSettings(array('host_to_dis' => 1));
4073
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4074
+					updateSettings(array('host_to_dis' => 1));
4075
+		}
3854 4076
 		// Maybe it found something, after all?
3855
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3856
-			$host = $match[1];
4077
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4078
+					$host = $match[1];
4079
+		}
3857 4080
 	}
3858 4081
 
3859 4082
 	// This is nslookup; usually only Windows, but possibly some Unix?
3860 4083
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3861 4084
 	{
3862 4085
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3863
-		if (strpos($test, 'Non-existent domain') !== false)
3864
-			$host = '';
3865
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3866
-			$host = $match[1];
4086
+		if (strpos($test, 'Non-existent domain') !== false) {
4087
+					$host = '';
4088
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4089
+					$host = $match[1];
4090
+		}
3867 4091
 	}
3868 4092
 
3869 4093
 	// This is the last try :/.
3870
-	if (!isset($host) || $host === false)
3871
-		$host = @gethostbyaddr($ip);
4094
+	if (!isset($host) || $host === false) {
4095
+			$host = @gethostbyaddr($ip);
4096
+	}
3872 4097
 
3873 4098
 	// It took a long time, so let's cache it!
3874
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3875
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4099
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4100
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4101
+	}
3876 4102
 
3877 4103
 	return $host;
3878 4104
 }
@@ -3908,20 +4134,21 @@  discard block
 block discarded – undo
3908 4134
 			{
3909 4135
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3910 4136
 				$total = 0;
3911
-				for ($i = 0; $i < $max_chars; $i++)
3912
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4137
+				for ($i = 0; $i < $max_chars; $i++) {
4138
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4139
+				}
3913 4140
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3914 4141
 			}
3915 4142
 		}
3916 4143
 		return array_unique($returned_ints);
3917
-	}
3918
-	else
4144
+	} else
3919 4145
 	{
3920 4146
 		// Trim characters before and after and add slashes for database insertion.
3921 4147
 		$returned_words = array();
3922
-		foreach ($words as $word)
3923
-			if (($word = trim($word, '-_\'')) !== '')
4148
+		foreach ($words as $word) {
4149
+					if (($word = trim($word, '-_\'')) !== '')
3924 4150
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4151
+		}
3925 4152
 
3926 4153
 		// Filter out all words that occur more than once.
3927 4154
 		return array_unique($returned_words);
@@ -3943,16 +4170,18 @@  discard block
 block discarded – undo
3943 4170
 	global $settings, $txt;
3944 4171
 
3945 4172
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3946
-	if (function_exists('template_create_button') && !$force_use)
3947
-		return template_create_button($name, $alt, $label = '', $custom = '');
4173
+	if (function_exists('template_create_button') && !$force_use) {
4174
+			return template_create_button($name, $alt, $label = '', $custom = '');
4175
+	}
3948 4176
 
3949
-	if (!$settings['use_image_buttons'])
3950
-		return $txt[$alt];
3951
-	elseif (!empty($settings['use_buttons']))
3952
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3953
-	else
3954
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3955
-}
4177
+	if (!$settings['use_image_buttons']) {
4178
+			return $txt[$alt];
4179
+	} elseif (!empty($settings['use_buttons'])) {
4180
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4181
+	} else {
4182
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4183
+	}
4184
+	}
3956 4185
 
3957 4186
 /**
3958 4187
  * Sets up all of the top menu buttons
@@ -3995,9 +4224,10 @@  discard block
 block discarded – undo
3995 4224
 	var user_menus = new smc_PopupMenu();
3996 4225
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3997 4226
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3998
-		if ($context['allow_pm'])
3999
-			addInlineJavaScript('
4227
+		if ($context['allow_pm']) {
4228
+					addInlineJavaScript('
4000 4229
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4230
+		}
4001 4231
 
4002 4232
 		if (!empty($modSettings['enable_ajax_alerts']))
4003 4233
 		{
@@ -4157,88 +4387,96 @@  discard block
 block discarded – undo
4157 4387
 
4158 4388
 		// Now we put the buttons in the context so the theme can use them.
4159 4389
 		$menu_buttons = array();
4160
-		foreach ($buttons as $act => $button)
4161
-			if (!empty($button['show']))
4390
+		foreach ($buttons as $act => $button) {
4391
+					if (!empty($button['show']))
4162 4392
 			{
4163 4393
 				$button['active_button'] = false;
4394
+		}
4164 4395
 
4165 4396
 				// This button needs some action.
4166
-				if (isset($button['action_hook']))
4167
-					$needs_action_hook = true;
4397
+				if (isset($button['action_hook'])) {
4398
+									$needs_action_hook = true;
4399
+				}
4168 4400
 
4169 4401
 				// Make sure the last button truly is the last button.
4170 4402
 				if (!empty($button['is_last']))
4171 4403
 				{
4172
-					if (isset($last_button))
4173
-						unset($menu_buttons[$last_button]['is_last']);
4404
+					if (isset($last_button)) {
4405
+											unset($menu_buttons[$last_button]['is_last']);
4406
+					}
4174 4407
 					$last_button = $act;
4175 4408
 				}
4176 4409
 
4177 4410
 				// Go through the sub buttons if there are any.
4178
-				if (!empty($button['sub_buttons']))
4179
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4411
+				if (!empty($button['sub_buttons'])) {
4412
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4180 4413
 					{
4181 4414
 						if (empty($subbutton['show']))
4182 4415
 							unset($button['sub_buttons'][$key]);
4416
+				}
4183 4417
 
4184 4418
 						// 2nd level sub buttons next...
4185 4419
 						if (!empty($subbutton['sub_buttons']))
4186 4420
 						{
4187 4421
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4188 4422
 							{
4189
-								if (empty($sub_button2['show']))
4190
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4423
+								if (empty($sub_button2['show'])) {
4424
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4425
+								}
4191 4426
 							}
4192 4427
 						}
4193 4428
 					}
4194 4429
 
4195 4430
 				// Does this button have its own icon?
4196
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4197
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4198
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4199
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4200
-				elseif (isset($button['icon']))
4201
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4202
-				else
4203
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4431
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4432
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4433
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4434
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4435
+				} elseif (isset($button['icon'])) {
4436
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4437
+				} else {
4438
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4439
+				}
4204 4440
 
4205 4441
 				$menu_buttons[$act] = $button;
4206 4442
 			}
4207 4443
 
4208
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4209
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4444
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4445
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4446
+		}
4210 4447
 	}
4211 4448
 
4212 4449
 	$context['menu_buttons'] = $menu_buttons;
4213 4450
 
4214 4451
 	// Logging out requires the session id in the url.
4215
-	if (isset($context['menu_buttons']['logout']))
4216
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4452
+	if (isset($context['menu_buttons']['logout'])) {
4453
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4454
+	}
4217 4455
 
4218 4456
 	// Figure out which action we are doing so we can set the active tab.
4219 4457
 	// Default to home.
4220 4458
 	$current_action = 'home';
4221 4459
 
4222
-	if (isset($context['menu_buttons'][$context['current_action']]))
4223
-		$current_action = $context['current_action'];
4224
-	elseif ($context['current_action'] == 'search2')
4225
-		$current_action = 'search';
4226
-	elseif ($context['current_action'] == 'theme')
4227
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4228
-	elseif ($context['current_action'] == 'register2')
4229
-		$current_action = 'register';
4230
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4231
-		$current_action = 'login';
4232
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4233
-		$current_action = 'moderate';
4460
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4461
+			$current_action = $context['current_action'];
4462
+	} elseif ($context['current_action'] == 'search2') {
4463
+			$current_action = 'search';
4464
+	} elseif ($context['current_action'] == 'theme') {
4465
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4466
+	} elseif ($context['current_action'] == 'register2') {
4467
+			$current_action = 'register';
4468
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4469
+			$current_action = 'login';
4470
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4471
+			$current_action = 'moderate';
4472
+	}
4234 4473
 
4235 4474
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4236 4475
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4237 4476
 	{
4238 4477
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4239 4478
 		$context[$current_action] = true;
4240
-	}
4241
-	elseif ($context['current_action'] == 'pm')
4479
+	} elseif ($context['current_action'] == 'pm')
4242 4480
 	{
4243 4481
 		$current_action = 'self_pm';
4244 4482
 		$context['self_pm'] = true;
@@ -4281,12 +4519,14 @@  discard block
 block discarded – undo
4281 4519
 	}
4282 4520
 
4283 4521
 	// Not all actions are simple.
4284
-	if (!empty($needs_action_hook))
4285
-		call_integration_hook('integrate_current_action', array(&$current_action));
4522
+	if (!empty($needs_action_hook)) {
4523
+			call_integration_hook('integrate_current_action', array(&$current_action));
4524
+	}
4286 4525
 
4287
-	if (isset($context['menu_buttons'][$current_action]))
4288
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4289
-}
4526
+	if (isset($context['menu_buttons'][$current_action])) {
4527
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4528
+	}
4529
+	}
4290 4530
 
4291 4531
 /**
4292 4532
  * Generate a random seed and ensure it's stored in settings.
@@ -4310,30 +4550,35 @@  discard block
 block discarded – undo
4310 4550
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4311 4551
 	global $context, $txt;
4312 4552
 
4313
-	if ($db_show_debug === true)
4314
-		$context['debug']['hooks'][] = $hook;
4553
+	if ($db_show_debug === true) {
4554
+			$context['debug']['hooks'][] = $hook;
4555
+	}
4315 4556
 
4316 4557
 	// Need to have some control.
4317
-	if (!isset($context['instances']))
4318
-		$context['instances'] = array();
4558
+	if (!isset($context['instances'])) {
4559
+			$context['instances'] = array();
4560
+	}
4319 4561
 
4320 4562
 	$results = array();
4321
-	if (empty($modSettings[$hook]))
4322
-		return $results;
4563
+	if (empty($modSettings[$hook])) {
4564
+			return $results;
4565
+	}
4323 4566
 
4324 4567
 	$functions = explode(',', $modSettings[$hook]);
4325 4568
 	// Loop through each function.
4326 4569
 	foreach ($functions as $function)
4327 4570
 	{
4328 4571
 		// Hook has been marked as "disabled". Skip it!
4329
-		if (strpos($function, '!') !== false)
4330
-			continue;
4572
+		if (strpos($function, '!') !== false) {
4573
+					continue;
4574
+		}
4331 4575
 
4332 4576
 		$call = call_helper($function, true);
4333 4577
 
4334 4578
 		// Is it valid?
4335
-		if (!empty($call))
4336
-			$results[$function] = call_user_func_array($call, $parameters);
4579
+		if (!empty($call)) {
4580
+					$results[$function] = call_user_func_array($call, $parameters);
4581
+		}
4337 4582
 
4338 4583
 		// Whatever it was suppose to call, it failed :(
4339 4584
 		elseif (!empty($function))
@@ -4349,8 +4594,9 @@  discard block
 block discarded – undo
4349 4594
 			}
4350 4595
 
4351 4596
 			// "Assume" the file resides on $boarddir somewhere...
4352
-			else
4353
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4597
+			else {
4598
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4599
+			}
4354 4600
 		}
4355 4601
 	}
4356 4602
 
@@ -4372,12 +4618,14 @@  discard block
 block discarded – undo
4372 4618
 	global $smcFunc, $modSettings;
4373 4619
 
4374 4620
 	// Any objects?
4375
-	if ($object)
4376
-		$function = $function . '#';
4621
+	if ($object) {
4622
+			$function = $function . '#';
4623
+	}
4377 4624
 
4378 4625
 	// Any files  to load?
4379
-	if (!empty($file) && is_string($file))
4380
-		$function = $file . (!empty($function) ? '|' . $function : '');
4626
+	if (!empty($file) && is_string($file)) {
4627
+			$function = $file . (!empty($function) ? '|' . $function : '');
4628
+	}
4381 4629
 
4382 4630
 	// Get the correct string.
4383 4631
 	$integration_call = $function;
@@ -4399,13 +4647,14 @@  discard block
 block discarded – undo
4399 4647
 		if (!empty($current_functions))
4400 4648
 		{
4401 4649
 			$current_functions = explode(',', $current_functions);
4402
-			if (in_array($integration_call, $current_functions))
4403
-				return;
4650
+			if (in_array($integration_call, $current_functions)) {
4651
+							return;
4652
+			}
4404 4653
 
4405 4654
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4655
+		} else {
4656
+					$permanent_functions = array($integration_call);
4406 4657
 		}
4407
-		else
4408
-			$permanent_functions = array($integration_call);
4409 4658
 
4410 4659
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4411 4660
 	}
@@ -4414,8 +4663,9 @@  discard block
 block discarded – undo
4414 4663
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4415 4664
 
4416 4665
 	// Do nothing, if it's already there.
4417
-	if (in_array($integration_call, $functions))
4418
-		return;
4666
+	if (in_array($integration_call, $functions)) {
4667
+			return;
4668
+	}
4419 4669
 
4420 4670
 	$functions[] = $integration_call;
4421 4671
 	$modSettings[$hook] = implode(',', $functions);
@@ -4438,12 +4688,14 @@  discard block
 block discarded – undo
4438 4688
 	global $smcFunc, $modSettings;
4439 4689
 
4440 4690
 	// Any objects?
4441
-	if ($object)
4442
-		$function = $function . '#';
4691
+	if ($object) {
4692
+			$function = $function . '#';
4693
+	}
4443 4694
 
4444 4695
 	// Any files  to load?
4445
-	if (!empty($file) && is_string($file))
4446
-		$function = $file . '|' . $function;
4696
+	if (!empty($file) && is_string($file)) {
4697
+			$function = $file . '|' . $function;
4698
+	}
4447 4699
 
4448 4700
 	// Get the correct string.
4449 4701
 	$integration_call = $function;
@@ -4464,16 +4716,18 @@  discard block
 block discarded – undo
4464 4716
 	{
4465 4717
 		$current_functions = explode(',', $current_functions);
4466 4718
 
4467
-		if (in_array($integration_call, $current_functions))
4468
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4719
+		if (in_array($integration_call, $current_functions)) {
4720
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4721
+		}
4469 4722
 	}
4470 4723
 
4471 4724
 	// Turn the function list into something usable.
4472 4725
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4473 4726
 
4474 4727
 	// You can only remove it if it's available.
4475
-	if (!in_array($integration_call, $functions))
4476
-		return;
4728
+	if (!in_array($integration_call, $functions)) {
4729
+			return;
4730
+	}
4477 4731
 
4478 4732
 	$functions = array_diff($functions, array($integration_call));
4479 4733
 	$modSettings[$hook] = implode(',', $functions);
@@ -4494,17 +4748,20 @@  discard block
 block discarded – undo
4494 4748
 	global $context, $smcFunc, $txt, $db_show_debug;
4495 4749
 
4496 4750
 	// Really?
4497
-	if (empty($string))
4498
-		return false;
4751
+	if (empty($string)) {
4752
+			return false;
4753
+	}
4499 4754
 
4500 4755
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4501 4756
 	// A closure? should be a callable one.
4502
-	if (is_array($string) || $string instanceof Closure)
4503
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4757
+	if (is_array($string) || $string instanceof Closure) {
4758
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4759
+	}
4504 4760
 
4505 4761
 	// No full objects, sorry! pass a method or a property instead!
4506
-	if (is_object($string))
4507
-		return false;
4762
+	if (is_object($string)) {
4763
+			return false;
4764
+	}
4508 4765
 
4509 4766
 	// Stay vitaminized my friends...
4510 4767
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4513,8 +4770,9 @@  discard block
 block discarded – undo
4513 4770
 	$string = load_file($string);
4514 4771
 
4515 4772
 	// Loaded file failed
4516
-	if (empty($string))
4517
-		return false;
4773
+	if (empty($string)) {
4774
+			return false;
4775
+	}
4518 4776
 
4519 4777
 	// Found a method.
4520 4778
 	if (strpos($string, '::') !== false)
@@ -4535,8 +4793,9 @@  discard block
 block discarded – undo
4535 4793
 				// Add another one to the list.
4536 4794
 				if ($db_show_debug === true)
4537 4795
 				{
4538
-					if (!isset($context['debug']['instances']))
4539
-						$context['debug']['instances'] = array();
4796
+					if (!isset($context['debug']['instances'])) {
4797
+											$context['debug']['instances'] = array();
4798
+					}
4540 4799
 
4541 4800
 					$context['debug']['instances'][$class] = $class;
4542 4801
 				}
@@ -4546,13 +4805,15 @@  discard block
 block discarded – undo
4546 4805
 		}
4547 4806
 
4548 4807
 		// Right then. This is a call to a static method.
4549
-		else
4550
-			$func = array($class, $method);
4808
+		else {
4809
+					$func = array($class, $method);
4810
+		}
4551 4811
 	}
4552 4812
 
4553 4813
 	// Nope! just a plain regular function.
4554
-	else
4555
-		$func = $string;
4814
+	else {
4815
+			$func = $string;
4816
+	}
4556 4817
 
4557 4818
 	// Right, we got what we need, time to do some checks.
4558 4819
 	if (!is_callable($func, false, $callable_name))
@@ -4568,17 +4829,18 @@  discard block
 block discarded – undo
4568 4829
 	else
4569 4830
 	{
4570 4831
 		// What are we gonna do about it?
4571
-		if ($return)
4572
-			return $func;
4832
+		if ($return) {
4833
+					return $func;
4834
+		}
4573 4835
 
4574 4836
 		// If this is a plain function, avoid the heat of calling call_user_func().
4575 4837
 		else
4576 4838
 		{
4577
-			if (is_array($func))
4578
-				call_user_func($func);
4579
-
4580
-			else
4581
-				$func();
4839
+			if (is_array($func)) {
4840
+							call_user_func($func);
4841
+			} else {
4842
+							$func();
4843
+			}
4582 4844
 		}
4583 4845
 	}
4584 4846
 }
@@ -4595,31 +4857,34 @@  discard block
 block discarded – undo
4595 4857
 {
4596 4858
 	global $sourcedir, $txt, $boarddir, $settings;
4597 4859
 
4598
-	if (empty($string))
4599
-		return false;
4860
+	if (empty($string)) {
4861
+			return false;
4862
+	}
4600 4863
 
4601 4864
 	if (strpos($string, '|') !== false)
4602 4865
 	{
4603 4866
 		list ($file, $string) = explode('|', $string);
4604 4867
 
4605 4868
 		// Match the wildcards to their regular vars.
4606
-		if (empty($settings['theme_dir']))
4607
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4608
-
4609
-		else
4610
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4869
+		if (empty($settings['theme_dir'])) {
4870
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4871
+		} else {
4872
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4873
+		}
4611 4874
 
4612 4875
 		// Load the file if it can be loaded.
4613
-		if (file_exists($absPath))
4614
-			require_once($absPath);
4876
+		if (file_exists($absPath)) {
4877
+					require_once($absPath);
4878
+		}
4615 4879
 
4616 4880
 		// No? try a fallback to $sourcedir
4617 4881
 		else
4618 4882
 		{
4619 4883
 			$absPath = $sourcedir .'/'. $file;
4620 4884
 
4621
-			if (file_exists($absPath))
4622
-				require_once($absPath);
4885
+			if (file_exists($absPath)) {
4886
+							require_once($absPath);
4887
+			}
4623 4888
 
4624 4889
 			// Sorry, can't do much for you at this point.
4625 4890
 			else
@@ -4646,8 +4911,9 @@  discard block
 block discarded – undo
4646 4911
 	global $user_info, $smcFunc;
4647 4912
 
4648 4913
 	// Make sure we have something to work with.
4649
-	if (empty($topic))
4650
-		return array();
4914
+	if (empty($topic)) {
4915
+			return array();
4916
+	}
4651 4917
 
4652 4918
 
4653 4919
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4670,8 +4936,9 @@  discard block
 block discarded – undo
4670 4936
 				'topic' => $topic,
4671 4937
 			)
4672 4938
 		);
4673
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4674
-			$temp[] = (int) $row['content_id'];
4939
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4940
+					$temp[] = (int) $row['content_id'];
4941
+		}
4675 4942
 
4676 4943
 		cache_put_data($cache_key, $temp, $ttl);
4677 4944
 	}
@@ -4692,8 +4959,9 @@  discard block
 block discarded – undo
4692 4959
 {
4693 4960
 	global $context;
4694 4961
 
4695
-	if (empty($string))
4696
-		return $string;
4962
+	if (empty($string)) {
4963
+			return $string;
4964
+	}
4697 4965
 
4698 4966
 	// UTF-8 occurences of MS special characters
4699 4967
 	$findchars_utf8 = array(
@@ -4734,10 +5002,11 @@  discard block
 block discarded – undo
4734 5002
 		'--',	// &mdash;
4735 5003
 	);
4736 5004
 
4737
-	if ($context['utf8'])
4738
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4739
-	else
4740
-		$string = str_replace($findchars_iso, $replacechars, $string);
5005
+	if ($context['utf8']) {
5006
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5007
+	} else {
5008
+			$string = str_replace($findchars_iso, $replacechars, $string);
5009
+	}
4741 5010
 
4742 5011
 	return $string;
4743 5012
 }
@@ -4756,49 +5025,59 @@  discard block
 block discarded – undo
4756 5025
 {
4757 5026
 	global $context;
4758 5027
 
4759
-	if (!isset($matches[2]))
4760
-		return '';
5028
+	if (!isset($matches[2])) {
5029
+			return '';
5030
+	}
4761 5031
 
4762 5032
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4763 5033
 
4764 5034
 	// remove left to right / right to left overrides
4765
-	if ($num === 0x202D || $num === 0x202E)
4766
-		return '';
5035
+	if ($num === 0x202D || $num === 0x202E) {
5036
+			return '';
5037
+	}
4767 5038
 
4768 5039
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4769
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4770
-		return '&#' . $num . ';';
5040
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5041
+			return '&#' . $num . ';';
5042
+	}
4771 5043
 
4772 5044
 	if (empty($context['utf8']))
4773 5045
 	{
4774 5046
 		// no control characters
4775
-		if ($num < 0x20)
4776
-			return '';
5047
+		if ($num < 0x20) {
5048
+					return '';
5049
+		}
4777 5050
 		// text is text
4778
-		elseif ($num < 0x80)
4779
-			return chr($num);
5051
+		elseif ($num < 0x80) {
5052
+					return chr($num);
5053
+		}
4780 5054
 		// all others get html-ised
4781
-		else
4782
-			return '&#' . $matches[2] . ';';
4783
-	}
4784
-	else
5055
+		else {
5056
+					return '&#' . $matches[2] . ';';
5057
+		}
5058
+	} else
4785 5059
 	{
4786 5060
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4787 5061
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4788
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4789
-			return '';
5062
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5063
+					return '';
5064
+		}
4790 5065
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4791
-		elseif ($num < 0x80)
4792
-			return chr($num);
5066
+		elseif ($num < 0x80) {
5067
+					return chr($num);
5068
+		}
4793 5069
 		// <0x800 (2048)
4794
-		elseif ($num < 0x800)
4795
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5070
+		elseif ($num < 0x800) {
5071
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5072
+		}
4796 5073
 		// < 0x10000 (65536)
4797
-		elseif ($num < 0x10000)
4798
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5074
+		elseif ($num < 0x10000) {
5075
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5076
+		}
4799 5077
 		// <= 0x10FFFF (1114111)
4800
-		else
4801
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5078
+		else {
5079
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5080
+		}
4802 5081
 	}
4803 5082
 }
4804 5083
 
@@ -4814,28 +5093,34 @@  discard block
 block discarded – undo
4814 5093
  */
4815 5094
 function fixchar__callback($matches)
4816 5095
 {
4817
-	if (!isset($matches[1]))
4818
-		return '';
5096
+	if (!isset($matches[1])) {
5097
+			return '';
5098
+	}
4819 5099
 
4820 5100
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4821 5101
 
4822 5102
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4823 5103
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4824
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4825
-		return '';
5104
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5105
+			return '';
5106
+	}
4826 5107
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4827
-	elseif ($num < 0x80)
4828
-		return chr($num);
5108
+	elseif ($num < 0x80) {
5109
+			return chr($num);
5110
+	}
4829 5111
 	// <0x800 (2048)
4830
-	elseif ($num < 0x800)
4831
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5112
+	elseif ($num < 0x800) {
5113
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5114
+	}
4832 5115
 	// < 0x10000 (65536)
4833
-	elseif ($num < 0x10000)
4834
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5116
+	elseif ($num < 0x10000) {
5117
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5118
+	}
4835 5119
 	// <= 0x10FFFF (1114111)
4836
-	else
4837
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4838
-}
5120
+	else {
5121
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5122
+	}
5123
+	}
4839 5124
 
4840 5125
 /**
4841 5126
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4848,17 +5133,19 @@  discard block
 block discarded – undo
4848 5133
  */
4849 5134
 function entity_fix__callback($matches)
4850 5135
 {
4851
-	if (!isset($matches[2]))
4852
-		return '';
5136
+	if (!isset($matches[2])) {
5137
+			return '';
5138
+	}
4853 5139
 
4854 5140
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4855 5141
 
4856 5142
 	// we don't allow control characters, characters out of range, byte markers, etc
4857
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4858
-		return '';
4859
-	else
4860
-		return '&#' . $num . ';';
4861
-}
5143
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5144
+			return '';
5145
+	} else {
5146
+			return '&#' . $num . ';';
5147
+	}
5148
+	}
4862 5149
 
4863 5150
 /**
4864 5151
  * Return a Gravatar URL based on
@@ -4882,18 +5169,23 @@  discard block
 block discarded – undo
4882 5169
 		$ratings = array('G', 'PG', 'R', 'X');
4883 5170
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4884 5171
 		$url_params = array();
4885
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4886
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4887
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4888
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4889
-		if (!empty($modSettings['avatar_max_width_external']))
4890
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4891
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4892
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5172
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5173
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5174
+		}
5175
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5176
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5177
+		}
5178
+		if (!empty($modSettings['avatar_max_width_external'])) {
5179
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5180
+		}
5181
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5182
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4893 5183
 				$size_string = $modSettings['avatar_max_height_external'];
5184
+		}
4894 5185
 
4895
-		if (!empty($size_string))
4896
-			$url_params[] = 's=' . $size_string;
5186
+		if (!empty($size_string)) {
5187
+					$url_params[] = 's=' . $size_string;
5188
+		}
4897 5189
 	}
4898 5190
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4899 5191
 
@@ -4912,22 +5204,26 @@  discard block
 block discarded – undo
4912 5204
 	static $timezones = null, $lastwhen = null;
4913 5205
 
4914 5206
 	// No point doing this over if we already did it once
4915
-	if (!empty($timezones) && $when == $lastwhen)
4916
-		return $timezones;
4917
-	else
4918
-		$lastwhen = $when;
5207
+	if (!empty($timezones) && $when == $lastwhen) {
5208
+			return $timezones;
5209
+	} else {
5210
+			$lastwhen = $when;
5211
+	}
4919 5212
 
4920 5213
 	// Parseable datetime string?
4921
-	if (is_int($timestamp = strtotime($when)))
4922
-		$when = $timestamp;
5214
+	if (is_int($timestamp = strtotime($when))) {
5215
+			$when = $timestamp;
5216
+	}
4923 5217
 
4924 5218
 	// A Unix timestamp?
4925
-	elseif (is_numeric($when))
4926
-		$when = intval($when);
5219
+	elseif (is_numeric($when)) {
5220
+			$when = intval($when);
5221
+	}
4927 5222
 
4928 5223
 	// Invalid value? Just get current Unix timestamp.
4929
-	else
4930
-		$when = time();
5224
+	else {
5225
+			$when = time();
5226
+	}
4931 5227
 
4932 5228
 	// We'll need these too
4933 5229
 	$date_when = date_create('@' . $when);
@@ -4991,8 +5287,9 @@  discard block
 block discarded – undo
4991 5287
 	foreach ($priority_countries as $country)
4992 5288
 	{
4993 5289
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
4994
-		if (!empty($country_tzids))
4995
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5290
+		if (!empty($country_tzids)) {
5291
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5292
+		}
4996 5293
 	}
4997 5294
 
4998 5295
 	// Process the preferred timezones first, then the rest.
@@ -5002,8 +5299,9 @@  discard block
 block discarded – undo
5002 5299
 	foreach ($tzids as $tzid)
5003 5300
 	{
5004 5301
 		// We don't want UTC right now
5005
-		if ($tzid == 'UTC')
5006
-			continue;
5302
+		if ($tzid == 'UTC') {
5303
+					continue;
5304
+		}
5007 5305
 
5008 5306
 		$tz = timezone_open($tzid);
5009 5307
 
@@ -5018,12 +5316,14 @@  discard block
 block discarded – undo
5018 5316
 		$tzgeo = timezone_location_get($tz);
5019 5317
 
5020 5318
 		// Don't overwrite our preferred tzids
5021
-		if (empty($zones[$tzkey]['tzid']))
5022
-			$zones[$tzkey]['tzid'] = $tzid;
5319
+		if (empty($zones[$tzkey]['tzid'])) {
5320
+					$zones[$tzkey]['tzid'] = $tzid;
5321
+		}
5023 5322
 
5024 5323
 		// A time zone from a prioritized country?
5025
-		if (in_array($tzid, $priority_tzids))
5026
-			$priority_zones[$tzkey] = true;
5324
+		if (in_array($tzid, $priority_tzids)) {
5325
+					$priority_zones[$tzkey] = true;
5326
+		}
5027 5327
 
5028 5328
 		// Keep track of the location and offset for this tzid
5029 5329
 		$tzid_parts = explode('/', $tzid);
@@ -5044,15 +5344,17 @@  discard block
 block discarded – undo
5044 5344
 
5045 5345
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5046 5346
 
5047
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5048
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5049
-		else
5050
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5347
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5348
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5349
+		} else {
5350
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5351
+		}
5051 5352
 
5052
-		if (isset($priority_zones[$tzkey]))
5053
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5054
-		else
5055
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5353
+		if (isset($priority_zones[$tzkey])) {
5354
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5355
+		} else {
5356
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5357
+		}
5056 5358
 	}
5057 5359
 
5058 5360
 	$timezones = array_merge(
@@ -5106,9 +5408,9 @@  discard block
 block discarded – undo
5106 5408
 			'Indian/Kerguelen' => 'TFT',
5107 5409
 		);
5108 5410
 
5109
-		if (!empty($missing_tz_abbrs[$tzid]))
5110
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5111
-		else
5411
+		if (!empty($missing_tz_abbrs[$tzid])) {
5412
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5413
+		} else
5112 5414
 		{
5113 5415
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5114 5416
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5136,8 +5438,9 @@  discard block
 block discarded – undo
5136 5438
  */
5137 5439
 function inet_ptod($ip_address)
5138 5440
 {
5139
-	if (!isValidIP($ip_address))
5140
-		return $ip_address;
5441
+	if (!isValidIP($ip_address)) {
5442
+			return $ip_address;
5443
+	}
5141 5444
 
5142 5445
 	$bin = inet_pton($ip_address);
5143 5446
 	return $bin;
@@ -5149,13 +5452,15 @@  discard block
 block discarded – undo
5149 5452
  */
5150 5453
 function inet_dtop($bin)
5151 5454
 {
5152
-	if(empty($bin))
5153
-		return '';
5455
+	if(empty($bin)) {
5456
+			return '';
5457
+	}
5154 5458
 
5155 5459
 	global $db_type;
5156 5460
 
5157
-	if ($db_type == 'postgresql')
5158
-		return $bin;
5461
+	if ($db_type == 'postgresql') {
5462
+			return $bin;
5463
+	}
5159 5464
 
5160 5465
 	$ip_address = inet_ntop($bin);
5161 5466
 
@@ -5180,26 +5485,32 @@  discard block
 block discarded – undo
5180 5485
  */
5181 5486
 function _safe_serialize($value)
5182 5487
 {
5183
-	if(is_null($value))
5184
-		return 'N;';
5488
+	if(is_null($value)) {
5489
+			return 'N;';
5490
+	}
5185 5491
 
5186
-	if(is_bool($value))
5187
-		return 'b:'. (int) $value .';';
5492
+	if(is_bool($value)) {
5493
+			return 'b:'. (int) $value .';';
5494
+	}
5188 5495
 
5189
-	if(is_int($value))
5190
-		return 'i:'. $value .';';
5496
+	if(is_int($value)) {
5497
+			return 'i:'. $value .';';
5498
+	}
5191 5499
 
5192
-	if(is_float($value))
5193
-		return 'd:'. str_replace(',', '.', $value) .';';
5500
+	if(is_float($value)) {
5501
+			return 'd:'. str_replace(',', '.', $value) .';';
5502
+	}
5194 5503
 
5195
-	if(is_string($value))
5196
-		return 's:'. strlen($value) .':"'. $value .'";';
5504
+	if(is_string($value)) {
5505
+			return 's:'. strlen($value) .':"'. $value .'";';
5506
+	}
5197 5507
 
5198 5508
 	if(is_array($value))
5199 5509
 	{
5200 5510
 		$out = '';
5201
-		foreach($value as $k => $v)
5202
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5511
+		foreach($value as $k => $v) {
5512
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5513
+		}
5203 5514
 
5204 5515
 		return 'a:'. count($value) .':{'. $out .'}';
5205 5516
 	}
@@ -5225,8 +5536,9 @@  discard block
 block discarded – undo
5225 5536
 
5226 5537
 	$out = _safe_serialize($value);
5227 5538
 
5228
-	if (isset($mbIntEnc))
5229
-		mb_internal_encoding($mbIntEnc);
5539
+	if (isset($mbIntEnc)) {
5540
+			mb_internal_encoding($mbIntEnc);
5541
+	}
5230 5542
 
5231 5543
 	return $out;
5232 5544
 }
@@ -5243,8 +5555,9 @@  discard block
 block discarded – undo
5243 5555
 function _safe_unserialize($str)
5244 5556
 {
5245 5557
 	// Input  is not a string.
5246
-	if(empty($str) || !is_string($str))
5247
-		return false;
5558
+	if(empty($str) || !is_string($str)) {
5559
+			return false;
5560
+	}
5248 5561
 
5249 5562
 	$stack = array();
5250 5563
 	$expected = array();
@@ -5260,43 +5573,38 @@  discard block
 block discarded – undo
5260 5573
 	while($state != 1)
5261 5574
 	{
5262 5575
 		$type = isset($str[0]) ? $str[0] : '';
5263
-		if($type == '}')
5264
-			$str = substr($str, 1);
5265
-
5266
-		else if($type == 'N' && $str[1] == ';')
5576
+		if($type == '}') {
5577
+					$str = substr($str, 1);
5578
+		} else if($type == 'N' && $str[1] == ';')
5267 5579
 		{
5268 5580
 			$value = null;
5269 5581
 			$str = substr($str, 2);
5270
-		}
5271
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5582
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5272 5583
 		{
5273 5584
 			$value = $matches[1] == '1' ? true : false;
5274 5585
 			$str = substr($str, 4);
5275
-		}
5276
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5586
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5277 5587
 		{
5278 5588
 			$value = (int)$matches[1];
5279 5589
 			$str = $matches[2];
5280
-		}
5281
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5590
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5282 5591
 		{
5283 5592
 			$value = (float)$matches[1];
5284 5593
 			$str = $matches[3];
5285
-		}
5286
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5594
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5287 5595
 		{
5288 5596
 			$value = substr($matches[2], 0, (int)$matches[1]);
5289 5597
 			$str = substr($matches[2], (int)$matches[1] + 2);
5290
-		}
5291
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5598
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5292 5599
 		{
5293 5600
 			$expectedLength = (int)$matches[1];
5294 5601
 			$str = $matches[2];
5295 5602
 		}
5296 5603
 
5297 5604
 		// Object or unknown/malformed type.
5298
-		else
5299
-			return false;
5605
+		else {
5606
+					return false;
5607
+		}
5300 5608
 
5301 5609
 		switch($state)
5302 5610
 		{
@@ -5324,8 +5632,9 @@  discard block
 block discarded – undo
5324 5632
 				if($type == '}')
5325 5633
 				{
5326 5634
 					// Array size is less than expected.
5327
-					if(count($list) < end($expected))
5328
-						return false;
5635
+					if(count($list) < end($expected)) {
5636
+											return false;
5637
+					}
5329 5638
 
5330 5639
 					unset($list);
5331 5640
 					$list = &$stack[count($stack)-1];
@@ -5334,8 +5643,9 @@  discard block
 block discarded – undo
5334 5643
 					// Go to terminal state if we're at the end of the root array.
5335 5644
 					array_pop($expected);
5336 5645
 
5337
-					if(count($expected) == 0)
5338
-						$state = 1;
5646
+					if(count($expected) == 0) {
5647
+											$state = 1;
5648
+					}
5339 5649
 
5340 5650
 					break;
5341 5651
 				}
@@ -5343,8 +5653,9 @@  discard block
 block discarded – undo
5343 5653
 				if($type == 'i' || $type == 's')
5344 5654
 				{
5345 5655
 					// Array size exceeds expected length.
5346
-					if(count($list) >= end($expected))
5347
-						return false;
5656
+					if(count($list) >= end($expected)) {
5657
+											return false;
5658
+					}
5348 5659
 
5349 5660
 					$key = $value;
5350 5661
 					$state = 3;
@@ -5378,8 +5689,9 @@  discard block
 block discarded – undo
5378 5689
 	}
5379 5690
 
5380 5691
 	// Trailing data in input.
5381
-	if(!empty($str))
5382
-		return false;
5692
+	if(!empty($str)) {
5693
+			return false;
5694
+	}
5383 5695
 
5384 5696
 	return $data;
5385 5697
 }
@@ -5402,8 +5714,9 @@  discard block
 block discarded – undo
5402 5714
 
5403 5715
 	$out = _safe_unserialize($str);
5404 5716
 
5405
-	if (isset($mbIntEnc))
5406
-		mb_internal_encoding($mbIntEnc);
5717
+	if (isset($mbIntEnc)) {
5718
+			mb_internal_encoding($mbIntEnc);
5719
+	}
5407 5720
 
5408 5721
 	return $out;
5409 5722
 }
@@ -5418,12 +5731,14 @@  discard block
 block discarded – undo
5418 5731
 function smf_chmod($file, $value = 0)
5419 5732
 {
5420 5733
 	// No file? no checks!
5421
-	if (empty($file))
5422
-		return false;
5734
+	if (empty($file)) {
5735
+			return false;
5736
+	}
5423 5737
 
5424 5738
 	// Already writable?
5425
-	if (is_writable($file))
5426
-		return true;
5739
+	if (is_writable($file)) {
5740
+			return true;
5741
+	}
5427 5742
 
5428 5743
 	// Do we have a file or a dir?
5429 5744
 	$isDir = is_dir($file);
@@ -5439,10 +5754,9 @@  discard block
 block discarded – undo
5439 5754
 		{
5440 5755
 			$isWritable = true;
5441 5756
 			break;
5757
+		} else {
5758
+					@chmod($file, $val);
5442 5759
 		}
5443
-
5444
-		else
5445
-			@chmod($file, $val);
5446 5760
 	}
5447 5761
 
5448 5762
 	return $isWritable;
@@ -5461,8 +5775,9 @@  discard block
 block discarded – undo
5461 5775
 	global $txt;
5462 5776
 
5463 5777
 	// Come on...
5464
-	if (empty($json) || !is_string($json))
5465
-		return array();
5778
+	if (empty($json) || !is_string($json)) {
5779
+			return array();
5780
+	}
5466 5781
 
5467 5782
 	$returnArray = @json_decode($json, $returnAsArray);
5468 5783
 
@@ -5500,11 +5815,11 @@  discard block
 block discarded – undo
5500 5815
 		$jsonDebug = $jsonDebug[0];
5501 5816
 		loadLanguage('Errors');
5502 5817
 
5503
-		if (!empty($jsonDebug))
5504
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5505
-
5506
-		else
5507
-			log_error($txt['json_'. $jsonError], 'critical');
5818
+		if (!empty($jsonDebug)) {
5819
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5820
+		} else {
5821
+					log_error($txt['json_'. $jsonError], 'critical');
5822
+		}
5508 5823
 
5509 5824
 		// Everyone expects an array.
5510 5825
 		return array();
@@ -5534,8 +5849,9 @@  discard block
 block discarded – undo
5534 5849
 	global $db_show_debug, $modSettings;
5535 5850
 
5536 5851
 	// Defensive programming anyone?
5537
-	if (empty($data))
5538
-		return false;
5852
+	if (empty($data)) {
5853
+			return false;
5854
+	}
5539 5855
 
5540 5856
 	// Don't need extra stuff...
5541 5857
 	$db_show_debug = false;
@@ -5543,11 +5859,11 @@  discard block
 block discarded – undo
5543 5859
 	// Kill anything else.
5544 5860
 	ob_end_clean();
5545 5861
 
5546
-	if (!empty($modSettings['CompressedOutput']))
5547
-		@ob_start('ob_gzhandler');
5548
-
5549
-	else
5550
-		ob_start();
5862
+	if (!empty($modSettings['CompressedOutput'])) {
5863
+			@ob_start('ob_gzhandler');
5864
+	} else {
5865
+			ob_start();
5866
+	}
5551 5867
 
5552 5868
 	// Set the header.
5553 5869
 	header($type);
@@ -5579,8 +5895,9 @@  discard block
 block discarded – undo
5579 5895
 	static $done = false;
5580 5896
 
5581 5897
 	// If we don't need to do anything, don't
5582
-	if (!$update && $done)
5583
-		return;
5898
+	if (!$update && $done) {
5899
+			return;
5900
+	}
5584 5901
 
5585 5902
 	// Should we get a new copy of the official list of TLDs?
5586 5903
 	if ($update)
@@ -5601,10 +5918,11 @@  discard block
 block discarded – undo
5601 5918
 		// Clean $tlds and convert it to an array
5602 5919
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5603 5920
 			$line = trim($line);
5604
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5605
-				return false;
5606
-			else
5607
-				return true;
5921
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5922
+							return false;
5923
+			} else {
5924
+							return true;
5925
+			}
5608 5926
 		});
5609 5927
 
5610 5928
 		// Convert Punycode to Unicode
@@ -5658,8 +5976,9 @@  discard block
 block discarded – undo
5658 5976
 						$idx += $digit * $w;
5659 5977
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5660 5978
 
5661
-						if ($digit < $t)
5662
-							break;
5979
+						if ($digit < $t) {
5980
+													break;
5981
+						}
5663 5982
 
5664 5983
 						$w = (int) ($w * ($base - $t));
5665 5984
 					}
@@ -5668,8 +5987,9 @@  discard block
 block discarded – undo
5668 5987
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5669 5988
 					$delta += intval($delta / ($deco_len + 1));
5670 5989
 
5671
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5672
-						$delta = intval($delta / ($base - $tmin));
5990
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
5991
+											$delta = intval($delta / ($base - $tmin));
5992
+					}
5673 5993
 
5674 5994
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5675 5995
 					$is_first = false;
@@ -5678,8 +5998,9 @@  discard block
 block discarded – undo
5678 5998
 
5679 5999
 					if ($deco_len > 0)
5680 6000
 					{
5681
-						for ($i = $deco_len; $i > $idx; $i--)
5682
-							$decoded[$i] = $decoded[($i - 1)];
6001
+						for ($i = $deco_len; $i > $idx; $i--) {
6002
+													$decoded[$i] = $decoded[($i - 1)];
6003
+						}
5683 6004
 					}
5684 6005
 					$decoded[$idx++] = $char;
5685 6006
 				}
@@ -5687,24 +6008,29 @@  discard block
 block discarded – undo
5687 6008
 				foreach ($decoded as $k => $v)
5688 6009
 				{
5689 6010
 					// 7bit are transferred literally
5690
-					if ($v < 128)
5691
-						$output .= chr($v);
6011
+					if ($v < 128) {
6012
+											$output .= chr($v);
6013
+					}
5692 6014
 
5693 6015
 					// 2 bytes
5694
-					elseif ($v < (1 << 11))
5695
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6016
+					elseif ($v < (1 << 11)) {
6017
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6018
+					}
5696 6019
 
5697 6020
 					// 3 bytes
5698
-					elseif ($v < (1 << 16))
5699
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6021
+					elseif ($v < (1 << 16)) {
6022
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6023
+					}
5700 6024
 
5701 6025
 					// 4 bytes
5702
-					elseif ($v < (1 << 21))
5703
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6026
+					elseif ($v < (1 << 21)) {
6027
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6028
+					}
5704 6029
 
5705 6030
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5706
-					else
5707
-						$output .= $safe_char;
6031
+					else {
6032
+											$output .= $safe_char;
6033
+					}
5708 6034
 				}
5709 6035
 
5710 6036
 				$output_parts[] = $output;
@@ -5799,8 +6125,7 @@  discard block
 block discarded – undo
5799 6125
 
5800 6126
 		$strlen = 'mb_strlen';
5801 6127
 		$substr = 'mb_substr';
5802
-	}
5803
-	else
6128
+	} else
5804 6129
 	{
5805 6130
 		$strlen = $smcFunc['strlen'];
5806 6131
 		$substr = $smcFunc['substr'];
@@ -5814,20 +6139,21 @@  discard block
 block discarded – undo
5814 6139
 
5815 6140
 		$first = $substr($string, 0, 1);
5816 6141
 
5817
-		if (empty($index[$first]))
5818
-			$index[$first] = array();
6142
+		if (empty($index[$first])) {
6143
+					$index[$first] = array();
6144
+		}
5819 6145
 
5820 6146
 		if ($strlen($string) > 1)
5821 6147
 		{
5822 6148
 			// Sanity check on recursion
5823
-			if ($depth > 99)
5824
-				$index[$first][$substr($string, 1)] = '';
5825
-
5826
-			else
5827
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6149
+			if ($depth > 99) {
6150
+							$index[$first][$substr($string, 1)] = '';
6151
+			} else {
6152
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6153
+			}
6154
+		} else {
6155
+					$index[$first][''] = '';
5828 6156
 		}
5829
-		else
5830
-			$index[$first][''] = '';
5831 6157
 
5832 6158
 		$depth--;
5833 6159
 		return $index;
@@ -5850,9 +6176,9 @@  discard block
 block discarded – undo
5850 6176
 			$key_regex = preg_quote($key, $delim);
5851 6177
 			$new_key = $key;
5852 6178
 
5853
-			if (empty($value))
5854
-				$sub_regex = '';
5855
-			else
6179
+			if (empty($value)) {
6180
+							$sub_regex = '';
6181
+			} else
5856 6182
 			{
5857 6183
 				$sub_regex = $index_to_regex($value, $delim);
5858 6184
 
@@ -5860,22 +6186,22 @@  discard block
 block discarded – undo
5860 6186
 				{
5861 6187
 					$new_key_array = explode('(?'.'>', $sub_regex);
5862 6188
 					$new_key .= $new_key_array[0];
6189
+				} else {
6190
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5863 6191
 				}
5864
-				else
5865
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5866 6192
 			}
5867 6193
 
5868
-			if ($depth > 1)
5869
-				$regex[$new_key] = $key_regex . $sub_regex;
5870
-			else
6194
+			if ($depth > 1) {
6195
+							$regex[$new_key] = $key_regex . $sub_regex;
6196
+			} else
5871 6197
 			{
5872 6198
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5873 6199
 				{
5874 6200
 					$regex[$new_key] = $key_regex . $sub_regex;
5875 6201
 					unset($index[$key]);
6202
+				} else {
6203
+									break;
5876 6204
 				}
5877
-				else
5878
-					break;
5879 6205
 			}
5880 6206
 		}
5881 6207
 
@@ -5884,10 +6210,11 @@  discard block
 block discarded – undo
5884 6210
 			$l1 = $strlen($k1);
5885 6211
 			$l2 = $strlen($k2);
5886 6212
 
5887
-			if ($l1 == $l2)
5888
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5889
-			else
5890
-				return $l1 > $l2 ? -1 : 1;
6213
+			if ($l1 == $l2) {
6214
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6215
+			} else {
6216
+							return $l1 > $l2 ? -1 : 1;
6217
+			}
5891 6218
 		});
5892 6219
 
5893 6220
 		$depth--;
@@ -5898,15 +6225,18 @@  discard block
 block discarded – undo
5898 6225
 	$index = array();
5899 6226
 	$regexes = array();
5900 6227
 
5901
-	foreach ($strings as $string)
5902
-		$index = $add_string_to_index($string, $index);
6228
+	foreach ($strings as $string) {
6229
+			$index = $add_string_to_index($string, $index);
6230
+	}
5903 6231
 
5904
-	while (!empty($index))
5905
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6232
+	while (!empty($index)) {
6233
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6234
+	}
5906 6235
 
5907 6236
 	// Restore PHP's internal character encoding to whatever it was originally
5908
-	if (!empty($current_encoding))
5909
-		mb_internal_encoding($current_encoding);
6237
+	if (!empty($current_encoding)) {
6238
+			mb_internal_encoding($current_encoding);
6239
+	}
5910 6240
 
5911 6241
 	return $regexes;
5912 6242
 }
Please login to merge, or discard this patch.
Sources/Attachments.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 		// Just send a generic message.
77 77
 		else
78 78
 			$this->setResponse(array(
79
-				'text' => $this->_sa == 'add' ? 'attach_error_title' :   'attached_file_deleted_error',
79
+				'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error',
80 80
 				'type' => 'error',
81 81
 				'data' => false,
82 82
 			));
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 			// Gotta urlencode the filename.
405 405
 			if ($this->_attachResults)
406 406
 				foreach ($this->_attachResults as $k => $v)
407
-					$this->_attachResults[$k]['name'] =  urlencode($this->_attachResults[$k]['name']);
407
+					$this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']);
408 408
 
409 409
 			$this->_response = array(
410 410
 				'files' => $this->_attachResults ? $this->_attachResults : false,
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 			ob_start();
432 432
 
433 433
 		// Set the header.
434
-		header('Content-Type: application/json; charset='. $context['character_set'] .'');
434
+		header('Content-Type: application/json; charset=' . $context['character_set'] . '');
435 435
 
436 436
 		echo json_encode($this->_response ? $this->_response : array());
437 437
 
Please login to merge, or discard this patch.
Braces   +102 added lines, -75 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
 class Attachments
20 21
 {
@@ -70,16 +71,18 @@  discard block
 block discarded – undo
70 71
 
71 72
 		$this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false;
72 73
 
73
-		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions))
74
-			$this->{$this->_sa}();
74
+		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) {
75
+					$this->{$this->_sa}();
76
+		}
75 77
 
76 78
 		// Just send a generic message.
77
-		else
78
-			$this->setResponse(array(
79
+		else {
80
+					$this->setResponse(array(
79 81
 				'text' => $this->_sa == 'add' ? 'attach_error_title' :   'attached_file_deleted_error',
80 82
 				'type' => 'error',
81 83
 				'data' => false,
82 84
 			));
85
+		}
83 86
 
84 87
 		// Back to the future, oh, to the browser!
85 88
 		$this->sendResponse();
@@ -95,12 +98,13 @@  discard block
 block discarded – undo
95 98
 		$attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0;
96 99
 
97 100
 		// Need something to work with.
98
-		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID])))
99
-			return $this->setResponse(array(
101
+		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) {
102
+					return $this->setResponse(array(
100 103
 				'text' => 'attached_file_deleted_error',
101 104
 				'type' => 'error',
102 105
 				'data' => false,
103 106
 			));
107
+		}
104 108
 
105 109
 		// Lets pass some params and see what happens :P
106 110
 		$affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true);
@@ -119,19 +123,21 @@  discard block
 block discarded – undo
119 123
 	public function add()
120 124
 	{
121 125
 		// You gotta be able to post attachments.
122
-		if (!$this->_canPostAttachment)
123
-			return $this->setResponse(array(
126
+		if (!$this->_canPostAttachment) {
127
+					return $this->setResponse(array(
124 128
 				'text' => 'attached_file_cannot',
125 129
 				'type' => 'error',
126 130
 				'data' => false,
127 131
 			));
132
+		}
128 133
 
129 134
 		// Process them at once!
130 135
 		$this->processAttachments();
131 136
 
132 137
 		// The attachments was created and moved the the right folder, time to update the DB.
133
-		if (!empty($_SESSION['temp_attachments']))
134
-			$this->createAtttach();
138
+		if (!empty($_SESSION['temp_attachments'])) {
139
+					$this->createAtttach();
140
+		}
135 141
 
136 142
 		// Set the response.
137 143
 		$this->setResponse();
@@ -144,8 +150,9 @@  discard block
 block discarded – undo
144 150
 	{
145 151
 		global $context, $modSettings, $smcFunc, $user_info, $txt;
146 152
 
147
-		if (!isset($_FILES['attachment']['name']))
148
-			$_FILES['attachment']['tmp_name'] = array();
153
+		if (!isset($_FILES['attachment']['name'])) {
154
+					$_FILES['attachment']['tmp_name'] = array();
155
+		}
149 156
 
150 157
 		// If there are attachments, calculate the total size and how many.
151 158
 		$context['attachments']['total_size'] = 0;
@@ -155,25 +162,30 @@  discard block
 block discarded – undo
155 162
 		if (isset($_REQUEST['msg']))
156 163
 		{
157 164
 			$context['attachments']['quantity'] = count($context['current_attachments']);
158
-			foreach ($context['current_attachments'] as $attachment)
159
-				$context['attachments']['total_size'] += $attachment['size'];
165
+			foreach ($context['current_attachments'] as $attachment) {
166
+							$context['attachments']['total_size'] += $attachment['size'];
167
+			}
160 168
 		}
161 169
 
162 170
 		// A bit of house keeping first.
163
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
164
-			unset($_SESSION['temp_attachments']);
171
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
172
+					unset($_SESSION['temp_attachments']);
173
+		}
165 174
 
166 175
 		// Our infamous SESSION var, we are gonna have soo much fun with it!
167
-		if (!isset($_SESSION['temp_attachments']))
168
-			$_SESSION['temp_attachments'] = array();
176
+		if (!isset($_SESSION['temp_attachments'])) {
177
+					$_SESSION['temp_attachments'] = array();
178
+		}
169 179
 
170 180
 		// Make sure we're uploading to the right place.
171
-		if (!empty($modSettings['automanage_attachments']))
172
-			automanage_attachments_check_directory();
181
+		if (!empty($modSettings['automanage_attachments'])) {
182
+					automanage_attachments_check_directory();
183
+		}
173 184
 
174 185
 		// Is the attachments folder actually there?
175
-		if (!empty($context['dir_creation_error']))
176
-			$this->_generalErrors[] = $context['dir_creation_error'];
186
+		if (!empty($context['dir_creation_error'])) {
187
+					$this->_generalErrors[] = $context['dir_creation_error'];
188
+		}
177 189
 
178 190
 		// The current attach folder ha some issues...
179 191
 		elseif (!is_dir($this->_attchDir))
@@ -198,13 +210,12 @@  discard block
 block discarded – undo
198 210
 			);
199 211
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
200 212
 			$smcFunc['db_free_result']($request);
201
-		}
202
-
203
-		else
204
-			$context['attachments'] = array(
213
+		} else {
214
+					$context['attachments'] = array(
205 215
 				'quantity' => 0,
206 216
 				'total_size' => 0,
207 217
 			);
218
+		}
208 219
 
209 220
 		// Check for other general errors here.
210 221
 
@@ -212,9 +223,10 @@  discard block
 block discarded – undo
212 223
 		if (!empty($this->_generalErrors))
213 224
 		{
214 225
 			// And delete the files 'cos they ain't going nowhere.
215
-			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
216
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
226
+			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
227
+							if (file_exists($_FILES['attachment']['tmp_name'][$n]))
217 228
 					unlink($_FILES['attachment']['tmp_name'][$n]);
229
+			}
218 230
 
219 231
 			$_FILES['attachment']['tmp_name'] = array();
220 232
 
@@ -225,26 +237,29 @@  discard block
 block discarded – undo
225 237
 		// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
226 238
 		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
227 239
 		{
228
-			if ($_FILES['attachment']['name'][$n] == '')
229
-				continue;
240
+			if ($_FILES['attachment']['name'][$n] == '') {
241
+							continue;
242
+			}
230 243
 
231 244
 			// First, let's first check for PHP upload errors.
232 245
 			$errors = array();
233 246
 			if (!empty($_FILES['attachment']['error'][$n]))
234 247
 			{
235
-				if ($_FILES['attachment']['error'][$n] == 2)
236
-					$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
237
-
238
-				else
239
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
248
+				if ($_FILES['attachment']['error'][$n] == 2) {
249
+									$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
250
+				} else {
251
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
252
+				}
240 253
 
241 254
 				// Log this one, because...
242
-				if ($_FILES['attachment']['error'][$n] == 6)
243
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
255
+				if ($_FILES['attachment']['error'][$n] == 6) {
256
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
257
+				}
244 258
 
245 259
 				// Weird, no errors were cached, still fill out a generic one.
246
-				if (empty($errors))
247
-					$errors[] = 'attach_php_error';
260
+				if (empty($errors)) {
261
+									$errors[] = 'attach_php_error';
262
+				}
248 263
 			}
249 264
 
250 265
 			// Try to move and rename the file before doing any more checks on it.
@@ -256,8 +271,9 @@  discard block
 block discarded – undo
256 271
 			{
257 272
 				// The reported MIME type of the attachment might not be reliable.
258 273
 				// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
259
-				if (function_exists('mime_content_type'))
260
-					$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
274
+				if (function_exists('mime_content_type')) {
275
+									$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
276
+				}
261 277
 
262 278
 				$_SESSION['temp_attachments'][$attachID] = array(
263 279
 					'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -269,16 +285,18 @@  discard block
 block discarded – undo
269 285
 				);
270 286
 
271 287
 				// Move the file to the attachments folder with a temp name for now.
272
-				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
273
-					smf_chmod($destName, 0644);
288
+				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
289
+									smf_chmod($destName, 0644);
290
+				}
274 291
 
275 292
 				// This is madness!!
276 293
 				else
277 294
 				{
278 295
 					// File couldn't be moved.
279 296
 					$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
280
-					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
281
-						unlink($_FILES['attachment']['tmp_name'][$n]);
297
+					if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
298
+											unlink($_FILES['attachment']['tmp_name'][$n]);
299
+					}
282 300
 				}
283 301
 			}
284 302
 
@@ -291,13 +309,15 @@  discard block
 block discarded – undo
291 309
 					'errors' => $errors,
292 310
 				);
293 311
 
294
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
295
-					unlink($_FILES['attachment']['tmp_name'][$n]);
312
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
313
+									unlink($_FILES['attachment']['tmp_name'][$n]);
314
+				}
296 315
 			}
297 316
 
298 317
 			// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
299
-			if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
300
-				attachmentChecks($attachID);
318
+			if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
319
+							attachmentChecks($attachID);
320
+			}
301 321
 		}
302 322
 
303 323
 		// Mod authors, finally a hook to hang an alternate attachment upload system upon
@@ -344,14 +364,15 @@  discard block
 block discarded – undo
344 364
 
345 365
 					$_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID'];
346 366
 
347
-					if (!empty($attachmentOptions['thumb']))
348
-						$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
367
+					if (!empty($attachmentOptions['thumb'])) {
368
+											$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
369
+					}
349 370
 
350
-					if ($this->_msg)
351
-						assignAttachments($_SESSION['already_attached'], $this->_msg);
371
+					if ($this->_msg) {
372
+											assignAttachments($_SESSION['already_attached'], $this->_msg);
373
+					}
352 374
 				}
353
-			}
354
-			else
375
+			} else
355 376
 			{
356 377
 				// Sort out the errors for display and delete any associated files.
357 378
 				$log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file');
@@ -363,14 +384,16 @@  discard block
 block discarded – undo
363 384
 					if (!is_array($error))
364 385
 					{
365 386
 						$attachmentOptions['errors'][] = $txt[$error];
366
-						if (in_array($error, $log_these))
367
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
387
+						if (in_array($error, $log_these)) {
388
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
389
+						}
390
+					} else {
391
+											$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
368 392
 					}
369
-					else
370
-						$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
371 393
 				}
372
-				if (file_exists($attachment['tmp_name']))
373
-					unlink($attachment['tmp_name']);
394
+				if (file_exists($attachment['tmp_name'])) {
395
+									unlink($attachment['tmp_name']);
396
+				}
374 397
 			}
375 398
 
376 399
 			// Regardless of errors, pass the results.
@@ -378,8 +401,9 @@  discard block
 block discarded – undo
378 401
 		}
379 402
 
380 403
 		// Temp save this on the db.
381
-		if (!empty($_SESSION['already_attached']))
382
-			$this->_attachSuccess = $_SESSION['already_attached'];
404
+		if (!empty($_SESSION['already_attached'])) {
405
+					$this->_attachSuccess = $_SESSION['already_attached'];
406
+		}
383 407
 
384 408
 		unset($_SESSION['temp_attachments']);
385 409
 	}
@@ -399,14 +423,16 @@  discard block
 block discarded – undo
399 423
 		if ($this->_sa == 'add')
400 424
 		{
401 425
 			// Is there any generic errors? made some sense out of them!
402
-			if ($this->_generalErrors)
403
-				foreach ($this->_generalErrors as $k => $v)
426
+			if ($this->_generalErrors) {
427
+							foreach ($this->_generalErrors as $k => $v)
404 428
 					$this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]);
429
+			}
405 430
 
406 431
 			// Gotta urlencode the filename.
407
-			if ($this->_attachResults)
408
-				foreach ($this->_attachResults as $k => $v)
432
+			if ($this->_attachResults) {
433
+							foreach ($this->_attachResults as $k => $v)
409 434
 					$this->_attachResults[$k]['name'] =  urlencode($this->_attachResults[$k]['name']);
435
+			}
410 436
 
411 437
 			$this->_response = array(
412 438
 				'files' => $this->_attachResults ? $this->_attachResults : false,
@@ -415,9 +441,10 @@  discard block
 block discarded – undo
415 441
 		}
416 442
 
417 443
 		// Rest of us mere mortals gets no special treatment...
418
-		elseif (!empty($data))
419
-			if (!empty($data['text']) && !empty($txt[$data['text']]))
444
+		elseif (!empty($data)) {
445
+					if (!empty($data['text']) && !empty($txt[$data['text']]))
420 446
 				$this->_response['text'] = $txt[$data['text']];
447
+		}
421 448
 	}
422 449
 
423 450
 	protected function sendResponse()
@@ -426,11 +453,11 @@  discard block
 block discarded – undo
426 453
 
427 454
 		ob_end_clean();
428 455
 
429
-		if (!empty($modSettings['CompressedOutput']))
430
-			@ob_start('ob_gzhandler');
431
-
432
-		else
433
-			ob_start();
456
+		if (!empty($modSettings['CompressedOutput'])) {
457
+					@ob_start('ob_gzhandler');
458
+		} else {
459
+					ob_start();
460
+		}
434 461
 
435 462
 		// Set the header.
436 463
 		header('Content-Type: application/json; charset='. $context['character_set'] .'');
Please login to merge, or discard this patch.
Sources/SearchAPI-Custom.php 1 patch
Braces   +48 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Used for the "custom search index" option
@@ -54,8 +55,9 @@  discard block
 block discarded – undo
54 55
 			return;
55 56
 		}
56 57
 
57
-		if (empty($modSettings['search_custom_index_config']))
58
-			return;
58
+		if (empty($modSettings['search_custom_index_config'])) {
59
+					return;
60
+		}
59 61
 
60 62
 		$this->indexSettings = smf_json_decode($modSettings['search_custom_index_config'], true);
61 63
 
@@ -118,21 +120,23 @@  discard block
 block discarded – undo
118 120
 
119 121
 		$subwords = text2words($word, $this->min_word_length, true);
120 122
 
121
-		if (empty($modSettings['search_force_index']))
122
-			$wordsSearch['words'][] = $word;
123
+		if (empty($modSettings['search_force_index'])) {
124
+					$wordsSearch['words'][] = $word;
125
+		}
123 126
 
124 127
 		// Excluded phrases don't benefit from being split into subwords.
125
-		if (count($subwords) > 1 && $isExcluded)
126
-			return;
127
-		else
128
+		if (count($subwords) > 1 && $isExcluded) {
129
+					return;
130
+		} else
128 131
 		{
129 132
 			foreach ($subwords as $subword)
130 133
 			{
131 134
 				if ($smcFunc['strlen']($subword) >= $this->min_word_length && !in_array($subword, $this->bannedWords))
132 135
 				{
133 136
 					$wordsSearch['indexed_words'][] = $subword;
134
-					if ($isExcluded)
135
-						$wordsExclude[] = $subword;
137
+					if ($isExcluded) {
138
+											$wordsExclude[] = $subword;
139
+					}
136 140
 				}
137 141
 			}
138 142
 		}
@@ -153,8 +157,9 @@  discard block
 block discarded – undo
153 157
 		$query_where = array();
154 158
 		$query_params = $search_data['params'];
155 159
 
156
-		if ($query_params['id_search'])
157
-			$query_select['id_search'] = '{int:id_search}';
160
+		if ($query_params['id_search']) {
161
+					$query_select['id_search'] = '{int:id_search}';
162
+		}
158 163
 
159 164
 		$count = 0;
160 165
 		foreach ($words['words'] as $regularWord)
@@ -163,30 +168,37 @@  discard block
 block discarded – undo
163 168
 			$query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
164 169
 		}
165 170
 
166
-		if ($query_params['user_query'])
167
-			$query_where[] = '{raw:user_query}';
168
-		if ($query_params['board_query'])
169
-			$query_where[] = 'm.id_board {raw:board_query}';
171
+		if ($query_params['user_query']) {
172
+					$query_where[] = '{raw:user_query}';
173
+		}
174
+		if ($query_params['board_query']) {
175
+					$query_where[] = 'm.id_board {raw:board_query}';
176
+		}
170 177
 
171
-		if ($query_params['topic'])
172
-			$query_where[] = 'm.id_topic = {int:topic}';
173
-		if ($query_params['min_msg_id'])
174
-			$query_where[] = 'm.id_msg >= {int:min_msg_id}';
175
-		if ($query_params['max_msg_id'])
176
-			$query_where[] = 'm.id_msg <= {int:max_msg_id}';
178
+		if ($query_params['topic']) {
179
+					$query_where[] = 'm.id_topic = {int:topic}';
180
+		}
181
+		if ($query_params['min_msg_id']) {
182
+					$query_where[] = 'm.id_msg >= {int:min_msg_id}';
183
+		}
184
+		if ($query_params['max_msg_id']) {
185
+					$query_where[] = 'm.id_msg <= {int:max_msg_id}';
186
+		}
177 187
 
178 188
 		$count = 0;
179
-		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index']))
180
-			foreach ($query_params['excluded_phrases'] as $phrase)
189
+		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) {
190
+					foreach ($query_params['excluded_phrases'] as $phrase)
181 191
 			{
182 192
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_phrase_' . $count . '}';
193
+		}
183 194
 				$query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]';
184 195
 			}
185 196
 		$count = 0;
186
-		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index']))
187
-			foreach ($query_params['excluded_subject_words'] as $excludedWord)
197
+		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) {
198
+					foreach ($query_params['excluded_subject_words'] as $excludedWord)
188 199
 			{
189 200
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_words_' . $count . '}';
201
+		}
190 202
 				$query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]';
191 203
 			}
192 204
 
@@ -199,8 +211,7 @@  discard block
 block discarded – undo
199 211
 			{
200 212
 				$query_left_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_word = ' . $indexedWord . ' AND lsw' . $numTables . '.id_msg = m.id_msg)';
201 213
 				$query_where[] = '(lsw' . $numTables . '.id_word IS NULL)';
202
-			}
203
-			else
214
+			} else
204 215
 			{
205 216
 				$query_inner_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_msg = ' . ($prev_join === 0 ? 'm' : 'lsw' . $prev_join) . '.id_msg)';
206 217
 				$query_where[] = 'lsw' . $numTables . '.id_word = ' . $indexedWord;
@@ -236,16 +247,18 @@  discard block
 block discarded – undo
236 247
 		$customIndexSettings = smf_json_decode($modSettings['search_custom_index_config'], true);
237 248
 
238 249
 		$inserts = array();
239
-		foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word)
240
-			$inserts[] = array($word, $msgOptions['id']);
250
+		foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) {
251
+					$inserts[] = array($word, $msgOptions['id']);
252
+		}
241 253
 
242
-		if (!empty($inserts))
243
-			$smcFunc['db_insert']('ignore',
254
+		if (!empty($inserts)) {
255
+					$smcFunc['db_insert']('ignore',
244 256
 				'{db_prefix}log_search_words',
245 257
 				array('id_word' => 'int', 'id_msg' => 'int'),
246 258
 				$inserts,
247 259
 				array('id_word', 'id_msg')
248 260
 			);
261
+		}
249 262
 	}
250 263
 
251 264
 	/**
@@ -288,8 +301,9 @@  discard block
 block discarded – undo
288 301
 			if (!empty($inserted_words))
289 302
 			{
290 303
 				$inserts = array();
291
-				foreach ($inserted_words as $word)
292
-					$inserts[] = array($word, $msgOptions['id']);
304
+				foreach ($inserted_words as $word) {
305
+									$inserts[] = array($word, $msgOptions['id']);
306
+				}
293 307
 				$smcFunc['db_insert']('insert',
294 308
 					'{db_prefix}log_search_words',
295 309
 					array('id_word' => 'string', 'id_msg' => 'int'),
Please login to merge, or discard this patch.
Sources/ViewQuery.php 1 patch
Braces   +34 added lines, -26 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
  * Show the database queries for debugging
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 	global $scripturl, $settings, $context, $db_connection, $boarddir, $smcFunc, $txt, $db_show_debug;
31 32
 
32 33
 	// We should have debug mode enabled, as well as something to display!
33
-	if (!isset($db_show_debug) || $db_show_debug !== true || !isset($_SESSION['debug']))
34
-		fatal_lang_error('no_access', false);
34
+	if (!isset($db_show_debug) || $db_show_debug !== true || !isset($_SESSION['debug'])) {
35
+			fatal_lang_error('no_access', false);
36
+	}
35 37
 
36 38
 	// Don't allow except for administrators.
37 39
 	isAllowedTo('admin_forum');
@@ -41,10 +43,11 @@  discard block
 block discarded – undo
41 43
 	{
42 44
 		$_SESSION['view_queries'] = $_SESSION['view_queries'] == 1 ? 0 : 1;
43 45
 
44
-		if (strpos($_SESSION['old_url'], 'action=viewquery') !== false)
45
-			redirectexit();
46
-		else
47
-			redirectexit($_SESSION['old_url']);
46
+		if (strpos($_SESSION['old_url'], 'action=viewquery') !== false) {
47
+					redirectexit();
48
+		} else {
49
+					redirectexit($_SESSION['old_url']);
50
+		}
48 51
 	}
49 52
 
50 53
 	call_integration_hook('integrate_egg_nog');
@@ -83,26 +86,28 @@  discard block
 block discarded – undo
83 86
 		foreach ($query as $line)
84 87
 		{
85 88
 			preg_match('/^(\t*)/', $line, $temp);
86
-			if (strlen($temp[0]) < $min_indent || $min_indent == 0)
87
-				$min_indent = strlen($temp[0]);
89
+			if (strlen($temp[0]) < $min_indent || $min_indent == 0) {
90
+							$min_indent = strlen($temp[0]);
91
+			}
92
+		}
93
+		foreach ($query as $l => $dummy) {
94
+					$query[$l] = substr($dummy, $min_indent);
88 95
 		}
89
-		foreach ($query as $l => $dummy)
90
-			$query[$l] = substr($dummy, $min_indent);
91 96
 		$query_data['q'] = implode("\n", $query);
92 97
 
93 98
 		// Make the filenames look a bit better.
94
-		if (isset($query_data['f']))
95
-			$query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']);
99
+		if (isset($query_data['f'])) {
100
+					$query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']);
101
+		}
96 102
 
97 103
 		$is_select_query = substr(trim($query_data['q']), 0, 6) == 'SELECT';
98
-		if ($is_select_query)
99
-			$select = $query_data['q'];
100
-		elseif (preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+(SELECT .+)$~s', trim($query_data['q']), $matches) != 0)
104
+		if ($is_select_query) {
105
+					$select = $query_data['q'];
106
+		} elseif (preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+(SELECT .+)$~s', trim($query_data['q']), $matches) != 0)
101 107
 		{
102 108
 			$is_select_query = true;
103 109
 			$select = $matches[1];
104
-		}
105
-		elseif (preg_match('~^CREATE TEMPORARY TABLE .+?(SELECT .+)$~s', trim($query_data['q']), $matches) != 0)
110
+		} elseif (preg_match('~^CREATE TEMPORARY TABLE .+?(SELECT .+)$~s', trim($query_data['q']), $matches) != 0)
106 111
 		{
107 112
 			$is_select_query = true;
108 113
 			$select = $matches[1];
@@ -110,10 +115,11 @@  discard block
 block discarded – undo
110 115
 		// Temporary tables created in earlier queries are not explainable.
111 116
 		if ($is_select_query)
112 117
 		{
113
-			foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp)
114
-				if (strpos($select, $tmp) !== false)
118
+			foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
119
+							if (strpos($select, $tmp) !== false)
115 120
 				{
116 121
 					$is_select_query = false;
122
+			}
117 123
 					break;
118 124
 				}
119 125
 		}
@@ -124,13 +130,15 @@  discard block
 block discarded – undo
124 130
 				', nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', $smcFunc['htmlspecialchars']($query_data['q']))), '
125 131
 			</a><br>';
126 132
 
127
-		if (!empty($query_data['f']) && !empty($query_data['l']))
128
-			echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']);
133
+		if (!empty($query_data['f']) && !empty($query_data['l'])) {
134
+					echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']);
135
+		}
129 136
 
130
-		if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at']))
131
-			echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8));
132
-		else
133
-			echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8));
137
+		if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) {
138
+					echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8));
139
+		} else {
140
+					echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8));
141
+		}
134 142
 
135 143
 		echo '
136 144
 		</div>';
Please login to merge, or discard this patch.
Sources/Printpage.php 1 patch
Braces   +30 added lines, -23 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Format a topic to be printer friendly.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $board_info, $smcFunc, $modSettings;
33 34
 
34 35
 	// Redirect to the boardindex if no valid topic id is provided.
35
-	if (empty($topic))
36
-		redirectexit();
36
+	if (empty($topic)) {
37
+			redirectexit();
38
+	}
37 39
 
38 40
 	if (!empty($modSettings['disable_print_topic']))
39 41
 	{
@@ -59,8 +61,9 @@  discard block
 block discarded – undo
59 61
 		)
60 62
 	);
61 63
 	// Redirect to the boardindex if no valid topic id is provided.
62
-	if ($smcFunc['db_num_rows']($request) == 0)
63
-		redirectexit();
64
+	if ($smcFunc['db_num_rows']($request) == 0) {
65
+			redirectexit();
66
+	}
64 67
 	$row = $smcFunc['db_fetch_assoc']($request);
65 68
 	$smcFunc['db_free_result']($request);
66 69
 
@@ -134,20 +137,21 @@  discard block
 block discarded – undo
134 137
 				foreach ($guestinfo as $i => $guestvoted)
135 138
 				{
136 139
 					$guestvoted = explode(',', $guestvoted);
137
-					if ($guestvoted[0] == $row['id_poll'])
138
-						break;
140
+					if ($guestvoted[0] == $row['id_poll']) {
141
+											break;
142
+					}
139 143
 				}
140 144
 				// Has the poll been reset since guest voted?
141 145
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
142 146
 				{
143 147
 					// Remove the poll info from the cookie to allow guest to vote again
144 148
 					unset($guestinfo[$i]);
145
-					if (!empty($guestinfo))
146
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
147
-					else
148
-						unset($_COOKIE['guest_poll_vote']);
149
-				}
150
-				else
149
+					if (!empty($guestinfo)) {
150
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
151
+					} else {
152
+											unset($_COOKIE['guest_poll_vote']);
153
+					}
154
+				} else
151 155
 				{
152 156
 					// What did they vote for?
153 157
 					unset($guestvoted[0], $guestvoted[1]);
@@ -233,8 +237,9 @@  discard block
 block discarded – undo
233 237
 	$context['poster_name'] = $row['poster_name'];
234 238
 	$context['post_time'] = timeformat($row['poster_time'], false);
235 239
 	$context['parent_boards'] = array();
236
-	foreach ($board_info['parent_boards'] as $parent)
237
-		$context['parent_boards'][] = $parent['name'];
240
+	foreach ($board_info['parent_boards'] as $parent) {
241
+			$context['parent_boards'][] = $parent['name'];
242
+	}
238 243
 
239 244
 	// Split the topics up so we can print them.
240 245
 	$request = $smcFunc['db_query']('', '
@@ -266,8 +271,9 @@  discard block
 block discarded – undo
266 271
 			'id_msg' => $row['id_msg'],
267 272
 		);
268 273
 
269
-		if (!isset($context['topic_subject']))
270
-			$context['topic_subject'] = $row['subject'];
274
+		if (!isset($context['topic_subject'])) {
275
+					$context['topic_subject'] = $row['subject'];
276
+		}
271 277
 	}
272 278
 	$smcFunc['db_free_result']($request);
273 279
 
@@ -275,8 +281,9 @@  discard block
 block discarded – undo
275 281
 	if (isset($_REQUEST['images']) && !empty($modSettings['attachmentEnable']) && allowedTo('view_attachments'))
276 282
 	{
277 283
 		$messages = array();
278
-		foreach ($context['posts'] as $temp)
279
-			$messages[] = $temp['id_msg'];
284
+		foreach ($context['posts'] as $temp) {
285
+					$messages[] = $temp['id_msg'];
286
+		}
280 287
 
281 288
 		// build the request
282 289
 		$request = $smcFunc['db_query']('', '
@@ -295,8 +302,9 @@  discard block
 block discarded – undo
295 302
 		while ($row = $smcFunc['db_fetch_assoc']($request))
296 303
 		{
297 304
 			$temp[$row['id_attach']] = $row;
298
-			if (!isset($context['printattach'][$row['id_msg']]))
299
-				$context['printattach'][$row['id_msg']] = array();
305
+			if (!isset($context['printattach'][$row['id_msg']])) {
306
+							$context['printattach'][$row['id_msg']] = array();
307
+			}
300 308
 		}
301 309
 		$smcFunc['db_free_result']($request);
302 310
 		ksort($temp);
@@ -313,8 +321,7 @@  discard block
 block discarded – undo
313 321
 						$row['height'] = floor($row['height'] * ($modSettings['max_image_width'] / $row['width']));
314 322
 						$row['width'] = $modSettings['max_image_width'];
315 323
 					}
316
-				}
317
-				elseif (!empty($modSettings['max_image_width']))
324
+				} elseif (!empty($modSettings['max_image_width']))
318 325
 				{
319 326
 					if ($row['height'] > $modSettings['max_image_height'])
320 327
 					{
Please login to merge, or discard this patch.
Sources/CacheAPI-memcache.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
 			$server = trim($servers[array_rand($servers)]);
62 62
 
63 63
 			// Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0.
64
-			if (strpos($server,'/') !== false)
64
+			if (strpos($server, '/') !== false)
65 65
 				$host = $server;
66 66
 			else
67 67
 			{
Please login to merge, or discard this patch.
Braces   +19 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * Our Cache API class
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 
35 36
 		$supported = class_exists('memcache');
36 37
 
37
-		if ($test)
38
-			return $supported;
38
+		if ($test) {
39
+					return $supported;
40
+		}
39 41
 		return parent::isSupported() && $supported && !empty($cache_memcached);
40 42
 	}
41 43
 
@@ -61,9 +63,9 @@  discard block
 block discarded – undo
61 63
 			$server = trim($servers[array_rand($servers)]);
62 64
 
63 65
 			// Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0.
64
-			if (strpos($server,'/') !== false)
65
-				$host = $server;
66
-			else
66
+			if (strpos($server,'/') !== false) {
67
+							$host = $server;
68
+			} else
67 69
 			{
68 70
 				$server = explode(':', $server);
69 71
 				$host = $server[0];
@@ -71,10 +73,11 @@  discard block
 block discarded – undo
71 73
 			}
72 74
 
73 75
 			// Don't wait too long: yes, we want the server, but we might be able to run the query faster!
74
-			if (empty($db_persist))
75
-				$connected = $this->memcache->connect($host, $port);
76
-			else
77
-				$connected = $this->memcache->pconnect($host, $port);
76
+			if (empty($db_persist)) {
77
+							$connected = $this->memcache->connect($host, $port);
78
+			} else {
79
+							$connected = $this->memcache->pconnect($host, $port);
80
+			}
78 81
 		}
79 82
 
80 83
 		return $connected;
@@ -90,8 +93,9 @@  discard block
 block discarded – undo
90 93
 		$value = $this->memcache->get($key);
91 94
 
92 95
 		// $value should return either data or false (from failure, key not found or empty array).
93
-		if ($value === false)
94
-			return null;
96
+		if ($value === false) {
97
+					return null;
98
+		}
95 99
 		return $value;
96 100
 	}
97 101
 
@@ -132,8 +136,9 @@  discard block
 block discarded – undo
132 136
 		$config_vars[] = $txt['cache_memcache_settings'];
133 137
 		$config_vars[] = array('cache_memcached', $txt['cache_memcache_servers'], 'file', 'text', 0, 'cache_memcached', 'postinput' => '<br /><div class="smalltext"><em>' . $txt['cache_memcache_servers_subtext'] . '</em></div>');
134 138
 
135
-		if (!isset($context['settings_post_javascript']))
136
-			$context['settings_post_javascript'] = '';
139
+		if (!isset($context['settings_post_javascript'])) {
140
+					$context['settings_post_javascript'] = '';
141
+		}
137 142
 
138 143
 		$context['settings_post_javascript'] .= '
139 144
 			$("#cache_accelerator").change(function (e) {
Please login to merge, or discard this patch.
Sources/Topic.php 1 patch
Braces   +31 added lines, -21 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Locks a topic... either by way of a moderator or the topic starter.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $topic, $user_info, $sourcedir, $board, $smcFunc;
33 34
 
34 35
 	// Just quit if there's no topic to lock.
35
-	if (empty($topic))
36
-		fatal_lang_error('not_a_topic', false);
36
+	if (empty($topic)) {
37
+			fatal_lang_error('not_a_topic', false);
38
+	}
37 39
 
38 40
 	checkSession('get');
39 41
 
@@ -55,23 +57,28 @@  discard block
 block discarded – undo
55 57
 
56 58
 	// Can you lock topics here, mister?
57 59
 	$user_lock = !allowedTo('lock_any');
58
-	if ($user_lock && $starter == $user_info['id'])
59
-		isAllowedTo('lock_own');
60
-	else
61
-		isAllowedTo('lock_any');
60
+	if ($user_lock && $starter == $user_info['id']) {
61
+			isAllowedTo('lock_own');
62
+	} else {
63
+			isAllowedTo('lock_any');
64
+	}
62 65
 
63 66
 	// Locking with high privileges.
64
-	if ($locked == '0' && !$user_lock)
65
-		$locked = '1';
67
+	if ($locked == '0' && !$user_lock) {
68
+			$locked = '1';
69
+	}
66 70
 	// Locking with low privileges.
67
-	elseif ($locked == '0')
68
-		$locked = '2';
71
+	elseif ($locked == '0') {
72
+			$locked = '2';
73
+	}
69 74
 	// Unlocking - make sure you don't unlock what you can't.
70
-	elseif ($locked == '2' || ($locked == '1' && !$user_lock))
71
-		$locked = '0';
75
+	elseif ($locked == '2' || ($locked == '1' && !$user_lock)) {
76
+			$locked = '0';
77
+	}
72 78
 	// You cannot unlock this!
73
-	else
74
-		fatal_lang_error('locked_by_admin', 'user');
79
+	else {
80
+			fatal_lang_error('locked_by_admin', 'user');
81
+	}
75 82
 
76 83
 	// Actually lock the topic in the database with the new value.
77 84
 	$smcFunc['db_query']('', '
@@ -85,8 +92,9 @@  discard block
 block discarded – undo
85 92
 	);
86 93
 
87 94
 	// If they are allowed a "moderator" permission, log it in the moderator log.
88
-	if (!$user_lock)
89
-		logAction($locked ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $board));
95
+	if (!$user_lock) {
96
+			logAction($locked ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $board));
97
+	}
90 98
 	// Notify people that this topic has been locked?
91 99
 	sendNotifications($topic, empty($locked) ? 'unlock' : 'lock');
92 100
 
@@ -112,8 +120,9 @@  discard block
 block discarded – undo
112 120
 	isAllowedTo('make_sticky');
113 121
 
114 122
 	// You can't sticky a board or something!
115
-	if (empty($topic))
116
-		fatal_lang_error('not_a_topic', false);
123
+	if (empty($topic)) {
124
+			fatal_lang_error('not_a_topic', false);
125
+	}
117 126
 
118 127
 	checkSession('get');
119 128
 
@@ -147,8 +156,9 @@  discard block
 block discarded – undo
147 156
 	// Log this sticky action - always a moderator thing.
148 157
 	logAction(empty($is_sticky) ? 'sticky' : 'unsticky', array('topic' => $topic, 'board' => $board));
149 158
 	// Notify people that this topic has been stickied?
150
-	if (empty($is_sticky))
151
-		sendNotifications($topic, 'sticky');
159
+	if (empty($is_sticky)) {
160
+			sendNotifications($topic, 'sticky');
161
+	}
152 162
 
153 163
 	// Take them back to the now stickied topic.
154 164
 	redirectexit('topic=' . $topic . '.' . $_REQUEST['start'] . ';moderate');
Please login to merge, or discard this patch.
Sources/tasks/GroupAct-Notify.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,10 +19,10 @@
 block discarded – undo
19 19
  */
20 20
 class GroupAct_Notify_Background extends SMF_BackgroundTask
21 21
 {
22
-    /**
23
-     * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed.
24
-     * @return bool Always returns true
25
-     */
22
+	/**
23
+	 * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed.
24
+	 * @return bool Always returns true
25
+	 */
26 26
 	public function execute()
27 27
 	{
28 28
 		global $sourcedir, $smcFunc, $language, $modSettings;
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -132,8 +132,9 @@  discard block
 block discarded – undo
132 132
 						'GROUPNAME' => $user['group_name'],
133 133
 					);
134 134
 
135
-					if (!empty($custom_reason))
136
-						$replacements['REASON'] = $custom_reason;
135
+					if (!empty($custom_reason)) {
136
+											$replacements['REASON'] = $custom_reason;
137
+					}
137 138
 
138 139
 					$emaildata = loadEmailTemplate($email_template_name, $replacements, $user['language']);
139 140
 
@@ -142,8 +143,8 @@  discard block
 block discarded – undo
142 143
 			}
143 144
 
144 145
 			// Insert the alerts if any
145
-			if (!empty($alert_rows))
146
-				$smcFunc['db_insert']('',
146
+			if (!empty($alert_rows)) {
147
+							$smcFunc['db_insert']('',
147 148
 					'{db_prefix}user_alerts',
148 149
 					array(
149 150
 						'alert_time' => 'int', 'id_member' => 'int', 'content_type' => 'string',
@@ -152,6 +153,7 @@  discard block
 block discarded – undo
152 153
 					$alert_rows,
153 154
 					array()
154 155
 				);
156
+			}
155 157
 		}
156 158
 
157 159
 		return true;
Please login to merge, or discard this patch.