Completed
Branch release-2.1 (4c82a0)
by Rick
15:44
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 3 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.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 	// This ensures you can't search someones email address if you can't see it.
394 394
 	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
395 395
 		$email_condition = '
396
-			OR (email_address ' . $comparison . ' \'' . implode( '\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
396
+			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
397 397
 	else
398 398
 		$email_condition = '';
399 399
 
@@ -412,8 +412,8 @@  discard block
 block discarded – undo
412 412
 		LIMIT {int:limit}',
413 413
 		array(
414 414
 			'buddy_list' => $user_info['buddies'],
415
-			'member_name_search' => $member_name . ' ' . $comparison . ' \'' . implode( '\' OR ' . $member_name . ' ' . $comparison . ' \'', $names) . '\'',
416
-			'real_name_search' => $real_name . ' ' . $comparison . ' \'' . implode( '\' OR ' . $real_name . ' ' . $comparison . ' \'', $names) . '\'',
415
+			'member_name_search' => $member_name . ' ' . $comparison . ' \'' . implode('\' OR ' . $member_name . ' ' . $comparison . ' \'', $names) . '\'',
416
+			'real_name_search' => $real_name . ' ' . $comparison . ' \'' . implode('\' OR ' . $real_name . ' ' . $comparison . ' \'', $names) . '\'',
417 417
 			'email_condition' => $email_condition,
418 418
 			'limit' => $max,
419 419
 		)
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 = json_decode($_COOKIE[$cookiename], true);
44 45
 
45 46
 		// Legacy format
46
-		if (is_null($array))
47
-			$array = @unserialize($_COOKIE[$cookiename]);
47
+		if (is_null($array)) {
48
+					$array = @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
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
  * Backtrace, log, try to fix.
531 531
  *
532 532
  * @param string $db_string The DB string
533
- * @param object $connection The connection to use (if null, $db_connection is used)
533
+ * @param resource $connection The connection to use (if null, $db_connection is used)
534 534
  */
535 535
 function smf_db_error($db_string, $connection = null)
536 536
 {
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
  * @param array $data The data to insert
726 726
  * @param array $keys The keys for the table
727 727
  * @param bool $disable_trans Whether to disable transactions
728
- * @param object $connection The connection to use (if null, $db_connection is used)
728
+ * @param resource $connection The connection to use (if null, $db_connection is used)
729 729
  */
730 730
 function smf_db_insert($method = 'replace', $table, $columns, $data, $keys, $disable_trans = false, $connection = null)
731 731
 {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -840,7 +840,7 @@
 block discarded – undo
840 840
  * @param bool $translate_human_wildcards If true, turns human readable wildcards into SQL wildcards.
841 841
  * @return string The escaped string
842 842
  */
843
-function smf_db_escape_wildcard_string($string, $translate_human_wildcards=false)
843
+function smf_db_escape_wildcard_string($string, $translate_human_wildcards = false)
844 844
 {
845 845
 	$replacements = array(
846 846
 		'%' => '\%',
Please login to merge, or discard this patch.
Braces   +230 added lines, -168 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,34 +59,40 @@  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
-	if (!empty($db_options['port']))
66
-		$connection = @mysqli_connect($db_server, $db_user, $db_passwd, '', $db_options['port']);
67
-	else
68
-		$connection = @mysqli_connect($db_server, $db_user, $db_passwd);
68
+	if (!empty($db_options['port'])) {
69
+			$connection = @mysqli_connect($db_server, $db_user, $db_passwd, '', $db_options['port']);
70
+	} else {
71
+			$connection = @mysqli_connect($db_server, $db_user, $db_passwd);
72
+	}
69 73
 
70 74
 	// Something's wrong, show an error if its fatal (which we assume it is)
71 75
 	if (!$connection)
72 76
 	{
73
-		if (!empty($db_options['non_fatal']))
74
-			return null;
75
-		else
76
-			display_db_error();
77
+		if (!empty($db_options['non_fatal'])) {
78
+					return null;
79
+		} else {
80
+					display_db_error();
81
+		}
77 82
 	}
78 83
 
79 84
 	// Select the database, unless told not to
80
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
81
-		display_db_error();
85
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
86
+			display_db_error();
87
+	}
82 88
 
83 89
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
84
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
85
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
90
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
91
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
86 92
 		array(),
87 93
 		false
88 94
 	);
95
+	}
89 96
 
90 97
 	return $connection;
91 98
 }
@@ -156,37 +163,46 @@  discard block
 block discarded – undo
156 163
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
157 164
 
158 165
 	list ($values, $connection) = $db_callback;
159
-	if (!is_object($connection))
160
-		display_db_error();
166
+	if (!is_object($connection)) {
167
+			display_db_error();
168
+	}
161 169
 
162
-	if ($matches[1] === 'db_prefix')
163
-		return $db_prefix;
170
+	if ($matches[1] === 'db_prefix') {
171
+			return $db_prefix;
172
+	}
164 173
 
165
-	if ($matches[1] === 'query_see_board')
166
-		return $user_info['query_see_board'];
174
+	if ($matches[1] === 'query_see_board') {
175
+			return $user_info['query_see_board'];
176
+	}
167 177
 
168
-	if ($matches[1] === 'query_wanna_see_board')
169
-		return $user_info['query_wanna_see_board'];
178
+	if ($matches[1] === 'query_wanna_see_board') {
179
+			return $user_info['query_wanna_see_board'];
180
+	}
170 181
 
171
-	if ($matches[1] === 'empty')
172
-		return '\'\'';
182
+	if ($matches[1] === 'empty') {
183
+			return '\'\'';
184
+	}
173 185
 
174
-	if (!isset($matches[2]))
175
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
186
+	if (!isset($matches[2])) {
187
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
188
+	}
176 189
 
177
-	if ($matches[1] === 'literal')
178
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
190
+	if ($matches[1] === 'literal') {
191
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
192
+	}
179 193
 
180
-	if (!isset($values[$matches[2]]))
181
-		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__);
194
+	if (!isset($values[$matches[2]])) {
195
+			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__);
196
+	}
182 197
 
183 198
 	$replacement = $values[$matches[2]];
184 199
 
185 200
 	switch ($matches[1])
186 201
 	{
187 202
 		case 'int':
188
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
189
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
203
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
204
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
205
+			}
190 206
 			return (string) (int) $replacement;
191 207
 		break;
192 208
 
@@ -198,49 +214,55 @@  discard block
 block discarded – undo
198 214
 		case 'array_int':
199 215
 			if (is_array($replacement))
200 216
 			{
201
-				if (empty($replacement))
202
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
217
+				if (empty($replacement)) {
218
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
219
+				}
203 220
 
204 221
 				foreach ($replacement as $key => $value)
205 222
 				{
206
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
207
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
224
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+					}
208 226
 
209 227
 					$replacement[$key] = (string) (int) $value;
210 228
 				}
211 229
 
212 230
 				return implode(', ', $replacement);
231
+			} else {
232
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213 233
 			}
214
-			else
215
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
216 234
 
217 235
 		break;
218 236
 
219 237
 		case 'array_string':
220 238
 			if (is_array($replacement))
221 239
 			{
222
-				if (empty($replacement))
223
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240
+				if (empty($replacement)) {
241
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
242
+				}
224 243
 
225
-				foreach ($replacement as $key => $value)
226
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
244
+				foreach ($replacement as $key => $value) {
245
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
246
+				}
227 247
 
228 248
 				return implode(', ', $replacement);
249
+			} else {
250
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229 251
 			}
230
-			else
231
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
232 252
 		break;
233 253
 
234 254
 		case 'date':
235
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
236
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
237
-			else
238
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
256
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
257
+			} else {
258
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
259
+			}
239 260
 		break;
240 261
 
241 262
 		case 'float':
242
-			if (!is_numeric($replacement))
243
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+			if (!is_numeric($replacement)) {
264
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			}
244 266
 			return (string) (float) $replacement;
245 267
 		break;
246 268
 
@@ -254,10 +276,12 @@  discard block
 block discarded – undo
254 276
 		break;
255 277
 
256 278
 		case 'inet':
257
-			if ($replacement == 'null')
258
-				return 'null';
259
-			if (!isValidIP($replacement))
260
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+			if ($replacement == 'null') {
280
+							return 'null';
281
+			}
282
+			if (!isValidIP($replacement)) {
283
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
284
+			}
261 285
 			//we don't use the native support of mysql > 5.6.2
262 286
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
263 287
 		break;
@@ -335,22 +359,25 @@  discard block
 block discarded – undo
335 359
 		// Are we in SSI mode?  If so try that username and password first
336 360
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
337 361
 		{
338
-			if (empty($db_persist))
339
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
340
-			else
341
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
362
+			if (empty($db_persist)) {
363
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
364
+			} else {
365
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
366
+			}
342 367
 		}
343 368
 		// Fall back to the regular username and password if need be
344 369
 		if (!$db_connection)
345 370
 		{
346
-			if (empty($db_persist))
347
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
348
-			else
349
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
371
+			if (empty($db_persist)) {
372
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
373
+			} else {
374
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
375
+			}
350 376
 		}
351 377
 
352
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
353
-			$db_connection = false;
378
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
379
+					$db_connection = false;
380
+		}
354 381
 
355 382
 		$connection = $db_connection;
356 383
 	}
@@ -358,18 +385,20 @@  discard block
 block discarded – undo
358 385
 	// One more query....
359 386
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
360 387
 
361
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
362
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
388
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
389
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
390
+	}
363 391
 
364 392
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
365 393
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
366 394
 	{
367 395
 		// Add before LIMIT
368
-		if ($pos = strpos($db_string, 'LIMIT '))
369
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
370
-		else
371
-			// Append it.
396
+		if ($pos = strpos($db_string, 'LIMIT ')) {
397
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
398
+		} else {
399
+					// Append it.
372 400
 			$db_string .= "\n\t\t\tORDER BY null";
401
+		}
373 402
 	}
374 403
 
375 404
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -391,8 +420,9 @@  discard block
 block discarded – undo
391 420
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
392 421
 
393 422
 		// Initialize $db_cache if not already initialized.
394
-		if (!isset($db_cache))
395
-			$db_cache = array();
423
+		if (!isset($db_cache)) {
424
+					$db_cache = array();
425
+		}
396 426
 
397 427
 		if (!empty($_SESSION['debug_redirect']))
