Completed
Pull Request — release-2.1 (#3807)
by Martyn
07:18
created
Sources/Subs-Admin.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
 
19 19
 /**
20 20
  * Get a list of versions that are currently installed on the server.
21
- * @param array $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server'
21
+ * @param string[] $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server'
22 22
  * @return array An array of versions (keys are same as what was in $checkFor, values are the versions)
23 23
  */
24 24
 function getServerVersions($checkFor)
Please login to merge, or discard this patch.
Braces   +124 added lines, -89 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get a list of versions that are currently installed on the server.
@@ -45,8 +46,7 @@  discard block
 block discarded – undo
45 46
 			$temp2 = $temp->getVersion();
46 47
 			$im_version = $temp2['versionString'];
47 48
 			$extension_version = 'Imagick ' . phpversion('Imagick');
48
-		}
49
-		else
49
+		} else
50 50
 		{
51 51
 			$im_version = MagickGetVersionString();
52 52
 			$extension_version = 'MagickWand ' . phpversion('MagickWand');
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	if (in_array('db_server', $checkFor))
62 62
 	{
63 63
 		db_extend();
64
-		if (!isset($db_connection) || $db_connection === false)
65
-			trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
-		else
64
+		if (!isset($db_connection) || $db_connection === false) {
65
+					trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
+		} else
67 67
 		{
68 68
 			$versions['db_engine'] = array('title' => sprintf($txt['support_versions_db_engine'], $smcFunc['db_title']), 'version' => '');
69 69
 			$versions['db_engine']['version'] = $smcFunc['db_get_engine']();
@@ -74,24 +74,31 @@  discard block
 block discarded – undo
74 74
 	}
75 75
 
76 76
 	// If we're using memcache we need the server info.
77
-	if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '')
78
-		get_memcached_server();
77
+	if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
78
+			get_memcached_server();
79
+	}
79 80
 
80 81
 	// Check to see if we have any accelerators installed...
81
-	if (in_array('phpa', $checkFor) && isset($_PHPA))
82
-		$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
83
-	if (in_array('apc', $checkFor) && extension_loaded('apc'))
84
-		$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
85
-	if (in_array('memcache', $checkFor) && function_exists('memcache_set'))
86
-		$versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached));
87
-	if (in_array('xcache', $checkFor) && function_exists('xcache_set'))
88
-		$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
82
+	if (in_array('phpa', $checkFor) && isset($_PHPA)) {
83
+			$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
84
+	}
85
+	if (in_array('apc', $checkFor) && extension_loaded('apc')) {
86
+			$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
87
+	}
88
+	if (in_array('memcache', $checkFor) && function_exists('memcache_set')) {
89
+			$versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached));
90
+	}
91
+	if (in_array('xcache', $checkFor) && function_exists('xcache_set')) {
92
+			$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
93
+	}
89 94
 
90
-	if (in_array('php', $checkFor))
91
-		$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
95
+	if (in_array('php', $checkFor)) {
96
+			$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
97
+	}
92 98
 
93
-	if (in_array('server', $checkFor))
94
-		$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
99
+	if (in_array('server', $checkFor)) {
100
+			$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
101
+	}
95 102
 
96 103
 	return $versions;
97 104
 }
@@ -131,11 +138,13 @@  discard block
 block discarded – undo
131 138
 		fclose($fp);
132 139
 
133 140
 		// The comment looks rougly like... that.
134
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
135
-			$version_info['file_versions']['SSI.php'] = $match[1];
141
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
142
+					$version_info['file_versions']['SSI.php'] = $match[1];
143
+		}
136 144
 		// Not found!  This is bad.
137
-		else
138
-			$version_info['file_versions']['SSI.php'] = '??';
145
+		else {
146
+					$version_info['file_versions']['SSI.php'] = '??';
147
+		}
139 148
 	}
140 149
 
141 150
 	// Do the paid subscriptions handler?
@@ -146,11 +155,13 @@  discard block
 block discarded – undo
146 155
 		fclose($fp);
147 156
 
148 157
 		// Found it?
149
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
150
-			$version_info['file_versions']['subscriptions.php'] = $match[1];
158
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
159
+					$version_info['file_versions']['subscriptions.php'] = $match[1];
160
+		}
151 161
 		// If we haven't how do we all get paid?
152
-		else
153
-			$version_info['file_versions']['subscriptions.php'] = '??';
162
+		else {
163
+					$version_info['file_versions']['subscriptions.php'] = '??';
164
+		}
154 165
 	}
155 166
 
156 167
 	// Load all the files in the Sources directory, except this file and the redirect.
@@ -165,11 +176,13 @@  discard block
 block discarded – undo
165 176
 			fclose($fp);
166 177
 
167 178
 			// Look for the version comment in the file header.
168
-			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
169
-				$version_info['file_versions'][$entry] = $match[1];
179
+			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
180
+							$version_info['file_versions'][$entry] = $match[1];
181
+			}
170 182
 			// It wasn't found, but the file was... show a '??'.
171
-			else
172
-				$version_info['file_versions'][$entry] = '??';
183
+			else {
184
+							$version_info['file_versions'][$entry] = '??';
185
+			}
173 186
 		}
174 187
 	}
175 188
 	$sources_dir->close();
@@ -188,11 +201,13 @@  discard block
 block discarded – undo
188 201
 				fclose($fp);
189 202
 
190 203
 				// Look for the version comment in the file header.
191
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
192
-					$version_info['tasks_versions'][$entry] = $match[1];
204
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
205
+									$version_info['tasks_versions'][$entry] = $match[1];
206
+				}
193 207
 				// It wasn't found, but the file was... show a '??'.
194
-				else
195
-					$version_info['tasks_versions'][$entry] = '??';
208
+				else {
209
+									$version_info['tasks_versions'][$entry] = '??';
210
+				}
196 211
 			}
197 212
 		}
198 213
 		$tasks_dir->close();
@@ -200,8 +215,9 @@  discard block
 block discarded – undo
200 215
 
201 216
 	// Load all the files in the default template directory - and the current theme if applicable.
202 217
 	$directories = array('default_template_versions' => $settings['default_theme_dir']);
203
-	if ($settings['theme_id'] != 1)
204
-		$directories += array('template_versions' => $settings['theme_dir']);
218
+	if ($settings['theme_id'] != 1) {
219
+			$directories += array('template_versions' => $settings['theme_dir']);
220
+	}
205 221
 
206 222
 	foreach ($directories as $type => $dirname)
207 223
 	{
@@ -216,11 +232,13 @@  discard block
 block discarded – undo
216 232
 				fclose($fp);
217 233
 
218 234
 				// Look for the version comment in the file header.
219
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
220
-					$version_info[$type][$entry] = $match[1];
235
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
236
+									$version_info[$type][$entry] = $match[1];
237
+				}
221 238
 				// It wasn't found, but the file was... show a '??'.
222
-				else
223
-					$version_info[$type][$entry] = '??';
239
+				else {
240
+									$version_info[$type][$entry] = '??';
241
+				}
224 242
 			}
225 243
 		}
226 244
 		$this_dir->close();
@@ -241,11 +259,13 @@  discard block
 block discarded – undo
241 259
 			list ($name, $language) = explode('.', $entry);
242 260
 
243 261
 			// Look for the version comment in the file header.
244
-			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1)
245
-				$version_info['default_language_versions'][$language][$name] = $match[1];
262
+			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) {
263
+							$version_info['default_language_versions'][$language][$name] = $match[1];
264
+			}
246 265
 			// It wasn't found, but the file was... show a '??'.
247
-			else
248
-				$version_info['default_language_versions'][$language][$name] = '??';
266
+			else {
267
+							$version_info['default_language_versions'][$language][$name] = '??';
268
+			}
249 269
 		}
250 270
 	}
251 271
 	$this_dir->close();
@@ -260,8 +280,9 @@  discard block
 block discarded – undo
260 280
 		ksort($version_info['tasks_versions']);
261 281
 
262 282
 		// For languages sort each language too.
263
-		foreach ($version_info['default_language_versions'] as $language => $dummy)
264
-			ksort($version_info['default_language_versions'][$language]);
283
+		foreach ($version_info['default_language_versions'] as $language => $dummy) {
284
+					ksort($version_info['default_language_versions'][$language]);
285
+		}
265 286
 	}
266 287
 	return $version_info;
267 288
 }
@@ -303,27 +324,31 @@  discard block
 block discarded – undo
303 324
 	$settingsArray = trim(file_get_contents($boarddir . '/Settings.php'));
304 325
 
305 326
 	// Break it up based on \r or \n, and then clean out extra characters.
306
-	if (strpos($settingsArray, "\n") !== false)
307
-		$settingsArray = explode("\n", $settingsArray);
308
-	elseif (strpos($settingsArray, "\r") !== false)
309
-		$settingsArray = explode("\r", $settingsArray);
310
-	else
311
-		return;
327
+	if (strpos($settingsArray, "\n") !== false) {
328
+			$settingsArray = explode("\n", $settingsArray);
329
+	} elseif (strpos($settingsArray, "\r") !== false) {
330
+			$settingsArray = explode("\r", $settingsArray);
331
+	} else {
332
+			return;
333
+	}
312 334
 
313 335
 	// Presumably, the file has to have stuff in it for this function to be called :P.
314
-	if (count($settingsArray) < 10)
315
-		return;
336
+	if (count($settingsArray) < 10) {
337
+			return;
338
+	}
316 339
 
317 340
 	// remove any /r's that made there way in here
318
-	foreach ($settingsArray as $k => $dummy)
319
-		$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
341
+	foreach ($settingsArray as $k => $dummy) {
342
+			$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
343
+	}
320 344
 
321 345
 	// go line by line and see whats changing
322 346
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
323 347
 	{
324 348
 		// Don't trim or bother with it if it's not a variable.
325
-		if (substr($settingsArray[$i], 0, 1) != '$')
326
-			continue;
349
+		if (substr($settingsArray[$i], 0, 1) != '$') {
350
+					continue;
351
+		}
327 352
 
328 353
 		$settingsArray[$i] = trim($settingsArray[$i]) . "\n";
329 354
 
@@ -335,8 +360,7 @@  discard block
 block discarded – undo
335 360
 			{
336 361
 				updateDbLastError($val);
337 362
 				unset($config_vars[$var]);
338
-			}
339
-			elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
363
+			} elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
340 364
 			{
341 365
 				$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
342 366
 				$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n";
@@ -347,34 +371,39 @@  discard block
 block discarded – undo
347 371
 		}
348 372
 
349 373
 		// End of the file ... maybe
350
-		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>')
351
-			$end = $i;
374
+		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') {
375
+					$end = $i;
376
+		}
352 377
 	}
353 378
 
354 379
 	// This should never happen, but apparently it is happening.
355
-	if (empty($end) || $end < 10)
356
-		$end = count($settingsArray) - 1;
380
+	if (empty($end) || $end < 10) {
381
+			$end = count($settingsArray) - 1;
382
+	}
357 383
 
358 384
 	// Still more variables to go?  Then lets add them at the end.
359 385
 	if (!empty($config_vars))
360 386
 	{
361
-		if (trim($settingsArray[$end]) == '?' . '>')
362
-			$settingsArray[$end++] = '';
363
-		else
364
-			$end++;
387
+		if (trim($settingsArray[$end]) == '?' . '>') {
388
+					$settingsArray[$end++] = '';
389
+		} else {
390
+					$end++;
391
+		}
365 392
 
366 393
 		// Add in any newly defined vars that were passed
367
-		foreach ($config_vars as $var => $val)
368
-			$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
394
+		foreach ($config_vars as $var => $val) {
395
+					$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
396
+		}
369 397
 
370 398
 		$settingsArray[$end] = '?' . '>';
399
+	} else {
400
+			$settingsArray[$end] = trim($settingsArray[$end]);
371 401
 	}
372
-	else
373
-		$settingsArray[$end] = trim($settingsArray[$end]);
374 402
 
375 403
 	// Sanity error checking: the file needs to be at least 12 lines.
376
-	if (count($settingsArray) < 12)
377
-		return;
404
+	if (count($settingsArray) < 12) {
405
+			return;
406
+	}
378 407
 
379 408
 	// Try to avoid a few pitfalls:
380 409
 	//  - like a possible race condition,
@@ -382,8 +411,9 @@  discard block
 block discarded – undo
382 411
 	//
383 412
 	// Check before you act: if cache is enabled, we can do a simple write test
384 413
 	// to validate that we even write things on this filesystem.
385
-	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
386
-		$cachedir = $boarddir . '/cache';
414
+	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
415
+			$cachedir = $boarddir . '/cache';
416
+	}
387 417
 
388 418
 	$test_fp = @fopen($cachedir . '/settings_update.tmp', "w+");
389 419
 	if ($test_fp)
@@ -419,16 +449,18 @@  discard block
 block discarded – undo
419 449
 			// Well this is not good at all, lets see if we can save this
420 450
 			$context['settings_message'] = 'settings_error';
421 451
 
422
-			if (file_exists($boarddir . '/Settings_bak.php'))
423
-				@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
452
+			if (file_exists($boarddir . '/Settings_bak.php')) {
453
+							@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
454
+			}
424 455
 		}
425 456
 	}
426 457
 
427 458
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
428 459
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
429
-	if (function_exists('opcache_invalidate'))
430
-		opcache_invalidate($boarddir . '/Settings.php', true);
431
-}
460
+	if (function_exists('opcache_invalidate')) {
461
+			opcache_invalidate($boarddir . '/Settings.php', true);
462
+	}
463
+	}
432 464
 
433 465
 /**
434 466
  * Saves the time of the last db error for the error log
@@ -454,8 +486,9 @@  discard block
 block discarded – undo
454 486
 	global $options, $context, $smcFunc, $settings, $user_info;
455 487
 
456 488
 	// This must exist!
457
-	if (!isset($context['admin_preferences']))
458
-		return false;
489
+	if (!isset($context['admin_preferences'])) {
490
+			return false;
491
+	}
459 492
 
460 493
 	// This is what we'll be saving.
461 494
 	$options['admin_preferences'] = json_encode($context['admin_preferences']);
@@ -519,8 +552,9 @@  discard block
 block discarded – undo
519 552
 	$emails_sent = array();
520 553
 	while ($row = $smcFunc['db_fetch_assoc']($request))
521 554
 	{
522
-		if (empty($prefs[$row['id_member']]['announcements']))
523
-			continue;
555
+		if (empty($prefs[$row['id_member']]['announcements'])) {
556
+					continue;
557
+		}
524 558
 
525 559
 		// Stick their particulars in the replacement data.
526 560
 		$replacements['IDMEMBER'] = $row['id_member'];
@@ -539,11 +573,12 @@  discard block
 block discarded – undo
539 573
 	$smcFunc['db_free_result']($request);
540 574
 
541 575
 	// Any additional users we must email this to?
542
-	if (!empty($additional_recipients))
543
-		foreach ($additional_recipients as $recipient)
576
+	if (!empty($additional_recipients)) {
577
+			foreach ($additional_recipients as $recipient)
544 578
 		{
545 579
 			if (in_array($recipient['email'], $emails_sent))
546 580
 				continue;
581
+	}
547 582
 
548 583
 			$replacements['IDMEMBER'] = $recipient['id'];
549 584
 			$replacements['REALNAME'] = $recipient['name'];
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@
 block discarded – undo
150 150
  *
151 151
  * @param bool $local Whether we want local cookies
152 152
  * @param bool $global Whether we want global cookies
153
- * @return array An array to set the cookie on with domain and path in it, in that order
153
+ * @return string An array to set the cookie on with domain and path in it, in that order
154 154
  */
155 155
 function url_parts($local, $global)
156 156
 {
Please login to merge, or discard this patch.
Braces   +160 added lines, -115 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -43,8 +44,9 @@  discard block
 block discarded – undo
43 44
 		$array = smf_json_decode($_COOKIE[$cookiename], true);
44 45
 
45 46
 		// Legacy format
46
-		if (is_null($array))
47
-			$array = safe_unserialize($_COOKIE[$cookiename]);
47
+		if (is_null($array)) {
48
+					$array = safe_unserialize($_COOKIE[$cookiename]);
49
+		}
48 50
 
49 51
 		// Out with the old, in with the new!
50 52
 		if (isset($array[3]) && $array[3] != $cookie_state)
@@ -62,8 +64,9 @@  discard block
 block discarded – undo
62 64
 	smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
63 65
 
64 66
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
65
-	if (empty($id) && !empty($modSettings['globalCookies']))
66
-		smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
67
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
68
+			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
69
+	}
67 70
 
68 71
 	// Any alias URLs?  This is mainly for use with frames, etc.
69 72
 	if (!empty($modSettings['forum_alias_urls']))
@@ -79,8 +82,9 @@  discard block
 block discarded – undo
79 82
 
80 83
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
81 84
 
82
-			if ($cookie_url[0] == '')
83
-				$cookie_url[0] = strtok($alias, '/');
85
+			if ($cookie_url[0] == '') {
86
+							$cookie_url[0] = strtok($alias, '/');
87
+			}
84 88
 
85 89
 			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
86 90
 		}
@@ -126,8 +130,9 @@  discard block
 block discarded – undo
126 130
 	$identifier = $cookiename . '_tfa';
127 131
 	$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
128 132
 
129
-	if ($preserve)
130
-		$cookie_length = 81600 * 30;
133
+	if ($preserve) {
134
+			$cookie_length = 81600 * 30;
135
+	}
131 136
 
132 137
 	// Get the data and path to set it on.
133 138
 	$data = json_encode(empty($id) ? array(0, '', 0, $cookie_state, false) : array($id, $secret, time() + $cookie_length, $cookie_state, $preserve));
@@ -137,8 +142,9 @@  discard block
 block discarded – undo
137 142
 	smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
138 143
 
139 144
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
140
-	if (empty($id) && !empty($modSettings['globalCookies']))
141
-		smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
145
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
146
+			smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
147
+	}
142 148
 
143 149
 	$_COOKIE[$identifier] = $data;
144 150
 }
@@ -160,23 +166,28 @@  discard block
 block discarded – undo
160 166
 	$parsed_url = parse_url($boardurl);
161 167
 
162 168
 	// Is local cookies off?
163
-	if (empty($parsed_url['path']) || !$local)
164
-		$parsed_url['path'] = '';
169
+	if (empty($parsed_url['path']) || !$local) {
170
+			$parsed_url['path'] = '';
171
+	}
165 172
 
166
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
167
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
173
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
174
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
175
+	}
168 176
 
169 177
 	// Globalize cookies across domains (filter out IP-addresses)?
170
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
171
-		$parsed_url['host'] = '.' . $parts[1];
178
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
179
+			$parsed_url['host'] = '.' . $parts[1];
180
+	}
172 181
 
173 182
 	// We shouldn't use a host at all if both options are off.
174
-	elseif (!$local && !$global)
175
-		$parsed_url['host'] = '';
183
+	elseif (!$local && !$global) {
184
+			$parsed_url['host'] = '';
185
+	}
176 186
 
177 187
 	// The host also shouldn't be set if there aren't any dots in it.
178
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
179
-		$parsed_url['host'] = '';
188
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
189
+			$parsed_url['host'] = '';
190
+	}
180 191
 
181 192
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
182 193
 }
@@ -195,8 +206,9 @@  discard block
 block discarded – undo
195 206
 	createToken('login');
196 207
 
197 208
 	// Never redirect to an attachment
198
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
199
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
209
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
210
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
211
+	}
200 212
 
201 213
 	$context['sub_template'] = 'kick_guest';
202 214
 	$context['page_title'] = $txt['login'];
@@ -251,10 +263,12 @@  discard block
 block discarded – undo
251 263
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
252 264
 		log_error($txt['security_wrong'], 'critical');
253 265
 
254
-		if (isset($_POST[$type . '_hash_pass']))
255
-			unset($_POST[$type . '_hash_pass']);
256
-		if (isset($_POST[$type . '_pass']))
257
-			unset($_POST[$type . '_pass']);
266
+		if (isset($_POST[$type . '_hash_pass'])) {
267
+					unset($_POST[$type . '_hash_pass']);
268
+		}
269
+		if (isset($_POST[$type . '_pass'])) {
270
+					unset($_POST[$type . '_pass']);
271
+		}
258 272
 
259 273
 		$context['incorrect_password'] = true;
260 274
 	}
@@ -267,15 +281,17 @@  discard block
 block discarded – undo
267 281
 
268 282
 	// Now go through $_POST.  Make sure the session hash is sent.
269 283
 	$_POST[$context['session_var']] = $context['session_id'];
270
-	foreach ($_POST as $k => $v)
271
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
284
+	foreach ($_POST as $k => $v) {
285
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
286
+	}
272 287
 
273 288
 	// Now we'll use the admin_login sub template of the Login template.
274 289
 	$context['sub_template'] = 'admin_login';
275 290
 
276 291
 	// And title the page something like "Login".
277
-	if (!isset($context['page_title']))
278
-		$context['page_title'] = $txt['login'];
292
+	if (!isset($context['page_title'])) {
293
+			$context['page_title'] = $txt['login'];
294
+	}
279 295
 
280 296
 	// The type of action.
281 297
 	$context['sessionCheckType'] = $type;
@@ -298,14 +314,15 @@  discard block
 block discarded – undo
298 314
 {
299 315
 	global $smcFunc;
300 316
 
301
-	if (!is_array($v))
302
-		return '
317
+	if (!is_array($v)) {
318
+			return '
303 319
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
304
-	else
320
+	} else
305 321
 	{
306 322
 		$ret = '';
307
-		foreach ($v as $k2 => $v2)
308
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
323
+		foreach ($v as $k2 => $v2) {
324
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
325
+		}
309 326
 
310 327
 		return $ret;
311 328
 	}
@@ -332,18 +349,20 @@  discard block
 block discarded – undo
332 349
 		foreach ($get as $k => $v)
333 350
 		{
334 351
 			// Only if it's not already in the $scripturl!
335
-			if (!isset($temp[$k]))
336
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
352
+			if (!isset($temp[$k])) {
353
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
354
+			}
337 355
 			// If it changed, put it out there, but with an ampersand.
338
-			elseif ($temp[$k] != $get[$k])
339
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
356
+			elseif ($temp[$k] != $get[$k]) {
357
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
358
+			}
340 359
 		}
341
-	}
342
-	else
360
+	} else
343 361
 	{
344 362
 		// Add up all the data from $_GET into get_data.
345
-		foreach ($get as $k => $v)
346
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
363
+		foreach ($get as $k => $v) {
364
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
365
+		}
347 366
 	}
348 367
 
349 368
 	$query_string = substr($query_string, 0, -1);
@@ -366,8 +385,9 @@  discard block
 block discarded – undo
366 385
 	global $scripturl, $user_info, $smcFunc;
367 386
 
368 387
 	// If it's not already an array, make it one.
369
-	if (!is_array($names))
370
-		$names = explode(',', $names);
388
+	if (!is_array($names)) {
389
+			$names = explode(',', $names);
390
+	}
371 391
 
372 392
 	$maybe_email = false;
373 393
 	foreach ($names as $i => $name)
@@ -378,10 +398,11 @@  discard block
 block discarded – undo
378 398
 		$maybe_email |= strpos($name, '@') !== false;
379 399
 
380 400
 		// Make it so standard wildcards will work. (* and ?)
381
-		if ($use_wildcards)
382
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
383
-		else
384
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
401
+		if ($use_wildcards) {
402
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
403
+		} else {
404
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
405
+		}
385 406
 	}
386 407
 
387 408
 	// What are we using to compare?
@@ -391,11 +412,12 @@  discard block
 block discarded – undo
391 412
 	$results = array();
392 413
 
393 414
 	// This ensures you can't search someones email address if you can't see it.
394
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
395
-		$email_condition = '
415
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
416
+			$email_condition = '
396 417
 			OR (email_address ' . $comparison . ' \'' . implode( '\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
397
-	else
398
-		$email_condition = '';
418
+	} else {
419
+			$email_condition = '';
420
+	}
399 421
 
400 422
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
401 423
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -453,10 +475,11 @@  discard block
 block discarded – undo
453 475
 	$context['template_layers'] = array();
454 476
 	$context['sub_template'] = 'find_members';
455 477
 
456
-	if (isset($_REQUEST['search']))
457
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
458
-	else
459
-		$_REQUEST['start'] = 0;
478
+	if (isset($_REQUEST['search'])) {
479
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
480
+	} else {
481
+			$_REQUEST['start'] = 0;
482
+	}
460 483
 
461 484
 	// Allow the user to pass the input to be added to to the box.
462 485
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -497,10 +520,10 @@  discard block
 block discarded – undo
497 520
 		);
498 521
 
499 522
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
523
+	} else {
524
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
525
+	}
500 526
 	}
501
-	else
502
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
503
-}
504 527
 
505 528
 /**
506 529
  * Outputs each member name on its own line.
@@ -516,8 +539,9 @@  discard block
 block discarded – undo
516 539
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
517 540
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
518 541
 
519
-	if (function_exists('iconv'))
520
-		header('Content-Type: text/plain; charset=UTF-8');
542
+	if (function_exists('iconv')) {
543
+			header('Content-Type: text/plain; charset=UTF-8');
544
+	}
521 545
 
522 546
 	$request = $smcFunc['db_query']('', '
523 547
 		SELECT real_name
@@ -537,14 +561,16 @@  discard block
 block discarded – undo
537 561
 		if (function_exists('iconv'))
538 562
 		{
539 563
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
540
-			if ($utf8)
541
-				$row['real_name'] = $utf8;
564
+			if ($utf8) {
565
+							$row['real_name'] = $utf8;
566
+			}
542 567
 		}
543 568
 
544 569
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
545 570
 
546
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
547
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
571
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
572
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
573
+		}
548 574
 
549 575
 		echo $row['real_name'], "\n";
550 576
 	}
@@ -601,9 +627,9 @@  discard block
 block discarded – undo
601 627
 
602 628
 		// Update the database...
603 629
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
630
+	} else {
631
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
604 632
 	}
605
-	else
606
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
607 633
 
608 634
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
609 635
 
@@ -634,31 +660,37 @@  discard block
 block discarded – undo
634 660
 	$errors = array();
635 661
 
636 662
 	// Don't use too long a name.
637
-	if ($smcFunc['strlen']($username) > 25)
638
-		$errors[] = array('lang', 'error_long_name');
663
+	if ($smcFunc['strlen']($username) > 25) {
664
+			$errors[] = array('lang', 'error_long_name');
665
+	}
639 666
 
640 667
 	// No name?!  How can you register with no name?
641
-	if ($username == '')
642
-		$errors[] = array('lang', 'need_username');
668
+	if ($username == '') {
669
+			$errors[] = array('lang', 'need_username');
670
+	}
643 671
 
644 672
 	// Only these characters are permitted.
645
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
646
-		$errors[] = array('lang', 'error_invalid_characters_username');
673
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
674
+			$errors[] = array('lang', 'error_invalid_characters_username');
675
+	}
647 676
 
648
-	if (stristr($username, $txt['guest_title']) !== false)
649
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
677
+	if (stristr($username, $txt['guest_title']) !== false) {
678
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
679
+	}
650 680
 
651 681
 	if ($check_reserved_name)
652 682
 	{
653 683
 		require_once($sourcedir . '/Subs-Members.php');
654
-		if (isReservedName($username, $memID, false))
655
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
684
+		if (isReservedName($username, $memID, false)) {
685
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
686
+		}
656 687
 	}
657 688
 
658
-	if ($return_error)
659
-		return $errors;
660
-	elseif (empty($errors))
661
-		return null;
689
+	if ($return_error) {
690
+			return $errors;
691
+	} elseif (empty($errors)) {
692
+			return null;
693
+	}
662 694
 
663 695
 	loadLanguage('Errors');
664 696
 	$error = $errors[0];
@@ -684,22 +716,26 @@  discard block
 block discarded – undo
684 716
 	global $modSettings, $smcFunc;
685 717
 
686 718
 	// Perform basic requirements first.
687
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
688
-		return 'short';
719
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
720
+			return 'short';
721
+	}
689 722
 
690 723
 	// Is this enough?
691
-	if (empty($modSettings['password_strength']))
692
-		return null;
724
+	if (empty($modSettings['password_strength'])) {
725
+			return null;
726
+	}
693 727
 
694 728
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
695
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
696
-		return 'restricted_words';
697
-	elseif ($smcFunc['strpos']($password, $username) !== false)
698
-		return 'restricted_words';
729
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
730
+			return 'restricted_words';
731
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
732
+			return 'restricted_words';
733
+	}
699 734
 
700 735
 	// If just medium, we're done.
701
-	if ($modSettings['password_strength'] == 1)
702
-		return null;
736
+	if ($modSettings['password_strength'] == 1) {
737
+			return null;
738
+	}
703 739
 
704 740
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
705 741
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -731,14 +767,16 @@  discard block
 block discarded – undo
731 767
 			)
732 768
 		);
733 769
 		$groups = array();
734
-		while ($row = $smcFunc['db_fetch_assoc']($request))
735
-			$groups[] = $row['id_group'];
770
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
771
+					$groups[] = $row['id_group'];
772
+		}
736 773
 		$smcFunc['db_free_result']($request);
737 774
 
738
-		if (empty($groups))
739
-			$group_query = '0=1';
740
-		else
741
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
775
+		if (empty($groups)) {
776
+					$group_query = '0=1';
777
+		} else {
778
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
779
+		}
742 780
 	}
743 781
 
744 782
 	// Then, same again, just the boards this time!
@@ -748,10 +786,11 @@  discard block
 block discarded – undo
748 786
 	{
749 787
 		$boards = boardsAllowedTo('moderate_board', true);
750 788
 
751
-		if (empty($boards))
752
-			$board_query = '0=1';
753
-		else
754
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
789
+		if (empty($boards)) {
790
+					$board_query = '0=1';
791
+		} else {
792
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
793
+		}
755 794
 	}
756 795
 
757 796
 	// What boards are they the moderator of?
@@ -766,8 +805,9 @@  discard block
 block discarded – undo
766 805
 				'current_member' => $user_info['id'],
767 806
 			)
768 807
 		);
769
-		while ($row = $smcFunc['db_fetch_assoc']($request))
770
-			$boards_mod[] = $row['id_board'];
808
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
809
+					$boards_mod[] = $row['id_board'];
810
+		}
771 811
 		$smcFunc['db_free_result']($request);
772 812
 
773 813
 		// Can any of the groups they're in moderate any of the boards?
@@ -779,8 +819,9 @@  discard block
 block discarded – undo
779 819
 				'groups' => $user_info['groups'],
780 820
 			)
781 821
 		);
782
-		while ($row = $smcFunc['db_fetch_assoc']($request))
783
-			$boards_mod[] = $row['id_board'];
822
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
823
+					$boards_mod[] = $row['id_board'];
824
+		}
784 825
 		$smcFunc['db_free_result']($request);
785 826
 
786 827
 		// Just in case we've got duplicates here...
@@ -825,10 +866,12 @@  discard block
 block discarded – undo
825 866
 	global $modSettings;
826 867
 
827 868
 	// In case a customization wants to override the default settings
828
-	if ($httponly === null)
829
-		$httponly = !empty($modSettings['httponlyCookies']);
830
-	if ($secure === null)
831
-		$secure = !empty($modSettings['secureCookies']);
869
+	if ($httponly === null) {
870
+			$httponly = !empty($modSettings['httponlyCookies']);
871
+	}
872
+	if ($secure === null) {
873
+			$secure = !empty($modSettings['secureCookies']);
874
+	}
832 875
 
833 876
 	// Intercept cookie?
834 877
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -848,8 +891,9 @@  discard block
 block discarded – undo
848 891
 function hash_password($username, $password, $cost = null)
849 892
 {
850 893
 	global $sourcedir, $smcFunc, $modSettings;
851
-	if (!function_exists('password_hash'))
852
-		require_once($sourcedir . '/Subs-Password.php');
894
+	if (!function_exists('password_hash')) {
895
+			require_once($sourcedir . '/Subs-Password.php');
896
+	}
853 897
 
854 898
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
855 899
 
@@ -881,8 +925,9 @@  discard block
 block discarded – undo
881 925
 function hash_verify_password($username, $password, $hash)
882 926
 {
883 927
 	global $sourcedir, $smcFunc;
884
-	if (!function_exists('password_verify'))
885
-		require_once($sourcedir . '/Subs-Password.php');
928
+	if (!function_exists('password_verify')) {
929
+			require_once($sourcedir . '/Subs-Password.php');
930
+	}
886 931
 
887 932
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
888 933
 }
Please login to merge, or discard this patch.
Sources/Subs-Db-mysqli.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
  * Backtrace, log, try to fix.
559 559
  *
560 560
  * @param string $db_string The DB string
561
- * @param object $connection The connection to use (if null, $db_connection is used)
561
+ * @param resource $connection The connection to use (if null, $db_connection is used)
562 562
  */
563 563
 function smf_db_error($db_string, $connection = null)
564 564
 {
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
  * @param array $data The data to insert
754 754
  * @param array $keys The keys for the table
755 755
  * @param bool $disable_trans Whether to disable transactions
756
- * @param object $connection The connection to use (if null, $db_connection is used)
756
+ * @param resource $connection The connection to use (if null, $db_connection is used)
757 757
  */
758 758
 function smf_db_insert($method = 'replace', $table, $columns, $data, $keys, $disable_trans = false, $connection = null)
759 759
 {
Please login to merge, or discard this patch.
Braces   +252 added lines, -185 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -58,9 +59,11 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource'            => 'smf_is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['persist']))
63
-		$db_server = 'p:' . $db_server;
64
+	if (!empty($db_options['persist'])) {
65
+			$db_server = 'p:' . $db_server;
66
+	}
64 67
 
65 68
 	$connection = mysqli_init();
66 69
 	
@@ -69,31 +72,35 @@  discard block
 block discarded – undo
69 72
 	$success = false;
70 73
 	
71 74
 	if ($connection) {
72
-		if (!empty($db_options['port']))
73
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
74
-		else
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
75
+		if (!empty($db_options['port'])) {
76
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
77
+		} else {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
79
+		}
76 80
 	}
77 81
 
78 82
 	// Something's wrong, show an error if its fatal (which we assume it is)
79 83
 	if ($success === false)
80 84
 	{
81
-		if (!empty($db_options['non_fatal']))
82
-			return null;
83
-		else
84
-			display_db_error();
85
+		if (!empty($db_options['non_fatal'])) {
86
+					return null;
87
+		} else {
88
+					display_db_error();
89
+		}
85 90
 	}
86 91
 
87 92
 	// Select the database, unless told not to
88
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
89
-		display_db_error();
93
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
94
+			display_db_error();
95
+	}
90 96
 
91 97
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
92
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
93
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
98
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
99
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
94 100
 		array(),
95 101
 		false
96 102
 	);
103
+	}
97 104
 
98 105
 	return $connection;
99 106
 }
@@ -164,37 +171,46 @@  discard block
 block discarded – undo
164 171
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 172
 
166 173
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
174
+	if (!is_object($connection)) {
175
+			display_db_error();
176
+	}
169 177
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
178
+	if ($matches[1] === 'db_prefix') {
179
+			return $db_prefix;
180
+	}
172 181
 
173
-	if ($matches[1] === 'query_see_board')
174
-		return $user_info['query_see_board'];
182
+	if ($matches[1] === 'query_see_board') {
183
+			return $user_info['query_see_board'];
184
+	}
175 185
 
176
-	if ($matches[1] === 'query_wanna_see_board')
177
-		return $user_info['query_wanna_see_board'];
186
+	if ($matches[1] === 'query_wanna_see_board') {
187
+			return $user_info['query_wanna_see_board'];
188
+	}
178 189
 
179
-	if ($matches[1] === 'empty')
180
-		return '\'\'';
190
+	if ($matches[1] === 'empty') {
191
+			return '\'\'';
192
+	}
181 193
 
182
-	if (!isset($matches[2]))
183
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
194
+	if (!isset($matches[2])) {
195
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
196
+	}
184 197
 
185
-	if ($matches[1] === 'literal')
186
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
198
+	if ($matches[1] === 'literal') {
199
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
200
+	}
187 201
 
188
-	if (!isset($values[$matches[2]]))
189
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
202
+	if (!isset($values[$matches[2]])) {
203
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
204
+	}
190 205
 
191 206
 	$replacement = $values[$matches[2]];
192 207
 
193 208
 	switch ($matches[1])
194 209
 	{
195 210
 		case 'int':
196
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
212
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			}
198 214
 			return (string) (int) $replacement;
199 215
 		break;
200 216
 
@@ -206,56 +222,63 @@  discard block
 block discarded – undo
206 222
 		case 'array_int':
207 223
 			if (is_array($replacement))
208 224
 			{
209
-				if (empty($replacement))
210
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+				if (empty($replacement)) {
226
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+				}
211 228
 
212 229
 				foreach ($replacement as $key => $value)
213 230
 				{
214
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
215
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
232
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+					}
216 234
 
217 235
 					$replacement[$key] = (string) (int) $value;
218 236
 				}
219 237
 
220 238
 				return implode(', ', $replacement);
239
+			} else {
240
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 241
 			}
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224 242
 
225 243
 		break;
226 244
 
227 245
 		case 'array_string':
228 246
 			if (is_array($replacement))
229 247
 			{
230
-				if (empty($replacement))
231
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
248
+				if (empty($replacement)) {
249
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+				}
232 251
 
233
-				foreach ($replacement as $key => $value)
234
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
252
+				foreach ($replacement as $key => $value) {
253
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
254
+				}
235 255
 
236 256
 				return implode(', ', $replacement);
257
+			} else {
258
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 259
 			}
238
-			else
239
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240 260
 		break;
241 261
 
242 262
 		case 'date':
243
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
244
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
245
-			else
246
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
264
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
265
+			} else {
266
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+			}
247 268
 		break;
248 269
 
249 270
 		case 'time':
250
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
251
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
252
-			else
253
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
272
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
273
+			} else {
274
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
275
+			}
254 276
 		break;
255 277
 
256 278
 		case 'float':
257
-			if (!is_numeric($replacement))
258
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+			if (!is_numeric($replacement)) {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
281
+			}
259 282
 			return (string) (float) $replacement;
260 283
 		break;
261 284
 
@@ -269,32 +292,37 @@  discard block
 block discarded – undo
269 292
 		break;
270 293
 
271 294
 		case 'inet':
272
-			if ($replacement == 'null' || $replacement == '')
273
-				return 'null';
274
-			if (!isValidIP($replacement))
275
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295
+			if ($replacement == 'null' || $replacement == '') {
296
+							return 'null';
297
+			}
298
+			if (!isValidIP($replacement)) {
299
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			}
276 301
 			//we don't use the native support of mysql > 5.6.2
277 302
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
278 303
 
279 304
 		case 'array_inet':
280 305
 			if (is_array($replacement))
281 306
 			{
282
-				if (empty($replacement))
283
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+				if (empty($replacement)) {
308
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
309
+				}
284 310
 
285 311
 				foreach ($replacement as $key => $value)
286 312
 				{
287
-					if ($replacement == 'null' || $replacement == '')
288
-						$replacement[$key] = 'null';
289
-					if (!isValidIP($value))
290
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
313
+					if ($replacement == 'null' || $replacement == '') {
314
+											$replacement[$key] = 'null';
315
+					}
316
+					if (!isValidIP($value)) {
317
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					}
291 319
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
292 320
 				}
293 321
 
294 322
 				return implode(', ', $replacement);
323
+			} else {
324
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295 325
 			}
