Completed
Pull Request — release-2.1 (#4166)
by 01
10:19
created
Sources/ManagePosts.php 1 patch
Braces   +39 added lines, -29 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main entrance point for the 'Posts and topics' screen.
@@ -98,23 +99,23 @@  discard block
 block discarded – undo
98 99
 		{
99 100
 			$_POST['censortext'] = explode("\n", strtr($_POST['censortext'], array("\r" => '')));
100 101
 
101
-			foreach ($_POST['censortext'] as $c)
102
-				list ($censored_vulgar[], $censored_proper[]) = array_pad(explode('=', trim($c)), 2, '');
103
-		}
104
-		elseif (isset($_POST['censor_vulgar'], $_POST['censor_proper']))
102
+			foreach ($_POST['censortext'] as $c) {
103
+							list ($censored_vulgar[], $censored_proper[]) = array_pad(explode('=', trim($c)), 2, '');
104
+			}
105
+		} elseif (isset($_POST['censor_vulgar'], $_POST['censor_proper']))
105 106
 		{
106 107
 			if (is_array($_POST['censor_vulgar']))
107 108
 			{
108 109
 				foreach ($_POST['censor_vulgar'] as $i => $value)
109 110
 				{
110
-					if (trim(strtr($value, '*', ' ')) == '')
111
-						unset($_POST['censor_vulgar'][$i], $_POST['censor_proper'][$i]);
111
+					if (trim(strtr($value, '*', ' ')) == '') {
112
+											unset($_POST['censor_vulgar'][$i], $_POST['censor_proper'][$i]);
113
+					}
112 114
 				}
113 115
 
114 116
 				$censored_vulgar = $_POST['censor_vulgar'];
115 117
 				$censored_proper = $_POST['censor_proper'];
116
-			}
117
-			else
118
+			} else
118 119
 			{
119 120
 				$censored_vulgar = explode("\n", strtr($_POST['censor_vulgar'], array("\r" => '')));
120 121
 				$censored_proper = explode("\n", strtr($_POST['censor_proper'], array("\r" => '')));
@@ -151,12 +152,14 @@  discard block
 block discarded – undo
151 152
 	$context['censored_words'] = array();
152 153
 	for ($i = 0, $n = count($censor_vulgar); $i < $n; $i++)
153 154
 	{
154
-		if (empty($censor_vulgar[$i]))
155
-			continue;
155
+		if (empty($censor_vulgar[$i])) {
156
+					continue;
157
+		}
156 158
 
157 159
 		// Skip it, it's either spaces or stars only.
158
-		if (trim(strtr($censor_vulgar[$i], '*', ' ')) == '')
159
-			continue;
160
+		if (trim(strtr($censor_vulgar[$i], '*', ' ')) == '') {
161
+					continue;
162
+		}
160 163
 
161 164
 		$context['censored_words'][$smcFunc['htmlspecialchars'](trim($censor_vulgar[$i]))] = isset($censor_proper[$i]) ? $smcFunc['htmlspecialchars']($censor_proper[$i]) : '';
162 165
 	}
@@ -187,10 +190,11 @@  discard block
 block discarded – undo
187 190
 
188 191
 	// Make an inline conditional a little shorter...
189 192
 	$can_spell_check = false;
190
-	if (function_exists('pspell_new'))
191
-		$can_spell_check = true;
192
-	elseif (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))
193
-		$can_spell_check = true;
193
+	if (function_exists('pspell_new')) {
194
+			$can_spell_check = true;
195
+	} elseif (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))) {
196
+			$can_spell_check = true;
197
+	}
194 198
 
195 199
 	// All the settings...
196 200
 	$config_vars = array(
@@ -221,8 +225,9 @@  discard block
 block discarded – undo
221 225
 
222 226
 	call_integration_hook('integrate_modify_post_settings', array(&$config_vars));
223 227
 
224
-	if ($return_config)
225
-		return $config_vars;
228
+	if ($return_config) {
229
+			return $config_vars;
230
+	}
226 231
 
227 232
 	// We'll want this for our easy save.
228 233
 	require_once($sourcedir . '/ManageServer.php');
@@ -242,17 +247,20 @@  discard block
 block discarded – undo
242 247
 			db_extend('packages');
243 248
 
244 249
 			$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
245
-			foreach ($colData as $column)
246
-				if ($column['name'] == 'body')
250
+			foreach ($colData as $column) {
251
+							if ($column['name'] == 'body')
247 252
 					$body_type = $column['type'];
253
+			}
248 254
 
249
-			if (isset($body_type) && ($_POST['max_messageLength'] > 65535 || $_POST['max_messageLength'] == 0) && $body_type == 'text')
250
-				fatal_lang_error('convert_to_mediumtext', false, array($scripturl . '?action=admin;area=maintain;sa=database'));
255
+			if (isset($body_type) && ($_POST['max_messageLength'] > 65535 || $_POST['max_messageLength'] == 0) && $body_type == 'text') {
256
+							fatal_lang_error('convert_to_mediumtext', false, array($scripturl . '?action=admin;area=maintain;sa=database'));
257
+			}
251 258
 		}
252 259
 
253 260
 		// If we're changing the post preview length let's check its valid
254
-		if (!empty($_POST['preview_characters']))
255
-			$_POST['preview_characters'] = (int) min(max(0, $_POST['preview_characters']), 512);
261
+		if (!empty($_POST['preview_characters'])) {
262
+					$_POST['preview_characters'] = (int) min(max(0, $_POST['preview_characters']), 512);
263
+		}
256 264
 
257 265
 		call_integration_hook('integrate_save_post_settings');
258 266
 
@@ -313,8 +321,9 @@  discard block
 block discarded – undo
313 321
 
314 322
 	call_integration_hook('integrate_modify_topic_settings', array(&$config_vars));
315 323
 
316
-	if ($return_config)
317
-		return $config_vars;
324
+	if ($return_config) {
325
+			return $config_vars;
326
+	}
318 327
 
319 328
 	// Get the settings template ready.
320 329
 	require_once($sourcedir . '/ManageServer.php');
@@ -367,8 +376,9 @@  discard block
 block discarded – undo
367 376
 		array('int', 'drafts_autosave_frequency', 'postinput' => $txt['manageposts_seconds'], 'subtext' => $txt['drafts_autosave_frequency_subnote']),
368 377
 	);
369 378
 
370
-	if ($return_config)
371
-		return $config_vars;
379
+	if ($return_config) {
380
+			return $config_vars;
381
+	}
372 382
 
373 383
 	// Get the settings template ready.
374 384
 	require_once($sourcedir . '/ManageServer.php');
Please login to merge, or discard this patch.
Sources/ManageErrors.php 1 patch
Braces   +49 added lines, -38 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * View the forum's error log.
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 	global $scripturl, $txt, $context, $modSettings, $user_profile, $filter, $smcFunc;
31 32
 
32 33
 	// Viewing contents of a file?
33
-	if (isset($_GET['file']))
34
-		return ViewFile();
34
+	if (isset($_GET['file'])) {
35
+			return ViewFile();
36
+	}
35 37
 
36 38
 	// Check for the administrative permission to do this.
37 39
 	isAllowedTo('admin_forum');
@@ -85,8 +87,8 @@  discard block
 block discarded – undo
85 87
 	);
86 88
 
87 89
 	// Set up the filtering...
88
-	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']]))
89
-		$filter = array(
90
+	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) {
91
+			$filter = array(
90 92
 			'variable' => $_GET['filter'],
91 93
 			'value' => array(
92 94
 				'sql' => in_array($_GET['filter'], array('message', 'url', 'file')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']),
@@ -94,10 +96,12 @@  discard block
 block discarded – undo
94 96
 			'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'],
95 97
 			'entity' => $filters[$_GET['filter']]['txt']
96 98
 		);
99
+	}
97 100
 
98 101
 	// Deleting, are we?
99
-	if (isset($_POST['delall']) || isset($_POST['delete']))
100
-		deleteErrors();
102
+	if (isset($_POST['delall']) || isset($_POST['delete'])) {
103
+			deleteErrors();
104
+	}
101 105
 
102 106
 	// Just how many errors are there?
103 107
 	$result = $smcFunc['db_query']('', '
@@ -112,12 +116,14 @@  discard block
 block discarded – undo
112 116
 	$smcFunc['db_free_result']($result);
113 117
 
114 118
 	// If this filter is empty...
115
-	if ($num_errors == 0 && isset($filter))
116
-		redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
119
+	if ($num_errors == 0 && isset($filter)) {
120
+			redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
121
+	}
117 122
 
118 123
 	// Clean up start.
119
-	if (!isset($_GET['start']) || $_GET['start'] < 0)
120
-		$_GET['start'] = 0;
124
+	if (!isset($_GET['start']) || $_GET['start'] < 0) {
125
+			$_GET['start'] = 0;
126
+	}
121 127
 
122 128
 	// Do we want to reverse error listing?
123 129
 	$context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up';
@@ -127,9 +133,9 @@  discard block
 block discarded – undo
127 133
 	$context['start'] = $_GET['start'];
128 134
 
129 135
 	// Update the error count
130
-	if (!isset($filter))
131
-		$context['num_errors'] = $num_errors;
132
-	else
136
+	if (!isset($filter)) {
137
+			$context['num_errors'] = $num_errors;
138
+	} else
133 139
 	{
134 140
 		// We want all errors, not just the number of filtered messages...
135 141
 		$query = $smcFunc['db_query']('', '
@@ -161,8 +167,9 @@  discard block
 block discarded – undo
161 167
 	for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++)
162 168
 	{
163 169
 		$search_message = preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '%', $smcFunc['db_escape_wildcard_string']($row['message']));
164
-		if ($search_message == $filter['value']['sql'])
165
-			$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
170
+		if ($search_message == $filter['value']['sql']) {
171
+					$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
172
+		}
166 173
 		$show_message = strtr(strtr(preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '$1', $row['message']), array("\r" => '', '<br>' => "\n", '<' => '&lt;', '>' => '&gt;', '"' => '&quot;')), array("\n" => '<br>'));
167 174
 
168 175
 		$context['errors'][$row['id_error']] = array(
@@ -221,8 +228,9 @@  discard block
 block discarded – undo
221 228
 				'members' => count($members),
222 229
 			)
223 230
 		);
224
-		while ($row = $smcFunc['db_fetch_assoc']($request))
225
-			$members[$row['id_member']] = $row;
231
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
232
+					$members[$row['id_member']] = $row;
233
+		}
226 234
 		$smcFunc['db_free_result']($request);
227 235
 
228 236
 		// This is a guest...
@@ -254,20 +262,18 @@  discard block
 block discarded – undo
254 262
 			$id = $filter['value']['sql'];
255 263
 			loadMemberData($id, false, 'minimal');
256 264
 			$context['filter']['value']['html'] = '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $user_profile[$id]['real_name'] . '</a>';
257
-		}
258
-		elseif ($filter['variable'] == 'url')
259
-			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
260
-		elseif ($filter['variable'] == 'message')
265
+		} elseif ($filter['variable'] == 'url') {
266
+					$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
267
+		} elseif ($filter['variable'] == 'message')
261 268
 		{
262 269
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
263 270
 			$context['filter']['value']['html'] = preg_replace('~&amp;lt;span class=&amp;quot;remove&amp;quot;&amp;gt;(.+?)&amp;lt;/span&amp;gt;~', '$1', $context['filter']['value']['html']);
264
-		}
265
-		elseif ($filter['variable'] == 'error_type')
271
+		} elseif ($filter['variable'] == 'error_type')
266 272
 		{
267 273
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
274
+		} else {
275
+					$context['filter']['value']['html'] = &$filter['value']['sql'];
268 276
 		}
269
-		else
270
-			$context['filter']['value']['html'] = &$filter['value']['sql'];
271 277
 	}
272 278
 
273 279
 	$context['error_types'] = array();
@@ -308,10 +314,11 @@  discard block
 block discarded – undo
308 314
 	$context['error_types']['all']['label'] .= ' (' . $sum . ')';
309 315
 
310 316
 	// Finally, work out what is the last tab!
311
-	if (isset($context['error_types'][$sum]))
312
-		$context['error_types'][$sum]['is_last'] = true;
313
-	else
314
-		$context['error_types']['all']['is_last'] = true;
317
+	if (isset($context['error_types'][$sum])) {
318
+			$context['error_types'][$sum]['is_last'] = true;
319
+	} else {
320
+			$context['error_types']['all']['is_last'] = true;
321
+	}
315 322
 
316 323
 	// And this is pretty basic ;).
317 324
 	$context['page_title'] = $txt['errlog'];
@@ -337,21 +344,23 @@  discard block
 block discarded – undo
337 344
 	validateToken('admin-el');
338 345
 
339 346
 	// Delete all or just some?
340
-	if (isset($_POST['delall']) && !isset($filter))
341
-		$smcFunc['db_query']('truncate_table', '
347
+	if (isset($_POST['delall']) && !isset($filter)) {
348
+			$smcFunc['db_query']('truncate_table', '
342 349
 			TRUNCATE {db_prefix}log_errors',
343 350
 			array(
344 351
 			)
345 352
 		);
353
+	}
346 354
 	// Deleting all with a filter?
347
-	elseif (isset($_POST['delall']) && isset($filter))
348
-		$smcFunc['db_query']('', '
355
+	elseif (isset($_POST['delall']) && isset($filter)) {
356
+			$smcFunc['db_query']('', '
349 357
 			DELETE FROM {db_prefix}log_errors
350 358
 			WHERE ' . $filter['variable'] . ' LIKE {string:filter}',
351 359
 			array(
352 360
 				'filter' => $filter['value']['sql'],
353 361
 			)
354 362
 		);
363
+	}
355 364
 	// Just specific errors?
356 365
 	elseif (!empty($_POST['delete']))
357 366
 	{
@@ -397,15 +406,17 @@  discard block
 block discarded – undo
397 406
 	$line = isset($_REQUEST['line']) ? (int) $_REQUEST['line'] : 0;
398 407
 
399 408
 	// Make sure the file we are looking for is one they are allowed to look at
400
-	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file))
401
-		fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
409
+	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) {
410
+			fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
411
+	}
402 412
 
403 413
 	// get the min and max lines
404 414
 	$min = $line - 20 <= 0 ? 1 : $line - 20;
405 415
 	$max = $line + 21; // One additional line to make everything work out correctly
406 416
 
407
-	if ($max <= 0 || $min >= $max)
408
-		fatal_lang_error('error_bad_line');
417
+	if ($max <= 0 || $min >= $max) {
418
+			fatal_lang_error('error_bad_line');
419
+	}
409 420
 
410 421
 	$file_data = explode('<br />', highlight_php_code($smcFunc['htmlspecialchars'](implode('', file($file)))));
411 422
 
Please login to merge, or discard this patch.
Sources/Subs-Editor.php 1 patch
Braces   +402 added lines, -303 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * !!!Compatibility!!!
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 {
31 32
 	global $modSettings;
32 33
 
33
-	if (!$compat_mode)
34
-		return $text;
34
+	if (!$compat_mode) {
35
+			return $text;
36
+	}
35 37
 
36 38
 	// Turn line breaks back into br's.
37 39
 	$text = strtr($text, array("\r" => '', "\n" => '<br>'));
@@ -48,8 +50,9 @@  discard block
 block discarded – undo
48 50
 			for ($i = 0, $n = count($parts); $i < $n; $i++)
49 51
 			{
50 52
 				// Value of 2 means we're inside the tag.
51
-				if ($i % 4 == 2)
52
-					$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
53
+				if ($i % 4 == 2) {
54
+									$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
55
+				}
53 56
 			}
54 57
 			// Put our humpty dumpty message back together again.
55 58
 			$text = implode('', $parts);
@@ -107,8 +110,9 @@  discard block
 block discarded – undo
107 110
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
108 111
 
109 112
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
110
-	if (isBrowser('webkit'))
111
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
113
+	if (isBrowser('webkit')) {
114
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
115
+	}
112 116
 
113 117
 	// If there's a trailing break get rid of it - Firefox tends to add one.
114 118
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -123,8 +127,9 @@  discard block
 block discarded – undo
123 127
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
124 128
 		{
125 129
 			// Value of 2 means we're inside the tag.
126
-			if ($i % 4 == 2)
127
-				$parts[$i] = strip_tags($parts[$i]);
130
+			if ($i % 4 == 2) {
131
+							$parts[$i] = strip_tags($parts[$i]);
132
+			}
128 133
 		}
129 134
 
130 135
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -150,18 +155,19 @@  discard block
 block discarded – undo
150 155
 			{
151 156
 				$found = array_search($file, $smileysto);
152 157
 				// Note the weirdness here is to stop double spaces between smileys.
153
-				if ($found)
154
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
155
-				else
156
-					$matches[1][$k] = '';
158
+				if ($found) {
159
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
160
+				} else {
161
+									$matches[1][$k] = '';
162
+				}
157 163
 			}
158
-		}
159
-		else
164
+		} else
160 165
 		{
161 166
 			// Load all the smileys.
162 167
 			$names = array();
163
-			foreach ($matches[1] as $file)
164
-				$names[] = $file;
168
+			foreach ($matches[1] as $file) {
169
+							$names[] = $file;
170
+			}
165 171
 			$names = array_unique($names);
166 172
 
167 173
 			if (!empty($names))
@@ -175,13 +181,15 @@  discard block
 block discarded – undo
175 181
 					)
176 182
 				);
177 183
 				$mappings = array();
178
-				while ($row = $smcFunc['db_fetch_assoc']($request))
179
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
184
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
186
+				}
180 187
 				$smcFunc['db_free_result']($request);
181 188
 
182
-				foreach ($matches[1] as $k => $file)
183
-					if (isset($mappings[$file]))
189
+				foreach ($matches[1] as $k => $file) {
190
+									if (isset($mappings[$file]))
184 191
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
192
+				}
185 193
 			}
186 194
 		}
187 195
 
@@ -193,8 +201,9 @@  discard block
 block discarded – undo
193 201
 	}
194 202
 
195 203
 	// Only try to buy more time if the client didn't quit.
196
-	if (connection_aborted() && $context['server']['is_apache'])
197
-		@apache_reset_timeout();
204
+	if (connection_aborted() && $context['server']['is_apache']) {
205
+			@apache_reset_timeout();
206
+	}
198 207
 
199 208
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
200 209
 	$replacement = '';
@@ -205,9 +214,9 @@  discard block
 block discarded – undo
205 214
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
206 215
 		{
207 216
 			// If it's being closed instantly, we can't deal with it...yet.
208
-			if ($matches[5] === '/')
209
-				continue;
210
-			else
217
+			if ($matches[5] === '/') {
218
+							continue;
219
+			} else
211 220
 			{
212 221
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
213 222
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -223,8 +232,9 @@  discard block
 block discarded – undo
223 232
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
224 233
 
225 234
 					// Something like 'font-weight: bold' is expected here.
226
-					if (strpos($clean_type_value_pair, ':') === false)
227
-						continue;
235
+					if (strpos($clean_type_value_pair, ':') === false) {
236
+											continue;
237
+					}
228 238
 
229 239
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
230 240
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -246,8 +256,7 @@  discard block
 block discarded – undo
246 256
 							{
247 257
 								$curCloseTags .= '[/u]';
248 258
 								$replacement .= '[u]';
249
-							}
250
-							elseif ($style_value == 'line-through')
259
+							} elseif ($style_value == 'line-through')
251 260
 							{
252 261
 								$curCloseTags .= '[/s]';
253 262
 								$replacement .= '[s]';
@@ -259,13 +268,11 @@  discard block
 block discarded – undo
259 268
 							{
260 269
 								$curCloseTags .= '[/left]';
261 270
 								$replacement .= '[left]';
262
-							}
263
-							elseif ($style_value == 'center')
271
+							} elseif ($style_value == 'center')
264 272
 							{
265 273
 								$curCloseTags .= '[/center]';
266 274
 								$replacement .= '[center]';
267
-							}
268
-							elseif ($style_value == 'right')
275
+							} elseif ($style_value == 'right')
269 276
 							{
270 277
 								$curCloseTags .= '[/right]';
271 278
 								$replacement .= '[right]';
@@ -287,8 +294,9 @@  discard block
 block discarded – undo
287 294
 
288 295
 						case 'font-size':
289 296
 							// Sometimes people put decimals where decimals should not be.
290
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
291
-								$style_value = $dec_matches[1] . $dec_matches[2];
297
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
298
+															$style_value = $dec_matches[1] . $dec_matches[2];
299
+							}
292 300
 