398 428
 		{
@@ -418,17 +448,18 @@  discard block
 block discarded – undo
418 448
 		while (true)
419 449
 		{
420 450
 			$pos = strpos($db_string, '\'', $pos + 1);
421
-			if ($pos === false)
422
-				break;
451
+			if ($pos === false) {
452
+							break;
453
+			}
423 454
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
424 455
 
425 456
 			while (true)
426 457
 			{
427 458
 				$pos1 = strpos($db_string, '\'', $pos + 1);
428 459
 				$pos2 = strpos($db_string, '\\', $pos + 1);
429
-				if ($pos1 === false)
430
-					break;
431
-				elseif ($pos2 == false || $pos2 > $pos1)
460
+				if ($pos1 === false) {
461
+									break;
462
+				} elseif ($pos2 == false || $pos2 > $pos1)
432 463
 				{
433 464
 					$pos = $pos1;
434 465
 					break;
@@ -444,29 +475,35 @@  discard block
 block discarded – undo
444 475
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
445 476
 
446 477
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
447
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
448
-			$fail = true;
478
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
479
+					$fail = true;
480
+		}
449 481
 		// Trying to change passwords, slow us down, or something?
450
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
451
-			$fail = true;
452
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
453
-			$fail = true;
482
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
483
+					$fail = true;
484
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
485
+					$fail = true;
486
+		}
454 487
 
455
-		if (!empty($fail) && function_exists('log_error'))
456
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
488
+		if (!empty($fail) && function_exists('log_error')) {
489
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
490
+		}
457 491
 	}
458 492
 
459
-	if (empty($db_unbuffered))
460
-		$ret = @mysqli_query($connection, $db_string);
461
-	else
462
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
493
+	if (empty($db_unbuffered)) {
494
+			$ret = @mysqli_query($connection, $db_string);
495
+	} else {
496
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
497
+	}
463 498
 
464
-	if ($ret === false && empty($db_values['db_error_skip']))
465
-		$ret = smf_db_error($db_string, $connection);
499
+	if ($ret === false && empty($db_values['db_error_skip'])) {
500
+			$ret = smf_db_error($db_string, $connection);
501
+	}
466 502
 
467 503
 	// Debugging.
468
-	if (isset($db_show_debug) && $db_show_debug === true)
469
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
504
+	if (isset($db_show_debug) && $db_show_debug === true) {
505
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
506
+	}
470 507
 
471 508
 	return $ret;
472 509
 }
@@ -515,12 +552,13 @@  discard block
 block discarded – undo
515 552
 	// Decide which connection to use
516 553
 	$connection = $connection === null ? $db_connection : $connection;
517 554
 
518
-	if ($type == 'begin')
519
-		return @mysqli_query($connection, 'BEGIN');
520
-	elseif ($type == 'rollback')
521
-		return @mysqli_query($connection, 'ROLLBACK');
522
-	elseif ($type == 'commit')
523
-		return @mysqli_query($connection, 'COMMIT');
555
+	if ($type == 'begin') {
556
+			return @mysqli_query($connection, 'BEGIN');
557
+	} elseif ($type == 'rollback') {
558
+			return @mysqli_query($connection, 'ROLLBACK');
559
+	} elseif ($type == 'commit') {
560
+			return @mysqli_query($connection, 'COMMIT');
561
+	}
524 562
 
525 563
 	return false;
526 564
 }
@@ -560,8 +598,9 @@  discard block
 block discarded – undo
560 598
 	//    2013: Lost connection to server during query.
561 599
 
562 600
 	// Log the error.
563
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
564
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
601
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
602
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
603
+	}
565 604
 
566 605
 	// Database error auto fixing ;).
567 606
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -570,8 +609,9 @@  discard block
 block discarded – undo
570 609
 		$old_cache = @$modSettings['cache_enable'];
571 610
 		$modSettings['cache_enable'] = '1';
572 611
 
573
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
574
-			$db_last_error = max(@$db_last_error, $temp);
612
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
613
+					$db_last_error = max(@$db_last_error, $temp);
614
+		}
575 615
 
576 616
 		if (@$db_last_error < time() - 3600 * 24 * 3)
577 617
 		{
@@ -587,8 +627,9 @@  discard block
 block discarded – undo
587 627
 					foreach ($tables as $table)
588 628
 					{
589 629
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
590
-						if (trim($table) != '')
591
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
630
+						if (trim($table) != '') {
631
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
632
+						}
592 633
 					}
593 634
 				}
594 635
 
@@ -597,8 +638,9 @@  discard block
 block discarded – undo
597 638
 			// Table crashed.  Let's try to fix it.
598 639
 			elseif ($query_errno == 1016)
599 640
 			{
600
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
601
-					$fix_tables = array('`' . $match[1] . '`');
641
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
642
+									$fix_tables = array('`' . $match[1] . '`');
643
+				}
602 644
 			}
603 645
 			// Indexes crashed.  Should be easy to fix!
604 646
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -617,13 +659,15 @@  discard block
 block discarded – undo
617 659
 
618 660
 			// Make a note of the REPAIR...
619 661
 			cache_put_data('db_last_error', time(), 600);
620
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
621
-				updateSettingsFile(array('db_last_error' => time()));
662
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
663
+							updateSettingsFile(array('db_last_error' => time()));
664
+			}
622 665
 
623 666
 			// Attempt to find and repair the broken table.
624
-			foreach ($fix_tables as $table)
625
-				$smcFunc['db_query']('', "
667
+			foreach ($fix_tables as $table) {
668
+							$smcFunc['db_query']('', "
626 669
 					REPAIR TABLE $table", false, false);
670
+			}
627 671
 
628 672
 			// And send off an email!
629 673
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -632,11 +676,12 @@  discard block
 block discarded – undo
632 676
 
633 677
 			// Try the query again...?
634 678
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
635
-			if ($ret !== false)
636
-				return $ret;
679
+			if ($ret !== false) {
680
+							return $ret;
681
+			}
682
+		} else {
683
+					$modSettings['cache_enable'] = $old_cache;
637 684
 		}
638
-		else
639
-			$modSettings['cache_enable'] = $old_cache;
640 685
 
641 686
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
642 687
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -646,22 +691,25 @@  discard block
 block discarded – undo
646 691
 				// Are we in SSI mode?  If so try that username and password first
647 692
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
648 693
 				{
649
-					if (empty($db_persist))
650
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
651
-					else
652
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
694
+					if (empty($db_persist)) {
695
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
696
+					} else {
697
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
698
+					}
653 699
 				}
654 700
 				// Fall back to the regular username and password if need be
655 701
 				if (!$db_connection)
656 702
 				{
657
-					if (empty($db_persist))
658
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
659
-					else
660
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
703
+					if (empty($db_persist)) {
704
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
705
+					} else {
706
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
707
+					}
661 708
 				}
662 709
 
663
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
664
-					$db_connection = false;
710
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
711
+									$db_connection = false;
712
+				}
665 713
 			}
666 714
 
667 715
 			if ($db_connection)
@@ -672,24 +720,27 @@  discard block
 block discarded – undo
672 720
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
673 721
 
674 722
 					$new_errno = mysqli_errno($db_connection);
675
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
676
-						break;
723
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
724
+											break;
725
+					}
677 726
 				}
678 727
 
679 728
 				// If it failed again, shucks to be you... we're not trying it over and over.
680
-				if ($ret !== false)
681
-					return $ret;
729
+				if ($ret !== false) {
730
+									return $ret;
731
+				}
682 732
 			}
683 733
 		}
684 734
 		// Are they out of space, perhaps?
685 735
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
686 736
 		{
687
-			if (!isset($txt))
688
-				$query_error .= ' - check database storage space.';
689
-			else
737
+			if (!isset($txt)) {
738
+							$query_error .= ' - check database storage space.';
739
+			} else
690 740
 			{
691
-				if (!isset($txt['mysql_error_space']))
692
-					loadLanguage('Errors');
741
+				if (!isset($txt['mysql_error_space'])) {
742
+									loadLanguage('Errors');
743
+				}
693 744
 
694 745
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
695 746
 			}
@@ -697,15 +748,17 @@  discard block
 block discarded – undo
697 748
 	}
698 749
 
699 750
 	// Nothing's defined yet... just die with it.
700
-	if (empty($context) || empty($txt))
701
-		die($query_error);
751
+	if (empty($context) || empty($txt)) {
752
+			die($query_error);
753
+	}
702 754
 
703 755
 	// Show an error message, if possible.
704 756
 	$context['error_title'] = $txt['database_error'];
705
-	if (allowedTo('admin_forum'))
706
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
707
-	else
708
-		$context['error_message'] = $txt['try_again'];
757
+	if (allowedTo('admin_forum')) {
758
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
759
+	} else {
760
+			$context['error_message'] = $txt['try_again'];
761
+	}
709 762
 
710 763
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
711 764
 	{
@@ -734,25 +787,28 @@  discard block
 block discarded – undo
734 787
 	$connection = $connection === null ? $db_connection : $connection;
735 788
 
736 789
 	// With nothing to insert, simply return.
737
-	if (empty($data))
738
-		return;
790
+	if (empty($data)) {
791
+			return;
792
+	}
739 793
 
740 794
 	// Replace the prefix holder with the actual prefix.
741 795
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
742 796
 
743 797
 	// Inserting data as a single row can be done as a single array.
744
-	if (!is_array($data[array_rand($data)]))
745
-		$data = array($data);
798
+	if (!is_array($data[array_rand($data)])) {
799
+			$data = array($data);
800
+	}
746 801
 
747 802
 	// Create the mold for a single row insert.
748 803
 	$insertData = '(';
749 804
 	foreach ($columns as $columnName => $type)
750 805
 	{
751 806
 		// Are we restricting the length?
752
-		if (strpos($type, 'string-') !== false)
753
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
754
-		else
755
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
807
+		if (strpos($type, 'string-') !== false) {
808
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
809
+		} else {
810
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
811
+		}
756 812
 	}
757 813
 	$insertData = substr($insertData, 0, -2) . ')';
758 814
 
@@ -761,8 +817,9 @@  discard block
 block discarded – undo
761 817
 
762 818
 	// Here's where the variables are injected to the query.
763 819
 	$insertRows = array();
764
-	foreach ($data as $dataRow)
765
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
820
+	foreach ($data as $dataRow) {
821
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
822
+	}
766 823
 
767 824
 	// Determine the method of insertion.
768 825
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -793,8 +850,9 @@  discard block
 block discarded – undo
793 850
  */
794 851
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
795 852
 {
796
-	if (empty($log_message))
797
-		$log_message = $error_message;
853
+	if (empty($log_message)) {
854
+			$log_message = $error_message;
855
+	}
798 856
 
799 857
 	foreach (debug_backtrace() as $step)
800 858
 	{
@@ -813,12 +871,14 @@  discard block
 block discarded – undo
813 871
 	}
814 872
 
815 873
 	// A special case - we want the file and line numbers for debugging.
816
-	if ($error_type == 'return')
817
-		return array($file, $line);
874
+	if ($error_type == 'return') {
875
+			return array($file, $line);
876
+	}
818 877
 
819 878
 	// Is always a critical error.
820
-	if (function_exists('log_error'))
821
-		log_error($log_message, 'critical', $file, $line);
879
+	if (function_exists('log_error')) {
880
+			log_error($log_message, 'critical', $file, $line);
881
+	}
822 882
 
823 883
 	if (function_exists('fatal_error'))
824 884
 	{
@@ -826,12 +886,12 @@  discard block
 block discarded – undo
826 886
 
827 887
 		// Cannot continue...
828 888
 		exit;
889
+	} elseif ($error_type) {
890
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
891
+	} else {
892
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
893
+	}
829 894
 	}
830
-	elseif ($error_type)
831
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
832
-	else
833
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
834
-}
835 895
 