296
-			else
297
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
298 326
 		break;
299 327
 
300 328
 		default:
@@ -370,22 +398,25 @@  discard block
 block discarded – undo
370 398
 		// Are we in SSI mode?  If so try that username and password first
371 399
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
372 400
 		{
373
-			if (empty($db_persist))
374
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
375
-			else
376
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
401
+			if (empty($db_persist)) {
402
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
403
+			} else {
404
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
405
+			}
377 406
 		}
378 407
 		// Fall back to the regular username and password if need be
379 408
 		if (!$db_connection)
380 409
 		{
381
-			if (empty($db_persist))
382
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
383
-			else
384
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
410
+			if (empty($db_persist)) {
411
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
412
+			} else {
413
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
414
+			}
385 415
 		}
386 416
 
387
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
388
-			$db_connection = false;
417
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
418
+					$db_connection = false;
419
+		}
389 420
 
390 421
 		$connection = $db_connection;
391 422
 	}
@@ -393,18 +424,20 @@  discard block
 block discarded – undo
393 424
 	// One more query....
394 425
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
395 426
 
396
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
397
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
427
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
428
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
429
+	}
398 430
 
399 431
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
400 432
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
401 433
 	{
402 434
 		// Add before LIMIT
403
-		if ($pos = strpos($db_string, 'LIMIT '))
404
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
405
-		else
406
-			// Append it.
435
+		if ($pos = strpos($db_string, 'LIMIT ')) {
436
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
437
+		} else {
438
+					// Append it.
407 439
 			$db_string .= "\n\t\t\tORDER BY null";
440
+		}
408 441
 	}
409 442
 
410 443
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -426,8 +459,9 @@  discard block
 block discarded – undo
426 459
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
427 460
 
428 461
 		// Initialize $db_cache if not already initialized.
429
-		if (!isset($db_cache))
430
-			$db_cache = array();
462
+		if (!isset($db_cache)) {
463
+					$db_cache = array();
464
+		}
431 465
 
432 466
 		if (!empty($_SESSION['debug_redirect']))
433 467
 		{
@@ -453,17 +487,18 @@  discard block
 block discarded – undo
453 487
 		while (true)
454 488
 		{
455 489
 			$pos = strpos($db_string, '\'', $pos + 1);
456
-			if ($pos === false)
457
-				break;
490
+			if ($pos === false) {
491
+							break;
492
+			}
458 493
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
459 494
 
460 495
 			while (true)
461 496
 			{
462 497
 				$pos1 = strpos($db_string, '\'', $pos + 1);
463 498
 				$pos2 = strpos($db_string, '\\', $pos + 1);
464
-				if ($pos1 === false)
465
-					break;
466
-				elseif ($pos2 === false || $pos2 > $pos1)
499
+				if ($pos1 === false) {
500
+									break;
501
+				} elseif ($pos2 === false || $pos2 > $pos1)
467 502
 				{
468 503
 					$pos = $pos1;
469 504
 					break;
@@ -479,29 +514,35 @@  discard block
 block discarded – undo
479 514
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
480 515
 
481 516
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
482
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
483
-			$fail = true;
517
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
518
+					$fail = true;
519
+		}
484 520
 		// Trying to change passwords, slow us down, or something?
485
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
486
-			$fail = true;
487
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
488
-			$fail = true;
521
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
522
+					$fail = true;
523
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
524
+					$fail = true;
525
+		}
489 526
 
490
-		if (!empty($fail) && function_exists('log_error'))
491
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
527
+		if (!empty($fail) && function_exists('log_error')) {
528
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
529
+		}
492 530
 	}
493 531
 
494
-	if (empty($db_unbuffered))
495
-		$ret = @mysqli_query($connection, $db_string);
496
-	else
497
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
532
+	if (empty($db_unbuffered)) {
533
+			$ret = @mysqli_query($connection, $db_string);
534
+	} else {
535
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
536
+	}
498 537
 
499
-	if ($ret === false && empty($db_values['db_error_skip']))
500
-		$ret = smf_db_error($db_string, $connection);
538
+	if ($ret === false && empty($db_values['db_error_skip'])) {
539
+			$ret = smf_db_error($db_string, $connection);
540
+	}
501 541
 
502 542
 	// Debugging.
503
-	if (isset($db_show_debug) && $db_show_debug === true)
504
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
543
+	if (isset($db_show_debug) && $db_show_debug === true) {
544
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
545
+	}
505 546
 
506 547
 	return $ret;
507 548
 }
@@ -548,12 +589,13 @@  discard block
 block discarded – undo
548 589
 	// Decide which connection to use
549 590
 	$connection = $connection === null ? $db_connection : $connection;
550 591
 
551
-	if ($type == 'begin')
552
-		return @mysqli_query($connection, 'BEGIN');
553
-	elseif ($type == 'rollback')
554
-		return @mysqli_query($connection, 'ROLLBACK');
555
-	elseif ($type == 'commit')
556
-		return @mysqli_query($connection, 'COMMIT');
592
+	if ($type == 'begin') {
593
+			return @mysqli_query($connection, 'BEGIN');
594
+	} elseif ($type == 'rollback') {
595
+			return @mysqli_query($connection, 'ROLLBACK');
596
+	} elseif ($type == 'commit') {
597
+			return @mysqli_query($connection, 'COMMIT');
598
+	}
557 599
 
558 600
 	return false;
559 601
 }
@@ -593,8 +635,9 @@  discard block
 block discarded – undo
593 635
 	//    2013: Lost connection to server during query.
594 636
 
595 637
 	// Log the error.
596
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
597
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
638
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
639
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
640
+	}
598 641
 
599 642
 	// Database error auto fixing ;).
600 643
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -603,8 +646,9 @@  discard block
 block discarded – undo
603 646
 		$old_cache = @$modSettings['cache_enable'];
604 647
 		$modSettings['cache_enable'] = '1';
605 648
 
606
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
607
-			$db_last_error = max(@$db_last_error, $temp);
649
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
650
+					$db_last_error = max(@$db_last_error, $temp);
651
+		}
608 652
 
609 653
 		if (@$db_last_error < time() - 3600 * 24 * 3)
610 654
 		{
@@ -620,8 +664,9 @@  discard block
 block discarded – undo
620 664
 					foreach ($tables as $table)
621 665
 					{
622 666
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
623
-						if (trim($table) != '')
624
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
667
+						if (trim($table) != '') {
668
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
669
+						}
625 670
 					}
626 671
 				}
627 672
 
@@ -630,8 +675,9 @@  discard block
 block discarded – undo
630 675
 			// Table crashed.  Let's try to fix it.
631 676
 			elseif ($query_errno == 1016)
632 677
 			{
633
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
634
-					$fix_tables = array('`' . $match[1] . '`');
678
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
679
+									$fix_tables = array('`' . $match[1] . '`');
680
+				}
635 681
 			}
636 682
 			// Indexes crashed.  Should be easy to fix!
637 683
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -650,13 +696,15 @@  discard block
 block discarded – undo
650 696
 
651 697
 			// Make a note of the REPAIR...
652 698
 			cache_put_data('db_last_error', time(), 600);
653
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
654
-				updateSettingsFile(array('db_last_error' => time()));
699
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
700
+							updateSettingsFile(array('db_last_error' => time()));
701
+			}
655 702
 
656 703
 			// Attempt to find and repair the broken table.
657
-			foreach ($fix_tables as $table)
658
-				$smcFunc['db_query']('', "
704
+			foreach ($fix_tables as $table) {
705
+							$smcFunc['db_query']('', "
659 706
 					REPAIR TABLE $table", false, false);
707
+			}
660 708
 
661 709
 			// And send off an email!
662 710
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -665,11 +713,12 @@  discard block
 block discarded – undo
665 713
 
666 714
 			// Try the query again...?
667 715
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
668
-			if ($ret !== false)
669
-				return $ret;
716
+			if ($ret !== false) {
717
+							return $ret;
718
+			}
719
+		} else {
720
+					$modSettings['cache_enable'] = $old_cache;
670 721
 		}
671
-		else
672
-			$modSettings['cache_enable'] = $old_cache;
673 722
 
674 723
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
675 724
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -679,22 +728,25 @@  discard block
 block discarded – undo
679 728
 				// Are we in SSI mode?  If so try that username and password first
680 729
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
681 730
 				{
682
-					if (empty($db_persist))
683
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
684
-					else
685
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
731
+					if (empty($db_persist)) {
732
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
733
+					} else {
734
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
735
+					}
686 736
 				}
687 737
 				// Fall back to the regular username and password if need be
688 738
 				if (!$db_connection)
689 739
 				{
690
-					if (empty($db_persist))
691
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
692
-					else
693
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
740
+					if (empty($db_persist)) {
741
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
742
+					} else {
743
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
744
+					}
694 745
 				}
695 746
 
696
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
697
-					$db_connection = false;
747
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
748
+									$db_connection = false;
749
+				}
698 750
 			}
699 751
 
700 752
 			if ($db_connection)
@@ -705,24 +757,27 @@  discard block
 block discarded – undo
705 757
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
706 758
 
707 759
 					$new_errno = mysqli_errno($db_connection);
708
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
709
-						break;
760
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
761
+											break;
762
+					}
710 763
 				}
711 764
 
712 765
 				// If it failed again, shucks to be you... we're not trying it over and over.
713
-				if ($ret !== false)
714
-					return $ret;
766
+				if ($ret !== false) {
767
+									return $ret;
768
+				}
715 769
 			}
716 770
 		}
717 771
 		// Are they out of space, perhaps?
718 772
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
719 773
 		{
720
-			if (!isset($txt))
721
-				$query_error .= ' - check database storage space.';
722
-			else
774
+			if (!isset($txt)) {
775
+							$query_error .= ' - check database storage space.';
776
+			} else
723 777
 			{
724
-				if (!isset($txt['mysql_error_space']))
725
-					loadLanguage('Errors');
778
+				if (!isset($txt['mysql_error_space'])) {
779
+									loadLanguage('Errors');
780
+				}
726 781
 
727 782
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
728 783
 			}
@@ -730,15 +785,17 @@  discard block
 block discarded – undo
730 785
 	}
731 786
 
732 787
 	// Nothing's defined yet... just die with it.
733
-	if (empty($context) || empty($txt))
734
-		die($query_error);
788
+	if (empty($context) || empty($txt)) {
789
+			die($query_error);
790
+	}
735 791
 
736 792
 	// Show an error message, if possible.
737 793
 	$context['error_title'] = $txt['database_error'];
738
-	if (allowedTo('admin_forum'))
739
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
740
-	else
741
-		$context['error_message'] = $txt['try_again'];
794
+	if (allowedTo('admin_forum')) {
795
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
796
+	} else {
797
+			$context['error_message'] = $txt['try_again'];
798
+	}
742 799
 
743 800
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
744 801
 	{
@@ -769,25 +826,28 @@  discard block
 block discarded – undo
769 826
 	$connection = $connection === null ? $db_connection : $connection;
770 827
 
771 828
 	// With nothing to insert, simply return.
772
-	if (empty($data))
773
-		return;
829
+	if (empty($data)) {
830
+			return;
831
+	}
774 832
 
775 833
 	// Replace the prefix holder with the actual prefix.
776 834
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
777 835
 
778 836
 	// Inserting data as a single row can be done as a single array.
779
-	if (!is_array($data[array_rand($data)]))
780
-		$data = array($data);
837
+	if (!is_array($data[array_rand($data)])) {
838
+			$data = array($data);
839
+	}
781 840
 
782 841
 	// Create the mold for a single row insert.
783 842
 	$insertData = '(';
784 843
 	foreach ($columns as $columnName => $type)
785 844
 	{
786 845
 		// Are we restricting the length?
787
-		if (strpos($type, 'string-') !== false)
788
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
789
-		else
790
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
846
+		if (strpos($type, 'string-') !== false) {
847
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
848
+		} else {
849
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
850
+		}
791 851
 	}
792 852
 	$insertData = substr($insertData, 0, -2) . ')';
793 853
 
@@ -796,8 +856,9 @@  discard block
 block discarded – undo
796 856
 
797 857
 	// Here's where the variables are injected to the query.
798 858
 	$insertRows = array();
799
-	foreach ($data as $dataRow)
800
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
859
+	foreach ($data as $dataRow) {
860
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
861
+	}
801 862
 
802 863
 	// Determine the method of insertion.
803 864
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -817,15 +878,16 @@  discard block
 block discarded – undo
817 878
 	
818 879
 	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
819 880
 	{
820
-		if ($returnmode == 1)
821
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
822
-		else if ($returnmode == 2)
881
+		if ($returnmode == 1) {
882
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
883
+		} else if ($returnmode == 2)
823 884
 		{
824 885
 			$return_var = array();
825 886
 			$count = count($insertRows);
826 887
 			$start = smf_db_insert_id($table, $keys[0]);
827
-			for ($i = 0; $i < $count; $i++ )
828
-				$return_var[] = $start + $i;
888
+			for ($i = 0; $i < $count; $i++ ) {
889
+							$return_var[] = $start + $i;
890
+			}
829 891
 		}
830 892
 		return $return_var;
831 893
 	}
@@ -843,8 +905,9 @@  discard block
 block discarded – undo
843 905
  */
844 906
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
845 907
 {
846
-	if (empty($log_message))
847
-		$log_message = $error_message;
908
+	if (empty($log_message)) {
909
+			$log_message = $error_message;
910
+	}
848 911
 
849 912
 	foreach (debug_backtrace() as $step)
850 913
 	{
@@ -863,12 +926,14 @@  discard block
 block discarded – undo
863 926
 	}
864 927
 
865 928
 	// A special case - we want the file and line numbers for debugging.
866
-	if ($error_type == 'return')
867
-		return array($file, $line);
929
+	if ($error_type == 'return') {
930
+			return array($file, $line);
931
+	}
868 932
 
869 933
 	// Is always a critical error.
870
-	if (function_exists('log_error'))
871
-		log_error($log_message, 'critical', $file, $line);
934
+	if (function_exists('log_error')) {
935
+			log_error($log_message, 'critical', $file, $line);
936
+	}
872 937
 
873 938
 	if (function_exists('fatal_error'))
874 939
 	{
@@ -876,12 +941,12 @@  discard block
 block discarded – undo
876 941
 
877 942
 		// Cannot continue...
878 943
 		exit;
944
+	} elseif ($error_type) {
945
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
946
+	} else {
947
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
948
+	}
879 949
 	}
880
-	elseif ($error_type)
881
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
882
-	else
883
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
884
-}
885 950
 
886 951
 /**
887 952
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -898,10 +963,11 @@  discard block
 block discarded – undo
898 963
 		'\\' => '\\\\',
899 964
 	);
900 965
 
901
-	if ($translate_human_wildcards)
902
-		$replacements += array(
966
+	if ($translate_human_wildcards) {
967
+			$replacements += array(
903 968
 			'*' => '%',
904 969
 		);
970
+	}
905 971
 
906 972
 	return strtr($string, $replacements);
907 973
 }
@@ -915,8 +981,9 @@  discard block
 block discarded – undo
915 981
  */
916 982
 function smf_is_resource($result)
917 983
 {
918
-	if ($result instanceof mysqli_result)
919
-		return true;
984
+	if ($result instanceof mysqli_result) {
985
+			return true;
986
+	}
920 987
 
921 988
 	return false;
922 989
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 		$connection
758 758
 	);
759 759
 	
760
-	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
760
+	if (!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
761 761
 	{
762 762
 		if ($returnmode == 1)
763 763
 			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 			$return_var = array();
767 767
 			$count = count($insertRows);
768 768
 			$start = smf_db_insert_id($table, $keys[0]);
769
-			for ($i = 0; $i < $count; $i++ )
769
+			for ($i = 0; $i < $count; $i++)
770 770
 				$return_var[] = $start + $i;
771 771
 		}
772 772
 		return $return_var;
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -456,7 +456,6 @@  discard block
 block discarded – undo
456 456
 
457 457
 /**
458 458
  * affected_rows
459
- * @param resource $connection
460 459
  */
461 460
 function smf_db_affected_rows($result = null)
462 461
 {
@@ -799,7 +798,7 @@  discard block
 block discarded – undo
799 798
  *
800 799
  * @param string $db_name The database name
801 800
  * @param resource $db_connection The database connection
802
- * @return true Always returns true
801
+ * @return boolean Always returns true
803 802
  */
804 803
 function smf_db_select_db($db_name, $db_connection)
805 804
 {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -763,10 +763,10 @@  discard block
 block discarded – undo
763 763
 	$returning = '';
764 764
 	$with_returning = false;
765 765
 	// lets build the returning string, mysql allow only in normal mode
766
-	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
766
+	if (!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
767 767
 	{
768 768
 		// we only take the first key
769
-		$returning = ' RETURNING '.$keys[0];
769
+		$returning = ' RETURNING ' . $keys[0];
770 770
 		$with_returning = true;
771 771
 	}
772 772
 
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 			INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '")
798 798
 			VALUES
799 799
 				' . implode(',
800
-				', $insertRows).$replace.$returning,
800
+				', $insertRows) . $replace . $returning,
801 801
 			array(
802 802
 				'security_override' => true,
803 803
 				'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors',
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 			if ($returnmode === 2)
811 811
 				$return_var = array();
812 812
 
813
-			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
813
+			while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
814 814
 			{
815 815
 				if (is_numeric($row[0])) // try to emulate mysql limitation
816 816
 				{
Please login to merge, or discard this patch.
Braces   +214 added lines, -159 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc')
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') {
39
+			$smcFunc += array(
39 40
 			'db_query' => 'smf_db_query',
40 41
 			'db_quote' => 'smf_db_quote',
41 42
 			'db_insert' => 'smf_db_insert',
@@ -59,11 +60,13 @@  discard block
 block discarded – undo
59 60
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
60 61
 			'db_is_resource' => 'is_resource',
61 62
 		);
63
+	}
62 64
 
63
-	if (!empty($db_options['persist']))
64
-		$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
65
-	else
66
-		$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
65
+	if (!empty($db_options['persist'])) {
66
+			$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
+	} else {
68
+			$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
69
+	}
67 70
 
68 71
 	// Something's wrong, show an error if its fatal (which we assume it is)
69 72
 	if (!$connection)
@@ -71,8 +74,7 @@  discard block
 block discarded – undo
71 74
 		if (!empty($db_options['non_fatal']))
72 75
 		{
73 76
 			return null;
74
-		}
75
-		else
77
+		} else
76 78
 		{
77 79
 			display_db_error();
78 80
 		}
@@ -123,34 +125,42 @@  discard block
 block discarded – undo
123 125
 
124 126
 	list ($values, $connection) = $db_callback;
125 127
 
126
-	if ($matches[1] === 'db_prefix')
127
-		return $db_prefix;
128
+	if ($matches[1] === 'db_prefix') {
129
+			return $db_prefix;
130
+	}
128 131
 
129
-	if ($matches[1] === 'query_see_board')
130
-		return $user_info['query_see_board'];
132
+	if ($matches[1] === 'query_see_board') {
133
+			return $user_info['query_see_board'];
134
+	}
131 135
 
132
-	if ($matches[1] === 'query_wanna_see_board')
133
-		return $user_info['query_wanna_see_board'];
136
+	if ($matches[1] === 'query_wanna_see_board') {
137
+			return $user_info['query_wanna_see_board'];
138
+	}
134 139
 
135
-	if ($matches[1] === 'empty')
136
-		return '\'\'';
140
+	if ($matches[1] === 'empty') {
141
+			return '\'\'';
142
+	}
137 143
 
138
-	if (!isset($matches[2]))
139
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
144
+	if (!isset($matches[2])) {
145
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
146
+	}
140 147
 
141
-	if ($matches[1] === 'literal')
142
-		return '\'' . pg_escape_string($matches[2]) . '\'';
148
+	if ($matches[1] === 'literal') {
149
+			return '\'' . pg_escape_string($matches[2]) . '\'';
150
+	}
143 151
 
144
-	if (!isset($values[$matches[2]]))
145
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
152
+	if (!isset($values[$matches[2]])) {
153
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
154
+	}
146 155
 
147 156
 	$replacement = $values[$matches[2]];
148 157
 
149 158
 	switch ($matches[1])
150 159
 	{
151 160
 		case 'int':
152
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
153
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
161
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
162
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
163
+			}
154 164
 			return (string) (int) $replacement;
155 165
 		break;
156 166
 
@@ -162,56 +172,63 @@  discard block
 block discarded – undo
162 172
 		case 'array_int':
163 173
 			if (is_array($replacement))
164 174
 			{
165
-				if (empty($replacement))
166
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+				if (empty($replacement)) {
176
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177
+				}
167 178
 
168 179
 				foreach ($replacement as $key => $value)
169 180
 				{
170
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
171
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
182
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+					}
172 184
 
173 185
 					$replacement[$key] = (string) (int) $value;
174 186
 				}
175 187
 
176 188
 				return implode(', ', $replacement);
189
+			} else {
190
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177 191
 			}
178
-			else
179
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
180 192
 
181 193
 		break;
182 194
 
183 195
 		case 'array_string':
184 196
 			if (is_array($replacement))
185 197
 			{
186
-				if (empty($replacement))
187
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198
+				if (empty($replacement)) {
199
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
200
+				}
188 201
 
189
-				foreach ($replacement as $key => $value)
190
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
202
+				foreach ($replacement as $key => $value) {
203
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
204
+				}
191 205
 
192 206
 				return implode(', ', $replacement);
207
+			} else {
208
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
193 209
 			}
194
-			else
195
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
196 210
 		break;
197 211
 
198 212
 		case 'date':
199
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
200
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
201
-			else
202
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
214
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
+			} else {
216
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
217
+			}
203 218
 		break;
204 219
 
205 220
 		case 'time':
206
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
207
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
208
-			else
209
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
222
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
223
+			} else {
224
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+			}
210 226
 		break;
211 227
 
212 228
 		case 'float':
213
-			if (!is_numeric($replacement))
214
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+			if (!is_numeric($replacement)) {
230
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+			}
215 232
 			return (string) (float) $replacement;
216 233
 		break;
217 234
 
@@ -224,31 +241,36 @@  discard block
 block discarded – undo
224 241
 		break;
225 242
 
226 243
 		case 'inet':
227
-			if ($replacement == 'null' || $replacement == '')
228
-				return 'null';
229
-			if (inet_pton($replacement) === false)
230
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
244
+			if ($replacement == 'null' || $replacement == '') {
245
+							return 'null';
246
+			}
247
+			if (inet_pton($replacement) === false) {
248
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+			}
231 250
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
232 251
 
233 252
 		case 'array_inet':
234 253
 			if (is_array($replacement))
235 254
 			{
236
-				if (empty($replacement))
237
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+				if (empty($replacement)) {
256
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+				}
238 258
 
239 259
 				foreach ($replacement as $key => $value)
240 260
 				{
241
-					if ($replacement == 'null' || $replacement == '')
242
-						$replacement[$key] = 'null';
243
-					if (!isValidIP($value))
244
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
261
+					if ($replacement == 'null' || $replacement == '') {
262
+											$replacement[$key] = 'null';
263
+					}
264
+					if (!isValidIP($value)) {
265
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+					}
245 267
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
246 268
 				}
247 269
 
248 270
 				return implode(', ', $replacement);
271
+			} else {
272
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249 273
 			}
250
-			else
251
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252 274
 		break;
253 275
 
254 276
 		default:
@@ -335,14 +357,16 @@  discard block
 block discarded – undo
335 357
 		),
336 358
 	);
337 359
 
338
-	if (isset($replacements[$identifier]))
339
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
360
+	if (isset($replacements[$identifier])) {
361
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
362
+	}
340 363
 
341 364
 	// Limits need to be a little different.
342 365
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
343 366
 
344
-	if (trim($db_string) == '')
345
-		return false;
367
+	if (trim($db_string) == '') {
368
+			return false;
369
+	}
346 370
 
347 371
 	// Comments that are allowed in a query are preg_removed.
348 372
 	static $allowed_comments_from = array(
@@ -362,8 +386,9 @@  discard block
 block discarded – undo
362 386
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
363 387
 	$db_replace_result = 0;
364 388
 
365
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
366
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
389
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
390
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
391
+	}
367 392
 
368 393
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
369 394
 	{
@@ -384,8 +409,9 @@  discard block
 block discarded – undo
384 409
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
385 410
 
386 411
 		// Initialize $db_cache if not already initialized.
387
-		if (!isset($db_cache))
388
-			$db_cache = array();
412
+		if (!isset($db_cache)) {
413
+					$db_cache = array();
414
+		}
389 415
 
390 416
 		if (!empty($_SESSION['debug_redirect']))
391 417
 		{
@@ -411,17 +437,18 @@  discard block
 block discarded – undo
411 437
 		while (true)
412 438
 		{
413 439
 			$pos = strpos($db_string, '\'', $pos + 1);
414
-			if ($pos === false)
415
-				break;
440
+			if ($pos === false) {
441
+							break;
442
+			}
416 443
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
417 444
 
418 445
 			while (true)
419 446
 			{
420 447
 				$pos1 = strpos($db_string, '\'', $pos + 1);
421 448
 				$pos2 = strpos($db_string, '\\', $pos + 1);
422
-				if ($pos1 === false)
423
-					break;
424
-				elseif ($pos2 === false || $pos2 > $pos1)
449
+				if ($pos1 === false) {
450
+									break;
451
+				} elseif ($pos2 === false || $pos2 > $pos1)
425 452
 				{
426 453
 					$pos = $pos1;
427 454
 					break;
@@ -437,26 +464,31 @@  discard block
 block discarded – undo
437 464
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
438 465
 
439 466
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
440
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
441
-			$fail = true;
467
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
468
+					$fail = true;
469
+		}
442 470
 		// Trying to change passwords, slow us down, or something?
443
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
444
-			$fail = true;
445
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
446
-			$fail = true;
471
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
472
+					$fail = true;
473
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
474
+					$fail = true;
475
+		}
447 476
 
448
-		if (!empty($fail) && function_exists('log_error'))
449
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
477
+		if (!empty($fail) && function_exists('log_error')) {
478
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
479
+		}
450 480
 	}
451 481
 
452 482
 	$db_last_result = @pg_query($connection, $db_string);
453 483
 
454
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
455
-		$db_last_result = smf_db_error($db_string, $connection);
484
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
485
+			$db_last_result = smf_db_error($db_string, $connection);
486
+	}
456 487
 
457 488
 	// Debugging.
458
-	if (isset($db_show_debug) && $db_show_debug === true)
459
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
489
+	if (isset($db_show_debug) && $db_show_debug === true) {
490
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
491
+	}
460 492
 
461 493
 	return $db_last_result;
462 494
 }
@@ -469,10 +501,11 @@  discard block
 block discarded – undo
469 501
 {
470 502
 	global $db_last_result, $db_replace_result;
471 503
 
472
-	if ($db_replace_result)
473
-		return $db_replace_result;
474
-	elseif ($result === null && !$db_last_result)
475
-		return 0;
504
+	if ($db_replace_result) {
505
+			return $db_replace_result;
506
+	} elseif ($result === null && !$db_last_result) {
507
+			return 0;
508
+	}
476 509
 
477 510
 	return pg_affected_rows($result === null ? $db_last_result : $result);
478 511
 }
@@ -496,8 +529,9 @@  discard block
 block discarded – undo
496 529
 		array(
497 530
 		)
498 531
 	);
499
-	if (!$request)
500
-		return false;
532
+	if (!$request) {
533
+			return false;
534
+	}
501 535
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
502 536
 	$smcFunc['db_free_result']($request);
503 537
 
@@ -518,12 +552,13 @@  discard block
 block discarded – undo
518 552
 	// Decide which connection to use
519 553
 	$connection = $connection === null ? $db_connection : $connection;
520 554
 
521
-	if ($type == 'begin')
522
-		return @pg_query($connection, 'BEGIN');
523
-	elseif ($type == 'rollback')
524
-		return @pg_query($connection, 'ROLLBACK');
525
-	elseif ($type == 'commit')
526
-		return @pg_query($connection, 'COMMIT');
555
+	if ($type == 'begin') {
556
+			return @pg_query($connection, 'BEGIN');
557
+	} elseif ($type == 'rollback') {
558
+			return @pg_query($connection, 'ROLLBACK');
559
+	} elseif ($type == 'commit') {
560
+			return @pg_query($connection, 'COMMIT');
561
+	}
527 562
 
528 563
 	return false;
529 564
 }
@@ -551,19 +586,22 @@  discard block
 block discarded – undo
551 586
 	$query_error = @pg_last_error($connection);
552 587
 
553 588
 	// Log the error.
554
-	if (function_exists('log_error'))
555
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
589
+	if (function_exists('log_error')) {
590
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
591
+	}
556 592
 
557 593
 	// Nothing's defined yet... just die with it.
558
-	if (empty($context) || empty($txt))
559
-		die($query_error);
594
+	if (empty($context) || empty($txt)) {
595
+			die($query_error);
596
+	}
560 597
 
561 598
 	// Show an error message, if possible.
562 599
 	$context['error_title'] = $txt['database_error'];
563
-	if (allowedTo('admin_forum'))
564
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
565
-	else
566
-		$context['error_message'] = $txt['try_again'];
600
+	if (allowedTo('admin_forum')) {
601
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
602
+	} else {
603
+			$context['error_message'] = $txt['try_again'];
604
+	}
567 605
 
568 606
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
569 607
 	{
@@ -585,12 +623,14 @@  discard block
 block discarded – undo
585 623
 {
586 624
 	global $db_row_count;
587 625
 
588
-	if ($counter !== false)
589
-		return pg_fetch_row($request, $counter);
626
+	if ($counter !== false) {
627
+			return pg_fetch_row($request, $counter);
628
+	}
590 629
 
591 630
 	// Reset the row counter...
592
-	if (!isset($db_row_count[(int) $request]))
593
-		$db_row_count[(int) $request] = 0;
631
+	if (!isset($db_row_count[(int) $request])) {
632
+			$db_row_count[(int) $request] = 0;
633
+	}
594 634
 
595 635
 	// Return the right row.
596 636
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -607,12 +647,14 @@  discard block
 block discarded – undo
607 647
 {
608 648
 	global $db_row_count;
609 649
 
610
-	if ($counter !== false)
611
-		return pg_fetch_assoc($request, $counter);
650
+	if ($counter !== false) {
651
+			return pg_fetch_assoc($request, $counter);
652
+	}
612 653
 
613 654
 	// Reset the row counter...
614
-	if (!isset($db_row_count[(int) $request]))
615
-		$db_row_count[(int) $request] = 0;
655
+	if (!isset($db_row_count[(int) $request])) {
656
+			$db_row_count[(int) $request] = 0;
657
+	}
616 658
 
617 659
 	// Return the right row.
618 660
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -665,11 +707,13 @@  discard block
 block discarded – undo
665 707
 
666 708
 	$replace = '';
667 709
 
668
-	if (empty($data))
669
-		return;
710
+	if (empty($data)) {
711
+			return;
712
+	}
670 713
 
671
-	if (!is_array($data[array_rand($data)]))
672
-		$data = array($data);
714
+	if (!is_array($data[array_rand($data)])) {
715
+			$data = array($data);
716
+	}
673 717
 
674 718
 	// Replace the prefix holder with the actual prefix.
675 719
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -688,11 +732,13 @@  discard block
 block discarded – undo
688 732
 			//pg 9.5 got replace support
689 733
 			$pg_version = $smcFunc['db_get_version']();
690 734
 			// if we got a Beta Version
691
-			if (stripos($pg_version, 'beta') !== false)
692
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
735
+			if (stripos($pg_version, 'beta') !== false) {
736
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
737
+			}
693 738
 			// or RC
694
-			if (stripos($pg_version, 'rc') !== false)
695
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
739
+			if (stripos($pg_version, 'rc') !== false) {
740
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
741
+			}
696 742
 
697 743
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
698 744
 		}
@@ -711,8 +757,7 @@  discard block
 block discarded – undo
711 757
 					$key_str .= ($count_pk > 0 ? ',' : '');
712 758
 					$key_str .= $columnName;
713 759
 					$count_pk++;
714
-				}
715
-				else //normal field
760
+				} else //normal field
716 761
 				{
717 762
 					$col_str .= ($count > 0 ? ',' : '');
718 763
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
@@ -720,20 +765,21 @@  discard block
 block discarded – undo
720 765
 				}
721 766
 			}
722 767
 			$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
723
-		}
724
-		else
768
+		} else
725 769
 		{
726 770
 			foreach ($columns as $columnName => $type)
727 771
 			{
728 772
 				// Are we restricting the length?
729
-				if (strpos($type, 'string-') !== false)
730
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
731
-				else
732
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
773
+				if (strpos($type, 'string-') !== false) {
774
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
775
+				} else {
776
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
777
+				}
733 778
 
734 779
 				// A key? That's what we were looking for.
735
-				if (in_array($columnName, $keys))
736
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
780
+				if (in_array($columnName, $keys)) {
781
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
782
+				}
737 783
 				$count++;
738 784
 			}
739 785
 
@@ -769,10 +815,11 @@  discard block
 block discarded – undo
769 815
 		foreach ($columns as $columnName => $type)
770 816
 		{
771 817
 			// Are we restricting the length?
772
-			if (strpos($type, 'string-') !== false)
773
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
774
-			else
775
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
818
+			if (strpos($type, 'string-') !== false) {
819
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
820
+			} else {
821
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
822
+			}
776 823
 		}
777 824
 		$insertData = substr($insertData, 0, -2) . ')';
778 825
 
@@ -781,8 +828,9 @@  discard block
 block discarded – undo
781 828
 
782 829
 		// Here's where the variables are injected to the query.
783 830
 		$insertRows = array();
784
-		foreach ($data as $dataRow)
785
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
831
+		foreach ($data as $dataRow) {
832
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
833
+		}
786 834
 
787 835
 		// Do the insert.
788 836
 		$request = $smcFunc['db_query']('', '
@@ -799,19 +847,21 @@  discard block
 block discarded – undo
799 847
 
800 848
 		if ($with_returning && $request !== false)
801 849
 		{
802
-			if ($returnmode === 2)
803
-				$return_var = array();
850
+			if ($returnmode === 2) {
851
+							$return_var = array();
852
+			}
804 853
 
805 854
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
806 855
 			{
807
-				if (is_numeric($row[0])) // try to emulate mysql limitation
856
+				if (is_numeric($row[0])) {
857
+					// try to emulate mysql limitation
808 858
 				{
809 859
 					if ($returnmode === 1)
810 860
 						$return_var = $row[0];
811
-					elseif ($returnmode === 2)
812
-						$return_var[] = $row[0];
813
-				}
814
-				else
861
+				} elseif ($returnmode === 2) {
862
+											$return_var[] = $row[0];
863
+					}
864
+				} else
815 865
 				{
816 866
 					$with_returning = false;
817 867
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -820,9 +870,10 @@  discard block
 block discarded – undo
820 870
 		}
821 871
 	}
822 872
 	
823
-	if ($with_returning && !empty($return_var))
824
-		return $return_var; 
825
-}
873
+	if ($with_returning && !empty($return_var)) {
874
+			return $return_var;
875
+	}
876
+	}
826 877
 
827 878
 /**
828 879
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -859,8 +910,9 @@  discard block
 block discarded – undo
859 910
  */
860 911
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
861 912
 {
862
-	if (empty($log_message))
863
-		$log_message = $error_message;
913
+	if (empty($log_message)) {
914
+			$log_message = $error_message;
915
+	}
864 916
 
865 917
 	foreach (debug_backtrace() as $step)
866 918
 	{
@@ -879,12 +931,14 @@  discard block
 block discarded – undo
879 931
 	}
880 932
 
881 933
 	// A special case - we want the file and line numbers for debugging.
882
-	if ($error_type == 'return')
883
-		return array($file, $line);
934
+	if ($error_type == 'return') {
935
+			return array($file, $line);
936
+	}
884 937
 
885 938
 	// Is always a critical error.
886
-	if (function_exists('log_error'))
887
-		log_error($log_message, 'critical', $file, $line);
939
+	if (function_exists('log_error')) {
940
+			log_error($log_message, 'critical', $file, $line);
941
+	}
888 942
 
889 943
 	if (function_exists('fatal_error'))
890 944
 	{
@@ -892,12 +946,12 @@  discard block
 block discarded – undo
892 946
 
893 947
 		// Cannot continue...
894 948
 		exit;
949
+	} elseif ($error_type) {
950
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
951
+	} else {
952
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
953
+	}
895 954
 	}
896
-	elseif ($error_type)
897
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
898
-	else
899
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
900
-}
901 955
 
902 956
 /**
903 957
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -914,10 +968,11 @@  discard block
 block discarded – undo
914 968
 		'\\' => '\\\\',
915 969
 	);
916 970
 
917
-	if ($translate_human_wildcards)
918
-		$replacements += array(
971
+	if ($translate_human_wildcards) {
972
+			$replacements += array(
919 973
 			'*' => '%',
920 974
 		);
975
+	}
921 976
 
922 977
 	return strtr($string, $replacements);
923 978
 }
Please login to merge, or discard this patch.
Sources/Subs-Graphics.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -170,7 +170,7 @@
 block discarded – undo
170 170
  *
171 171
  * @param string $fileName The path to the file
172 172
  * @param int $preferred_format The preferred format - 0 to automatically determine, 1 for gif, 2 for jpg, 3 for png, 6 for bmp and 15 for wbmp
173
- * @return boolean Whether the reencoding was successful
173
+ * @return false|null Whether the reencoding was successful
174 174
  */
175 175
 function reencodeImage($fileName, $preferred_format = 0)