293 301
 							$curCloseTags .= '[/size]';
294 302
 							$replacement .= '[size=' . $style_value . ']';
@@ -296,8 +304,9 @@  discard block
 block discarded – undo
296 304
 
297 305
 						case 'font-family':
298 306
 							// Only get the first freaking font if there's a list!
299
-							if (strpos($style_value, ',') !== false)
300
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
307
+							if (strpos($style_value, ',') !== false) {
308
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
309
+							}
301 310
 
302 311
 							$curCloseTags .= '[/font]';
303 312
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -306,13 +315,15 @@  discard block
 block discarded – undo
306 315
 						// This is a hack for images with dimensions embedded.
307 316
 						case 'width':
308 317
 						case 'height':
309
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
310
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
318
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
319
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
320
+							}
311 321
 						break;
312 322
 
313 323
 						case 'list-style-type':
314
-							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1)
315
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
324
+							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) {
325
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
326
+							}
316 327
 						break;
317 328
 					}
318 329
 				}
@@ -325,18 +336,17 @@  discard block
 block discarded – undo
325 336
 				}
326 337
 
327 338
 				// If there's something that still needs closing, push it to the stack.
328
-				if (!empty($curCloseTags))
329
-					array_push($stack, array(
339
+				if (!empty($curCloseTags)) {
340
+									array_push($stack, array(
330 341
 							'element' => strtolower($curElement),
331 342
 							'closeTags' => $curCloseTags
332 343
 						)
333 344
 					);
334
-				elseif (!empty($extra_attr))
335
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
345
+				} elseif (!empty($extra_attr)) {
346
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
347
+				}
336 348
 			}
337
-		}
338
-
339
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
349
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
340 350
 		{
341 351
 			// Is this the element that we've been waiting for to be closed?
342 352
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -346,28 +356,32 @@  discard block
 block discarded – undo
346 356
 			}
347 357
 
348 358
 			// Must've been something else.
349
-			else
350
-				$replacement .= $part;
359
+			else {
360
+							$replacement .= $part;
361
+			}
351 362
 		}
352 363
 		// In all other cases, just add the part to the replacement.
353
-		else
354
-			$replacement .= $part;
364
+		else {
365
+					$replacement .= $part;
366
+		}
355 367
 	}
356 368
 
357 369
 	// Now put back the replacement in the text.
358 370
 	$text = $replacement;
359 371
 
360 372
 	// We are not finished yet, request more time.
361
-	if (connection_aborted() && $context['server']['is_apache'])
362
-		@apache_reset_timeout();
373
+	if (connection_aborted() && $context['server']['is_apache']) {
374
+			@apache_reset_timeout();
375
+	}
363 376
 
364 377
 	// Let's pull out any legacy alignments.
365 378
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
366 379
 	{
367 380
 		// Find the position in the text of this tag over again.
368 381
 		$start_pos = strpos($text, $matches[0]);
369
-		if ($start_pos === false)
370
-			break;
382
+		if ($start_pos === false) {
383
+					break;
384
+		}
371 385
 
372 386
 		// End tag?
373 387
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -381,8 +395,7 @@  discard block
 block discarded – undo
381 395
 
382 396
 			// Put the tags back into the body.
383 397
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
384
-		}
385
-		else
398
+		} else
386 399
 		{
387 400
 			// Just get rid of this evil tag.
388 401
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -395,8 +408,9 @@  discard block
 block discarded – undo
395 408
 		// Find the position of this again.
396 409
 		$start_pos = strpos($text, $matches[0]);
397 410
 		$end_pos = false;
398
-		if ($start_pos === false)
399
-			break;
411
+		if ($start_pos === false) {
412
+					break;
413
+		}
400 414
 
401 415
 		// This must have an end tag - and we must find the right one.
402 416
 		$lower_text = strtolower($text);
@@ -429,8 +443,9 @@  discard block
 block discarded – undo
429 443
 				break;
430 444
 			}
431 445
 		}
432
-		if ($end_pos === false)
433
-			break;
446
+		if ($end_pos === false) {
447
+					break;
448
+		}
434 449
 
435 450
 		// Now work out what the attributes are.
436 451
 		$attribs = fetchTagAttributes($matches[1]);
@@ -444,11 +459,11 @@  discard block
 block discarded – undo
444 459
 				$v = (int) trim($v);
445 460
 				$v = empty($v) ? 1 : $v;
446 461
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
462
+			} elseif ($s == 'face') {
463
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
464
+			} elseif ($s == 'color') {
465
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
447 466
 			}
448
-			elseif ($s == 'face')
449
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
450
-			elseif ($s == 'color')
451
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
452 467
 		}
453 468
 
454 469
 		// As before add in our tags.
@@ -456,8 +471,9 @@  discard block
 block discarded – undo
456 471
 		foreach ($tags as $tag)
457 472
 		{
458 473
 			$before .= $tag[0];
459
-			if (isset($tag[1]))
460
-				$after = $tag[1] . $after;
474
+			if (isset($tag[1])) {
475
+							$after = $tag[1] . $after;
476
+			}
461 477
 		}
462 478
 
463 479
 		// Remove the tag so it's never checked again.
@@ -468,8 +484,9 @@  discard block
 block discarded – undo
468 484
 	}
469 485
 
470 486
 	// Almost there, just a little more time.
471
-	if (connection_aborted() && $context['server']['is_apache'])
472
-		@apache_reset_timeout();
487
+	if (connection_aborted() && $context['server']['is_apache']) {
488
+			@apache_reset_timeout();
489
+	}
473 490
 
474 491
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
475 492
 	{
@@ -525,12 +542,13 @@  discard block
 block discarded – undo
525 542
 						{
526 543
 							$inList = true;
527 544
 
528
-							if ($tag === 'ol')
529
-								$listType = 'decimal';
530
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
531
-								$listType = $listTypeMapping[$match[1]];
532
-							else
533
-								$listType = null;
545
+							if ($tag === 'ol') {
546
+															$listType = 'decimal';
547
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
548
+															$listType = $listTypeMapping[$match[1]];
549
+							} else {
550
+															$listType = null;
551
+							}
534 552
 
535 553
 							$listDepth++;
536 554
 
@@ -594,9 +612,7 @@  discard block
 block discarded – undo
594 612
 							$parts[$i + 1] = '';
595 613
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
596 614
 							$parts[$i + 3] = '';
597
-						}
598
-
599
-						else
615
+						} else
600 616
 						{
601 617
 							// We're in a list item.
602 618
 							if ($listDepth > 0)
@@ -633,9 +649,7 @@  discard block
 block discarded – undo
633 649
 							$parts[$i + 1] = '';
634 650
 							$parts[$i + 2] = '';
635 651
 							$parts[$i + 3] = '';
636
-						}
637
-
638
-						else
652
+						} else
639 653
 						{
640 654
 							// Remove the trailing breaks from the list item.
641 655
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -673,8 +687,9 @@  discard block
 block discarded – undo
673 687
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
674 688
 		}
675 689
 
676
-		for ($i = $listDepth; $i > 0; $i--)
677
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
690
+		for ($i = $listDepth; $i > 0; $i--) {
691
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
692
+		}
678 693
 
679 694
 	}
680 695
 
@@ -683,8 +698,9 @@  discard block
 block discarded – undo
683 698
 	{
684 699
 		// Find the position of the image.
685 700
 		$start_pos = strpos($text, $matches[0]);
686
-		if ($start_pos === false)
687
-			break;
701
+		if ($start_pos === false) {
702
+					break;
703
+		}
688 704
 		$end_pos = $start_pos + strlen($matches[0]);
689 705
 
690 706
 		$params = '';
@@ -693,12 +709,13 @@  discard block
 block discarded – undo
693 709
 		$attrs = fetchTagAttributes($matches[1]);
694 710
 		foreach ($attrs as $attrib => $value)
695 711
 		{
696
-			if (in_array($attrib, array('width', 'height')))
697
-				$params .= ' ' . $attrib . '=' . (int) $value;
698
-			elseif ($attrib == 'alt' && trim($value) != '')
699
-				$params .= ' alt=' . trim($value);
700
-			elseif ($attrib == 'src')
701
-				$src = trim($value);
712
+			if (in_array($attrib, array('width', 'height'))) {
713
+							$params .= ' ' . $attrib . '=' . (int) $value;
714
+			} elseif ($attrib == 'alt' && trim($value) != '') {
715
+							$params .= ' alt=' . trim($value);
716
+			} elseif ($attrib == 'src') {
717
+							$src = trim($value);
718
+			}
702 719
 		}
703 720
 
704 721
 		$tag = '';
@@ -709,10 +726,11 @@  discard block
 block discarded – undo
709 726
 			{
710 727
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
711 728
 
712
-				if (substr($src, 0, 1) === '/')
713
-					$src = $baseURL . $src;
714
-				else
715
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
729
+				if (substr($src, 0, 1) === '/') {
730
+									$src = $baseURL . $src;
731
+				} else {
732
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
733
+				}
716 734
 			}
717 735
 
718 736
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -890,20 +908,23 @@  discard block
 block discarded – undo
890 908
 		},
891 909
 	);
892 910
 
893
-	foreach ($tags as $tag => $replace)
894
-		$text = preg_replace_callback($tag, $replace, $text);
911
+	foreach ($tags as $tag => $replace) {
912
+			$text = preg_replace_callback($tag, $replace, $text);
913
+	}
895 914
 
896 915
 	// Please give us just a little more time.
897
-	if (connection_aborted() && $context['server']['is_apache'])
898
-		@apache_reset_timeout();
916
+	if (connection_aborted() && $context['server']['is_apache']) {
917
+			@apache_reset_timeout();
918
+	}
899 919
 
900 920
 	// What about URL's - the pain in the ass of the tag world.
901 921
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
902 922
 	{
903 923
 		// Find the position of the URL.
904 924
 		$start_pos = strpos($text, $matches[0]);
905
-		if ($start_pos === false)
906
-			break;
925
+		if ($start_pos === false) {
926
+					break;
927
+		}
907 928
 		$end_pos = $start_pos + strlen($matches[0]);
908 929
 
909 930
 		$tag_type = 'url';
@@ -917,8 +938,9 @@  discard block
 block discarded – undo
917 938
 				$href = trim($value);
918 939
 
919 940
 				// Are we dealing with an FTP link?
920
-				if (preg_match('~^ftps?://~', $href) === 1)
921
-					$tag_type = 'ftp';
941
+				if (preg_match('~^ftps?://~', $href) === 1) {
942
+									$tag_type = 'ftp';
943
+				}
922 944
 
923 945
 				// Or is this a link to an email address?
924 946
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -932,28 +954,31 @@  discard block
 block discarded – undo
932 954
 				{
933 955
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
934 956
 
935
-					if (substr($href, 0, 1) === '/')
936
-						$href = $baseURL . $href;
937
-					else
938
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
957
+					if (substr($href, 0, 1) === '/') {
958
+											$href = $baseURL . $href;
959
+					} else {
960
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
961
+					}
939 962
 				}
940 963
 			}
941 964
 
942 965
 			// External URL?
943 966
 			if ($attrib == 'target' && $tag_type == 'url')
944 967
 			{
945
-				if (trim($value) == '_blank')
946
-					$tag_type == 'iurl';
968
+				if (trim($value) == '_blank') {
969
+									$tag_type == 'iurl';
970
+				}
947 971
 			}
948 972
 		}
949 973
 
950 974
 		$tag = '';
951 975
 		if ($href != '')
952 976
 		{
953
-			if ($matches[2] == $href)
954
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
955
-			else
956
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
977
+			if ($matches[2] == $href) {
978
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
979
+			} else {
980
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
981
+			}
957 982
 		}
958 983
 
959 984
 		// Replace the tag
@@ -992,17 +1017,18 @@  discard block
 block discarded – undo
992 1017
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
993 1018
 		if ($text[$i] == '=')
994 1019
 		{
995
-			if ($tag_state == 0)
996
-				$tag_state = 1;
997
-			elseif ($tag_state == 2)
998
-				$value .= '=';
1020
+			if ($tag_state == 0) {
1021
+							$tag_state = 1;
1022
+			} elseif ($tag_state == 2) {
1023
+							$value .= '=';
1024
+			}
999 1025
 		}
1000 1026
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
1001 1027
 		elseif ($text[$i] == ' ')
1002 1028
 		{
1003
-			if ($tag_state == 2)
1004
-				$value .= ' ';
1005
-			elseif ($tag_state == 1)
1029
+			if ($tag_state == 2) {
1030
+							$value .= ' ';
1031
+			} elseif ($tag_state == 1)
1006 1032
 			{
1007 1033
 				$attribs[$key] = $value;
1008 1034
 				$key = $value = '';
@@ -1013,24 +1039,27 @@  discard block
 block discarded – undo
1013 1039
 		elseif ($text[$i] == '"')
1014 1040
 		{
1015 1041
 			// Must be either going into or out of a string.
1016
-			if ($tag_state == 1)
1017
-				$tag_state = 2;
1018
-			else
1019
-				$tag_state = 1;
1042
+			if ($tag_state == 1) {
1043
+							$tag_state = 2;
1044
+			} else {
1045
+							$tag_state = 1;
1046
+			}
1020 1047
 		}
1021 1048
 		// Otherwise it's fine.
1022 1049
 		else
1023 1050
 		{
1024
-			if ($tag_state == 0)
1025
-				$key .= $text[$i];
1026
-			else
1027
-				$value .= $text[$i];
1051
+			if ($tag_state == 0) {
1052
+							$key .= $text[$i];
1053
+			} else {
1054
+							$value .= $text[$i];
1055
+			}
1028 1056
 		}
1029 1057
 	}
1030 1058
 
1031 1059
 	// Anything left?
1032
-	if ($key != '' && $value != '')
1033
-		$attribs[$key] = $value;
1060
+	if ($key != '' && $value != '') {
1061
+			$attribs[$key] = $value;
1062
+	}
1034 1063
 
1035 1064
 	return $attribs;
1036 1065
 }
@@ -1046,15 +1075,17 @@  discard block
 block discarded – undo
1046 1075
 	global $modSettings;
1047 1076
 
1048 1077
 	// Don't care about the texts that are too short.
1049
-	if (strlen($text) < 3)
1050
-		return $text;
1078
+	if (strlen($text) < 3) {
1079
+			return $text;
1080
+	}
1051 1081
 
1052 1082
 	// A list of tags that's disabled by the admin.
1053 1083
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
1054 1084
 
1055 1085
 	// Add flash if it's disabled as embedded tag.
1056
-	if (empty($modSettings['enableEmbeddedFlash']))
1057
-		$disabled['flash'] = true;
1086
+	if (empty($modSettings['enableEmbeddedFlash'])) {
1087
+			$disabled['flash'] = true;
1088
+	}
1058 1089
 
1059 1090
 	// Get a list of all the tags that are not disabled.
1060 1091
 	$all_tags = parse_bbc(false);
@@ -1062,10 +1093,12 @@  discard block
 block discarded – undo
1062 1093
 	$self_closing_tags = array();
1063 1094
 	foreach ($all_tags as $tag)
1064 1095
 	{
1065
-		if (!isset($disabled[$tag['tag']]))
1066
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1067
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1068
-			$self_closing_tags[] = $tag['tag'];
1096
+		if (!isset($disabled[$tag['tag']])) {
1097
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1098
+		}
1099
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1100
+					$self_closing_tags[] = $tag['tag'];
1101
+		}
1069 1102
 	}
1070 1103
 
1071 1104
 	// Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid!
@@ -1092,16 +1125,19 @@  discard block
 block discarded – undo
1092 1125
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1093 1126
 
1094 1127
 				// We're closing the exact same tag that we opened.
1095
-				if ($isClosingTag && $insideTag === $tagName)
1096
-					$insideTag = null;
1128
+				if ($isClosingTag && $insideTag === $tagName) {
1129
+									$insideTag = null;
1130
+				}
1097 1131
 
1098 1132
 				// We're opening a tag and we're not yet inside one either
1099
-				elseif (!$isClosingTag && $insideTag === null)
1100
-					$insideTag = $tagName;
1133
+				elseif (!$isClosingTag && $insideTag === null) {
1134
+									$insideTag = $tagName;
1135
+				}
1101 1136
 
1102 1137
 				// In all other cases, this tag must be invalid
1103
-				else
1104
-					unset($matches[$i]);
1138
+				else {
1139
+									unset($matches[$i]);
1140
+				}
1105 1141
 			}
1106 1142
 
1107 1143
 			// The next one is gonna be the other one.
@@ -1109,8 +1145,9 @@  discard block
 block discarded – undo
1109 1145
 		}
1110 1146
 
1111 1147
 		// We're still inside a tag and had no chance for closure?
1112
-		if ($insideTag !== null)
1113
-			$matches[] = '[/' . $insideTag . ']';
1148
+		if ($insideTag !== null) {
1149
+					$matches[] = '[/' . $insideTag . ']';
1150
+		}
1114 1151
 
1115 1152
 		// And a complete text string again.
1116 1153
 		$text = implode('', $matches);
@@ -1119,8 +1156,9 @@  discard block
 block discarded – undo
1119 1156
 	// Quickly remove any tags which are back to back.
1120 1157
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1121 1158
 	$lastlen = 0;
1122
-	while (strlen($text) !== $lastlen)
1123
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1159
+	while (strlen($text) !== $lastlen) {
1160
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1161
+	}
1124 1162
 
1125 1163
 	// Need to sort the tags my name length.
1126 1164
 	uksort($valid_tags, 'sort_array_length');
@@ -1157,8 +1195,9 @@  discard block
 block discarded – undo
1157 1195
 			$isCompetingTag = in_array($tag, $competing_tags);
1158 1196
 
1159 1197
 			// Check if this might be one of those cleaned out tags.
1160
-			if ($tag === '')
1161
-				continue;
1198
+			if ($tag === '') {
1199
+							continue;
1200
+			}
1162 1201
 
1163 1202
 			// Special case: inside [code] blocks any code is left untouched.
1164 1203
 			elseif ($tag === 'code')
@@ -1169,8 +1208,9 @@  discard block
 block discarded – undo
1169 1208
 					$inCode = false;
1170 1209
 
1171 1210
 					// Reopen tags that were closed before the code block.
1172
-					if (!empty($inlineElements))
1173
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1211
+					if (!empty($inlineElements)) {
1212
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1213
+					}
1174 1214
 				}
1175 1215
 
1176 1216
 				// We're outside a coding and nobbc block and opening it.
@@ -1199,8 +1239,9 @@  discard block
 block discarded – undo
1199 1239
 					$inNoBbc = false;
1200 1240
 
1201 1241
 					// Some inline elements might've been closed that need reopening.
1202
-					if (!empty($inlineElements))
1203
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1242
+					if (!empty($inlineElements)) {
1243
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1244
+					}
1204 1245
 				}
1205 1246
 
1206 1247
 				// We're outside a nobbc and coding block and opening it.
@@ -1220,8 +1261,9 @@  discard block
 block discarded – undo
1220 1261
 			}
1221 1262
 
1222 1263
 			// So, we're inside one of the special blocks: ignore any tag.