836 896
 /**
837 897
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -848,10 +908,11 @@  discard block
 block discarded – undo
848 908
 		'\\' => '\\\\',
849 909
 	);
850 910
 
851
-	if ($translate_human_wildcards)
852
-		$replacements += array(
911
+	if ($translate_human_wildcards) {
912
+			$replacements += array(
853 913
 			'*' => '%',
854 914
 		);
915
+	}
855 916
 
856 917
 	return strtr($string, $replacements);
857 918
 }
@@ -865,8 +926,9 @@  discard block
 block discarded – undo
865 926
  */
866 927
 function smf_is_resource($result)
867 928
 {
868
-	if ($result instanceof mysqli_result)
869
-		return true;
929
+	if ($result instanceof mysqli_result) {
930
+			return true;
931
+	}
870 932
 
871 933
 	return false;
872 934
 }
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
@@ -447,7 +447,6 @@  discard block
 block discarded – undo
447 447
 
448 448
 /**
449 449
  * affected_rows
450
- * @param resource $connection
451 450
  */
452 451
 function smf_db_affected_rows($result = null)
453 452
 {
@@ -790,7 +789,7 @@  discard block
 block discarded – undo
790 789
  *
791 790
  * @param string $db_name The database name
792 791
  * @param resource $db_connection The database connection
793
- * @return true Always returns true
792
+ * @return boolean Always returns true
794 793
  */
795 794
 function smf_db_select_db($db_name, $db_connection)
796 795
 {
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	if (!empty($db_options['persist']))
64 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 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'] . '\''));
66
+		$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67 67
 
68 68
 	// Something's wrong, show an error if its fatal (which we assume it is)
69 69
 	if (!$connection)
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
  *
88 88
  * @param string $type Indicates which additional file to load. ('extra', 'packages')
89 89
  */
90
-function db_extend ($type = 'extra')
90
+function db_extend($type = 'extra')
91 91
 {
92 92
 	global $sourcedir, $db_type;
93 93
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
  * @param string $db_prefix The database prefix
104 104
  * @param string $db_name The database name
105 105
  */
106
-function db_fix_prefix (&$db_prefix, $db_name)
106
+function db_fix_prefix(&$db_prefix, $db_name)
107 107
 {
108 108
 	return;
109 109
 }
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 
540 540
 	// Log the error.
541 541
 	if (function_exists('log_error'))
542
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line);
542
+		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
543 543
 
544 544
 	// Nothing's defined yet... just die with it.
545 545
 	if (empty($context) || empty($txt))
@@ -675,31 +675,31 @@  discard block
 block discarded – undo
675 675
 		static $pg_version;
676 676
 		static $replace_support;
677 677
 		
678
-		if(empty($pg_version))
678
+		if (empty($pg_version))
679 679
 		{
680 680
 			db_extend();
681 681
 			//pg 9.5 got replace support
682 682
 			$pg_version = $smcFunc['db_get_version']();
683 683
 			// if we got a Beta Version
684 684
 			if (stripos($pg_version, 'beta') !== false)
685
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0';
685
+				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
686 686
 			// or RC
687 687
 			if (stripos($pg_version, 'rc') !== false)
688
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0';
688
+				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
689 689
 
690
-			$replace_support = (version_compare($pg_version,'9.5.0','>=') ? true : false);
690
+			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
691 691
 		}
692 692
 		
693 693
 		$count = 0;
694 694
 		$where = '';
695 695
 		$count_pk = 0;
696 696
 		
697
-		If($replace_support)
697
+		If ($replace_support)
698 698
 		{
699 699
 			foreach ($columns as $columnName => $type)
700 700
 			{
701 701
 				//check pk fiel
702
-				IF(in_array($columnName, $keys))
702
+				IF (in_array($columnName, $keys))
703 703
 				{
704 704
 					$key_str .= ($count_pk > 0 ? ',' : '');
705 705
 					$key_str .= $columnName;
@@ -708,11 +708,11 @@  discard block
 block discarded – undo
708 708
 				else //normal field
709 709
 				{					
710 710
 					$col_str .= ($count > 0 ? ',' : '');
711
-					$col_str .= $columnName.' = EXCLUDED.'.$columnName;
711
+					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
712 712
 					$count++;
713 713
 				}
714 714
 			}
715
-			$replace = ' ON CONFLICT ('.$key_str.') DO UPDATE SET '.$col_str;
715
+			$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
716 716
 		} 
717 717
 		else
718 718
 		{
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 			$smcFunc['db_query']('', '
773 773
 				INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '")
774 774
 				VALUES
775
-					' . $entry.$replace,
775
+					' . $entry . $replace,
776 776
 				array(
777 777
 					'security_override' => true,
778 778
 					'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors',
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
  * @param bool $translate_human_wildcards If true, turns human readable wildcards into SQL wildcards.
868 868
  * @return string The escaped string
869 869
  */
870
-function smf_db_escape_wildcard_string($string, $translate_human_wildcards=false)
870
+function smf_db_escape_wildcard_string($string, $translate_human_wildcards = false)
871 871
 {
872 872
 	$replacements = array(
873 873
 		'%' => '\%',
Please login to merge, or discard this patch.
Braces   +195 added lines, -144 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,49 +172,55 @@  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 'float':
206
-			if (!is_numeric($replacement))
207
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221
+			if (!is_numeric($replacement)) {
222
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223
+			}
208 224
 			return (string) (float) $replacement;
209 225
 		break;
210 226
 
@@ -217,10 +233,12 @@  discard block
 block discarded – undo
217 233
 		break;
218 234
 		
219 235
 		case 'inet':
220
-			if ($replacement == 'null')
221
-				return 'null';
222
-			if (inet_pton($replacement) === false)
223
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236
+			if ($replacement == 'null') {
237
+							return 'null';
238
+			}
239
+			if (inet_pton($replacement) === false) {
240
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			}
224 242
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
225 243
 		break;
226 244
 
@@ -319,14 +337,16 @@  discard block
 block discarded – undo
319 337
 		),
320 338
 	);
321 339
 
322
-	if (isset($replacements[$identifier]))
323
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
340
+	if (isset($replacements[$identifier])) {
341
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
342
+	}
324 343
 
325 344
 	// Limits need to be a little different.
326 345
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
327 346
 
328
-	if (trim($db_string) == '')
329
-		return false;
347
+	if (trim($db_string) == '') {
348
+			return false;
349
+	}
330 350
 
331 351
 	// Comments that are allowed in a query are preg_removed.
332 352
 	static $allowed_comments_from = array(
@@ -346,8 +366,9 @@  discard block
 block discarded – undo
346 366
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
347 367
 	$db_replace_result = 0;
348 368
 
349
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
350
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
369
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
370
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
371
+	}
351 372
 
352 373
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
353 374
 	{
@@ -368,8 +389,9 @@  discard block
 block discarded – undo
368 389
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
369 390
 
370 391
 		// Initialize $db_cache if not already initialized.
371
-		if (!isset($db_cache))
372
-			$db_cache = array();
392
+		if (!isset($db_cache)) {
393
+					$db_cache = array();
394
+		}
373 395
 
374 396
 		if (!empty($_SESSION['debug_redirect']))
375 397
 		{
@@ -395,17 +417,18 @@  discard block
 block discarded – undo
395 417
 		while (true)
396 418
 		{
397 419
 			$pos = strpos($db_string, '\'', $pos + 1);
398
-			if ($pos === false)
399
-				break;
420
+			if ($pos === false) {
421
+							break;
422
+			}
400 423
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
401 424
 
402 425
 			while (true)
403 426
 			{
404 427
 				$pos1 = strpos($db_string, '\'', $pos + 1);
405 428
 				$pos2 = strpos($db_string, '\\', $pos + 1);
406
-				if ($pos1 === false)
407
-					break;
408
-				elseif ($pos2 == false || $pos2 > $pos1)
429
+				if ($pos1 === false) {
430
+									break;
431
+				} elseif ($pos2 == false || $pos2 > $pos1)
409 432
 				{
410 433
 					$pos = $pos1;
411 434
 					break;
@@ -421,26 +444,31 @@  discard block
 block discarded – undo
421 444
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
422 445
 
423 446
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
424
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
425
-			$fail = true;
447
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
448
+					$fail = true;
449
+		}
426 450
 		// Trying to change passwords, slow us down, or something?
427
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
428
-			$fail = true;
429
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
430
-			$fail = true;
451
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
452
+					$fail = true;
453
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
454
+					$fail = true;
455
+		}
431 456
 
432
-		if (!empty($fail) && function_exists('log_error'))
433
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
457
+		if (!empty($fail) && function_exists('log_error')) {
458
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
459
+		}
434 460
 	}
435 461
 
436 462
 	$db_last_result = @pg_query($connection, $db_string);
437 463
 
438
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
439
-		$db_last_result = smf_db_error($db_string, $connection);
464
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
465
+			$db_last_result = smf_db_error($db_string, $connection);
466
+	}
440 467
 
441 468
 	// Debugging.
442
-	if (isset($db_show_debug) && $db_show_debug === true)
443
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
469
+	if (isset($db_show_debug) && $db_show_debug === true) {
470
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
471
+	}
444 472
 
445 473
 	return $db_last_result;
446 474
 }
@@ -453,10 +481,11 @@  discard block
 block discarded – undo
453 481
 {
454 482
 	global $db_last_result, $db_replace_result;
455 483
 
456
-	if ($db_replace_result)
457
-		return $db_replace_result;
458
-	elseif ($result === null && !$db_last_result)
459
-		return 0;
484
+	if ($db_replace_result) {
485
+			return $db_replace_result;
486
+	} elseif ($result === null && !$db_last_result) {
487
+			return 0;
488
+	}
460 489
 
461 490
 	return pg_affected_rows($result === null ? $db_last_result : $result);
462 491
 }
@@ -475,16 +504,18 @@  discard block
 block discarded – undo
475 504
 
476 505
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
477 506
 
478
-	if ($connection === false)
479
-		$connection = $db_connection;
507
+	if ($connection === false) {
508
+			$connection = $db_connection;
509
+	}
480 510
 
481 511
 	// Try get the last ID for the auto increment field.
482 512
 	$request = $smcFunc['db_query']('', 'SELECT CURRVAL(\'' . $table . '_seq\') AS insertID',
483 513
 		array(
484 514
 		)
485 515
 	);
486
-	if (!$request)
487
-		return false;
516
+	if (!$request) {
517
+			return false;
518
+	}
488 519
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
489 520
 	$smcFunc['db_free_result']($request);
490 521
 
@@ -505,12 +536,13 @@  discard block
 block discarded – undo
505 536
 	// Decide which connection to use
506 537
 	$connection = $connection === null ? $db_connection : $connection;
507 538
 
508
-	if ($type == 'begin')
509
-		return @pg_query($connection, 'BEGIN');
510
-	elseif ($type == 'rollback')
511
-		return @pg_query($connection, 'ROLLBACK');
512
-	elseif ($type == 'commit')
513
-		return @pg_query($connection, 'COMMIT');
539
+	if ($type == 'begin') {
540
+			return @pg_query($connection, 'BEGIN');
541
+	} elseif ($type == 'rollback') {
542
+			return @pg_query($connection, 'ROLLBACK');
543
+	} elseif ($type == 'commit') {
544
+			return @pg_query($connection, 'COMMIT');
545
+	}
514 546
 
515 547
 	return false;
516 548
 }
@@ -538,19 +570,22 @@  discard block
 block discarded – undo
538 570
 	$query_error = @pg_last_error($connection);
539 571
 
540 572
 	// Log the error.
541
-	if (function_exists('log_error'))
542
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line);
573
+	if (function_exists('log_error')) {
574
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line);
575
+	}
543 576
 
544 577
 	// Nothing's defined yet... just die with it.
545
-	if (empty($context) || empty($txt))
546
-		die($query_error);
578
+	if (empty($context) || empty($txt)) {
579
+			die($query_error);
580
+	}
547 581
 
548 582
 	// Show an error message, if possible.
549 583
 	$context['error_title'] = $txt['database_error'];
550
-	if (allowedTo('admin_forum'))
551
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
552
-	else
553
-		$context['error_message'] = $txt['try_again'];
584
+	if (allowedTo('admin_forum')) {
585
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
586
+	} else {
587
+			$context['error_message'] = $txt['try_again'];
588
+	}
554 589
 
555 590
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
556 591
 	{
@@ -572,12 +607,14 @@  discard block
 block discarded – undo
572 607
 {
573 608
 	global $db_row_count;
574 609
 
575
-	if ($counter !== false)
576
-		return pg_fetch_row($request, $counter);
610
+	if ($counter !== false) {
611
+			return pg_fetch_row($request, $counter);
612
+	}
577 613
 
578 614
 	// Reset the row counter...
579
-	if (!isset($db_row_count[(int) $request]))
580
-		$db_row_count[(int) $request] = 0;
615
+	if (!isset($db_row_count[(int) $request])) {
616
+			$db_row_count[(int) $request] = 0;
617
+	}
581 618
 
582 619
 	// Return the right row.
583 620
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -594,12 +631,14 @@  discard block
 block discarded – undo
594 631
 {
595 632
 	global $db_row_count;
596 633
 
597
-	if ($counter !== false)
598
-		return pg_fetch_assoc($request, $counter);
634
+	if ($counter !== false) {
635
+			return pg_fetch_assoc($request, $counter);
636
+	}
599 637
 
600 638
 	// Reset the row counter...
601
-	if (!isset($db_row_count[(int) $request]))
602
-		$db_row_count[(int) $request] = 0;
639
+	if (!isset($db_row_count[(int) $request])) {
640
+			$db_row_count[(int) $request] = 0;
641
+	}
603 642
 
604 643
 	// Return the right row.
605 644
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -651,11 +690,13 @@  discard block
 block discarded – undo
651 690
 	
652 691
 	$replace = '';
653 692
 
654
-	if (empty($data))
655
-		return;
693
+	if (empty($data)) {
694
+			return;
695
+	}
656 696
 
657
-	if (!is_array($data[array_rand($data)]))
658
-		$data = array($data);
697
+	if (!is_array($data[array_rand($data)])) {
698
+			$data = array($data);
699
+	}
659 700
 
660 701
 	// Replace the prefix holder with the actual prefix.
661 702
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -681,11 +722,13 @@  discard block
 block discarded – undo
681 722
 			//pg 9.5 got replace support
682 723
 			$pg_version = $smcFunc['db_get_version']();
683 724
 			// if we got a Beta Version
684
-			if (stripos($pg_version, 'beta') !== false)
685
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0';
725
+			if (stripos($pg_version, 'beta') !== false) {
726
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0';
727
+			}
686 728
 			// or RC
687
-			if (stripos($pg_version, 'rc') !== false)
688
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0';
729
+			if (stripos($pg_version, 'rc') !== false) {
730
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0';
731
+			}
689 732
 
690 733
 			$replace_support = (version_compare($pg_version,'9.5.0','>=') ? true : false);
691 734
 		}
@@ -704,8 +747,7 @@  discard block
 block discarded – undo
704 747
 					$key_str .= ($count_pk > 0 ? ',' : '');
705 748
 					$key_str .= $columnName;
706 749
 					$count_pk++;
707
-				}
708
-				else //normal field
750
+				} else //normal field
709 751
 				{					
710 752
 					$col_str .= ($count > 0 ? ',' : '');
711 753
 					$col_str .= $columnName.' = EXCLUDED.'.$columnName;
@@ -713,20 +755,21 @@  discard block
 block discarded – undo
713 755
 				}
714 756
 			}