176 176
 {
Please login to merge, or discard this patch.
Braces   +240 added lines, -195 removed lines patch added patch discarded remove patch
@@ -18,8 +18,9 @@  discard block
 block discarded – undo
18 18
  * @version 2.1 Beta 3
19 19
  */
20 20
 
21
-if (!defined('SMF'))
21
+if (!defined('SMF')) {
22 22
 	die('No direct access...');
23
+}
23 24
 
24 25
 /**
25 26
  * downloads a file from a url and stores it locally for avatar use by id_member.
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$destName = 'avatar_' . $memID . '_' . time() . '.' . $ext;
45 46
 
46 47
 	// Just making sure there is a non-zero member.
47
-	if (empty($memID))
48
-		return false;
48
+	if (empty($memID)) {
49
+			return false;
50
+	}
49 51
 
50 52
 	require_once($sourcedir . '/ManageAttachments.php');
51 53
 	removeAttachments(array('id_member' => $memID));
@@ -76,10 +78,11 @@  discard block
 block discarded – undo
76 78
 	$destName = $modSettings['custom_avatar_dir'] . '/' . $destName . '.tmp';
77 79
 
78 80
 	// Resize it.
79
-	if (!empty($modSettings['avatar_download_png']))
80
-		$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
81
-	else
82
-		$success = resizeImageFile($url, $destName, $max_width, $max_height);
81
+	if (!empty($modSettings['avatar_download_png'])) {
82
+			$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
83
+	} else {
84
+			$success = resizeImageFile($url, $destName, $max_width, $max_height);
85
+	}
83 86
 
84 87
 	// Remove the .tmp extension.
85 88
 	$destName = substr($destName, 0, -4);
@@ -108,11 +111,10 @@  discard block
 block discarded – undo
108 111
 				)
109 112
 			);
110 113
 			return true;
114
+		} else {
115
+					return false;
111 116
 		}
112
-		else
113
-			return false;
114
-	}
115
-	else
117
+	} else
116 118
 	{
117 119
 		$smcFunc['db_query']('', '
118 120
 			DELETE FROM {db_prefix}attachments
@@ -144,17 +146,18 @@  discard block
 block discarded – undo
144 146
 	$destName = $source . '_thumb.tmp';
145 147
 
146 148
 	// Do the actual resize.
147
-	if (!empty($modSettings['attachment_thumb_png']))
148
-		$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
149
-	else
150
-		$success = resizeImageFile($source, $destName, $max_width, $max_height);
149
+	if (!empty($modSettings['attachment_thumb_png'])) {
150
+			$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
151
+	} else {
152
+			$success = resizeImageFile($source, $destName, $max_width, $max_height);
153
+	}
151 154
 
152 155
 	// Okay, we're done with the temporary stuff.
153 156
 	$destName = substr($destName, 0, -4);
154 157
 
155
-	if ($success && @rename($destName . '.tmp', $destName))
156
-		return true;
157
-	else
158
+	if ($success && @rename($destName . '.tmp', $destName)) {
159
+			return true;
160
+	} else
158 161
 	{
159 162
 		@unlink($destName . '.tmp');
160 163
 		@touch($destName);
@@ -176,18 +179,21 @@  discard block
 block discarded – undo
176 179
 {
177 180
 	if (!resizeImageFile($fileName, $fileName . '.tmp', null, null, $preferred_format))
178 181
 	{
179
-		if (file_exists($fileName . '.tmp'))
180
-			unlink($fileName . '.tmp');
182
+		if (file_exists($fileName . '.tmp')) {
183
+					unlink($fileName . '.tmp');
184
+		}
181 185
 
182 186
 		return false;
183 187
 	}
184 188
 
185
-	if (!unlink($fileName))
186
-		return false;
189
+	if (!unlink($fileName)) {
190
+			return false;
191
+	}
187 192
 
188
-	if (!rename($fileName . '.tmp', $fileName))
189
-		return false;
190
-}
193
+	if (!rename($fileName . '.tmp', $fileName)) {
194
+			return false;
195
+	}
196
+	}
191 197
 
192 198
 /**
193 199
  * Searches through the file to see if there's potentially harmful non-binary content.
@@ -200,8 +206,9 @@  discard block
 block discarded – undo
200 206
 function checkImageContents($fileName, $extensiveCheck = false)
201 207
 {
202 208
 	$fp = fopen($fileName, 'rb');
203
-	if (!$fp)
204
-		fatal_lang_error('attach_timeout');
209
+	if (!$fp) {
210
+			fatal_lang_error('attach_timeout');
211
+	}
205 212
 
206 213
 	$prev_chunk = '';
207 214
 	while (!feof($fp))
@@ -217,8 +224,7 @@  discard block
 block discarded – undo
217 224
 				fclose($fp);
218 225
 				return false;
219 226
 			}
220
-		}
221
-		else
227
+		} else
222 228
 		{
223 229
 			// Check for potential infection
224 230
 			if (preg_match('~(iframe|(?<!cellTextIs)html|eval|body|script\W|[CF]WS[\x01-\x0C])~i', $prev_chunk . $cur_chunk) === 1)
@@ -245,8 +251,9 @@  discard block
 block discarded – undo
245 251
 	global $gd2;
246 252
 
247 253
 	// Check to see if GD is installed and what version.
248
-	if (($extensionFunctions = get_extension_funcs('gd')) === false)
249
-		return false;
254
+	if (($extensionFunctions = get_extension_funcs('gd')) === false) {
255
+			return false;
256
+	}
250 257
 
251 258
 	// Also determine if GD2 is installed and store it in a global.
252 259
 	$gd2 = in_array('imagecreatetruecolor', $extensionFunctions) && function_exists('imagecreatetruecolor');
@@ -318,8 +325,9 @@  discard block
 block discarded – undo
318 325
 	global $sourcedir;
319 326
 
320 327
 	// Nothing to do without GD or IM/MW
321
-	if (!checkGD() && !checkImagick() && !checkMagickWand())
322
-		return false;
328
+	if (!checkGD() && !checkImagick() && !checkMagickWand()) {
329
+			return false;
330
+	}
323 331
 
324 332
 	static $default_formats = array(
325 333
 		'1' => 'gif',
@@ -341,38 +349,39 @@  discard block
 block discarded – undo
341 349
 		fclose($fp_destination);
342 350
 
343 351
 		$sizes = @getimagesize($destination);
344
-	}
345
-	elseif ($fp_destination)
352
+	} elseif ($fp_destination)
346 353
 	{
347 354
 		$sizes = @getimagesize($source);
348 355
 
349 356
 		$fp_source = fopen($source, 'rb');
350 357
 		if ($fp_source !== false)
351 358
 		{
352
-			while (!feof($fp_source))
353
-				fwrite($fp_destination, fread($fp_source, 8192));
359
+			while (!feof($fp_source)) {
360
+							fwrite($fp_destination, fread($fp_source, 8192));
361
+			}
354 362
 			fclose($fp_source);
363
+		} else {
364
+					$sizes = array(-1, -1, -1);
355 365
 		}
356
-		else
357
-			$sizes = array(-1, -1, -1);
358 366
 		fclose($fp_destination);
359 367
 	}
360 368
 	// We can't get to the file.
361
-	else
362
-		$sizes = array(-1, -1, -1);
369
+	else {
370
+			$sizes = array(-1, -1, -1);
371
+	}
363 372
 
364 373
 	// See if we have -or- can get the needed memory for this operation
365 374
 	// ImageMagick isn't subject to PHP's memory limits :)
366
-	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes))
367
-		return false;
375
+	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) {
376
+			return false;
377
+	}
368 378
 
369 379
 	// A known and supported format?
370 380
 	// @todo test PSD and gif.
371 381
 	if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]]))
372 382
 	{
373 383
 		return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format);
374
-	}
375
-	elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
384
+	} elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
376 385
 	{
377 386
 		$imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
378 387
 		if ($src_img = @$imagecreatefrom($destination))
@@ -425,14 +434,14 @@  discard block
 block discarded – undo
425 434
 			$dest_width = empty($max_width) ? $src_width : $max_width;
426 435
 			$dest_height = empty($max_height) ? $src_height : $max_height;
427 436
 
428
-			if ($default_formats[$preferred_format] == 'jpeg')
429
-				$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
437
+			if ($default_formats[$preferred_format] == 'jpeg') {
438
+							$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
439
+			}
430 440
 
431 441
 			$imagick->setImageFormat($default_formats[$preferred_format]);
432 442
 			$imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true);
433 443
 			$success = $imagick->writeImage($destName);
434
-		}
435
-		else
444
+		} else
436 445
 		{
437 446
 			$magick_wand = newMagickWand();
438 447
 			MagickReadImage($magick_wand, $destName);
@@ -441,8 +450,9 @@  discard block
 block discarded – undo
441 450
 			$dest_width = empty($max_width) ? $src_width : $max_width;
442 451
 			$dest_height = empty($max_height) ? $src_height : $max_height;
443 452
 
444
-			if ($default_formats[$preferred_format] == 'jpeg')
445
-				MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
453
+			if ($default_formats[$preferred_format] == 'jpeg') {
454
+							MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
455
+			}
446 456
 
447 457
 			MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]);
448 458
 			MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true);
@@ -450,8 +460,7 @@  discard block
 block discarded – undo
450 460
 		}
451 461
 
452 462
 		return !empty($success);
453
-	}
454
-	elseif (checkGD())
463
+	} elseif (checkGD())
455 464
 	{
456 465
 		$success = false;
457 466
 
@@ -462,8 +471,7 @@  discard block
 block discarded – undo
462 471
 			{
463 472
 				$dst_width = $max_width;
464 473
 				$dst_height = round($src_height * $max_width / $src_width);
465
-			}
466
-			elseif (!empty($max_height))
474
+			} elseif (!empty($max_height))
467 475
 			{
468 476
 				$dst_width = round($src_width * $max_height / $src_height);
469 477
 				$dst_height = $max_height;
@@ -481,44 +489,48 @@  discard block
 block discarded – undo
481 489
 					if ((!empty($preferred_format)) && ($preferred_format == 3))
482 490
 					{
483 491
 						imagealphablending($dst_img, false);
484
-						if (function_exists('imagesavealpha'))
485
-							imagesavealpha($dst_img, true);
492
+						if (function_exists('imagesavealpha')) {
493
+													imagesavealpha($dst_img, true);
494
+						}
486 495
 					}
496
+				} else {
497
+									$dst_img = imagecreate($dst_width, $dst_height);
487 498
 				}
488
-				else
489
-					$dst_img = imagecreate($dst_width, $dst_height);
490 499
 
491 500
 				// Resize it!
492
-				if ($gd2)
493
-					imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
494
-				else
495
-					imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
501
+				if ($gd2) {
502
+									imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
503
+				} else {
504
+									imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
505
+				}
506
+			} else {
507
+							$dst_img = $src_img;
496 508
 			}
497
-			else
498
-				$dst_img = $src_img;
509
+		} else {
510
+					$dst_img = $src_img;
499 511
 		}
500
-		else
501
-			$dst_img = $src_img;
502 512
 
503 513
 		// Save the image as ...
504
-		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng'))
505
-			$success = imagepng($dst_img, $destName);
506
-		elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif'))
507
-			$success = imagegif($dst_img, $destName);
508
-		elseif (function_exists('imagejpeg'))
509
-			$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
514
+		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) {
515
+					$success = imagepng($dst_img, $destName);
516
+		} elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) {
517
+					$success = imagegif($dst_img, $destName);
518
+		} elseif (function_exists('imagejpeg')) {
519
+					$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
520
+		}
510 521
 
511 522
 		// Free the memory.
512 523
 		imagedestroy($src_img);
513
-		if ($dst_img != $src_img)
514
-			imagedestroy($dst_img);
524
+		if ($dst_img != $src_img) {
525
+					imagedestroy($dst_img);
526
+		}
515 527
 
516 528
 		return $success;
517
-	}
518
-	else
519
-		// Without GD, no image resizing at all.
529
+	} else {
530
+			// Without GD, no image resizing at all.
520 531
 		return false;
521
-}
532
+	}
533
+	}
522 534
 
523 535
 /**
524 536
  * Copy image.
@@ -572,8 +584,9 @@  discard block
 block discarded – undo
572 584
 			$color = imagecolorresolve($dst_img, $red, $green, $blue);
573 585
 			if ($color == -1)
574 586
 			{
575
-				if ($palsize++ < 256)
576
-					imagecolorallocate($dst_img, $red, $green, $blue);
587
+				if ($palsize++ < 256) {
588
+									imagecolorallocate($dst_img, $red, $green, $blue);
589
+				}
577 590
 				$color = imagecolorclosest($dst_img, $red, $green, $blue);
578 591
 			}
579 592
 
@@ -603,13 +616,15 @@  discard block
 block discarded – undo
603 616
 		$header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14));
604 617
 		$info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40));
605 618
 
606
-		if ($header['type'] != 0x4D42)
607
-			return false;
619
+		if ($header['type'] != 0x4D42) {
620
+					return false;
621
+		}
608 622
 
609
-		if ($gd2)
610
-			$dst_img = imagecreatetruecolor($info['width'], $info['height']);
611
-		else
612
-			$dst_img = imagecreate($info['width'], $info['height']);
623
+		if ($gd2) {
624
+					$dst_img = imagecreatetruecolor($info['width'], $info['height']);
625
+		} else {
626
+					$dst_img = imagecreate($info['width'], $info['height']);
627
+		}
613 628
 
614 629
 		$palette_size = $header['offset'] - 54;
615 630
 		$info['ncolor'] = $palette_size / 4;
@@ -635,8 +650,9 @@  discard block
 block discarded – undo
635 650
 			fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l);
636 651
 			$scan_line = fread($fp, $scan_line_size);
637 652
 
638
-			if (strlen($scan_line) < $scan_line_size)
639
-				continue;
653
+			if (strlen($scan_line) < $scan_line_size) {
654
+							continue;
655
+			}
640 656
 
641 657
 			if ($info['bits'] == 32)
642 658
 			{
@@ -654,14 +670,14 @@  discard block
 block discarded – undo
654 670
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
655 671
 
656 672
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
657
-						if ($color == -1)
658
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
673
+						if ($color == -1) {
674
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
675
+						}
659 676
 					}
660 677
 
661 678
 					imagesetpixel($dst_img, $x, $y, $color);
662 679
 				}
663
-			}
664
-			elseif ($info['bits'] == 24)
680
+			} elseif ($info['bits'] == 24)
665 681
 			{
666 682
 				$x = 0;
667 683
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -676,14 +692,14 @@  discard block
 block discarded – undo
676 692
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
677 693
 
678 694
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
679
-						if ($color == -1)
680
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
695
+						if ($color == -1) {
696
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
697
+						}
681 698
 					}
682 699
 
683 700
 					imagesetpixel($dst_img, $x, $y, $color);
684 701
 				}
685
-			}
686
-			elseif ($info['bits'] == 16)
702
+			} elseif ($info['bits'] == 16)
687 703
 			{
688 704
 				$x = 0;
689 705
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -704,20 +720,20 @@  discard block
 block discarded – undo
704 720
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
705 721
 
706 722
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
707
-						if ($color == -1)
708
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
723
+						if ($color == -1) {
724
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
725
+						}
709 726
 					}
710 727
 
711 728
 					imagesetpixel($dst_img, $x, $y, $color);
712 729
 				}
713
-			}
714
-			elseif ($info['bits'] == 8)
730
+			} elseif ($info['bits'] == 8)
715 731
 			{
716 732
 				$x = 0;
717
-				for ($j = 0; $j < $scan_line_size; $x++)
718
-					imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
719
-			}
720
-			elseif ($info['bits'] == 4)
733
+				for ($j = 0; $j < $scan_line_size; $x++) {
734
+									imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
735
+				}
736
+			} elseif ($info['bits'] == 4)
721 737
 			{
722 738
 				$x = 0;
723 739
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -725,11 +741,11 @@  discard block
 block discarded – undo
725 741
 					$byte = ord($scan_line{$j++});
726 742
 
727 743
 					imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]);
728
-					if (++$x < $info['width'])
729
-						imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
744
+					if (++$x < $info['width']) {
745
+											imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
746
+					}
730 747
 				}
731
-			}
732
-			elseif ($info['bits'] == 1)
748
+			} elseif ($info['bits'] == 1)
733 749
 			{
734 750
 				$x = 0;
735 751
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -738,7 +754,9 @@  discard block
 block discarded – undo
738 754
 
739 755
 					imagesetpixel($dst_img, $x, $y, $palette[(($byte) & 128) != 0]);
740 756
 					for ($shift = 1; $shift < 8; $shift++) {
741
-						if (++$x < $info['width']) imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
757
+						if (++$x < $info['width']) {
758
+							imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
759
+						}
742 760
 					}
743 761
 				}
744 762
 			}
@@ -762,15 +780,18 @@  discard block
 block discarded – undo
762 780
  */
763 781
 function gif_outputAsPng($gif, $lpszFileName, $background_color = -1)
764 782
 {
765
-	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '')
766
-		return false;
783
+	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') {
784
+			return false;
785
+	}
767 786
 
768 787
 	$fd = $gif->get_png_data($background_color);
769
-	if (strlen($fd) <= 0)
770
-		return false;
788
+	if (strlen($fd) <= 0) {
789
+			return false;
790
+	}
771 791
 
772
-	if (!($fh = @fopen($lpszFileName, 'wb')))
773
-		return false;
792
+	if (!($fh = @fopen($lpszFileName, 'wb'))) {
793
+			return false;
794
+	}
774 795
 
775 796
 	@fwrite($fh, $fd, strlen($fd));
776 797
 	@fflush($fh);
@@ -797,8 +818,9 @@  discard block
 block discarded – undo
797 818
 	// What type are we going to be doing?
798 819
 	$imageType = $modSettings['visual_verification_type'];
799 820
 	// Special case to allow the admin center to show samples.
800
-	if ($user_info['is_admin'] && isset($_GET['type']))
801
-		$imageType = (int) $_GET['type'];
821
+	if ($user_info['is_admin'] && isset($_GET['type'])) {
822
+			$imageType = (int) $_GET['type'];
823
+	}
802 824
 
803 825
 	// Some quick references for what we do.
804 826
 	// Do we show no, low or high noise?
@@ -832,25 +854,28 @@  discard block
 block discarded – undo
832 854
 	$character_spacing = 1;
833 855
 
834 856
 	// What color is the background - generally white unless we're on "hard".
835
-	if ($simpleBGColor)
836
-		$background_color = array(255, 255, 255);
837
-	else
838
-		$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
857
+	if ($simpleBGColor) {
858
+			$background_color = array(255, 255, 255);
859
+	} else {
860
+			$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
861
+	}
839 862
 
840 863
 	// The color of the characters shown (red, green, blue).
841
-	if ($simpleFGColor)
842
-		$foreground_color = array(0, 0, 0);
843
-	else
864
+	if ($simpleFGColor) {
865
+			$foreground_color = array(0, 0, 0);
866
+	} else
844 867
 	{
845 868
 		$foreground_color = array(64, 101, 136);
846 869
 
847 870
 		// Has the theme author requested a custom color?
848
-		if (isset($settings['verification_foreground']))
849
-			$foreground_color = $settings['verification_foreground'];
871
+		if (isset($settings['verification_foreground'])) {
872
+					$foreground_color = $settings['verification_foreground'];
873
+		}
850 874
 	}
851 875
 
852
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
853
-		return false;
876
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
877
+			return false;
878
+	}
854 879
 
855 880
 	// Get a list of the available fonts.
856 881
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
@@ -861,25 +886,28 @@  discard block
 block discarded – undo
861 886
 	{
862 887
 		if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1)
863 888
 		{
864
-			if ($endian ^ (strpos($entry, '_end.gdf') === false))
865
-				$font_list[] = $entry;
889
+			if ($endian ^ (strpos($entry, '_end.gdf') === false)) {
890
+							$font_list[] = $entry;
891
+			}
892
+		} elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) {
893
+					$ttfont_list[] = $entry;
866 894
 		}
867
-		elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1)
868
-			$ttfont_list[] = $entry;
869 895
 	}
870 896
 
871
-	if (empty($font_list))
872
-		return false;
897
+	if (empty($font_list)) {
898
+			return false;
899
+	}
873 900
 
874 901
 	// For non-hard things don't even change fonts.
875 902
 	if (!$varyFonts)
876 903
 	{
877 904
 		$font_list = array($font_list[0]);
878 905
 		// Try use Screenge if we can - it looks good!
879
-		if (in_array('AnonymousPro.ttf', $ttfont_list))
880
-			$ttfont_list = array('AnonymousPro.ttf');
881
-		else
882
-			$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
906
+		if (in_array('AnonymousPro.ttf', $ttfont_list)) {
907
+					$ttfont_list = array('AnonymousPro.ttf');
908
+		} else {
909
+					$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
910
+		}
883 911
 
884 912
 	}
885 913
 
@@ -897,14 +925,16 @@  discard block
 block discarded – undo
897 925
 	}
898 926
 
899 927
 	// Load all fonts and determine the maximum font height.
900
-	foreach ($loaded_fonts as $font_index => $dummy)
901
-		$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
928
+	foreach ($loaded_fonts as $font_index => $dummy) {
929
+			$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
930
+	}
902 931
 
903 932
 	// Determine the dimensions of each character.
904
-	if ($imageType == 4 || $imageType == 5)
905
-		$extra = 80;
906
-	else
907
-		$extra = 45;
933
+	if ($imageType == 4 || $imageType == 5) {
934
+			$extra = 80;
935
+	} else {
936
+			$extra = 45;
937
+	}
908 938
 
909 939
 	$total_width = $character_spacing * strlen($code) + $extra;
910 940
 	$max_height = 0;
@@ -925,13 +955,15 @@  discard block
 block discarded – undo
925 955
 	imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color);
926 956
 
927 957
 	// Randomize the foreground color a little.
928
-	for ($i = 0; $i < 3; $i++)
929
-		$foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
958
+	for ($i = 0; $i < 3; $i++) {
959
+			$foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
960
+	}
930 961
 	$fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
931 962
 
932 963
 	// Color for the dots.
933
-	for ($i = 0; $i < 3; $i++)
934
-		$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255);
964
+	for ($i = 0; $i < 3; $i++) {
965
+			$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255);
966
+	}
935 967
 	$randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]);
936 968
 
937 969
 	// Some squares/rectanges for new extreme level
@@ -957,10 +989,11 @@  discard block
 block discarded – undo
957 989
 			$can_do_ttf = function_exists('imagettftext');
958 990
 
959 991
 			// How much rotation will we give?
960
-			if ($rotationType == 'none')
961
-				$angle = 0;
962
-			else
963
-				$angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10);
992
+			if ($rotationType == 'none') {
993
+							$angle = 0;
994
+			} else {
995
+							$angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10);
996
+			}
964 997
 
965 998
 			// What color shall we do it?
966 999
 			if ($fontColorType == 'cyclic')
@@ -974,51 +1007,56 @@  discard block
 block discarded – undo
974 1007
 					array(0, 0, 0),
975 1008
 					array(143, 39, 31),
976 1009
 				);
977
-				if (!isset($last_index))
978
-					$last_index = -1;
1010
+				if (!isset($last_index)) {
1011
+									$last_index = -1;
1012
+				}
979 1013
 				$new_index = $last_index;
980
-				while ($last_index == $new_index)
981
-					$new_index = mt_rand(0, count($colors) - 1);
1014
+				while ($last_index == $new_index) {
1015
+									$new_index = mt_rand(0, count($colors) - 1);
1016
+				}
982 1017
 				$char_fg_color = $colors[$new_index];
983 1018
 				$last_index = $new_index;
1019
+			} elseif ($fontColorType == 'random') {
1020
+							$char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2]));
1021
+			} else {
1022
+							$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
984 1023
 			}
985
-			elseif ($fontColorType == 'random')
986
-				$char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2]));
987
-			else
988
-				$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
989 1024
 
990 1025
 			if (!empty($can_do_ttf))
991 1026
 			{
992 1027
 				// GD2 handles font size differently.
993
-				if ($fontSizeRandom)
994
-					$font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25);
995
-				else
996
-					$font_size = $gd2 ? 18 : 24;
1028
+				if ($fontSizeRandom) {
1029
+									$font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25);
1030
+				} else {
1031
+									$font_size = $gd2 ? 18 : 24;
1032
+				}
997 1033
 
998 1034
 				// Work out the sizes - also fix the character width cause TTF not quite so wide!
999 1035
 				$font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5;
1000 1036
 				$font_y = $max_height - ($fontVerPos == 'vrandom' ? mt_rand(2, 8) : ($fontVerPos == 'random' ? mt_rand(3, 5) : 5));
1001 1037
 
1002 1038
 				// What font face?
1003
-				if (!empty($ttfont_list))
1004
-					$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)];
1039
+				if (!empty($ttfont_list)) {
1040
+									$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)];
1041
+				}
1005 1042
 
1006 1043
 				// What color are we to do it in?
1007 1044
 				$is_reverse = $showReverseChars ? mt_rand(0, 1) : false;
1008 1045
 				$char_color = function_exists('imagecolorallocatealpha') && $fontTrans ? imagecolorallocatealpha($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2], 50) : imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]);
1009 1046
 
1010 1047
 				$fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']);
1011
-				if (empty($fontcord))
1012
-					$can_do_ttf = false;
1013
-				elseif ($is_reverse)
1048
+				if (empty($fontcord)) {
1049
+									$can_do_ttf = false;
1050
+				} elseif ($is_reverse)
1014 1051
 				{
1015 1052
 					imagefilledpolygon($code_image, $fontcord, 4, $fg_color);
1016 1053
 					// Put the character back!
1017 1054
 					imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']);
1018 1055
 				}
1019 1056
 
1020
-				if ($can_do_ttf)
1021
-					$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1057
+				if ($can_do_ttf) {
1058
+									$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1059
+				}
1022 1060
 			}
1023 1061
 
1024 1062
 			if (!$can_do_ttf)
@@ -1037,8 +1075,9 @@  discard block
 block discarded – undo
1037 1075
 				}
1038 1076
 
1039 1077
 				// Sorry, no rotation available.
1040
-				else
1041
-					imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1078
+				else {
1079
+									imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1080
+				}
1042 1081
 				$cur_x += $character['width'] + $character_spacing;
1043 1082
 			}
1044 1083
 		}
@@ -1051,17 +1090,22 @@  discard block
 block discarded – undo
1051 1090
 	}
1052 1091
 
1053 1092
 	// Make the background color transparent on the hard image.
1054
-	if (!$simpleBGColor)
1055
-		imagecolortransparent($code_image, $bg_color);
1056
-	if ($hasBorder)
1057
-		imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1093
+	if (!$simpleBGColor) {
1094
+			imagecolortransparent($code_image, $bg_color);
1095
+	}
1096
+	if ($hasBorder) {
1097
+			imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1098
+	}
1058 1099
 
1059 1100
 	// Add some noise to the background?
1060 1101
 	if ($noiseType != 'none')
1061 1102
 	{
1062
-		for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2))
1063
-			for ($j = mt_rand(0, 10); $j < $total_width; $j += mt_rand(1, 10))
1064
-				imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color);
1103
+		for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) {
1104
+					for ($j = mt_rand(0, 10);
1105
+		}
1106
+		$j < $total_width; $j += mt_rand(1, 10)) {
1107
+							imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color);
1108
+			}
1065 1109
 
1066 1110
 		// Put in some lines too?
1067 1111
 		if ($noiseType != 'extreme')
@@ -1074,8 +1118,7 @@  discard block
 block discarded – undo
1074 1118
 					$x1 = mt_rand(0, $total_width);
1075 1119
 					$x2 = mt_rand(0, $total_width);
1076 1120
 					$y1 = 0; $y2 = $max_height;
1077
-				}
1078
-				else
1121
+				} else
1079 1122
 				{
1080 1123
 					$y1 = mt_rand(0, $max_height);
1081 1124
 					$y2 = mt_rand(0, $max_height);
@@ -1084,8 +1127,7 @@  discard block
 block discarded – undo
1084 1127
 				imagesetthickness($code_image, mt_rand(1, 2));
1085 1128
 				imageline($code_image, $x1, $y1, $x2, $y2, mt_rand(0, 1) ? $fg_color : $randomness_color);
1086 1129
 			}
1087
-		}
1088
-		else
1130
+		} else
1089 1131
 		{
1090 1132
 			// Put in some ellipse
1091 1133
 			$num_ellipse = $noiseType == 'extreme' ? mt_rand(6, 12) : mt_rand(2, 6);
@@ -1105,8 +1147,7 @@  discard block
 block discarded – undo
1105 1147
 	{
1106 1148
 		header('Content-type: image/gif');
1107 1149
 		imagegif($code_image);
1108
-	}
1109
-	else
1150
+	} else
1110 1151
 	{
1111 1152
 		header('Content-type: image/png');
1112 1153
 		imagepng($code_image);
@@ -1129,25 +1170,29 @@  discard block
 block discarded – undo
1129 1170
 {
1130 1171
 	global $settings;
1131 1172
 
1132
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
1133
-		return false;
1173
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
1174
+			return false;
1175
+	}
1134 1176
 
1135 1177
 	// Get a list of the available font directories.
1136 1178
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
1137 1179
 	$font_list = array();
1138
-	while ($entry = $font_dir->read())
1139
-		if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1180
+	while ($entry = $font_dir->read()) {
1181
+			if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1140 1182
 			$font_list[] = $entry;
1183
+	}
1141 1184
 
1142
-	if (empty($font_list))
1143
-		return false;
1185
+	if (empty($font_list)) {
1186
+			return false;
1187
+	}
1144 1188
 
1145 1189
 	// Pick a random font.
1146 1190
 	$random_font = $font_list[array_rand($font_list)];
1147 1191
 
1148 1192
 	// Check if the given letter exists.
1149
-	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png'))
1150
-		return false;
1193
+	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) {
1194
+			return false;
1195
+	}
1151 1196
 
1152 1197
 	// Include it!
1153 1198
 	header('Content-type: image/png');
Please login to merge, or discard this patch.
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -5265,7 +5265,6 @@  discard block
 block discarded – undo
5265 5265
 
5266 5266
 /**
5267 5267
  * Tries different modes to make file/dirs writable. Wrapper function for chmod()
5268
-
5269 5268
  * @param string $file The file/dir full path.
5270 5269
  * @param int $value Not needed, added for legacy reasons.
5271 5270
  * @return boolean  true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable.
@@ -5305,7 +5304,6 @@  discard block
 block discarded – undo
5305 5304
 
5306 5305
 /**
5307 5306
  * Wrapper function for json_decode() with error handling.
5308
-
5309 5307
  * @param string $json The string to decode.
5310 5308
  * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default.
5311 5309
  * @param bool $logIt To specify if the error will be logged if theres any.
Please login to merge, or discard this patch.
Sources/Subs-Membergroups.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -243,6 +243,7 @@
 block discarded – undo
243 243
  * @param null|array The groups to remove the member(s) from. If null, the specified members are stripped from all their membergroups.
244 244
  * @param bool $permissionCheckDone Whether we've already checked permissions prior to calling this function
245 245
  * @param bool $ignoreProtected Whether to ignore protected groups
246
+ * @param integer $groups
246 247
  * @return bool Whether the operation was successful
247 248
  */
248 249
 function removeMembersFromGroups($members, $groups = null, $permissionCheckDone = false, $ignoreProtected = false)
Please login to merge, or discard this patch.
Braces   +149 added lines, -112 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Delete one of more membergroups.
@@ -31,15 +32,16 @@  discard block
 block discarded – undo
31 32
 	global $smcFunc, $modSettings, $txt;
32 33
 
33 34
 	// Make sure it's an array.
34
-	if (!is_array($groups))
35
-		$groups = array((int) $groups);
36
-	else
35
+	if (!is_array($groups)) {
36
+			$groups = array((int) $groups);
37
+	} else
37 38
 	{
38 39
 		$groups = array_unique($groups);
39 40
 
40 41
 		// Make sure all groups are integer.
41
-		foreach ($groups as $key => $value)
42
-			$groups[$key] = (int) $value;
42
+		foreach ($groups as $key => $value) {
43
+					$groups[$key] = (int) $value;
44
+		}
43 45
 	}
44 46
 
45 47
 	// Some groups are protected (guests, administrators, moderators, newbies).
@@ -56,15 +58,17 @@  discard block
 block discarded – undo
56 58
 				'is_protected' => 1,
57 59
 			)
58 60
 		);
59
-		while ($row = $smcFunc['db_fetch_assoc']($request))
60
-			$protected_groups[] = $row['id_group'];
61
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
62
+					$protected_groups[] = $row['id_group'];
63
+		}
61 64
 		$smcFunc['db_free_result']($request);
62 65
 	}
63 66
 
64 67
 	// Make sure they don't delete protected groups!
65 68
 	$groups = array_diff($groups, array_unique($protected_groups));
66
-	if (empty($groups))
67
-		return 'no_group_found';
69
+	if (empty($groups)) {
70
+			return 'no_group_found';
71
+	}
68 72
 
69 73
 	// Make sure they don't try to delete a group attached to a paid subscription.
70 74
 	$subscriptions = array();
@@ -74,13 +78,14 @@  discard block
 block discarded – undo
74 78
 		ORDER BY name');
75 79
 	while ($row = $smcFunc['db_fetch_assoc']($request))
76 80
 	{
77
-		if (in_array($row['id_group'], $groups))
78
-			$subscriptions[] = $row['name'];
79
-		else
81
+		if (in_array($row['id_group'], $groups)) {
82
+					$subscriptions[] = $row['name'];
83
+		} else
80 84
 		{
81 85
 			$add_groups = explode(',', $row['add_groups']);
82
-			if (count(array_intersect($add_groups, $groups)) != 0)
83
-				$subscriptions[] = $row['name'];
86
+			if (count(array_intersect($add_groups, $groups)) != 0) {
87
+							$subscriptions[] = $row['name'];
88
+			}
84 89
 		}
85 90
 	}
86 91
 	$smcFunc['db_free_result']($request);
@@ -101,8 +106,9 @@  discard block
 block discarded – undo
101 106
 			'group_list' => $groups,
102 107
 		)
103 108
 	);
104
-	while ($row = $smcFunc['db_fetch_assoc']($request))
105
-		logAction('delete_group', array('group' => $row['group_name']), 'admin');
109
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
110
+			logAction('delete_group', array('group' => $row['group_name']), 'admin');
111
+	}
106 112
 	$smcFunc['db_free_result']($request);
107 113
 
108 114
 	call_integration_hook('integrate_delete_membergroups', array($groups));
@@ -187,12 +193,14 @@  discard block
 block discarded – undo
187 193
 		)
188 194
 	);
189 195
 	$updates = array();
190
-	while ($row = $smcFunc['db_fetch_assoc']($request))
191
-		$updates[$row['additional_groups']][] = $row['id_member'];
196
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
197
+			$updates[$row['additional_groups']][] = $row['id_member'];
198
+	}
192 199
 	$smcFunc['db_free_result']($request);
193 200
 
194
-	foreach ($updates as $additional_groups => $memberArray)
195
-		updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups))));
201
+	foreach ($updates as $additional_groups => $memberArray) {
202
+			updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups))));
203
+	}
196 204
 
197 205
 	// No boards can provide access to these membergroups anymore.
198 206
 	$request = $smcFunc['db_query']('', '
@@ -204,12 +212,13 @@  discard block
 block discarded – undo
204 212
 		)
205 213
 	);
206 214
 	$updates = array();
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$updates[$row['member_groups']][] = $row['id_board'];
215
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
216
+			$updates[$row['member_groups']][] = $row['id_board'];
217
+	}
209 218
 	$smcFunc['db_free_result']($request);
210 219
 
211
-	foreach ($updates as $member_groups => $boardArray)
212
-		$smcFunc['db_query']('', '
220
+	foreach ($updates as $member_groups => $boardArray) {
221
+			$smcFunc['db_query']('', '
213 222
 			UPDATE {db_prefix}boards
214 223
 			SET member_groups = {string:member_groups}
215 224
 			WHERE id_board IN ({array_int:board_lists})',
@@ -218,6 +227,7 @@  discard block
 block discarded – undo
218 227
 				'member_groups' => implode(',', array_diff(explode(',', $member_groups), $groups)),
219 228
 			)
220 229
 		);
230
+	}
221 231
 
222 232
 	// Recalculate the post groups, as they likely changed.
223 233
 	updateStats('postgroups');
@@ -225,8 +235,9 @@  discard block
 block discarded – undo
225 235
 	// Make a note of the fact that the cache may be wrong.
226 236
 	$settings_update = array('settings_updated' => time());
227 237
 	// Have we deleted the spider group?
228
-	if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups))
229
-		$settings_update['spider_group'] = 0;
238
+	if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) {
239
+			$settings_update['spider_group'] = 0;
240
+	}
230 241
 
231 242
 	updateSettings($settings_update);
232 243
 
@@ -250,22 +261,24 @@  discard block
 block discarded – undo
250 261
 	global $smcFunc, $modSettings, $sourcedir;
251 262
 
252 263
 	// You're getting nowhere without this permission, unless of course you are the group's moderator.
253
-	if (!$permissionCheckDone)
254
-		isAllowedTo('manage_membergroups');
264
+	if (!$permissionCheckDone) {
265
+			isAllowedTo('manage_membergroups');
266
+	}
255 267
 
256 268
 	// Assume something will happen.
257 269
 	updateSettings(array('settings_updated' => time()));
258 270
 
259 271
 	// Cleaning the input.
260
-	if (!is_array($members))
261
-		$members = array((int) $members);
262
-	else
272
+	if (!is_array($members)) {
273
+			$members = array((int) $members);
274
+	} else
263 275
 	{
264 276
 		$members = array_unique($members);
265 277
 
266 278
 		// Cast the members to integer.
267
-		foreach ($members as $key => $value)
268
-			$members[$key] = (int) $value;
279
+		foreach ($members as $key => $value) {
280
+					$members[$key] = (int) $value;
281
+		}
269 282
 	}
270 283
 
271 284
 	// Before we get started, let's check we won't leave the admin group empty!
@@ -277,14 +290,15 @@  discard block
 block discarded – undo
277 290
 		// Remove any admins if there are too many.
278 291
 		$non_changing_admins = array_diff(array_keys($admins), $members);
279 292
 
280
-		if (empty($non_changing_admins))
281
-			$members = array_diff($members, array_keys($admins));
293
+		if (empty($non_changing_admins)) {
294
+					$members = array_diff($members, array_keys($admins));
295
+		}
282 296
 	}
283 297
 
284 298
 	// Just in case.
285
-	if (empty($members))
286
-		return false;
287
-	elseif ($groups === null)
299
+	if (empty($members)) {
300
+			return false;
301
+	} elseif ($groups === null)
288 302
 	{
289 303
 		// Wanna remove all groups from these members? That's easy.
290 304
 		$smcFunc['db_query']('', '
@@ -306,20 +320,21 @@  discard block
 block discarded – undo
306 320
 		updateStats('postgroups', $members);
307 321
 
308 322
 		// Log what just happened.
309
-		foreach ($members as $member)
310
-			logAction('removed_all_groups', array('member' => $member), 'admin');
323
+		foreach ($members as $member) {
324
+					logAction('removed_all_groups', array('member' => $member), 'admin');
325
+		}
311 326
 
312 327
 		return true;
313
-	}
314
-	elseif (!is_array($groups))
315
-		$groups = array((int) $groups);
316
-	else
328
+	} elseif (!is_array($groups)) {
329
+			$groups = array((int) $groups);
330
+	} else
317 331
 	{
318 332
 		$groups = array_unique($groups);
319 333
 
320 334
 		// Make sure all groups are integer.
321
-		foreach ($groups as $key => $value)
322
-			$groups[$key] = (int) $value;
335
+		foreach ($groups as $key => $value) {
336
+					$groups[$key] = (int) $value;
337
+		}
323 338
 	}
324 339
 
325 340
 	// Fetch a list of groups members cannot be assigned to explicitly, and the group names of the ones we want.
@@ -335,10 +350,11 @@  discard block
 block discarded – undo
335 350
 	$group_names = array();
336 351
 	while ($row = $smcFunc['db_fetch_assoc']($request))
337 352
 	{
338
-		if ($row['min_posts'] != -1)
339
-			$implicitGroups[] = $row['id_group'];
340
-		else
341
-			$group_names[$row['id_group']] = $row['group_name'];
353
+		if ($row['min_posts'] != -1) {
354
+					$implicitGroups[] = $row['id_group'];
355
+		} else {
356
+					$group_names[$row['id_group']] = $row['group_name'];
357
+		}
342 358
 	}