1223
-			elseif ($inCode || $inNoBbc)
1224
-				continue;
1264
+			elseif ($inCode || $inNoBbc) {
1265
+							continue;
1266
+			}
1225 1267
 
1226 1268
 			// We're dealing with an opening tag.
1227 1269
 			if ($isOpeningTag)
@@ -1262,8 +1304,9 @@  discard block
 block discarded – undo
1262 1304
 							if ($parts[$j + 3] === $tag)
1263 1305
 							{
1264 1306
 								// If it's an opening tag, increase the level.
1265
-								if ($parts[$j + 2] === '')
1266
-									$curLevel++;
1307
+								if ($parts[$j + 2] === '') {
1308
+																	$curLevel++;
1309
+								}
1267 1310
 
1268 1311
 								// A closing tag, decrease the level.
1269 1312
 								else
@@ -1286,13 +1329,15 @@  discard block
 block discarded – undo
1286 1329
 					{
1287 1330
 						if ($isCompetingTag)
1288 1331
 						{
1289
-							if (!isset($competingElements[$tag]))
1290
-								$competingElements[$tag] = array();
1332
+							if (!isset($competingElements[$tag])) {
1333
+															$competingElements[$tag] = array();
1334
+							}
1291 1335
 
1292 1336
 							$competingElements[$tag][] = $parts[$i + 4];
1293 1337
 
1294
-							if (count($competingElements[$tag]) > 1)
1295
-								$parts[$i] .= '[/' . $tag . ']';
1338
+							if (count($competingElements[$tag]) > 1) {
1339
+															$parts[$i] .= '[/' . $tag . ']';
1340
+							}
1296 1341
 						}
1297 1342
 
1298 1343
 						$inlineElements[$elementContent] = $tag;
@@ -1313,15 +1358,17 @@  discard block
 block discarded – undo
1313 1358
 						$addClosingTags = array();
1314 1359
 						while ($element = array_pop($blockElements))
1315 1360
 						{
1316
-							if ($element === $tag)
1317
-								break;
1361
+							if ($element === $tag) {
1362
+															break;
1363
+							}
1318 1364
 
1319 1365
 							// Still a block tag was open not equal to this tag.
1320 1366
 							$addClosingTags[] = $element['type'];
1321 1367
 						}
1322 1368
 
1323
-						if (!empty($addClosingTags))
1324
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1369
+						if (!empty($addClosingTags)) {
1370
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1371
+						}
1325 1372
 
1326 1373
 						// Apparently the closing tag was not found on the stack.
1327 1374
 						if (!is_string($element) || $element !== $tag)
@@ -1331,8 +1378,7 @@  discard block
 block discarded – undo
1331 1378
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1332 1379
 							continue;
1333 1380
 						}
1334
-					}
1335
-					else
1381
+					} else
1336 1382
 					{
1337 1383
 						// Get rid of this closing tag!
1338 1384
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1361,53 +1407,62 @@  discard block
 block discarded – undo
1361 1407
 							unset($inlineElements[$tagContentToBeClosed]);
1362 1408
 
1363 1409
 							// Was this the tag we were looking for?
1364
-							if ($tagToBeClosed === $tag)
1365
-								break;
1410
+							if ($tagToBeClosed === $tag) {
1411
+															break;
1412
+							}
1366 1413
 
1367 1414
 							// Nope, close it and look further!
1368
-							else
1369
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1415
+							else {
1416
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1417
+							}
1370 1418
 						}
1371 1419
 
1372 1420
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1373 1421
 						{
1374 1422
 							array_pop($competingElements[$tag]);
1375 1423
 
1376
-							if (count($competingElements[$tag]) > 0)
1377
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1424
+							if (count($competingElements[$tag]) > 0) {
1425
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1426
+							}
1378 1427
 						}
1379 1428
 					}
1380 1429
 
1381 1430
 					// Unexpected closing tag, ex-ter-mi-nate.
1382
-					else
1383
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1431
+					else {
1432
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1433
+					}
1384 1434
 				}
1385 1435
 			}
1386 1436
 		}
1387 1437
 
1388 1438
 		// Close the code tags.
1389
-		if ($inCode)
1390
-			$parts[$i] .= '[/code]';
1439
+		if ($inCode) {
1440
+					$parts[$i] .= '[/code]';
1441
+		}
1391 1442
 
1392 1443
 		// The same for nobbc tags.
1393
-		elseif ($inNoBbc)
1394
-			$parts[$i] .= '[/nobbc]';
1444
+		elseif ($inNoBbc) {
1445
+					$parts[$i] .= '[/nobbc]';
1446
+		}
1395 1447
 
1396 1448
 		// Still inline tags left unclosed? Close them now, better late than never.
1397
-		elseif (!empty($inlineElements))
1398
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1449
+		elseif (!empty($inlineElements)) {
1450
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1451
+		}
1399 1452
 
1400 1453
 		// Now close the block elements.
1401
-		if (!empty($blockElements))
1402
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1454
+		if (!empty($blockElements)) {
1455
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1456
+		}
1403 1457
 
1404 1458
 		$text = implode('', $parts);
1405 1459
 	}
1406 1460
 
1407 1461
 	// Final clean up of back to back tags.
1408 1462
 	$lastlen = 0;
1409
-	while (strlen($text) !== $lastlen)
1410
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1463
+	while (strlen($text) !== $lastlen) {
1464
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1465
+	}
1411 1466
 
1412 1467
 	return $text;
1413 1468
 }
@@ -1436,22 +1491,25 @@  discard block
 block discarded – undo
1436 1491
 	$context['template_layers'] = array();
1437 1492
 	// Lets make sure we aren't going to output anything nasty.
1438 1493
 	@ob_end_clean();
1439
-	if (!empty($modSettings['enableCompressedOutput']))
1440
-		@ob_start('ob_gzhandler');
1441
-	else
1442
-		@ob_start();
1494
+	if (!empty($modSettings['enableCompressedOutput'])) {
1495
+			@ob_start('ob_gzhandler');
1496
+	} else {
1497
+			@ob_start();
1498
+	}
1443 1499
 
1444 1500
 	// If we don't have any locale better avoid broken js
1445
-	if (empty($txt['lang_locale']))
1446
-		die();
1501
+	if (empty($txt['lang_locale'])) {
1502
+			die();
1503
+	}
1447 1504
 
1448 1505
 	$file_data = '(function ($) {
1449 1506
 	\'use strict\';
1450 1507
 
1451 1508
 	$.sceditor.locale[' . javaScriptEscape($txt['lang_locale']) . '] = {';
1452
-	foreach ($editortxt as $key => $val)
1453
-		$file_data .= '
1509
+	foreach ($editortxt as $key => $val) {
1510
+			$file_data .= '
1454 1511
 		' . javaScriptEscape($key) . ': ' . javaScriptEscape($val) . ',';
1512
+	}
1455 1513
 
1456 1514
 	$file_data .= '
1457 1515
 		dateFormat: "day.month.year"
@@ -1519,8 +1577,9 @@  discard block
 block discarded – undo
1519 1577
 				)
1520 1578
 			);
1521 1579
 			$icon_data = array();
1522
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1523
-				$icon_data[] = $row;
1580
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1581
+							$icon_data[] = $row;
1582
+			}
1524 1583
 			$smcFunc['db_free_result']($request);
1525 1584
 
1526 1585
 			$icons = array();
@@ -1535,9 +1594,9 @@  discard block
 block discarded – undo
1535 1594
 			}
1536 1595
 
1537 1596
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1597
+		} else {
1598
+					$icons = $temp;
1538 1599
 		}
1539
-		else
1540
-			$icons = $temp;
1541 1600
 	}
1542 1601
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1543 1602
 
@@ -1578,8 +1637,9 @@  discard block
 block discarded – undo
1578 1637
 	{
1579 1638
 		// Some general stuff.
1580 1639
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1581
-		if (!empty($context['drafts_autosave']))
1582
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1640
+		if (!empty($context['drafts_autosave'])) {
1641
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1642
+		}
1583 1643
 
1584 1644
 		// This really has some WYSIWYG stuff.
1585 1645
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1595,8 +1655,9 @@  discard block
 block discarded – undo
1595 1655
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1596 1656
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1597 1657
 		// editor language file
1598
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1599
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1658
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1659
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1660
+		}
1600 1661
 
1601 1662
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))];
1602 1663
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
@@ -1605,11 +1666,12 @@  discard block
 block discarded – undo
1605 1666
 			loadJavaScriptFile('spellcheck.js', array(), 'smf_spellcheck');
1606 1667
 
1607 1668
 			// Some hidden information is needed in order to make the spell checking work.
1608
-			if (!isset($_REQUEST['xml']))
1609
-				$context['insert_after_template'] .= '
1669
+			if (!isset($_REQUEST['xml'])) {
1670
+							$context['insert_after_template'] .= '
1610 1671
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1611 1672
 			<input type="hidden" name="spellstring" value="">
1612 1673
 		</form>';
1674
+			}
1613 1675
 		}
1614 1676
 	}
1615 1677
 
@@ -1775,10 +1837,12 @@  discard block
 block discarded – undo
1775 1837
 
1776 1838
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1777 1839
 		$disabled_tags = array();
1778
-		if (!empty($modSettings['disabledBBC']))
1779
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1780
-		if (empty($modSettings['enableEmbeddedFlash']))
1781
-			$disabled_tags[] = 'flash';
1840
+		if (!empty($modSettings['disabledBBC'])) {
1841
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1842
+		}
1843
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1844
+					$disabled_tags[] = 'flash';
1845
+		}
1782 1846
 
1783 1847
 		foreach ($disabled_tags as $tag)
1784 1848
 		{
@@ -1788,9 +1852,10 @@  discard block
 block discarded – undo
1788 1852
 				$context['disabled_tags']['orderedlist'] = true;
1789 1853
 			}
1790 1854
 
1791
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1792
-				if ($tag === $thisTag)
1855
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1856
+							if ($tag === $thisTag)
1793 1857
 					$context['disabled_tags'][$tagNameBBC] = true;
1858
+			}
1794 1859
 
1795 1860
 			$context['disabled_tags'][trim($tag)] = true;
1796 1861
 		}
@@ -1800,19 +1865,21 @@  discard block
 block discarded – undo
1800 1865
 		$context['bbc_toolbar'] = array();
1801 1866
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1802 1867
 		{
1803
-			if (!isset($context['bbc_toolbar'][$row]))
1804
-				$context['bbc_toolbar'][$row] = array();
1868
+			if (!isset($context['bbc_toolbar'][$row])) {
1869
+							$context['bbc_toolbar'][$row] = array();
1870
+			}
1805 1871
 			$tagsRow = array();
1806 1872
 			foreach ($tagRow as $tag)
1807 1873
 			{
1808 1874
 				if ((!empty($tag['code'])) && empty($context['disabled_tags'][$tag['code']]))
1809 1875
 				{
1810 1876
 					$tagsRow[] = $tag['code'];
1811
-					if (isset($tag['image']))
1812
-						$bbcodes_styles .= '
1877
+					if (isset($tag['image'])) {
1878
+											$bbcodes_styles .= '
1813 1879
 			.sceditor-button-' . $tag['code'] . ' div {
1814 1880
 				background: url(\'' . $settings['default_theme_url'] . '/images/bbc/' . $tag['image'] . '.png\');
1815 1881
 			}';
1882
+					}
1816 1883
 					if (isset($tag['before']))
1817 1884
 					{
1818 1885
 						$context['bbcodes_handlers'] .= '
@@ -1826,8 +1893,7 @@  discard block
 block discarded – undo
1826 1893
 				});';
1827 1894
 					}
1828 1895
 
1829
-				}
1830
-				else
1896
+				} else
1831 1897
 				{
1832 1898
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1833 1899
 					$tagsRow = array();
@@ -1838,14 +1904,16 @@  discard block
 block discarded – undo
1838 1904
 			{
1839 1905
 				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1840 1906
 				$tagsRow = array();
1841
-				if (!isset($context['disabled_tags']['font']))
1842
-					$tagsRow[] = 'font';
1843
-				if (!isset($context['disabled_tags']['size']))
1844
-					$tagsRow[] = 'size';
1845
-				if (!isset($context['disabled_tags']['color']))
1846
-					$tagsRow[] = 'color';
1847
-			}
1848
-			elseif ($row == 1 && empty($modSettings['disable_wysiwyg']))
1907
+				if (!isset($context['disabled_tags']['font'])) {
1908
+									$tagsRow[] = 'font';
1909
+				}
1910
+				if (!isset($context['disabled_tags']['size'])) {
1911
+									$tagsRow[] = 'size';
1912
+				}
1913
+				if (!isset($context['disabled_tags']['color'])) {
1914
+									$tagsRow[] = 'color';
1915
+				}
1916
+			} elseif ($row == 1 && empty($modSettings['disable_wysiwyg']))
1849 1917
 			{
1850 1918
 				$tmp = array();
1851 1919
 				$tagsRow[] = 'removeformat';
@@ -1856,13 +1924,15 @@  discard block
 block discarded – undo
1856 1924
 				}
1857 1925
 			}
1858 1926
 
1859
-			if (!empty($tagsRow))
1860
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1927
+			if (!empty($tagsRow)) {
1928
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1929
+			}
1861 1930
 		}
1862
-		if (!empty($bbcodes_styles))
1863
-			$context['html_headers'] .= '
1931
+		if (!empty($bbcodes_styles)) {
1932
+					$context['html_headers'] .= '
1864 1933
 		<style>' . $bbcodes_styles . '
1865 1934
 		</style>';
1935
+		}
1866 1936
 	}
1867 1937
 
1868 1938
 	// Initialize smiley array... if not loaded before.
@@ -1874,8 +1944,8 @@  discard block
 block discarded – undo
1874 1944
 		);
1875 1945
 
1876 1946
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1877
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1878
-			$context['smileys']['postform'][] = array(
1947
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1948
+					$context['smileys']['postform'][] = array(
1879 1949
 				'smileys' => array(
1880 1950
 					array(
1881 1951
 						'code' => ':)',
@@ -1961,7 +2031,7 @@  discard block
 block discarded – undo
1961 2031
 				),
1962 2032
 				'isLast' => true,
1963 2033
 			);
1964
-		elseif ($user_info['smiley_set'] != 'none')
2034
+		} elseif ($user_info['smiley_set'] != 'none')
1965 2035
 		{
1966 2036
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1967 2037
 			{
@@ -1984,17 +2054,19 @@  discard block
 block discarded – undo
1984 2054
 
1985 2055
 				foreach ($context['smileys'] as $section => $smileyRows)
1986 2056
 				{
1987
-					foreach ($smileyRows as $rowIndex => $smileys)
1988
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2057
+					foreach ($smileyRows as $rowIndex => $smileys) {
2058
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2059
+					}
1989 2060
 
1990
-					if (!empty($smileyRows))
1991
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2061
+					if (!empty($smileyRows)) {
2062
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2063
+					}
1992 2064
 				}
1993 2065
 
1994 2066
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2067
+			} else {
2068
+							$context['smileys'] = $temp;
1995 2069
 			}
1996
-			else
1997
-				$context['smileys'] = $temp;
1998 2070
 		}
1999 2071
 	}
2000 2072
 
@@ -2020,8 +2092,9 @@  discard block
 block discarded – undo
2020 2092
 		loadTemplate('GenericControls');
2021 2093
 
2022 2094
 		// Some javascript ma'am?
2023
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2024
-			loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2095
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2096
+					loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2097
+		}
2025 2098
 
2026 2099
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2027 2100
 
@@ -2034,8 +2107,8 @@  discard block
 block discarded – undo
2034 2107
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2035 2108
 
2036 2109
 	// Log this into our collection.
2037
-	if ($isNew)
2038
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2110
+	if ($isNew) {
2111
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2039 2112
 			'id' => $verificationOptions['id'],
2040 2113
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2041 2114
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2046,13 +2119,15 @@  discard block
 block discarded – undo
2046 2119
 			'questions' => array(),
2047 2120
 			'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']),
2048 2121
 		);
2122
+	}
2049 2123
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2050 2124
 
2051 2125
 	// Is there actually going to be anything?
2052
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha']))
2053
-		return false;
2054
-	elseif (!$isNew && !$do_test)
2055
-		return true;
2126
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) {
2127
+			return false;
2128
+	} elseif (!$isNew && !$do_test) {
2129
+			return true;
2130
+	}
2056 2131
 
2057 2132
 	// Sanitize reCAPTCHA fields?
2058 2133
 	if ($thisVerification['can_recaptcha'])
@@ -2065,11 +2140,12 @@  discard block
 block discarded – undo
2065 2140
 	}
2066 2141
 
2067 2142
 	// Add javascript for the object.
2068
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2069
-		$context['insert_after_template'] .= '
2143
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2144
+			$context['insert_after_template'] .= '
2070 2145
 			<script>
2071 2146
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2072 2147
 			</script>';
2148
+	}
2073 2149
 
2074 2150
 	// If we want questions do we have a cache of all the IDs?
2075 2151
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2092,8 +2168,9 @@  discard block
 block discarded – undo
2092 2168
 				unset ($row['id_question']);
2093 2169
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2094 2170
 				$row['answers'] = smf_json_decode($row['answers'], true);
2095
-				foreach ($row['answers'] as $k => $v)
2096
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2171
+				foreach ($row['answers'] as $k => $v) {
2172
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2173
+				}
2097 2174
 
2098 2175
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2099 2176
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2104,35 +2181,42 @@  discard block
 block discarded – undo
2104 2181
 		}
2105 2182
 	}
2106 2183
 
2107
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2108
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2184
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2185
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2186
+	}
2109 2187
 
2110 2188
 	// Do we need to refresh the verification?
2111
-	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh']))
2112
-		$force_refresh = true;
2113
-	else
2114
-		$force_refresh = false;
2189
+	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) {
2190
+			$force_refresh = true;
2191
+	} else {
2192
+			$force_refresh = false;
2193
+	}
2115 2194
 
2116 2195
 	// This can also force a fresh, although unlikely.
2117
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2118
-		$force_refresh = true;
2196
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2197
+			$force_refresh = true;
2198
+	}
2119 2199
 
2120 2200
 	$verification_errors = array();
2121 2201
 	// Start with any testing.
2122 2202
 	if ($do_test)
2123 2203
 	{
2124 2204
 		// This cannot happen!
2125
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2126
-			fatal_lang_error('no_access', false);
2205
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2206
+					fatal_lang_error('no_access', false);
2207
+		}
2127 2208
 		// ... nor this!
2128
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2129
-			fatal_lang_error('no_access', false);
2209
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2210
+					fatal_lang_error('no_access', false);
2211
+		}
2130 2212
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2131
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2132
-			fatal_lang_error('no_access', false);
2213
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2214
+					fatal_lang_error('no_access', false);
2215
+		}
2133 2216
 		// While we're here, did the user do something bad?
2134
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2135
-			$verification_errors[] = 'wrong_verification_answer';
2217
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2218
+					$verification_errors[] = 'wrong_verification_answer';
2219
+		}
2136 2220
 
2137 2221
 		if ($thisVerification['can_recaptcha'])
2138 2222
 		{
@@ -2143,22 +2227,25 @@  discard block
 block discarded – undo
2143 2227
 			{
2144 2228
 				$resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']);
2145 2229
 
2146
-				if (!$resp->isSuccess())
2147
-					$verification_errors[] = 'wrong_verification_code';
2230
+				if (!$resp->isSuccess()) {
2231
+									$verification_errors[] = 'wrong_verification_code';
2232
+				}
2233
+			} else {
2234
+							$verification_errors[] = 'wrong_verification_code';
2148 2235
 			}
2149
-			else
2150
-				$verification_errors[] = 'wrong_verification_code';
2151 2236
 		}
2152
-		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code']))
2153
-			$verification_errors[] = 'wrong_verification_code';
2237
+		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) {
2238
+					$verification_errors[] = 'wrong_verification_code';
2239
+		}
2154 2240
 		if ($thisVerification['number_questions'])