715 757
 			$replace = ' ON CONFLICT ('.$key_str.') DO UPDATE SET '.$col_str;
716
-		} 
717
-		else
758
+		} else
718 759
 		{
719 760
 			foreach ($columns as $columnName => $type)
720 761
 			{
721 762
 				// Are we restricting the length?
722
-				if (strpos($type, 'string-') !== false)
723
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
724
-				else
725
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
763
+				if (strpos($type, 'string-') !== false) {
764
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
765
+				} else {
766
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
767
+				}
726 768
 
727 769
 				// A key? That's what we were looking for.
728
-				if (in_array($columnName, $keys))
729
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
770
+				if (in_array($columnName, $keys)) {
771
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
772
+				}
730 773
 				$count++;
731 774
 			}
732 775
 
@@ -752,10 +795,11 @@  discard block
 block discarded – undo
752 795
 		foreach ($columns as $columnName => $type)
753 796
 		{
754 797
 			// Are we restricting the length?
755
-			if (strpos($type, 'string-') !== false)
756
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
757
-			else
758
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
798
+			if (strpos($type, 'string-') !== false) {
799
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
800
+			} else {
801
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
802
+			}
759 803
 		}
760 804
 		$insertData = substr($insertData, 0, -2) . ')';
761 805
 
@@ -764,11 +808,12 @@  discard block
 block discarded – undo
764 808
 
765 809
 		// Here's where the variables are injected to the query.
766 810
 		$insertRows = array();
767
-		foreach ($data as $dataRow)
768
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
811
+		foreach ($data as $dataRow) {
812
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
813
+		}
769 814
 
770
-		foreach ($insertRows as $entry)
771
-			// Do the insert.
815
+		foreach ($insertRows as $entry) {
816
+					// Do the insert.
772 817
 			$smcFunc['db_query']('', '
773 818
 				INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '")
774 819
 				VALUES
@@ -779,11 +824,13 @@  discard block
 block discarded – undo
779 824
 				),
780 825
 				$connection
781 826
 			);
827
+		}
782 828
 	}
783 829
 
784
-	if ($priv_trans)
785
-		$smcFunc['db_transaction']('commit', $connection);
786
-}
830
+	if ($priv_trans) {
831
+			$smcFunc['db_transaction']('commit', $connection);
832
+	}
833
+	}
787 834
 
788 835
 /**
789 836
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -820,8 +867,9 @@  discard block
 block discarded – undo
820 867
  */
821 868
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
822 869
 {
823
-	if (empty($log_message))
824
-		$log_message = $error_message;
870
+	if (empty($log_message)) {
871
+			$log_message = $error_message;
872
+	}
825 873
 
826 874
 	foreach (debug_backtrace() as $step)
827 875
 	{
@@ -840,12 +888,14 @@  discard block
 block discarded – undo
840 888
 	}
841 889
 
842 890
 	// A special case - we want the file and line numbers for debugging.
843
-	if ($error_type == 'return')
844
-		return array($file, $line);
891
+	if ($error_type == 'return') {
892
+			return array($file, $line);
893
+	}
845 894
 
846 895
 	// Is always a critical error.
847
-	if (function_exists('log_error'))
848
-		log_error($log_message, 'critical', $file, $line);
896
+	if (function_exists('log_error')) {
897
+			log_error($log_message, 'critical', $file, $line);
898
+	}
849 899
 
850 900
 	if (function_exists('fatal_error'))
851 901
 	{
@@ -853,12 +903,12 @@  discard block
 block discarded – undo
853 903
 
854 904
 		// Cannot continue...
855 905
 		exit;
906
+	} elseif ($error_type) {
907
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
908
+	} else {
909
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
910
+	}
856 911
 	}
857
-	elseif ($error_type)
858
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
859
-	else
860
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
861
-}
862 912
 
863 913
 /**
864 914
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -875,10 +925,11 @@  discard block
 block discarded – undo
875 925
 		'\\' => '\\\\',
876 926
 	);
877 927
 
878
-	if ($translate_human_wildcards)
879
-		$replacements += array(
928
+	if ($translate_human_wildcards) {
929
+			$replacements += array(
880 930
 			'*' => '%',
881 931
 		);
932
+	}
882 933
 
883 934
 	return strtr($string, $replacements);
884 935
 }
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.
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -523,7 +523,6 @@  discard block
 block discarded – undo
523 523
 /**
524 524
  * Copy image.
525 525
  * Used when imagecopyresample() is not available.
526
-
527 526
  * @param resource $dst_img The destination image - a GD image resource
528 527
  * @param resource $src_img The source image - a GD image resource
529 528
  * @param int $dst_x The "x" coordinate of the destination image
@@ -754,7 +753,6 @@  discard block
 block discarded – undo
754 753
 
755 754
 /**
756 755
  * Writes a gif file to disk as a png file.
757
-
758 756
  * @param resource $gif A gif image resource
759 757
  * @param string $lpszFileName The name of the file
760 758
  * @param int $background_color The background color
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.
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-Members.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -842,7 +842,7 @@
 block discarded – undo
842 842
  * @param int $current_ID_MEMBER The ID of the current member (to avoid false positives with the current member)
843 843
  * @param bool $is_name Whether we're checking against reserved names or just usernames
844 844
  * @param bool $fatal Whether to die with a fatal error if the name is reserved
845
- * @return bool|void False if name is not reserved, otherwise true if $fatal is false or dies with a fatal_lang_error if $fatal is true
845
+ * @return boolean False if name is not reserved, otherwise true if $fatal is false or dies with a fatal_lang_error if $fatal is true
846 846
  */