343 359
 	$smcFunc['db_free_result']($request);
344 360
 
@@ -357,8 +373,9 @@  discard block
 block discarded – undo
357 373
 			)
358 374
 		);
359 375
 		$protected_groups = array(1);
360
-		while ($row = $smcFunc['db_fetch_assoc']($request))
361
-			$protected_groups[] = $row['id_group'];
376
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
377
+					$protected_groups[] = $row['id_group'];
378
+		}
362 379
 		$smcFunc['db_free_result']($request);
363 380
 
364 381
 		// If you're not an admin yourself, you can't touch protected groups!
@@ -366,8 +383,9 @@  discard block
 block discarded – undo
366 383
 	}
367 384
 
368 385
 	// Only continue if there are still groups and members left.
369
-	if (empty($groups) || empty($members))
370
-		return false;
386
+	if (empty($groups) || empty($members)) {
387
+			return false;
388
+	}
371 389
 
372 390
 	// First, reset those who have this as their primary group - this is the easy one.
373 391
 	$log_inserts = array();
@@ -381,8 +399,9 @@  discard block
 block discarded – undo
381 399
 			'member_list' => $members,
382 400
 		)
383 401
 	);
384
-	while ($row = $smcFunc['db_fetch_assoc']($request))
385
-		$log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']);
402
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
403
+			$log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']);
404
+	}
386 405
 	$smcFunc['db_free_result']($request);
387 406
 
388 407
 	$smcFunc['db_query']('', '
@@ -414,16 +433,17 @@  discard block
 block discarded – undo
414 433
 	while ($row = $smcFunc['db_fetch_assoc']($request))
415 434
 	{
416 435
 		// What log entries must we make for this one, eh?
417
-		foreach (explode(',', $row['additional_groups']) as $group)
418
-			if (in_array($group, $groups))
436
+		foreach (explode(',', $row['additional_groups']) as $group) {
437
+					if (in_array($group, $groups))
419 438
 				$log_inserts[] = array('group' => $group_names[$group], 'member' => $row['id_member']);
439
+		}
420 440
 
421 441
 		$updates[$row['additional_groups']][] = $row['id_member'];
422 442
 	}
423 443
 	$smcFunc['db_free_result']($request);
424 444
 
425
-	foreach ($updates as $additional_groups => $memberArray)
426
-		$smcFunc['db_query']('', '
445
+	foreach ($updates as $additional_groups => $memberArray) {
446
+			$smcFunc['db_query']('', '
427 447
 			UPDATE {db_prefix}members
428 448
 			SET additional_groups = {string:additional_groups}
429 449
 			WHERE id_member IN ({array_int:member_list})',
@@ -432,6 +452,7 @@  discard block
 block discarded – undo
432 452
 				'additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)),
433 453
 			)
434 454
 		);
455
+	}
435 456
 
436 457
 	// Their post groups may have changed now...
437 458
 	updateStats('postgroups', $members);
@@ -440,8 +461,9 @@  discard block
 block discarded – undo
440 461
 	if (!empty($log_inserts) && !empty($modSettings['modlog_enabled']))
441 462
 	{
442 463
 		require_once($sourcedir . '/Logging.php');
443
-		foreach ($log_inserts as $extra)
444
-			logAction('removed_from_group', $extra, 'admin');
464
+		foreach ($log_inserts as $extra) {
465
+					logAction('removed_from_group', $extra, 'admin');
466
+		}
445 467
 	}
446 468
 
447 469
 	// Mission successful.
@@ -477,21 +499,23 @@  discard block
 block discarded – undo
477 499
 	global $smcFunc, $sourcedir;
478 500
 
479 501
 	// Show your licence, but only if it hasn't been done yet.
480
-	if (!$permissionCheckDone)
481
-		isAllowedTo('manage_membergroups');
502
+	if (!$permissionCheckDone) {
503
+			isAllowedTo('manage_membergroups');
504
+	}
482 505
 
483 506
 	// Make sure we don't keep old stuff cached.
484 507
 	updateSettings(array('settings_updated' => time()));
485 508
 
486
-	if (!is_array($members))
487
-		$members = array((int) $members);
488
-	else
509
+	if (!is_array($members)) {
510
+			$members = array((int) $members);
511
+	} else
489 512
 	{
490 513
 		$members = array_unique($members);
491 514
 
492 515
 		// Make sure all members are integer.
493
-		foreach ($members as $key => $value)
494
-			$members[$key] = (int) $value;
516
+		foreach ($members as $key => $value) {
517
+					$members[$key] = (int) $value;
518
+		}
495 519
 	}
496 520
 	$group = (int) $group;
497 521
 
@@ -508,20 +532,23 @@  discard block
 block discarded – undo
508 532
 	$group_names = array();
509 533
 	while ($row = $smcFunc['db_fetch_assoc']($request))
510 534
 	{
511
-		if ($row['min_posts'] != -1)
512
-			$implicitGroups[] = $row['id_group'];
513
-		else
514
-			$group_names[$row['id_group']] = $row['group_name'];
535
+		if ($row['min_posts'] != -1) {
536
+					$implicitGroups[] = $row['id_group'];
537
+		} else {
538
+					$group_names[$row['id_group']] = $row['group_name'];
539
+		}
515 540
 	}
516 541
 	$smcFunc['db_free_result']($request);
517 542
 
518 543
 	// Sorry, you can't join an implicit group.
519
-	if (in_array($group, $implicitGroups) || empty($members))
520
-		return false;
544
+	if (in_array($group, $implicitGroups) || empty($members)) {
545
+			return false;
546
+	}
521 547
 
522 548
 	// Only admins can add admins...
523
-	if (!allowedTo('admin_forum') && $group == 1)
524
-		return false;
549
+	if (!allowedTo('admin_forum') && $group == 1) {
550
+			return false;
551
+	}
525 552
 	// ... and assign protected groups!
526 553
 	elseif (!allowedTo('admin_forum') && !$ignoreProtected)
527 554
 	{
@@ -539,13 +566,14 @@  discard block
 block discarded – undo
539 566
 		$smcFunc['db_free_result']($request);
540 567
 
541 568
 		// Is it protected?
542
-		if ($is_protected == 1)
543
-			return false;
569
+		if ($is_protected == 1) {
570
+					return false;
571
+		}
544 572
 	}
545 573
 
546 574
 	// Do the actual updates.
547
-	if ($type == 'only_additional')
548
-		$smcFunc['db_query']('', '
575
+	if ($type == 'only_additional') {
576
+			$smcFunc['db_query']('', '
549 577
 			UPDATE {db_prefix}members
550 578
 			SET additional_groups = CASE WHEN additional_groups = {string:blank_string} THEN {string:id_group_string} ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END
551 579
 			WHERE id_member IN ({array_int:member_list})
@@ -559,8 +587,8 @@  discard block
 block discarded – undo
559 587
 				'blank_string' => '',
560 588
 			)
561 589
 		);
562
-	elseif ($type == 'only_primary' || $type == 'force_primary')
563
-		$smcFunc['db_query']('', '
590
+	} elseif ($type == 'only_primary' || $type == 'force_primary') {
591
+			$smcFunc['db_query']('', '
564 592
 			UPDATE {db_prefix}members
565 593
 			SET id_group = {int:id_group}
566 594
 			WHERE id_member IN ({array_int:member_list})' . ($type == 'force_primary' ? '' : '
@@ -572,8 +600,8 @@  discard block
 block discarded – undo
572 600
 				'regular_group' => 0,
573 601
 			)
574 602
 		);
575
-	elseif ($type == 'auto')
576
-		$smcFunc['db_query']('', '
603
+	} elseif ($type == 'auto') {
604
+			$smcFunc['db_query']('', '
577 605
 			UPDATE {db_prefix}members
578 606
 			SET
579 607
 				id_group = CASE WHEN id_group = {int:regular_group} THEN {int:id_group} ELSE id_group END,
@@ -592,9 +620,11 @@  discard block
 block discarded – undo
592 620
 				'id_group_string_extend' => ',' . $group,
593 621
 			)
594 622
 		);
623
+	}
595 624
 	// Ack!!?  What happened?
596
-	else
597
-		trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING);
625
+	else {
626
+			trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING);
627
+	}
598 628
 
599 629
 	call_integration_hook('integrate_add_members_to_group', array($members, $group, &$group_names));
600 630
 
@@ -603,8 +633,9 @@  discard block
 block discarded – undo
603 633
 
604 634
 	// Log the data.
605 635
 	require_once($sourcedir . '/Logging.php');
606
-	foreach ($members as $member)
607
-		logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin');
636
+	foreach ($members as $member) {
637
+			logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin');
638
+	}
608 639
 
609 640
 	return true;
610 641
 }
@@ -632,8 +663,9 @@  discard block
 block discarded – undo
632 663
 		)
633 664
 	);
634 665
 	$members = array();
635
-	while ($row = $smcFunc['db_fetch_assoc']($request))
636
-		$members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
666
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
667
+			$members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
668
+	}
637 669
 	$smcFunc['db_free_result']($request);
638 670
 
639 671
 	// If there are more than $limit members, add a 'more' link.
@@ -641,10 +673,10 @@  discard block
 block discarded – undo
641 673
 	{
642 674
 		array_pop($members);
643 675
 		return true;
676
+	} else {
677
+			return false;
678
+	}
644 679
 	}
645
-	else
646
-		return false;
647
-}
648 680
 
649 681
 /**
650 682
  * Retrieve a list of (visible) membergroups used by the cache.
@@ -669,8 +701,9 @@  discard block
 block discarded – undo
669 701
 		)
670 702
 	);
671 703
 	$groupCache = array();
672
-	while ($row = $smcFunc['db_fetch_assoc']($request))
673
-		$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
704
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
705
+			$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
706
+	}
674 707
 	$smcFunc['db_free_result']($request);
675 708
 
676 709
 	return array(
@@ -718,8 +751,9 @@  discard block
 block discarded – undo
718 751
 	while ($row = $smcFunc['db_fetch_assoc']($request))
719 752
 	{
720 753
 		// We only list the groups they can see.
721
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
722
-			continue;
754
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
755
+					continue;
756
+		}
723 757
 
724 758
 		$row['icons'] = explode('#', $row['icons']);
725 759
 
@@ -754,12 +788,11 @@  discard block
 block discarded – undo
754 788
 					'group_list' => $group_ids,
755 789
 				)
756 790
 			);
757
-			while ($row = $smcFunc['db_fetch_assoc']($query))
758
-				$groups[$row['id_group']]['num_members'] += $row['num_members'];
791
+			while ($row = $smcFunc['db_fetch_assoc']($query)) {
792
+							$groups[$row['id_group']]['num_members'] += $row['num_members'];
793
+			}
759 794
 			$smcFunc['db_free_result']($query);
760
-		}
761
-
762
-		else
795
+		} else
763 796
 		{
764 797
 			$query = $smcFunc['db_query']('', '
765 798
 				SELECT id_group, COUNT(*) AS num_members
@@ -770,8 +803,9 @@  discard block
 block discarded – undo
770 803
 					'group_list' => $group_ids,
771 804
 				)
772 805
 			);
773
-			while ($row = $smcFunc['db_fetch_assoc']($query))
774
-				$groups[$row['id_group']]['num_members'] += $row['num_members'];
806
+			while ($row = $smcFunc['db_fetch_assoc']($query)) {
807
+							$groups[$row['id_group']]['num_members'] += $row['num_members'];
808
+			}
775 809
 			$smcFunc['db_free_result']($query);
776 810
 
777 811
 			// Only do additional groups if we can moderate...
@@ -790,8 +824,9 @@  discard block
 block discarded – undo
790 824
 						'blank_string' => '',
791 825
 					)
792 826
 				);
793
-				while ($row = $smcFunc['db_fetch_assoc']($query))
794
-					$groups[$row['id_group']]['num_members'] += $row['num_members'];
827
+				while ($row = $smcFunc['db_fetch_assoc']($query)) {
828
+									$groups[$row['id_group']]['num_members'] += $row['num_members'];
829
+				}
795 830
 				$smcFunc['db_free_result']($query);
796 831
 			}
797 832
 		}
@@ -805,8 +840,9 @@  discard block
 block discarded – undo
805 840
 				'group_list' => $group_ids,
806 841
 			)
807 842
 		);
808
-		while ($row = $smcFunc['db_fetch_assoc']($query))
809
-			$groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
843
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
844
+					$groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
845
+		}
810 846
 		$smcFunc['db_free_result']($query);
811 847
 	}
812 848
 
@@ -815,8 +851,9 @@  discard block
 block discarded – undo
815 851
 	{
816 852
 		$sort_ascending = strpos($sort, 'DESC') === false;
817 853
 
818
-		foreach ($groups as $group)
819
-			$sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1;
854
+		foreach ($groups as $group) {
855
+					$sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1;
856
+		}
820 857
 
821 858
 		array_multisort($sort_array, $sort_ascending ? SORT_ASC : SORT_DESC, SORT_REGULAR, $groups);
822 859
 	}
Please login to merge, or discard this patch.
Sources/Subs-Menu.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -286,7 +286,7 @@
 block discarded – undo
286 286
 /**
287 287
  * Delete a menu.
288 288
  * @param string $menu_id The ID of the menu to destroy or 'last' for the most recent one
289
- * @return bool|void False if the menu doesn't exist, nothing otherwise
289
+ * @return false|null False if the menu doesn't exist, nothing otherwise
290 290
  */
291 291
 function destroyMenu($menu_id = 'last')
292 292
 {
Please login to merge, or discard this patch.
Braces   +87 added lines, -63 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Create a menu.
@@ -64,22 +65,26 @@  discard block
 block discarded – undo
64 65
 	$menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action'];
65 66
 
66 67
 	// Allow extend *any* menu with a single hook
67
-	if (!empty($menu_context['current_action']))
68
-		call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
68
+	if (!empty($menu_context['current_action'])) {
69
+			call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
70
+	}
69 71
 
70 72
 	// What is the current area selected?
71
-	if (isset($menuOptions['current_area']) || isset($_GET['area']))
72
-		$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
73
+	if (isset($menuOptions['current_area']) || isset($_GET['area'])) {
74
+			$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
75
+	}
73 76
 
74 77
 	// Build a list of additional parameters that should go in the URL.
75 78
 	$menu_context['extra_parameters'] = '';
76
-	if (!empty($menuOptions['extra_url_parameters']))
77
-		foreach ($menuOptions['extra_url_parameters'] as $key => $value)
79
+	if (!empty($menuOptions['extra_url_parameters'])) {
80
+			foreach ($menuOptions['extra_url_parameters'] as $key => $value)
78 81
 			$menu_context['extra_parameters'] .= ';' . $key . '=' . $value;
82
+	}
79 83
 
80 84
 	// Only include the session ID in the URL if it's strictly necessary.
81
-	if (empty($menuOptions['disable_url_session_check']))
82
-		$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
85
+	if (empty($menuOptions['disable_url_session_check'])) {
86
+			$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
87
+	}
83 88
 
84 89
 	$include_data = array();
85 90
 
@@ -87,8 +92,9 @@  discard block
 block discarded – undo
87 92
 	foreach ($menuData as $section_id => $section)
88 93
 	{
89 94
 		// Is this enabled - or has as permission check - which fails?
90
-		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission'])))
91
-			continue;
95
+		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) {
96
+					continue;
97
+		}
92 98
 
93 99
 		// Now we cycle through the sections to pick the right area.
94 100
 		foreach ($section['areas'] as $area_id => $area)
@@ -110,41 +116,45 @@  discard block
 block discarded – undo
110 116
 					if (empty($area['hidden']))
111 117
 					{
112 118
 						// First time this section?
113
-						if (!isset($menu_context['sections'][$section_id]))
114
-							$menu_context['sections'][$section_id]['title'] = $section['title'];
119
+						if (!isset($menu_context['sections'][$section_id])) {
120
+													$menu_context['sections'][$section_id]['title'] = $section['title'];
121
+						}
115 122
 
116 123
 						$menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]);
117 124
 						// We'll need the ID as well...
118 125
 						$menu_context['sections'][$section_id]['id'] = $section_id;
119 126
 						// Does it have a custom URL?
120
-						if (isset($area['custom_url']))
121
-							$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
127
+						if (isset($area['custom_url'])) {
128
+													$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
129
+						}
122 130
 
123 131
 						// Does this area have its own icon?
124
-						if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa')
125
-							$menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9'));
126
-						elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon']))
127
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">';
128
-						elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon']))
129
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">';
130
-						elseif (isset($area['icon']))
131
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
132
-						else
133
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
134
-
135
-						if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon']))
136
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class'];
137
-						elseif (isset($area['icon']))
132
+						if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') {
133
+													$menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9'));
134
+						} elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) {
135
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">';
136
+						} elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) {
137
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">';
138
+						} elseif (isset($area['icon'])) {
139
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
140
+						} else {
141
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
142
+						}
143
+
144
+						if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) {
145
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class'];
146
+						} elseif (isset($area['icon']))
138 147
 						{
139
-							if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon']))
140
-								$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon'];
141
-							elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
142
-								$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon'];
148
+							if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) {
149
+															$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon'];
150
+							} elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) {
151
+															$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon'];
152
+							}
143 153
 
144 154
 							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']);
155
+						} else {
156
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
145 157
 						}
146
-						else
147
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
148 158
 
149 159
 						// Some areas may be listed but not active, which we show as greyed out.
150 160
 						$menu_context['sections'][$section_id]['areas'][$area_id]['inactive'] = !empty($area['inactive']);
@@ -158,35 +168,41 @@  discard block
 block discarded – undo
158 168
 							{
159 169
 								if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled'])))
160 170
 								{
161
-									if ($first_sa == null)
162
-										$first_sa = $sa;
171
+									if ($first_sa == null) {
172
+																			$first_sa = $sa;
173
+									}
163 174
 
164 175
 									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]);
165 176
 									// Custom URL?
166
-									if (isset($sub['url']))
167
-										$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
177
+									if (isset($sub['url'])) {
178
+																			$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
179
+									}
168 180
 
169 181
 									// A bit complicated - but is this set?
170 182
 									if ($menu_context['current_area'] == $area_id)
171 183
 									{
172 184
 										// Save which is the first...
173
-										if (empty($first_sa))
174
-											$first_sa = $sa;
185
+										if (empty($first_sa)) {
186
+																					$first_sa = $sa;
187
+										}
175 188
 
176 189
 										// Is this the current subsection?
177
-										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa)
178
-											$menu_context['current_subsection'] = $sa;
190
+										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) {
191
+																					$menu_context['current_subsection'] = $sa;
192
+										}
179 193
 										// Otherwise is it the default?
180
-										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2]))
181
-											$menu_context['current_subsection'] = $sa;
194
+										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) {
195
+																					$menu_context['current_subsection'] = $sa;
196
+										}
182 197
 									}
183 198
 
184 199
 									// Let's assume this is the last, for now.
185 200
 									$last_sa = $sa;
186 201
 								}
187 202
 								// Mark it as disabled...
188
-								else
189
-									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
203
+								else {
204
+																	$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
205
+								}
190 206
 							}
191 207
 
192 208
 							// Set which one is first, last and selected in the group.
@@ -195,8 +211,9 @@  discard block
 block discarded – undo
195 211
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true;
196 212
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true;
197 213
 
198
-								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection']))
199
-									$menu_context['current_subsection'] = $first_sa;
214
+								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) {
215
+																	$menu_context['current_subsection'] = $first_sa;
216
+								}
200 217
 							}
201 218
 						}
202 219
 					}
@@ -230,23 +247,26 @@  discard block
 block discarded – undo
230 247
 	$menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action'];
231 248
 
232 249
 	// If we didn't find the area we were looking for go to a default one.
233
-	if (isset($backup_area) && empty($found_section))
234
-		$menu_context['current_area'] = $backup_area;
250
+	if (isset($backup_area) && empty($found_section)) {
251
+			$menu_context['current_area'] = $backup_area;
252
+	}
235 253
 
236 254
 	// If there are sections quickly goes through all the sections to check if the base menu has an url
237 255
 	if (!empty($menu_context['current_section']))
238 256
 	{
239 257
 		$menu_context['sections'][$menu_context['current_section']]['selected'] = true;
240 258
 		$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true;
241
-		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]))
242
-			$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
259
+		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) {
260
+					$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
261
+		}
243 262
 
244
-		foreach ($menu_context['sections'] as $section_id => $section)
245
-			foreach ($section['areas'] as $area_id => $area)
263
+		foreach ($menu_context['sections'] as $section_id => $section) {
264
+					foreach ($section['areas'] as $area_id => $area)
246 265
 			{
247 266
 				if (!isset($menu_context['sections'][$section_id]['url']))
248 267
 				{
249 268
 					$menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id;
269
+		}
250 270
 					break;
251 271
 				}
252 272
 			}
@@ -257,8 +277,9 @@  discard block
 block discarded – undo
257 277
 	{
258 278
 		// Never happened!
259 279
 		$context['max_menu_id']--;
260
-		if ($context['max_menu_id'] == 0)
261
-			unset($context['max_menu_id']);
280
+		if ($context['max_menu_id'] == 0) {
281
+					unset($context['max_menu_id']);
282
+		}
262 283
 
263 284
 		return false;
264 285
 	}
@@ -269,8 +290,9 @@  discard block
 block discarded – undo
269 290
 	$context['template_layers'][] = $menu_context['layer_name'];
270 291
 
271 292
 	// Check we had something - for sanity sake.
272
-	if (empty($include_data))
273
-		return false;
293
+	if (empty($include_data)) {
294
+			return false;
295
+	}
274 296
 
275 297
 	// Finally - return information on the selected item.
276 298
 	$include_data += array(
@@ -293,12 +315,14 @@  discard block
 block discarded – undo
293 315
 	global $context;
294 316
 
295 317
 	$menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id;
296
-	if (!isset($context[$menu_name]))
297
-		return false;
318
+	if (!isset($context[$menu_name])) {
319
+			return false;
320
+	}
298 321
 
299 322
 	$layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']);
300
-	if ($layer_index !== false)
301
-		unset($context['template_layers'][$layer_index]);
323
+	if ($layer_index !== false) {
324
+			unset($context['template_layers'][$layer_index]);
325
+	}
302 326
 
303 327
 	unset($context[$menu_name]);
304 328
 }
Please login to merge, or discard this patch.
Sources/Subs-Package.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  * @param bool $single_file If true returns the contents of the file specified by destination if it exists
29 29
  * @param bool $overwrite Whether to overwrite existing files
30 30
  * @param null|array $files_to_extract Specific files to extract
31
- * @return array|false An array of information about extracted files or false on failure
31
+ * @return string An array of information about extracted files or false on failure
32 32
  */
33 33
 function read_tgz_file($gzfilename, $destination, $single_file = false, $overwrite = false, $files_to_extract = null)
34 34
 {
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
  * @param bool $single_file Whether to only extract a single file
60 60
  * @param bool $overwrite Whether to overwrite existing data
61 61
  * @param null|array $files_to_extract If set, only extracts the specified files
62
- * @return array|false An array of information about the extracted files or false on failure
62
+ * @return string An array of information about the extracted files or false on failure
63 63
  */
64 64
 function read_tgz_data($gzfilename, $destination, $single_file = false, $overwrite = false, $files_to_extract = null)
65 65
 {
@@ -3251,7 +3251,7 @@  discard block
 block discarded – undo
3251 3251
 	 * http://www.php.net/crc32#79567
3252 3252
 	 *
3253 3253
 	 * @param string $number
3254
-	 * @return string The crc32
3254
+	 * @return integer The crc32
3255 3255
 	 */
3256 3256
 	function smf_crc32($number)
3257 3257
 	{
Please login to merge, or discard this patch.
Braces   +853 added lines, -669 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
  * @version 2.1 Beta 3
17 17
  */
18 18
 
19
-if (!defined('SMF'))
19
+if (!defined('SMF')) {
20 20
 	die('No direct access...');
21
+}
21 22
 
22 23
 /**
23 24
  * Reads a .tar.gz file, filename, in and extracts file(s) from it.
@@ -67,47 +68,53 @@  discard block
 block discarded – undo
67 68
 	loadLanguage('Packages');
68 69
 
69 70
 	// This function sorta needs gzinflate!
70
-	if (!function_exists('gzinflate'))
71
-		fatal_lang_error('package_no_zlib', 'critical');
71
+	if (!function_exists('gzinflate')) {
72
+			fatal_lang_error('package_no_zlib', 'critical');
73
+	}
72 74
 
73 75
 	if (substr($gzfilename, 0, 7) == 'http://' || substr($gzfilename, 0, 8) == 'https://')
74 76
 	{
75 77
 		$data = fetch_web_data($gzfilename);
76 78
 
77
-		if ($data === false)
78
-			return false;
79
-	}
80
-	else
79
+		if ($data === false) {
80
+					return false;
81
+		}
82
+	} else
81 83
 	{
82 84
 		$data = @file_get_contents($gzfilename);
83 85
 
84
-		if ($data === false)
85
-			return false;
86
+		if ($data === false) {
87
+					return false;
88
+		}
86 89
 	}
87 90
 
88 91
 	umask(0);
89
-	if (!$single_file && $destination !== null && !file_exists($destination))
90
-		mktree($destination, 0777);
92
+	if (!$single_file && $destination !== null && !file_exists($destination)) {
93
+			mktree($destination, 0777);
94
+	}
91 95
 
92 96
 	// No signature?
93
-	if (strlen($data) < 2)
94
-		return false;
97
+	if (strlen($data) < 2) {
98
+			return false;
99
+	}
95 100
 
96 101
 	$id = unpack('H2a/H2b', substr($data, 0, 2));
97 102
 	if (strtolower($id['a'] . $id['b']) != '1f8b')
98 103
 	{
99 104
 		// Okay, this ain't no tar.gz, but maybe it's a zip file.
100
-		if (substr($data, 0, 2) == 'PK')
101
-			return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract);
102
-		else
103
-			return false;
105
+		if (substr($data, 0, 2) == 'PK') {
106
+					return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract);
107
+		} else {
108
+					return false;
109
+		}
104 110
 	}
105 111
 
106 112
 	$flags = unpack('Ct/Cf', substr($data, 2, 2));
107 113
 
108 114
 	// Not deflate!
109
-	if ($flags['t'] != 8)
110
-		return false;
115
+	if ($flags['t'] != 8) {
116
+			return false;
117
+	}
111 118
 	$flags = $flags['f'];
112 119
 
113 120
 	$offset = 10;
@@ -117,18 +124,21 @@  discard block
 block discarded – undo
117 124
 	// @todo Might be mussed.
118 125
 	if ($flags & 12)
119 126
 	{
120
-		while ($flags & 8 && $data{$offset++} != "\0")
121
-			continue;
122
-		while ($flags & 4 && $data{$offset++} != "\0")
123
-			continue;
127
+		while ($flags & 8 && $data{$offset++} != "\0") {
128
+					continue;
129
+		}
130
+		while ($flags & 4 && $data{$offset++} != "\0") {
131
+					continue;
132
+		}
124 133
 	}
125 134
 
126 135
 	$crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8));
127 136
 	$data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset));
128 137
 
129 138
 	// smf_crc32 and crc32 may not return the same results, so we accept either.
130
-	if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data))
131
-		return false;
139
+	if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) {
140
+			return false;
141
+	}
132 142
 
133 143
 	$blocks = strlen($data) / 512 - 1;
134 144
 	$offset = 0;
@@ -149,83 +159,98 @@  discard block
 block discarded – undo
149 159
 
150 160
 		foreach ($current as $k => $v)
151 161
 		{
152
-			if (in_array($k, $octdec))
153
-				$current[$k] = octdec(trim($v));
154
-			else
155
-				$current[$k] = trim($v);
162
+			if (in_array($k, $octdec)) {
163
+							$current[$k] = octdec(trim($v));
164
+			} else {
165
+							$current[$k] = trim($v);
166
+			}
156 167
 		}
157 168
 
158
-		if ($current['type'] == 5 && substr($current['filename'], -1) != '/')
159
-			$current['filename'] .= '/';
169
+		if ($current['type'] == 5 && substr($current['filename'], -1) != '/') {
170
+					$current['filename'] .= '/';
171
+		}
160 172
 
161 173
 		$checksum = 256;
162
-		for ($i = 0; $i < 148; $i++)
163
-			$checksum += ord($header{$i});
164
-		for ($i = 156; $i < 512; $i++)
165
-			$checksum += ord($header{$i});
174
+		for ($i = 0; $i < 148; $i++) {
175
+					$checksum += ord($header{$i});
176
+		}
177
+		for ($i = 156; $i < 512; $i++) {
178
+					$checksum += ord($header{$i});
179
+		}
166 180
 
167
-		if ($current['checksum'] != $checksum)
168
-			break;
181
+		if ($current['checksum'] != $checksum) {
182
+					break;
183
+		}
169 184
 
170 185
 		$size = ceil($current['size'] / 512);
171 186
 		$current['data'] = substr($data, ++$offset << 9, $current['size']);
172 187
 		$offset += $size;
173 188
 
174 189
 		// Not a directory and doesn't exist already...
175
-		if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename']))
176
-			$write_this = true;
190
+		if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) {
191
+					$write_this = true;
192
+		}
177 193
 		// File exists... check if it is newer.
178
-		elseif (substr($current['filename'], -1, 1) != '/')
179
-			$write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime'];
194
+		elseif (substr($current['filename'], -1, 1) != '/') {
195
+					$write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime'];
196
+		}
180 197
 		// Folder... create.
181 198
 		elseif ($destination !== null && !$single_file)
182 199
 		{
183 200
 			// Protect from accidental parent directory writing...
184 201
 			$current['filename'] = strtr($current['filename'], array('../' => '', '/..' => ''));
185 202
 
186
-			if (!file_exists($destination . '/' . $current['filename']))
187
-				mktree($destination . '/' . $current['filename'], 0777);
203
+			if (!file_exists($destination . '/' . $current['filename'])) {
204
+							mktree($destination . '/' . $current['filename'], 0777);
205
+			}
188 206
 			$write_this = false;
207
+		} else {
208
+					$write_this = false;
189 209
 		}
190
-		else
191
-			$write_this = false;
192 210
 
193 211
 		if ($write_this && $destination !== null)
194 212
 		{
195
-			if (strpos($current['filename'], '/') !== false && !$single_file)
196
-				mktree($destination . '/' . dirname($current['filename']), 0777);
213
+			if (strpos($current['filename'], '/') !== false && !$single_file) {
214
+							mktree($destination . '/' . dirname($current['filename']), 0777);
215
+			}
197 216
 
198 217
 			// Is this the file we're looking for?
199
-			if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename'])))
200
-				return $current['data'];
218
+			if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) {
219
+							return $current['data'];
220
+			}
201 221
 			// If we're looking for another file, keep going.
202
-			elseif ($single_file)
203
-				continue;
222
+			elseif ($single_file) {
223
+							continue;
224
+			}
204 225
 			// Looking for restricted files?
205
-			elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract))
206
-				continue;
226
+			elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) {
227
+							continue;
228
+			}
207 229
 
208 230
 			package_put_contents($destination . '/' . $current['filename'], $current['data']);
209 231
 		}
210 232
 
211
-		if (substr($current['filename'], -1, 1) != '/')
212
-			$return[] = array(
233
+		if (substr($current['filename'], -1, 1) != '/') {
234
+					$return[] = array(
213 235
 				'filename' => $current['filename'],
214 236
 				'md5' => md5($current['data']),
215 237
 				'preview' => substr($current['data'], 0, 100),
216 238
 				'size' => $current['size'],
217 239
 				'skipped' => false
218 240
 			);
241
+		}
219 242
 	}
220 243
 
221
-	if ($destination !== null && !$single_file)
222
-		package_flush_cache();
244
+	if ($destination !== null && !$single_file) {
245
+			package_flush_cache();
246
+	}
223 247
 
224
-	if ($single_file)
225
-		return false;
226
-	else
227
-		return $return;
228
-}
248
+	if ($single_file) {
249
+			return false;
250
+	} else {
251
+			return $return;
252
+	}
253
+	}
229 254
 
230 255
 /**
231 256
  * Extract zip data. A functional copy of {@list read_zip_data()}.
@@ -254,65 +279,74 @@  discard block
 block discarded – undo
254 279
 			{
255 280
 				$i = $iterator->getSubPathname();
256 281
 				// If this is a file, and it doesn't exist.... happy days!
257
-				if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i))
258
-					$write_this = true;
282
+				if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) {
283
+									$write_this = true;
284
+				}
259 285
 				// If the file exists, we may not want to overwrite it.
260
-				elseif (substr($i, -1) != '/')
261
-					$write_this = $overwrite;
262
-				else
263
-					$write_this = false;
286
+				elseif (substr($i, -1) != '/') {
287
+									$write_this = $overwrite;
288
+				} else {
289
+									$write_this = false;
290
+				}
264 291
 
265 292
 				// Get the actual compressed data.
266
-				if (!$file_info->isDir())
267
-					$file_data = file_get_contents($file_info);
268
-				elseif ($destination !== null && !$single_file)
293
+				if (!$file_info->isDir()) {
294
+									$file_data = file_get_contents($file_info);
295
+				} elseif ($destination !== null && !$single_file)
269 296
 				{
270 297
 					// Folder... create.
271
-					if (!file_exists($destination . '/' . $i))
272
-						mktree($destination . '/' . $i, 0777);
298
+					if (!file_exists($destination . '/' . $i)) {
299
+											mktree($destination . '/' . $i, 0777);
300
+					}
273 301
 					$file_data = null;
302
+				} else {
303
+									$file_data = null;
274 304
 				}
275
-				else
276
-					$file_data = null;
277 305
 
278 306
 				// Okay!  We can write this file, looks good from here...
279 307
 				if ($write_this && $destination !== null)
280 308
 				{
281
-					if (!$single_file && !is_dir($destination . '/' . dirname($i)))
282
-						mktree($destination . '/' . dirname($i), 0777);
309
+					if (!$single_file && !is_dir($destination . '/' . dirname($i))) {
310
+											mktree($destination . '/' . dirname($i), 0777);
311
+					}
283 312
 
284 313
 					// If we're looking for a specific file, and this is it... ka-bam, baby.
285
-					if ($single_file && ($destination == $i || $destination == '*/' . basename($i)))
286
-						return $file_data;
314
+					if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) {
315
+											return $file_data;
316
+					}
287 317
 					// Oh?  Another file.  Fine.  You don't like this file, do you?  I know how it is.  Yeah... just go away.  No, don't apologize.  I know this file's just not *good enough* for you.
288
-					elseif ($single_file)
289
-						continue;
318
+					elseif ($single_file) {
319
+											continue;
320
+					}
290 321
 					// Don't really want this?
291
-					elseif ($files_to_extract !== null && !in_array($i, $files_to_extract))
292
-						continue;
322
+					elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) {
323
+											continue;
324
+					}
293 325
 
294 326
 					package_put_contents($destination . '/' . $i, $file_data);
295 327
 				}
296 328
 
297
-				if (substr($i, -1, 1) != '/')
298
-					$return[] = array(
329
+				if (substr($i, -1, 1) != '/') {
330
+									$return[] = array(
299 331
 						'filename' => $i,
300 332
 						'md5' => md5($file_data),
301 333
 						'preview' => substr($file_data, 0, 100),
302 334
 						'size' => strlen($file_data),
303 335
 						'skipped' => false
304 336
 					);
337
+				}
305 338
 			}
306 339
 
307
-		if ($destination !== null && !$single_file)
308
-			package_flush_cache();
340
+		if ($destination !== null && !$single_file) {
341
+					package_flush_cache();
342
+		}
309 343
 
310
-		if ($single_file)
311
-			return false;
312
-		else
313
-			return $return;
314
-	}
315
-	catch (Exception $e)
344
+		if ($single_file) {
345
+					return false;
346
+		} else {
347
+					return $return;
348
+		}
349
+	} catch (Exception $e)
316 350
 	{
317 351
 		return false;
318 352
 	}
@@ -334,13 +368,15 @@  discard block
 block discarded – undo
334 368
 function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null)
335 369
 {
336 370
 	umask(0);
337
-	if ($destination !== null && !file_exists($destination) && !$single_file)
338
-		mktree($destination, 0777);
371
+	if ($destination !== null && !file_exists($destination) && !$single_file) {
372
+			mktree($destination, 0777);
373
+	}
339 374
 
340 375
 	// Look for the end of directory signature 0x06054b50
341 376
 	$data_ecr = explode("\x50\x4b\x05\x06", $data);
342
-	if (!isset($data_ecr[1]))
343
-		return false;
377
+	if (!isset($data_ecr[1])) {
378
+			return false;
379
+	}
344 380
 
345 381
 	$return = array();
346 382
 
@@ -355,8 +391,9 @@  discard block
 block discarded – undo
355 391
 	array_shift($file_sections);
356 392
 
357 393
 	// sections and count from the signature must match or the zip file is bad
358
-	if (count($file_sections) != $zip_info['files'])
359
-		return false;
394
+	if (count($file_sections) != $zip_info['files']) {
395
+			return false;
396
+	}
360 397
 
361 398
 	// go though each file in the archive
362 399
 	foreach ($file_sections as $data)
@@ -378,68 +415,79 @@  discard block
 block discarded – undo
378 415
 		}
379 416
 
380 417
 		// If this is a file, and it doesn't exist.... happy days!
381
-		if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename']))
382
-			$write_this = true;
418
+		if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) {
419
+					$write_this = true;
420
+		}
383 421
 		// If the file exists, we may not want to overwrite it.
384
-		elseif (substr($file_info['filename'], -1) != '/')
385
-			$write_this = $overwrite;
422
+		elseif (substr($file_info['filename'], -1) != '/') {
423
+					$write_this = $overwrite;
424
+		}
386 425
 		// This is a directory, so we're gonna want to create it. (probably...)
387 426
 		elseif ($destination !== null && !$single_file)
388 427
 		{
389 428
 			// Just a little accident prevention, don't mind me.
390 429
 			$file_info['filename'] = strtr($file_info['filename'], array('../' => '', '/..' => ''));
391 430
 
392
-			if (!file_exists($destination . '/' . $file_info['filename']))
393
-				mktree($destination . '/' . $file_info['filename'], 0777);
431
+			if (!file_exists($destination . '/' . $file_info['filename'])) {
432
+							mktree($destination . '/' . $file_info['filename'], 0777);
433
+			}
394 434
 			$write_this = false;
435
+		} else {
436
+					$write_this = false;
395 437
 		}
396
-		else
397
-			$write_this = false;
398 438
 
399 439
 		// Get the actual compressed data.
400 440
 		$file_info['data'] = substr($data, 26 + $file_info['filename_length'] + $file_info['extrafield_length']);
401 441
 
402 442
 		// Only inflate it if we need to ;)
403
-		if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size']))
404
-			$file_info['data'] = gzinflate($file_info['data']);
443
+		if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) {
444
+					$file_info['data'] = gzinflate($file_info['data']);
445
+		}
405 446
 