2155 2241
 		{
2156 2242
 			$incorrectQuestions = array();
2157 2243
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2158 2244
 			{
2159 2245
 				// We don't have this question any more, thus no answers.
2160
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2161
-					continue;
2246
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2247
+									continue;
2248
+				}
2162 2249
 				// This is quite complex. We have our question but it might have multiple answers.
2163 2250
 				// First, did they actually answer this question?
2164 2251
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2170,24 +2257,28 @@  discard block
 block discarded – undo
2170 2257
 				else
2171 2258
 				{
2172 2259
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2173
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2174
-						$incorrectQuestions[] = $q;
2260
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2261
+											$incorrectQuestions[] = $q;
2262
+					}
2175 2263
 				}
2176 2264
 			}
2177 2265
 
2178
-			if (!empty($incorrectQuestions))
2179
-				$verification_errors[] = 'wrong_verification_answer';
2266
+			if (!empty($incorrectQuestions)) {
2267
+							$verification_errors[] = 'wrong_verification_answer';
2268
+			}
2180 2269
 		}
2181 2270
 	}
2182 2271
 
2183 2272
 	// Any errors means we refresh potentially.
2184 2273
 	if (!empty($verification_errors))
2185 2274
 	{
2186
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2187
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2275
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2276
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2277
+		}
2188 2278
 		// Too many errors?
2189
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2190
-			$force_refresh = true;
2279
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2280
+					$force_refresh = true;
2281
+		}
2191 2282
 
2192 2283
 		// Keep a track of these.
2193 2284
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2220,8 +2311,9 @@  discard block
 block discarded – undo
2220 2311
 			// Are we overriding the range?
2221 2312
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2222 2313
 
2223
-			for ($i = 0; $i < 6; $i++)
2224
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2314
+			for ($i = 0; $i < 6; $i++) {
2315
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2316
+			}
2225 2317
 		}
2226 2318
 
2227 2319
 		// Getting some new questions?
@@ -2229,8 +2321,9 @@  discard block
 block discarded – undo
2229 2321
 		{
2230 2322
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2231 2323
 			$possible_langs = array();
2232
-			if (isset($_SESSION['language']))
2233
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2324
+			if (isset($_SESSION['language'])) {
2325
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2326
+			}
2234 2327
 			if (!empty($user_info['language']));
2235 2328
 			$possible_langs[] = $user_info['language'];
2236 2329
 			$possible_langs[] = $language;
@@ -2249,8 +2342,7 @@  discard block
 block discarded – undo
2249 2342
 				}
2250 2343
 			}
2251 2344
 		}
2252
-	}
2253
-	else
2345
+	} else
2254 2346
 	{
2255 2347
 		// Same questions as before.
2256 2348
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2260,8 +2352,9 @@  discard block
 block discarded – undo
2260 2352
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2261 2353
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2262 2354
 	{
2263
-		if (!isset($context['html_headers']))
2264
-			$context['html_headers'] = '';
2355
+		if (!isset($context['html_headers'])) {
2356
+					$context['html_headers'] = '';
2357
+		}
2265 2358
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2266 2359
 	}
2267 2360
 
@@ -2287,11 +2380,13 @@  discard block
 block discarded – undo
2287 2380
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2288 2381
 
2289 2382
 	// Return errors if we have them.
2290
-	if (!empty($verification_errors))
2291
-		return $verification_errors;
2383
+	if (!empty($verification_errors)) {
2384
+			return $verification_errors;
2385
+	}
2292 2386
 	// If we had a test that one, make a note.
2293
-	elseif ($do_test)
2294
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2387
+	elseif ($do_test) {
2388
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2389
+	}
2295 2390
 
2296 2391
 	// Say that everything went well chaps.
2297 2392
 	return true;
@@ -2316,8 +2411,9 @@  discard block
 block discarded – undo
2316 2411
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2317 2412
 
2318 2413
 	// If we're just checking the callback function is registered return true or false.
2319
-	if ($checkRegistered != null)
2320
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2414
+	if ($checkRegistered != null) {
2415
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2416
+	}
2321 2417
 
2322 2418
 	checkSession('get');
2323 2419
 	loadTemplate('Xml');
@@ -2468,24 +2564,27 @@  discard block
 block discarded – undo
2468 2564
 		foreach ($possible_versions as $ver)
2469 2565
 		{
2470 2566
 			$ver = trim($ver);
2471
-			if (strpos($ver, 'SMF') === 0)
2472
-				$versions[] = $ver;
2567
+			if (strpos($ver, 'SMF') === 0) {
2568
+							$versions[] = $ver;
2569
+			}
2473 2570
 		}
2474 2571
 	}
2475 2572
 	$smcFunc['db_free_result']($request);
2476 2573
 
2477 2574
 	// Just in case we don't have ANYthing.
2478
-	if (empty($versions))
2479
-		$versions = array('SMF 2.0');
2575
+	if (empty($versions)) {
2576
+			$versions = array('SMF 2.0');
2577
+	}
2480 2578
 
2481
-	foreach ($versions as $id => $version)
2482
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2579
+	foreach ($versions as $id => $version) {
2580
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2483 2581
 			$xml_data['items']['children'][] = array(
2484 2582
 				'attributes' => array(
2485 2583
 					'id' => $id,
2486 2584
 				),
2487 2585
 				'value' => $version,
2488 2586
 			);
2587
+	}
2489 2588
 
2490 2589
 	return $xml_data;
2491 2590
 }
Please login to merge, or discard this patch.
Sources/Subs-Themes.php 1 patch
Braces   +67 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Gets a single theme's info.
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 	global $smcFunc, $modSettings;
28 29
 
29 30
 	// No data, no fun!
30
-	if (empty($id))
31
-		return false;
31
+	if (empty($id)) {
32
+			return false;
33
+	}
32 34
 
33 35
 	// Make sure $id is an int.
34 36
 	$id = (int) $id;
@@ -171,8 +173,9 @@  discard block
 block discarded – undo
171 173
 	global $sourcedir, $forum_version, $txt, $scripturl, $context;
172 174
 	global $explicit_images;
173 175
 
174
-	if (empty($path))
175
-		return false;
176
+	if (empty($path)) {
177
+			return false;
178
+	}
176 179
 
177 180
 	$xml_data = array();
178 181
 	$explicit_images = false;
@@ -229,9 +232,10 @@  discard block
 block discarded – undo
229 232
 	);
230 233
 
231 234
 	// Assign the values to be stored.
232
-	foreach ($xml_elements as $var => $name)
233
-		if (!empty($theme_info_xml[$name]))
235
+	foreach ($xml_elements as $var => $name) {
236
+			if (!empty($theme_info_xml[$name]))
234 237
 			$xml_data[$var] = $theme_info_xml[$name];
238
+	}
235 239
 
236 240
 	// Add the supported versions.
237 241
 	$xml_data['install_for'] = $install_versions;
@@ -243,8 +247,9 @@  discard block
 block discarded – undo
243 247
 		$explicit_images = true;
244 248
 	}
245 249
 
246
-	if (!empty($theme_info_xml['extra']))
247
-		$xml_data += smf_json_decode($theme_info_xml['extra'], true);
250
+	if (!empty($theme_info_xml['extra'])) {
251
+			$xml_data += smf_json_decode($theme_info_xml['extra'], true);
252
+	}
248 253
 
249 254
 	return $xml_data;
250 255
 }
@@ -262,12 +267,14 @@  discard block
 block discarded – undo
262 267
 	global $settings, $explicit_images;
263 268
 
264 269
 	// External use? no problem!
265
-	if ($to_install)
266
-		$context['to_install'] = $to_install;
270
+	if ($to_install) {
271
+			$context['to_install'] = $to_install;
272
+	}
267 273
 
268 274
 	// One last check.
269
-	if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes')
270
-		fatal_lang_error('theme_install_invalid_dir', false);
275
+	if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes') {
276
+			fatal_lang_error('theme_install_invalid_dir', false);
277
+	}
271 278
 
272 279
 	// OK, is this a newer version of an already installed theme?
273 280
 	if (!empty($context['to_install']['version']))
@@ -291,8 +298,8 @@  discard block
 block discarded – undo
291 298
 		$smcFunc['db_free_result']($request);
292 299
 
293 300
 		// Got something, lets figure it out what to do next.
294
-		if (!empty($to_update) && !empty($to_update['version']))
295
-			switch (compareVersions($context['to_install']['version'], $to_update['version']))
301
+		if (!empty($to_update) && !empty($to_update['version'])) {
302
+					switch (compareVersions($context['to_install']['version'], $to_update['version']))
296 303
 			{
297 304
 				case 1: // Got a newer version, update the old entry.
298 305
 					$smcFunc['db_query']('', '
@@ -306,6 +313,7 @@  discard block
 block discarded – undo
306 313
 							'id_theme' => $to_update['id_theme'],
307 314
 						)
308 315
 					);
316
+		}
309 317
 
310 318
 					// Done with the update, tell the user about it.
311 319
 					$context['to_install']['updated'] = true;
@@ -371,13 +379,15 @@  discard block
 block discarded – undo
371 379
 				$context['to_install']['base_theme_url'] = $temp['theme_url'];
372 380
 				$context['to_install']['base_theme_dir'] = $temp['theme_dir'];
373 381
 
374
-				if (empty($explicit_images) && !empty($context['to_install']['base_theme_url']))
375
-					$context['to_install']['theme_url'] = $context['to_install']['base_theme_url'];
382
+				if (empty($explicit_images) && !empty($context['to_install']['base_theme_url'])) {
383
+									$context['to_install']['theme_url'] = $context['to_install']['base_theme_url'];
384
+				}
376 385
 			}
377 386
 
378 387
 			// Nope, sorry, couldn't find any theme already installed.
379
-			else
380
-				fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']);
388
+			else {
389
+							fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']);
390
+			}
381 391
 		}
382 392
 
383 393
 		unset($context['to_install']['based_on']);
@@ -400,16 +410,18 @@  discard block
 block discarded – undo
400 410
 	call_integration_hook('integrate_theme_install', array(&$context['to_install'], $id_theme));
401 411
 
402 412
 	$inserts = array();
403
-	foreach ($context['to_install'] as $var => $val)
404
-		$inserts[] = array($id_theme, $var, $val);
413
+	foreach ($context['to_install'] as $var => $val) {
414
+			$inserts[] = array($id_theme, $var, $val);
415
+	}
405 416
 
406
-	if (!empty($inserts))
407
-		$smcFunc['db_insert']('insert',
417
+	if (!empty($inserts)) {
418
+			$smcFunc['db_insert']('insert',
408 419
 			'{db_prefix}themes',
409 420
 			array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
410 421
 			$inserts,
411 422
 			array('id_theme', 'variable')
412 423
 		);
424
+	}
413 425
 
414 426
 	// Update the known and enable Theme's settings.
415 427
 	$known = strtr($modSettings['knownThemes'] . ',' . $id_theme, array(',,' => ','));
@@ -428,21 +440,24 @@  discard block
 block discarded – undo
428 440
  */
429 441
 function remove_dir($path)
430 442
 {
431
-	if (empty($path))
432
-		return false;
443
+	if (empty($path)) {
444
+			return false;
445
+	}
433 446
 
434 447
 	if (is_dir($path))
435 448
 	{
436 449
 		$objects = scandir($path);
437 450
 
438
-		foreach ($objects as $object)
439
-			if ($object != '.' && $object != '..')
451
+		foreach ($objects as $object) {
452
+					if ($object != '.' && $object != '..')
440 453
 			{
441 454
 				if (filetype($path . '/' . $object) == 'dir')
442 455
 					remove_dir($path . '/' . $object);
456
+		}
443 457
 
444
-				else
445
-					unlink($path . '/' . $object);
458
+				else {
459
+									unlink($path . '/' . $object);
460
+				}
446 461
 			}
447 462
 	}
448 463
 
@@ -461,8 +476,9 @@  discard block
 block discarded – undo
461 476
 	global $smcFunc, $modSettings;
462 477
 
463 478
 	// Can't delete the default theme, sorry!
464
-	if (empty($themeID) || $themeID == 1)
465
-		return false;
479
+	if (empty($themeID) || $themeID == 1) {
480
+			return false;
481
+	}
466 482
 
467 483
 	$known = explode(',', $modSettings['knownThemes']);
468 484
 	$enable = explode(',', $modSettings['enableThemes']);
@@ -512,8 +528,9 @@  discard block
 block discarded – undo
512 528
 	updateSettings(array('enableThemes' => $enable, 'knownThemes' => $known));
513 529
 
514 530
 	// Fix it if the theme was the overall default theme.
515
-	if ($modSettings['theme_guests'] == $themeID)
516
-		updateSettings(array('theme_guests' => '1'));
531
+	if ($modSettings['theme_guests'] == $themeID) {
532
+			updateSettings(array('theme_guests' => '1'));
533
+	}
517 534
 
518 535
 	return true;
519 536
 }
@@ -530,13 +547,15 @@  discard block
 block discarded – undo
530 547
 	global $scripturl, $txt, $context;
531 548
 
532 549
 	// Is it even a directory?
533
-	if (!is_dir($path))
534
-		fatal_lang_error('error_invalid_dir', 'critical');
550
+	if (!is_dir($path)) {
551
+			fatal_lang_error('error_invalid_dir', 'critical');
552
+	}
535 553
 
536 554
 	$dir = dir($path);
537 555
 	$entries = array();
538
-	while ($entry = $dir->read())
539
-		$entries[] = $entry;
556
+	while ($entry = $dir->read()) {
557
+			$entries[] = $entry;
558
+	}
540 559
 	$dir->close();
541 560
 
542 561
 	natcasesort($entries);
@@ -547,11 +566,12 @@  discard block
 block discarded – undo
547 566
 	foreach ($entries as $entry)
548 567
 	{
549 568
 		// Skip all dot files, including .htaccess.
550
-		if (substr($entry, 0, 1) == '.' || $entry == 'CVS')
551
-			continue;
569
+		if (substr($entry, 0, 1) == '.' || $entry == 'CVS') {
570
+					continue;
571
+		}
552 572
 
553
-		if (is_dir($path . '/' . $entry))
554
-			$listing1[] = array(
573
+		if (is_dir($path . '/' . $entry)) {
574
+					$listing1[] = array(
555 575
 				'filename' => $entry,
556 576
 				'is_writable' => is_writable($path . '/' . $entry),
557 577
 				'is_directory' => true,
@@ -561,13 +581,14 @@  discard block
 block discarded – undo
561 581
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $relative . $entry,
562 582
 				'size' => '',
563 583
 			);
564
-		else
584
+		} else
565 585
 		{
566 586
 			$size = filesize($path . '/' . $entry);
567
-			if ($size > 2048 || $size == 1024)
568
-				$size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes'];
569
-			else
570
-				$size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes'];
587
+			if ($size > 2048 || $size == 1024) {
588
+							$size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes'];
589
+			} else {
590
+							$size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes'];
591
+			}
571 592
 
572 593
 			$listing2[] = array(
573 594
 				'filename' => $entry,
Please login to merge, or discard this patch.
Sources/Recent.php 1 patch
Braces   +208 added lines, -170 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get the latest post made on the system
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 			'is_approved' => 1,
45 46
 		)
46 47
 	);
47
-	if ($smcFunc['db_num_rows']($request) == 0)
48
-		return array();
48
+	if ($smcFunc['db_num_rows']($request) == 0) {
49
+			return array();
50
+	}
49 51
 	$row = $smcFunc['db_fetch_assoc']($request);
50 52
 	$smcFunc['db_free_result']($request);
51 53
 
@@ -54,8 +56,9 @@  discard block
 block discarded – undo
54 56
 	censorText($row['body']);
55 57
 
56 58
 	$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled']), array('<br>' => '&#10;')));
57
-	if ($smcFunc['strlen']($row['body']) > 128)
58
-		$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
59
+	if ($smcFunc['strlen']($row['body']) > 128) {
60
+			$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
61
+	}
59 62
 
60 63
 	// Send the data.
61 64
 	return array(
@@ -83,15 +86,17 @@  discard block
 block discarded – undo
83 86
 
84 87
 	$context['is_redirect'] = false;
85 88
 
86
-	if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95)
87
-		$_REQUEST['start'] = 95;
89
+	if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) {
90
+			$_REQUEST['start'] = 95;
91
+	}
88 92
 
89 93
 	$query_parameters = array();
90 94
 	if (!empty($_REQUEST['c']) && empty($board))
91 95
 	{
92 96
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
93
-		foreach ($_REQUEST['c'] as $i => $c)
94
-			$_REQUEST['c'][$i] = (int) $c;
97
+		foreach ($_REQUEST['c'] as $i => $c) {
98
+					$_REQUEST['c'][$i] = (int) $c;
99
+		}
95 100
 
96 101
 		if (count($_REQUEST['c']) == 1)
97 102
 		{
@@ -107,8 +112,9 @@  discard block
 block discarded – undo
107 112
 			list ($name) = $smcFunc['db_fetch_row']($request);
108 113
 			$smcFunc['db_free_result']($request);
109 114
 
110
-			if (empty($name))
111
-				fatal_lang_error('no_access', false);
115
+			if (empty($name)) {
116
+							fatal_lang_error('no_access', false);
117
+			}
112 118
 
113 119
 			$context['linktree'][] = array(
114 120
 				'url' => $scripturl . '#c' . (int) $_REQUEST['c'],
@@ -140,8 +146,9 @@  discard block
 block discarded – undo
140 146
 		}
141 147
 		$smcFunc['db_free_result']($request);
142 148
 
143
-		if (empty($boards))
144
-			fatal_lang_error('error_no_boards_selected');
149
+		if (empty($boards)) {
150
+					fatal_lang_error('error_no_boards_selected');
151
+		}
145 152
 
146 153
 		$query_this_board = 'b.id_board IN ({array_int:boards})';
147 154
 		$query_parameters['boards'] = $boards;
@@ -155,12 +162,12 @@  discard block
 block discarded – undo
155 162
 		}
156 163
 
157 164
 		$context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), 10, false);
158
-	}
159
-	elseif (!empty($_REQUEST['boards']))
165
+	} elseif (!empty($_REQUEST['boards']))
160 166
 	{
161 167
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
162
-		foreach ($_REQUEST['boards'] as $i => $b)
163
-			$_REQUEST['boards'][$i] = (int) $b;
168
+		foreach ($_REQUEST['boards'] as $i => $b) {
169
+					$_REQUEST['boards'][$i] = (int) $b;
170
+		}
164 171
 
165 172
 		$request = $smcFunc['db_query']('', '
166 173
 			SELECT b.id_board, b.num_posts
@@ -184,8 +191,9 @@  discard block
 block discarded – undo
184 191
 		}
185 192
 		$smcFunc['db_free_result']($request);
186 193
 
187
-		if (empty($boards))
188
-			fatal_lang_error('error_no_boards_selected');
194
+		if (empty($boards)) {
195
+					fatal_lang_error('error_no_boards_selected');
196
+		}
189 197
 
190 198
 		$query_this_board = 'b.id_board IN ({array_int:boards})';
191 199
 		$query_parameters['boards'] = $boards;
@@ -199,8 +207,7 @@  discard block
 block discarded – undo
199 207
 		}
200 208
 
201 209
 		$context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false);
202
-	}
203
-	elseif (!empty($board))
210
+	} elseif (!empty($board))
204 211
 	{
205 212
 		$request = $smcFunc['db_query']('', '
206 213
 			SELECT num_posts, redirect
@@ -233,8 +240,7 @@  discard block
 block discarded – undo
233 240
 		}
234 241
 
235 242
 		$context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), 10, true);
236
-	}
237
-	else
243
+	} else
238 244
 	{
239 245
 		$query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
240 246
 					AND b.id_board != {int:recycle_board}' : ''). '
@@ -269,8 +275,9 @@  discard block
 block discarded – undo
269 275
 	);