847 847
 function isReservedName($name, $current_ID_MEMBER = 0, $is_name = true, $fatal = true)
848 848
 {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 		'member_name' => $regOptions['username'],
587 587
 		'email_address' => $regOptions['email'],
588 588
 		'passwd' => hash_password($regOptions['username'], $regOptions['password']),
589
-		'password_salt' => substr(md5(mt_rand()), 0, 4) ,
589
+		'password_salt' => substr(md5(mt_rand()), 0, 4),
590 590
 		'posts' => 0,
591 591
 		'date_registered' => time(),
592 592
 		'member_ip' => $regOptions['interface'] == 'admin' ? '127.0.0.1' : $user_info['ip'],
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 	$checkName = strtr($name, array('_' => '\\_', '%' => '\\%'));
900 900
 	
901 901
 	//when we got no wildcard we can use equal -> fast
902
-	$operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '=' );
902
+	$operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '=');
903 903
 
904 904
 	// Make sure they don't want someone else's name.
905 905
 	$request = $smcFunc['db_query']('', '
@@ -1268,7 +1268,7 @@  discard block
 block discarded – undo
1268 1268
 		$user_info['buddies'][] = $userReceiver;
1269 1269
 
1270 1270
 		// And add a nice alert. Don't abuse though!
1271
-		if ((cache_get_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, 86400)) == null)
1271
+		if ((cache_get_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, 86400)) == null)
1272 1272
 		{
1273 1273
 			$smcFunc['db_insert']('insert',
1274 1274
 				'{db_prefix}background_tasks',
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
 			);
1284 1284
 
1285 1285
 			// Store this in a cache entry to avoid creating multiple alerts. Give it a long life cycle.
1286
-			cache_put_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, '1', 86400);
1286
+			cache_put_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, '1', 86400);
1287 1287
 		}
1288 1288
 	}
1289 1289
 
Please login to merge, or discard this patch.
Braces   +209 added lines, -151 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 or more members.
@@ -43,30 +44,32 @@  discard block
 block discarded – undo
43 44
 	setMemoryLimit('128M');
44 45
 
45 46
 	// If it's not an array, make it so!
46
-	if (!is_array($users))
47
-		$users = array($users);
48
-	else
49
-		$users = array_unique($users);
47
+	if (!is_array($users)) {
48
+			$users = array($users);
49
+	} else {
50
+			$users = array_unique($users);
51
+	}
50 52
 
51 53
 	// Make sure there's no void user in here.
52 54
 	$users = array_diff($users, array(0));
53 55
 
54 56
 	// How many are they deleting?
55
-	if (empty($users))
56
-		return;
57
-	elseif (count($users) == 1)
57
+	if (empty($users)) {
58
+			return;
59
+	} elseif (count($users) == 1)
58 60
 	{
59 61
 		list ($user) = $users;
60 62
 
61
-		if ($user == $user_info['id'])
62
-			isAllowedTo('profile_remove_own');
63
-		else
64
-			isAllowedTo('profile_remove_any');
65
-	}
66
-	else
63
+		if ($user == $user_info['id']) {
64
+					isAllowedTo('profile_remove_own');
65
+		} else {
66
+					isAllowedTo('profile_remove_any');
67
+		}
68
+	} else
67 69
 	{
68
-		foreach ($users as $k => $v)
69
-			$users[$k] = (int) $v;
70
+		foreach ($users as $k => $v) {
71
+					$users[$k] = (int) $v;
72
+		}
70 73
 
71 74
 		// Deleting more than one?  You can't have more than one account...
72 75
 		isAllowedTo('profile_remove_any');
@@ -88,26 +91,30 @@  discard block
 block discarded – undo
88 91
 	$user_log_details = array();
89 92
 	while ($row = $smcFunc['db_fetch_assoc']($request))
90 93
 	{
91
-		if ($row['is_admin'])
92
-			$admins[] = $row['id_member'];
94
+		if ($row['is_admin']) {
95
+					$admins[] = $row['id_member'];
96
+		}
93 97
 		$user_log_details[$row['id_member']] = array($row['id_member'], $row['member_name']);
94 98
 	}
95 99
 	$smcFunc['db_free_result']($request);
96 100
 
97
-	if (empty($user_log_details))
98
-		return;
101
+	if (empty($user_log_details)) {
102
+			return;
103
+	}
99 104
 
100 105
 	// Make sure they aren't trying to delete administrators if they aren't one.  But don't bother checking if it's just themself.
101 106
 	if (!empty($admins) && ($check_not_admin || (!allowedTo('admin_forum') && (count($users) != 1 || $users[0] != $user_info['id']))))
102 107
 	{
103 108
 		$users = array_diff($users, $admins);
104
-		foreach ($admins as $id)
105
-			unset($user_log_details[$id]);
109
+		foreach ($admins as $id) {
110
+					unset($user_log_details[$id]);
111
+		}
106 112
 	}
107 113
 
108 114
 	// No one left?
109
-	if (empty($users))
110
-		return;
115
+	if (empty($users)) {
116
+			return;
117
+	}
111 118
 
112 119
 	// Log the action - regardless of who is deleting it.
113 120
 	$log_changes = array();
@@ -124,8 +131,9 @@  discard block
 block discarded – undo
124 131
 		);
125 132
 
126 133
 		// Remove any cached data if enabled.
127
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
128
-			cache_put_data('user_settings-' . $user[0], null, 60);
134
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
135
+					cache_put_data('user_settings-' . $user[0], null, 60);
136
+		}
129 137
 	}
130 138
 
131 139
 	// Make these peoples' posts guest posts.
@@ -388,8 +396,8 @@  discard block
 block discarded – undo
388 396
 			'buddy_list' => implode(', buddy_list) != 0 OR FIND_IN_SET(', $users),
389 397
 		)
390 398
 	);
391
-	while ($row = $smcFunc['db_fetch_assoc']($request))
392
-		$smcFunc['db_query']('', '
399
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
400
+			$smcFunc['db_query']('', '
393 401
 			UPDATE {db_prefix}members
394 402
 			SET
395 403
 				pm_ignore_list = {string:pm_ignore_list},
@@ -401,6 +409,7 @@  discard block
 block discarded – undo
401 409
 				'buddy_list' => implode(',', array_diff(explode(',', $row['buddy_list']), $users)),
402 410
 			)
403 411
 		);
412
+	}
404 413
 	$smcFunc['db_free_result']($request);
405 414
 
406 415
 	// Make sure no member's birthday is still sticking in the calendar...
@@ -455,29 +464,34 @@  discard block
 block discarded – undo
455 464
 	elseif ($regOptions['interface'] == 'guest')
456 465
 	{
457 466
 		// You cannot register twice...
458
-		if (empty($user_info['is_guest']))
459
-			redirectexit();
467
+		if (empty($user_info['is_guest'])) {
468
+					redirectexit();
469
+		}
460 470
 
461 471
 		// Make sure they didn't just register with this session.
462
-		if (!empty($_SESSION['just_registered']) && empty($modSettings['disableRegisterCheck']))
463
-			fatal_lang_error('register_only_once', false);
472
+		if (!empty($_SESSION['just_registered']) && empty($modSettings['disableRegisterCheck'])) {
473
+					fatal_lang_error('register_only_once', false);
474
+		}
464 475
 	}
465 476
 
466 477
 	// Spaces and other odd characters are evil...
467 478
 	$regOptions['username'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $regOptions['username']));
468 479
 
469 480
 	// @todo Separate the sprintf?
470
-	if (empty($regOptions['email']) || !filter_var($regOptions['email'], FILTER_VALIDATE_EMAIL) || strlen($regOptions['email']) > 255)
471
-		$reg_errors[] = array('lang', 'profile_error_bad_email');
481
+	if (empty($regOptions['email']) || !filter_var($regOptions['email'], FILTER_VALIDATE_EMAIL) || strlen($regOptions['email']) > 255) {
482
+			$reg_errors[] = array('lang', 'profile_error_bad_email');
483
+	}
472 484
 
473 485
 	$username_validation_errors = validateUsername(0, $regOptions['username'], true, !empty($regOptions['check_reserved_name']));
474
-	if (!empty($username_validation_errors))
475
-		$reg_errors = array_merge($reg_errors, $username_validation_errors);
486
+	if (!empty($username_validation_errors)) {
487
+			$reg_errors = array_merge($reg_errors, $username_validation_errors);
488
+	}
476 489
 
477 490
 	// Generate a validation code if it's supposed to be emailed.
478 491
 	$validation_code = '';
479
-	if ($regOptions['require'] == 'activation')
480
-		$validation_code = generateValidationCode();
492
+	if ($regOptions['require'] == 'activation') {
493
+			$validation_code = generateValidationCode();
494
+	}
481 495
 
482 496
 	// If you haven't put in a password generate one.
483 497
 	if ($regOptions['interface'] == 'admin' && $regOptions['password'] == '')
@@ -487,8 +501,9 @@  discard block
 block discarded – undo
487 501
 		$regOptions['password_check'] = $regOptions['password'];
488 502
 	}
489 503
 	// Does the first password match the second?
490
-	elseif ($regOptions['password'] != $regOptions['password_check'])
491
-		$reg_errors[] = array('lang', 'passwords_dont_match');
504
+	elseif ($regOptions['password'] != $regOptions['password_check']) {
505
+			$reg_errors[] = array('lang', 'passwords_dont_match');
506
+	}
492 507
 
493 508
 	// That's kind of easy to guess...
494 509
 	if ($regOptions['password'] == '')
@@ -502,13 +517,15 @@  discard block
 block discarded – undo
502 517
 		$passwordError = validatePassword($regOptions['password'], $regOptions['username'], array($regOptions['email']));
503 518
 
504 519
 		// Password isn't legal?
505
-		if ($passwordError != null)
506
-			$reg_errors[] = array('lang', 'profile_error_password_' . $passwordError);
520
+		if ($passwordError != null) {
521
+					$reg_errors[] = array('lang', 'profile_error_password_' . $passwordError);
522
+		}
507 523
 	}
508 524
 
509 525
 	// You may not be allowed to register this email.
510
-	if (!empty($regOptions['check_email_ban']))
511
-		isBannedEmail($regOptions['email'], 'cannot_register', $txt['ban_register_prohibited']);
526
+	if (!empty($regOptions['check_email_ban'])) {
527
+			isBannedEmail($regOptions['email'], 'cannot_register', $txt['ban_register_prohibited']);
528
+	}
512 529
 
513 530
 	// Check if the email address is in use.
514 531
 	$request = $smcFunc['db_query']('', '
@@ -523,8 +540,9 @@  discard block
 block discarded – undo
523 540
 		)