406 447
 		// Okay!  We can write this file, looks good from here...
407 448
 		if ($write_this && $destination !== null)
408 449
 		{
409
-			if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir'])))
410
-				mktree($file_info['dir'], 0777);
450
+			if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) {
451
+							mktree($file_info['dir'], 0777);
452
+			}
411 453
 
412 454
 			// If we're looking for a specific file, and this is it... ka-bam, baby.
413
-			if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename'])))
414
-				return $file_info['data'];
455
+			if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) {
456
+							return $file_info['data'];
457
+			}
415 458
 			// Oh?  Another file.  Fine.  You don't like this file, do you?  I know how it is.  Yeah... just go away.  No, don't apologize.  I know this file's just not *good enough* for you.
416
-			elseif ($single_file)
417
-				continue;
459
+			elseif ($single_file) {
460
+							continue;
461
+			}
418 462
 			// Don't really want this?
419
-			elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract))
420
-				continue;
463
+			elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) {
464
+							continue;
465
+			}
421 466
 
422 467
 			package_put_contents($destination . '/' . $file_info['filename'], $file_info['data']);
423 468
 		}
424 469
 
425
-		if (substr($file_info['filename'], -1, 1) != '/')
426
-			$return[] = array(
470
+		if (substr($file_info['filename'], -1, 1) != '/') {
471
+					$return[] = array(
427 472
 				'filename' => $file_info['filename'],
428 473
 				'md5' => md5($file_info['data']),
429 474
 				'preview' => substr($file_info['data'], 0, 100),
430 475
 				'size' => $file_info['size'],
431 476
 				'skipped' => false
432 477
 			);
478
+		}
433 479
 	}
434 480
 
435
-	if ($destination !== null && !$single_file)
436
-		package_flush_cache();
481
+	if ($destination !== null && !$single_file) {
482
+			package_flush_cache();
483
+	}
437 484
 
438
-	if ($single_file)
439
-		return false;
440
-	else
441
-		return $return;
442
-}
485
+	if ($single_file) {
486
+			return false;
487
+	} else {
488
+			return $return;
489
+	}
490
+	}
443 491
 