270 276
 
271 277
 	// If you selected a redirection board, don't try getting posts for it...
272
-	if ($context['is_redirect'])
273
-		$messages = 0;
278
+	if ($context['is_redirect']) {
279
+			$messages = 0;
280
+	}
274 281
 
275 282
 	$key = 'recent-' . $user_info['id'] . '-' . md5(json_encode(array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start'];
276 283
 	if (!$context['is_redirect'] && (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null))
@@ -301,16 +308,18 @@  discard block
 block discarded – undo
301 308
 				$query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board);
302 309
 				$cache_results = true;
303 310
 				unset($query_parameters['max_id_msg']);
311
+			} else {
312
+							$done = true;
304 313
 			}
305
-			else
306
-				$done = true;
307 314
 		}
308 315
 		$messages = array();
309
-		while ($row = $smcFunc['db_fetch_assoc']($request))
310
-			$messages[] = $row['id_msg'];
316
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
317
+					$messages[] = $row['id_msg'];
318
+		}
311 319
 		$smcFunc['db_free_result']($request);
312
-		if (!empty($cache_results))
313
-			cache_put_data($key, $messages, 120);
320
+		if (!empty($cache_results)) {
321
+					cache_put_data($key, $messages, 120);
322
+		}
314 323
 	}
315 324
 
316 325
 	// Nothing here... Or at least, nothing you can see...
@@ -397,8 +406,9 @@  discard block
 block discarded – undo
397 406
 			'css_class' => 'windowbg',
398 407
 		);
399 408
 
400
-		if ($user_info['id'] == $row['id_first_member'])
401
-			$board_ids['own'][$row['id_board']][] = $row['id_msg'];
409
+		if ($user_info['id'] == $row['id_first_member']) {
410
+					$board_ids['own'][$row['id_board']][] = $row['id_msg'];
411
+		}
402 412
 		$board_ids['any'][$row['id_board']][] = $row['id_msg'];
403 413
 	}
404 414
 	$smcFunc['db_free_result']($request);
@@ -424,20 +434,23 @@  discard block
 block discarded – undo
424 434
 			$boards = boardsAllowedTo($permission);
425 435
 
426 436
 			// If 0 is the only thing in the array, they can do it everywhere!
427
-			if (!empty($boards) && $boards[0] == 0)
428
-				$boards = array_keys($board_ids[$type]);
437
+			if (!empty($boards) && $boards[0] == 0) {
438
+							$boards = array_keys($board_ids[$type]);
439
+			}
429 440
 
430 441
 			// Go through the boards, and look for posts they can do this on.
431 442
 			foreach ($boards as $board_id)
432 443
 			{
433 444
 				// Hmm, they have permission, but there are no topics from that board on this page.
434
-				if (!isset($board_ids[$type][$board_id]))
435
-					continue;
445
+				if (!isset($board_ids[$type][$board_id])) {
446
+									continue;
447
+				}
436 448
 
437 449
 				// Okay, looks like they can do it for these posts.
438
-				foreach ($board_ids[$type][$board_id] as $counter)
439
-					if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id'])
450
+				foreach ($board_ids[$type][$board_id] as $counter) {
451
+									if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id'])
440 452
 						$context['posts'][$counter][$allowed] = true;
453
+				}
441 454
 			}
442 455
 		}
443 456
 	}
@@ -480,17 +493,19 @@  discard block
 block discarded – undo
480 493
 	$context['showing_all_topics'] = isset($_GET['all']);
481 494
 	$context['start'] = (int) $_REQUEST['start'];
482 495
 	$context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
483
-	if ($_REQUEST['action'] == 'unread')
484
-		$context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit'];
485
-	else
486
-		$context['page_title'] = $txt['unread_replies'];
496
+	if ($_REQUEST['action'] == 'unread') {
497
+			$context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit'];
498
+	} else {
499
+			$context['page_title'] = $txt['unread_replies'];
500
+	}
487 501
 
488
-	if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread'])
489
-		fatal_lang_error('loadavg_allunread_disabled', false);
490
-	elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies'])
491
-		fatal_lang_error('loadavg_unreadreplies_disabled', false);
492
-	elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread'])
493
-		fatal_lang_error('loadavg_unread_disabled', false);
502
+	if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) {
503
+			fatal_lang_error('loadavg_allunread_disabled', false);
504
+	} elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) {
505
+			fatal_lang_error('loadavg_unreadreplies_disabled', false);
506
+	} elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) {
507
+			fatal_lang_error('loadavg_unread_disabled', false);
508
+	}
494 509
 
495 510
 	// Parameters for the main query.
496 511
 	$query_parameters = array();
@@ -503,12 +518,14 @@  discard block
 block discarded – undo
503 518
 		if (!empty($_REQUEST['boards']))
504 519
 		{
505 520
 			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
506
-			foreach ($_REQUEST['boards'] as $b)
507
-				$boards[] = (int) $b;
521
+			foreach ($_REQUEST['boards'] as $b) {
522
+							$boards[] = (int) $b;
523
+			}
508 524
 		}
509 525
 
510
-		if (!empty($board))
511
-			$boards[] = (int) $board;
526
+		if (!empty($board)) {
527
+					$boards[] = (int) $board;
528
+		}
512 529
 
513 530
 		// The easiest thing is to just get all the boards they can see, but since we've specified the top of tree we ignore some of them
514 531
 		$request = $smcFunc['db_query']('', '
@@ -525,30 +542,31 @@  discard block
 block discarded – undo
525 542
 			)
526 543
 		);
527 544
 
528
-		while ($row = $smcFunc['db_fetch_assoc']($request))
529
-			if (in_array($row['id_parent'], $boards))
545
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
546
+					if (in_array($row['id_parent'], $boards))
530 547
 				$boards[] = $row['id_board'];
548
+		}
531 549
 
532 550
 		$smcFunc['db_free_result']($request);
533 551
 
534
-		if (empty($boards))
535
-			fatal_lang_error('error_no_boards_selected');
552
+		if (empty($boards)) {
553
+					fatal_lang_error('error_no_boards_selected');
554
+		}
536 555
 
537 556
 		$query_this_board = 'id_board IN ({array_int:boards})';
538 557
 		$query_parameters['boards'] = $boards;
539 558
 		$context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d';
540
-	}
541
-	elseif (!empty($board))
559
+	} elseif (!empty($board))
542 560
 	{
543 561
 		$query_this_board = 'id_board = {int:board}';
544 562
 		$query_parameters['board'] = $board;
545 563
 		$context['querystring_board_limits'] = ';board=' . $board . '.%1$d';
546
-	}
547
-	elseif (!empty($_REQUEST['boards']))
564
+	} elseif (!empty($_REQUEST['boards']))
548 565
 	{
549 566
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
550
-		foreach ($_REQUEST['boards'] as $i => $b)
551
-			$_REQUEST['boards'][$i] = (int) $b;
567
+		foreach ($_REQUEST['boards'] as $i => $b) {
568
+					$_REQUEST['boards'][$i] = (int) $b;
569
+		}
552 570
 
553 571
 		$request = $smcFunc['db_query']('', '
554 572
 			SELECT b.id_board
@@ -560,22 +578,24 @@  discard block
 block discarded – undo
560 578
 			)
561 579
 		);
562 580
 		$boards = array();
563
-		while ($row = $smcFunc['db_fetch_assoc']($request))
564
-			$boards[] = $row['id_board'];
581
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
582
+					$boards[] = $row['id_board'];
583
+		}
565 584
 		$smcFunc['db_free_result']($request);
566 585
 
567
-		if (empty($boards))
568
-			fatal_lang_error('error_no_boards_selected');
586
+		if (empty($boards)) {
587
+					fatal_lang_error('error_no_boards_selected');
588
+		}
569 589
 
570 590
 		$query_this_board = 'id_board IN ({array_int:boards})';
571 591
 		$query_parameters['boards'] = $boards;
572 592
 		$context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d';
573
-	}
574
-	elseif (!empty($_REQUEST['c']))
593
+	} elseif (!empty($_REQUEST['c']))
575 594
 	{
576 595
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
577
-		foreach ($_REQUEST['c'] as $i => $c)
578
-			$_REQUEST['c'][$i] = (int) $c;
596
+		foreach ($_REQUEST['c'] as $i => $c) {
597
+					$_REQUEST['c'][$i] = (int) $c;
598
+		}
579 599
 
580 600
 		$see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
581 601
 		$request = $smcFunc['db_query']('', '
@@ -588,18 +608,19 @@  discard block
 block discarded – undo
588 608
 			)
589 609
 		);
590 610
 		$boards = array();
591
-		while ($row = $smcFunc['db_fetch_assoc']($request))
592
-			$boards[] = $row['id_board'];
611
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
612
+					$boards[] = $row['id_board'];
613
+		}
593 614
 		$smcFunc['db_free_result']($request);
594 615
 
595
-		if (empty($boards))
596
-			fatal_lang_error('error_no_boards_selected');
616
+		if (empty($boards)) {
617
+					fatal_lang_error('error_no_boards_selected');
618
+		}
597 619
 
598 620
 		$query_this_board = 'id_board IN ({array_int:boards})';
599 621
 		$query_parameters['boards'] = $boards;
600 622
 		$context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d';
601
-	}
602
-	else
623
+	} else
603 624
 	{
604 625
 		$see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
605 626
 		// Don't bother to show deleted posts!
@@ -613,12 +634,14 @@  discard block
 block discarded – undo
613 634
 			)
614 635
 		);
615 636
 		$boards = array();
616
-		while ($row = $smcFunc['db_fetch_assoc']($request))
617
-			$boards[] = $row['id_board'];
637
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
638
+					$boards[] = $row['id_board'];
639
+		}
618 640
 		$smcFunc['db_free_result']($request);
619 641
 
620
-		if (empty($boards))
621
-			fatal_lang_error('error_no_boards_available', false);
642
+		if (empty($boards)) {
643
+					fatal_lang_error('error_no_boards_available', false);
644
+		}
622 645
 
623 646
 		$query_this_board = 'id_board IN ({array_int:boards})';
624 647
 		$query_parameters['boards'] = $boards;
@@ -680,13 +703,14 @@  discard block
 block discarded – undo
680 703
 		'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies']
681 704
 	);
682 705
 
683
-	if ($context['showing_all_topics'])
684
-		$context['linktree'][] = array(
706
+	if ($context['showing_all_topics']) {
707
+			$context['linktree'][] = array(
685 708
 			'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'],
686 709
 			'name' => $txt['unread_topics_all']
687 710
 		);
688
-	else
689
-		$txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits']));
711
+	} else {
712
+			$txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits']));
713
+	}
690 714
 
691 715
 	loadTemplate('Recent');
692 716
 	loadTemplate('MessageIndex');
@@ -694,8 +718,9 @@  discard block
 block discarded – undo
694 718
 
695 719
 	// Setup the default topic icons... for checking they exist and the like ;)
696 720
 	$context['icon_sources'] = array();
697
-	foreach ($context['stable_icons'] as $icon)
698
-		$context['icon_sources'][$icon] = 'images_url';
721
+	foreach ($context['stable_icons'] as $icon) {
722
+			$context['icon_sources'][$icon] = 'images_url';
723
+	}
699 724
 
700 725
 	$is_topics = $_REQUEST['action'] == 'unread';
701 726
 
@@ -725,8 +750,7 @@  discard block
 block discarded – undo
725 750
 			);
726 751
 			list ($earliest_msg) = $smcFunc['db_fetch_row']($request);
727 752
 			$smcFunc['db_free_result']($request);
728
-		}
729
-		else
753
+		} else
730 754
 		{
731 755
 			$request = $smcFunc['db_query']('', '
732 756
 				SELECT MIN(lmr.id_msg)
@@ -742,14 +766,14 @@  discard block
 block discarded – undo
742 766
 		}
743 767
 
744 768
 		// This is needed in case of topics marked unread.
745
-		if (empty($earliest_msg))
746
-			$earliest_msg = 0;
747
-		else
769
+		if (empty($earliest_msg)) {
770
+					$earliest_msg = 0;
771
+		} else
748 772
 		{
749 773
 			// Using caching, when possible, to ignore the below slow query.
750
-			if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time())
751
-				$earliest_msg2 = $_SESSION['cached_log_time'][1];
752
-			else
774
+			if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) {
775
+							$earliest_msg2 = $_SESSION['cached_log_time'][1];
776
+			} else
753 777
 			{
754 778
 				// This query is pretty slow, but it's needed to ensure nothing crucial is ignored.
755 779
 				$request = $smcFunc['db_query']('', '
@@ -764,8 +788,9 @@  discard block
 block discarded – undo
764 788
 				$smcFunc['db_free_result']($request);
765 789
 
766 790
 				// In theory this could be zero, if the first ever post is unread, so fudge it ;)
767
-				if ($earliest_msg2 == 0)
768
-					$earliest_msg2 = -1;
791
+				if ($earliest_msg2 == 0) {
792
+									$earliest_msg2 = -1;
793
+				}
769 794
 
770 795
 				$_SESSION['cached_log_time'] = array(time(), $earliest_msg2);
771 796
 			}
@@ -803,9 +828,9 @@  discard block
 block discarded – undo
803 828
 				'db_error_skip' => true,
804 829
 			))
805 830
 		) !== false;
831
+	} else {
832
+			$have_temp_table = false;
806 833
 	}
807
-	else
808
-		$have_temp_table = false;
809 834
 
810 835
 	if ($context['showing_all_topics'] && $have_temp_table)
811 836
 	{
@@ -851,14 +876,15 @@  discard block
 block discarded – undo
851 876
 
852 877
 			$context['topics'] = array();
853 878
 			$context['no_topic_listing'] = true;
854
-			if ($context['querystring_board_limits'] == ';start=%1$d')
855
-				$context['querystring_board_limits'] = '';
856
-			else
857
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
879
+			if ($context['querystring_board_limits'] == ';start=%1$d') {
880
+							$context['querystring_board_limits'] = '';
881
+			} else {
882
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
883
+			}
858 884
 			return;
885
+		} else {
886
+					$min_message = (int) $min_message;
859 887
 		}
860
-		else
861
-			$min_message = (int) $min_message;
862 888
 
863 889
 		$request = $smcFunc['db_query']('substring', '
864 890
 			SELECT ' . $select_clause . '
@@ -887,8 +913,7 @@  discard block
 block discarded – undo
887 913
 				'limit' => $context['topics_per_page'],
888 914
 			))
889 915
 		);
890
-	}
891
-	elseif ($is_topics)
916
+	} elseif ($is_topics)
892 917
 	{
893 918
 		$request = $smcFunc['db_query']('', '
894 919
 			SELECT COUNT(*), MIN(t.id_last_msg)
@@ -939,14 +964,15 @@  discard block
 block discarded – undo
939 964
 
940 965
 			$context['topics'] = array();
941 966
 			$context['no_topic_listing'] = true;
942
-			if ($context['querystring_board_limits'] == ';start=%d')
943
-				$context['querystring_board_limits'] = '';
944
-			else
945
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
967
+			if ($context['querystring_board_limits'] == ';start=%d') {
968
+							$context['querystring_board_limits'] = '';
969
+			} else {
970
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
971
+			}
946 972
 			return;
973
+		} else {
974
+					$min_message = (int) $min_message;
947 975
 		}
948
-		else
949
-			$min_message = (int) $min_message;
950 976
 
951 977
 		$request = $smcFunc['db_query']('substring', '
952 978
 			SELECT ' . $select_clause . '
@@ -976,8 +1002,7 @@  discard block
 block discarded – undo
976 1002
 				'limit' => $context['topics_per_page'],
977 1003
 			))
978 1004
 		);
979
-	}
980
-	else
1005
+	} else
981 1006
 	{
982 1007
 		if ($modSettings['totalMessages'] > 100000)
983 1008
 		{
@@ -1029,8 +1054,8 @@  discard block
 block discarded – undo
1029 1054
 			) !== false;
1030 1055
 
1031 1056
 			// If that worked, create a sample of the log_topics table too.
1032
-			if ($have_temp_table)
1033
-				$have_temp_table = $smcFunc['db_query']('', '
1057
+			if ($have_temp_table) {
1058
+							$have_temp_table = $smcFunc['db_query']('', '
1034 1059
 					CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in (
1035 1060
 						PRIMARY KEY (id_topic)
1036 1061
 					)
@@ -1043,6 +1068,7 @@  discard block
 block discarded – undo
1043 1068
 						'db_error_skip' => true,
1044 1069
 					)
1045 1070
 				) !== false;
1071
+			}
1046 1072
 		}
1047 1073
 
1048 1074
 		if (!empty($have_temp_table))
@@ -1058,8 +1084,7 @@  discard block
 block discarded – undo
1058 1084
 			);
1059 1085
 			list ($num_topics) = $smcFunc['db_fetch_row']($request);
1060 1086
 			$smcFunc['db_free_result']($request);
1061
-		}
1062
-		else
1087
+		} else
1063 1088
 		{
1064 1089
 			$request = $smcFunc['db_query']('unread_fetch_topic_count', '
1065 1090
 				SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg)
@@ -1100,15 +1125,16 @@  discard block
 block discarded – undo
1100 1125
 		{
1101 1126
 			$context['topics'] = array();
1102 1127
 			$context['no_topic_listing'] = true;
1103
-			if ($context['querystring_board_limits'] == ';start=%d')
1104
-				$context['querystring_board_limits'] = '';
1105
-			else
1106
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1128
+			if ($context['querystring_board_limits'] == ';start=%d') {
1129
+							$context['querystring_board_limits'] = '';
1130
+			} else {
1131
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1132
+			}
1107 1133
 			return;
1108 1134
 		}
1109 1135
 
1110
-		if (!empty($have_temp_table))
1111
-			$request = $smcFunc['db_query']('', '
1136
+		if (!empty($have_temp_table)) {
1137
+					$request = $smcFunc['db_query']('', '
1112 1138
 				SELECT t.id_topic
1113 1139
 				FROM {db_prefix}topics_posted_in AS t
1114 1140
 					LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic)
@@ -1122,8 +1148,8 @@  discard block
 block discarded – undo
1122 1148
 					'limit' => $context['topics_per_page'],
1123 1149
 				))
1124 1150
 			);
1125
-		else
1126
-			$request = $smcFunc['db_query']('', '
1151
+		} else {
1152
+					$request = $smcFunc['db_query']('', '
1127 1153
 				SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'].'
1128 1154
 				FROM {db_prefix}topics AS t
1129 1155
 					INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : '
@@ -1147,10 +1173,12 @@  discard block
 block discarded – undo
1147 1173
 					'sort' => $_REQUEST['sort'],
1148 1174
 				))
1149 1175
 			);
1176
+		}
1150 1177
 
1151 1178
 		$topics = array();
1152
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1153
-			$topics[] = $row['id_topic'];
1179
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1180
+					$topics[] = $row['id_topic'];
1181
+		}
1154 1182
 		$smcFunc['db_free_result']($request);
1155 1183
 
1156 1184
 		// Sanity... where have you gone?
@@ -1158,10 +1186,11 @@  discard block
 block discarded – undo
1158 1186
 		{
1159 1187
 			$context['topics'] = array();
1160 1188
 			$context['no_topic_listing'] = true;
1161
-			if ($context['querystring_board_limits'] == ';start=%d')
1162
-				$context['querystring_board_limits'] = '';
1163
-			else
1164
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1189
+			if ($context['querystring_board_limits'] == ';start=%d') {
1190
+							$context['querystring_board_limits'] = '';
1191
+			} else {
1192
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1193
+			}
1165 1194
 			return;
1166 1195
 		}
1167 1196
 
@@ -1195,8 +1224,9 @@  discard block
 block discarded – undo
1195 1224
 