524 541
 	);
525 542
 	// @todo Separate the sprintf?
526
-	if ($smcFunc['db_num_rows']($request) != 0)
527
-		$reg_errors[] = array('lang', 'email_in_use', false, array($smcFunc['htmlspecialchars']($regOptions['email'])));
543
+	if ($smcFunc['db_num_rows']($request) != 0) {
544
+			$reg_errors[] = array('lang', 'email_in_use', false, array($smcFunc['htmlspecialchars']($regOptions['email'])));
545
+	}
528 546
 
529 547
 	$smcFunc['db_free_result']($request);
530 548
 
@@ -539,24 +557,27 @@  discard block
 block discarded – undo
539 557
 			1 = The text/index.
540 558
 			2 = Whether to log.
541 559
 			3 = sprintf data if necessary. */
542
-		if ($error[0] == 'lang')
543
-			loadLanguage('Errors');
560
+		if ($error[0] == 'lang') {
561
+					loadLanguage('Errors');
562
+		}
544 563
 		$message = $error[0] == 'lang' ? (empty($error[3]) ? $txt[$error[1]] : vsprintf($txt[$error[1]], $error[3])) : $error[1];
545 564
 
546 565
 		// What to do, what to do, what to do.
547 566
 		if ($return_errors)
548 567
 		{
549
-			if (!empty($error[2]))
550
-				log_error($message, $error[2]);
568
+			if (!empty($error[2])) {
569
+							log_error($message, $error[2]);
570
+			}
551 571
 			$reg_errors[$key] = $message;
572
+		} else {
573
+					fatal_error($message, empty($error[2]) ? false : $error[2]);
552 574
 		}
553
-		else
554
-			fatal_error($message, empty($error[2]) ? false : $error[2]);
555 575
 	}
556 576
 
557 577
 	// If there's any errors left return them at once!
558
-	if (!empty($reg_errors))
559
-		return $reg_errors;
578
+	if (!empty($reg_errors)) {
579
+			return $reg_errors;
580
+	}
560 581
 
561 582
 	$reservedVars = array(
562 583
 		'actual_theme_url',
@@ -578,8 +599,9 @@  discard block
 block discarded – undo
578 599
 	);
579 600
 
580 601
 	// Can't change reserved vars.
581
-	if (isset($regOptions['theme_vars']) && count(array_intersect(array_keys($regOptions['theme_vars']), $reservedVars)) != 0)
582
-		fatal_lang_error('no_theme');
602
+	if (isset($regOptions['theme_vars']) && count(array_intersect(array_keys($regOptions['theme_vars']), $reservedVars)) != 0) {
603
+			fatal_lang_error('no_theme');
604
+	}
583 605
 
584 606
 	// Some of these might be overwritten. (the lower ones that are in the arrays below.)
585 607
 	$regOptions['register_vars'] = array(
@@ -621,14 +643,17 @@  discard block
 block discarded – undo
621 643
 		$regOptions['register_vars']['validation_code'] = '';
622 644
 	}
623 645
 	// Maybe it can be activated right away?
624
-	elseif ($regOptions['require'] == 'nothing')
625
-		$regOptions['register_vars']['is_activated'] = 1;
646
+	elseif ($regOptions['require'] == 'nothing') {
647
+			$regOptions['register_vars']['is_activated'] = 1;
648
+	}
626 649
 	// Maybe it must be activated by email?
627
-	elseif ($regOptions['require'] == 'activation')
628
-		$regOptions['register_vars']['is_activated'] = 0;
650
+	elseif ($regOptions['require'] == 'activation') {
651
+			$regOptions['register_vars']['is_activated'] = 0;
652
+	}
629 653
 	// Otherwise it must be awaiting approval!
630
-	else
631
-		$regOptions['register_vars']['is_activated'] = 3;
654
+	else {
655
+			$regOptions['register_vars']['is_activated'] = 3;
656
+	}
632 657
 
633 658
 	if (isset($regOptions['memberGroup']))
634 659
 	{
@@ -647,24 +672,28 @@  discard block
 block discarded – undo
647 672
 				'is_protected' => 1,
648 673
 			)
649 674
 		);
650
-		while ($row = $smcFunc['db_fetch_assoc']($request))
651
-			$unassignableGroups[] = $row['id_group'];
675
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
676
+					$unassignableGroups[] = $row['id_group'];
677
+		}
652 678
 		$smcFunc['db_free_result']($request);
653 679
 
654
-		if (in_array($regOptions['register_vars']['id_group'], $unassignableGroups))
655
-			$regOptions['register_vars']['id_group'] = 0;
680
+		if (in_array($regOptions['register_vars']['id_group'], $unassignableGroups)) {
681
+					$regOptions['register_vars']['id_group'] = 0;
682
+		}
656 683
 	}
657 684
 
658 685
 	// Integrate optional member settings to be set.
659
-	if (!empty($regOptions['extra_register_vars']))
660
-		foreach ($regOptions['extra_register_vars'] as $var => $value)
686
+	if (!empty($regOptions['extra_register_vars'])) {
687
+			foreach ($regOptions['extra_register_vars'] as $var => $value)
661 688
 			$regOptions['register_vars'][$var] = $value;
689
+	}
662 690
 
663 691
 	// Integrate optional user theme options to be set.
664 692
 	$theme_vars = array();
665
-	if (!empty($regOptions['theme_vars']))
666
-		foreach ($regOptions['theme_vars'] as $var => $value)
693
+	if (!empty($regOptions['theme_vars'])) {
694
+			foreach ($regOptions['theme_vars'] as $var => $value)
667 695
 			$theme_vars[$var] = $value;
696
+	}
668 697
 
669 698
 	// Right, now let's prepare for insertion.
670 699
 	$knownInts = array(
@@ -684,12 +713,13 @@  discard block
 block discarded – undo
684 713
 	foreach ($regOptions['register_vars'] as $var => $val)
685 714
 	{
686 715
 		$type = 'string';
687
-		if (in_array($var, $knownInts))
688
-			$type = 'int';
689
-		elseif (in_array($var, $knownFloats))
690
-			$type = 'float';
691
-		elseif ($var == 'birthdate')
692
-			$type = 'date';
716
+		if (in_array($var, $knownInts)) {
717
+					$type = 'int';
718
+		} elseif (in_array($var, $knownFloats)) {
719
+					$type = 'float';
720
+		} elseif ($var == 'birthdate') {
721
+					$type = 'date';
722
+		}
693 723
 
694 724
 		$column_names[$var] = $type;
695 725
 		$values[$var] = $val;
@@ -708,17 +738,19 @@  discard block
 block discarded – undo
708 738
 	call_integration_hook('integrate_post_register', array(&$regOptions, &$theme_vars, &$memberID));
709 739
 
710 740
 	// Update the number of members and latest member's info - and pass the name, but remove the 's.
711
-	if ($regOptions['register_vars']['is_activated'] == 1)
712
-		updateStats('member', $memberID, $regOptions['register_vars']['real_name']);
713
-	else
714
-		updateStats('member');
741
+	if ($regOptions['register_vars']['is_activated'] == 1) {
742
+			updateStats('member', $memberID, $regOptions['register_vars']['real_name']);
743
+	} else {
744
+			updateStats('member');
745
+	}
715 746
 
716 747
 	// Theme variables too?
717 748
 	if (!empty($theme_vars))
718 749
 	{
719 750
 		$inserts = array();
720
-		foreach ($theme_vars as $var => $val)
721
-			$inserts[] = array($memberID, $var, $val);
751
+		foreach ($theme_vars as $var => $val) {
752
+					$inserts[] = array($memberID, $var, $val);
753
+		}
722 754
 		$smcFunc['db_insert']('insert',
723 755
 			'{db_prefix}themes',
724 756
 			array('id_member' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
@@ -733,10 +765,11 @@  discard block
 block discarded – undo
733 765
 	// Administrative registrations are a bit different...
734 766
 	if ($regOptions['interface'] == 'admin')
735 767
 	{
736
-		if ($regOptions['require'] == 'activation')
737
-			$email_message = 'admin_register_activate';
738
-		elseif (!empty($regOptions['send_welcome_email']))
739
-			$email_message = 'admin_register_immediate';
768
+		if ($regOptions['require'] == 'activation') {
769
+					$email_message = 'admin_register_activate';
770
+		} elseif (!empty($regOptions['send_welcome_email'])) {
771
+					$email_message = 'admin_register_immediate';
772
+		}
740 773
 
741 774
 		if (isset($email_message))
742 775
 		{
@@ -787,16 +820,17 @@  discard block
 block discarded – undo
787 820
 			'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
788 821
 		);
789 822
 
790
-		if ($regOptions['require'] == 'activation')
791
-			$replacements += array(
823
+		if ($regOptions['require'] == 'activation') {
824
+					$replacements += array(
792 825
 				'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $memberID . ';code=' . $validation_code,
793 826
 				'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $memberID,
794 827
 				'ACTIVATIONCODE' => $validation_code,
795 828
 			);
796
-		else
797
-			$replacements += array(
829
+		} else {
830
+					$replacements += array(
798 831
 				'COPPALINK' => $scripturl . '?action=coppa;u=' . $memberID,
799 832
 			);
833
+		}
800 834
 
801 835
 		$emaildata = loadEmailTemplate('register_' . ($regOptions['require'] == 'activation' ? 'activate' : 'coppa'), $replacements);
802 836
 
@@ -861,39 +895,45 @@  discard block
 block discarded – undo
861 895
 		// Check each name in the list...
862 896
 		foreach ($reservedNames as $reserved)
863 897
 		{
864
-			if ($reserved == '')
865
-				continue;
898
+			if ($reserved == '') {
899
+							continue;
900
+			}
866 901
 
867 902
 			// The admin might've used entities too, level the playing field.
868 903
 			$reservedCheck = preg_replace('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'replaceEntities__callback', $reserved);
869 904
 
870 905
 			// Case sensitive name?
871
-			if (empty($modSettings['reserveCase']))
872
-				$reservedCheck = $smcFunc['strtolower']($reservedCheck);
906
+			if (empty($modSettings['reserveCase'])) {
907
+							$reservedCheck = $smcFunc['strtolower']($reservedCheck);
908
+			}
873 909
 
874 910
 			// If it's not just entire word, check for it in there somewhere...
875
-			if ($checkMe == $reservedCheck || ($smcFunc['strpos']($checkMe, $reservedCheck) !== false && empty($modSettings['reserveWord'])))
876
-				if ($fatal)
911
+			if ($checkMe == $reservedCheck || ($smcFunc['strpos']($checkMe, $reservedCheck) !== false && empty($modSettings['reserveWord']))) {
912
+							if ($fatal)
877 913
 					fatal_lang_error('username_reserved', 'password', array($reserved));
878
-				else
879
-					return true;
914
+			} else {
915
+									return true;
916
+				}
880 917
 		}
881 918
 
882 919
 		$censor_name = $name;
883
-		if (censorText($censor_name) != $name)
884
-			if ($fatal)
920
+		if (censorText($censor_name) != $name) {
921
+					if ($fatal)
885 922
 				fatal_lang_error('name_censored', 'password', array($name));
886
-			else
887
-				return true;
923
+		} else {
924
+							return true;
925
+			}
888 926
 	}
889 927
 
890 928
 	// Characters we just shouldn't allow, regardless.
891
-	foreach (array('*') as $char)
892
-		if (strpos($checkName, $char) !== false)
929
+	foreach (array('*') as $char) {
930
+			if (strpos($checkName, $char) !== false)
893 931
 			if ($fatal)
894 932
 				fatal_lang_error('username_reserved', 'password', array($char));
895
-			else
896
-				return true;
933
+	}
934
+			else {
935
+							return true;
936
+			}
897 937
 
898 938
 	// Get rid of any SQL parts of the reserved name...
899 939
 	$checkName = strtr($name, array('_' => '\\_', '%' => '\\%'));
@@ -975,8 +1015,9 @@  discard block
 block discarded – undo
975 1015
 				'permission' => $permission,
976 1016
 			)
977 1017
 		);
978
-		while ($row = $smcFunc['db_fetch_assoc']($request))
979
-			$member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
1018
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1019
+					$member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
1020
+		}
980 1021
 		$smcFunc['db_free_result']($request);
981 1022
 	}
982 1023
 
@@ -984,9 +1025,9 @@  discard block
 block discarded – undo
984 1025
 	else
985 1026
 	{
986 1027
 		// First get the profile of the given board.
987
-		if (isset($board_info['id']) && $board_info['id'] == $board_id)
988
-			$profile_id = $board_info['profile'];
989
-		elseif ($board_id !== 0)
1028
+		if (isset($board_info['id']) && $board_info['id'] == $board_id) {
1029
+					$profile_id = $board_info['profile'];
1030
+		} elseif ($board_id !== 0)
990 1031
 		{
991 1032
 			$request = $smcFunc['db_query']('', '
992 1033
 				SELECT id_profile
@@ -997,13 +1038,14 @@  discard block
 block discarded – undo
997 1038
 					'id_board' => $board_id,
998 1039
 				)
999 1040
 			);
1000
-			if ($smcFunc['db_num_rows']($request) == 0)
1001
-				fatal_lang_error('no_board');
1041
+			if ($smcFunc['db_num_rows']($request) == 0) {
1042
+							fatal_lang_error('no_board');
1043
+			}
1002 1044
 			list ($profile_id) = $smcFunc['db_fetch_row']($request);
1003 1045
 			$smcFunc['db_free_result']($request);
1046
+		} else {
1047
+					$profile_id = 1;
1004 1048
 		}
1005
-		else
1006
-			$profile_id = 1;
1007 1049
 
1008 1050
 		$request = $smcFunc['db_query']('', '
1009 1051
 			SELECT bp.id_group, bp.add_deny
@@ -1015,8 +1057,9 @@  discard block
 block discarded – undo
1015 1057
 				'permission' => $permission,
1016 1058
 			)
1017 1059
 		);
1018
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1019
-			$member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
1060
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1061
+					$member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
1062
+		}
1020 1063
 		$smcFunc['db_free_result']($request);
1021 1064
 
1022 1065
 		$moderator_groups = array();
@@ -1025,8 +1068,7 @@  discard block
 block discarded – undo
1025 1068
 		if (isset($board_info['moderator_groups']))
1026 1069
 		{
1027 1070
 			$moderator_groups = array_keys($board_info['moderator_groups']);
1028
-		}
1029
-		elseif ($board_id !== 0)
1071
+		} elseif ($board_id !== 0)
1030 1072
 		{
1031 1073
 			// Get the groups that can moderate this board
1032 1074
 			$request = $smcFunc['db_query']('', '
@@ -1111,8 +1153,9 @@  discard block
 block discarded – undo
1111 1153
 		)
1112 1154
 	);
1113 1155
 	$members = array();
1114
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1115
-		$members[] = $row['id_member'];
1156
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1157
+			$members[] = $row['id_member'];
1158
+	}
1116 1159
 	$smcFunc['db_free_result']($request);