444 492
 /**
445 493
  * Checks the existence of a remote file since file_exists() does not do remote.
@@ -451,14 +499,16 @@  discard block
 block discarded – undo
451 499
 {
452 500
 	$a_url = parse_url($url);
453 501
 
454
-	if (!isset($a_url['scheme']))
455
-		return false;
502
+	if (!isset($a_url['scheme'])) {
503
+			return false;
504
+	}
456 505
 
457 506
 	// Attempt to connect...
458 507
 	$temp = '';
459 508
 	$fid = fsockopen($a_url['host'], !isset($a_url['port']) ? 80 : $a_url['port'], $temp, $temp, 8);
460
-	if (!$fid)
461
-		return false;
509
+	if (!$fid) {
510
+			return false;
511
+	}
462 512
 
463 513
 	fputs($fid, 'HEAD ' . $a_url['path'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . $a_url['host'] . "\r\n\r\n");
464 514
 	$head = fread($fid, 1024);
@@ -493,8 +543,9 @@  discard block
 block discarded – undo
493 543
 	while ($row = $smcFunc['db_fetch_assoc']($request))
494 544
 	{
495 545
 		// Already found this? If so don't add it twice!
496
-		if (in_array($row['package_id'], $found))
497
-			continue;
546
+		if (in_array($row['package_id'], $found)) {
547
+					continue;
548
+		}
498 549
 
499 550
 		$found[] = $row['package_id'];
500 551
 
@@ -529,19 +580,21 @@  discard block
 block discarded – undo
529 580
 	global $sourcedir, $packagesdir, $smcFunc;
530 581
 
531 582
 	// Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.)
532
-	if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false)
533
-		$packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true);
534
-	else
583
+	if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) {
584
+			$packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true);
585
+	} else
535 586
 	{
536
-		if (!file_exists($packagesdir . '/' . $gzfilename))
537
-			return 'package_get_error_not_found';
587
+		if (!file_exists($packagesdir . '/' . $gzfilename)) {
588
+					return 'package_get_error_not_found';
589
+		}
538 590
 
539
-		if (is_file($packagesdir . '/' . $gzfilename))
540
-			$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true);
541
-		elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml'))
542
-			$packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml');
543
-		else
544
-			return 'package_get_error_missing_xml';
591
+		if (is_file($packagesdir . '/' . $gzfilename)) {
592
+					$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true);
593
+		} elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) {
594
+					$packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml');
595
+		} else {
596
+					return 'package_get_error_missing_xml';
597
+		}
545 598
 	}
546 599
 
547 600
 	// Nothing?
@@ -549,10 +602,11 @@  discard block
 block discarded – undo
549 602
 	{
550 603
 		// Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function
551 604
 		$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/theme_info.xml', true);
552
-		if (!empty($packageInfo))
553
-			return 'package_get_error_is_theme';
554
-		else
555
-			return 'package_get_error_is_zero';
605
+		if (!empty($packageInfo)) {
606
+					return 'package_get_error_is_theme';
607
+		} else {
608
+					return 'package_get_error_is_zero';
609
+		}
556 610
 	}
557 611
 
558 612
 	// Parse package-info.xml into an xmlArray.
@@ -560,8 +614,9 @@  discard block
 block discarded – undo
560 614
 	$packageInfo = new xmlArray($packageInfo);
561 615
 
562 616
 	// @todo Error message of some sort?
563
-	if (!$packageInfo->exists('package-info[0]'))
564
-		return 'package_get_error_packageinfo_corrupt';
617
+	if (!$packageInfo->exists('package-info[0]')) {
618
+			return 'package_get_error_packageinfo_corrupt';
619
+	}
565 620
 
566 621
 	$packageInfo = $packageInfo->path('package-info[0]');
567 622
 
@@ -580,8 +635,9 @@  discard block
 block discarded – undo
580 635
 		}
581 636
 	}
582 637
 
583
-	if (!isset($package['type']))
584
-		$package['type'] = 'modification';
638
+	if (!isset($package['type'])) {
639
+			$package['type'] = 'modification';
640
+	}
585 641
 
586 642
 	return $package;
587 643
 }
@@ -634,15 +690,14 @@  discard block
 block discarded – undo
634 690
 					{
635 691
 						$ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => ''));
636 692
 						$package_ftp->chmod($ftp_file, $perms);
693
+					} else {
694
+											smf_chmod($file, $perms);
637 695
 					}
638
-					else
639
-						smf_chmod($file, $perms);
640 696
 
641 697
 					$new_permissions = @fileperms($file);
642 698
 					$result = $new_permissions == $perms ? 'success' : 'failure';
643 699
 					unset($_SESSION['pack_ftp']['original_perms'][$file]);
644
-				}
645
-				elseif ($do_change)
700
+				} elseif ($do_change)
646 701
 				{
647 702
 					$new_permissions = '';
648 703
 					$result = 'skipped';
@@ -758,8 +813,7 @@  discard block
 block discarded – undo
758 813
 
759 814
 			$context['sub_template'] = 'show_list';
760 815
 			$context['default_list'] = 'restore_file_permissions';
761
-		}
762
-		else
816
+		} else
763 817
 		{
764 818
 			unset($listOptions['columns']['result']);
765 819
 		}
@@ -769,12 +823,14 @@  discard block
 block discarded – undo
769 823
 		createList($listOptions);
770 824
 
771 825
 		// If we just restored permissions then whereever we are, we are now done and dusted.
772
-		if (!empty($_POST['restore_perms']))
773
-			obExit();
826
+		if (!empty($_POST['restore_perms'])) {
827
+					obExit();
828
+		}
774 829
 	}
775 830
 	// Otherwise, it's entirely irrelevant?
776
-	elseif ($restore_write_status)
777
-		return true;
831
+	elseif ($restore_write_status) {
832
+			return true;
833
+	}
778 834
 
779 835
 	// This is where we report what we got up to.
780 836
 	$return_data = array(
@@ -812,11 +868,12 @@  discard block
 block discarded – undo
812 868
 			if (!in_array($_POST['ftp_path'], array('', '/')))
813 869
 			{
814 870
 				$ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
815
-				if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/'))
816
-					$ftp_root = substr($ftp_root, 0, -1);
871
+				if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) {
872
+									$ftp_root = substr($ftp_root, 0, -1);
873
+				}
874
+			} else {
875
+							$ftp_root = $boarddir;
817 876
 			}
818
-			else
819
-				$ftp_root = $boarddir;
820 877
 
821 878
 			$_SESSION['pack_ftp'] = array(
822 879
 				'server' => $_POST['ftp_server'],
@@ -828,8 +885,9 @@  discard block
 block discarded – undo
828 885
 				'connected' => true,
829 886
 			);
830 887
 
831
-			if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path'])
832
-				updateSettings(array('package_path' => $_POST['ftp_path']));
888
+			if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
889
+							updateSettings(array('package_path' => $_POST['ftp_path']));
890
+			}
833 891
 
834 892
 			// This is now the primary connection.
835 893
 			$package_ftp = $ftp;
@@ -842,12 +900,13 @@  discard block
 block discarded – undo
842 900
 		foreach ($chmodFiles as $k => $file)
843 901
 		{
844 902
 			// Sometimes this can somehow happen maybe?
845
-			if (empty($file))
846
-				unset($chmodFiles[$k]);
903
+			if (empty($file)) {
904
+							unset($chmodFiles[$k]);
905
+			}
847 906
 			// Already writable?
848
-			elseif (@is_writable($file))
849
-				$return_data['files']['writable'][] = $file;
850
-			else
907
+			elseif (@is_writable($file)) {
908
+							$return_data['files']['writable'][] = $file;
909
+			} else
851 910
 			{
852 911
 				// Now try to change that.
853 912
 				$return_data['files'][package_chmod($file, 'writable', true) ? 'writable' : 'notwritable'][] = $file;
@@ -864,19 +923,21 @@  discard block
 block discarded – undo
864 923
 			{
865 924
 				require_once($sourcedir . '/Class-Package.php');
866 925
 				$ftp = new ftp_connection(null);
926
+			} elseif ($ftp->error !== false && !isset($ftp_error)) {
927
+							$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
867 928
 			}
868
-			elseif ($ftp->error !== false && !isset($ftp_error))
869
-				$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
870 929
 
871 930
 			list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
872 931
 
873
-			if ($found_path)
874
-				$_POST['ftp_path'] = $detect_path;
875
-			elseif (!isset($_POST['ftp_path']))
876
-				$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
932
+			if ($found_path) {
933
+							$_POST['ftp_path'] = $detect_path;
934
+			} elseif (!isset($_POST['ftp_path'])) {
935
+							$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
936
+			}
877 937
 
878
-			if (!isset($_POST['ftp_username']))
879
-				$_POST['ftp_username'] = $username;
938
+			if (!isset($_POST['ftp_username'])) {
939
+							$_POST['ftp_username'] = $username;
940
+			}
880 941
 		}
881 942
 
882 943
 		$context['package_ftp'] = array(
@@ -889,8 +950,9 @@  discard block
 block discarded – undo
889 950
 		);
890 951
 
891 952
 		// Which files failed?
892
-		if (!isset($context['notwritable_files']))
893
-			$context['notwritable_files'] = array();
953
+		if (!isset($context['notwritable_files'])) {
954
+					$context['notwritable_files'] = array();
955
+		}
894 956
 		$context['notwritable_files'] = array_merge($context['notwritable_files'], $return_data['files']['notwritable']);
895 957
 
896 958
 		// Sent here to die?
@@ -923,40 +985,48 @@  discard block
 block discarded – undo
923 985
 		foreach ($files as $k => $file)
924 986
 		{
925 987
 			// If this file doesn't exist, then we actually want to look at the directory, no?
926
-			if (!file_exists($file))
927
-				$file = dirname($file);
988
+			if (!file_exists($file)) {
989
+							$file = dirname($file);
990
+			}
928 991
 
929 992
 			// This looks odd, but it's an attempt to work around PHP suExec.
930
-			if (!@is_writable($file))
931
-				smf_chmod($file, 0755);
932
-			if (!@is_writable($file))
933
-				smf_chmod($file, 0777);
934
-			if (!@is_writable(dirname($file)))
935
-				smf_chmod($file, 0755);
936
-			if (!@is_writable(dirname($file)))
937
-				smf_chmod($file, 0777);
993
+			if (!@is_writable($file)) {
994
+							smf_chmod($file, 0755);
995
+			}
996
+			if (!@is_writable($file)) {
997
+							smf_chmod($file, 0777);
998
+			}
999
+			if (!@is_writable(dirname($file))) {
1000
+							smf_chmod($file, 0755);
1001
+			}
1002
+			if (!@is_writable(dirname($file))) {
1003
+							smf_chmod($file, 0777);
1004
+			}
938 1005
 
939 1006
 			$fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb');
940 1007
 			if (@is_writable($file) && $fp)
941 1008
 			{
942 1009
 				unset($files[$k]);
943
-				if (!is_dir($file))
944
-					fclose($fp);
945
-				else
946
-					closedir($fp);
1010
+				if (!is_dir($file)) {
1011
+									fclose($fp);
1012
+				} else {
1013
+									closedir($fp);
1014
+				}
947 1015
 			}
948 1016
 		}
949 1017
 
950 1018
 		// No FTP required!
951
-		if (empty($files))
952
-			return array();
1019
+		if (empty($files)) {
1020
+					return array();
1021
+		}
953 1022
 	}
954 1023
 
955 1024
 	// They've opted to not use FTP, and try anyway.
956 1025
 	if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false)
957 1026
 	{
958
-		if ($files === null)
959
-			return array();
1027
+		if ($files === null) {
1028
+					return array();
1029
+		}
960 1030
 
961 1031
 		foreach ($files as $k => $file)
962 1032
 		{
@@ -968,26 +1038,29 @@  discard block
 block discarded – undo
968 1038
 				smf_chmod($file, 0755);
969 1039
 			}
970 1040
 
971
-			if (!@is_writable($file))
972
-				smf_chmod($file, 0777);
973
-			if (!@is_writable(dirname($file)))
974
-				smf_chmod(dirname($file), 0777);
1041
+			if (!@is_writable($file)) {
1042
+							smf_chmod($file, 0777);
1043
+			}
1044
+			if (!@is_writable(dirname($file))) {
1045
+							smf_chmod(dirname($file), 0777);
1046
+			}
975 1047
 
976
-			if (@is_writable($file))
977
-				unset($files[$k]);
1048
+			if (@is_writable($file)) {
1049
+							unset($files[$k]);
1050
+			}
978 1051
 		}
979 1052
 
980 1053
 		return $files;
981
-	}
982
-	elseif (isset($_SESSION['pack_ftp']))
1054
+	} elseif (isset($_SESSION['pack_ftp']))
983 1055
 	{
984 1056
 		// Load the file containing the ftp_connection class.
985 1057
 		require_once($sourcedir . '/Class-Package.php');
986 1058
 
987 1059
 		$package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password']));
988 1060
 
989
-		if ($files === null)
990
-			return array();
1061
+		if ($files === null) {
1062
+					return array();
1063
+		}
991 1064
 
992 1065
 		foreach ($files as $k => $file)
993 1066
 		{
@@ -1001,13 +1074,16 @@  discard block
 block discarded – undo
1001 1074
 				$package_ftp->chmod($ftp_file, 0755);
1002 1075
 			}
1003 1076
 
1004
-			if (!@is_writable($file))
1005
-				$package_ftp->chmod($ftp_file, 0777);
1006
-			if (!@is_writable(dirname($file)))
1007
-				$package_ftp->chmod(dirname($ftp_file), 0777);
1077
+			if (!@is_writable($file)) {
1078
+							$package_ftp->chmod($ftp_file, 0777);
1079
+			}
1080
+			if (!@is_writable(dirname($file))) {
1081
+							$package_ftp->chmod(dirname($ftp_file), 0777);
1082
+			}
1008 1083
 
1009
-			if (@is_writable($file))
1010
-				unset($files[$k]);
1084
+			if (@is_writable($file)) {
1085
+							unset($files[$k]);
1086
+			}
1011 1087
 		}
1012 1088
 
1013 1089
 		return $files;
@@ -1019,8 +1095,7 @@  discard block
 block discarded – undo
1019 1095
 
1020 1096
 		$files = packageRequireFTP($destination_url, $files, $return);
1021 1097
 		return $files;
1022
-	}
1023
-	elseif (isset($_POST['ftp_username']))
1098
+	} elseif (isset($_POST['ftp_username']))
1024 1099
 	{
1025 1100
 		require_once($sourcedir . '/Class-Package.php');
1026 1101
 		$ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
@@ -1042,19 +1117,21 @@  discard block
 block discarded – undo
1042 1117
 		{
1043 1118
 			require_once($sourcedir . '/Class-Package.php');
1044 1119
 			$ftp = new ftp_connection(null);
1120
+		} elseif ($ftp->error !== false && !isset($ftp_error)) {
1121
+					$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
1045 1122
 		}
1046
-		elseif ($ftp->error !== false && !isset($ftp_error))
1047
-			$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
1048 1123
 
1049 1124
 		list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
1050 1125
 
1051
-		if ($found_path)
1052
-			$_POST['ftp_path'] = $detect_path;
1053
-		elseif (!isset($_POST['ftp_path']))
1054
-			$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
1126
+		if ($found_path) {
1127
+					$_POST['ftp_path'] = $detect_path;
1128
+		} elseif (!isset($_POST['ftp_path'])) {
1129
+					$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
1130
+		}
1055 1131
 
1056
-		if (!isset($_POST['ftp_username']))
1057
-			$_POST['ftp_username'] = $username;
1132
+		if (!isset($_POST['ftp_username'])) {
1133
+					$_POST['ftp_username'] = $username;
1134
+		}
1058 1135
 
1059 1136
 		$context['package_ftp'] = array(
1060 1137
 			'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'),
@@ -1066,23 +1143,24 @@  discard block
 block discarded – undo
1066 1143
 		);
1067 1144
 
1068 1145
 		// If we're returning dump out here.
1069
-		if ($return)
1070
-			return $files;
1146
+		if ($return) {
1147
+					return $files;
1148
+		}
1071 1149
 
1072 1150
 		$context['page_title'] = $txt['package_ftp_necessary'];
1073 1151
 		$context['sub_template'] = 'ftp_required';
1074 1152
 		obExit();
1075
-	}
1076
-	else
1153
+	} else
1077 1154
 	{
1078 1155
 		if (!in_array($_POST['ftp_path'], array('', '/')))
1079 1156
 		{
1080 1157
 			$ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
1081
-			if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/'))
1082
-				$ftp_root = substr($ftp_root, 0, -1);
1158
+			if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) {
1159
+							$ftp_root = substr($ftp_root, 0, -1);
1160
+			}
1161
+		} else {
1162
+					$ftp_root = $boarddir;
1083 1163
 		}
1084
-		else
1085
-			$ftp_root = $boarddir;
1086 1164
 
1087 1165
 		$_SESSION['pack_ftp'] = array(
1088 1166
 			'server' => $_POST['ftp_server'],
@@ -1093,8 +1171,9 @@  discard block
 block discarded – undo
1093 1171
 			'root' => $ftp_root,
1094 1172
 		);
1095 1173
 
1096
-		if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path'])
1097
-			updateSettings(array('package_path' => $_POST['ftp_path']));
1174
+		if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
1175
+					updateSettings(array('package_path' => $_POST['ftp_path']));
1176
+		}
1098 1177
 
1099 1178
 		$files = packageRequireFTP($destination_url, $files, $return);
1100 1179
 	}
@@ -1122,16 +1201,18 @@  discard block
 block discarded – undo
1122 1201
 	global $packagesdir, $forum_version, $context, $temp_path, $language, $smcFunc;
1123 1202
 
1124 1203
 	// Mayday!  That action doesn't exist!!
1125
-	if (empty($packageXML) || !$packageXML->exists($method))
1126
-		return array();
1204
+	if (empty($packageXML) || !$packageXML->exists($method)) {
1205
+			return array();
1206
+	}
1127 1207
 
1128 1208
 	// We haven't found the package script yet...
1129 1209
 	$script = false;
1130 1210
 	$the_version = strtr($forum_version, array('SMF ' => ''));
1131 1211
 
1132 1212
 	// Emulation support...
1133
-	if (!empty($_SESSION['version_emulate']))
1134
-		$the_version = $_SESSION['version_emulate'];
1213
+	if (!empty($_SESSION['version_emulate'])) {
1214
+			$the_version = $_SESSION['version_emulate'];
1215
+	}
1135 1216
 
1136 1217
 	// Single package emulation
1137 1218
 	if (!empty($_REQUEST['ve']) && !empty($_REQUEST['package']))
@@ -1139,8 +1220,9 @@  discard block
 block discarded – undo
1139 1220
 		$the_version = $_REQUEST['ve'];
1140 1221
 		$_SESSION['single_version_emulate'][$_REQUEST['package']] = $the_version;
1141 1222
 	}
1142
-	if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']])))
1143
-		$the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']];
1223
+	if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) {
1224
+			$the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']];
1225
+	}
1144 1226
 
1145 1227
 	// Get all the versions of this method and find the right one.
1146 1228
 	$these_methods = $packageXML->set($method);
@@ -1150,16 +1232,18 @@  discard block
 block discarded – undo
1150 1232
 		if ($this_method->exists('@for'))
1151 1233
 		{
1152 1234
 			// Don't keep going if this won't work for this version of SMF.
1153
-			if (!matchPackageVersion($the_version, $this_method->fetch('@for')))
1154
-				continue;
1235
+			if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) {
1236
+							continue;
1237
+			}
1155 1238
 		}
1156 1239
 
1157 1240
 		// Upgrades may go from a certain old version of the mod.
1158 1241
 		if ($method == 'upgrade' && $this_method->exists('@from'))
1159 1242
 		{
1160 1243
 			// Well, this is for the wrong old version...
1161
-			if (!matchPackageVersion($previous_version, $this_method->fetch('@from')))
1162
-				continue;
1244
+			if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) {
1245
+							continue;
1246
+			}
1163 1247
 		}
1164 1248
 
1165 1249
 		// We've found it!
@@ -1168,8 +1252,9 @@  discard block
 block discarded – undo
1168 1252
 	}
1169 1253
 
1170 1254
 	// Bad news, a matching script wasn't found!
1171
-	if ($script === false)
1172
-		return array();
1255
+	if ($script === false) {
1256
+			return array();
1257
+	}
1173 1258
 
1174 1259
 	// Find all the actions in this method - in theory, these should only be allowed actions. (* means all.)
1175 1260
 	$actions = $script->set('*');
@@ -1198,12 +1283,12 @@  discard block
 block discarded – undo
1198 1283
 					if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language)	|| (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language))
1199 1284
 					{
1200 1285
 						// In case the user put the blocks in the wrong order.
1201
-						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default')
1202
-							$context[$type][] = 'default';
1286
+						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') {
1287
+													$context[$type][] = 'default';
1288
+						}
1203 1289
 
1204 1290
 						$context[$type]['selected'] = $smcFunc['htmlspecialchars']($action->fetch('@lang'));
1205
-					}
1206
-					else
1291
+					} else
1207 1292
 					{
1208 1293
 						// We don't want this now, but we'll allow the user to select to read it.
1209 1294
 						$context[$type][] = $smcFunc['htmlspecialchars']($action->fetch('@lang'));
@@ -1218,9 +1303,9 @@  discard block
 block discarded – undo
1218 1303
 					{
1219 1304
 						$context[$type][] = 'default';
1220 1305
 						continue;
1306
+					} else {
1307
+											$context[$type]['selected'] = 'default';
1221 1308
 					}
1222
-					else
1223
-						$context[$type]['selected'] = 'default';
1224 1309
 				}
1225 1310
 			}
1226 1311
 
@@ -1230,9 +1315,9 @@  discard block
 block discarded – undo
1230 1315
 				$filename = $temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, array('readme', 'redirect', 'license')) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod'));
1231 1316
 				package_put_contents($filename, $action->fetch('.'));
1232 1317
 				$filename = strtr($filename, array($temp_path => ''));
1318
+			} else {
1319
+							$filename = $action->fetch('.');
1233 1320
 			}
1234
-			else
1235
-				$filename = $action->fetch('.');
1236 1321
 
1237 1322
 			$return[] = array(
1238 1323
 				'type' => $actionType,
@@ -1247,8 +1332,7 @@  discard block
 block discarded – undo
1247 1332
 			);
1248 1333
 
1249 1334
 			continue;
1250
-		}
1251
-		elseif ($actionType == 'hook')
1335
+		} elseif ($actionType == 'hook')
1252 1336
 		{
1253 1337
 			$return[] = array(
1254 1338
 				'type' => $actionType,
@@ -1260,16 +1344,16 @@  discard block
 block discarded – undo
1260 1344
 				'description' => '',
1261 1345
 			);
1262 1346
 			continue;
1263
-		}
1264
-		elseif ($actionType == 'credits')
1347
+		} elseif ($actionType == 'credits')
1265 1348
 		{
1266 1349
 			// quick check of any supplied url
1267 1350
 			$url = $action->exists('@url') ? $action->fetch('@url') : '';
1268 1351
 			if (strlen(trim($url)) > 0 && substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')
1269 1352
 			{
1270 1353
 				$url = 'http://' . $url;
1271
-				if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://'))
1272
-					$url = '';
1354
+				if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) {
1355
+									$url = '';
1356
+				}
1273 1357
 			}
1274 1358
 
1275 1359
 			$return[] = array(
@@ -1281,8 +1365,7 @@  discard block
 block discarded – undo
1281 1365
 				'title' => $action->fetch('.'),
1282 1366
 			);
1283 1367
 			continue;
1284
-		}
1285
-		elseif ($actionType == 'requires')
1368
+		} elseif ($actionType == 'requires')
1286 1369
 		{
1287 1370
 			$return[] = array(
1288 1371
 				'type' => $actionType,
@@ -1291,14 +1374,12 @@  discard block
 block discarded – undo
1291 1374
 				'description' => '',
1292 1375
 			);
1293 1376
 			continue;
1294
-		}
1295
-		elseif ($actionType == 'error')
1377
+		} elseif ($actionType == 'error')
1296 1378
 		{
1297 1379
 			$return[] = array(
1298 1380
 				'type' => 'error',
1299 1381
 			);
1300
-		}
1301
-		elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir')))
1382
+		} elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir')))
1302 1383
 		{
1303 1384
 			$this_action = &$return[];
1304 1385
 			$this_action = array(
@@ -1312,8 +1393,7 @@  discard block
 block discarded – undo
1312 1393
 			{
1313 1394
 				$this_action['unparsed_destination'] = $action->fetch('@destination');
1314 1395
 				$this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']);
1315
-			}
1316
-			else
1396
+			} else
1317 1397
 			{
1318 1398
 				$this_action['unparsed_filename'] = $this_action['filename'];
1319 1399
 				$this_action['filename'] = parse_path($this_action['filename']);
@@ -1322,10 +1402,11 @@  discard block
 block discarded – undo
1322 1402
 			// If we're moving or requiring (copying) a file.
1323 1403
 			if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require')
1324 1404
 			{
1325
-				if ($action->exists('@from'))
1326
-					$this_action['source'] = parse_path($action->fetch('@from'));
1327
-				else
1328
-					$this_action['source'] = $temp_path . $this_action['filename'];
1405
+				if ($action->exists('@from')) {
1406
+									$this_action['source'] = parse_path($action->fetch('@from'));
1407
+				} else {
1408
+									$this_action['source'] = $temp_path . $this_action['filename'];
1409
+				}
1329 1410
 			}
1330 1411
 
1331 1412
 			// Check if these things can be done. (chmod's etc.)
@@ -1334,22 +1415,23 @@  discard block
 block discarded – undo
1334 1415
 				if (!mktree($this_action['destination'], false))
1335 1416
 				{
1336 1417
 					$temp = $this_action['destination'];
1337
-					while (!file_exists($temp) && strlen($temp) > 1)
1338
-						$temp = dirname($temp);
1418
+					while (!file_exists($temp) && strlen($temp) > 1) {
1419
+											$temp = dirname($temp);
1420
+					}
1339 1421
 
1340 1422
 					$return[] = array(
1341 1423
 						'type' => 'chmod',
1342 1424
 						'filename' => $temp
1343 1425
 					);
1344 1426
 				}
1345
-			}
1346
-			elseif ($actionType == 'create-file')
1427
+			} elseif ($actionType == 'create-file')
1347 1428
 			{
1348 1429
 				if (!mktree(dirname($this_action['destination']), false))
1349 1430
 				{
1350 1431
 					$temp = dirname($this_action['destination']);
1351
-					while (!file_exists($temp) && strlen($temp) > 1)
1352
-						$temp = dirname($temp);
1432
+					while (!file_exists($temp) && strlen($temp) > 1) {
1433
+											$temp = dirname($temp);
1434
+					}
1353 1435
 
1354 1436
 					$return[] = array(
1355 1437
 						'type' => 'chmod',
@@ -1357,36 +1439,38 @@  discard block
 block discarded – undo
1357 1439
 					);
1358 1440
 				}
1359 1441
 
1360
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1361
-					$return[] = array(
1442
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1443
+									$return[] = array(
1362 1444
 						'type' => 'chmod',
1363 1445
 						'filename' => $this_action['destination']
1364 1446
 					);
1365
-			}
1366
-			elseif ($actionType == 'require-dir')
1447
+				}
1448
+			} elseif ($actionType == 'require-dir')
1367 1449
 			{
1368 1450
 				if (!mktree($this_action['destination'], false))
1369 1451
 				{
1370 1452
 					$temp = $this_action['destination'];
1371
-					while (!file_exists($temp) && strlen($temp) > 1)
1372
-						$temp = dirname($temp);
1453
+					while (!file_exists($temp) && strlen($temp) > 1) {
1454
+											$temp = dirname($temp);
1455
+					}
1373 1456
 
1374 1457
 					$return[] = array(
1375 1458
 						'type' => 'chmod',
1376 1459
 						'filename' => $temp
1377 1460
 					);
1378 1461
 				}
1379
-			}
1380
-			elseif ($actionType == 'require-file')
1462
+			} elseif ($actionType == 'require-file')
1381 1463
 			{
1382
-				if ($action->exists('@theme'))
1383
-					$this_action['theme_action'] = $action->fetch('@theme');
1464
+				if ($action->exists('@theme')) {
1465
+									$this_action['theme_action'] = $action->fetch('@theme');
1466
+				}
1384 1467
 
1385 1468
 				if (!mktree(dirname($this_action['destination']), false))
1386 1469
 				{
1387 1470
 					$temp = dirname($this_action['destination']);
1388
-					while (!file_exists($temp) && strlen($temp) > 1)
1389
-						$temp = dirname($temp);
1471
+					while (!file_exists($temp) && strlen($temp) > 1) {
1472
+											$temp = dirname($temp);
1473
+					}
1390 1474
 
1391 1475
 					$return[] = array(
1392 1476
 						'type' => 'chmod',
@@ -1394,19 +1478,20 @@  discard block
 block discarded – undo
1394 1478
 					);
1395 1479
 				}
1396 1480
 
1397
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1398
-					$return[] = array(
1481
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1482
+									$return[] = array(
1399 1483
 						'type' => 'chmod',
1400 1484
 						'filename' => $this_action['destination']
1401 1485
 					);
1402
-			}
1403
-			elseif ($actionType == 'move-dir' || $actionType == 'move-file')
1486
+				}
1487
+			} elseif ($actionType == 'move-dir' || $actionType == 'move-file')
1404 1488
 			{
1405 1489
 				if (!mktree(dirname($this_action['destination']), false))
1406 1490
 				{
1407 1491
 					$temp = dirname($this_action['destination']);
1408
-					while (!file_exists($temp) && strlen($temp) > 1)
1409
-						$temp = dirname($temp);
1492
+					while (!file_exists($temp) && strlen($temp) > 1) {
1493
+											$temp = dirname($temp);
1494
+					}
1410 1495
 
1411 1496
 					$return[] = array(
1412 1497
 						'type' => 'chmod',
@@ -1414,30 +1499,30 @@  discard block
 block discarded – undo
1414 1499
 					);
1415 1500
 				}
1416 1501
 
1417
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1418
-					$return[] = array(
1502
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1503
+									$return[] = array(
1419 1504
 						'type' => 'chmod',
1420 1505
 						'filename' => $this_action['destination']
1421 1506
 					);
1422
-			}
1423
-			elseif ($actionType == 'remove-dir')
1507
+				}
1508
+			} elseif ($actionType == 'remove-dir')
1424 1509
 			{
1425
-				if (!is_writable($this_action['filename']) && file_exists($this_action['filename']))
1426
-					$return[] = array(
1510
+				if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) {
1511
+									$return[] = array(
1427 1512
 						'type' => 'chmod',
1428 1513
 						'filename' => $this_action['filename']
1429 1514
 					);
1430
-			}
1431
-			elseif ($actionType == 'remove-file')
1515
+				}
1516
+			} elseif ($actionType == 'remove-file')
1432 1517
 			{
1433
-				if (!is_writable($this_action['filename']) && file_exists($this_action['filename']))
1434
-					$return[] = array(
1518
+				if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) {
1519
+									$return[] = array(
1435 1520
 						'type' => 'chmod',
1436 1521
 						'filename' => $this_action['filename']
1437 1522
 					);
1523
+				}
1438 1524
 			}
1439
-		}
1440
-		else
1525
+		} else
1441 1526
 		{
1442 1527
 			$return[] = array(
1443 1528
 				'type' => 'error',
@@ -1448,8 +1533,9 @@  discard block
 block discarded – undo
1448 1533
 	}
1449 1534
 
1450 1535
 	// Only testing - just return a list of things to be done.
1451
-	if ($testing_only)
1452
-		return $return;
1536
+	if ($testing_only) {
1537
+			return $return;
1538
+	}
1453 1539
 
1454 1540
 	umask(0);
1455 1541
 
@@ -1457,78 +1543,81 @@  discard block
 block discarded – undo
1457 1543
 	$not_done = array(array('type' => '!'));
1458 1544
 	foreach ($return as $action)
1459 1545
 	{
1460
-		if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits')))
1461
-			$not_done[] = $action;
1546
+		if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) {
1547
+					$not_done[] = $action;
1548
+		}
1462 1549
 
1463 1550
 		if ($action['type'] == 'create-dir')
1464 1551
 		{
1465
-			if (!mktree($action['destination'], 0755) || !is_writable($action['destination']))
1466
-				$failure |= !mktree($action['destination'], 0777);
1467
-		}
1468
-		elseif ($action['type'] == 'create-file')
1552
+			if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) {
1553
+							$failure |= !mktree($action['destination'], 0777);
1554
+			}
1555
+		} elseif ($action['type'] == 'create-file')
1469 1556
 		{
1470
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1471
-				$failure |= !mktree(dirname($action['destination']), 0777);
1557
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1558
+							$failure |= !mktree(dirname($action['destination']), 0777);
1559
+			}
1472 1560
 
1473 1561
 			// Create an empty file.
1474 1562
 			package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only);
1475 1563
 
1476
-			if (!file_exists($action['destination']))
1477
-				$failure = true;
1478
-		}
1479
-		elseif ($action['type'] == 'require-dir')
1564
+			if (!file_exists($action['destination'])) {
1565
+							$failure = true;
1566
+			}
1567
+		} elseif ($action['type'] == 'require-dir')
1480 1568
 		{
1481 1569
 			copytree($action['source'], $action['destination']);
1482 1570
 			// Any other theme folders?
1483
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']]))
1484
-				foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1571
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) {
1572
+							foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1485 1573
 					copytree($action['source'], $theme_destination);
1486
-		}
1487
-		elseif ($action['type'] == 'require-file')
1574
+			}
1575
+		} elseif ($action['type'] == 'require-file')
1488 1576
 		{
1489
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1490
-				$failure |= !mktree(dirname($action['destination']), 0777);
1577
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1578
+							$failure |= !mktree(dirname($action['destination']), 0777);
1579
+			}
1491 1580
 
1492 1581
 			package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only);
1493 1582
 
1494 1583
 			$failure |= !copy($action['source'], $action['destination']);
1495 1584
 
1496 1585
 			// Any other theme files?
1497
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']]))
1498
-				foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1586
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) {
1587
+							foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1499 1588
 				{
1500 1589
 					if (!mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination)))
1501 1590
 						$failure |= !mktree(dirname($theme_destination), 0777);
1591
+			}
1502 1592
 
1503 1593
 					package_put_contents($theme_destination, package_get_contents($action['source']), $testing_only);
1504 1594
 
1505 1595
 					$failure |= !copy($action['source'], $theme_destination);
1506 1596
 				}
1507
-		}
1508
-		elseif ($action['type'] == 'move-file')
1597
+		} elseif ($action['type'] == 'move-file')
1509 1598
 		{
1510
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1511
-				$failure |= !mktree(dirname($action['destination']), 0777);
1599
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1600
+							$failure |= !mktree(dirname($action['destination']), 0777);
1601
+			}
1512 1602
 
1513 1603
 			$failure |= !rename($action['source'], $action['destination']);
1514
-		}
1515
-		elseif ($action['type'] == 'move-dir')
1604
+		} elseif ($action['type'] == 'move-dir')
1516 1605
 		{
1517
-			if (!mktree($action['destination'], 0755) || !is_writable($action['destination']))
1518
-				$failure |= !mktree($action['destination'], 0777);
1606
+			if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) {
1607
+							$failure |= !mktree($action['destination'], 0777);
1608
+			}
1519 1609
 
1520 1610
 			$failure |= !rename($action['source'], $action['destination']);
1521
-		}
1522
-		elseif ($action['type'] == 'remove-dir')
1611
+		} elseif ($action['type'] == 'remove-dir')
1523 1612
 		{
1524 1613
 			deltree($action['filename']);
1525 1614
 
1526 1615
 			// Any other theme folders?
1527
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']]))
1528
-				foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1616
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) {
1617
+							foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1529 1618
 					deltree($theme_destination);
1530
-		}
1531
-		elseif ($action['type'] == 'remove-file')
1619
+			}
1620
+		} elseif ($action['type'] == 'remove-file')
1532 1621
 		{
1533 1622
 			// Make sure the file exists before deleting it.
1534 1623
 			if (file_exists($action['filename']))
@@ -1537,16 +1626,18 @@  discard block
 block discarded – undo
1537 1626
 				$failure |= !unlink($action['filename']);
1538 1627
 			}
1539 1628
 			// The file that was supposed to be deleted couldn't be found.
1540
-			else
1541
-				$failure = true;
1629
+			else {
1630
+							$failure = true;
1631
+			}
1542 1632
 
1543 1633
 			// Any other theme folders?
1544
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']]))
1545
-				foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1634
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) {
1635
+							foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1546 1636
 					if (file_exists($theme_destination))
1547 1637
 						$failure |= !unlink($theme_destination);
1548
-					else
1549
-						$failure = true;
1638
+			} else {
1639
+											$failure = true;
1640
+					}
1550 1641
 		}
1551 1642
 	}
1552 1643
 
@@ -1568,8 +1659,9 @@  discard block
 block discarded – undo
1568 1659
 {
1569 1660
 	static $near_version = 0;
1570 1661
 
1571
-	if ($reset)
1572
-		$near_version = 0;
1662
+	if ($reset) {
1663
+			$near_version = 0;
1664
+	}
1573 1665
 
1574 1666
 	// Normalize the $versions while we remove our previous Doh!
1575 1667
 	$versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions)));
@@ -1578,16 +1670,19 @@  discard block
 block discarded – undo
1578 1670
 	foreach ($versions as $for)
1579 1671
 	{
1580 1672
 		// Adjust for those wild cards
1581
-		if (strpos($for, '*') !== false)
1582
-			$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1673
+		if (strpos($for, '*') !== false) {
1674
+					$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1675
+		}
1583 1676
 
1584 1677
 		// If we have a range, grab the lower value, done this way so it looks normal-er to the user e.g. 2.0 vs 2.0.99
1585
-		if (strpos($for, '-') !== false)
1586
-			list ($for, $higher) = explode('-', $for);
1678
+		if (strpos($for, '-') !== false) {
1679
+					list ($for, $higher) = explode('-', $for);
1680
+		}
1587 1681
 
1588 1682
 		// Do the compare, if the for is greater, than what we have but not greater than what we are running .....
1589
-		if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1)
1590
-			$near_version = $for;
1683
+		if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) {
1684
+					$near_version = $for;
1685
+		}
1591 1686
 	}
1592 1687
 
1593 1688
 	return !empty($near_version) ? $near_version : false;
@@ -1610,15 +1705,17 @@  discard block
 block discarded – undo
1610 1705
 	$versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions)));
1611 1706
 
1612 1707
 	// Perhaps we do accept anything?
1613
-	if (in_array('all', $versions))
1614
-		return true;
1708
+	if (in_array('all', $versions)) {
1709
+			return true;
1710
+	}
1615 1711
 
1616 1712
 	// Loop through each version.
1617 1713
 	foreach ($versions as $for)
1618 1714
 	{
1619 1715
 		// Wild card spotted?
1620
-		if (strpos($for, '*') !== false)
1621
-			$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1716
+		if (strpos($for, '*') !== false) {
1717
+					$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1718
+		}
1622 1719
 
1623 1720
 		// Do we have a range?
1624 1721
 		if (strpos($for, '-') !== false)
@@ -1626,12 +1723,14 @@  discard block
 block discarded – undo
1626 1723
 			list ($lower, $upper) = explode('-', $for);
1627 1724
 
1628 1725
 			// Compare the version against lower and upper bounds.
1629
-			if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1)
1630
-				return true;
1726
+			if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) {
1727
+							return true;
1728
+			}
1631 1729
 		}
1632 1730
 		// Otherwise check if they are equal...
1633
-		elseif (compareVersions($version, $for) === 0)
1634
-			return true;
1731
+		elseif (compareVersions($version, $for) === 0) {
1732
+					return true;
1733
+		}
1635 1734
 	}
1636 1735
 
1637 1736
 	return false;
@@ -1671,12 +1770,14 @@  discard block
 block discarded – undo
1671 1770
 	}
1672 1771
 
1673 1772
 	// Are they the same, perhaps?
1674
-	if ($versions[1] === $versions[2])
1675
-		return 0;
1773
+	if ($versions[1] === $versions[2]) {
1774
+			return 0;
1775
+	}
1676 1776
 
1677 1777
 	// Get version numbering categories...
1678
-	if (!isset($categories))
1679
-		$categories = array_keys($versions[1]);
1778
+	if (!isset($categories)) {
1779
+			$categories = array_keys($versions[1]);
1780
+	}
1680 1781
 
1681 1782
 	// Loop through each category.
1682 1783
 	foreach ($categories as $category)
@@ -1686,13 +1787,15 @@  discard block
 block discarded – undo
1686 1787
 		{
1687 1788
 			// Dev builds are a problematic exception.
1688 1789
 			// (stable) dev < (stable) but (unstable) dev = (unstable)
1689
-			if ($category == 'type')
1690
-				return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1);
1691
-			elseif ($category == 'dev')
1692
-				return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0);
1790
+			if ($category == 'type') {
1791
+							return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1);
1792
+			} elseif ($category == 'dev') {
1793
+							return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0);
1794
+			}
1693 1795
 			// Otherwise a simple comparison.
1694
-			else
1695
-				return $versions[1][$category] > $versions[2][$category] ? 1 : -1;
1796
+			else {
1797
+							return $versions[1][$category] > $versions[2][$category] ? 1 : -1;
1798
+			}
1696 1799
 		}
1697 1800
 	}
1698 1801
 
@@ -1726,11 +1829,13 @@  discard block
 block discarded – undo
1726 1829
 	);
1727 1830
 
1728 1831
 	// do we parse in a package directory?
1729
-	if (!empty($temp_path))
1730
-		$dirs['$package'] = $temp_path;
1832
+	if (!empty($temp_path)) {
1833
+			$dirs['$package'] = $temp_path;
1834
+	}
1731 1835
 
1732
-	if (strlen($path) == 0)
1733
-		trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR);
1836
+	if (strlen($path) == 0) {
1837
+			trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR);
1838
+	}
1734 1839
 
1735 1840
 	return strtr($path, $dirs);
1736 1841
 }
@@ -1746,8 +1851,9 @@  discard block
 block discarded – undo
1746 1851
 {
1747 1852
 	global $package_ftp;
1748 1853
 
1749
-	if (!file_exists($dir))
1750
-		return;
1854
+	if (!file_exists($dir)) {
1855
+			return;
1856
+	}
1751 1857
 
1752 1858
 	$current_dir = @opendir($dir);
1753 1859
 	if ($current_dir == false)
@@ -1755,8 +1861,9 @@  discard block
 block discarded – undo
1755 1861
 		if ($delete_dir && isset($package_ftp))
1756 1862
 		{
1757 1863
 			$ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
1758
-			if (!is_dir($dir))
1759
-				$package_ftp->chmod($ftp_file, 0777);
1864
+			if (!is_dir($dir)) {
1865
+							$package_ftp->chmod($ftp_file, 0777);
1866
+			}
1760 1867
 			$package_ftp->unlink($ftp_file);
1761 1868
 		}
1762 1869
 
@@ -1765,26 +1872,28 @@  discard block
 block discarded – undo
1765 1872
 
1766 1873
 	while ($entryname = readdir($current_dir))
1767 1874
 	{
1768
-		if (in_array($entryname, array('.', '..')))
1769
-			continue;
1875
+		if (in_array($entryname, array('.', '..'))) {
1876
+					continue;
1877
+		}
1770 1878
 
1771
-		if (is_dir($dir . '/' . $entryname))
1772
-			deltree($dir . '/' . $entryname);
1773
-		else
1879
+		if (is_dir($dir . '/' . $entryname)) {
1880
+					deltree($dir . '/' . $entryname);
1881
+		} else
1774 1882
 		{
1775 1883
 			// Here, 755 doesn't really matter since we're deleting it anyway.
1776 1884
 			if (isset($package_ftp))
1777 1885
 			{
1778 1886
 				$ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
1779 1887
 
1780
-				if (!is_writable($dir . '/' . $entryname))
1781
-					$package_ftp->chmod($ftp_file, 0777);
1888
+				if (!is_writable($dir . '/' . $entryname)) {
1889
+									$package_ftp->chmod($ftp_file, 0777);
1890
+				}
1782 1891
 				$package_ftp->unlink($ftp_file);
1783
-			}
1784
-			else
1892
+			} else
1785 1893
 			{
1786
-				if (!is_writable($dir . '/' . $entryname))
1787
-					smf_chmod($dir . '/' . $entryname, 0777);
1894
+				if (!is_writable($dir . '/' . $entryname)) {
1895
+									smf_chmod($dir . '/' . $entryname, 0777);
1896
+				}
1788 1897
 				unlink($dir . '/' . $entryname);
1789 1898
 			}
1790 1899
 		}
@@ -1797,14 +1906,15 @@  discard block
 block discarded – undo
1797 1906
 		if (isset($package_ftp))
1798 1907
 		{
1799 1908
 			$ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
1800
-			if (!is_writable($dir . '/' . $entryname))
1801
-				$package_ftp->chmod($ftp_file, 0777);
1909
+			if (!is_writable($dir . '/' . $entryname)) {
1910
+							$package_ftp->chmod($ftp_file, 0777);
1911
+			}
1802 1912
 			$package_ftp->unlink($ftp_file);
1803
-		}
1804
-		else
1913
+		} else
1805 1914
 		{
1806
-			if (!is_writable($dir))
1807
-				smf_chmod($dir, 0777);
1915
+			if (!is_writable($dir)) {
1916
+							smf_chmod($dir, 0777);
1917
+			}
1808 1918
 			@rmdir($dir);
1809 1919
 		}
1810 1920
 	}
@@ -1826,10 +1936,11 @@  discard block
 block discarded – undo
1826 1936
 	{
1827 1937
 		if (!is_writable($strPath) && $mode !== false)
1828 1938
 		{
1829
-			if (isset($package_ftp))
1830
-				$package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode);
1831
-			else
1832
-				smf_chmod($strPath, $mode);
1939
+			if (isset($package_ftp)) {
1940
+							$package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode);
1941
+			} else {
1942
+							smf_chmod($strPath, $mode);
1943
+			}
1833 1944
 		}
1834 1945
 
1835 1946
 		$test = @opendir($strPath);
@@ -1837,36 +1948,37 @@  discard block
 block discarded – undo
1837 1948
 		{
1838 1949
 			closedir($test);
1839 1950
 			return is_writable($strPath);
1951
+		} else {
1952
+					return false;
1840 1953
 		}
1841
-		else
1842
-			return false;
1843 1954
 	}
1844 1955
 	// Is this an invalid path and/or we can't make the directory?
1845
-	if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode))
1846
-		return false;
1956
+	if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) {
1957
+			return false;
1958
+	}
1847 1959
 
1848 1960
 	if (!is_writable(dirname($strPath)) && $mode !== false)
1849 1961
 	{
1850
-		if (isset($package_ftp))
1851
-			$package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode);
1852
-		else
1853
-			smf_chmod(dirname($strPath), $mode);
1962
+		if (isset($package_ftp)) {
1963
+					$package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode);
1964
+		} else {
1965
+					smf_chmod(dirname($strPath), $mode);
1966
+		}
1854 1967
 	}
1855 1968
 
1856
-	if ($mode !== false && isset($package_ftp))
1857
-		return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')));
1858
-	elseif ($mode === false)
1969
+	if ($mode !== false && isset($package_ftp)) {
1970
+			return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')));
1971
+	} elseif ($mode === false)
1859 1972
 	{
1860 1973
 		$test = @opendir(dirname($strPath));
1861 1974
 		if ($test)
1862 1975
 		{
1863 1976
 			closedir($test);
1864 1977
 			return true;
1978
+		} else {
1979
+					return false;
1865 1980
 		}
1866
-		else
1867
-			return false;
1868
-	}
1869
-	else
1981
+	} else
1870 1982
 	{
1871 1983
 		@mkdir($strPath, $mode);
1872 1984
 		$test = @opendir($strPath);
@@ -1874,9 +1986,9 @@  discard block
 block discarded – undo
1874 1986
 		{
1875 1987
 			closedir($test);
1876 1988
 			return true;
1989
+		} else {
1990
+					return false;
1877 1991
 		}
1878
-		else
1879
-			return false;
1880 1992
 	}
1881 1993
 }
1882 1994
 
@@ -1891,39 +2003,46 @@  discard block
 block discarded – undo
1891 2003
 {
1892 2004
 	global $package_ftp;
1893 2005
 
1894
-	if (!file_exists($destination) || !is_writable($destination))
1895
-		mktree($destination, 0755);
1896
-	if (!is_writable($destination))
1897
-		mktree($destination, 0777);
2006
+	if (!file_exists($destination) || !is_writable($destination)) {
2007
+			mktree($destination, 0755);
2008
+	}
2009
+	if (!is_writable($destination)) {
2010
+			mktree($destination, 0777);
2011
+	}
1898 2012
 
1899 2013
 	$current_dir = opendir($source);
1900
-	if ($current_dir == false)
1901
-		return;
2014
+	if ($current_dir == false) {
2015
+			return;
2016
+	}
1902 2017
 
1903 2018
 	while ($entryname = readdir($current_dir))
1904 2019
 	{
1905
-		if (in_array($entryname, array('.', '..')))
1906
-			continue;
2020
+		if (in_array($entryname, array('.', '..'))) {
2021
+					continue;
2022
+		}
1907 2023
 
1908
-		if (isset($package_ftp))
1909
-			$ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
2024
+		if (isset($package_ftp)) {
2025
+					$ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
2026
+		}
1910 2027
 
1911 2028
 		if (is_file($source . '/' . $entryname))
1912 2029
 		{
1913
-			if (isset($package_ftp) && !file_exists($destination . '/' . $entryname))
1914
-				$package_ftp->create_file($ftp_file);
1915
-			elseif (!file_exists($destination . '/' . $entryname))
1916
-				@touch($destination . '/' . $entryname);
2030
+			if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) {
2031
+							$package_ftp->create_file($ftp_file);
2032
+			} elseif (!file_exists($destination . '/' . $entryname)) {
2033
+							@touch($destination . '/' . $entryname);
2034
+			}
1917 2035
 		}
1918 2036
 
1919 2037
 		package_chmod($destination . '/' . $entryname);
1920 2038
 
1921
-		if (is_dir($source . '/' . $entryname))
1922
-			copytree($source . '/' . $entryname, $destination . '/' . $entryname);
1923
-		elseif (file_exists($destination . '/' . $entryname))
1924
-			package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname));
1925
-		else
1926
-			copy($source . '/' . $entryname, $destination . '/' . $entryname);
2039
+		if (is_dir($source . '/' . $entryname)) {
2040
+					copytree($source . '/' . $entryname, $destination . '/' . $entryname);
2041
+		} elseif (file_exists($destination . '/' . $entryname)) {
2042
+					package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname));
2043
+		} else {
2044
+					copy($source . '/' . $entryname, $destination . '/' . $entryname);
2045
+		}
1927 2046
 	}
1928 2047
 
1929 2048
 	closedir($current_dir);
@@ -1941,21 +2060,24 @@  discard block
 block discarded – undo
1941 2060
 	$data = array();
1942 2061
 
1943 2062
 	$dir = @dir($path . $sub_path);
1944
-	if (!$dir)
1945
-		return array();
2063
+	if (!$dir) {
2064
+			return array();
2065
+	}
1946 2066
 	while ($entry = $dir->read())
1947 2067
 	{
1948
-		if ($entry == '.' || $entry == '..')
1949
-			continue;
2068
+		if ($entry == '.' || $entry == '..') {
2069
+					continue;
2070
+		}
1950 2071
 
1951
-		if (is_dir($path . $sub_path . '/' . $entry))
1952
-			$data = array_merge($data, listtree($path, $sub_path . '/' . $entry));
1953
-		else
1954
-			$data[] = array(
2072
+		if (is_dir($path . $sub_path . '/' . $entry)) {
2073
+					$data = array_merge($data, listtree($path, $sub_path . '/' . $entry));
2074
+		} else {
2075
+					$data[] = array(
1955 2076
 				'filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry,
1956 2077
 				'size' => filesize($path . $sub_path . '/' . $entry),
1957 2078
 				'skipped' => false,
1958 2079
 			);
2080
+		}
1959 2081
 	}
1960 2082
 	$dir->close();
1961 2083
 
@@ -2010,8 +2132,9 @@  discard block
 block discarded – undo
2010 2132
 		{
2011 2133
 			// If this filename is relative, if so take a guess at what it should be.
2012 2134
 			$real_filename = $filename;
2013
-			if (strpos($filename, 'Themes') === 0)
2014
-				$real_filename = $boarddir . '/' . $filename;
2135
+			if (strpos($filename, 'Themes') === 0) {
2136
+							$real_filename = $boarddir . '/' . $filename;
2137
+			}
2015 2138
 
2016 2139
 			if (strpos($real_filename, $theme['theme_dir']) === 0)
2017 2140
 			{
@@ -2030,8 +2153,9 @@  discard block
 block discarded – undo
2030 2153
 		foreach ($theme_paths as $id => $theme)
2031 2154
 		{
2032 2155
 			// Default is getting done anyway, so no need for involvement here.
2033
-			if ($id == 1)
2034
-				continue;
2156
+			if ($id == 1) {
2157
+							continue;
2158
+			}
2035 2159
 
2036 2160
 			// For every template, do we want it? Yea, no, maybe?
2037 2161
 			foreach ($template_changes[1] as $index => $template_file)
@@ -2054,8 +2178,9 @@  discard block
 block discarded – undo
2054 2178
 		);
2055 2179
 
2056 2180
 		// Sometimes though, we have some additional files for other themes, if we have add them to the mix.
2057
-		if (isset($custom_themes_add[$files_to_change[1]]))
2058
-			$files_to_change += $custom_themes_add[$files_to_change[1]];
2181
+		if (isset($custom_themes_add[$files_to_change[1]])) {
2182
+					$files_to_change += $custom_themes_add[$files_to_change[1]];
2183
+		}
2059 2184
 
2060 2185
 		// Now, loop through all the files we're changing, and, well, change them ;)
2061 2186
 		foreach ($files_to_change as $theme => $working_file)
@@ -2089,11 +2214,13 @@  discard block
 block discarded – undo
2089 2214
 				continue;
2090 2215
 			}
2091 2216
 			// Okay, we're creating this file then...?
2092
-			elseif (!file_exists($working_file))
2093
-				$working_data = '';
2217
+			elseif (!file_exists($working_file)) {
2218
+							$working_data = '';
2219
+			}
2094 2220
 			// Phew, it exists!  Load 'er up!
2095
-			else
2096
-				$working_data = str_replace("\r", '', package_get_contents($working_file));
2221
+			else {
2222
+							$working_data = str_replace("\r", '', package_get_contents($working_file));
2223
+			}
2097 2224
 
2098 2225
 			$actions[] = array(
2099 2226
 				'type' => 'opened',
@@ -2114,8 +2241,8 @@  discard block
 block discarded – undo
2114 2241
 
2115 2242
 				// Grab all search items of this operation (in most cases just 1).
2116 2243
 				$searches = $operation->set('search');
2117
-				foreach ($searches as $i => $search)
2118
-					$actual_operation['searches'][] = array(
2244
+				foreach ($searches as $i => $search) {
2245
+									$actual_operation['searches'][] = array(
2119 2246
 						'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), array('before', 'after', 'replace', 'end')) ? trim($search->fetch('@position')) : 'replace',
2120 2247
 						'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true',
2121 2248
 						'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose',
@@ -2124,6 +2251,7 @@  discard block
 block discarded – undo
2124 2251
 						'preg_search' => '',
2125 2252
 						'preg_replace' => '',
2126 2253
 					);
2254
+				}
2127 2255
 
2128 2256
 				// At least one search should be defined.
2129 2257
 				if (empty($actual_operation['searches']))
@@ -2148,30 +2276,32 @@  discard block
 block discarded – undo
2148 2276
 						// Reverse modification of regular expressions are not allowed.
2149 2277
 						if ($search['is_reg_exp'])
2150 2278
 						{
2151
-							if ($actual_operation['error'] === 'fatal')
2152
-								$actions[] = array(
2279
+							if ($actual_operation['error'] === 'fatal') {
2280
+															$actions[] = array(
2153 2281
 									'type' => 'failure',
2154 2282
 									'filename' => $working_file,
2155 2283
 									'search' => $search['search'],
2156 2284
 									'is_custom' => $theme > 1 ? $theme : 0,
2157 2285
 								);
2286
+							}
2158 2287
 
2159 2288
 							// Continue to the next operation.
2160 2289
 							continue 2;
2161 2290
 						}
2162 2291
 
2163 2292
 						// The replacement is now the search subject...
2164
-						if ($search['position'] === 'replace' || $search['position'] === 'end')
2165
-							$actual_operation['searches'][$i]['search'] = $search['add'];
2166
-						else
2293
+						if ($search['position'] === 'replace' || $search['position'] === 'end') {
2294
+													$actual_operation['searches'][$i]['search'] = $search['add'];
2295
+						} else
2167 2296
 						{
2168 2297
 							// Reversing a before/after modification becomes a replacement.
2169 2298
 							$actual_operation['searches'][$i]['position'] = 'replace';
2170 2299
 
2171
-							if ($search['position'] === 'before')
2172
-								$actual_operation['searches'][$i]['search'] .= $search['add'];
2173
-							elseif ($search['position'] === 'after')
2174
-								$actual_operation['searches'][$i]['search'] = $search['add'] . $search['search'];
2300
+							if ($search['position'] === 'before') {
2301
+															$actual_operation['searches'][$i]['search'] .= $search['add'];
2302
+							} elseif ($search['position'] === 'after') {
2303
+															$actual_operation['searches'][$i]['search'] = $search['add'] . $search['search'];
2304
+							}
2175 2305
 						}
2176 2306
 
2177 2307
 						// ...and the search subject is now the replacement.
@@ -2199,16 +2329,17 @@  discard block
 block discarded – undo
2199 2329
 				foreach ($actual_operation['searches'] as $i => $search)
2200 2330
 				{
2201 2331
 					// Not much needed if the search subject is already a regexp.
2202
-					if ($search['is_reg_exp'])
2203
-						$actual_operation['searches'][$i]['preg_search'] = $search['search'];
2204
-					else
2332
+					if ($search['is_reg_exp']) {
2333
+											$actual_operation['searches'][$i]['preg_search'] = $search['search'];
2334
+					} else
2205 2335
 					{
2206 2336
 						// Make the search subject fit into a regular expression.
2207 2337
 						$actual_operation['searches'][$i]['preg_search'] = preg_quote($search['search'], '~');
2208 2338
 
2209 2339
 						// Using 'loose', a random amount of tabs and spaces may be used.
2210
-						if ($search['loose_whitespace'])
2211
-							$actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']);
2340
+						if ($search['loose_whitespace']) {
2341
+													$actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']);
2342
+						}
2212 2343
 					}
2213 2344
 
2214 2345
 					// Shuzzup.  This is done so we can safely use a regular expression. ($0 is bad!!)
@@ -2234,8 +2365,7 @@  discard block
 block discarded – undo
2234 2365
 						if ($undo)
2235 2366
 						{
2236 2367
 							$actual_operation['searches'][$i]['preg_replace'] = '';
2237
-						}
2238
-						else
2368
+						} else
2239 2369
 						{
2240 2370
 							$actual_operation['searches'][$i]['preg_search'] = '(\\n\\?\\>)?$';
2241 2371
 							$actual_operation['searches'][$i]['preg_replace'] .= '$1';
@@ -2282,8 +2412,9 @@  discard block
 block discarded – undo
2282 2412
 					}
2283 2413
 
2284 2414
 					// Replace it into nothing? That's not an option...unless it's an undoing end.
2285
-					if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo))
2286
-						continue;
2415
+					if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) {
2416
+											continue;
2417
+					}
2287 2418
 
2288 2419
 					// Finally, we're doing some replacements.
2289 2420
 					$working_data = preg_replace('~' . $actual_operation['searches'][$i]['preg_search'] . '~s', $actual_operation['searches'][$i]['preg_replace'], $working_data, 1);
@@ -2308,22 +2439,25 @@  discard block
 block discarded – undo
2308 2439
 
2309 2440
 			package_chmod($working_file);
2310 2441
 
2311
-			if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file))))
2312
-				$actions[] = array(
2442
+			if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) {
2443
+							$actions[] = array(
2313 2444
 					'type' => 'chmod',
2314 2445
 					'filename' => $working_file
2315 2446
 				);
2447
+			}
2316 2448
 
2317
-			if (basename($working_file) == 'Settings_bak.php')
2318
-				continue;
2449
+			if (basename($working_file) == 'Settings_bak.php') {
2450
+							continue;
2451
+			}
2319 2452
 
2320 2453
 			if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2321 2454
 			{
2322 2455
 				// No, no, not Settings.php!
2323
-				if (basename($working_file) == 'Settings.php')
2324
-					@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2325
-				else
2326
-					@copy($working_file, $working_file . '~');
2456
+				if (basename($working_file) == 'Settings.php') {
2457
+									@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2458
+				} else {
2459
+									@copy($working_file, $working_file . '~');
2460
+				}
2327 2461
 			}
2328 2462
 
2329 2463
 			// Always call this, even if in testing, because it won't really be written in testing mode.
@@ -2390,8 +2524,9 @@  discard block
 block discarded – undo
2390 2524
 		if ($code_match[1] != 'edit file' && $code_match[1] != 'file')
2391 2525
 		{
2392 2526
 			// It's a step, let's add that to the current steps.
2393
-			if (isset($temp_changes[$step_counter]))
2394
-				$temp_changes[$step_counter]['changes'][] = $code_match[0];
2527
+			if (isset($temp_changes[$step_counter])) {
2528
+							$temp_changes[$step_counter]['changes'][] = $code_match[0];
2529
+			}
2395 2530
 			continue;
2396 2531
 		}
2397 2532
 
@@ -2408,11 +2543,13 @@  discard block
 block discarded – undo
2408 2543
 		foreach ($theme_paths as $id => $theme)
2409 2544
 		{
2410 2545
 			// If this filename is relative, if so take a guess at what it should be.
2411
-			if (strpos($filename, 'Themes') === 0)
2412
-				$filename = $boarddir . '/' . $filename;
2546
+			if (strpos($filename, 'Themes') === 0) {
2547
+							$filename = $boarddir . '/' . $filename;
2548
+			}
2413 2549
 
2414
-			if (strpos($filename, $theme['theme_dir']) === 0)
2415
-				$template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
2550
+			if (strpos($filename, $theme['theme_dir']) === 0) {
2551
+							$template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
2552
+			}
2416 2553
 		}
2417 2554
 	}
2418 2555
 
@@ -2427,8 +2564,9 @@  discard block
 block discarded – undo
2427 2564
 		foreach ($theme_paths as $id => $theme)
2428 2565
 		{
2429 2566
 			// Don't do default, it means nothing to me.
2430
-			if ($id == 1)
2431
-				continue;
2567
+			if ($id == 1) {
2568
+							continue;
2569
+			}
2432 2570
 
2433 2571
 			// Now, for each file do we need to edit it?
2434 2572
 			foreach ($template_changes[1] as $pos => $template_file)
@@ -2464,32 +2602,36 @@  discard block
 block discarded – undo
2464 2602
 				package_chmod($working_file);
2465 2603
 
2466 2604
 				// Don't even dare.
2467
-				if (basename($working_file) == 'Settings_bak.php')
2468
-					continue;
2605
+				if (basename($working_file) == 'Settings_bak.php') {
2606
+									continue;
2607
+				}
2469 2608
 
2470
-				if (!is_writable($working_file))
2471
-					$actions[] = array(
2609
+				if (!is_writable($working_file)) {
2610
+									$actions[] = array(
2472 2611
 						'type' => 'chmod',
2473 2612
 						'filename' => $working_file
2474 2613
 					);
2614
+				}
2475 2615
 
2476 2616
 				if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2477 2617
 				{
2478
-					if (basename($working_file) == 'Settings.php')
2479
-						@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2480
-					else
2481
-						@copy($working_file, $working_file . '~');
2618
+					if (basename($working_file) == 'Settings.php') {
2619
+											@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2620
+					} else {
2621
+											@copy($working_file, $working_file . '~');
2622
+					}
2482 2623
 				}
2483 2624
 
2484 2625
 				package_put_contents($working_file, $working_data, $testing);
2485 2626
 			}
2486 2627
 
2487
-			if ($working_file !== null)
2488
-				$actions[] = array(
2628
+			if ($working_file !== null) {
2629
+							$actions[] = array(
2489 2630
 					'type' => 'saved',
2490 2631
 					'filename' => $working_file,
2491 2632
 					'is_custom' => $is_custom,
2492 2633
 				);
2634
+			}
2493 2635
 
2494 2636
 			// Is this "now working on" file a theme specific one?
2495 2637
 			$is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0;
@@ -2508,10 +2650,11 @@  discard block
 block discarded – undo
2508 2650
 			{
2509 2651
 				$places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages');
2510 2652
 
2511
-				foreach ($places_to_check as $place)
2512
-					if (file_exists($place . '/' . $working_file))
2653
+				foreach ($places_to_check as $place) {
2654
+									if (file_exists($place . '/' . $working_file))
2513 2655
 					{
2514 2656
 						$working_file = $place . '/' . $working_file;
2657
+				}
2515 2658
 						break;
2516 2659
 					}
2517 2660
 			}
@@ -2525,8 +2668,7 @@  discard block
 block discarded – undo
2525 2668
 					'type' => 'opened',
2526 2669
 					'filename' => $working_file
2527 2670
 				);
2528
-			}
2529
-			else
2671
+			} else
2530 2672
 			{
2531 2673
 				$actions[] = array(
2532 2674
 					'type' => 'missing',
@@ -2562,11 +2704,13 @@  discard block
 block discarded – undo
2562 2704
 			$replace_with = $code_match[2];
2563 2705
 
2564 2706
 			// Add this afterward...
2565
-			if ($code_match[1] == 'add' || $code_match[1] == 'add after')
2566
-				$replace_with = $working_search . "\n" . $replace_with;
2707
+			if ($code_match[1] == 'add' || $code_match[1] == 'add after') {
2708
+							$replace_with = $working_search . "\n" . $replace_with;
2709
+			}
2567 2710
 			// Add this beforehand.
2568
-			elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above')
2569
-				$replace_with .= "\n" . $working_search;
2711
+			elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') {
2712
+							$replace_with .= "\n" . $working_search;
2713
+			}
2570 2714
 			// Otherwise.. replace with $replace_with ;).
2571 2715
 		}
2572 2716
 
@@ -2629,29 +2773,32 @@  discard block
 block discarded – undo
2629 2773
 	{
2630 2774
 		package_chmod($working_file);
2631 2775
 
2632
-		if (!is_writable($working_file))
2633
-			$actions[] = array(
2776
+		if (!is_writable($working_file)) {
2777
+					$actions[] = array(
2634 2778
 				'type' => 'chmod',
2635 2779
 				'filename' => $working_file
2636 2780
 			);
2781
+		}
2637 2782
 
2638 2783
 		if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2639 2784
 		{
2640
-			if (basename($working_file) == 'Settings.php')
2641
-				@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2642
-			else
2643
-				@copy($working_file, $working_file . '~');
2785
+			if (basename($working_file) == 'Settings.php') {
2786
+							@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2787
+			} else {
2788
+							@copy($working_file, $working_file . '~');
2789
+			}
2644 2790
 		}
2645 2791
 
2646 2792
 		package_put_contents($working_file, $working_data, $testing);
2647 2793
 	}
2648 2794
 
2649
-	if ($working_file !== null)
2650
-		$actions[] = array(
2795
+	if ($working_file !== null) {
2796
+			$actions[] = array(
2651 2797
 			'type' => 'saved',
2652 2798
 			'filename' => $working_file,
2653 2799
 			'is_custom' => $is_custom,
2654 2800
 		);
2801
+	}
2655 2802
 
2656 2803
 	$actions[] = array(
2657 2804
 		'type' => 'result',
@@ -2677,17 +2824,19 @@  discard block
 block discarded – undo
2677 2824
 		$mem_check = setMemoryLimit('128M');
2678 2825
 
2679 2826
 		// Windows doesn't seem to care about the memory_limit.
2680
-		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false)
2681
-			$package_cache = array();
2682
-		else
2683
-			$package_cache = false;
2827
+		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) {
2828
+					$package_cache = array();
2829
+		} else {
2830
+					$package_cache = false;
2831
+		}
2684 2832
 	}
2685 2833
 
2686
-	if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename]))
2687
-		return file_get_contents($filename);
2688
-	else
2689
-		return $package_cache[$filename];
2690
-}
2834
+	if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) {
2835
+			return file_get_contents($filename);
2836
+	} else {
2837
+			return $package_cache[$filename];
2838
+	}
2839
+	}
2691 2840
 
2692 2841
 /**
2693 2842
  * Writes data to a file, almost exactly like the file_put_contents() function.
@@ -2710,19 +2859,22 @@  discard block
 block discarded – undo
2710 2859
 		// Try to increase the memory limit - we don't want to run out of ram!
2711 2860
 		$mem_check = setMemoryLimit('128M');
2712 2861
 
2713
-		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false)
2714
-			$package_cache = array();
2715
-		else
2716
-			$package_cache = false;
2862
+		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) {
2863
+					$package_cache = array();
2864
+		} else {
2865
+					$package_cache = false;
2866
+		}
2717 2867
 	}
2718 2868
 
2719
-	if (isset($package_ftp))
2720
-		$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2869
+	if (isset($package_ftp)) {
2870
+			$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2871
+	}
2721 2872
 
2722
-	if (!file_exists($filename) && isset($package_ftp))
2723
-		$package_ftp->create_file($ftp_file);
2724
-	elseif (!file_exists($filename))
2725
-		@touch($filename);
2873
+	if (!file_exists($filename) && isset($package_ftp)) {
2874
+			$package_ftp->create_file($ftp_file);
2875
+	} elseif (!file_exists($filename)) {
2876
+			@touch($filename);
2877
+	}
2726 2878
 
2727 2879
 	package_chmod($filename);
2728 2880
 
@@ -2731,22 +2883,23 @@  discard block
 block discarded – undo
2731 2883
 		$fp = @fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb');
2732 2884
 
2733 2885
 		// We should show an error message or attempt a rollback, no?
2734
-		if (!$fp)
2735
-			return false;
2886
+		if (!$fp) {
2887
+					return false;
2888
+		}
2736 2889
 
2737 2890
 		fwrite($fp, $data);
2738 2891
 		fclose($fp);
2739
-	}
2740
-	elseif (strpos($filename, 'Packages/') !== false || $package_cache === false)
2741
-		return strlen($data);
2742
-	else
2892
+	} elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) {
2893
+			return strlen($data);
2894
+	} else
2743 2895
 	{
2744 2896
 		$package_cache[$filename] = $data;
2745 2897
 
2746 2898
 		// Permission denied, eh?
2747 2899
 		$fp = @fopen($filename, 'r+');
2748
-		if (!$fp)
2749
-			return false;
2900
+		if (!$fp) {
2901
+					return false;
2902
+		}
2750 2903
 		fclose($fp);
2751 2904
 	}
2752 2905
 
@@ -2763,19 +2916,22 @@  discard block
 block discarded – undo
2763 2916
 	global $package_ftp, $package_cache;
2764 2917
 	static $text_filetypes = array('php', 'txt', '.js', 'css', 'vbs', 'tml', 'htm');
2765 2918
 
2766
-	if (empty($package_cache))
2767
-		return;
2919
+	if (empty($package_cache)) {
2920
+			return;
2921
+	}
2768 2922
 
2769 2923
 	// First, let's check permissions!
2770 2924
 	foreach ($package_cache as $filename => $data)
2771 2925
 	{
2772
-		if (isset($package_ftp))
2773
-			$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2926
+		if (isset($package_ftp)) {
2927
+					$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2928
+		}
2774 2929
 
2775
-		if (!file_exists($filename) && isset($package_ftp))
2776
-			$package_ftp->create_file($ftp_file);
2777
-		elseif (!file_exists($filename))
2778
-			@touch($filename);
2930
+		if (!file_exists($filename) && isset($package_ftp)) {
2931
+					$package_ftp->create_file($ftp_file);
2932
+		} elseif (!file_exists($filename)) {
2933
+					@touch($filename);
2934
+		}
2779 2935
 
2780 2936
 		$result = package_chmod($filename);
2781 2937
 
@@ -2822,8 +2978,9 @@  discard block
 block discarded – undo
2822 2978
 {
2823 2979
 	global $package_ftp;
2824 2980
 
2825
-	if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable')
2826
-		return true;
2981
+	if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') {
2982
+			return true;
2983
+	}
2827 2984
 
2828 2985
 	// Start off checking without FTP.
2829 2986
 	if (!isset($package_ftp) || $package_ftp === false)
@@ -2845,8 +3002,7 @@  discard block
 block discarded – undo
2845 3002
 
2846 3003
 				// Keep track of the writable status here.
2847 3004
 				$file_permissions = @fileperms($chmod_file);
2848
-			}
2849
-			else
3005
+			} else
2850 3006
 			{
2851 3007
 				// This looks odd, but it's an attempt to work around PHP suExec.
2852 3008
 				if (!file_exists($chmod_file) && $perm_state == 'writable')
@@ -2856,24 +3012,28 @@  discard block
 block discarded – undo
2856 3012
 					mktree(dirname($chmod_file), 0755);
2857 3013
 					@touch($chmod_file);
2858 3014
 					smf_chmod($chmod_file, 0755);
3015
+				} else {
3016
+									$file_permissions = @fileperms($chmod_file);
2859 3017
 				}
2860
-				else
2861
-					$file_permissions = @fileperms($chmod_file);
2862 3018
 			}
2863 3019
 
2864 3020
 			// This looks odd, but it's another attempt to work around PHP suExec.
2865
-			if ($perm_state != 'writable')
2866
-				smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644);
2867
-			else
3021
+			if ($perm_state != 'writable') {
3022
+							smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644);
3023
+			} else
2868 3024
 			{
2869
-				if (!@is_writable($chmod_file))
2870
-					smf_chmod($chmod_file, 0755);
2871
-				if (!@is_writable($chmod_file))
2872
-					smf_chmod($chmod_file, 0777);
2873
-				if (!@is_writable(dirname($chmod_file)))
2874
-					smf_chmod($chmod_file, 0755);
2875
-				if (!@is_writable(dirname($chmod_file)))
2876
-					smf_chmod($chmod_file, 0777);
3025
+				if (!@is_writable($chmod_file)) {
3026
+									smf_chmod($chmod_file, 0755);
3027
+				}
3028
+				if (!@is_writable($chmod_file)) {
3029
+									smf_chmod($chmod_file, 0777);
3030
+				}
3031
+				if (!@is_writable(dirname($chmod_file))) {
3032
+									smf_chmod($chmod_file, 0755);
3033
+				}
3034
+				if (!@is_writable(dirname($chmod_file))) {
3035
+									smf_chmod($chmod_file, 0777);
3036
+				}
2877 3037
 			}
2878 3038
 
2879 3039
 			// The ultimate writable test.
@@ -2882,20 +3042,22 @@  discard block
 block discarded – undo
2882 3042
 				$fp = is_dir($chmod_file) ? @opendir($chmod_file) : @fopen($chmod_file, 'rb');
2883 3043
 				if (@is_writable($chmod_file) && $fp)
2884 3044
 				{
2885
-					if (!is_dir($chmod_file))
2886
-						fclose($fp);
2887
-					else
2888
-						closedir($fp);
3045
+					if (!is_dir($chmod_file)) {
3046
+											fclose($fp);
3047
+					} else {
3048
+											closedir($fp);
3049
+					}
2889 3050
 
2890 3051
 					// It worked!
2891
-					if ($track_change)
2892
-						$_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions;
3052
+					if ($track_change) {
3053
+											$_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions;
3054
+					}
2893 3055
 
2894 3056
 					return true;
2895 3057
 				}
3058
+			} elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) {
3059
+							unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]);
2896 3060
 			}
2897
-			elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file]))
2898
-				unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]);
2899 3061
 		}
2900 3062
 
2901 3063
 		// If we're here we're a failure.
@@ -2914,31 +3076,33 @@  discard block
 block discarded – undo
2914 3076
 			mktree(dirname($filename), 0755);
2915 3077
 			$package_ftp->create_file($ftp_file);
2916 3078
 			$package_ftp->chmod($ftp_file, 0755);
3079
+		} else {
3080
+					$file_permissions = @fileperms($filename);
2917 3081
 		}
2918
-		else
2919
-			$file_permissions = @fileperms($filename);
2920 3082
 
2921 3083
 		if ($perm_state != 'writable')
2922 3084
 		{
2923 3085
 			$package_ftp->chmod($ftp_file, $perm_state == 'execute' ? 0755 : 0644);
2924
-		}
2925
-		else
3086
+		} else
2926 3087
 		{
2927
-			if (!@is_writable($filename))
2928
-				$package_ftp->chmod($ftp_file, 0777);
2929
-			if (!@is_writable(dirname($filename)))
2930
-				$package_ftp->chmod(dirname($ftp_file), 0777);
3088
+			if (!@is_writable($filename)) {
3089
+							$package_ftp->chmod($ftp_file, 0777);
3090
+			}
3091
+			if (!@is_writable(dirname($filename))) {
3092
+							$package_ftp->chmod(dirname($ftp_file), 0777);
3093
+			}
2931 3094
 		}
2932 3095
 
2933 3096
 		if (@is_writable($filename))
2934 3097
 		{
2935
-			if ($track_change)
2936
-				$_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions;
3098
+			if ($track_change) {
3099
+							$_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions;
3100
+			}
2937 3101
 
2938 3102
 			return true;
3103
+		} elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) {
3104
+					unset($_SESSION['pack_ftp']['original_perms'][$filename]);
2939 3105
 		}
2940
-		elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename]))
2941
-			unset($_SESSION['pack_ftp']['original_perms'][$filename]);
2942 3106
 	}
2943 3107
 
2944 3108
 	// Oh dear, we failed if we get here.
@@ -2956,11 +3120,13 @@  discard block
 block discarded – undo
2956 3120
 	$n = strlen($pass);
2957 3121
 
2958 3122
 	$salt = session_id();
2959
-	while (strlen($salt) < $n)
2960
-		$salt .= session_id();
3123
+	while (strlen($salt) < $n) {
3124
+			$salt .= session_id();
3125
+	}
2961 3126
 
2962
-	for ($i = 0; $i < $n; $i++)
2963
-		$pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
3127
+	for ($i = 0; $i < $n; $i++) {
3128
+			$pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
3129
+	}
2964 3130
 
2965 3131
 	return $pass;
2966 3132
 }
@@ -2979,8 +3145,9 @@  discard block
 block discarded – undo
2979 3145
 	$base_files = array('index.php', 'SSI.php', 'agreement.txt', 'cron.php', 'ssi_examples.php', 'ssi_examples.shtml', 'subscriptions.php');
2980 3146
 	foreach ($base_files as $file)
2981 3147
 	{
2982
-		if (file_exists($boarddir . '/' . $file))
2983
-			$files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file;
3148
+		if (file_exists($boarddir . '/' . $file)) {
3149
+					$files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file;
3150
+		}
2984 3151
 	}
2985 3152
 
2986 3153
 	$dirs = array(
@@ -2997,8 +3164,9 @@  discard block
 block discarded – undo
2997 3164
 			'theme_dir' => 'theme_dir',
2998 3165
 		)
2999 3166
 	);
3000
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3001
-		$dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/');
3167
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3168
+			$dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/');
3169
+	}
3002 3170
 	$smcFunc['db_free_result']($request);
3003 3171
 
3004 3172
 	try
@@ -3013,11 +3181,13 @@  discard block
 block discarded – undo
3013 3181
 
3014 3182
 			foreach ($iter as $entry => $dir)
3015 3183
 			{
3016
-				if ($dir->isDir())
3017
-					continue;
3184
+				if ($dir->isDir()) {
3185
+									continue;
3186
+				}
3018 3187
 
3019
-				if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0)
3020
-					continue;
3188
+				if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) {
3189
+									continue;
3190
+				}
3021 3191
 
3022 3192
 				$files[empty($_REQUEST['use_full_paths']) ? str_replace(realpath($boarddir), '', $entry) : $entry] = $entry;
3023 3193
 			}
@@ -3025,26 +3195,30 @@  discard block
 block discarded – undo
3025 3195
 		$obj = new ArrayObject($files);
3026 3196
 		$iterator = $obj->getIterator();
3027 3197
 
3028
-		if (!file_exists($packagesdir . '/backups'))
3029
-			mktree($packagesdir . '/backups', 0777);
3030
-		if (!is_writable($packagesdir . '/backups'))
3031
-			package_chmod($packagesdir . '/backups');
3198
+		if (!file_exists($packagesdir . '/backups')) {
3199
+					mktree($packagesdir . '/backups', 0777);
3200
+		}
3201
+		if (!is_writable($packagesdir . '/backups')) {
3202
+					package_chmod($packagesdir . '/backups');
3203
+		}
3032 3204
 		$output_file = $packagesdir . '/backups/' . strftime('%Y-%m-%d_') . preg_replace('~[$\\\\/:<>|?*"\']~', '', $id);
3033 3205
 		$output_ext = '.tar';
3034 3206
 
3035 3207
 		if (file_exists($output_file . $output_ext))
3036 3208
 		{
3037 3209
 			$i = 2;
3038
-			while (file_exists($output_file . '_' . $i . $output_ext))
3039
-				$i++;
3210
+			while (file_exists($output_file . '_' . $i . $output_ext)) {
3211
+							$i++;
3212
+			}
3040 3213
 			$output_file = $output_file . '_' . $i . $output_ext;
3214
+		} else {
3215
+					$output_file .= $output_ext;
3041 3216
 		}
3042
-		else
3043
-			$output_file .= $output_ext;
3044 3217
 
3045 3218
 		@set_time_limit(300);
3046
-		if (function_exists('apache_reset_timeout'))
3047
-			@apache_reset_timeout();
3219
+		if (function_exists('apache_reset_timeout')) {
3220
+					@apache_reset_timeout();
3221
+		}
3048 3222
 
3049 3223
 		$a = new PharData($output_file);
3050 3224
 		$a->buildFromIterator($iterator);
@@ -3056,8 +3230,7 @@  discard block
 block discarded – undo
3056 3230
 		 */