1196 1225
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1197 1226
 	{
1198
-		if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
1199
-			continue;
1227
+		if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') {
1228
+					continue;
1229
+		}
1200 1230
 
1201 1231
 		$topic_ids[] = $row['id_topic'];
1202 1232
 
@@ -1204,11 +1234,13 @@  discard block
 block discarded – undo
1204 1234
 		{
1205 1235
 			// Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise.
1206 1236
 			$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
1207
-			if ($smcFunc['strlen']($row['first_body']) > 128)
1208
-				$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...';
1237
+			if ($smcFunc['strlen']($row['first_body']) > 128) {
1238
+							$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...';
1239
+			}
1209 1240
 			$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
1210
-			if ($smcFunc['strlen']($row['last_body']) > 128)
1211
-				$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...';
1241
+			if ($smcFunc['strlen']($row['last_body']) > 128) {
1242
+							$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...';
1243
+			}
1212 1244
 
1213 1245
 			// Censor the subject and message preview.
1214 1246
 			censorText($row['first_subject']);
@@ -1219,23 +1251,22 @@  discard block
 block discarded – undo
1219 1251
 			{
1220 1252
 				$row['last_subject'] = $row['first_subject'];
1221 1253
 				$row['last_body'] = $row['first_body'];
1222
-			}
1223
-			else
1254
+			} else
1224 1255
 			{
1225 1256
 				censorText($row['last_subject']);
1226 1257
 				censorText($row['last_body']);
1227 1258
 			}
1228
-		}
1229
-		else
1259
+		} else
1230 1260
 		{
1231 1261
 			$row['first_body'] = '';
1232 1262
 			$row['last_body'] = '';
1233 1263
 			censorText($row['first_subject']);
1234 1264
 
1235
-			if ($row['id_first_msg'] == $row['id_last_msg'])
1236
-				$row['last_subject'] = $row['first_subject'];
1237
-			else
1238
-				censorText($row['last_subject']);
1265
+			if ($row['id_first_msg'] == $row['id_last_msg']) {
1266
+							$row['last_subject'] = $row['first_subject'];
1267
+			} else {
1268
+							censorText($row['last_subject']);
1269
+			}
1239 1270
 		}
1240 1271
 
1241 1272
 		// Decide how many pages the topic should have.
@@ -1247,22 +1278,24 @@  discard block
 block discarded – undo
1247 1278
 			$pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $topic_length, $messages_per_page, true, false);
1248 1279
 
1249 1280
 			// If we can use all, show all.
1250
-			if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages'])
1251
-				$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
1281
+			if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) {
1282
+							$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
1283
+			}
1284
+		} else {
1285
+					$pages = '';
1252 1286
 		}
1253 1287
 
1254
-		else
1255
-			$pages = '';
1256
-
1257 1288
 		// We need to check the topic icons exist... you can never be too sure!
1258 1289
 		if (!empty($modSettings['messageIconChecks_enable']))
1259 1290
 		{
1260 1291
 			// First icon first... as you'd expect.
1261
-			if (!isset($context['icon_sources'][$row['first_icon']]))
1262
-				$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1292
+			if (!isset($context['icon_sources'][$row['first_icon']])) {
1293
+							$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1294
+			}
1263 1295
 			// Last icon... last... duh.
1264
-			if (!isset($context['icon_sources'][$row['last_icon']]))
1265
-				$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1296
+			if (!isset($context['icon_sources'][$row['last_icon']])) {
1297
+							$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1298
+			}
1266 1299
 		}
1267 1300
 
1268 1301
 		// Force the recycling icon if appropriate
@@ -1276,12 +1309,14 @@  discard block
 block discarded – undo
1276 1309
 		$colorClass = 'windowbg';
1277 1310
 
1278 1311
 		// Sticky topics should get a different color, too.
1279
-		if ($row['is_sticky'])
1280
-			$colorClass .= ' sticky';
1312
+		if ($row['is_sticky']) {
1313
+					$colorClass .= ' sticky';
1314
+		}
1281 1315
 
1282 1316
 		// Locked topics get special treatment as well.
1283
-		if ($row['locked'])
1284
-			$colorClass .= ' locked';
1317
+		if ($row['locked']) {
1318
+					$colorClass .= ' locked';
1319
+		}
1285 1320
 
1286 1321
 		// And build the array.
1287 1322
 		$context['topics'][$row['id_topic']] = array(
@@ -1378,8 +1413,9 @@  discard block
 block discarded – undo
1378 1413
 		);
1379 1414
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1380 1415
 		{
1381
-			if (empty($context['topics'][$row['id_topic']]['is_posted_in']))
1382
-				$context['topics'][$row['id_topic']]['is_posted_in'] = true;
1416
+			if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) {
1417
+							$context['topics'][$row['id_topic']]['is_posted_in'] = true;
1418
+			}
1383 1419
 		}
1384 1420
 		$smcFunc['db_free_result']($result);
1385 1421
 	}
@@ -1394,28 +1430,30 @@  discard block
 block discarded – undo
1394 1430
 			'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="'.  $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']),
1395 1431
 		);
1396 1432
 
1397
-		if ($context['showCheckboxes'])
1398
-			$context['recent_buttons']['markselectread'] = array(
1433
+		if ($context['showCheckboxes']) {
1434
+					$context['recent_buttons']['markselectread'] = array(
1399 1435
 				'text' => 'quick_mod_markread',
1400 1436
 				'image' => 'markselectedread.png',
1401 1437
 				'url' => 'javascript:document.quickModForm.submit();',
1402 1438
 			);
1439
+		}
1403 1440
 
1404
-		if (!empty($context['topics']) && !$context['showing_all_topics'])
1405
-			$context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true);
1406
-	}
1407
-	elseif (!$is_topics && isset($context['topics_to_mark']))
1441
+		if (!empty($context['topics']) && !$context['showing_all_topics']) {
1442
+					$context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true);
1443
+		}
1444
+	} elseif (!$is_topics && isset($context['topics_to_mark']))
1408 1445
 	{
1409 1446
 		$context['recent_buttons'] = array(
1410 1447
 			'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read']  .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']),
1411 1448
 		);
1412 1449
 
1413
-		if ($context['showCheckboxes'])
1414
-			$context['recent_buttons']['markselectread'] = array(
1450
+		if ($context['showCheckboxes']) {
1451
+					$context['recent_buttons']['markselectread'] = array(
1415 1452
 				'text' => 'quick_mod_markread',
1416 1453
 				'image' => 'markselectedread.png',
1417 1454
 				'url' => 'javascript:document.quickModForm.submit();',
1418 1455
 			);
1456
+		}
1419 1457
 	}
1420 1458
 
1421 1459
 	// Allow mods to add additional buttons here
Please login to merge, or discard this patch.
Sources/CacheAPI-smf.php 1 patch
Braces   +36 added lines, -26 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
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
@@ -43,8 +44,9 @@  discard block
 block discarded – undo
43 44
 	{
44 45
 		$supported = is_writable($this->cachedir);
45 46
 
46
-		if ($test)
47
-			return $supported;
47
+		if ($test) {
48
+					return $supported;
49
+		}
48 50
 		return parent::isSupported() && $supported;
49 51
 	}
50 52
 
@@ -61,11 +63,13 @@  discard block
 block discarded – undo
61 63
 		{
62 64
 			// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
63 65
 			// causing newer files to take effect a while later.
64
-			if (function_exists('opcache_invalidate'))
65
-				opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
66
+			if (function_exists('opcache_invalidate')) {
67
+							opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
68
+			}
66 69
 
67
-			if (function_exists('apc_delete_file'))
68
-				@apc_delete_file($cachedir . '/data_' . $key . '.php');
70
+			if (function_exists('apc_delete_file')) {
71
+							@apc_delete_file($cachedir . '/data_' . $key . '.php');
72
+			}
69 73
 
70 74
 			// php will cache file_exists et all, we can't 100% depend on its results so proceed with caution
71 75
 			@include($cachedir . '/data_' . $key . '.php');
@@ -89,16 +93,18 @@  discard block
 block discarded – undo
89 93
 
90 94
 		// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
91 95
 		// causing newer files to take effect a while later.
92
-		if (function_exists('opcache_invalidate'))
93
-			opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
96
+		if (function_exists('opcache_invalidate')) {
97
+					opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
98
+		}
94 99
 
95
-		if (function_exists('apc_delete_file'))
96
-			@apc_delete_file($cachedir . '/data_' . $key . '.php');
100
+		if (function_exists('apc_delete_file')) {
101
+					@apc_delete_file($cachedir . '/data_' . $key . '.php');
102
+		}
97 103
 
98 104
 		// Otherwise custom cache?
99
-		if ($value === null)
100
-			@unlink($cachedir . '/data_' . $key . '.php');
101
-		else
105
+		if ($value === null) {
106
+					@unlink($cachedir . '/data_' . $key . '.php');
107
+		} else
102 108
 		{
103 109
 			$cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>';
104 110
 
@@ -109,9 +115,9 @@  discard block
 block discarded – undo
109 115
 			{
110 116
 				@unlink($cachedir . '/data_' . $key . '.php');
111 117
 				return false;
118
+			} else {
119
+							return true;
112 120
 			}
113
-			else
114
-				return true;
115 121
 		}
116 122
 	}
117 123
 
@@ -123,15 +129,17 @@  discard block
 block discarded – undo
123 129
 		$cachedir = $this->cachedir;
124 130
 
125 131
 		// No directory = no game.
126
-		if (!is_dir($cachedir))
127
-			return;
132
+		if (!is_dir($cachedir)) {
133
+					return;
134
+		}
128 135
 
129 136
 		// Remove the files in SMF's own disk cache, if any
130 137
 		$dh = opendir($cachedir);
131 138
 		while ($file = readdir($dh))
132 139
 		{
133
-			if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type))
134
-				@unlink($cachedir . '/' . $file);
140
+			if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) {
141
+							@unlink($cachedir . '/' . $file);
142
+			}
135 143
 		}
136 144
 		closedir($dh);
137 145
 
@@ -165,8 +173,9 @@  discard block
 block discarded – undo
165 173
 		$config_vars[] = $txt['cache_smf_settings'];
166 174
 		$config_vars[] = array('cachedir', $txt['cachedir'], 'file', 'text', 36, 'cache_cachedir');
167 175
 
168
-		if (!isset($context['settings_post_javascript']))
169
-			$context['settings_post_javascript'] = '';
176
+		if (!isset($context['settings_post_javascript'])) {
177
+					$context['settings_post_javascript'] = '';
178
+		}
170 179
 
171 180
 		$context['settings_post_javascript'] .= '