1117 1160
 
1118 1161
 	return $members;
@@ -1185,10 +1228,12 @@  discard block
 block discarded – undo
1185 1228
 	}
1186 1229
 
1187 1230
 	$query_parts = array();
1188
-	if (!empty($email))
1189
-		$query_parts[] = 'poster_email = {string:email_address}';
1190
-	if (!empty($membername))
1191
-		$query_parts[] = 'poster_name = {string:member_name}';
1231
+	if (!empty($email)) {
1232
+			$query_parts[] = 'poster_email = {string:email_address}';
1233
+	}
1234
+	if (!empty($membername)) {
1235
+			$query_parts[] = 'poster_name = {string:member_name}';
1236
+	}
1192 1237
 	$query = implode(' AND ', $query_parts);
1193 1238
 
1194 1239
 	// Finally, update the posts themselves!
@@ -1255,12 +1300,14 @@  discard block
 block discarded – undo
1255 1300
 
1256 1301
 	$userReceiver = (int) !empty($_REQUEST['u']) ? $_REQUEST['u'] : 0;
1257 1302
 
1258
-	if (empty($userReceiver))
1259
-		fatal_lang_error('no_access', false);
1303
+	if (empty($userReceiver)) {
1304
+			fatal_lang_error('no_access', false);
1305
+	}
1260 1306
 
1261 1307
 	// Remove if it's already there...
1262
-	if (in_array($userReceiver, $user_info['buddies']))
1263
-		$user_info['buddies'] = array_diff($user_info['buddies'], array($userReceiver));
1308
+	if (in_array($userReceiver, $user_info['buddies'])) {
1309
+			$user_info['buddies'] = array_diff($user_info['buddies'], array($userReceiver));
1310
+	}
1264 1311
 
1265 1312
 	// ...or add if it's not and if it's not you.
1266 1313
 	elseif ($user_info['id'] != $userReceiver)
@@ -1326,13 +1373,15 @@  discard block
 block discarded – undo
1326 1373
 	);
1327 1374
 
1328 1375
 	$members = array();
1329
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1330
-		$members[] = $row;
1376
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1377
+			$members[] = $row;
1378
+	}
1331 1379
 	$smcFunc['db_free_result']($request);
1332 1380
 
1333 1381
 	// If we want duplicates pass the members array off.
1334
-	if ($get_duplicates)
1335
-		populateDuplicateMembers($members);
1382
+	if ($get_duplicates) {
1383
+			populateDuplicateMembers($members);
1384
+	}
1336 1385
 
1337 1386
 	return $members;
1338 1387
 }
@@ -1349,8 +1398,9 @@  discard block
 block discarded – undo
1349 1398
 	global $smcFunc, $modSettings;
1350 1399
 
1351 1400
 	// We know how many members there are in total.
1352
-	if (empty($where) || $where == '1=1')
1353
-		$num_members = $modSettings['totalMembers'];
1401
+	if (empty($where) || $where == '1=1') {
1402
+			$num_members = $modSettings['totalMembers'];
1403
+	}
1354 1404
 
1355 1405
 	// The database knows the amount when there are extra conditions.
1356 1406
 	else
@@ -1386,16 +1436,19 @@  discard block
 block discarded – undo
1386 1436
 		$members[$key]['duplicate_members'] = array();
1387 1437
 
1388 1438
 		// Store the IPs.
1389
-		if (!empty($member['member_ip']))
1390
-			$ips[] = $member['member_ip'];
1391
-		if (!empty($member['member_ip2']))
1392
-			$ips[] = $member['member_ip2'];
1439
+		if (!empty($member['member_ip'])) {
1440
+					$ips[] = $member['member_ip'];
1441
+		}
1442
+		if (!empty($member['member_ip2'])) {
1443
+					$ips[] = $member['member_ip2'];
1444
+		}
1393 1445
 	}
1394 1446
 
1395 1447
 	$ips = array_unique($ips);
1396 1448
 
1397
-	if (empty($ips))
1398
-		return false;
1449
+	if (empty($ips)) {
1450
+			return false;
1451
+	}
1399 1452
 
1400 1453
 	// Fetch all members with this IP address, we'll filter out the current ones in a sec.
1401 1454
 	$request = $smcFunc['db_query']('', '
@@ -1423,10 +1476,12 @@  discard block
 block discarded – undo
1423 1476
 			'ip2' => $row['member_ip2'],
1424 1477
 		);
1425 1478
 
1426
-		if (in_array($row['member_ip'], $ips))
1427
-			$duplicate_members[$row['member_ip']][] = $member_context;
1428
-		if ($row['member_ip'] != $row['member_ip2'] && in_array($row['member_ip2'], $ips))
1429
-			$duplicate_members[$row['member_ip2']][] = $member_context;
1479
+		if (in_array($row['member_ip'], $ips)) {
1480
+					$duplicate_members[$row['member_ip']][] = $member_context;
1481
+		}
1482
+		if ($row['member_ip'] != $row['member_ip2'] && in_array($row['member_ip2'], $ips)) {
1483
+					$duplicate_members[$row['member_ip2']][] = $member_context;
1484
+		}
1430 1485
 	}
1431 1486
 	$smcFunc['db_free_result']($request);
1432 1487
 
@@ -1449,8 +1504,9 @@  discard block
 block discarded – undo