3057 3231
 		unset($a);
3058 3232
 		unlink($output_file);
3059
-	}
3060
-	catch (Exception $e)
3233
+	} catch (Exception $e)
3061 3234
 	{
3062 3235
 		log_error($e->getMessage(), 'backup');
3063 3236
 
@@ -3089,32 +3262,35 @@  discard block
 block discarded – undo
3089 3262
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
3090 3263
 
3091 3264
 	// An FTP url. We should try connecting and RETRieving it...
3092
-	if (empty($match[1]))
3093
-		return false;
3094
-	elseif ($match[1] == 'ftp')
3265
+	if (empty($match[1])) {
3266
+			return false;
3267
+	} elseif ($match[1] == 'ftp')
3095 3268
 	{
3096 3269
 		// Include the file containing the ftp_connection class.
3097 3270
 		require_once($sourcedir . '/Class-Package.php');
3098 3271
 
3099 3272
 		// Establish a connection and attempt to enable passive mode.
3100 3273
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
3101
-		if ($ftp->error !== false || !$ftp->passive())
3102
-			return false;
3274
+		if ($ftp->error !== false || !$ftp->passive()) {
3275
+					return false;
3276
+		}
3103 3277
 
3104 3278
 		// I want that one *points*!
3105 3279
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
3106 3280
 
3107 3281
 		// Since passive mode worked (or we would have returned already!) open the connection.
3108 3282
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
3109
-		if (!$fp)
3110
-			return false;
3283
+		if (!$fp) {
3284
+					return false;
3285
+		}
3111 3286
 
3112 3287
 		// The server should now say something in acknowledgement.
3113 3288
 		$ftp->check_response(150);
3114 3289
 
3115 3290
 		$data = '';
3116
-		while (!feof($fp))
3117
-			$data .= fread($fp, 4096);
3291
+		while (!feof($fp)) {
3292
+					$data .= fread($fp, 4096);
3293
+		}
3118 3294
 		fclose($fp);
3119 3295
 
3120 3296
 		// All done, right?  Good.
@@ -3131,22 +3307,25 @@  discard block
 block discarded – undo
3131 3307
 		$fetch_data->get_url_data($url, $post_data);
3132 3308
 
3133 3309
 		// no errors and a 200 result, then we have a good dataset, well we at least have data ;)
3134
-		if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
3135
-			$data = $fetch_data->result('body');
3136
-		else
3137
-			return false;
3310
+		if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
3311
+					$data = $fetch_data->result('body');
3312
+		} else {
3313
+					return false;
3314
+		}
3138 3315
 	}
3139 3316
 	// This is more likely; a standard HTTP URL.
3140 3317
 	elseif (isset($match[1]) && $match[1] == 'http')
3141 3318
 	{
3142
-		if ($keep_alive && $match[3] == $keep_alive_dom)
3143
-			$fp = $keep_alive_fp;
3319
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
3320
+					$fp = $keep_alive_fp;
3321
+		}
3144 3322
 		if (empty($fp))
3145 3323
 		{
3146 3324
 			// Open the socket on the port we want...
3147 3325
 			$fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? ($match[2] ? 443 : 80) : $match[5], $err, $err, 5);
3148
-			if (!$fp)
3149
-				return false;
3326
+			if (!$fp) {
3327
+							return false;
3328
+			}
3150 3329
 		}
3151 3330
 
3152 3331
 		if ($keep_alive)
@@ -3161,20 +3340,21 @@  discard block
 block discarded – undo
3161 3340
 			fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
3162 3341
 			fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
3163 3342
 			fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n");
3164
-			if ($keep_alive)
3165
-				fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n");
3166
-			else
3167
-				fwrite($fp, 'Connection: close' . "\r\n\r\n");
3168
-		}
3169
-		else
3343
+			if ($keep_alive) {
3344
+							fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n");
3345
+			} else {
3346
+							fwrite($fp, 'Connection: close' . "\r\n\r\n");
3347
+			}
3348
+		} else
3170 3349
 		{
3171 3350
 			fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
3172 3351
 			fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
3173 3352
 			fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n");
3174
-			if ($keep_alive)
3175
-				fwrite($fp, 'Connection: Keep-Alive' . "\r\n");
3176
-			else
3177
-				fwrite($fp, 'Connection: close' . "\r\n");
3353
+			if ($keep_alive) {
3354
+							fwrite($fp, 'Connection: Keep-Alive' . "\r\n");
3355
+			} else {
3356
+							fwrite($fp, 'Connection: close' . "\r\n");
3357
+			}
3178 3358
 			fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n");
3179 3359
 			fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n");
3180 3360
 			fwrite($fp, $post_data);
@@ -3187,30 +3367,33 @@  discard block
 block discarded – undo
3187 3367
 		{
3188 3368
 			$header = '';
3189 3369
 			$location = '';
3190
-			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
3191
-				if (strpos($header, 'Location:') !== false)
3370
+			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
3371
+							if (strpos($header, 'Location:') !== false)
3192 3372
 					$location = trim(substr($header, strpos($header, ':') + 1));
3373
+			}
3193 3374
 
3194
-			if (empty($location))
3195
-				return false;
3196
-			else
3375
+			if (empty($location)) {
3376
+							return false;
3377
+			} else
3197 3378
 			{
3198
-				if (!$keep_alive)
3199
-					fclose($fp);
3379
+				if (!$keep_alive) {
3380
+									fclose($fp);
3381
+				}
3200 3382
 				return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
3201 3383
 			}
3202 3384
 		}
3203 3385
 
3204 3386
 		// Make sure we get a 200 OK.
3205
-		elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
3206
-			return false;
3387
+		elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
3388
+					return false;
3389
+		}
3207 3390
 
3208 3391
 		// Skip the headers...
3209 3392
 		while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
3210 3393
 		{
3211
-			if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
3212
-				$content_length = $match[1];
3213
-			elseif (preg_match('~connection:\s*close~i', $header) != 0)
3394
+			if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
3395
+							$content_length = $match[1];
3396
+			} elseif (preg_match('~connection:\s*close~i', $header) != 0)
3214 3397
 			{
3215 3398
 				$keep_alive_dom = null;
3216 3399
 				$keep_alive = false;
@@ -3222,19 +3405,20 @@  discard block
 block discarded – undo
3222 3405
 		$data = '';
3223 3406
 		if (isset($content_length))
3224 3407
 		{
3225
-			while (!feof($fp) && strlen($data) < $content_length)
3226
-				$data .= fread($fp, $content_length - strlen($data));
3227
-		}
3228
-		else
3408
+			while (!feof($fp) && strlen($data) < $content_length) {
3409
+							$data .= fread($fp, $content_length - strlen($data));
3410
+			}
3411
+		} else
3229 3412
 		{
3230
-			while (!feof($fp))
3231
-				$data .= fread($fp, 4096);
3413
+			while (!feof($fp)) {
3414
+							$data .= fread($fp, 4096);
3415
+			}
3232 3416
 		}
3233 3417
 
3234
-		if (!$keep_alive)
3235
-			fclose($fp);
3236
-	}
3237
-	else
3418
+		if (!$keep_alive) {
3419
+					fclose($fp);
3420
+		}
3421
+	} else
3238 3422
 	{
3239 3423
 		// Umm, this shouldn't happen?
3240 3424
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
Please login to merge, or discard this patch.
Sources/Subs-Post.php 2 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
  * @param resource $socket Socket to send on
1452 1452
  * @param string $code The expected response code
1453 1453
  * @param string $response The response from the SMTP server
1454
- * @return bool Whether it responded as such.
1454
+ * @return string|boolean Whether it responded as such.
1455 1455
  */
1456 1456
 function server_parse($message, $socket, $code, &$response = null)
1457 1457
 {
@@ -2265,7 +2265,7 @@  discard block
 block discarded – undo
2265 2265
  * @param array $msgs Array of message ids
2266 2266
  * @param bool $approve Whether to approve the posts (if false, posts are unapproved)
2267 2267
  * @param bool $notify Whether to notify users
2268
- * @return bool Whether the operation was successful
2268
+ * @return null|boolean Whether the operation was successful
2269 2269
  */
2270 2270
 function approvePosts($msgs, $approve = true, $notify = true)
2271 2271
 {
@@ -2518,7 +2518,7 @@  discard block
 block discarded – undo
2518 2518
  *
2519 2519
  * @param array $topics Array of topic ids
2520 2520
  * @param bool $approve Whether to approve the topics. If false, unapproves them instead
2521
- * @return bool Whether the operation was successful
2521
+ * @return null|boolean Whether the operation was successful
2522 2522
  */
2523 2523
 function approveTopics($topics, $approve = true)
2524 2524
 {
@@ -2908,7 +2908,7 @@  discard block
 block discarded – undo
2908 2908
  *
2909 2909
  * @param resource $dict An enchant or pspell dictionary resource set up by {@link spell_init()}
2910 2910
  * @param string $word A word to check the spelling of
2911
- * @return bool Whether or not the specified word is spelled properly
2911
+ * @return boolean|null Whether or not the specified word is spelled properly
2912 2912
  */
2913 2913
 function spell_check($dict, $word)
2914 2914
 {
Please login to merge, or discard this patch.
Braces   +528 added lines, -393 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -46,17 +47,19 @@  discard block
 block discarded – undo
46 47
 	$message = preg_replace('~\.{100,}~', '...', $message);
47 48
 
48 49
 	// Trim off trailing quotes - these often happen by accident.
49
-	while (substr($message, -7) == '[quote]')
50
-		$message = substr($message, 0, -7);
51
-	while (substr($message, 0, 8) == '[/quote]')
52
-		$message = substr($message, 8);
50
+	while (substr($message, -7) == '[quote]') {
51
+			$message = substr($message, 0, -7);
52
+	}
53
+	while (substr($message, 0, 8) == '[/quote]') {
54
+			$message = substr($message, 8);
55
+	}
53 56
 
54 57
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
55 58
 	$in_tag = false;
56 59
 	$had_tag = false;
57 60
 	$codeopen = 0;
58
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
59
-		foreach ($matches[0] as $index => $dummy)
61
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
62
+			foreach ($matches[0] as $index => $dummy)
60 63
 		{
61 64
 			// Closing?
62 65
 			if (!empty($matches[2][$index]))
@@ -64,6 +67,7 @@  discard block
 block discarded – undo
64 67
 				// If it's closing and we're not in a tag we need to open it...
65 68
 				if (!$in_tag)
66 69
 					$codeopen = true;
70
+	}
67 71
 				// Either way we ain't in one any more.
68 72
 				$in_tag = false;
69 73
 			}
@@ -72,17 +76,20 @@  discard block
 block discarded – undo
72 76
 			{
73 77
 				$had_tag = true;
74 78
 				// If we're in a tag don't do nought!
75
-				if (!$in_tag)
76
-					$in_tag = true;
79
+				if (!$in_tag) {
80
+									$in_tag = true;
81
+				}
77 82
 			}
78 83
 		}
79 84
 
80 85
 	// If we have an open tag, close it.
81
-	if ($in_tag)
82
-		$message .= '[/code]';
86
+	if ($in_tag) {
87
+			$message .= '[/code]';
88
+	}
83 89
 	// Open any ones that need to be open, only if we've never had a tag.
84
-	if ($codeopen && !$had_tag)
85
-		$message = '[code]' . $message;
90
+	if ($codeopen && !$had_tag) {
91
+			$message = '[code]' . $message;
92
+	}
86 93
 
87 94
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
88 95
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -108,23 +115,26 @@  discard block
 block discarded – undo
108 115
 	fixTags($message);
109 116
 
110 117
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
111
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
112
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
113
-	else
114
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
118
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
119
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
120
+	} else {
121
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
122
+	}
115 123
 
116 124
 	if (!$previewing && strpos($message, '[html]') !== false)
117 125
 	{
118
-		if (allowedTo('admin_forum'))
119
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
126
+		if (allowedTo('admin_forum')) {
127
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
120 128
 				return '[html]' . strtr(un_htmlspecialchars($m), array("\n" => '&#13;', '  ' => ' &#32;', '[' => '&#91;', ']' => '&#93;')) . '[/html]';
129
+		}
121 130
 			}, $message);
122 131
 
123 132
 		// We should edit them out, or else if an admin edits the message they will get shown...
124 133
 		else
125 134
 		{
126
-			while (strpos($message, '[html]') !== false)
127
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
135
+			while (strpos($message, '[html]') !== false) {
136
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			}
128 138
 		}
129 139
 	}
130 140
 
@@ -146,10 +156,12 @@  discard block
 block discarded – undo
146 156
 
147 157
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
148 158
 	$list_close = substr_count($message, '[/list]');
149
-	if ($list_close - $list_open > 0)
150
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
151
-	if ($list_open - $list_close > 0)
152
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
159
+	if ($list_close - $list_open > 0) {
160
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
161
+	}
162
+	if ($list_open - $list_close > 0) {
163
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
164
+	}
153 165
 
154 166
 	$mistake_fixes = array(
155 167
 		// Find [table]s not followed by [tr].
@@ -198,8 +210,9 @@  discard block
 block discarded – undo
198 210
 	);
199 211
 
200 212
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
201
-	for ($j = 0; $j < 3; $j++)
202
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
213
+	for ($j = 0; $j < 3; $j++) {
214
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	}
203 216
 
204 217
 	// Remove empty bbc from the sections outside the code tags
205 218
 	$allowedEmpty = array(
@@ -209,24 +222,28 @@  discard block
 block discarded – undo
209 222
 
210 223
 	require_once($sourcedir . '/Subs.php');
211 224
 
212
-	foreach (($codes = parse_bbc(false)) as $code)
213
-		if (!in_array($code['tag'], $allowedEmpty))
225
+	foreach (($codes = parse_bbc(false)) as $code) {
226
+			if (!in_array($code['tag'], $allowedEmpty))
214 227
 			$alltags[] = $code['tag'];
228
+	}
215 229
 
216 230
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
217 231
 
218
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
219
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
232
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
233
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	}
220 235
 
221 236
 	// Restore code blocks
222
-	if (!empty($code_tags))
223
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
237
+	if (!empty($code_tags)) {
238
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	}
224 240
 
225 241
 	// Restore white space entities
226
-	if (!$previewing)
227
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
228
-	else
229
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
242
+	if (!$previewing) {
243
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	} else {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	}
230 247
 
231 248
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
232 249
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -269,8 +286,9 @@  discard block
 block discarded – undo
269 286
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
270 287
 	}, $message);
271 288
 
272
-	if (!empty($code_tags))
273
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
289
+	if (!empty($code_tags)) {
290
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	}
274 292
 
275 293
 	// Change breaks back to \n's and &nsbp; back to spaces.
276 294
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -351,8 +369,9 @@  discard block
 block discarded – undo
351 369
 	);
352 370
 
353 371
 	// Fix each type of tag.
354
-	foreach ($fixArray as $param)
355
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
372
+	foreach ($fixArray as $param) {
373
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	}
356 375
 
357 376
 	// Now fix possible security problems with images loading links automatically...
358 377
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -388,16 +407,19 @@  discard block
 block discarded – undo
388 407
 					$desired_height = $height;
389 408
 				}
390 409
 				// Scale it to the width...
391
-				elseif (empty($desired_width) && !empty($height))
392
-					$desired_width = (int) (($desired_height * $width) / $height);
410
+				elseif (empty($desired_width) && !empty($height)) {
411
+									$desired_width = (int) (($desired_height * $width) / $height);
412
+				}
393 413
 				// Scale if to the height.
394
-				elseif (!empty($width))
395
-					$desired_height = (int) (($desired_width * $height) / $width);
414
+				elseif (!empty($width)) {
415
+									$desired_height = (int) (($desired_width * $height) / $width);
416
+				}
396 417
 			}
397 418
 
398 419
 			// If the width and height are fine, just continue along...
399
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
400
-				continue;
420
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
421
+							continue;
422
+			}
401 423
 
402 424
 			// Too bad, it's too wide.  Make it as wide as the maximum.
403 425
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -417,8 +439,9 @@  discard block
 block discarded – undo
417 439
 		}
418 440
 
419 441
 		// If any img tags were actually changed...
420
-		if (!empty($replaces))
421
-			$message = strtr($message, $replaces);
442
+		if (!empty($replaces)) {
443
+					$message = strtr($message, $replaces);
444
+		}
422 445
 	}
423 446
 }
424 447
 
@@ -437,10 +460,11 @@  discard block
 block discarded – undo
437 460
 {
438 461
 	global $boardurl, $scripturl;
439 462
 
440
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
441
-		$domain_url = $match[1];
442
-	else
443
-		$domain_url = $boardurl . '/';
463
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
464
+			$domain_url = $match[1];
465
+	} else {
466
+			$domain_url = $boardurl . '/';
467
+	}
444 468
 
445 469
 	$replaces = array();
446 470
 
@@ -448,11 +472,11 @@  discard block
 block discarded – undo
448 472
 	{
449 473
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
450 474
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
475
+	} elseif ($hasEqualSign) {
476
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
477
+	} else {
478
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
451 479
 	}
452
-	elseif ($hasEqualSign)
453
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
454
-	else
455
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
456 480
 
457 481
 	foreach ($matches[0] as $k => $dummy)
458 482
 	{
@@ -465,49 +489,53 @@  discard block
 block discarded – undo
465 489
 		foreach ($protocols as $protocol)
466 490
 		{
467 491
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
468
-			if ($found)
469
-				break;
492
+			if ($found) {
493
+							break;
494
+			}
470 495
 		}
471 496
 
472 497
 		if (!$found && $protocols[0] == 'http')
473 498
 		{
474
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
475
-				$replace = $domain_url . $replace;
476
-			elseif (substr($replace, 0, 1) == '?')
477
-				$replace = $scripturl . $replace;
478
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
499
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
500
+							$replace = $domain_url . $replace;
501
+			} elseif (substr($replace, 0, 1) == '?') {
502
+							$replace = $scripturl . $replace;
503
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
479 504
 			{
480 505
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
481 506
 				$this_tag = 'iurl';
482 507
 				$this_close = 'iurl';
508
+			} elseif (substr($replace, 0, 2) != '//') {
509
+							$replace = $protocols[0] . '://' . $replace;
483 510
 			}
484
-			elseif (substr($replace, 0, 2) != '//')
485
-				$replace = $protocols[0] . '://' . $replace;
486
-		}
487
-		elseif (!$found && $protocols[0] == 'ftp')
488
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
489
-		elseif (!$found)
490
-			$replace = $protocols[0] . '://' . $replace;
491
-
492
-		if ($hasEqualSign && $embeddedUrl)
493
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
494
-		elseif ($hasEqualSign)
495
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
496
-		elseif ($embeddedUrl)
497
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
498
-		else
499
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
511
+		} elseif (!$found && $protocols[0] == 'ftp') {
512
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
513
+		} elseif (!$found) {
514
+					$replace = $protocols[0] . '://' . $replace;
515
+		}
516
+
517
+		if ($hasEqualSign && $embeddedUrl) {
518
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
519
+		} elseif ($hasEqualSign) {
520
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
521
+		} elseif ($embeddedUrl) {
522
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
523
+		} else {
524
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
525
+		}
500 526
 	}
501 527
 
502 528
 	foreach ($replaces as $k => $v)
503 529
 	{
504
-		if ($k == $v)
505
-			unset($replaces[$k]);
530
+		if ($k == $v) {
531
+					unset($replaces[$k]);
532
+		}
506 533
 	}
507 534
 
508
-	if (!empty($replaces))
509
-		$message = strtr($message, $replaces);
510
-}
535
+	if (!empty($replaces)) {
536
+			$message = strtr($message, $replaces);
537
+	}
538
+	}
511 539
 