172 181
 			$("#cache_accelerator").change(function (e) {
@@ -187,10 +196,11 @@  discard block
 block discarded – undo
187 196
 		global $cachedir;
188 197
 
189 198
 		// If its invalid, use SMF's.
190
-		if (is_null($dir) || !is_writable($dir))
191
-			$this->cachedir = $cachedir;
192
-		else
193
-			$this->cachedir = $dir;
199
+		if (is_null($dir) || !is_writable($dir)) {
200
+					$this->cachedir = $cachedir;
201
+		} else {
202
+					$this->cachedir = $dir;
203
+		}
194 204
 	}
195 205
 
196 206
 	/**
Please login to merge, or discard this patch.
Sources/SearchAPI-Fulltext.php 1 patch
Braces   +44 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 4
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
  * Class fulltext_search
@@ -98,8 +99,9 @@  discard block
 block discarded – undo
98 99
 			$smcFunc['db_free_result']($request);
99 100
 		}
100 101
 		// 4 is the MySQL default...
101
-		else
102
-			$min_word_length = 4;
102
+		else {
103
+					$min_word_length = 4;
104
+		}
103 105
 
104 106
 		return $min_word_length;
105 107
 	}
@@ -138,8 +140,7 @@  discard block
 block discarded – undo
138 140
 					$wordsSearch['words'][] = trim($word, "/*- ");
139 141
 					$wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"';
140 142
 				}
141
-			}
142
-			elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
143
+			} elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
143 144
 			{
144 145
 				// short words have feelings too
145 146
 				$wordsSearch['words'][] = trim($word, "/*- ");
@@ -149,8 +150,9 @@  discard block
 block discarded – undo
149 150
 
150 151
 		$fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"';
151 152
 		$wordsSearch['indexed_words'][] = $fulltextWord;
152
-		if ($isExcluded)
153
-			$wordsExclude[] = $fulltextWord;
153
+		if ($isExcluded) {
154
+					$wordsExclude[] = $fulltextWord;
155
+		}
154 156
 	}
155 157
 
156 158
 	/**
@@ -166,41 +168,50 @@  discard block
 block discarded – undo
166 168
 		$query_where = array();
167 169
 		$query_params = $search_data['params'];
168 170
 
169
-		if ($query_params['id_search'])
170
-			$query_select['id_search'] = '{int:id_search}';
171
+		if ($query_params['id_search']) {
172
+					$query_select['id_search'] = '{int:id_search}';
173
+		}
171 174
 
172 175
 		$count = 0;
173
-		if (empty($modSettings['search_simple_fulltext']))
174
-			foreach ($words['words'] as $regularWord)
176
+		if (empty($modSettings['search_simple_fulltext'])) {
177
+					foreach ($words['words'] as $regularWord)
175 178
 			{
176 179
 				$query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}';
180
+		}
177 181
 				$query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
178 182
 			}
179 183
 
180
-		if ($query_params['user_query'])
181
-			$query_where[] = '{raw:user_query}';
182
-		if ($query_params['board_query'])
183
-			$query_where[] = 'm.id_board {raw:board_query}';
184
+		if ($query_params['user_query']) {
185
+					$query_where[] = '{raw:user_query}';
186
+		}
187
+		if ($query_params['board_query']) {
188
+					$query_where[] = 'm.id_board {raw:board_query}';
189
+		}
184 190
 
185
-		if ($query_params['topic'])
186
-			$query_where[] = 'm.id_topic = {int:topic}';
187
-		if ($query_params['min_msg_id'])
188
-			$query_where[] = 'm.id_msg >= {int:min_msg_id}';
189
-		if ($query_params['max_msg_id'])
190
-			$query_where[] = 'm.id_msg <= {int:max_msg_id}';
191
+		if ($query_params['topic']) {
192
+					$query_where[] = 'm.id_topic = {int:topic}';
193
+		}
194
+		if ($query_params['min_msg_id']) {
195
+					$query_where[] = 'm.id_msg >= {int:min_msg_id}';
196
+		}
197
+		if ($query_params['max_msg_id']) {
198
+					$query_where[] = 'm.id_msg <= {int:max_msg_id}';
199
+		}
191 200
 
192 201
 		$count = 0;
193
-		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index']))
194
-			foreach ($query_params['excluded_phrases'] as $phrase)
202
+		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) {
203
+					foreach ($query_params['excluded_phrases'] as $phrase)
195 204
 			{
196 205
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}';
206
+		}
197 207
 				$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), '\\\'') . '[[:>:]]';
198 208
 			}
199 209
 		$count = 0;
200
-		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index']))
201
-			foreach ($query_params['excluded_subject_words'] as $excludedWord)
210
+		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) {
211
+					foreach ($query_params['excluded_subject_words'] as $excludedWord)
202 212
 			{
203 213
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}';
214
+		}
204 215
 				$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), '\\\'') . '[[:>:]]';
205 216
 			}
206 217
 
@@ -212,12 +223,11 @@  discard block
 block discarded – undo
212 223
 
213 224
 				$query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:body_match})';
214 225
 				$query_params['language_ftx'] = $language_ftx;
226
+			} else {
227
+							$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
215 228
 			}
216
-			else
217
-				$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
218 229
 			$query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words']));
219
-		}
220
-		else
230
+		} else
221 231
 		{
222 232
 			$query_params['boolean_match'] = '';
223 233
 
@@ -231,10 +241,10 @@  discard block
 block discarded – undo
231 241
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' ';
232 242
 					$row++;
233 243
 				}
234
-			}
235
-			else
236
-				foreach ($words['indexed_words'] as $fulltextWord)
244
+			} else {
245
+							foreach ($words['indexed_words'] as $fulltextWord)
237 246
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' ';
247
+			}
238 248
 
239 249
 			$query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1);
240 250
 
@@ -246,9 +256,9 @@  discard block
 block discarded – undo
246 256
 
247 257
 					$query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:boolean_match})';
248 258
 					$query_params['language_ftx'] = $language_ftx;
259
+				} else {
260
+									$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
249 261
 				}
250
-				else
251
-					$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
252 262
 			}
253 263
 
254 264
 		}
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +164 added lines, -128 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -102,19 +106,20 @@  discard block
 block discarded – undo
102 106
 			list (,, $timeout) = smf_json_decode($_COOKIE[$cookiename], true);
103 107
 
104 108
 			// That didn't work... Maybe it's using serialize?
105
-			if (is_null($timeout))
106
-				list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
107
-		}
108
-		elseif (isset($_SESSION['login_' . $cookiename]))
109
+			if (is_null($timeout)) {
110
+							list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
111
+			}
112
+		} elseif (isset($_SESSION['login_' . $cookiename]))
109 113
 		{
110 114
 			list (,, $timeout) = smf_json_decode($_SESSION['login_' . $cookiename]);
111 115
 
112 116
 			// Try for old format
113
-			if (is_null($timeout))
114
-				list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
117
+			if (is_null($timeout)) {
118
+							list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
119
+			}
120
+		} else {
121
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
115 122
 		}
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
118 123
 
119 124
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 125
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -125,16 +130,18 @@  discard block
 block discarded – undo
125 130
 			$tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
126 131
 
127 132
 			// If that didn't work, try unserialize instead...
128
-			if (is_null($tfadata))
129
-				$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
133
+			if (is_null($tfadata)) {
134
+							$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
135
+			}
130 136
 
131 137
 			list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
132 138
 
133 139
 			// If we're preserving the cookie, reset it with updated salt
134
-			if ($preserve && time() < $exp)
135
-				setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
136
-			else
137
-				setTFACookie(-3600, 0, '');
140
+			if ($preserve && time() < $exp) {
141
+							setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
142
+			} else {
143
+							setTFACookie(-3600, 0, '');
144
+			}
138 145
 		}
139 146
 
140 147
 		setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
@@ -145,20 +152,20 @@  discard block
 block discarded – undo
145 152
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
146 153
 	{
147 154
 		// Strike!  You're outta there!
148
-		if ($_GET['member'] != $user_info['id'])
149
-			fatal_lang_error('login_cookie_error', false);
155
+		if ($_GET['member'] != $user_info['id']) {
156
+					fatal_lang_error('login_cookie_error', false);
157
+		}
150 158
 
151 159
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
152 160
 
153 161
 		// Some whitelisting for login_url...
154
-		if (empty($_SESSION['login_url']))
155
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
156
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
162
+		if (empty($_SESSION['login_url'])) {
163
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
164
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
157 165
 		{
158 166
 			unset ($_SESSION['login_url']);
159 167
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
160
-		}
161
-		else
168
+		} else
162 169
 		{
163 170
 			// Best not to clutter the session data too much...
164 171
 			$temp = $_SESSION['login_url'];
@@ -169,8 +176,9 @@  discard block
 block discarded – undo
169 176
 	}
170 177
 
171 178
 	// Beyond this point you are assumed to be a guest trying to login.
172
-	if (!$user_info['is_guest'])
173
-		redirectexit();
179
+	if (!$user_info['is_guest']) {
180
+			redirectexit();
181
+	}
174 182
 
175 183
 	// Are you guessing with a script?
176 184
 	checkSession();
@@ -178,18 +186,21 @@  discard block
 block discarded – undo
178 186
 	spamProtection('login');
179 187
 
180 188
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
181
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
182
-		$_SESSION['login_url'] = $_SESSION['old_url'];
189
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
190
+			$_SESSION['login_url'] = $_SESSION['old_url'];
191
+	}
183 192
 
184 193
 	// Been guessing a lot, haven't we?
185
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
186
-		fatal_lang_error('login_threshold_fail', 'critical');
194
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
195
+			fatal_lang_error('login_threshold_fail', 'critical');
196
+	}
187 197
 
188 198
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
189
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
190
-		$modSettings['cookieTime'] = 3153600;
191
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
192
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
199
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
200
+			$modSettings['cookieTime'] = 3153600;
201
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
202
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
203
+	}
193 204
 
194 205
 	loadLanguage('Login');
195 206
 	// Load the template stuff.
@@ -309,8 +320,9 @@  discard block
 block discarded – undo
309 320
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
310 321
 
311 322
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
312
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
313
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
323
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
324
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
325
+			}
314 326
 
315 327
 			// phpBB3 users new hashing.  We now support it as well ;).
316 328
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -330,27 +342,29 @@  discard block
 block discarded – undo
330 342
 			// Some common md5 ones.
331 343
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
332 344
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
333
-		}
334
-		elseif (strlen($user_settings['passwd']) == 40)
345
+		} elseif (strlen($user_settings['passwd']) == 40)
335 346
 		{
336 347
 			// Maybe they are using a hash from before the password fix.
337 348
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
338 349
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
339 350
 
340 351
 			// BurningBoard3 style of hashing.
341
-			if (!empty($modSettings['enable_password_conversion']))
342
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
352
+			if (!empty($modSettings['enable_password_conversion'])) {
353
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
354
+			}
343 355
 
344 356
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
345 357
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
346 358
 			{
347 359
 				// Try iconv first, for no particular reason.
348
-				if (function_exists('iconv'))
349
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
360
+				if (function_exists('iconv')) {
361
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
362
+				}
350 363
 
351 364
 				// Say it aint so, iconv failed!
352
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
353
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
365
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
366
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
367
+				}
354 368
 			}
355 369
 		}
356 370
 
@@ -380,8 +394,9 @@  discard block
 block discarded – undo
380 394
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
381 395
 
382 396
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
383
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
384
-				redirectexit('action=reminder');
397
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
398
+							redirectexit('action=reminder');
399
+			}
385 400
 			// We'll give you another chance...
386 401
 			else
387 402
 			{
@@ -392,8 +407,7 @@  discard block
 block discarded – undo
392 407
 				return;
393 408
 			}
394 409
 		}
395
-	}
396
-	elseif (!empty($user_settings['passwd_flood']))
410
+	} elseif (!empty($user_settings['passwd_flood']))
397 411
 	{
398 412
 		// Let's be sure they weren't a little hacker.
399 413
 		validatePasswordFlood($user_settings['id_member'], $user_settings['passwd_flood'], true);
@@ -410,8 +424,9 @@  discard block
 block discarded – undo
410 424
 	}
411 425
 
412 426
 	// Check their activation status.
413
-	if (!checkActivation())
414
-		return;
427
+	if (!checkActivation()) {
428
+			return;
429
+	}
415 430
 
416 431
 	DoLogin();
417 432
 }
@@ -423,8 +438,9 @@  discard block
 block discarded – undo
423 438
 {
424 439
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
425 440
 
426
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
427
-		fatal_lang_error('no_access', false);
441
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
442
+			fatal_lang_error('no_access', false);
443
+	}
428 444
 
429 445
 	loadLanguage('Profile');
430 446
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -432,8 +448,9 @@  discard block
 block discarded – undo
432 448
 	$member = $context['tfa_member'];
433 449
 
434 450
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
435
-	if (time() - $member['last_login'] < 120)
436
-		fatal_lang_error('tfa_wait', false);
451
+	if (time() - $member['last_login'] < 120) {
452
+			fatal_lang_error('tfa_wait', false);
453
+	}
437 454
 
438 455
 	$totp = new \TOTP\Auth($member['tfa_secret']);
439 456
 	$totp->setRange(1);
@@ -447,8 +464,9 @@  discard block
 block discarded – undo
447 464
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
448 465
 	{
449 466
 		// Check to ensure we're forcing SSL for authentication
450
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
451
-			fatal_lang_error('login_ssl_required');
467
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
468
+					fatal_lang_error('login_ssl_required');
469
+		}
452 470
 
453 471
 		$code = $_POST['tfa_code'];
454 472
 
@@ -458,20 +476,19 @@  discard block
 block discarded – undo
458 476
 
459 477
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve']));
460 478
 			redirectexit();
461
-		}
462
-		else
479
+		} else
463 480
 		{
464 481
 			validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true);
465 482
 
466 483
 			$context['tfa_error'] = true;
467 484
 			$context['tfa_value'] = $_POST['tfa_code'];
468 485
 		}
469
-	}
470
-	elseif (!empty($_POST['tfa_backup']))
486
+	} elseif (!empty($_POST['tfa_backup']))
471 487
 	{
472 488
 		// Check to ensure we're forcing SSL for authentication
473
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
474
-			fatal_lang_error('login_ssl_required');
489
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
490
+					fatal_lang_error('login_ssl_required');
491
+		}
475 492
 
476 493
 		$backup = $_POST['tfa_backup'];
477 494
 
@@ -485,8 +502,7 @@  discard block
 block discarded – undo
485 502
 			));
486 503
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
487 504
 			redirectexit('action=profile;area=tfasetup;backup');
488
-		}
489
-		else
505
+		} else
490 506
 		{
491 507
 			validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true);
492 508
 
@@ -509,8 +525,9 @@  discard block
 block discarded – undo
509 525
 {
510 526
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
511 527
 
512
-	if (!isset($context['login_errors']))
513
-		$context['login_errors'] = array();
528
+	if (!isset($context['login_errors'])) {
529
+			$context['login_errors'] = array();
530
+	}
514 531
 
515 532
 	// What is the true activation status of this account?
516 533
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -522,8 +539,9 @@  discard block
 block discarded – undo
522 539
 		return false;
523 540
 	}
524 541
 	// Awaiting approval still?
525
-	elseif ($activation_status == 3)
526
-		fatal_lang_error('still_awaiting_approval', 'user');
542
+	elseif ($activation_status == 3) {
543
+			fatal_lang_error('still_awaiting_approval', 'user');
544
+	}
527 545
 	// Awaiting deletion, changed their mind?
528 546
 	elseif ($activation_status == 4)
529 547
 	{
@@ -531,8 +549,7 @@  discard block
 block discarded – undo
531 549
 		{
532 550
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
533 551
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
534
-		}
535
-		else
552
+		} else
536 553
 		{
537 554
 			$context['disable_login_hashing'] = true;
538 555
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -572,8 +589,9 @@  discard block
 block discarded – undo
572 589
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
573 590
 
574 591
 	// Reset the login threshold.
575
-	if (isset($_SESSION['failed_login']))
576
-		unset($_SESSION['failed_login']);
592
+	if (isset($_SESSION['failed_login'])) {
593
+			unset($_SESSION['failed_login']);
594
+	}
577 595
 
578 596
 	$user_info['is_guest'] = false;
579 597
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -595,16 +613,18 @@  discard block
 block discarded – undo
595 613
 			'id_member' => $user_info['id'],
596 614
 		)
597 615
 	);
598
-	if ($smcFunc['db_num_rows']($request) == 1)
599
-		$_SESSION['first_login'] = true;
600
-	else
601
-		unset($_SESSION['first_login']);
616
+	if ($smcFunc['db_num_rows']($request) == 1) {
617
+			$_SESSION['first_login'] = true;
618
+	} else {
619
+			unset($_SESSION['first_login']);
620
+	}
602 621
 	$smcFunc['db_free_result']($request);
603 622
 
604 623
 	// You've logged in, haven't you?
605 624
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
606
-	if (empty($user_settings['tfa_secret']))
607
-		$update['last_login'] = time();
625
+	if (empty($user_settings['tfa_secret'])) {
626
+			$update['last_login'] = time();
627
+	}
608 628
 	updateMemberData($user_info['id'], $update);
609 629
 
610 630
 	// Get rid of the online entry for that old guest....
@@ -618,8 +638,8 @@  discard block
 block discarded – undo
618 638
 	$_SESSION['log_time'] = 0;
619 639
 
620 640
 	// Log this entry, only if we have it enabled.
621
-	if (!empty($modSettings['loginHistoryDays']))
622
-		$smcFunc['db_insert']('insert',
641
+	if (!empty($modSettings['loginHistoryDays'])) {
642
+			$smcFunc['db_insert']('insert',
623 643
 			'{db_prefix}member_logins',
624 644
 			array(
625 645
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -631,13 +651,15 @@  discard block
 block discarded – undo
631 651
 				'id_member', 'time'
632 652
 			)
633 653
 		);
654
+	}
634 655
 
635 656
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
636
-	if (empty($maintenance) || allowedTo('admin_forum'))
637
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
638
-	else
639
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
640
-}
657
+	if (empty($maintenance) || allowedTo('admin_forum')) {
658
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
659
+	} else {
660
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
661
+	}
662
+	}
641 663
 
642 664
 /**
643 665
  * Logs the current user out of their account.
@@ -653,13 +675,15 @@  discard block
 block discarded – undo
653 675
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
654 676
 
655 677
 	// Make sure they aren't being auto-logged out.
656
-	if (!$internal)
657
-		checkSession('get');
678
+	if (!$internal) {
679
+			checkSession('get');
680
+	}
658 681
 
659 682
 	require_once($sourcedir . '/Subs-Auth.php');
660 683
 
661
-	if (isset($_SESSION['pack_ftp']))
662
-		$_SESSION['pack_ftp'] = null;
684
+	if (isset($_SESSION['pack_ftp'])) {
685
+			$_SESSION['pack_ftp'] = null;
686
+	}
663 687
 
664 688
 	// It won't be first login anymore.
665 689
 	unset($_SESSION['first_login']);
@@ -687,24 +711,27 @@  discard block
 block discarded – undo
687 711
 
688 712
 	// And some other housekeeping while we're at it.
689 713
 	$salt = substr(md5(mt_rand()), 0, 4);
690
-	if (!empty($user_info['id']))
691
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
714
+	if (!empty($user_info['id'])) {
715
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
716
+	}
692 717
 
693 718
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
694 719
 	{
695 720
 		$tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
696 721
 
697 722
 		// If that failed, try the old method
698
-		if (is_null($tfadata))
699
-			$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
723
+		if (is_null($tfadata)) {
724
+					$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
725
+		}
700 726
 
701 727
 		list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
702 728
 
703 729
 		// If we're preserving the cookie, reset it with updated salt
704
-		if ($preserve && time() < $exp)
705
-			setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
706
-		else
707
-			setTFACookie(-3600, 0, '');
730
+		if ($preserve && time() < $exp) {
731
+					setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
732
+		} else {
733
+					setTFACookie(-3600, 0, '');
734
+		}
708 735
 	}
709 736
 
710 737
 	session_destroy();
@@ -712,14 +739,13 @@  discard block
 block discarded – undo
712 739
 	// Off to the merry board index we go!
713 740
 	if ($redirect)
714 741
 	{
715
-		if (empty($_SESSION['logout_url']))
716
-			redirectexit('', $context['server']['needs_login_fix']);
717
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
742
+		if (empty($_SESSION['logout_url'])) {
743
+					redirectexit('', $context['server']['needs_login_fix']);
744
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
718 745
 		{
719 746
 			unset ($_SESSION['logout_url']);
720 747
 			redirectexit();
721
-		}
722
-		else
748
+		} else
723 749
 		{
724 750
 			$temp = $_SESSION['logout_url'];
725 751
 			unset($_SESSION['logout_url']);
@@ -752,8 +778,9 @@  discard block
 block discarded – undo
752 778
 function phpBB3_password_check($passwd, $passwd_hash)
753 779
 {
754 780
 	// Too long or too short?
755
-	if (strlen($passwd_hash) != 34)
756
-		return;
781
+	if (strlen($passwd_hash) != 34) {
782
+			return;
783
+	}
757 784
 
758 785
 	// Range of characters allowed.
759 786
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -764,8 +791,9 @@  discard block
 block discarded – undo
764 791
 	$salt = substr($passwd_hash, 4, 8);
765 792
 
766 793
 	$hash = md5($salt . $passwd, true);
767
-	for (; $count != 0; --$count)
768
-		$hash = md5($hash . $passwd, true);
794
+	for (; $count != 0; --$count) {
795
+			$hash = md5($hash . $passwd, true);
796
+	}
769 797
 
770 798
 	$output = substr($passwd_hash, 0, 12);
771 799
 	$i = 0;
@@ -774,21 +802,25 @@  discard block
 block discarded – undo
774 802
 		$value = ord($hash[$i++]);
775 803
 		$output .= $range[$value & 0x3f];
776 804
 
777
-		if ($i < 16)
778
-			$value |= ord($hash[$i]) << 8;
805
+		if ($i < 16) {
806
+					$value |= ord($hash[$i]) << 8;
807
+		}
779 808
 
780 809
 		$output .= $range[($value >> 6) & 0x3f];
781 810
 
782
-		if ($i++ >= 16)
783
-			break;
811
+		if ($i++ >= 16) {
812
+					break;
813
+		}
784 814
 
785
-		if ($i < 16)
786
-			$value |= ord($hash[$i]) << 16;
815
+		if ($i < 16) {
816
+					$value |= ord($hash[$i]) << 16;
817
+		}
787 818
 
788 819
 		$output .= $range[($value >> 12) & 0x3f];
789 820
 
790
-		if ($i++ >= 16)
791
-			break;
821
+		if ($i++ >= 16) {
822
+					break;
823
+		}
792 824
 
793 825
 		$output .= $range[($value >> 18) & 0x3f];
794 826
 	}
@@ -819,8 +851,9 @@  discard block
 block discarded – undo
819 851
 		require_once($sourcedir . '/Subs-Auth.php');
820 852
 		setLoginCookie(-3600, 0);
821 853
 
822
-		if (isset($_SESSION['login_' . $cookiename]))
823
-			unset($_SESSION['login_' . $cookiename]);
854
+		if (isset($_SESSION['login_' . $cookiename])) {
855
+					unset($_SESSION['login_' . $cookiename]);
856
+		}
824 857
 	}
825 858
 
826 859
 	// We need a member!
@@ -834,8 +867,9 @@  discard block
 block discarded – undo
834 867
 	}
835 868
 
836 869
 	// Right, have we got a flood value?
837
-	if ($password_flood_value !== false)
838
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
870
+	if ($password_flood_value !== false) {
871
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
872
+	}
839 873
 
840 874
 	// Timestamp or number of tries invalid?
841 875
 	if (empty($number_tries) || empty($time_stamp))
@@ -851,15 +885,17 @@  discard block
 block discarded – undo
851 885
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
852 886
 
853 887
 		// They are trying too fast, make them wait longer
854
-		if ($time_stamp < time() - 10)
855
-			$time_stamp = time();
888
+		if ($time_stamp < time() - 10) {
889
+					$time_stamp = time();
890
+		}
856 891
 	}
857 892
 
858 893
 	$number_tries++;
859 894
 
860 895
 	// Broken the law?
861
-	if ($number_tries > 5)
862
-		fatal_lang_error('login_threshold_brute_fail', 'critical');
896
+	if ($number_tries > 5) {
897
+			fatal_lang_error('login_threshold_brute_fail', 'critical');
898
+	}
863 899
 
864 900
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
865 901
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/PackageGet.php 1 patch
Braces   +197 added lines, -154 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Browse the list of package servers, add servers...
@@ -43,13 +44,15 @@  discard block
 block discarded – undo
43 44
 	);
44 45
 
45 46
 	// Now let's decide where we are taking this...
46
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
47
-		$context['sub_action'] = $_REQUEST['sa'];
47
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
48
+			$context['sub_action'] = $_REQUEST['sa'];
49
+	}
48 50
 	// We need to support possible old javascript links...
49
-	elseif (isset($_GET['pgdownload']))
50
-		$context['sub_action'] = 'download';
51
-	else
52
-		$context['sub_action'] = 'servers';
51
+	elseif (isset($_GET['pgdownload'])) {
52
+			$context['sub_action'] = 'download';
53
+	} else {
54
+			$context['sub_action'] = 'servers';
55
+	}
53 56
 
54 57
 	// We need to force the "Download" tab as selected.
55 58
 	$context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'packageget';
@@ -141,17 +144,19 @@  discard block
 block discarded – undo
141 144
 			{
142 145
 				require_once($sourcedir . '/Class-Package.php');
143 146
 				$ftp = new ftp_connection(null);
147
+			} elseif ($ftp->error !== false && !isset($ftp_error)) {
148
+							$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
144 149
 			}
145
-			elseif ($ftp->error !== false && !isset($ftp_error))
146
-				$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
147 150
 
148 151
 			list ($username, $detect_path, $found_path) = $ftp->detect_path($packagesdir);
149 152
 
150
-			if ($found_path || !isset($_POST['ftp_path']))
151
-				$_POST['ftp_path'] = $detect_path;
153
+			if ($found_path || !isset($_POST['ftp_path'])) {
154
+							$_POST['ftp_path'] = $detect_path;
155
+			}
152 156
 
153
-			if (!isset($_POST['ftp_username']))
154
-				$_POST['ftp_username'] = $username;
157
+			if (!isset($_POST['ftp_username'])) {
158
+							$_POST['ftp_username'] = $username;
159
+			}
155 160
 
156 161
 			$context['package_ftp'] = array(
157 162
 				'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'),
@@ -160,8 +165,7 @@  discard block
 block discarded – undo
160 165
 				'path' => $_POST['ftp_path'],
161 166
 				'error' => empty($ftp_error) ? null : $ftp_error,
162 167
 			);
163
-		}
164
-		else
168
+		} else
165 169
 		{
166 170
 			$context['package_download_broken'] = false;
167 171
 
@@ -203,8 +207,9 @@  discard block
 block discarded – undo
203 207
 
204 208
 	if (isset($_GET['server']))
205 209
 	{
206
-		if ($_GET['server'] == '')
207
-			redirectexit('action=admin;area=packages;get');
210
+		if ($_GET['server'] == '') {
211
+					redirectexit('action=admin;area=packages;get');
212
+		}
208 213
 
209 214
 		$server = (int) $_GET['server'];
210 215
 
@@ -222,17 +227,18 @@  discard block
 block discarded – undo
222 227
 		$smcFunc['db_free_result']($request);
223 228
 
224 229
 		// If the server does not exist, dump out.
225
-		if (empty($url))
226
-			fatal_lang_error('couldnt_connect', false);
230
+		if (empty($url)) {
231
+					fatal_lang_error('couldnt_connect', false);
232
+		}
227 233
 
228 234
 		// If there is a relative link, append to the stored server url.
229
-		if (isset($_GET['relative']))
230
-			$url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative'];
235
+		if (isset($_GET['relative'])) {
236
+					$url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative'];
237
+		}
231 238
 
232 239
 		// Clear any "absolute" URL.  Since "server" is present, "absolute" is garbage.
233 240
 		unset($_GET['absolute']);
234
-	}
235
-	elseif (isset($_GET['absolute']) && $_GET['absolute'] != '')
241
+	} elseif (isset($_GET['absolute']) && $_GET['absolute'] != '')
236 242
 	{
237 243
 		// Initialize the requried variables.
238 244
 		$server = '';
@@ -256,16 +262,19 @@  discard block
 block discarded – undo
256 262
 		}
257 263
 	}
258 264
 	// Minimum required parameter did not exist so dump out.
259
-	else
260
-		fatal_lang_error('couldnt_connect', false);
265
+	else {
266
+			fatal_lang_error('couldnt_connect', false);
267
+	}
261 268
 
262 269
 	// Attempt to connect.  If unsuccessful... try the URL.
263
-	if (!isset($_GET['package']) || file_exists($_GET['package']))
264
-		$_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language'];
270
+	if (!isset($_GET['package']) || file_exists($_GET['package'])) {
271
+			$_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language'];
272
+	}
265 273
 
266 274
 	// Check to be sure the packages.xml file actually exists where it is should be... or dump out.
267
-	if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package']))
268
-		fatal_lang_error('packageget_unable', false, array($url . '/index.php'));
275
+	if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package'])) {
276
+			fatal_lang_error('packageget_unable', false, array($url . '/index.php'));
277
+	}
269 278
 
270 279
 	// Might take some time.
271 280
 	@set_time_limit(600);
@@ -275,8 +284,9 @@  discard block
 block discarded – undo
275 284
 	$listing = new xmlArray(fetch_web_data($_GET['package']), true);
276 285
 
277 286
 	// Errm.... empty file?  Try the URL....
278
-	if (!$listing->exists('package-list'))
279
-		fatal_lang_error('packageget_unable', false, array($url . '/index.php'));
287
+	if (!$listing->exists('package-list')) {
288
+			fatal_lang_error('packageget_unable', false, array($url . '/index.php'));
289
+	}
280 290
 
281 291
 	// List out the packages...
282 292
 	$context['package_list'] = array();
@@ -284,8 +294,9 @@  discard block
 block discarded – undo
284 294
 	$listing = $listing->path('package-list[0]');
285 295
 
286 296
 	// Use the package list's name if it exists.
287
-	if ($listing->exists('list-title'))
288
-		$name = $smcFunc['htmlspecialchars']($listing->fetch('list-title'));
297
+	if ($listing->exists('list-title')) {
298
+			$name = $smcFunc['htmlspecialchars']($listing->fetch('list-title'));
299
+	}
289 300
 
290 301
 	// Pick the correct template.
291 302
 	$context['sub_template'] = 'package_list';
@@ -300,28 +311,32 @@  discard block
 block discarded – undo
300 311
 
301 312
 	$installed_mods = array();
302 313
 	// Look through the list of installed mods...
303
-	foreach ($instmods as $installed_mod)
304
-		$installed_mods[$installed_mod['package_id']] = $installed_mod['version'];
314
+	foreach ($instmods as $installed_mod) {
315
+			$installed_mods[$installed_mod['package_id']] = $installed_mod['version'];
316
+	}
305 317
 
306 318
 	// Get default author and email if they exist.
307 319
 	if ($listing->exists('default-author'))
308 320
 	{
309 321
 		$default_author = $smcFunc['htmlspecialchars']($listing->fetch('default-author'));
310
-		if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL))
311
-			$default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email'));
322
+		if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL)) {
323
+					$default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email'));
324
+		}
312 325
 	}
313 326
 
314 327
 	// Get default web site if it exists.
315 328
 	if ($listing->exists('default-website'))
316 329
 	{
317 330
 		$default_website = $smcFunc['htmlspecialchars']($listing->fetch('default-website'));
318
-		if ($listing->exists('default-website/@title'))
319
-			$default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title'));
331
+		if ($listing->exists('default-website/@title')) {
332
+					$default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title'));
333
+		}
320 334
 	}
321 335
 
322 336
 	$the_version = strtr($forum_version, array('SMF ' => ''));
323
-	if (!empty($_SESSION['version_emulate']))
324
-		$the_version = $_SESSION['version_emulate'];
337
+	if (!empty($_SESSION['version_emulate'])) {
338
+			$the_version = $_SESSION['version_emulate'];
339
+	}
325 340
 
326 341
 	$packageNum = 0;
327 342
 	$packageSection = 0;
@@ -342,11 +357,13 @@  discard block
 block discarded – undo
342 357
 				'type' => $thisPackage->name(),
343 358
 			);
344 359
 
345
-			if (in_array($package['type'], array('title', 'text')))
346
-				$context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
360
+			if (in_array($package['type'], array('title', 'text'))) {
361
+							$context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
362
+			}
347 363
 			// It's a Title, Heading, Rule or Text.
348
-			elseif (in_array($package['type'], array('heading', 'rule')))
349
-				$package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
364
+			elseif (in_array($package['type'], array('heading', 'rule'))) {
365
+							$package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
366
+			}
350 367
 			// It's a Remote link.
351 368
 			elseif ($package['type'] == 'remote')
352 369
 			{
@@ -354,20 +371,21 @@  discard block
 block discarded – undo
354 371
 
355 372
 				if ($remote_type == 'relative' && substr($thisPackage->fetch('@href'), 0, 7) != 'http://' && substr($thisPackage->fetch('@href'), 0, 8) != 'https://')
356 373
 				{
357
-					if (isset($_GET['absolute']))
358
-						$current_url = $_GET['absolute'] . '/';
359
-					elseif (isset($_GET['relative']))
360
-						$current_url = $_GET['relative'] . '/';
361
-					else
362
-						$current_url = '';
374
+					if (isset($_GET['absolute'])) {
375
+											$current_url = $_GET['absolute'] . '/';
376
+					} elseif (isset($_GET['relative'])) {
377
+											$current_url = $_GET['relative'] . '/';
378
+					} else {
379
+											$current_url = '';
380
+					}
363 381
 
364 382
 					$current_url .= $thisPackage->fetch('@href');
365
-					if (isset($_GET['absolute']))
366
-						$package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url;
367
-					else
368
-						$package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url;
369
-				}
370
-				else
383
+					if (isset($_GET['absolute'])) {
384
+											$package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url;
385
+					} else {
386
+											$package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url;
387
+					}
388
+				} else
371 389
 				{
372 390
 					$current_url = $thisPackage->fetch('@href');
373 391
 					$package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url;
@@ -379,25 +397,28 @@  discard block
 block discarded – undo
379 397
 			// It's a package...
380 398
 			else
381 399
 			{
382
-				if (isset($_GET['absolute']))
383
-					$current_url = $_GET['absolute'] . '/';
384
-				elseif (isset($_GET['relative']))
385
-					$current_url = $_GET['relative'] . '/';
386
-				else
387
-					$current_url = '';
400
+				if (isset($_GET['absolute'])) {
401
+									$current_url = $_GET['absolute'] . '/';
402
+				} elseif (isset($_GET['relative'])) {
403
+									$current_url = $_GET['relative'] . '/';
404
+				} else {
405
+									$current_url = '';
406
+				}
388 407
 
389 408
 				$server_att = $server != '' ? ';server=' . $server : '';
390 409
 
391 410
 				$package += $thisPackage->to_array();
392 411
 
393
-				if (isset($package['website']))
394
-					unset($package['website']);
412
+				if (isset($package['website'])) {
413
+									unset($package['website']);
414
+				}
395 415
 				$package['author'] = array();
396 416
 
397
-				if ($package['description'] == '')
398
-					$package['description'] = $txt['package_no_description'];
399
-				else
400
-					$package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description'])));
417
+				if ($package['description'] == '') {
418
+									$package['description'] = $txt['package_no_description'];
419
+				} else {
420
+									$package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description'])));
421
+				}
401 422
 
402 423
 				$package['is_installed'] = isset($installed_mods[$package['id']]);
403 424
 				$package['is_current'] = $package['is_installed'] && ($installed_mods[$package['id']] == $package['version']);
@@ -406,12 +427,14 @@  discard block
 block discarded – undo
406 427
 				// This package is either not installed, or installed but old.  Is it supported on this version of SMF?
407 428
 				if (!$package['is_installed'] || (!$package['is_current'] && !$package['is_newer']))
408 429
 				{
409
-					if ($thisPackage->exists('version/@for'))
410
-						$package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for'));
430
+					if ($thisPackage->exists('version/@for')) {
431
+											$package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for'));
432
+					}
411 433
 				}
412 434
 				// Okay, it's already installed AND up to date.
413
-				else
414
-					$package['can_install'] = false;
435
+				else {
436
+									$package['can_install'] = false;
437
+				}
415 438
 
416 439
 				$already_exists = getPackageInfo(basename($package['filename']));
417 440
 				$package['download_conflict'] = is_array($already_exists) && $already_exists['id'] == $package['id'] && $already_exists['version'] != $package['version'];
@@ -423,40 +446,44 @@  discard block
 block discarded – undo
423 446
 
424 447
 				if ($thisPackage->exists('author') || isset($default_author))
425 448
 				{
426
-					if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL))
427
-						$package['author']['email'] = $thisPackage->fetch('author/@email');
428
-					elseif (isset($default_email))
429
-						$package['author']['email'] = $default_email;
430
-
431
-					if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '')
432
-						$package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author'));
433
-					else
434
-						$package['author']['name'] = $default_author;
435
-
436
-					if (!empty($package['author']['email']))
437
-						$package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>';
449
+					if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL)) {
450
+											$package['author']['email'] = $thisPackage->fetch('author/@email');
451
+					} elseif (isset($default_email)) {
452
+											$package['author']['email'] = $default_email;
453
+					}
454
+
455
+					if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '') {
456
+											$package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author'));
457
+					} else {
458
+											$package['author']['name'] = $default_author;
459
+					}
460
+
461
+					if (!empty($package['author']['email'])) {
462
+											$package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>';
463
+					}
438 464
 				}
439 465
 
440 466
 				if ($thisPackage->exists('website') || isset($default_website))
441 467
 				{
442
-					if ($thisPackage->exists('website') && $thisPackage->exists('website/@title'))
443
-						$package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title'));
444
-					elseif (isset($default_title))
445
-						$package['author']['website']['name'] = $default_title;
446
-					elseif ($thisPackage->exists('website'))
447
-						$package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website'));
448
-					else
449
-						$package['author']['website']['name'] = $default_website;
450
-
451
-					if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '')
452
-						$authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website'));
453
-					else
454
-						$authorhompage = $default_website;
468
+					if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) {
469
+											$package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title'));
470
+					} elseif (isset($default_title)) {
471
+											$package['author']['website']['name'] = $default_title;
472
+					} elseif ($thisPackage->exists('website')) {
473
+											$package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website'));
474
+					} else {
475
+											$package['author']['website']['name'] = $default_website;
476
+					}
477
+
478
+					if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') {
479
+											$authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website'));
480
+					} else {
481
+											$authorhompage = $default_website;
482
+					}
455 483
 
456 484
 					$package['author']['website']['href'] = $authorhompage;
457 485
 					$package['author']['website']['link'] = '<a href="' . $authorhompage . '">' . $package['author']['website']['name'] . '</a>';
458
-				}
459
-				else
486
+				} else
460 487
 				{
461 488
 					$package['author']['website']['href'] = '';
462 489
 					$package['author']['website']['link'] = '';
@@ -472,11 +499,13 @@  discard block
 block discarded – undo
472 499
 			$packageNum = in_array($package['type'], array('title', 'heading', 'text', 'remote', 'rule')) ? 0 : $packageNum + 1;
473 500
 			$package['count'] = $packageNum;
474 501
 
475
-			if (!in_array($package['type'], array('title', 'text')))
476
-				$context['package_list'][$packageSection]['items'][] = $package;
502
+			if (!in_array($package['type'], array('title', 'text'))) {
503
+							$context['package_list'][$packageSection]['items'][] = $package;
504
+			}
477 505
 
478
-			if ($package['count'] > 1)
479
-				$context['list_type'] = 'ol';
506
+			if ($package['count'] > 1) {
507
+							$context['list_type'] = 'ol';
508
+			}
480 509
 		}
481 510
 
482 511
 		$packageSection++;
@@ -489,8 +518,9 @@  discard block
 block discarded – undo
489 518
 	{
490 519
 		foreach ($packageSection['items'] as $i => $package)
491 520
 		{
492
-			if ($package['count'] == 0 || isset($package['can_install']))
493
-				continue;
521
+			if ($package['count'] == 0 || isset($package['can_install'])) {
522
+							continue;
523
+			}
494 524
 
495 525
 			$context['package_list'][$ps_id]['items'][$i]['can_install'] = false;
496 526
 
@@ -539,8 +569,9 @@  discard block
 block discarded – undo
539 569
 	checkSession('get');
540 570
 
541 571
 	// To download something, we need a valid server or url.
542
-	if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package'])))
543
-		fatal_lang_error('package_get_error_is_zero', false);
572
+	if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package']))) {
573
+			fatal_lang_error('package_get_error_is_zero', false);
574
+	}
544 575
 
545 576
 	if (isset($_GET['server']))
546 577
 	{
@@ -560,22 +591,23 @@  discard block
 block discarded – undo
560 591
 		$smcFunc['db_free_result']($request);
561 592
 
562 593
 		// If server does not exist then dump out.
563
-		if (empty($url))
564
-			fatal_lang_error('couldnt_connect', false);
594
+		if (empty($url)) {
595
+					fatal_lang_error('couldnt_connect', false);
596
+		}
565 597
 
566 598
 		$url = $url . '/';
567
-	}
568
-	else
599
+	} else
569 600
 	{
570 601
 		// Initialize the requried variables.
571 602
 		$server = '';
572 603
 		$url = '';
573 604
 	}
574 605
 
575
-	if (isset($_REQUEST['byurl']) && !empty($_POST['filename']))
576
-		$package_name = basename($_REQUEST['filename']);
577
-	else
578
-		$package_name = basename($_REQUEST['package']);
606
+	if (isset($_REQUEST['byurl']) && !empty($_POST['filename'])) {
607
+			$package_name = basename($_REQUEST['filename']);
608
+	} else {
609
+			$package_name = basename($_REQUEST['package']);
610
+	}
579 611
 
580 612
 	if (isset($_REQUEST['conflict']) || (isset($_REQUEST['auto']) && file_exists($packagesdir . '/' . $package_name)))
581 613
 	{
@@ -584,14 +616,15 @@  discard block
 block discarded – undo
584 616
 		{
585 617
 			$ext = substr($package_name, strrpos(substr($package_name, 0, -3), '.'));
586 618
 			$package_name = substr($package_name, 0, strrpos(substr($package_name, 0, -3), '.')) . '_';
619
+		} else {
620
+					$ext = '';
587 621
 		}
588
-		else
589
-			$ext = '';
590 622
 
591 623
 		// Find the first available.
592 624
 		$i = 1;
593
-		while (file_exists($packagesdir . '/' . $package_name . $i . $ext))
594
-			$i++;
625
+		while (file_exists($packagesdir . '/' . $package_name . $i . $ext)) {
626
+					$i++;
627
+		}
595 628
 
596 629
 		$package_name = $package_name . $i . $ext;
597 630
 	}
@@ -602,25 +635,28 @@  discard block
 block discarded – undo
602 635
 
603 636
 	// Done!  Did we get this package automatically?
604 637
 	// @ TODO: These are usually update packages.  Allowing both for now until more testing has been done.
605
-	if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto']))
606
-		redirectexit('action=admin;area=packages;sa=install;package=' . $package_name);
638
+	if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) {
639
+			redirectexit('action=admin;area=packages;sa=install;package=' . $package_name);
640
+	}
607 641
 
608 642
 	// You just downloaded a mod from SERVER_NAME_GOES_HERE.
609 643
 	$context['package_server'] = $server;
610 644
 
611 645
 	$context['package'] = getPackageInfo($package_name);
612 646
 
613
-	if (!is_array($context['package']))
614
-		fatal_lang_error('package_cant_download', false);
647
+	if (!is_array($context['package'])) {
648
+			fatal_lang_error('package_cant_download', false);
649
+	}
615 650
 
616
-	if ($context['package']['type'] == 'modification')
617
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>';
618
-	elseif ($context['package']['type'] == 'avatar')
619
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>';
620
-	elseif ($context['package']['type'] == 'language')
621
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>';
622
-	else
623
-		$context['package']['install']['link'] = '';
651
+	if ($context['package']['type'] == 'modification') {
652
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>';
653
+	} elseif ($context['package']['type'] == 'avatar') {
654
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>';
655
+	} elseif ($context['package']['type'] == 'language') {
656
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>';
657
+	} else {
658
+			$context['package']['install']['link'] = '';
659
+	}
624 660
 
625 661
 	// Does a 3rd party hook want to do some additional changes?
626 662
 	call_integration_hook('integrate_package_download');
@@ -646,10 +682,11 @@  discard block
 block discarded – undo
646 682
 	// @todo Use FTP if the Packages directory is not writable.
647 683
 
648 684
 	// Check the file was even sent!
649
-	if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '')
650
-		fatal_lang_error('package_upload_error_nofile');
651
-	elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name'])))
652
-		fatal_lang_error('package_upload_error_failed');
685
+	if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') {
686
+			fatal_lang_error('package_upload_error_nofile');
687
+	} elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) {
688
+			fatal_lang_error('package_upload_error_failed');
689
+	}
653 690
 
654 691
 	// Make sure it has a sane filename.
655 692
 	$_FILES['package']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['package']['name']);
@@ -666,8 +703,9 @@  discard block
 block discarded – undo
666 703
 	// Setup the destination and throw an error if the file is already there!
667 704
 	$destination = $packagesdir . '/' . $packageName;
668 705
 	// @todo Maybe just roll it like we do for downloads?
669
-	if (file_exists($destination))
670
-		fatal_lang_error('package_upload_error_exists');
706
+	if (file_exists($destination)) {
707
+			fatal_lang_error('package_upload_error_exists');
708
+	}
671 709
 
672 710
 	// Now move the file.
673 711
 	move_uploaded_file($_FILES['package']['tmp_name'], $destination);
@@ -690,12 +728,14 @@  discard block
 block discarded – undo
690 728
 	{
691 729
 		while ($package = readdir($dir))
692 730
 		{
693
-			if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip'))
694
-				continue;
731
+			if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) {
732
+							continue;
733
+			}
695 734
 
696 735
 			$packageInfo = getPackageInfo($package);
697
-			if (!is_array($packageInfo))
698
-				continue;
736
+			if (!is_array($packageInfo)) {
737
+							continue;
738
+			}
699 739
 
700 740
 			if ($packageInfo['id'] == $context['package']['id'] && $packageInfo['version'] == $context['package']['version'])
701 741
 			{
@@ -707,14 +747,15 @@  discard block
 block discarded – undo
707 747
 		closedir($dir);
708 748
 	}
709 749
 
710
-	if ($context['package']['type'] == 'modification')
711
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>';
712
-	elseif ($context['package']['type'] == 'avatar')
713
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>';
714
-	elseif ($context['package']['type'] == 'language')
715
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>';
716
-	else
717
-		$context['package']['install']['link'] = '';
750
+	if ($context['package']['type'] == 'modification') {
751
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>';
752
+	} elseif ($context['package']['type'] == 'avatar') {
753
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>';
754
+	} elseif ($context['package']['type'] == 'language') {
755
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>';
756
+	} else {
757
+			$context['package']['install']['link'] = '';
758
+	}
718 759
 
719 760
 	// Does a 3rd party hook want to do some additional changes?
720 761
 	call_integration_hook('integrate_package_upload');
@@ -737,16 +778,18 @@  discard block
 block discarded – undo
737 778
 	checkSession();
738 779
 
739 780
 	// If they put a slash on the end, get rid of it.
740
-	if (substr($_POST['serverurl'], -1) == '/')
741
-		$_POST['serverurl'] = substr($_POST['serverurl'], 0, -1);
781
+	if (substr($_POST['serverurl'], -1) == '/') {
782
+			$_POST['serverurl'] = substr($_POST['serverurl'], 0, -1);
783
+	}
742 784
 
743 785
 	// Are they both nice and clean?
744 786
 	$servername = trim($smcFunc['htmlspecialchars']($_POST['servername']));
745 787
 	$serverurl = trim($smcFunc['htmlspecialchars']($_POST['serverurl']));
746 788
 
747 789
 	// Make sure the URL has the correct prefix.
748
-	if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0)
749
-		$serverurl = 'http://' . $serverurl;
790
+	if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) {
791
+			$serverurl = 'http://' . $serverurl;
792
+	}
750 793
 
751 794
 	$smcFunc['db_insert']('',
752 795
 		'{db_prefix}package_servers',
Please login to merge, or discard this patch.