1449 1504
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1450 1505
 	{
1451 1506
 		// Don't collect lots of the same.
1452
-		if (isset($had_ips[$row['poster_ip']]) && in_array($row['id_member'], $had_ips[$row['poster_ip']]))
1453
-			continue;
1507
+		if (isset($had_ips[$row['poster_ip']]) && in_array($row['id_member'], $had_ips[$row['poster_ip']])) {
1508
+					continue;
1509
+		}
1454 1510
 		$had_ips[$row['poster_ip']][] = $row['id_member'];
1455 1511
 
1456 1512
 		$duplicate_members[$row['poster_ip']][] = array(
@@ -1465,13 +1521,15 @@  discard block
 block discarded – undo
1465 1521
 	$smcFunc['db_free_result']($request);
1466 1522
 
1467 1523
 	// Now we have all the duplicate members, stick them with their respective member in the list.
1468
-	if (!empty($duplicate_members))
1469
-		foreach ($members as $key => $member)
1524
+	if (!empty($duplicate_members)) {
1525
+			foreach ($members as $key => $member)
1470 1526
 		{
1471 1527
 			if (isset($duplicate_members[$member['member_ip']]))
1472 1528
 				$members[$key]['duplicate_members'] = $duplicate_members[$member['member_ip']];
1473
-			if ($member['member_ip'] != $member['member_ip2'] && isset($duplicate_members[$member['member_ip2']]))
1474
-				$members[$key]['duplicate_members'] = array_merge($member['duplicate_members'], $duplicate_members[$member['member_ip2']]);
1529
+	}
1530
+			if ($member['member_ip'] != $member['member_ip2'] && isset($duplicate_members[$member['member_ip2']])) {
1531
+							$members[$key]['duplicate_members'] = array_merge($member['duplicate_members'], $duplicate_members[$member['member_ip2']]);
1532
+			}
1475 1533
 
1476 1534
 			// Check we don't have lots of the same member.
1477 1535
 			$member_track = array($member['id_member']);
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] = 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] = 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 3 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
 {
@@ -3244,7 +3244,7 @@  discard block
 block discarded – undo
3244 3244
 	 * http://www.php.net/crc32#79567
3245 3245
 	 *
3246 3246
 	 * @param string $number
3247
-	 * @return string The crc32
3247
+	 * @return integer The crc32
3248 3248
 	 */
3249 3249
 	function smf_crc32($number)
3250 3250
 	{
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 
573 573
 	// Don't want to mess with code...
574 574
 	$types = array('install', 'uninstall', 'upgrade');
575
-	foreach($types as $type)
575
+	foreach ($types as $type)
576 576
 	{
577 577
 		if (isset($package[$type]['code']))
578 578
 		{
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 						'value' => $txt['package_restore_permissions_cur_status'],
698 698
 					),
699 699
 					'data' => array(
700
-						'function' => function ($rowData) use ($txt)
700
+						'function' => function($rowData) use ($txt)
701 701
 						{
702 702
 							$formatTxt = $rowData['result'] == '' || $rowData['result'] == 'skipped' ? $txt['package_restore_permissions_pre_change'] : $txt['package_restore_permissions_post_change'];
703 703
 							return sprintf($formatTxt, $rowData['cur_perms'], $rowData['new_perms'], $rowData['writable_message']);
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 						'value' => $txt['package_restore_permissions_result'],
726 726
 					),
727 727
 					'data' => array(
728
-						'function' => function ($rowData) use ($txt)
728
+						'function' => function($rowData) use ($txt)
729 729
 						{
730 730
 							return $txt['package_restore_permissions_action_' . $rowData['result']];
731 731
 						},
@@ -1195,7 +1195,7 @@  discard block
 block discarded – undo
1195 1195
 				if ($action->exists('@lang'))
1196 1196
 				{
1197 1197
 					// Auto-select the language based on either request variable or current language.
1198
-					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))
1198
+					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 1199
 					{
1200 1200
 						// In case the user put the blocks in the wrong order.
1201 1201
 						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default')
@@ -1243,7 +1243,7 @@  discard block
 block discarded – undo
1243 1243
 				'redirect_url' => $action->exists('@url') ? $action->fetch('@url') : '',
1244 1244
 				'redirect_timeout' => $action->exists('@timeout') ? (int) $action->fetch('@timeout') : '',
1245 1245
 				'parse_bbc' => $action->exists('@parsebbc') && $action->fetch('@parsebbc') == 'true',
1246
-				'language' => (($actionType == 'readme' || $actionType == 'license')  && $action->exists('@lang') && $action->fetch('@lang') == $language) ? $language : '',
1246
+				'language' => (($actionType == 'readme' || $actionType == 'license') && $action->exists('@lang') && $action->fetch('@lang') == $language) ? $language : '',
1247 1247
 			);
1248 1248
 
1249 1249
 			continue;
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,32 +3195,35 @@  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);
3051 3225
 		$a->compress(Phar::GZ);
3052
-	}
3053
-	catch (Exception $e)
3226
+	} catch (Exception $e)
3054 3227
 	{
3055 3228
 		log_error($e->getMessage(), 'backup');
3056 3229
 
@@ -3082,32 +3255,35 @@  discard block
 block discarded – undo
3082 3255
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
3083 3256
 
3084 3257
 	// An FTP url. We should try connecting and RETRieving it...
3085
-	if (empty($match[1]))
3086
-		return false;
3087
-	elseif ($match[1] == 'ftp')
3258
+	if (empty($match[1])) {
3259
+			return false;
3260
+	} elseif ($match[1] == 'ftp')
3088 3261
 	{
3089 3262
 		// Include the file containing the ftp_connection class.
3090 3263
 		require_once($sourcedir . '/Class-Package.php');
3091 3264
 
3092 3265
 		// Establish a connection and attempt to enable passive mode.
3093 3266
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
3094
-		if ($ftp->error !== false || !$ftp->passive())
3095
-			return false;
3267
+		if ($ftp->error !== false || !$ftp->passive()) {
3268
+					return false;
3269
+		}
3096 3270
 
3097 3271
 		// I want that one *points*!
3098 3272
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
3099 3273
 
3100 3274
 		// Since passive mode worked (or we would have returned already!) open the connection.
3101 3275
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
3102
-		if (!$fp)
3103
-			return false;
3276
+		if (!$fp) {
3277
+					return false;
3278
+		}
3104 3279
 
3105 3280
 		// The server should now say something in acknowledgement.
3106 3281
 		$ftp->check_response(150);
3107 3282
 
3108 3283
 		$data = '';
3109
-		while (!feof($fp))
3110
-			$data .= fread($fp, 4096);
3284
+		while (!feof($fp)) {
3285
+					$data .= fread($fp, 4096);
3286
+		}
3111 3287
 		fclose($fp);
3112 3288
 
3113 3289
 		// All done, right?  Good.
@@ -3124,22 +3300,25 @@  discard block
 block discarded – undo
3124 3300
 		$fetch_data->get_url_data($url, $post_data);
3125 3301
 
3126 3302
 		// no errors and a 200 result, then we have a good dataset, well we at least have data ;)
3127
-		if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
3128
-			$data = $fetch_data->result('body');
3129
-		else
3130
-			return false;
3303
+		if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
3304
+					$data = $fetch_data->result('body');
3305
+		} else {
3306
+					return false;
3307
+		}
3131 3308
 	}
3132 3309
 	// This is more likely; a standard HTTP URL.
3133 3310
 	elseif (isset($match[1]) && $match[1] == 'http')
3134 3311
 	{
3135
-		if ($keep_alive && $match[3] == $keep_alive_dom)
3136
-			$fp = $keep_alive_fp;
3312
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
3313
+					$fp = $keep_alive_fp;
3314
+		}
3137 3315
 		if (empty($fp))
3138 3316
 		{
3139 3317
 			// Open the socket on the port we want...
3140 3318
 			$fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? ($match[2] ? 443 : 80) : $match[5], $err, $err, 5);
3141
-			if (!$fp)
3142
-				return false;
3319
+			if (!$fp) {
3320
+							return false;
3321
+			}
3143 3322
 		}
3144 3323
 
3145 3324
 		if ($keep_alive)
@@ -3154,20 +3333,21 @@  discard block
 block discarded – undo
3154 3333
 			fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
3155 3334
 			fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
3156 3335
 			fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n");
3157
-			if ($keep_alive)
3158
-				fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n");
3159
-			else
3160
-				fwrite($fp, 'Connection: close' . "\r\n\r\n");
3161
-		}
3162
-		else
3336
+			if ($keep_alive) {
3337
+							fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n");
3338
+			} else {
3339
+							fwrite($fp, 'Connection: close' . "\r\n\r\n");
3340
+			}
3341
+		} else
3163 3342
 		{
3164 3343
 			fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
3165 3344
 			fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
3166 3345
 			fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n");
3167
-			if ($keep_alive)
3168
-				fwrite($fp, 'Connection: Keep-Alive' . "\r\n");
3169
-			else
3170
-				fwrite($fp, 'Connection: close' . "\r\n");
3346
+			if ($keep_alive) {
3347
+							fwrite($fp, 'Connection: Keep-Alive' . "\r\n");
3348
+			} else {
3349
+							fwrite($fp, 'Connection: close' . "\r\n");
3350
+			}
3171 3351
 			fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n");
3172 3352
 			fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n");
3173 3353
 			fwrite($fp, $post_data);
@@ -3180,30 +3360,33 @@  discard block
 block discarded – undo
3180 3360
 		{
3181 3361
 			$header = '';
3182 3362
 			$location = '';
3183
-			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
3184
-				if (strpos($header, 'Location:') !== false)
3363
+			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
3364
+							if (strpos($header, 'Location:') !== false)
3185 3365
 					$location = trim(substr($header, strpos($header, ':') + 1));
3366
+			}
3186 3367
 
3187
-			if (empty($location))
3188
-				return false;
3189
-			else
3368
+			if (empty($location)) {
3369
+							return false;
3370
+			} else
3190 3371
 			{
3191
-				if (!$keep_alive)
3192
-					fclose($fp);
3372
+				if (!$keep_alive) {
3373
+									fclose($fp);
3374
+				}
3193 3375
 				return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
3194 3376
 			}
3195 3377
 		}
3196 3378
 
3197 3379
 		// Make sure we get a 200 OK.
3198
-		elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
3199
-			return false;
3380
+		elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
3381
+					return false;
3382
+		}
3200 3383
 
3201 3384
 		// Skip the headers...
3202 3385
 		while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
3203 3386
 		{
3204
-			if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
3205
-				$content_length = $match[1];
3206
-			elseif (preg_match('~connection:\s*close~i', $header) != 0)
3387
+			if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
3388
+							$content_length = $match[1];
3389
+			} elseif (preg_match('~connection:\s*close~i', $header) != 0)
3207 3390
 			{
3208 3391
 				$keep_alive_dom = null;
3209 3392
 				$keep_alive = false;
@@ -3215,19 +3398,20 @@  discard block
 block discarded – undo
3215 3398
 		$data = '';
3216 3399
 		if (isset($content_length))
3217 3400
 		{
3218
-			while (!feof($fp) && strlen($data) < $content_length)
3219
-				$data .= fread($fp, $content_length - strlen($data));
3220
-		}
3221
-		else
3401
+			while (!feof($fp) && strlen($data) < $content_length) {
3402
+							$data .= fread($fp, $content_length - strlen($data));
3403
+			}
3404
+		} else
3222 3405
 		{
3223
-			while (!feof($fp))
3224
-				$data .= fread($fp, 4096);
3406
+			while (!feof($fp)) {
3407
+							$data .= fread($fp, 4096);
3408
+			}
3225 3409
 		}
3226 3410
 
3227
-		if (!$keep_alive)
3228
-			fclose($fp);
3229
-	}
3230
-	else
3411
+		if (!$keep_alive) {
3412
+					fclose($fp);
3413
+		}
3414
+	} else
3231 3415
 	{
3232 3416
 		// Umm, this shouldn't happen?
3233 3417
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
Please login to merge, or discard this patch.