512 540
 /**
513 541
  * This function sends an email to the specified recipient(s).
@@ -551,8 +579,9 @@  discard block
 block discarded – undo
551 579
 	}
552 580
 
553 581
 	// Nothing left? Nothing else to do
554
-	if (empty($to_array))
555
-		return true;
582
+	if (empty($to_array)) {
583
+			return true;
584
+	}
556 585
 
557 586
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
558 587
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -569,15 +598,17 @@  discard block
 block discarded – undo
569 598
 		}
570 599
 
571 600
 		// Call this function recursively for the hotmail addresses.
572
-		if (!empty($hotmail_to))
573
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
601
+		if (!empty($hotmail_to)) {
602
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
603
+		}
574 604
 
575 605
 		// The remaining addresses no longer need the fix.
576 606
 		$hotmail_fix = false;
577 607
 
578 608
 		// No other addresses left? Return instantly.
579
-		if (empty($to_array))
580
-			return $mail_result;
609
+		if (empty($to_array)) {
610
+					return $mail_result;
611
+		}
581 612
 	}
582 613
 
583 614
 	// Get rid of entities.
@@ -602,13 +633,15 @@  discard block
 block discarded – undo
602 633
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
603 634
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
604 635
 
605
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
606
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
636
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
637
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
638
+	}
607 639
 	$headers .= 'X-Mailer: SMF' . $line_break;
608 640
 
609 641
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
610
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
611
-		return false;
642
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
643
+			return false;
644
+	}
612 645
 
613 646
 	// Save the original message...
614 647
 	$orig_message = $message;
@@ -657,17 +690,19 @@  discard block
 block discarded – undo
657 690
 	}
658 691
 
659 692
 	// Are we using the mail queue, if so this is where we butt in...
660
-	if ($priority != 0)
661
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
693
+	if ($priority != 0) {
694
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
695
+	}
662 696
 
663 697
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
664 698
 	elseif (!empty($modSettings['mail_limit']))
665 699
 	{
666 700
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
667
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
668
-			$new_queue_stat = time() . '|' . 1;
669
-		else
670
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
701
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
702
+					$new_queue_stat = time() . '|' . 1;
703
+		} else {
704
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
705
+		}
671 706
 
672 707
 		updateSettings(array('mail_recent' => $new_queue_stat));
673 708
 	}
@@ -692,12 +727,13 @@  discard block
 block discarded – undo
692 727
 
693 728
 			// Wait, wait, I'm still sending here!
694 729
 			@set_time_limit(300);
695
-			if (function_exists('apache_reset_timeout'))
696
-				@apache_reset_timeout();
730
+			if (function_exists('apache_reset_timeout')) {
731
+							@apache_reset_timeout();
732
+			}
697 733
 		}
734
+	} else {
735
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
698 736
 	}
699
-	else
700
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
701 737
 
702 738
 	// Everything go smoothly?
703 739
 	return $mail_result;
@@ -723,8 +759,9 @@  discard block
 block discarded – undo
723 759
 	static $cur_insert = array();
724 760
 	static $cur_insert_len = 0;
725 761
 
726
-	if ($cur_insert_len == 0)
727
-		$cur_insert = array();
762
+	if ($cur_insert_len == 0) {
763
+			$cur_insert = array();
764
+	}
728 765
 
729 766
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
730 767
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -799,8 +836,9 @@  discard block
 block discarded – undo
799 836
 	}
800 837
 
801 838
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
802
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
803
-		return AddMailQueue(true);
839
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
840
+			return AddMailQueue(true);
841
+	}
804 842
 
805 843
 	return true;
806 844
 }
@@ -833,23 +871,26 @@  discard block
 block discarded – undo
833 871
 		'sent' => array()
834 872
 	);
835 873
 
836
-	if ($from === null)
837
-		$from = array(
874
+	if ($from === null) {
875
+			$from = array(
838 876
 			'id' => $user_info['id'],
839 877
 			'name' => $user_info['name'],
840 878
 			'username' => $user_info['username']
841 879
 		);
880
+	}
842 881
 
843 882
 	// This is the one that will go in their inbox.
844 883
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
845 884
 	preparsecode($htmlmessage);
846 885
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
847
-	if ($smcFunc['strlen']($htmlsubject) > 100)
848
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
886
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
887
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
888
+	}
849 889
 
850 890
 	// Make sure is an array
851
-	if (!is_array($recipients))
852
-		$recipients = array($recipients);
891
+	if (!is_array($recipients)) {
892
+			$recipients = array($recipients);
893
+	}
853 894
 
854 895
 	// Integrated PMs
855 896
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -877,21 +918,23 @@  discard block
 block discarded – undo
877 918
 				'usernames' => array_keys($usernames),
878 919
 			)
879 920
 		);
880
-		while ($row = $smcFunc['db_fetch_assoc']($request))
881
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
921
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
922
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
882 923
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
924
+		}
883 925
 		$smcFunc['db_free_result']($request);
884 926
 
885 927
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
886
-		foreach ($recipients as $rec_type => $rec)
887
-			foreach ($rec as $id => $member)
928
+		foreach ($recipients as $rec_type => $rec) {
929
+					foreach ($rec as $id => $member)
888 930
 			{
889 931
 				if (is_numeric($recipients[$rec_type][$id]))
890 932
 					continue;
933
+		}
891 934
 
892
-				if (!empty($usernames[$member]))
893
-					$recipients[$rec_type][$id] = $usernames[$member];
894
-				else
935
+				if (!empty($usernames[$member])) {
936
+									$recipients[$rec_type][$id] = $usernames[$member];
937
+				} else
895 938
 				{
896 939
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
897 940
 					unset($recipients[$rec_type][$id]);
@@ -930,8 +973,9 @@  discard block
 block discarded – undo
930 973
 		foreach ($criteria as $criterium)
931 974
 		{
932 975
 			$match = false;
933
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
934
-				$delete = true;
976
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
977
+							$delete = true;
978
+			}
935 979
 			// If we're adding and one criteria don't match then we stop!
936 980
 			elseif (!$row['is_or'])
937 981
 			{
@@ -939,8 +983,9 @@  discard block
 block discarded – undo
939 983
 				break;
940 984
 			}
941 985
 		}
942
-		if ($delete)
943
-			$deletes[$row['id_member']] = 1;
986
+		if ($delete) {
987
+					$deletes[$row['id_member']] = 1;
988
+		}
944 989
 	}
945 990
 	$smcFunc['db_free_result']($request);
946 991
 
@@ -955,8 +1000,9 @@  discard block
 block discarded – undo
955 1000
 			array(
956 1001
 			)
957 1002
 		);
958
-		while ($row = $smcFunc['db_fetch_assoc']($request))
959
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1003
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1004
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1005
+		}
960 1006
 		$smcFunc['db_free_result']($request);
961 1007
 	}
962 1008
 
@@ -964,8 +1010,9 @@  discard block
 block discarded – undo
964 1010
 	require_once($sourcedir . '/Subs-Members.php');
965 1011
 	$pmReadGroups = groupsAllowedTo('pm_read');
966 1012
 
967
-	if (empty($modSettings['permission_enable_deny']))
968
-		$pmReadGroups['denied'] = array();
1013
+	if (empty($modSettings['permission_enable_deny'])) {
1014
+			$pmReadGroups['denied'] = array();
1015
+	}
969 1016
 
970 1017
 	// Load their alert preferences
971 1018
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -997,8 +1044,9 @@  discard block
 block discarded – undo
997 1044
 	while ($row = $smcFunc['db_fetch_assoc']($request))
998 1045
 	{
999 1046
 		// Don't do anything for members to be deleted!
1000
-		if (isset($deletes[$row['id_member']]))
1001
-			continue;
1047
+		if (isset($deletes[$row['id_member']])) {
1048
+					continue;
1049
+		}
1002 1050
 
1003 1051
 		// Load the preferences for this member (if any)
1004 1052
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1019,8 +1067,9 @@  discard block
 block discarded – undo
1019 1067
 		{
1020 1068
 			foreach ($groups as $id)
1021 1069
 			{
1022
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1023
-					$message_limit = $message_limit_cache[$id];
1070
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1071
+									$message_limit = $message_limit_cache[$id];
1072
+				}
1024 1073
 			}
1025 1074
 
1026 1075
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1068,8 +1117,9 @@  discard block
 block discarded – undo
1068 1117
 	$smcFunc['db_free_result']($request);
1069 1118
 
1070 1119
 	// Only 'send' the message if there are any recipients left.
1071
-	if (empty($all_to))
1072
-		return $log;
1120
+	if (empty($all_to)) {
1121
+			return $log;
1122
+	}
1073 1123
 
1074 1124
 	// Insert the message itself and then grab the last insert id.
1075 1125
 	$smcFunc['db_insert']('',
@@ -1090,8 +1140,8 @@  discard block
 block discarded – undo
1090 1140
 	if (!empty($id_pm))
1091 1141
 	{
1092 1142
 		// If this is new we need to set it part of it's own conversation.
1093
-		if (empty($pm_head))
1094
-			$smcFunc['db_query']('', '
1143
+		if (empty($pm_head)) {
1144
+					$smcFunc['db_query']('', '
1095 1145
 				UPDATE {db_prefix}personal_messages
1096 1146
 				SET id_pm_head = {int:id_pm_head}
1097 1147
 				WHERE id_pm = {int:id_pm_head}',
@@ -1099,6 +1149,7 @@  discard block
 block discarded – undo
1099 1149
 					'id_pm_head' => $id_pm,
1100 1150
 				)
1101 1151
 			);
1152
+		}
1102 1153
 
1103 1154
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1104 1155
 		$smcFunc['db_query']('', '
@@ -1114,8 +1165,9 @@  discard block
 block discarded – undo
1114 1165
 		foreach ($all_to as $to)
1115 1166
 		{
1116 1167
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1117
-			if (!in_array($to, $recipients['bcc']))
1118
-				$to_list[] = $to;
1168
+			if (!in_array($to, $recipients['bcc'])) {
1169
+							$to_list[] = $to;
1170
+			}
1119 1171
 		}
1120 1172
 
1121 1173
 		$smcFunc['db_insert']('insert',
@@ -1133,9 +1185,9 @@  discard block
 block discarded – undo
1133 1185
 	{
1134 1186
 		censorText($message);
1135 1187
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1188
+	} else {
1189
+			$message = '';
1136 1190
 	}
1137
-	else
1138
-		$message = '';
1139 1191
 
1140 1192
 	$to_names = array();
1141 1193
 	if (count($to_list) > 1)
@@ -1148,8 +1200,9 @@  discard block
 block discarded – undo
1148 1200
 				'to_members' => $to_list,
1149 1201
 			)
1150 1202
 		);
1151
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1152
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1203
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1204
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1205
+		}
1153 1206
 		$smcFunc['db_free_result']($request);
1154 1207
 	}
1155 1208
 	$replacements = array(
@@ -1177,11 +1230,13 @@  discard block
 block discarded – undo
1177 1230
 	loadLanguage('index+PersonalMessage');
1178 1231
 
1179 1232
 	// Add one to their unread and read message counts.
1180
-	foreach ($all_to as $k => $id)
1181
-		if (isset($deletes[$id]))
1233
+	foreach ($all_to as $k => $id) {
1234
+			if (isset($deletes[$id]))
1182 1235
 			unset($all_to[$k]);
1183
-	if (!empty($all_to))
1184
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1236
+	}
1237
+	if (!empty($all_to)) {
1238
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1239
+	}
1185 1240
 
1186 1241
 	return $log;
1187 1242
 }
@@ -1211,15 +1266,17 @@  discard block
 block discarded – undo
1211 1266
 		// Let's, for now, assume there are only &#021;'ish characters.
1212 1267
 		$simple = true;
1213 1268
 
1214
-		foreach ($matches[1] as $entity)
1215
-			if ($entity > 128)
1269
+		foreach ($matches[1] as $entity) {
1270
+					if ($entity > 128)
1216 1271
 				$simple = false;
1272
+		}
1217 1273
 		unset($matches);
1218 1274
 
1219
-		if ($simple)
1220
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1275
+		if ($simple) {
1276
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1221 1277
 			{
1222 1278
 				return chr("$m[1]");
1279
+		}
1223 1280
 			}, $string);
1224 1281
 		else
1225 1282
 		{
@@ -1227,8 +1284,9 @@  discard block
 block discarded – undo
1227 1284
 			if (!$context['utf8'] && function_exists('iconv'))
1228 1285
 			{
1229 1286
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1230
-				if ($newstring)
1231
-					$string = $newstring;
1287
+				if ($newstring) {
1288
+									$string = $newstring;
1289
+				}
1232 1290
 			}
1233 1291
 
1234 1292
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1244,23 +1302,25 @@  discard block
 block discarded – undo
1244 1302
 		if (!$context['utf8'] && function_exists('iconv'))
1245 1303
 		{
1246 1304
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1247
-			if ($newstring)
1248
-				$string = $newstring;
1305
+			if ($newstring) {
1306
+							$string = $newstring;
1307
+			}
1249 1308
 		}
1250 1309
 
1251 1310
 		$entityConvert = function($m)
1252 1311
 		{
1253 1312
 			$c = $m[1];
1254
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1255
-				return $c;
1256
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1257
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1258
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1259
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1260
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1261
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1262
-			else
1263
-				return "";
1313
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1314
+							return $c;
1315
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1316
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1317
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1318
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1319
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1320
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1321
+			} else {
1322
+							return "";
1323
+			}
1264 1324
 		};
1265 1325
 
1266 1326
 		// Convert all 'special' characters to HTML entities.
@@ -1274,19 +1334,20 @@  discard block
 block discarded – undo
1274 1334
 		$string = base64_encode($string);
1275 1335
 
1276 1336
 		// Show the characterset and the transfer-encoding for header strings.
1277
-		if ($with_charset)
1278
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1337
+		if ($with_charset) {
1338
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1339
+		}
1279 1340
 
1280 1341
 		// Break it up in lines (mail body).
1281
-		else
1282
-			$string = chunk_split($string, 76, $line_break);
1342
+		else {
1343
+					$string = chunk_split($string, 76, $line_break);
1344
+		}
1283 1345
 
1284 1346
 		return array($charset, $string, 'base64');
1347
+	} else {
1348
+			return array($charset, $string, '7bit');
1349
+	}
1285 1350
 	}
1286
-
1287
-	else
1288
-		return array($charset, $string, '7bit');
1289
-}
1290 1351
 
1291 1352
 /**
1292 1353
  * Sends mail, like mail() but over SMTP.
@@ -1310,8 +1371,9 @@  discard block
 block discarded – undo
1310 1371
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1311 1372
 	{
1312 1373
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1313
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1314
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1374
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1375
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1376
+		}
1315 1377
 
1316 1378
 		if ($socket)
1317 1379
 		{
@@ -1332,8 +1394,9 @@  discard block
 block discarded – undo
1332 1394
 		// Maybe we can still save this?  The port might be wrong.
1333 1395
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1334 1396
 		{
1335
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1336
-				log_error($txt['smtp_port_ssl']);
1397
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1398
+							log_error($txt['smtp_port_ssl']);
1399
+			}
1337 1400
 		}
1338 1401
 
1339 1402
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1345,20 +1408,23 @@  discard block
 block discarded – undo
1345 1408
 	}
1346 1409
 
1347 1410
 	// Wait for a response of 220, without "-" continuer.
1348
-	if (!server_parse(null, $socket, '220'))
1349
-		return false;
1411
+	if (!server_parse(null, $socket, '220')) {
1412
+			return false;
1413
+	}
1350 1414
 
1351 1415
 	// Try and determine the servers name, fall back to the mail servers if not found
1352 1416
 	$helo = false;
1353
-	if (function_exists('gethostname') && gethostname() !== false)
1354
-		$helo = gethostname();
1355
-	elseif (function_exists('php_uname'))
1356
-		$helo = php_uname('n');
1357
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1358
-		$helo = $_SERVER['SERVER_NAME'];
1417
+	if (function_exists('gethostname') && gethostname() !== false) {
1418
+			$helo = gethostname();
1419
+	} elseif (function_exists('php_uname')) {
1420
+			$helo = php_uname('n');
1421
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1422
+			$helo = $_SERVER['SERVER_NAME'];
1423
+	}
1359 1424
 
1360
-	if (empty($helo))
1361
-		$helo = $modSettings['smtp_host'];
1425
+	if (empty($helo)) {
1426
+			$helo = $modSettings['smtp_host'];
1427
+	}
1362 1428
 
1363 1429
 	// SMTP = 1, SMTP - STARTTLS = 2
1364 1430
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1370,33 +1436,39 @@  discard block
 block discarded – undo
1370 1436
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1371 1437
 			{
1372 1438
 				// Send STARTTLS to enable encryption
1373
-				if (!server_parse('STARTTLS', $socket, '220'))
1374
-					return false;
1439
+				if (!server_parse('STARTTLS', $socket, '220')) {
1440
+									return false;
1441
+				}
1375 1442
 				// Enable the encryption
1376
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1377
-					return false;
1443
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1444
+									return false;
1445
+				}
1378 1446
 				// Send the EHLO command again
1379
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1380
-					return false;
1447
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1448
+									return false;
1449
+				}
1381 1450
 			}
1382 1451
 
1383
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1384
-				return false;
1452
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1453
+							return false;
1454
+			}
1385 1455
 			// Send the username and password, encoded.
1386
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1387
-				return false;
1456
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1457
+							return false;
1458
+			}
1388 1459
 			// The password is already encoded ;)
1389
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1390
-				return false;
1460
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1461
+							return false;
1462
+			}
1463
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1464
+					return false;
1391 1465
 		}
1392
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1393
-			return false;
1394
-	}
1395
-	else
1466
+	} else
1396 1467
 	{
1397 1468
 		// Just say "helo".
1398
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1399
-			return false;
1469
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1470
+					return false;
1471
+		}
1400 1472
 	}
1401 1473
 
1402 1474
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1409,31 +1481,38 @@  discard block
 block discarded – undo
1409 1481
 		// Reset the connection to send another email.
1410 1482
 		if ($i != 0)
1411 1483
 		{
1412
-			if (!server_parse('RSET', $socket, '250'))
1413
-				return false;
1484
+			if (!server_parse('RSET', $socket, '250')) {
1485
+							return false;
1486
+			}
1414 1487
 		}
1415 1488
 
1416 1489
 		// From, to, and then start the data...
1417
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1418
-			return false;
1419
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1420
-			return false;
1421
-		if (!server_parse('DATA', $socket, '354'))
1422
-			return false;
1490
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1491
+					return false;
1492
+		}
1493
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1494
+					return false;
1495
+		}
1496
+		if (!server_parse('DATA', $socket, '354')) {
1497
+					return false;
1498
+		}
1423 1499
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1424
-		if (strlen($mail_to) > 0)
1425
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1500
+		if (strlen($mail_to) > 0) {
1501
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1502
+		}
1426 1503
 		fputs($socket, $headers . "\r\n\r\n");
1427 1504
 		fputs($socket, $message . "\r\n");
1428 1505
 
1429 1506
 		// Send a ., or in other words "end of data".
1430
-		if (!server_parse('.', $socket, '250'))
1431
-			return false;
1507
+		if (!server_parse('.', $socket, '250')) {
1508
+					return false;
1509
+		}
1432 1510
 
1433 1511
 		// Almost done, almost done... don't stop me just yet!
1434 1512
 		@set_time_limit(300);
1435
-		if (function_exists('apache_reset_timeout'))
1436
-			@apache_reset_timeout();
1513
+		if (function_exists('apache_reset_timeout')) {
1514
+					@apache_reset_timeout();
1515
+		}
1437 1516
 	}
1438 1517
 	fputs($socket, 'QUIT' . "\r\n");
1439 1518
 	fclose($socket);
@@ -1457,8 +1536,9 @@  discard block
 block discarded – undo
1457 1536
 {
1458 1537
 	global $txt;
1459 1538
 
1460
-	if ($message !== null)
1461
-		fputs($socket, $message . "\r\n");
1539
+	if ($message !== null) {
1540
+			fputs($socket, $message . "\r\n");
1541
+	}
1462 1542
 
1463 1543
 	// No response yet.
1464 1544
 	$server_response = '';
@@ -1474,8 +1554,9 @@  discard block
 block discarded – undo
1474 1554
 		$response .= $server_response;
1475 1555
 	}
1476 1556
 
1477
-	if ($code === null)
1478
-		return substr($server_response, 0, 3);
1557
+	if ($code === null) {
1558
+			return substr($server_response, 0, 3);
1559
+	}
1479 1560
 
1480 1561
 	if (substr($server_response, 0, 3) != $code)
1481 1562
 	{
@@ -1505,8 +1586,9 @@  discard block
 block discarded – undo
1505 1586
 	// Create a pspell or enchant dictionary resource
1506 1587
 	$dict = spell_init();
1507 1588
 
1508
-	if (!isset($_POST['spellstring']) || !$dict)
1509
-		die;
1589
+	if (!isset($_POST['spellstring']) || !$dict) {
1590
+			die;
1591
+	}
1510 1592
 
1511 1593
 	// Construct a bit of Javascript code.
1512 1594
 	$context['spell_js'] = '
@@ -1524,8 +1606,9 @@  discard block
 block discarded – undo
1524 1606
 		$check_word = explode('|', $alphas[$i]);
1525 1607
 
1526 1608
 		// If the word is a known word, or spelled right...
1527
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1528
-			continue;
1609
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1610
+					continue;
1611
+		}
1529 1612
 
1530 1613
 		// Find the word, and move up the "last occurrence" to here.
1531 1614
 		$found_words = true;
@@ -1539,20 +1622,23 @@  discard block
 block discarded – undo
1539 1622
 		if (!empty($suggestions))
1540 1623
 		{
1541 1624
 			// But first check they aren't going to be censored - no naughty words!
1542
-			foreach ($suggestions as $k => $word)
1543
-				if ($suggestions[$k] != censorText($word))
1625
+			foreach ($suggestions as $k => $word) {
1626
+							if ($suggestions[$k] != censorText($word))
1544 1627
 					unset($suggestions[$k]);
1628
+			}
1545 1629
 
1546
-			if (!empty($suggestions))
1547
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1630
+			if (!empty($suggestions)) {
1631
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1632
+			}
1548 1633
 		}
1549 1634
 
1550 1635
 		$context['spell_js'] .= ']),';
1551 1636
 	}
1552 1637
 
1553 1638
 	// If words were found, take off the last comma.
1554
-	if ($found_words)
1555
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1639
+	if ($found_words) {
1640
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1641
+	}
1556 1642
 
1557 1643
 	$context['spell_js'] .= '
1558 1644
 		);';
@@ -1587,11 +1673,13 @@  discard block
 block discarded – undo
1587 1673
 	global $user_info, $smcFunc;
1588 1674
 
1589 1675
 	// Can't do it if there's no topics.
1590
-	if (empty($topics))
1591
-		return;
1676
+	if (empty($topics)) {
1677
+			return;
1678
+	}
1592 1679
 	// It must be an array - it must!
1593
-	if (!is_array($topics))
1594
-		$topics = array($topics);
1680
+	if (!is_array($topics)) {
1681
+			$topics = array($topics);
1682
+	}
1595 1683
 
1596 1684
 	// Get the subject and body...
1597 1685
 	$result = $smcFunc['db_query']('', '
@@ -1639,14 +1727,15 @@  discard block
 block discarded – undo
1639 1727
 	}
1640 1728
 	$smcFunc['db_free_result']($result);
1641 1729
 
1642
-	if (!empty($task_rows))
1643
-		$smcFunc['db_insert']('',
1730
+	if (!empty($task_rows)) {
1731
+			$smcFunc['db_insert']('',
1644 1732
 			'{db_prefix}background_tasks',
1645 1733
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1646 1734
 			$task_rows,
1647 1735
 			array('id_task')
1648 1736
 		);
1649
-}
1737
+	}
1738
+	}
1650 1739
 
1651 1740
 /**
1652 1741
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1684,9 +1773,9 @@  discard block
 block discarded – undo
1684 1773
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1685 1774
 
1686 1775
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1687
-	if (!$modSettings['postmod_active'])
1688
-		$topicOptions['is_approved'] = true;
1689
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1776
+	if (!$modSettings['postmod_active']) {
1777
+			$topicOptions['is_approved'] = true;
1778
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1690 1779
 	{
1691 1780
 		$request = $smcFunc['db_query']('', '
1692 1781
 			SELECT approved
@@ -1709,8 +1798,7 @@  discard block
 block discarded – undo
1709 1798
 			$posterOptions['id'] = 0;
1710 1799
 			$posterOptions['name'] = $txt['guest_title'];
1711 1800
 			$posterOptions['email'] = '';
1712
-		}
1713
-		elseif ($posterOptions['id'] != $user_info['id'])
1801
+		} elseif ($posterOptions['id'] != $user_info['id'])
1714 1802
 		{
1715 1803
 			$request = $smcFunc['db_query']('', '
1716 1804
 				SELECT member_name, email_address
@@ -1728,12 +1816,11 @@  discard block
 block discarded – undo
1728 1816
 				$posterOptions['id'] = 0;
1729 1817
 				$posterOptions['name'] = $txt['guest_title'];
1730 1818
 				$posterOptions['email'] = '';
1819
+			} else {
1820
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1731 1821
 			}
1732
-			else
1733
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1734 1822
 			$smcFunc['db_free_result']($request);
1735
-		}
1736
-		else
1823
+		} else
1737 1824
 		{
1738 1825
 			$posterOptions['name'] = $user_info['name'];
1739 1826
 			$posterOptions['email'] = $user_info['email'];
@@ -1743,8 +1830,9 @@  discard block
 block discarded – undo
1743 1830
 	if (!empty($modSettings['enable_mentions']))
1744 1831
 	{
1745 1832
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1746
-		if (!empty($msgOptions['mentioned_members']))
1747
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1833
+		if (!empty($msgOptions['mentioned_members'])) {
1834
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1835
+		}
1748 1836
 	}
1749 1837
 
1750 1838
 	// It's do or die time: forget any user aborts!
@@ -1777,12 +1865,13 @@  discard block
 block discarded – undo
1777 1865
 	$msgOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}messages', 'id_msg');
1778 1866
 
1779 1867
 	// Something went wrong creating the message...
1780
-	if (empty($msgOptions['id']))
1781
-		return false;
1868
+	if (empty($msgOptions['id'])) {
1869
+			return false;
1870
+	}
1782 1871
 
1783 1872
 	// Fix the attachments.
1784
-	if (!empty($msgOptions['attachments']))
1785
-		$smcFunc['db_query']('', '
1873
+	if (!empty($msgOptions['attachments'])) {
1874
+			$smcFunc['db_query']('', '
1786 1875
 			UPDATE {db_prefix}attachments
1787 1876
 			SET id_msg = {int:id_msg}
1788 1877
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1791,6 +1880,7 @@  discard block
 block discarded – undo
1791 1880
 				'id_msg' => $msgOptions['id'],
1792 1881
 			)
1793 1882
 		);
1883
+	}
1794 1884
 
1795 1885
 	// What if we want to export new posts out to a CMS?
1796 1886
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1868,20 +1958,23 @@  discard block
 block discarded – undo
1868 1958
 			'counter_increment' => 1,
1869 1959
 		);
1870 1960
 		$topics_columns = array();
1871
-		if ($msgOptions['approved'])
1872
-			$topics_columns = array(
1961
+		if ($msgOptions['approved']) {
1962
+					$topics_columns = array(
1873 1963
 				'id_member_updated = {int:poster_id}',
1874 1964
 				'id_last_msg = {int:id_msg}',
1875 1965
 				'num_replies = num_replies + {int:counter_increment}',
1876 1966
 			);
1877
-		else
1878
-			$topics_columns = array(
1967
+		} else {
1968
+					$topics_columns = array(
1879 1969
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1880 1970
 			);
1881
-		if ($topicOptions['lock_mode'] !== null)
1882
-			$topics_columns[] = 'locked = {int:locked}';
1883
-		if ($topicOptions['sticky_mode'] !== null)
1884
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1971
+		}
1972
+		if ($topicOptions['lock_mode'] !== null) {
1973
+					$topics_columns[] = 'locked = {int:locked}';
1974
+		}
1975
+		if ($topicOptions['sticky_mode'] !== null) {
1976
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1977
+		}
1885 1978
 
1886 1979
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1887 1980
 
@@ -1910,8 +2003,8 @@  discard block
 block discarded – undo
1910 2003
 	);
1911 2004
 
1912 2005
 	// Increase the number of posts and topics on the board.
1913
-	if ($msgOptions['approved'])
1914
-		$smcFunc['db_query']('', '
2006
+	if ($msgOptions['approved']) {
2007
+			$smcFunc['db_query']('', '
1915 2008
 			UPDATE {db_prefix}boards
1916 2009
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1917 2010
 			WHERE id_board = {int:id_board}',
@@ -1919,7 +2012,7 @@  discard block
 block discarded – undo
1919 2012
 				'id_board' => $topicOptions['board'],
1920 2013
 			)
1921 2014
 		);
1922
-	else
2015
+	} else
1923 2016
 	{
1924 2017
 		$smcFunc['db_query']('', '
1925 2018
 			UPDATE {db_prefix}boards
@@ -1989,8 +2082,8 @@  discard block
 block discarded – undo
1989 2082
 		}
1990 2083
 	}
1991 2084
 
1992
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1993
-		$smcFunc['db_insert']('',
2085
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2086
+			$smcFunc['db_insert']('',
1994 2087
 			'{db_prefix}background_tasks',
1995 2088
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1996 2089
 			array(
@@ -2002,19 +2095,22 @@  discard block
 block discarded – undo
2002 2095
 			),
2003 2096
 			array('id_task')
2004 2097
 		);
2098
+	}
2005 2099
 
2006 2100
 	// If there's a custom search index, it may need updating...
2007 2101
 	require_once($sourcedir . '/Search.php');
2008 2102
 	$searchAPI = findSearchAPI();
2009
-	if (is_callable(array($searchAPI, 'postCreated')))
2010
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2103
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2104
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2105
+	}
2011 2106
 
2012 2107
 	// Increase the post counter for the user that created the post.
2013 2108
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2014 2109
 	{
2015 2110
 		// Are you the one that happened to create this post?
2016
-		if ($user_info['id'] == $posterOptions['id'])
2017
-			$user_info['posts']++;
2111
+		if ($user_info['id'] == $posterOptions['id']) {
2112
+					$user_info['posts']++;
2113
+		}
2018 2114
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2019 2115
 	}
2020 2116
 
@@ -2022,19 +2118,21 @@  discard block
 block discarded – undo
2022 2118
 	$_SESSION['last_read_topic'] = 0;
2023 2119
 
2024 2120
 	// Better safe than sorry.
2025
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2026
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2121
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2122
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2123
+	}
2027 2124
 
2028 2125
 	// Update all the stats so everyone knows about this new topic and message.
2029 2126
 	updateStats('message', true, $msgOptions['id']);
2030 2127
 
2031 2128
 	// Update the last message on the board assuming it's approved AND the topic is.
2032
-	if ($msgOptions['approved'])
2033
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2129
+	if ($msgOptions['approved']) {
2130
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2131
+	}
2034 2132
 
2035 2133
 	// Queue createPost background notification
2036
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2037
-		$smcFunc['db_insert']('',
2134
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2135
+			$smcFunc['db_insert']('',
2038 2136
 			'{db_prefix}background_tasks',
2039 2137
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2040 2138
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array(
@@ -2045,6 +2143,7 @@  discard block
 block discarded – undo
2045 2143
 			)), 0),
2046 2144
 			array('id_task')
2047 2145
 		);
2146
+	}
2048 2147
 
2049 2148
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2050 2149
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2071,14 +2170,18 @@  discard block
 block discarded – undo
2071 2170
 
2072 2171
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2073 2172
 	$messages_columns = array();
2074
-	if (isset($posterOptions['name']))
2075
-		$messages_columns['poster_name'] = $posterOptions['name'];
2076
-	if (isset($posterOptions['email']))
2077
-		$messages_columns['poster_email'] = $posterOptions['email'];
2078
-	if (isset($msgOptions['icon']))
2079
-		$messages_columns['icon'] = $msgOptions['icon'];
2080
-	if (isset($msgOptions['subject']))
2081
-		$messages_columns['subject'] = $msgOptions['subject'];
2173
+	if (isset($posterOptions['name'])) {
2174
+			$messages_columns['poster_name'] = $posterOptions['name'];
2175
+	}
2176
+	if (isset($posterOptions['email'])) {
2177
+			$messages_columns['poster_email'] = $posterOptions['email'];
2178
+	}
2179
+	if (isset($msgOptions['icon'])) {
2180
+			$messages_columns['icon'] = $msgOptions['icon'];
2181
+	}
2182
+	if (isset($msgOptions['subject'])) {
2183
+			$messages_columns['subject'] = $msgOptions['subject'];
2184
+	}
2082 2185
 	if (isset($msgOptions['body']))
2083 2186
 	{
2084 2187
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2105,8 +2208,9 @@  discard block
 block discarded – undo
2105 2208
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2106 2209
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2107 2210
 	}
2108
-	if (isset($msgOptions['smileys_enabled']))
2109
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2211
+	if (isset($msgOptions['smileys_enabled'])) {
2212
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2213
+	}
2110 2214
 
2111 2215
 	// Which columns need to be ints?
2112 2216
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2124,23 +2228,27 @@  discard block
 block discarded – undo
2124 2228
 		{
2125 2229
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2126 2230
 
2127
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2128
-				foreach ($match[1] as $i => $oldID)
2231
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2232
+							foreach ($match[1] as $i => $oldID)
2129 2233
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2234
+			}
2130 2235
 
2131
-			if (empty($modSettings['search_custom_index_config']))
2132
-				unset($msgOptions['old_body']);
2236
+			if (empty($modSettings['search_custom_index_config'])) {
2237
+							unset($msgOptions['old_body']);
2238
+			}
2133 2239
 		}
2134 2240
 
2135 2241
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2136 2242
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2137 2243
 
2138 2244
 		// Remove the poster.
2139
-		if (isset($mentions[$user_info['id']]))
2140
-			unset($mentions[$user_info['id']]);
2245
+		if (isset($mentions[$user_info['id']])) {
2246
+					unset($mentions[$user_info['id']]);
2247
+		}
2141 2248
 
2142
-		if (isset($oldmentions[$user_info['id']]))
2143
-			unset($oldmentions[$user_info['id']]);
2249
+		if (isset($oldmentions[$user_info['id']])) {
2250
+					unset($oldmentions[$user_info['id']]);
2251
+		}
2144 2252
 
2145 2253
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2146 2254
 		{
@@ -2170,8 +2278,9 @@  discard block
 block discarded – undo
2170 2278
 	}
2171 2279
 
2172 2280
 	// Nothing to do?
2173
-	if (empty($messages_columns))
2174
-		return true;
2281
+	if (empty($messages_columns)) {
2282
+			return true;
2283
+	}
2175 2284
 
2176 2285
 	// Change the post.
2177 2286
 	$smcFunc['db_query']('', '
@@ -2232,8 +2341,9 @@  discard block
 block discarded – undo
2232 2341
 	// If there's a custom search index, it needs to be modified...
2233 2342
 	require_once($sourcedir . '/Search.php');
2234 2343
 	$searchAPI = findSearchAPI();
2235
-	if (is_callable(array($searchAPI, 'postModified')))
2236
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2344
+	if (is_callable(array($searchAPI, 'postModified'))) {
2345
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2346
+	}
2237 2347
 
2238 2348
 	if (isset($msgOptions['subject']))
2239 2349
 	{
@@ -2247,14 +2357,16 @@  discard block
 block discarded – undo
2247 2357
 				'id_first_msg' => $msgOptions['id'],
2248 2358
 			)
2249 2359
 		);
2250
-		if ($smcFunc['db_num_rows']($request) == 1)
2251
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2360
+		if ($smcFunc['db_num_rows']($request) == 1) {
2361
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2362
+		}
2252 2363
 		$smcFunc['db_free_result']($request);
2253 2364
 	}
2254 2365
 
2255 2366
 	// Finally, if we are setting the approved state we need to do much more work :(
2256
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2257
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2367
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2368
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2369
+	}
2258 2370
 
2259 2371
 	return true;
2260 2372
 }
@@ -2271,11 +2383,13 @@  discard block
 block discarded – undo
2271 2383
 {
2272 2384
 	global $smcFunc;
2273 2385
 
2274
-	if (!is_array($msgs))
2275
-		$msgs = array($msgs);
2386
+	if (!is_array($msgs)) {
2387
+			$msgs = array($msgs);
2388
+	}
2276 2389
 
2277
-	if (empty($msgs))
2278
-		return false;
2390
+	if (empty($msgs)) {
2391
+			return false;
2392
+	}
2279 2393
 
2280 2394
 	// May as well start at the beginning, working out *what* we need to change.
2281 2395
 	$request = $smcFunc['db_query']('', '
@@ -2307,20 +2421,22 @@  discard block
 block discarded – undo
2307 2421
 		$topics[] = $row['id_topic'];
2308 2422
 
2309 2423
 		// Ensure our change array exists already.
2310
-		if (!isset($topic_changes[$row['id_topic']]))
2311
-			$topic_changes[$row['id_topic']] = array(
2424
+		if (!isset($topic_changes[$row['id_topic']])) {
2425
+					$topic_changes[$row['id_topic']] = array(
2312 2426
 				'id_last_msg' => $row['id_last_msg'],
2313 2427
 				'approved' => $row['topic_approved'],
2314 2428
 				'replies' => 0,
2315 2429
 				'unapproved_posts' => 0,
2316 2430
 			);
2317
-		if (!isset($board_changes[$row['id_board']]))
2318
-			$board_changes[$row['id_board']] = array(
2431
+		}
2432
+		if (!isset($board_changes[$row['id_board']])) {
2433
+					$board_changes[$row['id_board']] = array(
2319 2434
 				'posts' => 0,
2320 2435
 				'topics' => 0,
2321 2436
 				'unapproved_posts' => 0,
2322 2437
 				'unapproved_topics' => 0,
2323 2438
 			);
2439
+		}
2324 2440
 
2325 2441
 		// If it's the first message then the topic state changes!
2326 2442
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2341,14 +2457,13 @@  discard block
 block discarded – undo
2341 2457
 				'poster' => $row['id_member'],
2342 2458
 				'new_topic' => true,
2343 2459
 			);
2344
-		}
2345
-		else
2460
+		} else
2346 2461
 		{
2347 2462
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2348 2463
 
2349 2464
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2350
-			if ($row['id_msg'] > $row['id_last_msg'])
2351
-				$notification_posts[$row['id_topic']] = array(
2465
+			if ($row['id_msg'] > $row['id_last_msg']) {
2466
+							$notification_posts[$row['id_topic']] = array(
2352 2467
 					'id' => $row['id_msg'],
2353 2468
 					'body' => $row['body'],
2354 2469
 					'subject' => $row['subject'],
@@ -2359,28 +2474,33 @@  discard block
 block discarded – undo
2359 2474
 					'new_topic' => false,
2360 2475
 					'msg' => $row['id_msg'],
2361 2476
 				);
2477
+			}
2362 2478
 		}
2363 2479
 
2364 2480
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2365
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2366
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2481
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2482
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2483
+		}
2367 2484
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2368
-		elseif (!$approve)
2369
-			// Default to the first message and then we'll override in a bit ;)
2485
+		elseif (!$approve) {
2486
+					// Default to the first message and then we'll override in a bit ;)
2370 2487
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2488
+		}
2371 2489
 
2372 2490
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2373 2491
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2374 2492
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2375 2493
 
2376 2494
 		// Post count for the user?
2377
-		if ($row['id_member'] && empty($row['count_posts']))
2378
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2495
+		if ($row['id_member'] && empty($row['count_posts'])) {
2496
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2497
+		}
2379 2498
 	}
2380 2499
 	$smcFunc['db_free_result']($request);
2381 2500
 
2382
-	if (empty($msgs))
2383
-		return;
2501
+	if (empty($msgs)) {
2502
+			return;
2503
+	}
2384 2504
 
2385 2505
 	// Now we have the differences make the changes, first the easy one.
2386 2506
 	$smcFunc['db_query']('', '
@@ -2407,14 +2527,15 @@  discard block
 block discarded – undo
2407 2527
 				'approved' => 1,
2408 2528
 			)
2409 2529
 		);
2410
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2411
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2530
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2531
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2532
+		}
2412 2533
 		$smcFunc['db_free_result']($request);
2413 2534
 	}
2414 2535
 
2415 2536
 	// ... next the topics...
2416
-	foreach ($topic_changes as $id => $changes)
2417
-		$smcFunc['db_query']('', '
2537
+	foreach ($topic_changes as $id => $changes) {
2538
+			$smcFunc['db_query']('', '
2418 2539
 			UPDATE {db_prefix}topics
2419 2540
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2420 2541
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2427,10 +2548,11 @@  discard block
 block discarded – undo
2427 2548
 				'id_topic' => $id,
2428 2549
 			)
2429 2550
 		);
2551
+	}
2430 2552
 
2431 2553
 	// ... finally the boards...
2432
-	foreach ($board_changes as $id => $changes)
2433
-		$smcFunc['db_query']('', '
2554
+	foreach ($board_changes as $id => $changes) {
2555
+			$smcFunc['db_query']('', '
2434 2556
 			UPDATE {db_prefix}boards
2435 2557
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2436 2558
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2443,13 +2565,14 @@  discard block
 block discarded – undo
2443 2565
 				'id_board' => $id,
2444 2566
 			)
2445 2567
 		);
2568
+	}
2446 2569
 
2447 2570
 	// Finally, least importantly, notifications!
2448 2571
 	if ($approve)
2449 2572
 	{
2450 2573
 		$task_rows = array();
2451
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2452
-			$task_rows[] = array(
2574
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2575
+					$task_rows[] = array(
2453 2576
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array(
2454 2577
 					'msgOptions' => array(
2455 2578
 						'id' => $topic['msg'],
@@ -2467,14 +2590,16 @@  discard block
 block discarded – undo
2467 2590
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2468 2591
 				)), 0
2469 2592
 			);
2593
+		}
2470 2594
 
2471
-		if ($notify)
2472
-			$smcFunc['db_insert']('',
2595
+		if ($notify) {
2596
+					$smcFunc['db_insert']('',
2473 2597
 				'{db_prefix}background_tasks',
2474 2598
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2475 2599
 				$task_rows,
2476 2600
 				array('id_task')
2477 2601
 			);
2602
+		}
2478 2603
 
2479 2604
 		$smcFunc['db_query']('', '
2480 2605
 			DELETE FROM {db_prefix}approval_queue
@@ -2490,8 +2615,9 @@  discard block
 block discarded – undo
2490 2615
 	else
2491 2616
 	{
2492 2617
 		$msgInserts = array();
2493
-		foreach ($msgs as $msg)
2494
-			$msgInserts[] = array($msg);
2618
+		foreach ($msgs as $msg) {
2619
+					$msgInserts[] = array($msg);
2620
+		}
2495 2621
 
2496 2622
 		$smcFunc['db_insert']('ignore',
2497 2623
 			'{db_prefix}approval_queue',
@@ -2505,9 +2631,10 @@  discard block
 block discarded – undo
2505 2631
 	updateLastMessages(array_keys($board_changes));
2506 2632
 
2507 2633
 	// Post count for the members?
2508
-	if (!empty($member_post_changes))
2509
-		foreach ($member_post_changes as $id_member => $count_change)
2634
+	if (!empty($member_post_changes)) {
2635
+			foreach ($member_post_changes as $id_member => $count_change)
2510 2636
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2637
+	}
2511 2638
 
2512 2639
 	return true;
2513 2640
 }
@@ -2524,11 +2651,13 @@  discard block
 block discarded – undo
2524 2651
 {
2525 2652
 	global $smcFunc;
2526 2653
 
2527
-	if (!is_array($topics))
2528
-		$topics = array($topics);
2654
+	if (!is_array($topics)) {
2655
+			$topics = array($topics);
2656
+	}
2529 2657
 
2530
-	if (empty($topics))
2531
-		return false;
2658
+	if (empty($topics)) {
2659
+			return false;
2660
+	}
2532 2661
 
2533 2662
 	$approve_type = $approve ? 0 : 1;
2534 2663
 
@@ -2544,8 +2673,9 @@  discard block
 block discarded – undo
2544 2673
 		)
2545 2674
 	);
2546 2675
 	$msgs = array();
2547
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2548
-		$msgs[] = $row['id_msg'];
2676
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2677
+			$msgs[] = $row['id_msg'];
2678
+	}
2549 2679
 	$smcFunc['db_free_result']($request);
2550 2680
 
2551 2681
 	return approvePosts($msgs, $approve);
@@ -2568,11 +2698,13 @@  discard block
 block discarded – undo
2568 2698
 	global $board_info, $board, $smcFunc;
2569 2699
 
2570 2700
 	// Please - let's be sane.
2571
-	if (empty($setboards))
2572
-		return false;
2701
+	if (empty($setboards)) {
2702
+			return false;
2703
+	}
2573 2704
 
2574
-	if (!is_array($setboards))
2575
-		$setboards = array($setboards);
2705
+	if (!is_array($setboards)) {
2706
+			$setboards = array($setboards);
2707
+	}
2576 2708
 
2577 2709
 	// If we don't know the id_msg we need to find it.
2578 2710
 	if (!$id_msg)
@@ -2590,15 +2722,16 @@  discard block
 block discarded – undo
2590 2722
 			)
2591 2723
 		);
2592 2724
 		$lastMsg = array();
2593
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2594
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2725
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2726
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2727
+		}
2595 2728
 		$smcFunc['db_free_result']($request);
2596
-	}
2597
-	else
2729
+	} else
2598 2730
 	{
2599 2731
 		// Just to note - there should only be one board passed if we are doing this.
2600
-		foreach ($setboards as $id_board)
2601
-			$lastMsg[$id_board] = $id_msg;
2732
+		foreach ($setboards as $id_board) {
2733
+					$lastMsg[$id_board] = $id_msg;
2734
+		}
2602 2735
 	}
2603 2736
 
2604 2737
 	$parent_boards = array();
@@ -2613,10 +2746,11 @@  discard block
 block discarded – undo
2613 2746
 			$lastModified[$id_board] = 0;
2614 2747
 		}
2615 2748
 
2616
-		if (!empty($board) && $id_board == $board)
2617
-			$parents = $board_info['parent_boards'];
2618
-		else
2619
-			$parents = getBoardParents($id_board);
2749
+		if (!empty($board) && $id_board == $board) {
2750
+					$parents = $board_info['parent_boards'];
2751
+		} else {
2752
+					$parents = getBoardParents($id_board);
2753
+		}
2620 2754
 
2621 2755
 		// Ignore any parents on the top child level.
2622 2756
 		// @todo Why?
@@ -2625,10 +2759,11 @@  discard block
 block discarded – undo
2625 2759
 			if ($parent['level'] != 0)
2626 2760
 			{
2627 2761
 				// If we're already doing this one as a board, is this a higher last modified?
2628
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2629
-					$lastModified[$id] = $lastModified[$id_board];
2630
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2631
-					$parent_boards[$id] = $lastModified[$id_board];
2762
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2763
+									$lastModified[$id] = $lastModified[$id_board];
2764
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2765
+									$parent_boards[$id] = $lastModified[$id_board];
2766
+				}
2632 2767
 			}
2633 2768
 		}
2634 2769
 	}
@@ -2641,23 +2776,24 @@  discard block
 block discarded – undo
2641 2776
 	// Finally, to save on queries make the changes...
2642 2777
 	foreach ($parent_boards as $id => $msg)
2643 2778
 	{
2644
-		if (!isset($parent_updates[$msg]))
2645
-			$parent_updates[$msg] = array($id);
2646
-		else
2647
-			$parent_updates[$msg][] = $id;
2779
+		if (!isset($parent_updates[$msg])) {
2780
+					$parent_updates[$msg] = array($id);
2781
+		} else {
2782
+					$parent_updates[$msg][] = $id;
2783
+		}
2648 2784
 	}
2649 2785
 
2650 2786
 	foreach ($lastMsg as $id => $msg)
2651 2787
 	{
2652
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2653
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2788
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2789
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2654 2790
 				'id' => $msg,
2655 2791
 				'updated' => $lastModified[$id],
2656 2792
 				'boards' => array($id)
2657 2793
 			);
2658
-
2659
-		else
2660
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2794
+		} else {
2795
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2796
+		}
2661 2797
 	}
2662 2798
 
2663 2799
 	// Now commit the changes!
@@ -2749,11 +2885,13 @@  discard block
 block discarded – undo
2749 2885
 	global $txt, $mbname, $scripturl, $settings;
2750 2886
 
2751 2887
 	// First things first, load up the email templates language file, if we need to.
2752
-	if ($loadLang)
2753
-		loadLanguage('EmailTemplates', $lang);
2888
+	if ($loadLang) {
2889
+			loadLanguage('EmailTemplates', $lang);
2890
+	}
2754 2891
 
2755
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2756
-		fatal_lang_error('email_no_template', 'template', array($template));
2892
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2893
+			fatal_lang_error('email_no_template', 'template', array($template));
2894
+	}
2757 2895
 
2758 2896
 	$ret = array(
2759 2897
 		'subject' => $txt[$template . '_subject'],
@@ -2803,17 +2941,18 @@  discard block
 block discarded – undo
2803 2941
 function user_info_callback($matches)
2804 2942
 {
2805 2943
 	global $user_info;
2806
-	if (empty($matches[1]))
2807
-		return '';
2944
+	if (empty($matches[1])) {
2945
+			return '';
2946
+	}
2808 2947
 
2809 2948
 	$use_ref = true;
2810 2949
 	$ref = &$user_info;
2811 2950
 
2812 2951
 	foreach (explode('.', $matches[1]) as $index)
2813 2952
 	{
2814
-		if ($use_ref && isset($ref[$index]))
2815
-			$ref = &$ref[$index];
2816
-		else
2953
+		if ($use_ref && isset($ref[$index])) {
2954
+					$ref = &$ref[$index];
2955
+		} else
2817 2956
 		{
2818 2957
 			$use_ref = false;
2819 2958
 			break;
@@ -2850,8 +2989,7 @@  discard block
 block discarded – undo
2850 2989
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2851 2990
 		{
2852 2991
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2853
-		}
2854
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2992
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2855 2993
 		{
2856 2994
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2857 2995
 		}
@@ -2861,8 +2999,7 @@  discard block
 block discarded – undo
2861 2999
 		{
2862 3000
 			$context['provider'] = 'enchant';
2863 3001
 			return $enchant_link;
2864
-		}
2865
-		else
3002
+		} else
2866 3003
 		{
2867 3004
 			// Free up any resources used...
2868 3005
 			@enchant_broker_free($context['enchant_broker']);
@@ -2883,8 +3020,9 @@  discard block
 block discarded – undo
2883 3020
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2884 3021
 
2885 3022
 		// Most people don't have anything but English installed... So we use English as a last resort.
2886
-		if (!$pspell_link)
2887
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3023
+		if (!$pspell_link) {
3024
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3025
+		}
2888 3026
 
2889 3027
 		error_reporting($old);
2890 3028
 		ob_end_clean();
@@ -2924,8 +3062,7 @@  discard block
 block discarded – undo
2924 3062
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2925 3063
 		}
2926 3064
 		return enchant_dict_check($dict, $word);
2927
-	}
2928
-	elseif ($context['provider'] == 'pspell')
3065
+	} elseif ($context['provider'] == 'pspell')
2929 3066
 	{
2930 3067
 		return pspell_check($dict, $word);
2931 3068
 	}
@@ -2961,13 +3098,11 @@  discard block
 block discarded – undo
2961 3098
 			}
2962 3099
 
2963 3100
 			return $suggestions;
2964
-		}
2965
-		else
3101
+		} else
2966 3102
 		{
2967 3103
 			return enchant_dict_suggest($dict, $word);
2968 3104
 		}
2969
-	}
2970
-	elseif ($context['provider'] == 'pspell')
3105
+	} elseif ($context['provider'] == 'pspell')
2971 3106
 	{
2972 3107
 		return pspell_suggest($dict, $word);
2973 3108
 	}
Please login to merge, or discard this patch.