Completed
Push — release-2.1 ( 29f159...8a60e5 )
by Michael
26:37 queued 18:07
created
other/install.php 1 patch
Braces   +438 added lines, -326 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 			
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 			
66
-			if ($charcode == 'UTF8')			
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -74,12 +76,14 @@  discard block
 block discarded – undo
74 76
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
75 77
 
76 78
 			// Is it reserved?
77
-			if ($value == 'pg_')
78
-				return $txt['error_db_prefix_reserved'];
79
+			if ($value == 'pg_') {
80
+							return $txt['error_db_prefix_reserved'];
81
+			}
79 82
 
80 83
 			// Is the prefix numeric?
81
-			if (preg_match('~^\d~', $value))
82
-				return $txt['error_db_prefix_numeric'];
84
+			if (preg_match('~^\d~', $value)) {
85
+							return $txt['error_db_prefix_numeric'];
86
+			}
83 87
 
84 88
 			return true;
85 89
 		},
@@ -124,10 +128,11 @@  discard block
 block discarded – undo
124 128
 		$incontext['skip'] = false;
125 129
 
126 130
 		// Call the step and if it returns false that means pause!
127
-		if (function_exists($step[2]) && $step[2]() === false)
128
-			break;
129
-		elseif (function_exists($step[2]))
130
-			$incontext['current_step']++;
131
+		if (function_exists($step[2]) && $step[2]() === false) {
132
+					break;
133
+		} elseif (function_exists($step[2])) {
134
+					$incontext['current_step']++;
135
+		}
131 136
 
132 137
 		// No warnings pass on.
133 138
 		$incontext['warning'] = '';
@@ -143,12 +148,14 @@  discard block
 block discarded – undo
143 148
 	global $databases, $incontext;
144 149
 
145 150
 	// Just so people using older versions of PHP aren't left in the cold.
146
-	if (!isset($_SERVER['PHP_SELF']))
147
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
151
+	if (!isset($_SERVER['PHP_SELF'])) {
152
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
153
+	}
148 154
 
149 155
 	// Turn off magic quotes runtime and enable error reporting.
150
-	if (function_exists('set_magic_quotes_runtime'))
151
-		@set_magic_quotes_runtime(0);
156
+	if (function_exists('set_magic_quotes_runtime')) {
157
+			@set_magic_quotes_runtime(0);
158
+	}
152 159
 	error_reporting(E_ALL);
153 160
 
154 161
 	// Fun.  Low PHP version...
@@ -162,21 +169,23 @@  discard block
 block discarded – undo
162 169
 	{
163 170
 		ob_start();
164 171
 
165
-		if (ini_get('session.save_handler') == 'user')
166
-			@ini_set('session.save_handler', 'files');
167
-		if (function_exists('session_start'))
168
-			@session_start();
169
-	}
170
-	else
172
+		if (ini_get('session.save_handler') == 'user') {
173
+					@ini_set('session.save_handler', 'files');
174
+		}
175
+		if (function_exists('session_start')) {
176
+					@session_start();
177
+		}
178
+	} else
171 179
 	{
172 180
 		ob_start('ob_gzhandler');
173 181
 
174
-		if (ini_get('session.save_handler') == 'user')
175
-			@ini_set('session.save_handler', 'files');
182
+		if (ini_get('session.save_handler') == 'user') {
183
+					@ini_set('session.save_handler', 'files');
184
+		}
176 185
 		session_start();
177 186
 
178
-		if (!headers_sent())
179
-			echo '<!DOCTYPE html>
187
+		if (!headers_sent()) {
188
+					echo '<!DOCTYPE html>
180 189
 <html>
181 190
 	<head>
182 191
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -185,14 +194,16 @@  discard block
 block discarded – undo
185 194
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
186 195
 	</body>
187 196
 </html>';
197
+		}
188 198
 		exit;
189 199
 	}
190 200
 
191 201
 	// Add slashes, as long as they aren't already being added.
192
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
193
-		foreach ($_POST as $k => $v)
202
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
203
+			foreach ($_POST as $k => $v)
194 204
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
195 205
 				$_POST[$k] = addslashes($v);
206
+	}
196 207
 
197 208
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
198 209
 	if (isset($_GET['delete']))
@@ -213,8 +224,7 @@  discard block
 block discarded – undo
213 224
 			$ftp->close();
214 225
 
215 226
 			unset($_SESSION['installer_temp_ftp']);
216
-		}
217
-		else
227
+		} else
218 228
 		{
219 229
 			@unlink(__FILE__);
220 230
 
@@ -235,10 +245,11 @@  discard block
 block discarded – undo
235 245
 	{
236 246
 		// Get PHP's default timezone, if set
237 247
 		$ini_tz = ini_get('date.timezone');
238
-		if (!empty($ini_tz))
239
-			$timezone_id = $ini_tz;
240
-		else
241
-			$timezone_id = '';
248
+		if (!empty($ini_tz)) {
249
+					$timezone_id = $ini_tz;
250
+		} else {
251
+					$timezone_id = '';
252
+		}
242 253
 
243 254
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
244 255
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -268,8 +279,9 @@  discard block
 block discarded – undo
268 279
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
269 280
 		while ($entry = $dir->read())
270 281
 		{
271
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
272
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
282
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
283
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
284
+			}
273 285
 		}
274 286
 		$dir->close();
275 287
 	}
@@ -304,10 +316,11 @@  discard block
 block discarded – undo
304 316
 	}
305 317
 
306 318
 	// Override the language file?
307
-	if (isset($_GET['lang_file']))
308
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
309
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
310
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
319
+	if (isset($_GET['lang_file'])) {
320
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
321
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
322
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
323
+	}
311 324
 
312 325
 	// Make sure it exists, if it doesn't reset it.
313 326
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -316,8 +329,9 @@  discard block
 block discarded – undo
316 329
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
317 330
 
318 331
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
319
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
320
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
332
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
333
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
334
+		}
321 335
 	}
322 336
 
323 337
 	// And now include the actual language file itself.
@@ -330,15 +344,18 @@  discard block
 block discarded – undo
330 344
 	global $db_prefix, $db_connection, $sourcedir;
331 345
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
332 346
 
333
-	if (empty($sourcedir))
334
-		$sourcedir = dirname(__FILE__) . '/Sources';
347
+	if (empty($sourcedir)) {
348
+			$sourcedir = dirname(__FILE__) . '/Sources';
349
+	}
335 350
 
336 351
 	// Need this to check whether we need the database password.
337 352
 	require(dirname(__FILE__) . '/Settings.php');
338
-	if (!defined('SMF'))
339
-		define('SMF', 1);
340
-	if (empty($smcFunc))
341
-		$smcFunc = array();
353
+	if (!defined('SMF')) {
354
+			define('SMF', 1);
355
+	}
356
+	if (empty($smcFunc)) {
357
+			$smcFunc = array();
358
+	}
342 359
 
343 360
 	$modSettings['disableQueryCheck'] = true;
344 361
 
@@ -346,8 +363,9 @@  discard block
 block discarded – undo
346 363
 	if (!$db_connection)
347 364
 	{
348 365
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
349
-		if (version_compare(PHP_VERSION, '5', '<'))
350
-			require_once($sourcedir . '/Subs-Compat.php');
366
+		if (version_compare(PHP_VERSION, '5', '<')) {
367
+					require_once($sourcedir . '/Subs-Compat.php');
368
+		}
351 369
 
352 370
 		$db_options = array('persist' => $db_persist);
353 371
 		$port = '';
@@ -358,19 +376,20 @@  discard block
 block discarded – undo
358 376
 			if ($db_type == 'mysql')
359 377
 			{
360 378
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
361
-			}
362
-			elseif ($db_type == 'postgresql')
379
+			} elseif ($db_type == 'postgresql')
363 380
 			{
364 381
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
365 382
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
366 383
 			}
367 384
 		}
368 385
 
369
-		if (!empty($port))
370
-			$db_options['port'] = $port;
386
+		if (!empty($port)) {
387
+					$db_options['port'] = $port;
388
+		}
371 389
 
372
-		if (!$db_connection)
373
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
390
+		if (!$db_connection) {
391
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
392
+		}
374 393
 	}
375 394
 }
376 395
 
@@ -398,8 +417,9 @@  discard block
 block discarded – undo
398 417
 		// @todo REMOVE THIS!!
399 418
 		else
400 419
 		{
401
-			if (function_exists('doStep' . $_GET['step']))
402
-				call_user_func('doStep' . $_GET['step']);
420
+			if (function_exists('doStep' . $_GET['step'])) {
421
+							call_user_func('doStep' . $_GET['step']);
422
+			}
403 423
 		}
404 424
 		// Show the footer.
405 425
 		template_install_below();
@@ -417,8 +437,9 @@  discard block
 block discarded – undo
417 437
 	$incontext['sub_template'] = 'welcome_message';
418 438
 
419 439
 	// Done the submission?
420
-	if (isset($_POST['contbutt']))
421
-		return true;
440
+	if (isset($_POST['contbutt'])) {
441
+			return true;
442
+	}
422 443
 
423 444
 	// See if we think they have already installed it?
424 445
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -426,14 +447,17 @@  discard block
 block discarded – undo
426 447
 		$probably_installed = 0;
427 448
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
428 449
 		{
429
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
430
-				$probably_installed++;
431
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
432
-				$probably_installed++;
450
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
451
+							$probably_installed++;
452
+			}
453
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
454
+							$probably_installed++;
455
+			}
433 456
 		}
434 457
 
435
-		if ($probably_installed == 2)
436
-			$incontext['warning'] = $txt['error_already_installed'];
458
+		if ($probably_installed == 2) {
459
+					$incontext['warning'] = $txt['error_already_installed'];
460
+		}
437 461
 	}
438 462
 
439 463
 	// Is some database support even compiled in?
@@ -448,36 +472,43 @@  discard block
 block discarded – undo
448 472
 				$databases[$key]['supported'] = false;
449 473
 				$notFoundSQLFile = true;
450 474
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
475
+			} else {
476
+							$incontext['supported_databases'][] = $db;
451 477
 			}
452
-			else
453
-				$incontext['supported_databases'][] = $db;
454 478
 		}
455 479
 	}
456 480
 
457 481
 	// Check the PHP version.
458
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
459
-		$error = 'error_php_too_low';
482
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
483
+			$error = 'error_php_too_low';
484
+	}
460 485
 	// Make sure we have a supported database
461
-	elseif (empty($incontext['supported_databases']))
462
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
486
+	elseif (empty($incontext['supported_databases'])) {
487
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
488
+	}
463 489
 	// How about session support?  Some crazy sysadmin remove it?
464
-	elseif (!function_exists('session_start'))
465
-		$error = 'error_session_missing';
490
+	elseif (!function_exists('session_start')) {
491
+			$error = 'error_session_missing';
492
+	}
466 493
 	// Make sure they uploaded all the files.
467
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
468
-		$error = 'error_missing_files';
494
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
495
+			$error = 'error_missing_files';
496
+	}
469 497
 	// Very simple check on the session.save_path for Windows.
470 498
 	// @todo Move this down later if they don't use database-driven sessions?
471
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
472
-		$error = 'error_session_save_path';
499
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
500
+			$error = 'error_session_save_path';
501
+	}
473 502
 
474 503
 	// Since each of the three messages would look the same, anyway...
475
-	if (isset($error))
476
-		$incontext['error'] = $txt[$error];
504
+	if (isset($error)) {
505
+			$incontext['error'] = $txt[$error];
506
+	}
477 507
 
478 508
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
479
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
480
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
509
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
510
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
511
+	}
481 512
 
482 513
 	return false;
483 514
 }
@@ -503,12 +534,14 @@  discard block
 block discarded – undo
503 534
 		'db_last_error.php',
504 535
 	);
505 536
 
506
-	foreach ($incontext['detected_languages'] as $lang => $temp)
507
-		$extra_files[] = 'Themes/default/languages/' . $lang;
537
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
538
+			$extra_files[] = 'Themes/default/languages/' . $lang;
539
+	}
508 540
 
509 541
 	// With mod_security installed, we could attempt to fix it with .htaccess.
510
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
511
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
542
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
543
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
544
+	}
512 545
 
513 546
 	$failed_files = array();
514 547
 
@@ -524,12 +557,14 @@  discard block
 block discarded – undo
524 557
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
525 558
 
526 559
 				// Well, 755 hopefully worked... if not, try 777.
527
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
528
-					$failed_files[] = $file;
560
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
561
+									$failed_files[] = $file;
562
+				}
529 563
 			}
530 564
 		}
531
-		foreach ($extra_files as $file)
532
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
565
+		foreach ($extra_files as $file) {
566
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
567
+		}
533 568
 	}
534 569
 	// Windows is trickier.  Let's try opening for r+...
535 570
 	else
@@ -539,30 +574,35 @@  discard block
 block discarded – undo
539 574
 		foreach ($writable_files as $file)
540 575
 		{
541 576
 			// Folders can't be opened for write... but the index.php in them can ;)
542
-			if (is_dir(dirname(__FILE__) . '/' . $file))
543
-				$file .= '/index.php';
577
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
578
+							$file .= '/index.php';
579
+			}
544 580
 
545 581
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
546 582
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
547 583
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
548 584
 
549 585
 			// Hmm, okay, try just for write in that case...
550
-			if (!is_resource($fp))
551
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
586
+			if (!is_resource($fp)) {
587
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
588
+			}
552 589
 
553
-			if (!is_resource($fp))
554
-				$failed_files[] = $file;
590
+			if (!is_resource($fp)) {
591
+							$failed_files[] = $file;
592
+			}
555 593
 
556 594
 			@fclose($fp);
557 595
 		}
558
-		foreach ($extra_files as $file)
559
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
596
+		foreach ($extra_files as $file) {
597
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
598
+		}
560 599
 	}
561 600
 
562 601
 	$failure = count($failed_files) >= 1;
563 602
 
564
-	if (!isset($_SERVER))
565
-		return !$failure;
603
+	if (!isset($_SERVER)) {
604
+			return !$failure;
605
+	}
566 606
 
567 607
 	// Put the list into context.
568 608
 	$incontext['failed_files'] = $failed_files;
@@ -610,19 +650,23 @@  discard block
 block discarded – undo
610 650
 
611 651
 		if (!isset($ftp) || $ftp->error !== false)
612 652
 		{
613
-			if (!isset($ftp))
614
-				$ftp = new ftp_connection(null);
653
+			if (!isset($ftp)) {
654
+							$ftp = new ftp_connection(null);
655
+			}
615 656
 			// Save the error so we can mess with listing...
616
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
617
-				$incontext['ftp_errors'][] = $ftp->last_message;
657
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
658
+							$incontext['ftp_errors'][] = $ftp->last_message;
659
+			}
618 660
 
619 661
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
620 662
 
621
-			if (empty($_POST['ftp_path']) && $found_path)
622
-				$_POST['ftp_path'] = $detect_path;
663
+			if (empty($_POST['ftp_path']) && $found_path) {
664
+							$_POST['ftp_path'] = $detect_path;
665
+			}
623 666
 
624
-			if (!isset($_POST['ftp_username']))
625
-				$_POST['ftp_username'] = $username;
667
+			if (!isset($_POST['ftp_username'])) {
668
+							$_POST['ftp_username'] = $username;
669
+			}
626 670
 
627 671
 			// Set the username etc, into context.
628 672
 			$incontext['ftp'] = array(
@@ -634,8 +678,7 @@  discard block
 block discarded – undo
634 678
 			);
635 679
 
636 680
 			return false;
637
-		}
638
-		else
681
+		} else
639 682
 		{
640 683
 			$_SESSION['installer_temp_ftp'] = array(
641 684
 				'server' => $_POST['ftp_server'],
@@ -649,10 +692,12 @@  discard block
 block discarded – undo
649 692
 
650 693
 			foreach ($failed_files as $file)
651 694
 			{
652
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
653
-					$ftp->chmod($file, 0755);
654
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
655
-					$ftp->chmod($file, 0777);
695
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
696
+									$ftp->chmod($file, 0755);
697
+				}
698
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
699
+									$ftp->chmod($file, 0777);
700
+				}
656 701
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
657 702
 				{
658 703
 					$failed_files_updated[] = $file;
@@ -707,15 +752,17 @@  discard block
 block discarded – undo
707 752
 
708 753
 			if (!$foundOne)
709 754
 			{
710
-				if (isset($db['default_host']))
711
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
755
+				if (isset($db['default_host'])) {
756
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
757
+				}
712 758
 				if (isset($db['default_user']))
713 759
 				{
714 760
 					$incontext['db']['user'] = ini_get($db['default_user']);
715 761
 					$incontext['db']['name'] = ini_get($db['default_user']);
716 762
 				}
717
-				if (isset($db['default_password']))
718
-					$incontext['db']['pass'] = ini_get($db['default_password']);
763
+				if (isset($db['default_password'])) {
764
+									$incontext['db']['pass'] = ini_get($db['default_password']);
765
+				}
719 766
 
720 767
 				// For simplicity and less confusion, leave the port blank by default
721 768
 				$incontext['db']['port'] = '';
@@ -734,10 +781,10 @@  discard block
 block discarded – undo
734 781
 		$incontext['db']['server'] = $_POST['db_server'];
735 782
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
736 783
 
737
-		if (!empty($_POST['db_port']))
738
-			$incontext['db']['port'] = $_POST['db_port'];
739
-	}
740
-	else
784
+		if (!empty($_POST['db_port'])) {
785
+					$incontext['db']['port'] = $_POST['db_port'];
786
+		}
787
+	} else
741 788
 	{
742 789
 		$incontext['db']['prefix'] = 'smf_';
743 790
 	}
@@ -773,10 +820,11 @@  discard block
 block discarded – undo
773 820
 		if (!empty($_POST['db_port']))
774 821
 		{
775 822
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
776
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
777
-				$vars['db_port'] = (int) $_POST['db_port'];
778
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
779
-				$vars['db_port'] = (int) $_POST['db_port'];
823
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
824
+							$vars['db_port'] = (int) $_POST['db_port'];
825
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
826
+							$vars['db_port'] = (int) $_POST['db_port'];
827
+			}
780 828
 		}
781 829
 
782 830
 		// God I hope it saved!
@@ -789,8 +837,9 @@  discard block
 block discarded – undo
789 837
 		// Make sure it works.
790 838
 		require(dirname(__FILE__) . '/Settings.php');
791 839
 
792
-		if (empty($sourcedir))
793
-			$sourcedir = dirname(__FILE__) . '/Sources';
840
+		if (empty($sourcedir)) {
841
+					$sourcedir = dirname(__FILE__) . '/Sources';
842
+		}
794 843
 
795 844
 		// Better find the database file!
796 845
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -800,18 +849,21 @@  discard block
 block discarded – undo
800 849
 		}
801 850
 
802 851
 		// Now include it for database functions!
803
-		if (!defined('SMF'))
804
-			define('SMF', 1);
852
+		if (!defined('SMF')) {
853
+					define('SMF', 1);
854
+		}
805 855
 
806 856
 		$modSettings['disableQueryCheck'] = true;
807
-		if (empty($smcFunc))
808
-			$smcFunc = array();
857
+		if (empty($smcFunc)) {
858
+					$smcFunc = array();
859
+		}
809 860
 
810 861
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
811 862
 
812 863
 		// What - running PHP4? The shame!
813
-		if (version_compare(PHP_VERSION, '5', '<'))
814
-			require_once($sourcedir . '/Subs-Compat.php');
864
+		if (version_compare(PHP_VERSION, '5', '<')) {
865
+					require_once($sourcedir . '/Subs-Compat.php');
866
+		}
815 867
 
816 868
 		// Attempt a connection.
817 869
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -899,12 +951,14 @@  discard block
 block discarded – undo
899 951
 	$incontext['page_title'] = $txt['install_settings'];
900 952
 
901 953
 	// Let's see if we got the database type correct.
902
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
903
-		$db_type = $_POST['db_type'];
954
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
955
+			$db_type = $_POST['db_type'];
956
+	}
904 957
 
905 958
 	// Else we'd better be able to get the connection.
906
-	else
907
-		load_database();
959
+	else {
960
+			load_database();
961
+	}
908 962
 
909 963
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
910 964
 
@@ -924,12 +978,14 @@  discard block
 block discarded – undo
924 978
 	// Submitting?
925 979
 	if (isset($_POST['boardurl']))
926 980
 	{
927
-		if (substr($_POST['boardurl'], -10) == '/index.php')
928
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
929
-		elseif (substr($_POST['boardurl'], -1) == '/')
930
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
931
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
932
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
981
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
982
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
983
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
984
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
985
+		}
986
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
987
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
988
+		}
933 989
 
934 990
 		// Save these variables.
935 991
 		$vars = array(
@@ -966,10 +1022,10 @@  discard block
 block discarded – undo
966 1022
 			{
967 1023
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
968 1024
 				return false;
969
-			}
970
-			else
971
-				// Set the character set here.
1025
+			} else {
1026
+							// Set the character set here.
972 1027
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1028
+			}
973 1029
 		}
974 1030
 
975 1031
 		// Good, skip on.
@@ -989,8 +1045,9 @@  discard block
 block discarded – undo
989 1045
 	$incontext['continue'] = 1;
990 1046
 
991 1047
 	// Already done?
992
-	if (isset($_POST['pop_done']))
993
-		return true;
1048
+	if (isset($_POST['pop_done'])) {
1049
+			return true;
1050
+	}
994 1051
 
995 1052
 	// Reload settings.
996 1053
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1008,8 +1065,9 @@  discard block
 block discarded – undo
1008 1065
 	$modSettings = array();
1009 1066
 	if ($result !== false)
1010 1067
 	{
1011
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1012
-			$modSettings[$row['variable']] = $row['value'];
1068
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1069
+					$modSettings[$row['variable']] = $row['value'];
1070
+		}
1013 1071
 		$smcFunc['db_free_result']($result);
1014 1072
 
1015 1073
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1022,20 +1080,22 @@  discard block
 block discarded – undo
1022 1080
 	$modSettings['disableQueryCheck'] = true;
1023 1081
 
1024 1082
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1025
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1026
-		$smcFunc['db_query']('', '
1083
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1084
+			$smcFunc['db_query']('', '
1027 1085
 			SET NAMES {string:utf8}',
1028 1086
 			array(
1029 1087
 				'db_error_skip' => true,
1030 1088
 				'utf8' => 'utf8',
1031 1089
 			)
1032 1090
 		);
1091
+	}
1033 1092
 
1034 1093
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1035
-	if (substr(__DIR__, -1) == '\\')
1036
-		$attachdir = __DIR__ . 'attachments';
1037
-	else
1038
-		$attachdir = __DIR__ . '/attachments';
1094
+	if (substr(__DIR__, -1) == '\\') {
1095
+			$attachdir = __DIR__ . 'attachments';
1096
+	} else {
1097
+			$attachdir = __DIR__ . '/attachments';
1098
+	}
1039 1099
 
1040 1100
 	$replaces = array(
1041 1101
 		'{$db_prefix}' => $db_prefix,
@@ -1052,8 +1112,9 @@  discard block
 block discarded – undo
1052 1112
 
1053 1113
 	foreach ($txt as $key => $value)
1054 1114
 	{
1055
-		if (substr($key, 0, 8) == 'default_')
1056
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1115
+		if (substr($key, 0, 8) == 'default_') {
1116
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1117
+		}
1057 1118
 	}
1058 1119
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1059 1120
 
@@ -1068,8 +1129,9 @@  discard block
 block discarded – undo
1068 1129
 
1069 1130
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1070 1131
 		{
1071
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1072
-				$engines[] = $row['Engine'];
1132
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1133
+							$engines[] = $row['Engine'];
1134
+			}
1073 1135
 		}
1074 1136
 
1075 1137
 		// Done with this now
@@ -1093,8 +1155,7 @@  discard block
 block discarded – undo
1093 1155
 			$replaces['START TRANSACTION;'] = '';
1094 1156
 			$replaces['COMMIT;'] = '';
1095 1157
 		}
1096
-	}
1097
-	else
1158
+	} else
1098 1159
 	{
1099 1160
 		$has_innodb = false;
1100 1161
 	}
@@ -1116,21 +1177,24 @@  discard block
 block discarded – undo
1116 1177
 	foreach ($sql_lines as $count => $line)
1117 1178
 	{
1118 1179
 		// No comments allowed!
1119
-		if (substr(trim($line), 0, 1) != '#')
1120
-			$current_statement .= "\n" . rtrim($line);
1180
+		if (substr(trim($line), 0, 1) != '#') {
1181
+					$current_statement .= "\n" . rtrim($line);
1182
+		}
1121 1183
 
1122 1184
 		// Is this the end of the query string?
1123
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1124
-			continue;
1185
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1186
+					continue;
1187
+		}
1125 1188
 
1126 1189
 		// Does this table already exist?  If so, don't insert more data into it!
1127 1190
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1128 1191
 		{
1129 1192
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1130
-			if (!empty($matches[0]))
1131
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1132
-			else
1133
-				$incontext['sql_results']['insert_dups']++;
1193
+			if (!empty($matches[0])) {
1194
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1195
+			} else {
1196
+							$incontext['sql_results']['insert_dups']++;
1197
+			}
1134 1198
 
1135 1199
 			$current_statement = '';
1136 1200
 			continue;
@@ -1139,8 +1203,9 @@  discard block
 block discarded – undo
1139 1203
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1140 1204
 		{
1141 1205
 			// Use the appropriate function based on the DB type
1142
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1143
-				$db_errorno = $db_type . '_errno';
1206
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1207
+							$db_errorno = $db_type . '_errno';
1208
+			}
1144 1209
 
1145 1210
 			// Error 1050: Table already exists!
1146 1211
 			// @todo Needs to be made better!
@@ -1155,18 +1220,18 @@  discard block
 block discarded – undo
1155 1220
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1156 1221
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1157 1222
 			}
1158
-		}
1159
-		else
1223
+		} else
1160 1224
 		{
1161
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1162
-				$incontext['sql_results']['tables']++;
1163
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1225
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1226
+							$incontext['sql_results']['tables']++;
1227
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1164 1228
 			{
1165 1229
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1166
-				if (!empty($matches[0]))
1167
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1168
-				else
1169
-					$incontext['sql_results']['inserts']++;
1230
+				if (!empty($matches[0])) {
1231
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1232
+				} else {
1233
+									$incontext['sql_results']['inserts']++;
1234
+				}
1170 1235
 			}
1171 1236
 		}
1172 1237
 
@@ -1179,15 +1244,17 @@  discard block
 block discarded – undo
1179 1244
 	// Sort out the context for the SQL.
1180 1245
 	foreach ($incontext['sql_results'] as $key => $number)
1181 1246
 	{
1182
-		if ($number == 0)
1183
-			unset($incontext['sql_results'][$key]);
1184
-		else
1185
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1247
+		if ($number == 0) {
1248
+					unset($incontext['sql_results'][$key]);
1249
+		} else {
1250
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1251
+		}
1186 1252
 	}
1187 1253
 
1188 1254
 	// Make sure UTF will be used globally.
1189
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1190
-		$newSettings[] = array('global_character_set', 'UTF-8');
1255
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1256
+			$newSettings[] = array('global_character_set', 'UTF-8');
1257
+	}
1191 1258
 
1192 1259
 	// Maybe we can auto-detect better cookie settings?
1193 1260
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1198,16 +1265,20 @@  discard block
 block discarded – undo
1198 1265
 		$globalCookies = false;
1199 1266
 
1200 1267
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1201
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1202
-			$globalCookies = true;
1268
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1269
+					$globalCookies = true;
1270
+		}
1203 1271
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1204
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1205
-			$localCookies = true;
1272
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1273
+					$localCookies = true;
1274
+		}
1206 1275
 
1207
-		if ($globalCookies)
1208
-			$newSettings[] = array('globalCookies', '1');
1209
-		if ($localCookies)
1210
-			$newSettings[] = array('localCookies', '1');
1276
+		if ($globalCookies) {
1277
+					$newSettings[] = array('globalCookies', '1');
1278
+		}
1279
+		if ($localCookies) {
1280
+					$newSettings[] = array('localCookies', '1');
1281
+		}
1211 1282
 	}
1212 1283
 
1213 1284
 	// Are we allowing stat collection?
@@ -1223,32 +1294,36 @@  discard block
 block discarded – undo
1223 1294
 			fwrite($fp, $out);
1224 1295
 
1225 1296
 			$return_data = '';
1226
-			while (!feof($fp))
1227
-				$return_data .= fgets($fp, 128);
1297
+			while (!feof($fp)) {
1298
+							$return_data .= fgets($fp, 128);
1299
+			}
1228 1300
 
1229 1301
 			fclose($fp);
1230 1302
 
1231 1303
 			// Get the unique site ID.
1232 1304
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1233 1305
 
1234
-			if (!empty($ID[1]))
1235
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1306
+			if (!empty($ID[1])) {
1307
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1308
+			}
1236 1309
 		}
1237 1310
 	}
1238 1311
 
1239 1312
 	// Are we enabling SSL?
1240
-	if (!empty($_POST['force_ssl']))
1241
-		$newSettings[] = array('force_ssl', 2);
1313
+	if (!empty($_POST['force_ssl'])) {
1314
+			$newSettings[] = array('force_ssl', 2);
1315
+	}
1242 1316
 
1243 1317
 	// Setting a timezone is required.
1244 1318
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1245 1319
 	{
1246 1320
 		// Get PHP's default timezone, if set
1247 1321
 		$ini_tz = ini_get('date.timezone');
1248
-		if (!empty($ini_tz))
1249
-			$timezone_id = $ini_tz;
1250
-		else
1251
-			$timezone_id = '';
1322
+		if (!empty($ini_tz)) {
1323
+					$timezone_id = $ini_tz;
1324
+		} else {
1325
+					$timezone_id = '';
1326
+		}
1252 1327
 
1253 1328
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1254 1329
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1257,8 +1332,9 @@  discard block
 block discarded – undo
1257 1332
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1258 1333
 		}
1259 1334
 
1260
-		if (date_default_timezone_set($timezone_id))
1261
-			$newSettings[] = array('default_timezone', $timezone_id);
1335
+		if (date_default_timezone_set($timezone_id)) {
1336
+					$newSettings[] = array('default_timezone', $timezone_id);
1337
+		}
1262 1338
 	}
1263 1339
 
1264 1340
 	if (!empty($newSettings))
@@ -1289,16 +1365,18 @@  discard block
 block discarded – undo
1289 1365
 	}
1290 1366
 
1291 1367
 	// MySQL specific stuff
1292
-	if (substr($db_type, 0, 5) != 'mysql')
1293
-		return false;
1368
+	if (substr($db_type, 0, 5) != 'mysql') {
1369
+			return false;
1370
+	}
1294 1371
 
1295 1372
 	// Find database user privileges.
1296 1373
 	$privs = array();
1297 1374
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1298 1375
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1299 1376
 	{
1300
-		if ($row['Privilege'] == 'Alter')
1301
-			$privs[] = $row['Privilege'];
1377
+		if ($row['Privilege'] == 'Alter') {
1378
+					$privs[] = $row['Privilege'];
1379
+		}
1302 1380
 	}
1303 1381
 	$smcFunc['db_free_result']($get_privs);
1304 1382
 
@@ -1328,8 +1406,9 @@  discard block
 block discarded – undo
1328 1406
 	$incontext['continue'] = 1;
1329 1407
 
1330 1408
 	// Skipping?
1331
-	if (!empty($_POST['skip']))
1332
-		return true;
1409
+	if (!empty($_POST['skip'])) {
1410
+			return true;
1411
+	}
1333 1412
 
1334 1413
 	// Need this to check whether we need the database password.
1335 1414
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1342,18 +1421,22 @@  discard block
 block discarded – undo
1342 1421
 	// We need this to properly hash the password for Admin
1343 1422
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1344 1423
 			global $sourcedir;
1345
-			if (function_exists('mb_strtolower'))
1346
-				return mb_strtolower($string, 'UTF-8');
1424
+			if (function_exists('mb_strtolower')) {
1425
+							return mb_strtolower($string, 'UTF-8');
1426
+			}
1347 1427
 			require_once($sourcedir . '/Subs-Charset.php');
1348 1428
 			return utf8_strtolower($string);
1349 1429
 		};
1350 1430
 
1351
-	if (!isset($_POST['username']))
1352
-		$_POST['username'] = '';
1353
-	if (!isset($_POST['email']))
1354
-		$_POST['email'] = '';
1355
-	if (!isset($_POST['server_email']))
1356
-		$_POST['server_email'] = '';
1431
+	if (!isset($_POST['username'])) {
1432
+			$_POST['username'] = '';
1433
+	}
1434
+	if (!isset($_POST['email'])) {
1435
+			$_POST['email'] = '';
1436
+	}
1437
+	if (!isset($_POST['server_email'])) {
1438
+			$_POST['server_email'] = '';
1439
+	}
1357 1440
 
1358 1441
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1359 1442
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1372,8 +1455,9 @@  discard block
 block discarded – undo
1372 1455
 			'admin_group' => 1,
1373 1456
 		)
1374 1457
 	);
1375
-	if ($smcFunc['db_num_rows']($request) != 0)
1376
-		$incontext['skip'] = 1;
1458
+	if ($smcFunc['db_num_rows']($request) != 0) {
1459
+			$incontext['skip'] = 1;
1460
+	}
1377 1461
 	$smcFunc['db_free_result']($request);
1378 1462
 
1379 1463
 	// Trying to create an account?
@@ -1404,8 +1488,9 @@  discard block
 block discarded – undo
1404 1488
 		}
1405 1489
 
1406 1490
 		// Update the webmaster's email?
1407
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1408
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1491
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1492
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1493
+		}
1409 1494
 
1410 1495
 		// Work out whether we're going to have dodgy characters and remove them.
1411 1496
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1428,32 +1513,27 @@  discard block
 block discarded – undo
1428 1513
 			$smcFunc['db_free_result']($result);
1429 1514
 
1430 1515
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1431
-		}
1432
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1516
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1433 1517
 		{
1434 1518
 			// Try the previous step again.
1435 1519
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1436 1520
 			return false;
1437
-		}
1438
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1521
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1439 1522
 		{
1440 1523
 			// Try the previous step again.
1441 1524
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1442 1525
 			return false;
1443
-		}
1444
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1526
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1445 1527
 		{
1446 1528
 			// One step back, this time fill out a proper admin email address.
1447 1529
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1448 1530
 			return false;
1449
-		}
1450
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1531
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1451 1532
 		{
1452 1533
 			// One step back, this time fill out a proper admin email address.
1453 1534
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1454 1535
 			return false;
1455
-		}
1456
-		elseif ($_POST['username'] != '')
1536
+		} elseif ($_POST['username'] != '')
1457 1537
 		{
1458 1538
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1459 1539
 
@@ -1519,17 +1599,19 @@  discard block
 block discarded – undo
1519 1599
 	require_once($sourcedir . '/Subs-Auth.php');
1520 1600
 
1521 1601
 	// Bring a warning over.
1522
-	if (!empty($incontext['account_existed']))
1523
-		$incontext['warning'] = $incontext['account_existed'];
1602
+	if (!empty($incontext['account_existed'])) {
1603
+			$incontext['warning'] = $incontext['account_existed'];
1604
+	}
1524 1605
 
1525
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1526
-		$smcFunc['db_query']('', '
1606
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1607
+			$smcFunc['db_query']('', '
1527 1608
 			SET NAMES {string:db_character_set}',
1528 1609
 			array(
1529 1610
 				'db_character_set' => $db_character_set,
1530 1611
 				'db_error_skip' => true,
1531 1612
 			)
1532 1613
 		);
1614
+	}
1533 1615
 
1534 1616
 	// As track stats is by default enabled let's add some activity.
1535 1617
 	$smcFunc['db_insert']('ignore',
@@ -1550,14 +1632,16 @@  discard block
 block discarded – undo
1550 1632
 	// Only proceed if we can load the data.
1551 1633
 	if ($request)
1552 1634
 	{
1553
-		while ($row = $smcFunc['db_fetch_row']($request))
1554
-			$modSettings[$row[0]] = $row[1];
1635
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1636
+					$modSettings[$row[0]] = $row[1];
1637
+		}
1555 1638
 		$smcFunc['db_free_result']($request);
1556 1639
 	}
1557 1640
 
1558 1641
 	// Automatically log them in ;)
1559
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1560
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1642
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1643
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1644
+	}
1561 1645
 
1562 1646
 	$result = $smcFunc['db_query']('', '
1563 1647
 		SELECT value
@@ -1568,13 +1652,14 @@  discard block
 block discarded – undo
1568 1652
 			'db_error_skip' => true,
1569 1653
 		)
1570 1654
 	);
1571
-	if ($smcFunc['db_num_rows']($result) != 0)
1572
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1655
+	if ($smcFunc['db_num_rows']($result) != 0) {
1656
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1657
+	}
1573 1658
 	$smcFunc['db_free_result']($result);
1574 1659
 
1575
-	if (empty($db_sessions))
1576
-		$_SESSION['admin_time'] = time();
1577
-	else
1660
+	if (empty($db_sessions)) {
1661
+			$_SESSION['admin_time'] = time();
1662
+	} else
1578 1663
 	{
1579 1664
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1580 1665
 
@@ -1598,8 +1683,9 @@  discard block
 block discarded – undo
1598 1683
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1599 1684
 		function($string){
1600 1685
 			global $sourcedir;
1601
-			if (function_exists('mb_strtolower'))
1602
-				return mb_strtolower($string, 'UTF-8');
1686
+			if (function_exists('mb_strtolower')) {
1687
+							return mb_strtolower($string, 'UTF-8');
1688
+			}
1603 1689
 			require_once($sourcedir . '/Subs-Charset.php');
1604 1690
 			return utf8_strtolower($string);
1605 1691
 		};
@@ -1615,8 +1701,9 @@  discard block
 block discarded – undo
1615 1701
 		)
1616 1702
 	);
1617 1703
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1618
-	if ($smcFunc['db_num_rows']($request) > 0)
1619
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1704
+	if ($smcFunc['db_num_rows']($request) > 0) {
1705
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1706
+	}
1620 1707
 	$smcFunc['db_free_result']($request);
1621 1708
 
1622 1709
 	// Now is the perfect time to fetch the SM files.
@@ -1635,8 +1722,9 @@  discard block
 block discarded – undo
1635 1722
 
1636 1723
 	// Check if we need some stupid MySQL fix.
1637 1724
 	$server_version = $smcFunc['db_server_info']();
1638
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1639
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1725
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1726
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1727
+	}
1640 1728
 
1641 1729
 	// Some final context for the template.
1642 1730
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1656,8 +1744,9 @@  discard block
 block discarded – undo
1656 1744
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1657 1745
 
1658 1746
 	// @todo Do we just want to read the file in clean, and split it this way always?
1659
-	if (count($settingsArray) == 1)
1660
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1747
+	if (count($settingsArray) == 1) {
1748
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1749
+	}
1661 1750
 
1662 1751
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1663 1752
 	{
@@ -1672,19 +1761,22 @@  discard block
 block discarded – undo
1672 1761
 			continue;
1673 1762
 		}
1674 1763
 
1675
-		if (trim($settingsArray[$i]) == '?' . '>')
1676
-			$settingsArray[$i] = '';
1764
+		if (trim($settingsArray[$i]) == '?' . '>') {
1765
+					$settingsArray[$i] = '';
1766
+		}
1677 1767
 
1678 1768
 		// Don't trim or bother with it if it's not a variable.
1679
-		if (substr($settingsArray[$i], 0, 1) != '$')
1680
-			continue;
1769
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1770
+					continue;
1771
+		}
1681 1772
 
1682 1773
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1683 1774
 
1684
-		foreach ($vars as $var => $val)
1685
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1775
+		foreach ($vars as $var => $val) {
1776
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1686 1777
 			{
1687 1778
 				$comment = strstr($settingsArray[$i], '#');
1779
+		}
1688 1780
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1689 1781
 				unset($vars[$var]);
1690 1782
 			}
@@ -1694,36 +1786,41 @@  discard block
 block discarded – undo
1694 1786
 	if (!empty($vars))
1695 1787
 	{
1696 1788
 		$settingsArray[$i++] = '';
1697
-		foreach ($vars as $var => $val)
1698
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1789
+		foreach ($vars as $var => $val) {
1790
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1791
+		}
1699 1792
 	}
1700 1793
 
1701 1794
 	// Blank out the file - done to fix a oddity with some servers.
1702 1795
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1703
-	if (!$fp)
1704
-		return false;
1796
+	if (!$fp) {
1797
+			return false;
1798
+	}
1705 1799
 	fclose($fp);
1706 1800
 
1707 1801
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1708 1802
 
1709 1803
 	// Gotta have one of these ;)
1710
-	if (trim($settingsArray[0]) != '<?php')
1711
-		fwrite($fp, "<?php\n");
1804
+	if (trim($settingsArray[0]) != '<?php') {
1805
+			fwrite($fp, "<?php\n");
1806
+	}
1712 1807
 
1713 1808
 	$lines = count($settingsArray);
1714 1809
 	for ($i = 0; $i < $lines - 1; $i++)
1715 1810
 	{
1716 1811
 		// Don't just write a bunch of blank lines.
1717
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1718
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1812
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1813
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1814
+		}
1719 1815
 	}
1720 1816
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1721 1817
 	fclose($fp);
1722 1818
 
1723 1819
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1724 1820
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1725
-	if (function_exists('opcache_invalidate'))
1726
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1821
+	if (function_exists('opcache_invalidate')) {
1822
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1823
+	}
1727 1824
 
1728 1825
 	return true;
1729 1826
 }
@@ -1748,9 +1845,9 @@  discard block
 block discarded – undo
1748 1845
 	SecFilterScanPOST Off
1749 1846
 </IfModule>';
1750 1847
 
1751
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1752
-		return true;
1753
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1848
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1849
+			return true;
1850
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1754 1851
 	{
1755 1852
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1756 1853
 
@@ -1762,29 +1859,28 @@  discard block
 block discarded – undo
1762 1859
 				fwrite($ht_handle, $htaccess_addition);
1763 1860
 				fclose($ht_handle);
1764 1861
 				return true;
1862
+			} else {
1863
+							return false;
1765 1864
 			}
1766
-			else
1767
-				return false;
1865
+		} else {
1866
+					return true;
1768 1867
 		}
1769
-		else
1770
-			return true;
1771
-	}
1772
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1773
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1774
-	elseif (is_writable(dirname(__FILE__)))
1868
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1869
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1870
+	} elseif (is_writable(dirname(__FILE__)))
1775 1871
 	{
1776 1872
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1777 1873
 		{
1778 1874
 			fwrite($ht_handle, $htaccess_addition);
1779 1875
 			fclose($ht_handle);
1780 1876
 			return true;
1877
+		} else {
1878
+					return false;
1781 1879
 		}
1782
-		else
1880
+	} else {
1783 1881
 			return false;
1784 1882
 	}
1785
-	else
1786
-		return false;
1787
-}
1883
+	}
1788 1884
 
1789 1885
 function template_install_above()
1790 1886
 {
@@ -1822,9 +1918,10 @@  discard block
 block discarded – undo
1822 1918
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1823 1919
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1824 1920
 
1825
-		foreach ($incontext['detected_languages'] as $lang => $name)
1826
-			echo '
1921
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1922
+					echo '
1827 1923
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1924
+		}
1828 1925
 
1829 1926
 		echo '
1830 1927
 								</select>
@@ -1844,9 +1941,10 @@  discard block
 block discarded – undo
1844 1941
 						<h2>', $txt['upgrade_progress'], '</h2>
1845 1942
 						<ul>';
1846 1943
 
1847
-	foreach ($incontext['steps'] as $num => $step)
1848
-		echo '
1944
+	foreach ($incontext['steps'] as $num => $step) {
1945
+			echo '
1849 1946
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1947
+	}
1850 1948
 
1851 1949
 	echo '
1852 1950
 						</ul>
@@ -1871,20 +1969,23 @@  discard block
 block discarded – undo
1871 1969
 		echo '
1872 1970
 								<div>';
1873 1971
 
1874
-		if (!empty($incontext['continue']))
1875
-			echo '
1972
+		if (!empty($incontext['continue'])) {
1973
+					echo '
1876 1974
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1877
-		if (!empty($incontext['skip']))
1878
-			echo '
1975
+		}
1976
+		if (!empty($incontext['skip'])) {
1977
+					echo '
1879 1978
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1979
+		}
1880 1980
 		echo '
1881 1981
 								</div>';
1882 1982
 	}
1883 1983
 
1884 1984
 	// Show the closing form tag and other data only if not in the last step
1885
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1886
-		echo '
1985
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
1986
+			echo '
1887 1987
 							</form>';
1988
+	}
1888 1989
 
1889 1990
 	echo '
1890 1991
 						</div>
@@ -1919,13 +2020,15 @@  discard block
 block discarded – undo
1919 2020
 		</div>';
1920 2021
 
1921 2022
 	// Show the warnings, or not.
1922
-	if (template_warning_divs())
1923
-		echo '
2023
+	if (template_warning_divs()) {
2024
+			echo '
1924 2025
 		<h3>', $txt['install_all_lovely'], '</h3>';
2026
+	}
1925 2027
 
1926 2028
 	// Say we want the continue button!
1927
-	if (empty($incontext['error']))
1928
-		$incontext['continue'] = 1;
2029
+	if (empty($incontext['error'])) {
2030
+			$incontext['continue'] = 1;
2031
+	}
1929 2032
 
1930 2033
 	// For the latest version stuff.
1931 2034
 	echo '
@@ -1959,8 +2062,8 @@  discard block
 block discarded – undo
1959 2062
 	global $txt, $incontext;
1960 2063
 
1961 2064
 	// Errors are very serious..
1962
-	if (!empty($incontext['error']))
1963
-		echo '
2065
+	if (!empty($incontext['error'])) {
2066
+			echo '
1964 2067
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1965 2068
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1966 2069
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1968,9 +2071,10 @@  discard block
 block discarded – undo
1968 2071
 				', $incontext['error'], '
1969 2072
 			</div>
1970 2073
 		</div>';
2074
+	}
1971 2075
 	// A warning message?
1972
-	elseif (!empty($incontext['warning']))
1973
-		echo '
2076
+	elseif (!empty($incontext['warning'])) {
2077
+			echo '
1974 2078
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1975 2079
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1976 2080
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -1978,6 +2082,7 @@  discard block
 block discarded – undo
1978 2082
 				', $incontext['warning'], '
1979 2083
 			</div>
1980 2084
 		</div>';
2085
+	}
1981 2086
 
1982 2087
 	return empty($incontext['error']) && empty($incontext['warning']);
1983 2088
 }
@@ -1993,27 +2098,30 @@  discard block
 block discarded – undo
1993 2098
 			<li>', $incontext['failed_files']), '</li>
1994 2099
 		</ul>';
1995 2100
 
1996
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
1997
-		echo '
2101
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2102
+			echo '
1998 2103
 		<hr>
1999 2104
 		<p>', $txt['chmod_linux_info'], '</p>
2000 2105
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2106
+	}
2001 2107
 
2002 2108
 	// This is serious!
2003
-	if (!template_warning_divs())
2004
-		return;
2109
+	if (!template_warning_divs()) {
2110
+			return;
2111
+	}
2005 2112
 
2006 2113
 	echo '
2007 2114
 		<hr>
2008 2115
 		<p>', $txt['ftp_setup_info'], '</p>';
2009 2116
 
2010
-	if (!empty($incontext['ftp_errors']))
2011
-		echo '
2117
+	if (!empty($incontext['ftp_errors'])) {
2118
+			echo '
2012 2119
 		<div class="error_message">
2013 2120
 			', $txt['error_ftp_no_connect'], '<br><br>
2014 2121
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2015 2122
 		</div>
2016 2123
 		<br>';
2124
+	}
2017 2125
 
2018 2126
 	echo '
2019 2127
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2073,17 +2181,17 @@  discard block
 block discarded – undo
2073 2181
 				<td>
2074 2182
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2075 2183
 
2076
-	foreach ($incontext['supported_databases'] as $key => $db)
2077
-			echo '
2184
+	foreach ($incontext['supported_databases'] as $key => $db) {
2185
+				echo '
2078 2186
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2187
+	}
2079 2188
 
2080 2189
 	echo '
2081 2190
 					</select>
2082 2191
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2083 2192
 				</td>
2084 2193
 			</tr>';
2085
-	}
2086
-	else
2194
+	} else
2087 2195
 	{
2088 2196
 		echo '
2089 2197
 			<tr style="display: none;">
@@ -2275,9 +2383,10 @@  discard block
 block discarded – undo
2275 2383
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2276 2384
 				<ul>';
2277 2385
 
2278
-		foreach ($incontext['failures'] as $line => $fail)
2279
-			echo '
2386
+		foreach ($incontext['failures'] as $line => $fail) {
2387
+					echo '
2280 2388
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2389
+		}
2281 2390
 
2282 2391
 		echo '
2283 2392
 				</ul>';
@@ -2338,15 +2447,16 @@  discard block
 block discarded – undo
2338 2447
 			</tr>
2339 2448
 		</table>';
2340 2449
 
2341
-	if ($incontext['require_db_confirm'])
2342
-		echo '
2450
+	if ($incontext['require_db_confirm']) {
2451
+			echo '
2343 2452
 		<h2>', $txt['user_settings_database'], '</h2>
2344 2453
 		<p>', $txt['user_settings_database_info'], '</p>
2345 2454
 
2346 2455
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2347 2456
 			<input type="password" name="password3" size="30" class="input_password" />
2348 2457
 		</div>';
2349
-}
2458
+	}
2459
+	}
2350 2460
 
2351 2461
 // Tell them it's done, and to delete.
2352 2462
 function template_delete_install()
@@ -2359,14 +2469,15 @@  discard block
 block discarded – undo
2359 2469
 	template_warning_divs();
2360 2470
 
2361 2471
 	// Install directory still writable?
2362
-	if ($incontext['dir_still_writable'])
2363
-		echo '
2472
+	if ($incontext['dir_still_writable']) {
2473
+			echo '
2364 2474
 		<em>', $txt['still_writable'], '</em><br>
2365 2475
 		<br>';
2476
+	}
2366 2477
 
2367 2478
 	// Don't show the box if it's like 99% sure it won't work :P.
2368
-	if ($incontext['probably_delete_install'])
2369
-		echo '
2479
+	if ($incontext['probably_delete_install']) {
2480
+			echo '
2370 2481
 		<div style="margin: 1ex; font-weight: bold;">
2371 2482
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2372 2483
 		</div>
@@ -2382,6 +2493,7 @@  discard block
 block discarded – undo
2382 2493
 			}
2383 2494
 		</script>
2384 2495
 		<br>';
2496
+	}
2385 2497
 
2386 2498
 	echo '
2387 2499
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
Sources/ManageLanguages.php 1 patch
Braces   +190 added lines, -142 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
  * This is the main function for the languages area.
@@ -153,11 +154,11 @@  discard block
 block discarded – undo
153 154
 	$language_list = new xmlArray(fetch_web_data($url), true);
154 155
 
155 156
 	// Check that the site responded and that the language exists.
156
-	if (!$language_list->exists('languages'))
157
-		$context['smf_error'] = 'no_response';
158
-	elseif (!$language_list->exists('languages/language'))
159
-		$context['smf_error'] = 'no_files';
160
-	else
157
+	if (!$language_list->exists('languages')) {
158
+			$context['smf_error'] = 'no_response';
159
+	} elseif (!$language_list->exists('languages/language')) {
160
+			$context['smf_error'] = 'no_files';
161
+	} else
161 162
 	{
162 163
 		$language_list = $language_list->path('languages[0]');
163 164
 		$lang_files = $language_list->set('language');
@@ -165,8 +166,9 @@  discard block
 block discarded – undo
165 166
 		foreach ($lang_files as $file)
166 167
 		{
167 168
 			// Were we searching?
168
-			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false)
169
-				continue;
169
+			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) {
170
+							continue;
171
+			}
170 172
 
171 173
 			$smf_languages[] = array(
172 174
 				'id' => $file->fetch('id'),
@@ -177,10 +179,11 @@  discard block
 block discarded – undo
177 179
 				'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_smf_install'] . '</a>',
178 180
 			);
179 181
 		}
180
-		if (empty($smf_languages))
181
-			$context['smf_error'] = 'no_files';
182
-		else
183
-			return $smf_languages;
182
+		if (empty($smf_languages)) {
183
+					$context['smf_error'] = 'no_files';
184
+		} else {
185
+					return $smf_languages;
186
+		}
184 187
 	}
185 188
 }
186 189
 
@@ -202,8 +205,9 @@  discard block
 block discarded – undo
202 205
 	require_once($sourcedir . '/Subs-Package.php');
203 206
 
204 207
 	// Clearly we need to know what to request.
205
-	if (!isset($_GET['did']))
206
-		fatal_lang_error('no_access', false);
208
+	if (!isset($_GET['did'])) {
209
+			fatal_lang_error('no_access', false);
210
+	}
207 211
 
208 212
 	// Some lovely context.
209 213
 	$context['download_id'] = $_GET['did'];
@@ -223,8 +227,9 @@  discard block
 block discarded – undo
223 227
 		foreach ($_POST['copy_file'] as $file)
224 228
 		{
225 229
 			// Check it's not very bad.
226
-			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file)))
227
-				fatal_error($txt['languages_download_illegal_paths']);
230
+			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) {
231
+							fatal_error($txt['languages_download_illegal_paths']);
232
+			}
228 233
 
229 234
 			$chmod_files[] = $boarddir . '/' . $file;
230 235
 			$install_files[] = $file;
@@ -235,8 +240,9 @@  discard block
 block discarded – undo
235 240
 		$files_left = $file_status['files']['notwritable'];
236 241
 
237 242
 		// Something not writable?
238
-		if (!empty($files_left))
239
-			$context['error_message'] = $txt['languages_download_not_chmod'];
243
+		if (!empty($files_left)) {
244
+					$context['error_message'] = $txt['languages_download_not_chmod'];
245
+		}
240 246
 		// Otherwise, go go go!
241 247
 		elseif (!empty($install_files))
242 248
 		{
@@ -251,11 +257,13 @@  discard block
 block discarded – undo
251 257
 	}
252 258
 
253 259
 	// Open up the old china.
254
-	if (!isset($archive_content))
255
-		$archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
260
+	if (!isset($archive_content)) {
261
+			$archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
262
+	}
256 263
 
257
-	if (empty($archive_content))
258
-		fatal_error($txt['add_language_error_no_response']);
264
+	if (empty($archive_content)) {
265
+			fatal_error($txt['add_language_error_no_response']);
266
+	}
259 267
 
260 268
 	// Now for each of the files, let's do some *stuff*
261 269
 	$context['files'] = array(
@@ -270,8 +278,9 @@  discard block
 block discarded – undo
270 278
 		$extension = substr($filename, strrpos($filename, '.') + 1);
271 279
 
272 280
 		// Don't do anything with files we don't understand.
273
-		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt')))
274
-			continue;
281
+		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) {
282
+					continue;
283
+		}
275 284
 
276 285
 		// Basic data.
277 286
 		$context_data = array(
@@ -290,8 +299,9 @@  discard block
 block discarded – undo
290 299
 		// Does the file exist, is it different and can we overwrite?
291 300
 		if (file_exists($boarddir . '/' . $file['filename']))
292 301
 		{
293
-			if (is_writable($boarddir . '/' . $file['filename']))
294
-				$context_data['writable'] = true;
302
+			if (is_writable($boarddir . '/' . $file['filename'])) {
303
+							$context_data['writable'] = true;
304
+			}
295 305
 
296 306
 			// Finally, do we actually think the content has changed?
297 307
 			if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename']))
@@ -304,16 +314,17 @@  discard block
 block discarded – undo
304 314
 			{
305 315
 				$context_data['exists'] = 'same';
306 316
 				$context_data['default_copy'] = false;
317
+			} else {
318
+							$context_data['exists'] = 'different';
307 319
 			}
308
-			else
309
-				$context_data['exists'] = 'different';
310 320
 		}
311 321
 		// No overwrite?
312 322
 		else
313 323
 		{
314 324
 			// Can we at least stick it in the directory...
315
-			if (is_writable($boarddir . '/' . $dirname))
316
-				$context_data['writable'] = true;
325
+			if (is_writable($boarddir . '/' . $dirname)) {
326
+							$context_data['writable'] = true;
327
+			}
317 328
 		}
318 329
 
319 330
 		// I love PHP files, that's why I'm a developer and not an artistic type spending my time drinking absinth and living a life of sin...
@@ -328,8 +339,9 @@  discard block
 block discarded – undo
328 339
 			list ($name, $language) = explode('.', $filename);
329 340
 
330 341
 			// Let's get the new version, I like versions, they tell me that I'm up to date.
331
-			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1)
332
-				$context_data['version'] = $match[1];
342
+			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) {
343
+							$context_data['version'] = $match[1];
344
+			}
333 345
 
334 346
 			// Now does the old file exist - if so what is it's version?
335 347
 			if (file_exists($boarddir . '/' . $file['filename']))
@@ -345,34 +357,35 @@  discard block
 block discarded – undo
345 357
 					$context_data['cur_version'] = $match[1];
346 358
 
347 359
 					// How does this compare?
348
-					if ($context_data['cur_version'] == $context_data['version'])
349
-						$context_data['version_compare'] = 'same';
350
-					elseif ($context_data['cur_version'] > $context_data['version'])
351
-						$context_data['version_compare'] = 'older';
360
+					if ($context_data['cur_version'] == $context_data['version']) {
361
+											$context_data['version_compare'] = 'same';
362
+					} elseif ($context_data['cur_version'] > $context_data['version']) {
363
+											$context_data['version_compare'] = 'older';
364
+					}
352 365
 
353 366
 					// Don't recommend copying if the version is the same.
354
-					if ($context_data['version_compare'] != 'newer')
355
-						$context_data['default_copy'] = false;
367
+					if ($context_data['version_compare'] != 'newer') {
368
+											$context_data['default_copy'] = false;
369
+					}
356 370
 				}
357 371
 			}
358 372
 
359 373
 			// Add the context data to the main set.
360 374
 			$context['files']['lang'][] = $context_data;
361
-		}
362
-		elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
375
+		} elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
363 376
 		{
364 377
 			// Registration agreement is a primary file
365 378
 			$context['files']['lang'][] = $context_data;
366
-		}
367
-		else
379
+		} else
368 380
 		{
369 381
 			// There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future
370 382
 			$context['files']['other'][] = $context_data;
371 383
 		}
372 384
 
373 385
 		// Collect together all non-writable areas.
374
-		if (!$context_data['writable'])
375
-			$context['make_writable'][] = $context_data['destination'];
386
+		if (!$context_data['writable']) {
387
+					$context['make_writable'][] = $context_data['destination'];
388
+		}
376 389
 	}
377 390
 
378 391
 	// Before we go to far can we make anything writable, eh, eh?
@@ -387,22 +400,24 @@  discard block
 block discarded – undo
387 400
 		{
388 401
 			if ($type == 'lang')
389 402
 			{
390
-				foreach ($data as $k => $file)
391
-					if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
403
+				foreach ($data as $k => $file) {
404
+									if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
392 405
 						$context['files'][$type][$k]['writable'] = true;
393
-			}
394
-			else
406
+				}
407
+			} else
395 408
 			{
396
-				foreach ($data as $theme => $files)
397
-					foreach ($files as $k => $file)
409
+				foreach ($data as $theme => $files) {
410
+									foreach ($files as $k => $file)
398 411
 						if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
399 412
 							$context['files'][$type][$theme][$k]['writable'] = true;
413
+				}
400 414
 			}
401 415
 		}
402 416
 
403 417
 		// Are we going to need more language stuff?
404
-		if (!empty($context['still_not_writable']))
405
-			loadLanguage('Packages');
418
+		if (!empty($context['still_not_writable'])) {
419
+					loadLanguage('Packages');
420
+		}
406 421
 	}
407 422
 
408 423
 	// This is the list for the main files.
@@ -615,12 +630,13 @@  discard block
 block discarded – undo
615 630
 	highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true);
616 631
 
617 632
 	// Display a warning if we cannot edit the default setting.
618
-	if (!is_writable($boarddir . '/Settings.php'))
619
-		$listOptions['additional_rows'][] = array(
633
+	if (!is_writable($boarddir . '/Settings.php')) {
634
+			$listOptions['additional_rows'][] = array(
620 635
 				'position' => 'after_title',
621 636
 				'value' => $txt['language_settings_writable'],
622 637
 				'class' => 'smalltext alert',
623 638
 			);
639
+	}
624 640
 
625 641
 	require_once($sourcedir . '/Subs-List.php');
626 642
 	createList($listOptions);
@@ -662,10 +678,11 @@  discard block
 block discarded – undo
662 678
 
663 679
 	// Put them back.
664 680
 	$settings['actual_theme_dir'] = $backup_actual_theme_dir;
665
-	if (!empty($backup_base_theme_dir))
666
-		$settings['base_theme_dir'] = $backup_base_theme_dir;
667
-	else
668
-		unset($settings['base_theme_dir']);
681
+	if (!empty($backup_base_theme_dir)) {
682
+			$settings['base_theme_dir'] = $backup_base_theme_dir;
683
+	} else {
684
+			unset($settings['base_theme_dir']);
685
+	}
669 686
 
670 687
 	// Get the language files and data...
671 688
 	foreach ($context['languages'] as $lang)
@@ -694,13 +711,15 @@  discard block
 block discarded – undo
694 711
 	while ($row = $smcFunc['db_fetch_assoc']($request))
695 712
 	{
696 713
 		// Default?
697
-		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']]))
698
-			$row['lngfile'] = $language;
714
+		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) {
715
+					$row['lngfile'] = $language;
716
+		}
699 717
 
700
-		if (!isset($languages[$row['lngfile']]) && isset($languages['english']))
701
-			$languages['english']['count'] += $row['num_users'];
702
-		elseif (isset($languages[$row['lngfile']]))
703
-			$languages[$row['lngfile']]['count'] += $row['num_users'];
718
+		if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) {
719
+					$languages['english']['count'] += $row['num_users'];
720
+		} elseif (isset($languages[$row['lngfile']])) {
721
+					$languages[$row['lngfile']]['count'] += $row['num_users'];
722
+		}
704 723
 	}
705 724
 	$smcFunc['db_free_result']($request);
706 725
 
@@ -740,13 +759,15 @@  discard block
 block discarded – undo
740 759
 
741 760
 	call_integration_hook('integrate_language_settings', array(&$config_vars));
742 761
 
743
-	if ($return_config)
744
-		return $config_vars;
762
+	if ($return_config) {
763
+			return $config_vars;
764
+	}
745 765
 
746 766
 	// Get our languages. No cache
747 767
 	getLanguages(false);
748
-	foreach ($context['languages'] as $lang)
749
-		$config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']);
768
+	foreach ($context['languages'] as $lang) {
769
+			$config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']);
770
+	}
750 771
 
751 772
 	// Saving settings?
752 773
 	if (isset($_REQUEST['save']))
@@ -756,8 +777,9 @@  discard block
 block discarded – undo
756 777
 		call_integration_hook('integrate_save_language_settings', array(&$config_vars));
757 778
 
758 779
 		saveSettings($config_vars);
759
-		if (!$settings_not_writable && !$settings_backup_fail)
760
-			$_SESSION['adm-save'] = true;
780
+		if (!$settings_not_writable && !$settings_backup_fail) {
781
+					$_SESSION['adm-save'] = true;
782
+		}
761 783
 		redirectexit('action=admin;area=languages;sa=settings');
762 784
 	}
763 785
 
@@ -766,10 +788,11 @@  discard block
 block discarded – undo
766 788
 	$context['settings_title'] = $txt['language_settings'];
767 789
 	$context['save_disabled'] = $settings_not_writable;
768 790
 
769
-	if ($settings_not_writable)
770
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
771
-	elseif ($settings_backup_fail)
772
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
791
+	if ($settings_not_writable) {
792
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
793
+	} elseif ($settings_backup_fail) {
794
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
795
+	}
773 796
 
774 797
 	// Fill the config array.
775 798
 	prepareServerSettingsContext($config_vars);
@@ -816,8 +839,9 @@  discard block
 block discarded – undo
816 839
 			'theme_dir' => $settings['default_theme_dir'],
817 840
 		),
818 841
 	);
819
-	while ($row = $smcFunc['db_fetch_assoc']($request))
820
-		$themes[$row['id_theme']][$row['variable']] = $row['value'];
842
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
843
+			$themes[$row['id_theme']][$row['variable']] = $row['value'];
844
+	}
821 845
 	$smcFunc['db_free_result']($request);
822 846
 
823 847
 	// This will be where we look
@@ -829,14 +853,16 @@  discard block
 block discarded – undo
829 853
 	// Check we have themes with a path and a name - just in case - and add the path.
830 854
 	foreach ($themes as $id => $data)
831 855
 	{
832
-		if (count($data) != 2)
833
-			unset($themes[$id]);
834
-		elseif (is_dir($data['theme_dir'] . '/languages'))
835
-			$lang_dirs[$id] = $data['theme_dir'] . '/languages';
856
+		if (count($data) != 2) {
857
+					unset($themes[$id]);
858
+		} elseif (is_dir($data['theme_dir'] . '/languages')) {
859
+					$lang_dirs[$id] = $data['theme_dir'] . '/languages';
860
+		}
836 861
 
837 862
 		// How about image directories?
838
-		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id']))
839
-			$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
863
+		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) {
864
+					$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
865
+		}
840 866
 	}
841 867
 
842 868
 	$current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : '';
@@ -850,15 +876,17 @@  discard block
 block discarded – undo
850 876
 		while ($entry = $dir->read())
851 877
 		{
852 878
 			// We're only after the files for this language.
853
-			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0)
854
-				continue;
879
+			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) {
880
+							continue;
881
+			}
855 882
 
856
-			if (!isset($context['possible_files'][$theme]))
857
-				$context['possible_files'][$theme] = array(
883
+			if (!isset($context['possible_files'][$theme])) {
884
+							$context['possible_files'][$theme] = array(
858 885
 					'id' => $theme,
859 886
 					'name' => $themes[$theme]['name'],
860 887
 					'files' => array(),
861 888
 				);
889
+			}
862 890
 
863 891
 			$context['possible_files'][$theme]['files'][] = array(
864 892
 				'id' => $matches[1],
@@ -887,31 +915,36 @@  discard block
 block discarded – undo
887 915
 		{
888 916
 			$_SESSION['last_backup_for'] = $context['lang_id'] . '$$$';
889 917
 			$result = package_create_backup('backup_lang_' . $context['lang_id']);
890
-			if (!$result)
891
-				fatal_lang_error('could_not_language_backup', false);
918
+			if (!$result) {
919
+							fatal_lang_error('could_not_language_backup', false);
920
+			}
892 921
 		}
893 922
 
894 923
 		// Second, loop through the array to remove the files.
895 924
 		foreach ($lang_dirs as $curPath)
896 925
 		{
897
-			foreach ($context['possible_files'][1]['files'] as $lang)
898
-				if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
926
+			foreach ($context['possible_files'][1]['files'] as $lang) {
927
+							if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
899 928
 					unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php');
929
+			}
900 930
 
901 931
 			// Check for the email template.
902
-			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'))
903
-				unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
932
+			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) {
933
+							unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
934
+			}
904 935
 		}
905 936
 
906 937
 		// Third, the agreement file.
907
-		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt'))
908
-			unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
938
+		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) {
939
+					unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
940
+		}
909 941
 
910 942
 		// Fourth, a related images folder, if it exists...
911
-		if (!empty($images_dirs))
912
-			foreach ($images_dirs as $curPath)
943
+		if (!empty($images_dirs)) {
944
+					foreach ($images_dirs as $curPath)
913 945
 				if (is_dir($curPath))
914 946
 					deltree($curPath);
947
+		}
915 948
 
916 949
 		// Members can no longer use this language.
917 950
 		$smcFunc['db_query']('', '
@@ -995,8 +1028,9 @@  discard block
 block discarded – undo
995 1028
 		foreach ($_POST['entry'] as $k => $v)
996 1029
 		{
997 1030
 			// Only try to save if it's changed!
998
-			if ($_POST['entry'][$k] != $_POST['comp'][$k])
999
-				$save_strings[$k] = cleanLangString($v, false);
1031
+			if ($_POST['entry'][$k] != $_POST['comp'][$k]) {
1032
+							$save_strings[$k] = cleanLangString($v, false);
1033
+			}
1000 1034
 		}
1001 1035
 	}
1002 1036
 
@@ -1030,12 +1064,13 @@  discard block
 block discarded – undo
1030 1064
 		if ($multiline_cache)
1031 1065
 		{
1032 1066
 			preg_match('~\$(helptxt|txt|editortxt)\[\'(.+)\'\]\s?=\s?(.+);~ms', strtr($multiline_cache, array("\r" => '')), $matches);
1033
-			if (!empty($matches[3]))
1034
-				$entries[$matches[2]] = array(
1067
+			if (!empty($matches[3])) {
1068
+							$entries[$matches[2]] = array(
1035 1069
 					'type' => $matches[1],
1036 1070
 					'full' => $matches[0],
1037 1071
 					'entry' => $matches[3],
1038 1072
 				);
1073
+			}
1039 1074
 		}
1040 1075
 
1041 1076
 		// These are the entries we can definitely save.
@@ -1046,8 +1081,9 @@  discard block
 block discarded – undo
1046 1081
 		{
1047 1082
 			// Ignore some things we set separately.
1048 1083
 			$ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl');
1049
-			if (in_array($entryKey, $ignore_files))
1050
-				continue;
1084
+			if (in_array($entryKey, $ignore_files)) {
1085
+							continue;
1086
+			}
1051 1087
 
1052 1088
 			// These are arrays that need breaking out.
1053 1089
 			$arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short', 'happy_birthday_author', 'karlbenson1_author', 'nite0859_author', 'zwaldowski_author', 'geezmo_author', 'karlbenson2_author');
@@ -1080,9 +1116,9 @@  discard block
 block discarded – undo
1080 1116
 					{
1081 1117
 						$save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => ''));
1082 1118
 						$save_cache['enabled'] = true;
1119
+					} else {
1120
+											$save_cache['entries'][$cur_index] = $subValue;
1083 1121
 					}
1084
-					else
1085
-						$save_cache['entries'][$cur_index] = $subValue;
1086 1122
 
1087 1123
 					$context['file_entries'][] = array(
1088 1124
 						'key' => $entryKey . '-+- ' . $cur_index,
@@ -1105,9 +1141,9 @@  discard block
 block discarded – undo
1105 1141
 						{
1106 1142
 							$items[] = $k2 . ' => \'' . $v2 . '\'';
1107 1143
 							$cur_index = $k2;
1144
+						} else {
1145
+													$items[] = '\'' . $v2 . '\'';
1108 1146
 						}
1109
-						else
1110
-							$items[] = '\'' . $v2 . '\'';
1111 1147
 
1112 1148
 						$cur_index++;
1113 1149
 					}
@@ -1117,15 +1153,15 @@  discard block
 block discarded – undo
1117 1153
 						'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');',
1118 1154
 					);
1119 1155
 				}
1120
-			}
1121
-			else
1156
+			} else
1122 1157
 			{
1123 1158
 				// Saving?
1124 1159
 				if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry'])
1125 1160
 				{
1126 1161
 					// @todo Fix this properly.
1127
-					if ($save_strings[$entryKey] == '')
1128
-						$save_strings[$entryKey] = '\'\'';
1162
+					if ($save_strings[$entryKey] == '') {
1163
+											$save_strings[$entryKey] = '\'\'';
1164
+					}
1129 1165
 
1130 1166
 					// Set the new value.
1131 1167
 					$entryValue['entry'] = $save_strings[$entryKey];
@@ -1151,8 +1187,9 @@  discard block
 block discarded – undo
1151 1187
 			checkSession();
1152 1188
 
1153 1189
 			$file_contents = implode('', file($current_file));
1154
-			foreach ($final_saves as $save)
1155
-				$file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
1190
+			foreach ($final_saves as $save) {
1191
+							$file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
1192
+			}
1156 1193
 
1157 1194
 			// Save the actual changes.
1158 1195
 			$fp = fopen($current_file, 'w+');
@@ -1167,8 +1204,9 @@  discard block
 block discarded – undo
1167 1204
 	}
1168 1205
 
1169 1206
 	// If we saved, redirect.
1170
-	if ($madeSave)
1171
-		redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
1207
+	if ($madeSave) {
1208
+			redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
1209
+	}
1172 1210
 
1173 1211
 	createToken('admin-mlang');
1174 1212
 }
@@ -1200,8 +1238,9 @@  discard block
 block discarded – undo
1200 1238
 				// Toggle the escape.
1201 1239
 				$is_escape = !$is_escape;
1202 1240
 				// If we're now escaped don't add this string.
1203
-				if ($is_escape)
1204
-					continue;
1241
+				if ($is_escape) {
1242
+									continue;
1243
+				}
1205 1244
 			}
1206 1245
 			// Special case - parsed string with line break etc?
1207 1246
 			elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape)
@@ -1218,11 +1257,13 @@  discard block
 block discarded – undo
1218 1257
 				if ($in_string != 2 && ($in_string != 1 || !$is_escape))
1219 1258
 				{
1220 1259
 					// Is it the end of a single quote string?
1221
-					if ($in_string == 1)
1222
-						$in_string = 0;
1260
+					if ($in_string == 1) {
1261
+											$in_string = 0;
1262
+					}
1223 1263
 					// Otherwise it's the start!
1224
-					else
1225
-						$in_string = 1;
1264
+					else {
1265
+											$in_string = 1;
1266
+					}
1226 1267
 
1227 1268
 					// Don't actually include this character!
1228 1269
 					continue;
@@ -1235,19 +1276,22 @@  discard block
 block discarded – undo
1235 1276
 				if ($in_string != 1 && ($in_string != 2 || !$is_escape))
1236 1277
 				{
1237 1278
 					// Is it the end of a double quote string?
1238
-					if ($in_string == 2)
1239
-						$in_string = 0;
1279
+					if ($in_string == 2) {
1280
+											$in_string = 0;
1281
+					}
1240 1282
 					// Otherwise it's the start!
1241
-					else
1242
-						$in_string = 2;
1283
+					else {
1284
+											$in_string = 2;
1285
+					}
1243 1286
 
1244 1287
 					// Don't actually include this character!
1245 1288
 					continue;
1246 1289
 				}
1247 1290
 			}
1248 1291
 			// A join/space outside of a string is simply removed.
1249
-			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.'))
1250
-				continue;
1292
+			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) {
1293
+							continue;
1294
+			}
1251 1295
 			// Start of a variable?
1252 1296
 			elseif ($in_string == 0 && $string{$i} == '$')
1253 1297
 			{
@@ -1281,8 +1325,7 @@  discard block
 block discarded – undo
1281 1325
 
1282 1326
 		// Unhtml then rehtml the whole thing!
1283 1327
 		$new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string));
1284
-	}
1285
-	else
1328
+	} else
1286 1329
 	{
1287 1330
 		// Keep track of what we're doing...
1288 1331
 		$in_string = 0;
@@ -1311,10 +1354,11 @@  discard block
 block discarded – undo
1311 1354
 				preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches);
1312 1355
 				if (!empty($matches[1]))
1313 1356
 				{
1314
-					if ($in_string == 1)
1315
-						$new_string .= '\' . ';
1316
-					elseif ($new_string)
1317
-						$new_string .= ' . ';
1357
+					if ($in_string == 1) {
1358
+											$new_string .= '\' . ';
1359
+					} elseif ($new_string) {
1360
+											$new_string .= ' . ';
1361
+					}
1318 1362
 
1319 1363
 					$new_string .= $matches[1];
1320 1364
 					$i += strlen($matches[1]) + 3;
@@ -1327,8 +1371,9 @@  discard block
 block discarded – undo
1327 1371
 			elseif ($string{$i} == '<')
1328 1372
 			{
1329 1373
 				// Probably HTML?
1330
-				if ($string{$i + 1} != ' ')
1331
-					$in_html = true;
1374
+				if ($string{$i + 1} != ' ') {
1375
+									$in_html = true;
1376
+				}
1332 1377
 				// Assume we need an entity...
1333 1378
 				else
1334 1379
 				{
@@ -1340,8 +1385,9 @@  discard block
 block discarded – undo
1340 1385
 			elseif ($string{$i} == '>')
1341 1386
 			{
1342 1387
 				// Will it be HTML?
1343
-				if ($in_html)
1344
-					$in_html = false;
1388
+				if ($in_html) {
1389
+									$in_html = false;
1390
+				}
1345 1391
 				// Otherwise we need an entity...
1346 1392
 				else
1347 1393
 				{
@@ -1350,8 +1396,9 @@  discard block
 block discarded – undo
1350 1396
 				}
1351 1397
 			}
1352 1398
 			// Is it a slash? If so escape it...
1353
-			if ($string{$i} == '\\')
1354
-				$new_string .= '\\';
1399
+			if ($string{$i} == '\\') {
1400
+							$new_string .= '\\';
1401
+			}
1355 1402
 			// The infamous double quote?
1356 1403
 			elseif ($string{$i} == '"')
1357 1404
 			{
@@ -1374,10 +1421,11 @@  discard block
 block discarded – undo
1374 1421
 		}
1375 1422
 
1376 1423
 		// If we ended as a string then close it off.
1377
-		if ($in_string == 1)
1378
-			$new_string .= '\'';
1379
-		elseif ($in_string == 2)
1380
-			$new_string .= '"';
1424
+		if ($in_string == 1) {
1425
+					$new_string .= '\'';
1426
+		} elseif ($in_string == 2) {
1427
+					$new_string .= '"';
1428
+		}
1381 1429
 	}
1382 1430
 
1383 1431
 	return $new_string;
Please login to merge, or discard this patch.
Sources/Admin.php 1 patch
Braces   +75 added lines, -52 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
  * The main admin handling function.<br>
@@ -444,8 +445,9 @@  discard block
 block discarded – undo
444 445
 		foreach ($admin_includes as $include)
445 446
 		{
446 447
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
447
-			if (file_exists($include))
448
-				require_once($include);
448
+			if (file_exists($include)) {
449
+							require_once($include);
450
+			}
449 451
 		}
450 452
 	}
451 453
 
@@ -457,24 +459,27 @@  discard block
 block discarded – undo
457 459
 	unset($admin_areas);
458 460
 
459 461
 	// Nothing valid?
460
-	if ($admin_include_data == false)
461
-		fatal_lang_error('no_access', false);
462
+	if ($admin_include_data == false) {
463
+			fatal_lang_error('no_access', false);
464
+	}
462 465
 
463 466
 	// Build the link tree.
464 467
 	$context['linktree'][] = array(
465 468
 		'url' => $scripturl . '?action=admin',
466 469
 		'name' => $txt['admin_center'],
467 470
 	);
468
-	if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index')
469
-		$context['linktree'][] = array(
471
+	if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') {
472
+			$context['linktree'][] = array(
470 473
 			'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'],
471 474
 			'name' => $admin_include_data['label'],
472 475
 		);
473
-	if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label'])
474
-		$context['linktree'][] = array(
476
+	}
477
+	if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) {
478
+			$context['linktree'][] = array(
475 479
 			'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'],
476 480
 			'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0],
477 481
 		);
482
+	}
478 483
 
479 484
 	// Make a note of the Unique ID for this menu.
480 485
 	$context['admin_menu_id'] = $context['max_menu_id'];
@@ -484,16 +489,18 @@  discard block
 block discarded – undo
484 489
 	$context['admin_area'] = $admin_include_data['current_area'];
485 490
 
486 491
 	// Now - finally - call the right place!
487
-	if (isset($admin_include_data['file']))
488
-		require_once($sourcedir . '/' . $admin_include_data['file']);
492
+	if (isset($admin_include_data['file'])) {
493
+			require_once($sourcedir . '/' . $admin_include_data['file']);
494
+	}
489 495
 
490 496
 	// Get the right callable.
491 497
 	$call = call_helper($admin_include_data['function'], true);
492 498
 
493 499
 	// Is it valid?
494
-	if (!empty($call))
495
-		call_user_func($call);
496
-}
500
+	if (!empty($call)) {
501
+			call_user_func($call);
502
+	}
503
+	}
497 504
 
498 505
 /**
499 506
  * The main administration section.
@@ -547,13 +554,14 @@  discard block
 block discarded – undo
547 554
 
548 555
 	$context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin';
549 556
 	$context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center'];
550
-	if ($context['admin_area'] != 'credits')
551
-		$context[$context['admin_menu_name']]['tab_data'] = array(
557
+	if ($context['admin_area'] != 'credits') {
558
+			$context[$context['admin_menu_name']]['tab_data'] = array(
552 559
 			'title' => $txt['admin_center'],
553 560
 			'help' => '',
554 561
 			'description' => '<strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong>
555 562
 						' . sprintf($txt['admin_main_welcome'], $txt['admin_center'], $txt['help'], $txt['help']),
556 563
 		);
564
+	}
557 565
 
558 566
 	// Lastly, fill in the blanks in the support resources paragraphs.
559 567
 	$txt['support_resources_p1'] = sprintf($txt['support_resources_p1'],
@@ -571,9 +579,10 @@  discard block
 block discarded – undo
571 579
 		'https://www.simplemachines.org/redirect/customize_support'
572 580
 	);
573 581
 
574
-	if ($context['admin_area'] == 'admin')
575
-		loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin');
576
-}
582
+	if ($context['admin_area'] == 'admin') {
583
+			loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin');
584
+	}
585
+	}
577 586
 
578 587
 /**
579 588
  * Get one of the admin information files from Simple Machines.
@@ -584,8 +593,9 @@  discard block
 block discarded – undo
584 593
 
585 594
 	setMemoryLimit('32M');
586 595
 
587
-	if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename']))
588
-		fatal_lang_error('no_access', false);
596
+	if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) {
597
+			fatal_lang_error('no_access', false);
598
+	}
589 599
 
590 600
 	// Strip off the forum cache part or we won't find it...
591 601
 	$_REQUEST['filename'] = str_replace($modSettings['browser_cache'], '', $_REQUEST['filename']);
@@ -600,27 +610,30 @@  discard block
 block discarded – undo
600 610
 		)
601 611
 	);
602 612
 
603
-	if ($smcFunc['db_num_rows']($request) == 0)
604
-		fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404);
613
+	if ($smcFunc['db_num_rows']($request) == 0) {
614
+			fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404);
615
+	}
605 616
 
606 617
 	list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request);
607 618
 	$smcFunc['db_free_result']($request);
608 619
 
609 620
 	// @todo Temp
610 621
 	// Figure out if sesc is still being used.
611
-	if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript')
612
-		$file_data = '
622
+	if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') {
623
+			$file_data = '
613 624
 if (!(\'smfForum_sessionvar\' in window))
614 625
 	window.smfForum_sessionvar = \'sesc\';
615 626
 ' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'='));
627
+	}
616 628
 
617 629
 	$context['template_layers'] = array();
618 630
 	// Lets make sure we aren't going to output anything nasty.
619 631
 	@ob_end_clean();
620
-	if (!empty($modSettings['enableCompressedOutput']))
621
-		@ob_start('ob_gzhandler');
622
-	else
623
-		@ob_start();
632
+	if (!empty($modSettings['enableCompressedOutput'])) {
633
+			@ob_start('ob_gzhandler');
634
+	} else {
635
+			@ob_start();
636
+	}
624 637
 
625 638
 	// Make sure they know what type of file we are.
626 639
 	header('Content-Type: ' . $filetype);
@@ -660,11 +673,12 @@  discard block
 block discarded – undo
660 673
 		updateAdminPreferences();
661 674
 	}
662 675
 
663
-	if (trim($context['search_term']) == '')
664
-		$context['search_results'] = array();
665
-	else
666
-		call_helper($subActions[$context['search_type']]);
667
-}
676
+	if (trim($context['search_term']) == '') {
677
+			$context['search_results'] = array();
678
+	} else {
679
+			call_helper($subActions[$context['search_type']]);
680
+	}
681
+	}
668 682
 
669 683
 /**
670 684
  * A complicated but relatively quick internal search.
@@ -728,8 +742,9 @@  discard block
 block discarded – undo
728 742
 
729 743
 	loadLanguage(implode('+', $language_files));
730 744
 
731
-	foreach ($include_files as $file)
732
-		require_once($sourcedir . '/' . $file . '.php');
745
+	foreach ($include_files as $file) {
746
+			require_once($sourcedir . '/' . $file . '.php');
747
+	}
733 748
 
734 749
 	/* This is the huge array that defines everything... it's a huge array of items formatted as follows:
735 750
 		0 = Language index (Can be array of indexes) to search through for this setting.
@@ -753,11 +768,12 @@  discard block
 block discarded – undo
753 768
 		foreach ($section['areas'] as $menu_key => $menu_item)
754 769
 		{
755 770
 			$search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key);
756
-			if (!empty($menu_item['subsections']))
757
-				foreach ($menu_item['subsections'] as $key => $sublabel)
771
+			if (!empty($menu_item['subsections'])) {
772
+							foreach ($menu_item['subsections'] as $key => $sublabel)
758 773
 				{
759 774
 					if (isset($sublabel['label']))
760 775
 						$search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key);
776
+			}
761 777
 				}
762 778
 		}
763 779
 	}
@@ -767,9 +783,10 @@  discard block
 block discarded – undo
767 783
 		// Get a list of their variables.
768 784
 		$config_vars = $setting_area[0](true);
769 785
 
770
-		foreach ($config_vars as $var)
771
-			if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc')))
786
+		foreach ($config_vars as $var) {
787
+					if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc')))
772 788
 				$search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1]);
789
+		}
773 790
 	}
774 791
 
775 792
 	$context['page_title'] = $txt['admin_search_results'];
@@ -782,8 +799,9 @@  discard block
 block discarded – undo
782 799
 		foreach ($data as $item)
783 800
 		{
784 801
 			$found = false;
785
-			if (!is_array($item[0]))
786
-				$item[0] = array($item[0]);
802
+			if (!is_array($item[0])) {
803
+							$item[0] = array($item[0]);
804
+			}
787 805
 			foreach ($item[0] as $term)
788 806
 			{
789 807
 				if (stripos($term, $search_term) !== false || (isset($txt[$term]) && stripos($txt[$term], $search_term) !== false) || (isset($txt['setting_' . $term]) && stripos($txt['setting_' . $term], $search_term) !== false))
@@ -841,8 +859,9 @@  discard block
 block discarded – undo
841 859
 	$postVars = explode(' ', $context['search_term']);
842 860
 
843 861
 	// Encode the search data.
844
-	foreach ($postVars as $k => $v)
845
-		$postVars[$k] = urlencode($v);
862
+	foreach ($postVars as $k => $v) {
863
+			$postVars[$k] = urlencode($v);
864
+	}
846 865
 
847 866
 	// This is what we will send.
848 867
 	$postVars = implode('+', $postVars);
@@ -854,8 +873,9 @@  discard block
 block discarded – undo
854 873
 	$search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars);
855 874
 
856 875
 	// If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded?
857
-	if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true)
858
-		fatal_lang_error('cannot_connect_doc_site');
876
+	if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) {
877
+			fatal_lang_error('cannot_connect_doc_site');
878
+	}
859 879
 
860 880
 	$search_results = $matches[1];
861 881
 
@@ -867,8 +887,9 @@  discard block
 block discarded – undo
867 887
 	$results = new xmlArray($search_results, false);
868 888
 
869 889
 	// Move through the api layer.
870
-	if (!$results->exists('api'))
871
-		fatal_lang_error('cannot_connect_doc_site');
890
+	if (!$results->exists('api')) {
891
+			fatal_lang_error('cannot_connect_doc_site');
892
+	}
872 893
 
873 894
 	// Are there actually some results?
874 895
 	if ($results->exists('api/query/search/p'))
@@ -904,8 +925,9 @@  discard block
 block discarded – undo
904 925
 	);
905 926
 
906 927
 	// If it's not got a sa set it must have come here for first time, pretend error log should be reversed.
907
-	if (!isset($_REQUEST['sa']))
908
-		$_REQUEST['desc'] = true;
928
+	if (!isset($_REQUEST['sa'])) {
929
+			$_REQUEST['desc'] = true;
930
+	}
909 931
 
910 932
 	// Setup some tab stuff.
911 933
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -955,9 +977,10 @@  discard block
 block discarded – undo
955 977
 	unset($_SESSION['admin_time']);
956 978
 
957 979
 	// Clean any admin tokens as well.
958
-	foreach ($_SESSION['token'] as $key => $token)
959
-		if (strpos($key, '-admin') !== false)
980
+	foreach ($_SESSION['token'] as $key => $token) {
981
+			if (strpos($key, '-admin') !== false)
960 982
 			unset($_SESSION['token'][$key]);
983
+	}
961 984
 
962 985
 	redirectexit();
963 986
 }
Please login to merge, or discard this patch.
Sources/ManageSmileys.php 1 patch
Braces   +297 added lines, -211 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
  * This is the dispatcher of smileys administration.
@@ -91,8 +92,9 @@  discard block
 block discarded – undo
91 92
 	);
92 93
 
93 94
 	// Some settings may not be enabled, disallow these from the tabs as appropriate.
94
-	if (empty($modSettings['messageIcons_enable']))
95
-		$context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
95
+	if (empty($modSettings['messageIcons_enable'])) {
96
+			$context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
97
+	}
96 98
 	if (empty($modSettings['smiley_enable']))
97 99
 	{
98 100
 		$context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true;
@@ -125,8 +127,9 @@  discard block
 block discarded – undo
125 127
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
126 128
 
127 129
 	$smiley_context = array();
128
-	foreach ($smiley_sets as $i => $set)
129
-		$smiley_context[$set] = $set_names[$i];
130
+	foreach ($smiley_sets as $i => $set) {
131
+			$smiley_context[$set] = $set_names[$i];
132
+	}
130 133
 
131 134
 	// All the settings for the page...
132 135
 	$config_vars = array(
@@ -147,8 +150,9 @@  discard block
 block discarded – undo
147 150
 
148 151
 	call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars));
149 152
 
150
-	if ($return_config)
151
-		return $config_vars;
153
+	if ($return_config) {
154
+			return $config_vars;
155
+	}
152 156
 
153 157
 	// Setup the basics of the settings template.
154 158
 	require_once($sourcedir . '/ManageServer.php');
@@ -207,8 +211,9 @@  discard block
 block discarded – undo
207 211
 			foreach ($_POST['smiley_set'] as $id => $val)
208 212
 			{
209 213
 				// If this is the set you've marked as default, or the only one remaining, you can't delete it
210
-				if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id]))
211
-					unset($set_paths[$id], $set_names[$id]);
214
+				if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) {
215
+									unset($set_paths[$id], $set_names[$id]);
216
+				}
212 217
 			}
213 218
 
214 219
 			// Shortcut... array_merge() on a single array resets the numeric keys
@@ -222,8 +227,9 @@  discard block
 block discarded – undo
222 227
 			));
223 228
 		}
224 229
 		// Add a new smiley set.
225
-		elseif (!empty($_POST['add']))
226
-			$context['sub_action'] = 'modifyset';
230
+		elseif (!empty($_POST['add'])) {
231
+					$context['sub_action'] = 'modifyset';
232
+		}
227 233
 		// Create or modify a smiley set.
228 234
 		elseif (isset($_POST['set']))
229 235
 		{
@@ -233,8 +239,9 @@  discard block
 block discarded – undo
233 239
 			// Create a new smiley set.
234 240
 			if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path']))
235 241
 			{
236
-				if (in_array($_POST['smiley_sets_path'], $set_paths))
237
-					fatal_lang_error('smiley_set_already_exists');
242
+				if (in_array($_POST['smiley_sets_path'], $set_paths)) {
243
+									fatal_lang_error('smiley_set_already_exists');
244
+				}
238 245
 
239 246
 				updateSettings(array(
240 247
 					'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'],
@@ -246,12 +253,14 @@  discard block
 block discarded – undo
246 253
 			else
247 254
 			{
248 255
 				// Make sure the smiley set exists.
249
-				if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']]))
250
-					fatal_lang_error('smiley_set_not_found');
256
+				if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) {
257
+									fatal_lang_error('smiley_set_not_found');
258
+				}
251 259
 
252 260
 				// Make sure the path is not yet used by another smileyset.
253
-				if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']])
254
-					fatal_lang_error('smiley_set_path_already_used');
261
+				if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) {
262
+									fatal_lang_error('smiley_set_path_already_used');
263
+				}
255 264
 
256 265
 				$set_paths[$_POST['set']] = $_POST['smiley_sets_path'];
257 266
 				$set_names[$_POST['set']] = $_POST['smiley_sets_name'];
@@ -263,8 +272,9 @@  discard block
 block discarded – undo
263 272
 			}
264 273
 
265 274
 			// The user might have checked to also import smileys.
266
-			if (!empty($_POST['smiley_sets_import']))
267
-				ImportSmileys($_POST['smiley_sets_path']);
275
+			if (!empty($_POST['smiley_sets_import'])) {
276
+							ImportSmileys($_POST['smiley_sets_path']);
277
+			}
268 278
 		}
269 279
 		cache_put_data('parsing_smileys', null, 480);
270 280
 		cache_put_data('posting_smileys', null, 480);
@@ -273,13 +283,14 @@  discard block
 block discarded – undo
273 283
 	// Load all available smileysets...
274 284
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
275 285
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
276
-	foreach ($context['smiley_sets'] as $i => $set)
277
-		$context['smiley_sets'][$i] = array(
286
+	foreach ($context['smiley_sets'] as $i => $set) {
287
+			$context['smiley_sets'][$i] = array(
278 288
 			'id' => $i,
279 289
 			'path' => $smcFunc['htmlspecialchars']($set),
280 290
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
281 291
 			'selected' => $set == $modSettings['smiley_sets_default']
282 292
 		);
293
+	}
283 294
 
284 295
 	// Importing any smileys from an existing set?
285 296
 	if ($context['sub_action'] == 'import')
@@ -290,8 +301,9 @@  discard block
 block discarded – undo
290 301
 		$_GET['set'] = (int) $_GET['set'];
291 302
 
292 303
 		// Sanity check - then import.
293
-		if (isset($context['smiley_sets'][$_GET['set']]))
294
-			ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
304
+		if (isset($context['smiley_sets'][$_GET['set']])) {
305
+					ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
306
+		}
295 307
 
296 308
 		// Force the process to continue.
297 309
 		$context['sub_action'] = 'modifyset';
@@ -301,15 +313,15 @@  discard block
 block discarded – undo
301 313
 	if ($context['sub_action'] == 'modifyset')
302 314
 	{
303 315
 		$_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set'];
304
-		if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']]))
305
-			$context['current_set'] = array(
316
+		if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) {
317
+					$context['current_set'] = array(
306 318
 				'id' => '-1',
307 319
 				'path' => '',
308 320
 				'name' => '',
309 321
 				'selected' => false,
310 322
 				'is_new' => true,
311 323
 			);
312
-		else
324
+		} else
313 325
 		{
314 326
 			$context['current_set'] = &$context['smiley_sets'][$_GET['set']];
315 327
 			$context['current_set']['is_new'] = false;
@@ -321,13 +333,15 @@  discard block
 block discarded – undo
321 333
 				$dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']);
322 334
 				while ($entry = $dir->read())
323 335
 				{
324
-					if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
325
-						$smileys[strtolower($entry)] = $entry;
336
+					if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
337
+											$smileys[strtolower($entry)] = $entry;
338
+					}
326 339
 				}
327 340
 				$dir->close();
328 341
 
329
-				if (empty($smileys))
330
-					fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name']));
342
+				if (empty($smileys)) {
343
+									fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name']));
344
+				}
331 345
 
332 346
 				// Exclude the smileys that are already in the database.
333 347
 				$request = $smcFunc['db_query']('', '
@@ -338,9 +352,10 @@  discard block
 block discarded – undo
338 352
 						'smiley_list' => $smileys,
339 353
 					)
340 354
 				);
341
-				while ($row = $smcFunc['db_fetch_assoc']($request))
342
-					if (isset($smileys[strtolower($row['filename'])]))
355
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
356
+									if (isset($smileys[strtolower($row['filename'])]))
343 357
 						unset($smileys[strtolower($row['filename'])]);
358
+				}
344 359
 				$smcFunc['db_free_result']($request);
345 360
 
346 361
 				$context['current_set']['can_import'] = count($smileys);
@@ -355,13 +370,14 @@  discard block
 block discarded – undo
355 370
 			$dir = dir($modSettings['smileys_dir']);
356 371
 			while ($entry = $dir->read())
357 372
 			{
358
-				if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry))
359
-					$context['smiley_set_dirs'][] = array(
373
+				if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) {
374
+									$context['smiley_set_dirs'][] = array(
360 375
 						'id' => $entry,
361 376
 						'path' => $modSettings['smileys_dir'] . '/' . $entry,
362 377
 						'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])),
363 378
 						'current' => $entry == $context['current_set']['path'],
364 379
 					);
380
+				}
365 381
 			}
366 382
 			$dir->close();
367 383
 		}
@@ -371,8 +387,9 @@  discard block
 block discarded – undo
371 387
 	createToken('admin-mss', 'request');
372 388
 
373 389
 	// In case we need to import smileys, we need to add the token in now.
374
-	if (isset($context['current_set']['import_url']))
375
-		$context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token'];
390
+	if (isset($context['current_set']['import_url'])) {
391
+			$context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token'];
392
+	}
376 393
 
377 394
 	$listOptions = array(
378 395
 		'id' => 'smiley_set_list',
@@ -510,21 +527,23 @@  discard block
 block discarded – undo
510 527
 		$cols['name'][] = $set_names[$i];
511 528
 	}
512 529
 	$sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC;
513
-	if (substr($sort, 0, 4) === 'name')
514
-		array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']);
515
-	elseif (substr($sort, 0, 4) === 'path')
516
-		array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']);
517
-	else
518
-		array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']);
530
+	if (substr($sort, 0, 4) === 'name') {
531
+			array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']);
532
+	} elseif (substr($sort, 0, 4) === 'path') {
533
+			array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']);
534
+	} else {
535
+			array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']);
536
+	}
519 537
 
520 538
 	$smiley_sets = array();
521
-	foreach ($cols['id'] as $i => $id)
522
-		$smiley_sets[] = array(
539
+	foreach ($cols['id'] as $i => $id) {
540
+			$smiley_sets[] = array(
523 541
 			'id' => $id,
524 542
 			'path' => $cols['path'][$i],
525 543
 			'name' => $cols['name'][$i],
526 544
 			'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default']
527 545
 		);
546
+	}
528 547
 
529 548
 	return $smiley_sets;
530 549
 }
@@ -553,13 +572,14 @@  discard block
 block discarded – undo
553 572
 	$context['smileys_dir_found'] = is_dir($context['smileys_dir']);
554 573
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
555 574
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
556
-	foreach ($context['smiley_sets'] as $i => $set)
557
-		$context['smiley_sets'][$i] = array(
575
+	foreach ($context['smiley_sets'] as $i => $set) {
576
+			$context['smiley_sets'][$i] = array(
558 577
 			'id' => $i,
559 578
 			'path' => $smcFunc['htmlspecialchars']($set),
560 579
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
561 580
 			'selected' => $set == $modSettings['smiley_sets_default']
562 581
 		);
582
+	}
563 583
 
564 584
 	// Submitting a form?
565 585
 	if (isset($_POST[$context['session_var']], $_POST['smiley_code']))
@@ -575,8 +595,9 @@  discard block
 block discarded – undo
575 595
 		$_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']);
576 596
 
577 597
 		// Make sure some code was entered.
578
-		if (empty($_POST['smiley_code']))
579
-			fatal_lang_error('smiley_has_no_code');
598
+		if (empty($_POST['smiley_code'])) {
599
+					fatal_lang_error('smiley_has_no_code');
600
+		}
580 601
 
581 602
 		// Check whether the new code has duplicates. It should be unique.
582 603
 		$request = $smcFunc['db_query']('', '
@@ -588,8 +609,9 @@  discard block
 block discarded – undo
588 609
 				'smiley_code' => $_POST['smiley_code'],
589 610
 			)
590 611
 		);
591
-		if ($smcFunc['db_num_rows']($request) > 0)
592
-			fatal_lang_error('smiley_not_unique');
612
+		if ($smcFunc['db_num_rows']($request) > 0) {
613
+					fatal_lang_error('smiley_not_unique');
614
+		}
593 615
 		$smcFunc['db_free_result']($request);
594 616
 
595 617
 		// If we are uploading - check all the smiley sets are writable!
@@ -598,38 +620,44 @@  discard block
 block discarded – undo
598 620
 			$writeErrors = array();
599 621
 			foreach ($context['smiley_sets'] as $set)
600 622
 			{
601
-				if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path'])))
602
-					$writeErrors[] = $set['path'];
623
+				if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) {
624
+									$writeErrors[] = $set['path'];
625
+				}
626
+			}
627
+			if (!empty($writeErrors)) {
628
+							fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
603 629
 			}
604
-			if (!empty($writeErrors))
605
-				fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
606 630
 		}
607 631
 
608 632
 		// Uploading just one smiley for all of them?
609 633
 		if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '')
610 634
 		{
611
-			if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name'])))
612
-				fatal_lang_error('smileys_upload_error');
635
+			if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) {
636
+							fatal_lang_error('smileys_upload_error');
637
+			}
613 638
 
614 639
 			// Sorry, no spaces, dots, or anything else but letters allowed.
615 640
 			$_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']);
616 641
 
617 642
 			// We only allow image files - it's THAT simple - no messing around here...
618
-			if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes))
619
-				fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
643
+			if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) {
644
+							fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
645
+			}
620 646
 
621 647
 			// We only need the filename...
622 648
 			$destName = basename($_FILES['uploadSmiley']['name']);
623 649
 
624 650
 			// Make sure they aren't trying to upload a nasty file - for their own good here!
625
-			if (in_array(strtolower($destName), $disabledFiles))
626
-				fatal_lang_error('smileys_upload_error_illegal');
651
+			if (in_array(strtolower($destName), $disabledFiles)) {
652
+							fatal_lang_error('smileys_upload_error_illegal');
653
+			}
627 654
 
628 655
 			// Check if the file already exists... and if not move it to EVERY smiley set directory.
629 656
 			$i = 0;
630 657
 			// Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?)
631
-			while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName))
632
-				$i++;
658
+			while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) {
659
+							$i++;
660
+			}
633 661
 
634 662
 			// Okay, we're going to put the smiley right here, since it's not there yet!
635 663
 			if (isset($context['smiley_sets'][$i]['path']))
@@ -644,8 +672,9 @@  discard block
 block discarded – undo
644 672
 					$currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName;
645 673
 
646 674
 					// The file is already there!  Don't overwrite it!
647
-					if (file_exists($currentPath))
648
-						continue;
675
+					if (file_exists($currentPath)) {
676
+											continue;
677
+					}
649 678
 
650 679
 					// Okay, so copy the first one we made to here.
651 680
 					copy($smileyLocation, $currentPath);
@@ -662,13 +691,15 @@  discard block
 block discarded – undo
662 691
 			$newName = '';
663 692
 			foreach ($_FILES as $name => $data)
664 693
 			{
665
-				if ($_FILES[$name]['name'] == '')
666
-					fatal_lang_error('smileys_upload_error_blank');
694
+				if ($_FILES[$name]['name'] == '') {
695
+									fatal_lang_error('smileys_upload_error_blank');
696
+				}
667 697
 
668
-				if (empty($newName))
669
-					$newName = basename($_FILES[$name]['name']);
670
-				elseif (basename($_FILES[$name]['name']) != $newName)
671
-					fatal_lang_error('smileys_upload_error_name');
698
+				if (empty($newName)) {
699
+									$newName = basename($_FILES[$name]['name']);
700
+				} elseif (basename($_FILES[$name]['name']) != $newName) {
701
+									fatal_lang_error('smileys_upload_error_name');
702
+				}
672 703
 			}
673 704
 
674 705
 			foreach ($context['smiley_sets'] as $i => $set)
@@ -676,31 +707,36 @@  discard block
 block discarded – undo
676 707
 				$set['name'] = un_htmlspecialchars($set['name']);
677 708
 				$set['path'] = un_htmlspecialchars($set['path']);
678 709
 
679
-				if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '')
680
-					continue;
710
+				if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') {
711
+									continue;
712
+				}
681 713
 
682 714
 				// Got one...
683
-				if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name'])))
684
-					fatal_lang_error('smileys_upload_error');
715
+				if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) {
716
+									fatal_lang_error('smileys_upload_error');
717
+				}
685 718
 
686 719
 				// Sorry, no spaces, dots, or anything else but letters allowed.
687 720
 				$_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']);
688 721
 
689 722
 				// We only allow image files - it's THAT simple - no messing around here...
690
-				if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes))
691
-					fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
723
+				if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) {
724
+									fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
725
+				}
692 726
 
693 727
 				// We only need the filename...
694 728
 				$destName = basename($_FILES['individual_' . $set['name']]['name']);
695 729
 
696 730
 				// Make sure they aren't trying to upload a nasty file - for their own good here!
697
-				if (in_array(strtolower($destName), $disabledFiles))
698
-					fatal_lang_error('smileys_upload_error_illegal');
731
+				if (in_array(strtolower($destName), $disabledFiles)) {
732
+									fatal_lang_error('smileys_upload_error_illegal');
733
+				}
699 734
 
700 735
 				// If the file exists - ignore it.
701 736
 				$smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName;
702
-				if (file_exists($smileyLocation))
703
-					continue;
737
+				if (file_exists($smileyLocation)) {
738
+									continue;
739
+				}
704 740
 
705 741
 				// Finally - move the image!
706 742
 				move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation);
@@ -712,8 +748,9 @@  discard block
 block discarded – undo
712 748
 		}
713 749
 
714 750
 		// Also make sure a filename was given.
715
-		if (empty($_POST['smiley_filename']))
716
-			fatal_lang_error('smiley_has_no_filename');
751
+		if (empty($_POST['smiley_filename'])) {
752
+					fatal_lang_error('smiley_has_no_filename');
753
+		}
717 754
 
718 755
 		// Find the position on the right.
719 756
 		$smiley_order = '0';
@@ -732,8 +769,9 @@  discard block
 block discarded – undo
732 769
 			list ($smiley_order) = $smcFunc['db_fetch_row']($request);
733 770
 			$smcFunc['db_free_result']($request);
734 771
 
735
-			if (empty($smiley_order))
736
-				$smiley_order = '0';
772
+			if (empty($smiley_order)) {
773
+							$smiley_order = '0';
774
+			}
737 775
 		}
738 776
 		$smcFunc['db_insert']('',
739 777
 			'{db_prefix}smileys',
@@ -761,17 +799,19 @@  discard block
 block discarded – undo
761 799
 	{
762 800
 		foreach ($context['smiley_sets'] as $smiley_set)
763 801
 		{
764
-			if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
765
-				continue;
802
+			if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) {
803
+							continue;
804
+			}
766 805
 
767 806
 			$dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
768 807
 			while ($entry = $dir->read())
769 808
 			{
770
-				if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
771
-					$context['filenames'][strtolower($entry)] = array(
809
+				if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
810
+									$context['filenames'][strtolower($entry)] = array(
772 811
 						'id' => $smcFunc['htmlspecialchars']($entry),
773 812
 						'selected' => false,
774 813
 					);
814
+				}
775 815
 			}
776 816
 			$dir->close();
777 817
 		}
@@ -809,17 +849,19 @@  discard block
 block discarded – undo
809 849
 		// Changing the selected smileys?
810 850
 		if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys']))
811 851
 		{
812
-			foreach ($_POST['checked_smileys'] as $id => $smiley_id)
813
-				$_POST['checked_smileys'][$id] = (int) $smiley_id;
852
+			foreach ($_POST['checked_smileys'] as $id => $smiley_id) {
853
+							$_POST['checked_smileys'][$id] = (int) $smiley_id;
854
+			}
814 855
 
815
-			if ($_POST['smiley_action'] == 'delete')
816
-				$smcFunc['db_query']('', '
856
+			if ($_POST['smiley_action'] == 'delete') {
857
+							$smcFunc['db_query']('', '
817 858
 					DELETE FROM {db_prefix}smileys
818 859
 					WHERE id_smiley IN ({array_int:checked_smileys})',
819 860
 					array(
820 861
 						'checked_smileys' => $_POST['checked_smileys'],
821 862
 					)
822 863
 				);
864
+			}
823 865
 			// Changing the status of the smiley?
824 866
 			else
825 867
 			{
@@ -829,8 +871,8 @@  discard block
 block discarded – undo
829 871
 					'hidden' => 1,
830 872
 					'popup' => 2
831 873
 				);
832
-				if (isset($displayTypes[$_POST['smiley_action']]))
833
-					$smcFunc['db_query']('', '
874
+				if (isset($displayTypes[$_POST['smiley_action']])) {
875
+									$smcFunc['db_query']('', '
834 876
 						UPDATE {db_prefix}smileys
835 877
 						SET hidden = {int:display_type}
836 878
 						WHERE id_smiley IN ({array_int:checked_smileys})',
@@ -839,6 +881,7 @@  discard block
 block discarded – undo
839 881
 							'display_type' => $displayTypes[$_POST['smiley_action']],
840 882
 						)
841 883
 					);
884
+				}
842 885
 			}
843 886
 		}
844 887
 		// Create/modify a smiley.
@@ -864,12 +907,14 @@  discard block
 block discarded – undo
864 907
 				$_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location'];
865 908
 
866 909
 				// Make sure some code was entered.
867
-				if (empty($_POST['smiley_code']))
868
-					fatal_lang_error('smiley_has_no_code');
910
+				if (empty($_POST['smiley_code'])) {
911
+									fatal_lang_error('smiley_has_no_code');
912
+				}
869 913
 
870 914
 				// Also make sure a filename was given.
871
-				if (empty($_POST['smiley_filename']))
872
-					fatal_lang_error('smiley_has_no_filename');
915
+				if (empty($_POST['smiley_filename'])) {
916
+									fatal_lang_error('smiley_has_no_filename');
917
+				}
873 918
 
874 919
 				// Check whether the new code has duplicates. It should be unique.
875 920
 				$request = $smcFunc['db_query']('', '
@@ -883,8 +928,9 @@  discard block
 block discarded – undo
883 928
 						'smiley_code' => $_POST['smiley_code'],
884 929
 					)
885 930
 				);
886
-				if ($smcFunc['db_num_rows']($request) > 0)
887
-					fatal_lang_error('smiley_not_unique');
931
+				if ($smcFunc['db_num_rows']($request) > 0) {
932
+									fatal_lang_error('smiley_not_unique');
933
+				}
888 934
 				$smcFunc['db_free_result']($request);
889 935
 
890 936
 				$smcFunc['db_query']('', '
@@ -913,13 +959,14 @@  discard block
 block discarded – undo
913 959
 	// Load all known smiley sets.
914 960
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
915 961
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
916
-	foreach ($context['smiley_sets'] as $i => $set)
917
-		$context['smiley_sets'][$i] = array(
962
+	foreach ($context['smiley_sets'] as $i => $set) {
963
+			$context['smiley_sets'][$i] = array(
918 964
 			'id' => $i,
919 965
 			'path' => $smcFunc['htmlspecialchars']($set),
920 966
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
921 967
 			'selected' => $set == $modSettings['smiley_sets_default']
922 968
 		);
969
+	}
923 970
 
924 971
 	// Prepare overview of all (custom) smileys.
925 972
 	if ($context['sub_action'] == 'editsmileys')
@@ -935,9 +982,10 @@  discard block
 block discarded – undo
935 982
 		// Create a list of options for selecting smiley sets.
936 983
 		$smileyset_option_list = '
937 984
 			<select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">';
938
-		foreach ($context['smiley_sets'] as $smiley_set)
939
-			$smileyset_option_list .= '
985
+		foreach ($context['smiley_sets'] as $smiley_set) {
986
+					$smileyset_option_list .= '
940 987
 				<option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>';
988
+		}
941 989
 		$smileyset_option_list .= '
942 990
 			</select>';
943 991
 
@@ -999,12 +1047,13 @@  discard block
 block discarded – undo
999 1047
 					'data' => array(
1000 1048
 						'function' => function ($rowData) use ($txt)
1001 1049
 						{
1002
-							if (empty($rowData['hidden']))
1003
-								return $txt['smileys_location_form'];
1004
-							elseif ($rowData['hidden'] == 1)
1005
-								return $txt['smileys_location_hidden'];
1006
-							else
1007
-								return $txt['smileys_location_popup'];
1050
+							if (empty($rowData['hidden'])) {
1051
+															return $txt['smileys_location_form'];
1052
+							} elseif ($rowData['hidden'] == 1) {
1053
+															return $txt['smileys_location_hidden'];
1054
+							} else {
1055
+															return $txt['smileys_location_popup'];
1056
+							}
1008 1057
 						},
1009 1058
 					),
1010 1059
 					'sort' => array(
@@ -1019,19 +1068,22 @@  discard block
 block discarded – undo
1019 1068
 					'data' => array(
1020 1069
 						'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc)
1021 1070
 						{
1022
-							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir']))
1023
-								return $smcFunc['htmlspecialchars']($rowData['description']);
1071
+							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) {
1072
+															return $smcFunc['htmlspecialchars']($rowData['description']);
1073
+							}
1024 1074
 
1025 1075
 							// Check if there are smileys missing in some sets.
1026 1076
 							$missing_sets = array();
1027
-							foreach ($context['smiley_sets'] as $smiley_set)
1028
-								if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename'])))
1077
+							foreach ($context['smiley_sets'] as $smiley_set) {
1078
+															if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename'])))
1029 1079
 									$missing_sets[] = $smiley_set['path'];
1080
+							}
1030 1081
 
1031 1082
 							$description = $smcFunc['htmlspecialchars']($rowData['description']);
1032 1083
 
1033
-							if (!empty($missing_sets))
1034
-								$description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets));
1084
+							if (!empty($missing_sets)) {
1085
+															$description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets));
1086
+							}
1035 1087
 
1036 1088
 							return $description;
1037 1089
 						},
@@ -1147,13 +1199,14 @@  discard block
 block discarded – undo
1147 1199
 		$context['smileys_dir_found'] = is_dir($context['smileys_dir']);
1148 1200
 		$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
1149 1201
 		$set_names = explode("\n", $modSettings['smiley_sets_names']);
1150
-		foreach ($context['smiley_sets'] as $i => $set)
1151
-			$context['smiley_sets'][$i] = array(
1202
+		foreach ($context['smiley_sets'] as $i => $set) {
1203
+					$context['smiley_sets'][$i] = array(
1152 1204
 				'id' => $i,
1153 1205
 				'path' => $smcFunc['htmlspecialchars']($set),
1154 1206
 				'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
1155 1207
 				'selected' => $set == $modSettings['smiley_sets_default']
1156 1208
 			);
1209
+		}
1157 1210
 
1158 1211
 		$context['selected_set'] = $modSettings['smiley_sets_default'];
1159 1212
 
@@ -1163,17 +1216,19 @@  discard block
 block discarded – undo
1163 1216
 		{
1164 1217
 			foreach ($context['smiley_sets'] as $smiley_set)
1165 1218
 			{
1166
-				if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
1167
-					continue;
1219
+				if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) {
1220
+									continue;
1221
+				}
1168 1222
 
1169 1223
 				$dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
1170 1224
 				while ($entry = $dir->read())
1171 1225
 				{
1172
-					if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
1173
-						$context['filenames'][strtolower($entry)] = array(
1226
+					if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
1227
+											$context['filenames'][strtolower($entry)] = array(
1174 1228
 							'id' => $smcFunc['htmlspecialchars']($entry),
1175 1229
 							'selected' => false,
1176 1230
 						);
1231
+					}
1177 1232
 				}
1178 1233
 				$dir->close();
1179 1234
 			}
@@ -1188,8 +1243,9 @@  discard block
 block discarded – undo
1188 1243
 				'current_smiley' => (int) $_REQUEST['smiley'],
1189 1244
 			)
1190 1245
 		);
1191
-		if ($smcFunc['db_num_rows']($request) != 1)
1192
-			fatal_lang_error('smiley_not_found');
1246
+		if ($smcFunc['db_num_rows']($request) != 1) {
1247
+					fatal_lang_error('smiley_not_found');
1248
+		}
1193 1249
 		$context['current_smiley'] = $smcFunc['db_fetch_assoc']($request);
1194 1250
 		$smcFunc['db_free_result']($request);
1195 1251
 
@@ -1197,8 +1253,9 @@  discard block
 block discarded – undo
1197 1253
 		$context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']);
1198 1254
 		$context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']);
1199 1255
 
1200
-		if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])]))
1201
-			$context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
1256
+		if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) {
1257
+					$context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
1258
+		}
1202 1259
 	}
1203 1260
 }
1204 1261
 
@@ -1223,8 +1280,9 @@  discard block
 block discarded – undo
1223 1280
 		)
1224 1281
 	);
1225 1282
 	$smileys = array();
1226
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1227
-		$smileys[] = $row;
1283
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1284
+			$smileys[] = $row;
1285
+	}
1228 1286
 	$smcFunc['db_free_result']($request);
1229 1287
 
1230 1288
 	return $smileys;
@@ -1264,8 +1322,9 @@  discard block
 block discarded – undo
1264 1322
 		$_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2;
1265 1323
 		$_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source'];
1266 1324
 
1267
-		if (empty($_GET['source']))
1268
-			fatal_lang_error('smiley_not_found');
1325
+		if (empty($_GET['source'])) {
1326
+					fatal_lang_error('smiley_not_found');
1327
+		}
1269 1328
 
1270 1329
 		if (!empty($_GET['after']))
1271 1330
 		{
@@ -1281,12 +1340,12 @@  discard block
 block discarded – undo
1281 1340
 					'after_smiley' => $_GET['after'],
1282 1341
 				)
1283 1342
 			);
1284
-			if ($smcFunc['db_num_rows']($request) != 1)
1285
-				fatal_lang_error('smiley_not_found');
1343
+			if ($smcFunc['db_num_rows']($request) != 1) {
1344
+							fatal_lang_error('smiley_not_found');
1345
+			}
1286 1346
 			list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request);
1287 1347
 			$smcFunc['db_free_result']($request);
1288
-		}
1289
-		else
1348
+		} else
1290 1349
 		{
1291 1350
 			$smiley_row = (int) $_GET['row'];
1292 1351
 			$smiley_order = -1;
@@ -1360,14 +1419,15 @@  discard block
 block discarded – undo
1360 1419
 	$context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move'];
1361 1420
 
1362 1421
 	// Make sure all rows are sequential.
1363
-	foreach (array_keys($context['smileys']) as $location)
1364
-		$context['smileys'][$location] = array(
1422
+	foreach (array_keys($context['smileys']) as $location) {
1423
+			$context['smileys'][$location] = array(
1365 1424
 			'id' => $location,
1366 1425
 			'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'],
1367 1426
 			'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'],
1368 1427
 			'last_row' => count($context['smileys'][$location]['rows']),
1369 1428
 			'rows' => array_values($context['smileys'][$location]['rows']),
1370 1429
 		);
1430
+	}
1371 1431
 
1372 1432
 	// Check & fix smileys that are not ordered properly in the database.
1373 1433
 	foreach (array_keys($context['smileys']) as $location)
@@ -1392,8 +1452,8 @@  discard block
 block discarded – undo
1392 1452
 				$context['smileys'][$location]['rows'][$id][0]['row'] = $id;
1393 1453
 			}
1394 1454
 			// Make sure the smiley order is always sequential.
1395
-			foreach ($smiley_row as $order_id => $smiley)
1396
-				if ($order_id != $smiley['order'])
1455
+			foreach ($smiley_row as $order_id => $smiley) {
1456
+							if ($order_id != $smiley['order'])
1397 1457
 					$smcFunc['db_query']('', '
1398 1458
 						UPDATE {db_prefix}smileys
1399 1459
 						SET smiley_order = {int:new_order}
@@ -1403,6 +1463,7 @@  discard block
 block discarded – undo
1403 1463
 							'current_smiley' => $smiley['id'],
1404 1464
 						)
1405 1465
 					);
1466
+			}
1406 1467
 		}
1407 1468
 	}
1408 1469
 
@@ -1436,19 +1497,20 @@  discard block
 block discarded – undo
1436 1497
 
1437 1498
 		// Check that the smiley is from simplemachines.org, for now... maybe add mirroring later.
1438 1499
 		// @ TODO: Our current xml files serve http links.  Allowing both for now until we serve https.
1439
-		if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false)
1440
-			fatal_lang_error('not_on_simplemachines');
1500
+		if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) {
1501
+					fatal_lang_error('not_on_simplemachines');
1502
+		}
1441 1503
 
1442 1504
 		$destination = $packagesdir . '/' . $base_name;
1443 1505
 
1444
-		if (file_exists($destination))
1445
-			fatal_lang_error('package_upload_error_exists');
1506
+		if (file_exists($destination)) {
1507
+					fatal_lang_error('package_upload_error_exists');
1508
+		}
1446 1509
 
1447 1510
 		// Let's copy it to the Packages directory
1448 1511
 		file_put_contents($destination, fetch_web_data($_REQUEST['set_gz']));
1449 1512
 		$testing = true;
1450
-	}
1451
-	elseif (isset($_REQUEST['package']))
1513
+	} elseif (isset($_REQUEST['package']))
1452 1514
 	{
1453 1515
 		$base_name = basename($_REQUEST['package']);
1454 1516
 		$name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.'));
@@ -1457,12 +1519,14 @@  discard block
 block discarded – undo
1457 1519
 		$destination = $packagesdir . '/' . basename($_REQUEST['package']);
1458 1520
 	}
1459 1521
 
1460
-	if (empty($destination) || !file_exists($destination))
1461
-		fatal_lang_error('package_no_file', false);
1522
+	if (empty($destination) || !file_exists($destination)) {
1523
+			fatal_lang_error('package_no_file', false);
1524
+	}
1462 1525
 
1463 1526
 	// Make sure temp directory exists and is empty.
1464
-	if (file_exists($packagesdir . '/temp'))
1465
-		deltree($packagesdir . '/temp', false);
1527
+	if (file_exists($packagesdir . '/temp')) {
1528
+			deltree($packagesdir . '/temp', false);
1529
+	}
1466 1530
 
1467 1531
 	if (!mktree($packagesdir . '/temp', 0755))
1468 1532
 	{
@@ -1474,31 +1538,37 @@  discard block
 block discarded – undo
1474 1538
 			create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true));
1475 1539
 
1476 1540
 			deltree($packagesdir . '/temp', false);
1477
-			if (!mktree($packagesdir . '/temp', 0777))
1478
-				fatal_lang_error('package_cant_download', false);
1541
+			if (!mktree($packagesdir . '/temp', 0777)) {
1542
+							fatal_lang_error('package_cant_download', false);
1543
+			}
1479 1544
 		}
1480 1545
 	}
1481 1546
 
1482 1547
 	$extracted = read_tgz_file($destination, $packagesdir . '/temp');
1483
-	if (!$extracted)
1484
-		fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name));
1485
-	if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml'))
1486
-		foreach ($extracted as $file)
1548
+	if (!$extracted) {
1549
+			fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name));
1550
+	}
1551
+	if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) {
1552
+			foreach ($extracted as $file)
1487 1553
 			if (basename($file['filename']) == 'package-info.xml')
1488 1554
 			{
1489 1555
 				$base_path = dirname($file['filename']) . '/';
1556
+	}
1490 1557
 				break;
1491 1558
 			}
1492 1559
 
1493
-	if (!isset($base_path))
1494
-		$base_path = '';
1560
+	if (!isset($base_path)) {
1561
+			$base_path = '';
1562
+	}
1495 1563
 
1496
-	if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml'))
1497
-		fatal_lang_error('package_get_error_missing_xml', false);
1564
+	if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) {
1565
+			fatal_lang_error('package_get_error_missing_xml', false);
1566
+	}
1498 1567
 
1499 1568
 	$smileyInfo = getPackageInfo($context['filename']);
1500
-	if (!is_array($smileyInfo))
1501
-		fatal_lang_error($smileyInfo);
1569
+	if (!is_array($smileyInfo)) {
1570
+			fatal_lang_error($smileyInfo);
1571
+	}
1502 1572
 
1503 1573
 	// See if it is installed?
1504 1574
 	$request = $smcFunc['db_query']('', '
@@ -1514,8 +1584,9 @@  discard block
 block discarded – undo
1514 1584
 		)
1515 1585
 	);
1516 1586
 
1517
-	if ($smcFunc['db_num_rows']($request) > 0)
1518
-		fata_lang_error('package_installed_warning1');
1587
+	if ($smcFunc['db_num_rows']($request) > 0) {
1588
+			fata_lang_error('package_installed_warning1');
1589
+	}
1519 1590
 
1520 1591
 	// Everything is fine, now it's time to do something
1521 1592
 	$actions = parsePackageInfo($smileyInfo['xml'], true, 'install');
@@ -1532,23 +1603,23 @@  discard block
 block discarded – undo
1532 1603
 		{
1533 1604
 			$has_readme = true;
1534 1605
 			$type = 'package_' . $action['type'];
1535
-			if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename']))
1536
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r"));
1537
-			elseif (file_exists($action['filename']))
1538
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
1606
+			if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) {
1607
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r"));
1608
+			} elseif (file_exists($action['filename'])) {
1609
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
1610
+			}
1539 1611
 
1540 1612
 			if (!empty($action['parse_bbc']))
1541 1613
 			{
1542 1614
 				require_once($sourcedir . '/Subs-Post.php');
1543 1615
 				preparsecode($context[$type]);
1544 1616
 				$context[$type] = parse_bbc($context[$type]);
1617
+			} else {
1618
+							$context[$type] = nl2br($context[$type]);
1545 1619
 			}
1546
-			else
1547
-				$context[$type] = nl2br($context[$type]);
1548 1620
 
1549 1621
 			continue;
1550
-		}
1551
-		elseif ($action['type'] == 'require-dir')
1622
+		} elseif ($action['type'] == 'require-dir')
1552 1623
 		{
1553 1624
 			// Do this one...
1554 1625
 			$thisAction = array(
@@ -1567,12 +1638,12 @@  discard block
 block discarded – undo
1567 1638
 				);
1568 1639
 			}
1569 1640
 			// @todo None given?
1570
-			if (empty($thisAction['description']))
1571
-				$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
1641
+			if (empty($thisAction['description'])) {
1642
+							$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
1643
+			}
1572 1644
 
1573 1645
 			$context['actions'][] = $thisAction;
1574
-		}
1575
-		elseif ($action['type'] == 'credits')
1646
+		} elseif ($action['type'] == 'credits')
1576 1647
 		{
1577 1648
 			// Time to build the billboard
1578 1649
 			$credits_tag = array(
@@ -1631,12 +1702,14 @@  discard block
 block discarded – undo
1631 1702
 		cache_put_data('posting_smileys', null, 480);
1632 1703
 	}
1633 1704
 
1634
-	if (file_exists($packagesdir . '/temp'))
1635
-		deltree($packagesdir . '/temp');
1705
+	if (file_exists($packagesdir . '/temp')) {
1706
+			deltree($packagesdir . '/temp');
1707
+	}
1636 1708
 
1637
-	if (!$testing)
1638
-		redirectexit('action=admin;area=smileys');
1639
-}
1709
+	if (!$testing) {
1710
+			redirectexit('action=admin;area=smileys');
1711
+	}
1712
+	}
1640 1713
 
1641 1714
 /**
1642 1715
  * A function to import new smileys from an existing directory into the database.
@@ -1647,15 +1720,17 @@  discard block
 block discarded – undo
1647 1720
 {
1648 1721
 	global $modSettings, $smcFunc;
1649 1722
 
1650
-	if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath))
1651
-		fatal_lang_error('smiley_set_unable_to_import');
1723
+	if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) {
1724
+			fatal_lang_error('smiley_set_unable_to_import');
1725
+	}
1652 1726
 
1653 1727
 	$smileys = array();
1654 1728
 	$dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath);
1655 1729
 	while ($entry = $dir->read())
1656 1730
 	{
1657
-		if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
1658
-			$smileys[strtolower($entry)] = $entry;
1731
+		if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
1732
+					$smileys[strtolower($entry)] = $entry;
1733
+		}
1659 1734
 	}
1660 1735
 	$dir->close();
1661 1736
 
@@ -1668,9 +1743,10 @@  discard block
 block discarded – undo
1668 1743
 			'smiley_list' => $smileys,
1669 1744
 		)
1670 1745
 	);
1671
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1672
-		if (isset($smileys[strtolower($row['filename'])]))
1746
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1747
+			if (isset($smileys[strtolower($row['filename'])]))
1673 1748
 			unset($smileys[strtolower($row['filename'])]);
1749
+	}
1674 1750
 	$smcFunc['db_free_result']($request);
1675 1751
 
1676 1752
 	$request = $smcFunc['db_query']('', '
@@ -1687,9 +1763,10 @@  discard block
 block discarded – undo
1687 1763
 	$smcFunc['db_free_result']($request);
1688 1764
 
1689 1765
 	$new_smileys = array();
1690
-	foreach ($smileys as $smiley)
1691
-		if (strlen($smiley) <= 48)
1766
+	foreach ($smileys as $smiley) {
1767
+			if (strlen($smiley) <= 48)
1692 1768
 			$new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order);
1769
+	}
1693 1770
 
1694 1771
 	if (!empty($new_smileys))
1695 1772
 	{
@@ -1754,8 +1831,9 @@  discard block
 block discarded – undo
1754 1831
 		if (isset($_POST['delete']) && !empty($_POST['checked_icons']))
1755 1832
 		{
1756 1833
 			$deleteIcons = array();
1757
-			foreach ($_POST['checked_icons'] as $icon)
1758
-				$deleteIcons[] = (int) $icon;
1834
+			foreach ($_POST['checked_icons'] as $icon) {
1835
+							$deleteIcons[] = (int) $icon;
1836
+			}
1759 1837
 
1760 1838
 			// Do the actual delete!
1761 1839
 			$smcFunc['db_query']('', '
@@ -1772,35 +1850,41 @@  discard block
 block discarded – undo
1772 1850
 			$_GET['icon'] = (int) $_GET['icon'];
1773 1851
 
1774 1852
 			// Do some preperation with the data... like check the icon exists *somewhere*
1775
-			if (strpos($_POST['icon_filename'], '.png') !== false)
1776
-				$_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
1777
-			if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png'))
1778
-				fatal_lang_error('icon_not_found');
1853
+			if (strpos($_POST['icon_filename'], '.png') !== false) {
1854
+							$_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
1855
+			}
1856
+			if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) {
1857
+							fatal_lang_error('icon_not_found');
1858
+			}
1779 1859
 			// There is a 16 character limit on message icons...
1780
-			elseif (strlen($_POST['icon_filename']) > 16)
1781
-				fatal_lang_error('icon_name_too_long');
1782
-			elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon']))
1783
-				fatal_lang_error('icon_after_itself');
1860
+			elseif (strlen($_POST['icon_filename']) > 16) {
1861
+							fatal_lang_error('icon_name_too_long');
1862
+			} elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) {
1863
+							fatal_lang_error('icon_after_itself');
1864
+			}
1784 1865
 
1785 1866
 			// First do the sorting... if this is an edit reduce the order of everything after it by one ;)
1786 1867
 			if ($_GET['icon'] != 0)
1787 1868
 			{
1788 1869
 				$oldOrder = $context['icons'][$_GET['icon']]['true_order'];
1789
-				foreach ($context['icons'] as $id => $data)
1790
-					if ($data['true_order'] > $oldOrder)
1870
+				foreach ($context['icons'] as $id => $data) {
1871
+									if ($data['true_order'] > $oldOrder)
1791 1872
 						$context['icons'][$id]['true_order']--;
1873
+				}
1792 1874
 			}
1793 1875
 
1794 1876
 			// If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql)
1795
-			if (empty($_GET['icon']) && empty($context['icons']))
1796
-				$_GET['icon'] = 1;
1877
+			if (empty($_GET['icon']) && empty($context['icons'])) {
1878
+							$_GET['icon'] = 1;
1879
+			}
1797 1880
 
1798 1881
 			// Get the new order.
1799 1882
 			$newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1;
1800 1883
 			// Do the same, but with the one that used to be after this icon, done to avoid conflict.
1801
-			foreach ($context['icons'] as $id => $data)
1802
-				if ($data['true_order'] >= $newOrder)
1884
+			foreach ($context['icons'] as $id => $data) {
1885
+							if ($data['true_order'] >= $newOrder)
1803 1886
 					$context['icons'][$id]['true_order']++;
1887
+			}
1804 1888
 
1805 1889
 			// Finally set the current icon's position!
1806 1890
 			$context['icons'][$_GET['icon']]['true_order'] = $newOrder;
@@ -1818,8 +1902,7 @@  discard block
 block discarded – undo
1818 1902
 				if ($id != 0)
1819 1903
 				{
1820 1904
 					$iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
1821
-				}
1822
-				else
1905
+				} else
1823 1906
 				{
1824 1907
 					$iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
1825 1908
 				}
@@ -1844,8 +1927,9 @@  discard block
 block discarded – undo
1844 1927
 		}
1845 1928
 
1846 1929
 		// Unless we're adding a new thing, we'll escape
1847
-		if (!isset($_POST['add']))
1848
-			redirectexit('action=admin;area=smileys;sa=editicons');
1930
+		if (!isset($_POST['add'])) {
1931
+					redirectexit('action=admin;area=smileys;sa=editicons');
1932
+		}
1849 1933
 	}
1850 1934
 
1851 1935
 	$context[$context['admin_menu_name']]['current_subsection'] = 'editicons';
@@ -1955,8 +2039,9 @@  discard block
 block discarded – undo
1955 2039
 		$context['new_icon'] = !isset($_GET['icon']);
1956 2040
 
1957 2041
 		// Get the properties of the current icon from the icon list.
1958
-		if (!$context['new_icon'])
1959
-			$context['icon'] = $context['icons'][$_GET['icon']];
2042
+		if (!$context['new_icon']) {
2043
+					$context['icon'] = $context['icons'][$_GET['icon']];
2044
+		}
1960 2045
 
1961 2046
 		// Get a list of boards needed for assigning this icon to a specific board.
1962 2047
 		$boardListOptions = array(
@@ -1990,8 +2075,9 @@  discard block
 block discarded – undo
1990 2075
 	);
1991 2076
 
1992 2077
 	$message_icons = array();
1993
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1994
-		$message_icons[] = $row;
2078
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2079
+			$message_icons[] = $row;
2080
+	}
1995 2081
 	$smcFunc['db_free_result']($request);
1996 2082
 
1997 2083
 	return $message_icons;
Please login to merge, or discard this patch.
Sources/PackageGet.php 1 patch
Braces   +197 added lines, -154 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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
  * Browse the list of package servers, add servers...
@@ -43,13 +44,15 @@  discard block
 block discarded – undo
43 44
 	);
44 45
 
45 46
 	// Now let's decide where we are taking this...
46
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
47
-		$context['sub_action'] = $_REQUEST['sa'];
47
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
48
+			$context['sub_action'] = $_REQUEST['sa'];
49
+	}
48 50
 	// We need to support possible old javascript links...
49
-	elseif (isset($_GET['pgdownload']))
50
-		$context['sub_action'] = 'download';
51
-	else
52
-		$context['sub_action'] = 'servers';
51
+	elseif (isset($_GET['pgdownload'])) {
52
+			$context['sub_action'] = 'download';
53
+	} else {
54
+			$context['sub_action'] = 'servers';
55
+	}
53 56
 
54 57
 	// We need to force the "Download" tab as selected.
55 58
 	$context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'packageget';
@@ -141,17 +144,19 @@  discard block
 block discarded – undo
141 144
 			{
142 145
 				require_once($sourcedir . '/Class-Package.php');
143 146
 				$ftp = new ftp_connection(null);
147
+			} elseif ($ftp->error !== false && !isset($ftp_error)) {
148
+							$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
144 149
 			}
145
-			elseif ($ftp->error !== false && !isset($ftp_error))
146
-				$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
147 150
 
148 151
 			list ($username, $detect_path, $found_path) = $ftp->detect_path($packagesdir);
149 152
 
150
-			if ($found_path || !isset($_POST['ftp_path']))
151
-				$_POST['ftp_path'] = $detect_path;
153
+			if ($found_path || !isset($_POST['ftp_path'])) {
154
+							$_POST['ftp_path'] = $detect_path;
155
+			}
152 156
 
153
-			if (!isset($_POST['ftp_username']))
154
-				$_POST['ftp_username'] = $username;
157
+			if (!isset($_POST['ftp_username'])) {
158
+							$_POST['ftp_username'] = $username;
159
+			}
155 160
 
156 161
 			$context['package_ftp'] = array(
157 162
 				'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'),
@@ -160,8 +165,7 @@  discard block
 block discarded – undo
160 165
 				'path' => $_POST['ftp_path'],
161 166
 				'error' => empty($ftp_error) ? null : $ftp_error,
162 167
 			);
163
-		}
164
-		else
168
+		} else
165 169
 		{
166 170
 			$context['package_download_broken'] = false;
167 171
 
@@ -203,8 +207,9 @@  discard block
 block discarded – undo
203 207
 
204 208
 	if (isset($_GET['server']))
205 209
 	{
206
-		if ($_GET['server'] == '')
207
-			redirectexit('action=admin;area=packages;get');
210
+		if ($_GET['server'] == '') {
211
+					redirectexit('action=admin;area=packages;get');
212
+		}
208 213
 
209 214
 		$server = (int) $_GET['server'];
210 215
 
@@ -222,17 +227,18 @@  discard block
 block discarded – undo
222 227
 		$smcFunc['db_free_result']($request);
223 228
 
224 229
 		// If the server does not exist, dump out.
225
-		if (empty($url))
226
-			fatal_lang_error('couldnt_connect', false);
230
+		if (empty($url)) {
231
+					fatal_lang_error('couldnt_connect', false);
232
+		}
227 233
 
228 234
 		// If there is a relative link, append to the stored server url.
229
-		if (isset($_GET['relative']))
230
-			$url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative'];
235
+		if (isset($_GET['relative'])) {
236
+					$url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative'];
237
+		}
231 238
 
232 239
 		// Clear any "absolute" URL.  Since "server" is present, "absolute" is garbage.
233 240
 		unset($_GET['absolute']);
234
-	}
235
-	elseif (isset($_GET['absolute']) && $_GET['absolute'] != '')
241
+	} elseif (isset($_GET['absolute']) && $_GET['absolute'] != '')
236 242
 	{
237 243
 		// Initialize the requried variables.
238 244
 		$server = '';
@@ -256,16 +262,19 @@  discard block
 block discarded – undo
256 262
 		}
257 263
 	}
258 264
 	// Minimum required parameter did not exist so dump out.
259
-	else
260
-		fatal_lang_error('couldnt_connect', false);
265
+	else {
266
+			fatal_lang_error('couldnt_connect', false);
267
+	}
261 268
 
262 269
 	// Attempt to connect.  If unsuccessful... try the URL.
263
-	if (!isset($_GET['package']) || file_exists($_GET['package']))
264
-		$_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language'];
270
+	if (!isset($_GET['package']) || file_exists($_GET['package'])) {
271
+			$_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language'];
272
+	}
265 273
 
266 274
 	// Check to be sure the packages.xml file actually exists where it is should be... or dump out.
267
-	if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package']))
268
-		fatal_lang_error('packageget_unable', false, array($url . '/index.php'));
275
+	if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package'])) {
276
+			fatal_lang_error('packageget_unable', false, array($url . '/index.php'));
277
+	}
269 278
 
270 279
 	// Might take some time.
271 280
 	@set_time_limit(600);
@@ -275,8 +284,9 @@  discard block
 block discarded – undo
275 284
 	$listing = new xmlArray(fetch_web_data($_GET['package']), true);
276 285
 
277 286
 	// Errm.... empty file?  Try the URL....
278
-	if (!$listing->exists('package-list'))
279
-		fatal_lang_error('packageget_unable', false, array($url . '/index.php'));
287
+	if (!$listing->exists('package-list')) {
288
+			fatal_lang_error('packageget_unable', false, array($url . '/index.php'));
289
+	}
280 290
 
281 291
 	// List out the packages...
282 292
 	$context['package_list'] = array();
@@ -284,8 +294,9 @@  discard block
 block discarded – undo
284 294
 	$listing = $listing->path('package-list[0]');
285 295
 
286 296
 	// Use the package list's name if it exists.
287
-	if ($listing->exists('list-title'))
288
-		$name = $smcFunc['htmlspecialchars']($listing->fetch('list-title'));
297
+	if ($listing->exists('list-title')) {
298
+			$name = $smcFunc['htmlspecialchars']($listing->fetch('list-title'));
299
+	}
289 300
 
290 301
 	// Pick the correct template.
291 302
 	$context['sub_template'] = 'package_list';
@@ -300,28 +311,32 @@  discard block
 block discarded – undo
300 311
 
301 312
 	$installed_mods = array();
302 313
 	// Look through the list of installed mods...
303
-	foreach ($instmods as $installed_mod)
304
-		$installed_mods[$installed_mod['package_id']] = $installed_mod['version'];
314
+	foreach ($instmods as $installed_mod) {
315
+			$installed_mods[$installed_mod['package_id']] = $installed_mod['version'];
316
+	}
305 317
 
306 318
 	// Get default author and email if they exist.
307 319
 	if ($listing->exists('default-author'))
308 320
 	{
309 321
 		$default_author = $smcFunc['htmlspecialchars']($listing->fetch('default-author'));
310
-		if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL))
311
-			$default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email'));
322
+		if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL)) {
323
+					$default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email'));
324
+		}
312 325
 	}
313 326
 
314 327
 	// Get default web site if it exists.
315 328
 	if ($listing->exists('default-website'))
316 329
 	{
317 330
 		$default_website = $smcFunc['htmlspecialchars']($listing->fetch('default-website'));
318
-		if ($listing->exists('default-website/@title'))
319
-			$default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title'));
331
+		if ($listing->exists('default-website/@title')) {
332
+					$default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title'));
333
+		}
320 334
 	}
321 335
 
322 336
 	$the_version = strtr($forum_version, array('SMF ' => ''));
323
-	if (!empty($_SESSION['version_emulate']))
324
-		$the_version = $_SESSION['version_emulate'];
337
+	if (!empty($_SESSION['version_emulate'])) {
338
+			$the_version = $_SESSION['version_emulate'];
339
+	}
325 340
 
326 341
 	$packageNum = 0;
327 342
 	$packageSection = 0;
@@ -342,11 +357,13 @@  discard block
 block discarded – undo
342 357
 				'type' => $thisPackage->name(),
343 358
 			);
344 359
 
345
-			if (in_array($package['type'], array('title', 'text')))
346
-				$context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
360
+			if (in_array($package['type'], array('title', 'text'))) {
361
+							$context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
362
+			}
347 363
 			// It's a Title, Heading, Rule or Text.
348
-			elseif (in_array($package['type'], array('heading', 'rule')))
349
-				$package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
364
+			elseif (in_array($package['type'], array('heading', 'rule'))) {
365
+							$package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.'));
366
+			}
350 367
 			// It's a Remote link.
351 368
 			elseif ($package['type'] == 'remote')
352 369
 			{
@@ -354,20 +371,21 @@  discard block
 block discarded – undo
354 371
 
355 372
 				if ($remote_type == 'relative' && substr($thisPackage->fetch('@href'), 0, 7) != 'http://' && substr($thisPackage->fetch('@href'), 0, 8) != 'https://')
356 373
 				{
357
-					if (isset($_GET['absolute']))
358
-						$current_url = $_GET['absolute'] . '/';
359
-					elseif (isset($_GET['relative']))
360
-						$current_url = $_GET['relative'] . '/';
361
-					else
362
-						$current_url = '';
374
+					if (isset($_GET['absolute'])) {
375
+											$current_url = $_GET['absolute'] . '/';
376
+					} elseif (isset($_GET['relative'])) {
377
+											$current_url = $_GET['relative'] . '/';
378
+					} else {
379
+											$current_url = '';
380
+					}
363 381
 
364 382
 					$current_url .= $thisPackage->fetch('@href');
365
-					if (isset($_GET['absolute']))
366
-						$package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url;
367
-					else
368
-						$package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url;
369
-				}
370
-				else
383
+					if (isset($_GET['absolute'])) {
384
+											$package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url;
385
+					} else {
386
+											$package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url;
387
+					}
388
+				} else
371 389
 				{
372 390
 					$current_url = $thisPackage->fetch('@href');
373 391
 					$package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url;
@@ -379,25 +397,28 @@  discard block
 block discarded – undo
379 397
 			// It's a package...
380 398
 			else
381 399
 			{
382
-				if (isset($_GET['absolute']))
383
-					$current_url = $_GET['absolute'] . '/';
384
-				elseif (isset($_GET['relative']))
385
-					$current_url = $_GET['relative'] . '/';
386
-				else
387
-					$current_url = '';
400
+				if (isset($_GET['absolute'])) {
401
+									$current_url = $_GET['absolute'] . '/';
402
+				} elseif (isset($_GET['relative'])) {
403
+									$current_url = $_GET['relative'] . '/';
404
+				} else {
405
+									$current_url = '';
406
+				}
388 407
 
389 408
 				$server_att = $server != '' ? ';server=' . $server : '';
390 409
 
391 410
 				$package += $thisPackage->to_array();
392 411
 
393
-				if (isset($package['website']))
394
-					unset($package['website']);
412
+				if (isset($package['website'])) {
413
+									unset($package['website']);
414
+				}
395 415
 				$package['author'] = array();
396 416
 
397
-				if ($package['description'] == '')
398
-					$package['description'] = $txt['package_no_description'];
399
-				else
400
-					$package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description'])));
417
+				if ($package['description'] == '') {
418
+									$package['description'] = $txt['package_no_description'];
419
+				} else {
420
+									$package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description'])));
421
+				}
401 422
 
402 423
 				$package['is_installed'] = isset($installed_mods[$package['id']]);
403 424
 				$package['is_current'] = $package['is_installed'] && ($installed_mods[$package['id']] == $package['version']);
@@ -406,12 +427,14 @@  discard block
 block discarded – undo
406 427
 				// This package is either not installed, or installed but old.  Is it supported on this version of SMF?
407 428
 				if (!$package['is_installed'] || (!$package['is_current'] && !$package['is_newer']))
408 429
 				{
409
-					if ($thisPackage->exists('version/@for'))
410
-						$package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for'));
430
+					if ($thisPackage->exists('version/@for')) {
431
+											$package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for'));
432
+					}
411 433
 				}
412 434
 				// Okay, it's already installed AND up to date.
413
-				else
414
-					$package['can_install'] = false;
435
+				else {
436
+									$package['can_install'] = false;
437
+				}
415 438
 
416 439
 				$already_exists = getPackageInfo(basename($package['filename']));
417 440
 				$package['download_conflict'] = is_array($already_exists) && $already_exists['id'] == $package['id'] && $already_exists['version'] != $package['version'];
@@ -423,40 +446,44 @@  discard block
 block discarded – undo
423 446
 
424 447
 				if ($thisPackage->exists('author') || isset($default_author))
425 448
 				{
426
-					if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL))
427
-						$package['author']['email'] = $thisPackage->fetch('author/@email');
428
-					elseif (isset($default_email))
429
-						$package['author']['email'] = $default_email;
430
-
431
-					if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '')
432
-						$package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author'));
433
-					else
434
-						$package['author']['name'] = $default_author;
435
-
436
-					if (!empty($package['author']['email']))
437
-						$package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>';
449
+					if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL)) {
450
+											$package['author']['email'] = $thisPackage->fetch('author/@email');
451
+					} elseif (isset($default_email)) {
452
+											$package['author']['email'] = $default_email;
453
+					}
454
+
455
+					if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '') {
456
+											$package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author'));
457
+					} else {
458
+											$package['author']['name'] = $default_author;
459
+					}
460
+
461
+					if (!empty($package['author']['email'])) {
462
+											$package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>';
463
+					}
438 464
 				}
439 465
 
440 466
 				if ($thisPackage->exists('website') || isset($default_website))
441 467
 				{
442
-					if ($thisPackage->exists('website') && $thisPackage->exists('website/@title'))
443
-						$package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title'));
444
-					elseif (isset($default_title))
445
-						$package['author']['website']['name'] = $default_title;
446
-					elseif ($thisPackage->exists('website'))
447
-						$package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website'));
448
-					else
449
-						$package['author']['website']['name'] = $default_website;
450
-
451
-					if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '')
452
-						$authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website'));
453
-					else
454
-						$authorhompage = $default_website;
468
+					if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) {
469
+											$package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title'));
470
+					} elseif (isset($default_title)) {
471
+											$package['author']['website']['name'] = $default_title;
472
+					} elseif ($thisPackage->exists('website')) {
473
+											$package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website'));
474
+					} else {
475
+											$package['author']['website']['name'] = $default_website;
476
+					}
477
+
478
+					if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') {
479
+											$authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website'));
480
+					} else {
481
+											$authorhompage = $default_website;
482
+					}
455 483
 
456 484
 					$package['author']['website']['href'] = $authorhompage;
457 485
 					$package['author']['website']['link'] = '<a href="' . $authorhompage . '">' . $package['author']['website']['name'] . '</a>';
458
-				}
459
-				else
486
+				} else
460 487
 				{
461 488
 					$package['author']['website']['href'] = '';
462 489
 					$package['author']['website']['link'] = '';
@@ -472,11 +499,13 @@  discard block
 block discarded – undo
472 499
 			$packageNum = in_array($package['type'], array('title', 'heading', 'text', 'remote', 'rule')) ? 0 : $packageNum + 1;
473 500
 			$package['count'] = $packageNum;
474 501
 
475
-			if (!in_array($package['type'], array('title', 'text')))
476
-				$context['package_list'][$packageSection]['items'][] = $package;
502
+			if (!in_array($package['type'], array('title', 'text'))) {
503
+							$context['package_list'][$packageSection]['items'][] = $package;
504
+			}
477 505
 
478
-			if ($package['count'] > 1)
479
-				$context['list_type'] = 'ol';
506
+			if ($package['count'] > 1) {
507
+							$context['list_type'] = 'ol';
508
+			}
480 509
 		}
481 510
 
482 511
 		$packageSection++;
@@ -489,8 +518,9 @@  discard block
 block discarded – undo
489 518
 	{
490 519
 		foreach ($packageSection['items'] as $i => $package)
491 520
 		{
492
-			if ($package['count'] == 0 || isset($package['can_install']))
493
-				continue;
521
+			if ($package['count'] == 0 || isset($package['can_install'])) {
522
+							continue;
523
+			}
494 524
 
495 525
 			$context['package_list'][$ps_id]['items'][$i]['can_install'] = false;
496 526
 
@@ -539,8 +569,9 @@  discard block
 block discarded – undo
539 569
 	checkSession('get');
540 570
 
541 571
 	// To download something, we need a valid server or url.
542
-	if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package'])))
543
-		fatal_lang_error('package_get_error_is_zero', false);
572
+	if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package']))) {
573
+			fatal_lang_error('package_get_error_is_zero', false);
574
+	}
544 575
 
545 576
 	if (isset($_GET['server']))
546 577
 	{
@@ -560,22 +591,23 @@  discard block
 block discarded – undo
560 591
 		$smcFunc['db_free_result']($request);
561 592
 
562 593
 		// If server does not exist then dump out.
563
-		if (empty($url))
564
-			fatal_lang_error('couldnt_connect', false);
594
+		if (empty($url)) {
595
+					fatal_lang_error('couldnt_connect', false);
596
+		}
565 597
 
566 598
 		$url = $url . '/';
567
-	}
568
-	else
599
+	} else
569 600
 	{
570 601
 		// Initialize the requried variables.
571 602
 		$server = '';
572 603
 		$url = '';
573 604
 	}
574 605
 
575
-	if (isset($_REQUEST['byurl']) && !empty($_POST['filename']))
576
-		$package_name = basename($_REQUEST['filename']);
577
-	else
578
-		$package_name = basename($_REQUEST['package']);
606
+	if (isset($_REQUEST['byurl']) && !empty($_POST['filename'])) {
607
+			$package_name = basename($_REQUEST['filename']);
608
+	} else {
609
+			$package_name = basename($_REQUEST['package']);
610
+	}
579 611
 
580 612
 	if (isset($_REQUEST['conflict']) || (isset($_REQUEST['auto']) && file_exists($packagesdir . '/' . $package_name)))
581 613
 	{
@@ -584,14 +616,15 @@  discard block
 block discarded – undo
584 616
 		{
585 617
 			$ext = substr($package_name, strrpos(substr($package_name, 0, -3), '.'));
586 618
 			$package_name = substr($package_name, 0, strrpos(substr($package_name, 0, -3), '.')) . '_';
619
+		} else {
620
+					$ext = '';
587 621
 		}
588
-		else
589
-			$ext = '';
590 622
 
591 623
 		// Find the first available.
592 624
 		$i = 1;
593
-		while (file_exists($packagesdir . '/' . $package_name . $i . $ext))
594
-			$i++;
625
+		while (file_exists($packagesdir . '/' . $package_name . $i . $ext)) {
626
+					$i++;
627
+		}
595 628
 
596 629
 		$package_name = $package_name . $i . $ext;
597 630
 	}
@@ -602,25 +635,28 @@  discard block
 block discarded – undo
602 635
 
603 636
 	// Done!  Did we get this package automatically?
604 637
 	// @ TODO: These are usually update packages.  Allowing both for now until more testing has been done.
605
-	if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto']))
606
-		redirectexit('action=admin;area=packages;sa=install;package=' . $package_name);
638
+	if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) {
639
+			redirectexit('action=admin;area=packages;sa=install;package=' . $package_name);
640
+	}
607 641
 
608 642
 	// You just downloaded a mod from SERVER_NAME_GOES_HERE.
609 643
 	$context['package_server'] = $server;
610 644
 
611 645
 	$context['package'] = getPackageInfo($package_name);
612 646
 
613
-	if (!is_array($context['package']))
614
-		fatal_lang_error('package_cant_download', false);
647
+	if (!is_array($context['package'])) {
648
+			fatal_lang_error('package_cant_download', false);
649
+	}
615 650
 
616
-	if ($context['package']['type'] == 'modification')
617
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>';
618
-	elseif ($context['package']['type'] == 'avatar')
619
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>';
620
-	elseif ($context['package']['type'] == 'language')
621
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>';
622
-	else
623
-		$context['package']['install']['link'] = '';
651
+	if ($context['package']['type'] == 'modification') {
652
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>';
653
+	} elseif ($context['package']['type'] == 'avatar') {
654
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>';
655
+	} elseif ($context['package']['type'] == 'language') {
656
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>';
657
+	} else {
658
+			$context['package']['install']['link'] = '';
659
+	}
624 660
 
625 661
 	// Does a 3rd party hook want to do some additional changes?
626 662
 	call_integration_hook('integrate_package_download');
@@ -646,10 +682,11 @@  discard block
 block discarded – undo
646 682
 	// @todo Use FTP if the Packages directory is not writable.
647 683
 
648 684
 	// Check the file was even sent!
649
-	if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '')
650
-		fatal_lang_error('package_upload_error_nofile');
651
-	elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name'])))
652
-		fatal_lang_error('package_upload_error_failed');
685
+	if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') {
686
+			fatal_lang_error('package_upload_error_nofile');
687
+	} elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) {
688
+			fatal_lang_error('package_upload_error_failed');
689
+	}
653 690
 
654 691
 	// Make sure it has a sane filename.
655 692
 	$_FILES['package']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['package']['name']);
@@ -666,8 +703,9 @@  discard block
 block discarded – undo
666 703
 	// Setup the destination and throw an error if the file is already there!
667 704
 	$destination = $packagesdir . '/' . $packageName;
668 705
 	// @todo Maybe just roll it like we do for downloads?
669
-	if (file_exists($destination))
670
-		fatal_lang_error('package_upload_error_exists');
706
+	if (file_exists($destination)) {
707
+			fatal_lang_error('package_upload_error_exists');
708
+	}
671 709
 
672 710
 	// Now move the file.
673 711
 	move_uploaded_file($_FILES['package']['tmp_name'], $destination);
@@ -690,12 +728,14 @@  discard block
 block discarded – undo
690 728
 	{
691 729
 		while ($package = readdir($dir))
692 730
 		{
693
-			if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip'))
694
-				continue;
731
+			if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) {
732
+							continue;
733
+			}
695 734
 
696 735
 			$packageInfo = getPackageInfo($package);
697
-			if (!is_array($packageInfo))
698
-				continue;
736
+			if (!is_array($packageInfo)) {
737
+							continue;
738
+			}
699 739
 
700 740
 			if ($packageInfo['id'] == $context['package']['id'] && $packageInfo['version'] == $context['package']['version'])
701 741
 			{
@@ -707,14 +747,15 @@  discard block
 block discarded – undo
707 747
 		closedir($dir);
708 748
 	}
709 749
 
710
-	if ($context['package']['type'] == 'modification')
711
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>';
712
-	elseif ($context['package']['type'] == 'avatar')
713
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>';
714
-	elseif ($context['package']['type'] == 'language')
715
-		$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>';
716
-	else
717
-		$context['package']['install']['link'] = '';
750
+	if ($context['package']['type'] == 'modification') {
751
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>';
752
+	} elseif ($context['package']['type'] == 'avatar') {
753
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>';
754
+	} elseif ($context['package']['type'] == 'language') {
755
+			$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>';
756
+	} else {
757
+			$context['package']['install']['link'] = '';
758
+	}
718 759
 
719 760
 	// Does a 3rd party hook want to do some additional changes?
720 761
 	call_integration_hook('integrate_package_upload');
@@ -737,16 +778,18 @@  discard block
 block discarded – undo
737 778
 	checkSession();
738 779
 
739 780
 	// If they put a slash on the end, get rid of it.
740
-	if (substr($_POST['serverurl'], -1) == '/')
741
-		$_POST['serverurl'] = substr($_POST['serverurl'], 0, -1);
781
+	if (substr($_POST['serverurl'], -1) == '/') {
782
+			$_POST['serverurl'] = substr($_POST['serverurl'], 0, -1);
783
+	}
742 784
 
743 785
 	// Are they both nice and clean?
744 786
 	$servername = trim($smcFunc['htmlspecialchars']($_POST['servername']));
745 787
 	$serverurl = trim($smcFunc['htmlspecialchars']($_POST['serverurl']));
746 788
 
747 789
 	// Make sure the URL has the correct prefix.
748
-	if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0)
749
-		$serverurl = 'http://' . $serverurl;
790
+	if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) {
791
+			$serverurl = 'http://' . $serverurl;
792
+	}
750 793
 
751 794
 	$smcFunc['db_insert']('',
752 795
 		'{db_prefix}package_servers',
Please login to merge, or discard this patch.
Sources/minify/src/JS.php 1 patch
Indentation   +415 added lines, -415 removed lines patch added patch discarded remove patch
@@ -14,134 +14,134 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class JS extends Minify
16 16
 {
17
-    /**
18
-     * Var-matching regex based on https://stackoverflow.com/a/9337047/802993.
19
-     *
20
-     * Note that regular expressions using that bit must have the PCRE_UTF8
21
-     * pattern modifier (/u) set.
22
-     *
23
-     * @var string
24
-     */
25
-    const REGEX_VARIABLE = '\b[$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\x{02c1}\x{02c6}-\x{02d1}\x{02e0}-\x{02e4}\x{02ec}\x{02ee}\x{0370}-\x{0374}\x{0376}\x{0377}\x{037a}-\x{037d}\x{0386}\x{0388}-\x{038a}\x{038c}\x{038e}-\x{03a1}\x{03a3}-\x{03f5}\x{03f7}-\x{0481}\x{048a}-\x{0527}\x{0531}-\x{0556}\x{0559}\x{0561}-\x{0587}\x{05d0}-\x{05ea}\x{05f0}-\x{05f2}\x{0620}-\x{064a}\x{066e}\x{066f}\x{0671}-\x{06d3}\x{06d5}\x{06e5}\x{06e6}\x{06ee}\x{06ef}\x{06fa}-\x{06fc}\x{06ff}\x{0710}\x{0712}-\x{072f}\x{074d}-\x{07a5}\x{07b1}\x{07ca}-\x{07ea}\x{07f4}\x{07f5}\x{07fa}\x{0800}-\x{0815}\x{081a}\x{0824}\x{0828}\x{0840}-\x{0858}\x{08a0}\x{08a2}-\x{08ac}\x{0904}-\x{0939}\x{093d}\x{0950}\x{0958}-\x{0961}\x{0971}-\x{0977}\x{0979}-\x{097f}\x{0985}-\x{098c}\x{098f}\x{0990}\x{0993}-\x{09a8}\x{09aa}-\x{09b0}\x{09b2}\x{09b6}-\x{09b9}\x{09bd}\x{09ce}\x{09dc}\x{09dd}\x{09df}-\x{09e1}\x{09f0}\x{09f1}\x{0a05}-\x{0a0a}\x{0a0f}\x{0a10}\x{0a13}-\x{0a28}\x{0a2a}-\x{0a30}\x{0a32}\x{0a33}\x{0a35}\x{0a36}\x{0a38}\x{0a39}\x{0a59}-\x{0a5c}\x{0a5e}\x{0a72}-\x{0a74}\x{0a85}-\x{0a8d}\x{0a8f}-\x{0a91}\x{0a93}-\x{0aa8}\x{0aaa}-\x{0ab0}\x{0ab2}\x{0ab3}\x{0ab5}-\x{0ab9}\x{0abd}\x{0ad0}\x{0ae0}\x{0ae1}\x{0b05}-\x{0b0c}\x{0b0f}\x{0b10}\x{0b13}-\x{0b28}\x{0b2a}-\x{0b30}\x{0b32}\x{0b33}\x{0b35}-\x{0b39}\x{0b3d}\x{0b5c}\x{0b5d}\x{0b5f}-\x{0b61}\x{0b71}\x{0b83}\x{0b85}-\x{0b8a}\x{0b8e}-\x{0b90}\x{0b92}-\x{0b95}\x{0b99}\x{0b9a}\x{0b9c}\x{0b9e}\x{0b9f}\x{0ba3}\x{0ba4}\x{0ba8}-\x{0baa}\x{0bae}-\x{0bb9}\x{0bd0}\x{0c05}-\x{0c0c}\x{0c0e}-\x{0c10}\x{0c12}-\x{0c28}\x{0c2a}-\x{0c33}\x{0c35}-\x{0c39}\x{0c3d}\x{0c58}\x{0c59}\x{0c60}\x{0c61}\x{0c85}-\x{0c8c}\x{0c8e}-\x{0c90}\x{0c92}-\x{0ca8}\x{0caa}-\x{0cb3}\x{0cb5}-\x{0cb9}\x{0cbd}\x{0cde}\x{0ce0}\x{0ce1}\x{0cf1}\x{0cf2}\x{0d05}-\x{0d0c}\x{0d0e}-\x{0d10}\x{0d12}-\x{0d3a}\x{0d3d}\x{0d4e}\x{0d60}\x{0d61}\x{0d7a}-\x{0d7f}\x{0d85}-\x{0d96}\x{0d9a}-\x{0db1}\x{0db3}-\x{0dbb}\x{0dbd}\x{0dc0}-\x{0dc6}\x{0e01}-\x{0e30}\x{0e32}\x{0e33}\x{0e40}-\x{0e46}\x{0e81}\x{0e82}\x{0e84}\x{0e87}\x{0e88}\x{0e8a}\x{0e8d}\x{0e94}-\x{0e97}\x{0e99}-\x{0e9f}\x{0ea1}-\x{0ea3}\x{0ea5}\x{0ea7}\x{0eaa}\x{0eab}\x{0ead}-\x{0eb0}\x{0eb2}\x{0eb3}\x{0ebd}\x{0ec0}-\x{0ec4}\x{0ec6}\x{0edc}-\x{0edf}\x{0f00}\x{0f40}-\x{0f47}\x{0f49}-\x{0f6c}\x{0f88}-\x{0f8c}\x{1000}-\x{102a}\x{103f}\x{1050}-\x{1055}\x{105a}-\x{105d}\x{1061}\x{1065}\x{1066}\x{106e}-\x{1070}\x{1075}-\x{1081}\x{108e}\x{10a0}-\x{10c5}\x{10c7}\x{10cd}\x{10d0}-\x{10fa}\x{10fc}-\x{1248}\x{124a}-\x{124d}\x{1250}-\x{1256}\x{1258}\x{125a}-\x{125d}\x{1260}-\x{1288}\x{128a}-\x{128d}\x{1290}-\x{12b0}\x{12b2}-\x{12b5}\x{12b8}-\x{12be}\x{12c0}\x{12c2}-\x{12c5}\x{12c8}-\x{12d6}\x{12d8}-\x{1310}\x{1312}-\x{1315}\x{1318}-\x{135a}\x{1380}-\x{138f}\x{13a0}-\x{13f4}\x{1401}-\x{166c}\x{166f}-\x{167f}\x{1681}-\x{169a}\x{16a0}-\x{16ea}\x{16ee}-\x{16f0}\x{1700}-\x{170c}\x{170e}-\x{1711}\x{1720}-\x{1731}\x{1740}-\x{1751}\x{1760}-\x{176c}\x{176e}-\x{1770}\x{1780}-\x{17b3}\x{17d7}\x{17dc}\x{1820}-\x{1877}\x{1880}-\x{18a8}\x{18aa}\x{18b0}-\x{18f5}\x{1900}-\x{191c}\x{1950}-\x{196d}\x{1970}-\x{1974}\x{1980}-\x{19ab}\x{19c1}-\x{19c7}\x{1a00}-\x{1a16}\x{1a20}-\x{1a54}\x{1aa7}\x{1b05}-\x{1b33}\x{1b45}-\x{1b4b}\x{1b83}-\x{1ba0}\x{1bae}\x{1baf}\x{1bba}-\x{1be5}\x{1c00}-\x{1c23}\x{1c4d}-\x{1c4f}\x{1c5a}-\x{1c7d}\x{1ce9}-\x{1cec}\x{1cee}-\x{1cf1}\x{1cf5}\x{1cf6}\x{1d00}-\x{1dbf}\x{1e00}-\x{1f15}\x{1f18}-\x{1f1d}\x{1f20}-\x{1f45}\x{1f48}-\x{1f4d}\x{1f50}-\x{1f57}\x{1f59}\x{1f5b}\x{1f5d}\x{1f5f}-\x{1f7d}\x{1f80}-\x{1fb4}\x{1fb6}-\x{1fbc}\x{1fbe}\x{1fc2}-\x{1fc4}\x{1fc6}-\x{1fcc}\x{1fd0}-\x{1fd3}\x{1fd6}-\x{1fdb}\x{1fe0}-\x{1fec}\x{1ff2}-\x{1ff4}\x{1ff6}-\x{1ffc}\x{2071}\x{207f}\x{2090}-\x{209c}\x{2102}\x{2107}\x{210a}-\x{2113}\x{2115}\x{2119}-\x{211d}\x{2124}\x{2126}\x{2128}\x{212a}-\x{212d}\x{212f}-\x{2139}\x{213c}-\x{213f}\x{2145}-\x{2149}\x{214e}\x{2160}-\x{2188}\x{2c00}-\x{2c2e}\x{2c30}-\x{2c5e}\x{2c60}-\x{2ce4}\x{2ceb}-\x{2cee}\x{2cf2}\x{2cf3}\x{2d00}-\x{2d25}\x{2d27}\x{2d2d}\x{2d30}-\x{2d67}\x{2d6f}\x{2d80}-\x{2d96}\x{2da0}-\x{2da6}\x{2da8}-\x{2dae}\x{2db0}-\x{2db6}\x{2db8}-\x{2dbe}\x{2dc0}-\x{2dc6}\x{2dc8}-\x{2dce}\x{2dd0}-\x{2dd6}\x{2dd8}-\x{2dde}\x{2e2f}\x{3005}-\x{3007}\x{3021}-\x{3029}\x{3031}-\x{3035}\x{3038}-\x{303c}\x{3041}-\x{3096}\x{309d}-\x{309f}\x{30a1}-\x{30fa}\x{30fc}-\x{30ff}\x{3105}-\x{312d}\x{3131}-\x{318e}\x{31a0}-\x{31ba}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}\x{4e00}-\x{9fcc}\x{a000}-\x{a48c}\x{a4d0}-\x{a4fd}\x{a500}-\x{a60c}\x{a610}-\x{a61f}\x{a62a}\x{a62b}\x{a640}-\x{a66e}\x{a67f}-\x{a697}\x{a6a0}-\x{a6ef}\x{a717}-\x{a71f}\x{a722}-\x{a788}\x{a78b}-\x{a78e}\x{a790}-\x{a793}\x{a7a0}-\x{a7aa}\x{a7f8}-\x{a801}\x{a803}-\x{a805}\x{a807}-\x{a80a}\x{a80c}-\x{a822}\x{a840}-\x{a873}\x{a882}-\x{a8b3}\x{a8f2}-\x{a8f7}\x{a8fb}\x{a90a}-\x{a925}\x{a930}-\x{a946}\x{a960}-\x{a97c}\x{a984}-\x{a9b2}\x{a9cf}\x{aa00}-\x{aa28}\x{aa40}-\x{aa42}\x{aa44}-\x{aa4b}\x{aa60}-\x{aa76}\x{aa7a}\x{aa80}-\x{aaaf}\x{aab1}\x{aab5}\x{aab6}\x{aab9}-\x{aabd}\x{aac0}\x{aac2}\x{aadb}-\x{aadd}\x{aae0}-\x{aaea}\x{aaf2}-\x{aaf4}\x{ab01}-\x{ab06}\x{ab09}-\x{ab0e}\x{ab11}-\x{ab16}\x{ab20}-\x{ab26}\x{ab28}-\x{ab2e}\x{abc0}-\x{abe2}\x{ac00}-\x{d7a3}\x{d7b0}-\x{d7c6}\x{d7cb}-\x{d7fb}\x{f900}-\x{fa6d}\x{fa70}-\x{fad9}\x{fb00}-\x{fb06}\x{fb13}-\x{fb17}\x{fb1d}\x{fb1f}-\x{fb28}\x{fb2a}-\x{fb36}\x{fb38}-\x{fb3c}\x{fb3e}\x{fb40}\x{fb41}\x{fb43}\x{fb44}\x{fb46}-\x{fbb1}\x{fbd3}-\x{fd3d}\x{fd50}-\x{fd8f}\x{fd92}-\x{fdc7}\x{fdf0}-\x{fdfb}\x{fe70}-\x{fe74}\x{fe76}-\x{fefc}\x{ff21}-\x{ff3a}\x{ff41}-\x{ff5a}\x{ff66}-\x{ffbe}\x{ffc2}-\x{ffc7}\x{ffca}-\x{ffcf}\x{ffd2}-\x{ffd7}\x{ffda}-\x{ffdc}][$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\x{02c1}\x{02c6}-\x{02d1}\x{02e0}-\x{02e4}\x{02ec}\x{02ee}\x{0370}-\x{0374}\x{0376}\x{0377}\x{037a}-\x{037d}\x{0386}\x{0388}-\x{038a}\x{038c}\x{038e}-\x{03a1}\x{03a3}-\x{03f5}\x{03f7}-\x{0481}\x{048a}-\x{0527}\x{0531}-\x{0556}\x{0559}\x{0561}-\x{0587}\x{05d0}-\x{05ea}\x{05f0}-\x{05f2}\x{0620}-\x{064a}\x{066e}\x{066f}\x{0671}-\x{06d3}\x{06d5}\x{06e5}\x{06e6}\x{06ee}\x{06ef}\x{06fa}-\x{06fc}\x{06ff}\x{0710}\x{0712}-\x{072f}\x{074d}-\x{07a5}\x{07b1}\x{07ca}-\x{07ea}\x{07f4}\x{07f5}\x{07fa}\x{0800}-\x{0815}\x{081a}\x{0824}\x{0828}\x{0840}-\x{0858}\x{08a0}\x{08a2}-\x{08ac}\x{0904}-\x{0939}\x{093d}\x{0950}\x{0958}-\x{0961}\x{0971}-\x{0977}\x{0979}-\x{097f}\x{0985}-\x{098c}\x{098f}\x{0990}\x{0993}-\x{09a8}\x{09aa}-\x{09b0}\x{09b2}\x{09b6}-\x{09b9}\x{09bd}\x{09ce}\x{09dc}\x{09dd}\x{09df}-\x{09e1}\x{09f0}\x{09f1}\x{0a05}-\x{0a0a}\x{0a0f}\x{0a10}\x{0a13}-\x{0a28}\x{0a2a}-\x{0a30}\x{0a32}\x{0a33}\x{0a35}\x{0a36}\x{0a38}\x{0a39}\x{0a59}-\x{0a5c}\x{0a5e}\x{0a72}-\x{0a74}\x{0a85}-\x{0a8d}\x{0a8f}-\x{0a91}\x{0a93}-\x{0aa8}\x{0aaa}-\x{0ab0}\x{0ab2}\x{0ab3}\x{0ab5}-\x{0ab9}\x{0abd}\x{0ad0}\x{0ae0}\x{0ae1}\x{0b05}-\x{0b0c}\x{0b0f}\x{0b10}\x{0b13}-\x{0b28}\x{0b2a}-\x{0b30}\x{0b32}\x{0b33}\x{0b35}-\x{0b39}\x{0b3d}\x{0b5c}\x{0b5d}\x{0b5f}-\x{0b61}\x{0b71}\x{0b83}\x{0b85}-\x{0b8a}\x{0b8e}-\x{0b90}\x{0b92}-\x{0b95}\x{0b99}\x{0b9a}\x{0b9c}\x{0b9e}\x{0b9f}\x{0ba3}\x{0ba4}\x{0ba8}-\x{0baa}\x{0bae}-\x{0bb9}\x{0bd0}\x{0c05}-\x{0c0c}\x{0c0e}-\x{0c10}\x{0c12}-\x{0c28}\x{0c2a}-\x{0c33}\x{0c35}-\x{0c39}\x{0c3d}\x{0c58}\x{0c59}\x{0c60}\x{0c61}\x{0c85}-\x{0c8c}\x{0c8e}-\x{0c90}\x{0c92}-\x{0ca8}\x{0caa}-\x{0cb3}\x{0cb5}-\x{0cb9}\x{0cbd}\x{0cde}\x{0ce0}\x{0ce1}\x{0cf1}\x{0cf2}\x{0d05}-\x{0d0c}\x{0d0e}-\x{0d10}\x{0d12}-\x{0d3a}\x{0d3d}\x{0d4e}\x{0d60}\x{0d61}\x{0d7a}-\x{0d7f}\x{0d85}-\x{0d96}\x{0d9a}-\x{0db1}\x{0db3}-\x{0dbb}\x{0dbd}\x{0dc0}-\x{0dc6}\x{0e01}-\x{0e30}\x{0e32}\x{0e33}\x{0e40}-\x{0e46}\x{0e81}\x{0e82}\x{0e84}\x{0e87}\x{0e88}\x{0e8a}\x{0e8d}\x{0e94}-\x{0e97}\x{0e99}-\x{0e9f}\x{0ea1}-\x{0ea3}\x{0ea5}\x{0ea7}\x{0eaa}\x{0eab}\x{0ead}-\x{0eb0}\x{0eb2}\x{0eb3}\x{0ebd}\x{0ec0}-\x{0ec4}\x{0ec6}\x{0edc}-\x{0edf}\x{0f00}\x{0f40}-\x{0f47}\x{0f49}-\x{0f6c}\x{0f88}-\x{0f8c}\x{1000}-\x{102a}\x{103f}\x{1050}-\x{1055}\x{105a}-\x{105d}\x{1061}\x{1065}\x{1066}\x{106e}-\x{1070}\x{1075}-\x{1081}\x{108e}\x{10a0}-\x{10c5}\x{10c7}\x{10cd}\x{10d0}-\x{10fa}\x{10fc}-\x{1248}\x{124a}-\x{124d}\x{1250}-\x{1256}\x{1258}\x{125a}-\x{125d}\x{1260}-\x{1288}\x{128a}-\x{128d}\x{1290}-\x{12b0}\x{12b2}-\x{12b5}\x{12b8}-\x{12be}\x{12c0}\x{12c2}-\x{12c5}\x{12c8}-\x{12d6}\x{12d8}-\x{1310}\x{1312}-\x{1315}\x{1318}-\x{135a}\x{1380}-\x{138f}\x{13a0}-\x{13f4}\x{1401}-\x{166c}\x{166f}-\x{167f}\x{1681}-\x{169a}\x{16a0}-\x{16ea}\x{16ee}-\x{16f0}\x{1700}-\x{170c}\x{170e}-\x{1711}\x{1720}-\x{1731}\x{1740}-\x{1751}\x{1760}-\x{176c}\x{176e}-\x{1770}\x{1780}-\x{17b3}\x{17d7}\x{17dc}\x{1820}-\x{1877}\x{1880}-\x{18a8}\x{18aa}\x{18b0}-\x{18f5}\x{1900}-\x{191c}\x{1950}-\x{196d}\x{1970}-\x{1974}\x{1980}-\x{19ab}\x{19c1}-\x{19c7}\x{1a00}-\x{1a16}\x{1a20}-\x{1a54}\x{1aa7}\x{1b05}-\x{1b33}\x{1b45}-\x{1b4b}\x{1b83}-\x{1ba0}\x{1bae}\x{1baf}\x{1bba}-\x{1be5}\x{1c00}-\x{1c23}\x{1c4d}-\x{1c4f}\x{1c5a}-\x{1c7d}\x{1ce9}-\x{1cec}\x{1cee}-\x{1cf1}\x{1cf5}\x{1cf6}\x{1d00}-\x{1dbf}\x{1e00}-\x{1f15}\x{1f18}-\x{1f1d}\x{1f20}-\x{1f45}\x{1f48}-\x{1f4d}\x{1f50}-\x{1f57}\x{1f59}\x{1f5b}\x{1f5d}\x{1f5f}-\x{1f7d}\x{1f80}-\x{1fb4}\x{1fb6}-\x{1fbc}\x{1fbe}\x{1fc2}-\x{1fc4}\x{1fc6}-\x{1fcc}\x{1fd0}-\x{1fd3}\x{1fd6}-\x{1fdb}\x{1fe0}-\x{1fec}\x{1ff2}-\x{1ff4}\x{1ff6}-\x{1ffc}\x{2071}\x{207f}\x{2090}-\x{209c}\x{2102}\x{2107}\x{210a}-\x{2113}\x{2115}\x{2119}-\x{211d}\x{2124}\x{2126}\x{2128}\x{212a}-\x{212d}\x{212f}-\x{2139}\x{213c}-\x{213f}\x{2145}-\x{2149}\x{214e}\x{2160}-\x{2188}\x{2c00}-\x{2c2e}\x{2c30}-\x{2c5e}\x{2c60}-\x{2ce4}\x{2ceb}-\x{2cee}\x{2cf2}\x{2cf3}\x{2d00}-\x{2d25}\x{2d27}\x{2d2d}\x{2d30}-\x{2d67}\x{2d6f}\x{2d80}-\x{2d96}\x{2da0}-\x{2da6}\x{2da8}-\x{2dae}\x{2db0}-\x{2db6}\x{2db8}-\x{2dbe}\x{2dc0}-\x{2dc6}\x{2dc8}-\x{2dce}\x{2dd0}-\x{2dd6}\x{2dd8}-\x{2dde}\x{2e2f}\x{3005}-\x{3007}\x{3021}-\x{3029}\x{3031}-\x{3035}\x{3038}-\x{303c}\x{3041}-\x{3096}\x{309d}-\x{309f}\x{30a1}-\x{30fa}\x{30fc}-\x{30ff}\x{3105}-\x{312d}\x{3131}-\x{318e}\x{31a0}-\x{31ba}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}\x{4e00}-\x{9fcc}\x{a000}-\x{a48c}\x{a4d0}-\x{a4fd}\x{a500}-\x{a60c}\x{a610}-\x{a61f}\x{a62a}\x{a62b}\x{a640}-\x{a66e}\x{a67f}-\x{a697}\x{a6a0}-\x{a6ef}\x{a717}-\x{a71f}\x{a722}-\x{a788}\x{a78b}-\x{a78e}\x{a790}-\x{a793}\x{a7a0}-\x{a7aa}\x{a7f8}-\x{a801}\x{a803}-\x{a805}\x{a807}-\x{a80a}\x{a80c}-\x{a822}\x{a840}-\x{a873}\x{a882}-\x{a8b3}\x{a8f2}-\x{a8f7}\x{a8fb}\x{a90a}-\x{a925}\x{a930}-\x{a946}\x{a960}-\x{a97c}\x{a984}-\x{a9b2}\x{a9cf}\x{aa00}-\x{aa28}\x{aa40}-\x{aa42}\x{aa44}-\x{aa4b}\x{aa60}-\x{aa76}\x{aa7a}\x{aa80}-\x{aaaf}\x{aab1}\x{aab5}\x{aab6}\x{aab9}-\x{aabd}\x{aac0}\x{aac2}\x{aadb}-\x{aadd}\x{aae0}-\x{aaea}\x{aaf2}-\x{aaf4}\x{ab01}-\x{ab06}\x{ab09}-\x{ab0e}\x{ab11}-\x{ab16}\x{ab20}-\x{ab26}\x{ab28}-\x{ab2e}\x{abc0}-\x{abe2}\x{ac00}-\x{d7a3}\x{d7b0}-\x{d7c6}\x{d7cb}-\x{d7fb}\x{f900}-\x{fa6d}\x{fa70}-\x{fad9}\x{fb00}-\x{fb06}\x{fb13}-\x{fb17}\x{fb1d}\x{fb1f}-\x{fb28}\x{fb2a}-\x{fb36}\x{fb38}-\x{fb3c}\x{fb3e}\x{fb40}\x{fb41}\x{fb43}\x{fb44}\x{fb46}-\x{fbb1}\x{fbd3}-\x{fd3d}\x{fd50}-\x{fd8f}\x{fd92}-\x{fdc7}\x{fdf0}-\x{fdfb}\x{fe70}-\x{fe74}\x{fe76}-\x{fefc}\x{ff21}-\x{ff3a}\x{ff41}-\x{ff5a}\x{ff66}-\x{ffbe}\x{ffc2}-\x{ffc7}\x{ffca}-\x{ffcf}\x{ffd2}-\x{ffd7}\x{ffda}-\x{ffdc}0-9\x{0300}-\x{036f}\x{0483}-\x{0487}\x{0591}-\x{05bd}\x{05bf}\x{05c1}\x{05c2}\x{05c4}\x{05c5}\x{05c7}\x{0610}-\x{061a}\x{064b}-\x{0669}\x{0670}\x{06d6}-\x{06dc}\x{06df}-\x{06e4}\x{06e7}\x{06e8}\x{06ea}-\x{06ed}\x{06f0}-\x{06f9}\x{0711}\x{0730}-\x{074a}\x{07a6}-\x{07b0}\x{07c0}-\x{07c9}\x{07eb}-\x{07f3}\x{0816}-\x{0819}\x{081b}-\x{0823}\x{0825}-\x{0827}\x{0829}-\x{082d}\x{0859}-\x{085b}\x{08e4}-\x{08fe}\x{0900}-\x{0903}\x{093a}-\x{093c}\x{093e}-\x{094f}\x{0951}-\x{0957}\x{0962}\x{0963}\x{0966}-\x{096f}\x{0981}-\x{0983}\x{09bc}\x{09be}-\x{09c4}\x{09c7}\x{09c8}\x{09cb}-\x{09cd}\x{09d7}\x{09e2}\x{09e3}\x{09e6}-\x{09ef}\x{0a01}-\x{0a03}\x{0a3c}\x{0a3e}-\x{0a42}\x{0a47}\x{0a48}\x{0a4b}-\x{0a4d}\x{0a51}\x{0a66}-\x{0a71}\x{0a75}\x{0a81}-\x{0a83}\x{0abc}\x{0abe}-\x{0ac5}\x{0ac7}-\x{0ac9}\x{0acb}-\x{0acd}\x{0ae2}\x{0ae3}\x{0ae6}-\x{0aef}\x{0b01}-\x{0b03}\x{0b3c}\x{0b3e}-\x{0b44}\x{0b47}\x{0b48}\x{0b4b}-\x{0b4d}\x{0b56}\x{0b57}\x{0b62}\x{0b63}\x{0b66}-\x{0b6f}\x{0b82}\x{0bbe}-\x{0bc2}\x{0bc6}-\x{0bc8}\x{0bca}-\x{0bcd}\x{0bd7}\x{0be6}-\x{0bef}\x{0c01}-\x{0c03}\x{0c3e}-\x{0c44}\x{0c46}-\x{0c48}\x{0c4a}-\x{0c4d}\x{0c55}\x{0c56}\x{0c62}\x{0c63}\x{0c66}-\x{0c6f}\x{0c82}\x{0c83}\x{0cbc}\x{0cbe}-\x{0cc4}\x{0cc6}-\x{0cc8}\x{0cca}-\x{0ccd}\x{0cd5}\x{0cd6}\x{0ce2}\x{0ce3}\x{0ce6}-\x{0cef}\x{0d02}\x{0d03}\x{0d3e}-\x{0d44}\x{0d46}-\x{0d48}\x{0d4a}-\x{0d4d}\x{0d57}\x{0d62}\x{0d63}\x{0d66}-\x{0d6f}\x{0d82}\x{0d83}\x{0dca}\x{0dcf}-\x{0dd4}\x{0dd6}\x{0dd8}-\x{0ddf}\x{0df2}\x{0df3}\x{0e31}\x{0e34}-\x{0e3a}\x{0e47}-\x{0e4e}\x{0e50}-\x{0e59}\x{0eb1}\x{0eb4}-\x{0eb9}\x{0ebb}\x{0ebc}\x{0ec8}-\x{0ecd}\x{0ed0}-\x{0ed9}\x{0f18}\x{0f19}\x{0f20}-\x{0f29}\x{0f35}\x{0f37}\x{0f39}\x{0f3e}\x{0f3f}\x{0f71}-\x{0f84}\x{0f86}\x{0f87}\x{0f8d}-\x{0f97}\x{0f99}-\x{0fbc}\x{0fc6}\x{102b}-\x{103e}\x{1040}-\x{1049}\x{1056}-\x{1059}\x{105e}-\x{1060}\x{1062}-\x{1064}\x{1067}-\x{106d}\x{1071}-\x{1074}\x{1082}-\x{108d}\x{108f}-\x{109d}\x{135d}-\x{135f}\x{1712}-\x{1714}\x{1732}-\x{1734}\x{1752}\x{1753}\x{1772}\x{1773}\x{17b4}-\x{17d3}\x{17dd}\x{17e0}-\x{17e9}\x{180b}-\x{180d}\x{1810}-\x{1819}\x{18a9}\x{1920}-\x{192b}\x{1930}-\x{193b}\x{1946}-\x{194f}\x{19b0}-\x{19c0}\x{19c8}\x{19c9}\x{19d0}-\x{19d9}\x{1a17}-\x{1a1b}\x{1a55}-\x{1a5e}\x{1a60}-\x{1a7c}\x{1a7f}-\x{1a89}\x{1a90}-\x{1a99}\x{1b00}-\x{1b04}\x{1b34}-\x{1b44}\x{1b50}-\x{1b59}\x{1b6b}-\x{1b73}\x{1b80}-\x{1b82}\x{1ba1}-\x{1bad}\x{1bb0}-\x{1bb9}\x{1be6}-\x{1bf3}\x{1c24}-\x{1c37}\x{1c40}-\x{1c49}\x{1c50}-\x{1c59}\x{1cd0}-\x{1cd2}\x{1cd4}-\x{1ce8}\x{1ced}\x{1cf2}-\x{1cf4}\x{1dc0}-\x{1de6}\x{1dfc}-\x{1dff}\x{200c}\x{200d}\x{203f}\x{2040}\x{2054}\x{20d0}-\x{20dc}\x{20e1}\x{20e5}-\x{20f0}\x{2cef}-\x{2cf1}\x{2d7f}\x{2de0}-\x{2dff}\x{302a}-\x{302f}\x{3099}\x{309a}\x{a620}-\x{a629}\x{a66f}\x{a674}-\x{a67d}\x{a69f}\x{a6f0}\x{a6f1}\x{a802}\x{a806}\x{a80b}\x{a823}-\x{a827}\x{a880}\x{a881}\x{a8b4}-\x{a8c4}\x{a8d0}-\x{a8d9}\x{a8e0}-\x{a8f1}\x{a900}-\x{a909}\x{a926}-\x{a92d}\x{a947}-\x{a953}\x{a980}-\x{a983}\x{a9b3}-\x{a9c0}\x{a9d0}-\x{a9d9}\x{aa29}-\x{aa36}\x{aa43}\x{aa4c}\x{aa4d}\x{aa50}-\x{aa59}\x{aa7b}\x{aab0}\x{aab2}-\x{aab4}\x{aab7}\x{aab8}\x{aabe}\x{aabf}\x{aac1}\x{aaeb}-\x{aaef}\x{aaf5}\x{aaf6}\x{abe3}-\x{abea}\x{abec}\x{abed}\x{abf0}-\x{abf9}\x{fb1e}\x{fe00}-\x{fe0f}\x{fe20}-\x{fe26}\x{fe33}\x{fe34}\x{fe4d}-\x{fe4f}\x{ff10}-\x{ff19}\x{ff3f}]*\b';
26
-
27
-    /**
28
-     * Full list of JavaScript reserved words.
29
-     * Will be loaded from /data/js/keywords_reserved.txt.
30
-     *
31
-     * @see https://mathiasbynens.be/notes/reserved-keywords
32
-     *
33
-     * @var string[]
34
-     */
35
-    protected $keywordsReserved = array();
36
-
37
-    /**
38
-     * List of JavaScript reserved words that accept a <variable, value, ...>
39
-     * after them. Some end of lines are not the end of a statement, like with
40
-     * these keywords.
41
-     *
42
-     * E.g.: we shouldn't insert a ; after this else
43
-     * else
44
-     *     console.log('this is quite fine')
45
-     *
46
-     * Will be loaded from /data/js/keywords_before.txt
47
-     *
48
-     * @var string[]
49
-     */
50
-    protected $keywordsBefore = array();
51
-
52
-    /**
53
-     * List of JavaScript reserved words that accept a <variable, value, ...>
54
-     * before them. Some end of lines are not the end of a statement, like when
55
-     * continued by one of these keywords on the newline.
56
-     *
57
-     * E.g.: we shouldn't insert a ; before this instanceof
58
-     * variable
59
-     *     instanceof String
60
-     *
61
-     * Will be loaded from /data/js/keywords_after.txt
62
-     *
63
-     * @var string[]
64
-     */
65
-    protected $keywordsAfter = array();
66
-
67
-    /**
68
-     * List of all JavaScript operators.
69
-     *
70
-     * Will be loaded from /data/js/operators.txt
71
-     *
72
-     * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
73
-     *
74
-     * @var string[]
75
-     */
76
-    protected $operators = array();
77
-
78
-    /**
79
-     * List of JavaScript operators that accept a <variable, value, ...> after
80
-     * them. Some end of lines are not the end of a statement, like with these
81
-     * operators.
82
-     *
83
-     * Note: Most operators are fine, we've only removed !, ++ and --.
84
-     * There can't be a newline separating ! and whatever it is negating.
85
-     * ++ & -- have to be joined with the value they're in-/decrementing.
86
-     *
87
-     * Will be loaded from /data/js/operators_before.txt
88
-     *
89
-     * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
90
-     *
91
-     * @var string[]
92
-     */
93
-    protected $operatorsBefore = array();
94
-
95
-    /**
96
-     * List of JavaScript operators that accept a <variable, value, ...> before
97
-     * them. Some end of lines are not the end of a statement, like when
98
-     * continued by one of these operators on the newline.
99
-     *
100
-     * Note: Most operators are fine, we've only removed ), ], ++ and --.
101
-     * ++ & -- have to be joined with the value they're in-/decrementing.
102
-     * ) & ] are "special" in that they have lots or usecases. () for example
103
-     * is used for function calls, for grouping, in if () and for (), ...
104
-     *
105
-     * Will be loaded from /data/js/operators_after.txt
106
-     *
107
-     * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
108
-     *
109
-     * @var string[]
110
-     */
111
-    protected $operatorsAfter = array();
112
-
113
-    /**
114
-     * {@inheritdoc}
115
-     */
116
-    public function __construct()
117
-    {
118
-        call_user_func_array(array('parent', '__construct'), func_get_args());
119
-
120
-        $dataDir = __DIR__.'/../data/js/';
121
-        $options = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES;
122
-        $this->keywordsReserved = file($dataDir.'keywords_reserved.txt', $options);
123
-        $this->keywordsBefore = file($dataDir.'keywords_before.txt', $options);
124
-        $this->keywordsAfter = file($dataDir.'keywords_after.txt', $options);
125
-        $this->operators = file($dataDir.'operators.txt', $options);
126
-        $this->operatorsBefore = file($dataDir.'operators_before.txt', $options);
127
-        $this->operatorsAfter = file($dataDir.'operators_after.txt', $options);
128
-    }
129
-
130
-    /**
131
-     * Minify the data.
132
-     * Perform JS optimizations.
133
-     *
134
-     * @param string[optional] $path Path to write the data to
135
-     *
136
-     * @return string The minified data
137
-     */
138
-    public function execute($path = null)
139
-    {
140
-        $content = '';
141
-
142
-        // loop files
143
-        foreach ($this->data as $source => $js) {
144
-            /*
17
+	/**
18
+	 * Var-matching regex based on https://stackoverflow.com/a/9337047/802993.
19
+	 *
20
+	 * Note that regular expressions using that bit must have the PCRE_UTF8
21
+	 * pattern modifier (/u) set.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	const REGEX_VARIABLE = '\b[$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\x{02c1}\x{02c6}-\x{02d1}\x{02e0}-\x{02e4}\x{02ec}\x{02ee}\x{0370}-\x{0374}\x{0376}\x{0377}\x{037a}-\x{037d}\x{0386}\x{0388}-\x{038a}\x{038c}\x{038e}-\x{03a1}\x{03a3}-\x{03f5}\x{03f7}-\x{0481}\x{048a}-\x{0527}\x{0531}-\x{0556}\x{0559}\x{0561}-\x{0587}\x{05d0}-\x{05ea}\x{05f0}-\x{05f2}\x{0620}-\x{064a}\x{066e}\x{066f}\x{0671}-\x{06d3}\x{06d5}\x{06e5}\x{06e6}\x{06ee}\x{06ef}\x{06fa}-\x{06fc}\x{06ff}\x{0710}\x{0712}-\x{072f}\x{074d}-\x{07a5}\x{07b1}\x{07ca}-\x{07ea}\x{07f4}\x{07f5}\x{07fa}\x{0800}-\x{0815}\x{081a}\x{0824}\x{0828}\x{0840}-\x{0858}\x{08a0}\x{08a2}-\x{08ac}\x{0904}-\x{0939}\x{093d}\x{0950}\x{0958}-\x{0961}\x{0971}-\x{0977}\x{0979}-\x{097f}\x{0985}-\x{098c}\x{098f}\x{0990}\x{0993}-\x{09a8}\x{09aa}-\x{09b0}\x{09b2}\x{09b6}-\x{09b9}\x{09bd}\x{09ce}\x{09dc}\x{09dd}\x{09df}-\x{09e1}\x{09f0}\x{09f1}\x{0a05}-\x{0a0a}\x{0a0f}\x{0a10}\x{0a13}-\x{0a28}\x{0a2a}-\x{0a30}\x{0a32}\x{0a33}\x{0a35}\x{0a36}\x{0a38}\x{0a39}\x{0a59}-\x{0a5c}\x{0a5e}\x{0a72}-\x{0a74}\x{0a85}-\x{0a8d}\x{0a8f}-\x{0a91}\x{0a93}-\x{0aa8}\x{0aaa}-\x{0ab0}\x{0ab2}\x{0ab3}\x{0ab5}-\x{0ab9}\x{0abd}\x{0ad0}\x{0ae0}\x{0ae1}\x{0b05}-\x{0b0c}\x{0b0f}\x{0b10}\x{0b13}-\x{0b28}\x{0b2a}-\x{0b30}\x{0b32}\x{0b33}\x{0b35}-\x{0b39}\x{0b3d}\x{0b5c}\x{0b5d}\x{0b5f}-\x{0b61}\x{0b71}\x{0b83}\x{0b85}-\x{0b8a}\x{0b8e}-\x{0b90}\x{0b92}-\x{0b95}\x{0b99}\x{0b9a}\x{0b9c}\x{0b9e}\x{0b9f}\x{0ba3}\x{0ba4}\x{0ba8}-\x{0baa}\x{0bae}-\x{0bb9}\x{0bd0}\x{0c05}-\x{0c0c}\x{0c0e}-\x{0c10}\x{0c12}-\x{0c28}\x{0c2a}-\x{0c33}\x{0c35}-\x{0c39}\x{0c3d}\x{0c58}\x{0c59}\x{0c60}\x{0c61}\x{0c85}-\x{0c8c}\x{0c8e}-\x{0c90}\x{0c92}-\x{0ca8}\x{0caa}-\x{0cb3}\x{0cb5}-\x{0cb9}\x{0cbd}\x{0cde}\x{0ce0}\x{0ce1}\x{0cf1}\x{0cf2}\x{0d05}-\x{0d0c}\x{0d0e}-\x{0d10}\x{0d12}-\x{0d3a}\x{0d3d}\x{0d4e}\x{0d60}\x{0d61}\x{0d7a}-\x{0d7f}\x{0d85}-\x{0d96}\x{0d9a}-\x{0db1}\x{0db3}-\x{0dbb}\x{0dbd}\x{0dc0}-\x{0dc6}\x{0e01}-\x{0e30}\x{0e32}\x{0e33}\x{0e40}-\x{0e46}\x{0e81}\x{0e82}\x{0e84}\x{0e87}\x{0e88}\x{0e8a}\x{0e8d}\x{0e94}-\x{0e97}\x{0e99}-\x{0e9f}\x{0ea1}-\x{0ea3}\x{0ea5}\x{0ea7}\x{0eaa}\x{0eab}\x{0ead}-\x{0eb0}\x{0eb2}\x{0eb3}\x{0ebd}\x{0ec0}-\x{0ec4}\x{0ec6}\x{0edc}-\x{0edf}\x{0f00}\x{0f40}-\x{0f47}\x{0f49}-\x{0f6c}\x{0f88}-\x{0f8c}\x{1000}-\x{102a}\x{103f}\x{1050}-\x{1055}\x{105a}-\x{105d}\x{1061}\x{1065}\x{1066}\x{106e}-\x{1070}\x{1075}-\x{1081}\x{108e}\x{10a0}-\x{10c5}\x{10c7}\x{10cd}\x{10d0}-\x{10fa}\x{10fc}-\x{1248}\x{124a}-\x{124d}\x{1250}-\x{1256}\x{1258}\x{125a}-\x{125d}\x{1260}-\x{1288}\x{128a}-\x{128d}\x{1290}-\x{12b0}\x{12b2}-\x{12b5}\x{12b8}-\x{12be}\x{12c0}\x{12c2}-\x{12c5}\x{12c8}-\x{12d6}\x{12d8}-\x{1310}\x{1312}-\x{1315}\x{1318}-\x{135a}\x{1380}-\x{138f}\x{13a0}-\x{13f4}\x{1401}-\x{166c}\x{166f}-\x{167f}\x{1681}-\x{169a}\x{16a0}-\x{16ea}\x{16ee}-\x{16f0}\x{1700}-\x{170c}\x{170e}-\x{1711}\x{1720}-\x{1731}\x{1740}-\x{1751}\x{1760}-\x{176c}\x{176e}-\x{1770}\x{1780}-\x{17b3}\x{17d7}\x{17dc}\x{1820}-\x{1877}\x{1880}-\x{18a8}\x{18aa}\x{18b0}-\x{18f5}\x{1900}-\x{191c}\x{1950}-\x{196d}\x{1970}-\x{1974}\x{1980}-\x{19ab}\x{19c1}-\x{19c7}\x{1a00}-\x{1a16}\x{1a20}-\x{1a54}\x{1aa7}\x{1b05}-\x{1b33}\x{1b45}-\x{1b4b}\x{1b83}-\x{1ba0}\x{1bae}\x{1baf}\x{1bba}-\x{1be5}\x{1c00}-\x{1c23}\x{1c4d}-\x{1c4f}\x{1c5a}-\x{1c7d}\x{1ce9}-\x{1cec}\x{1cee}-\x{1cf1}\x{1cf5}\x{1cf6}\x{1d00}-\x{1dbf}\x{1e00}-\x{1f15}\x{1f18}-\x{1f1d}\x{1f20}-\x{1f45}\x{1f48}-\x{1f4d}\x{1f50}-\x{1f57}\x{1f59}\x{1f5b}\x{1f5d}\x{1f5f}-\x{1f7d}\x{1f80}-\x{1fb4}\x{1fb6}-\x{1fbc}\x{1fbe}\x{1fc2}-\x{1fc4}\x{1fc6}-\x{1fcc}\x{1fd0}-\x{1fd3}\x{1fd6}-\x{1fdb}\x{1fe0}-\x{1fec}\x{1ff2}-\x{1ff4}\x{1ff6}-\x{1ffc}\x{2071}\x{207f}\x{2090}-\x{209c}\x{2102}\x{2107}\x{210a}-\x{2113}\x{2115}\x{2119}-\x{211d}\x{2124}\x{2126}\x{2128}\x{212a}-\x{212d}\x{212f}-\x{2139}\x{213c}-\x{213f}\x{2145}-\x{2149}\x{214e}\x{2160}-\x{2188}\x{2c00}-\x{2c2e}\x{2c30}-\x{2c5e}\x{2c60}-\x{2ce4}\x{2ceb}-\x{2cee}\x{2cf2}\x{2cf3}\x{2d00}-\x{2d25}\x{2d27}\x{2d2d}\x{2d30}-\x{2d67}\x{2d6f}\x{2d80}-\x{2d96}\x{2da0}-\x{2da6}\x{2da8}-\x{2dae}\x{2db0}-\x{2db6}\x{2db8}-\x{2dbe}\x{2dc0}-\x{2dc6}\x{2dc8}-\x{2dce}\x{2dd0}-\x{2dd6}\x{2dd8}-\x{2dde}\x{2e2f}\x{3005}-\x{3007}\x{3021}-\x{3029}\x{3031}-\x{3035}\x{3038}-\x{303c}\x{3041}-\x{3096}\x{309d}-\x{309f}\x{30a1}-\x{30fa}\x{30fc}-\x{30ff}\x{3105}-\x{312d}\x{3131}-\x{318e}\x{31a0}-\x{31ba}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}\x{4e00}-\x{9fcc}\x{a000}-\x{a48c}\x{a4d0}-\x{a4fd}\x{a500}-\x{a60c}\x{a610}-\x{a61f}\x{a62a}\x{a62b}\x{a640}-\x{a66e}\x{a67f}-\x{a697}\x{a6a0}-\x{a6ef}\x{a717}-\x{a71f}\x{a722}-\x{a788}\x{a78b}-\x{a78e}\x{a790}-\x{a793}\x{a7a0}-\x{a7aa}\x{a7f8}-\x{a801}\x{a803}-\x{a805}\x{a807}-\x{a80a}\x{a80c}-\x{a822}\x{a840}-\x{a873}\x{a882}-\x{a8b3}\x{a8f2}-\x{a8f7}\x{a8fb}\x{a90a}-\x{a925}\x{a930}-\x{a946}\x{a960}-\x{a97c}\x{a984}-\x{a9b2}\x{a9cf}\x{aa00}-\x{aa28}\x{aa40}-\x{aa42}\x{aa44}-\x{aa4b}\x{aa60}-\x{aa76}\x{aa7a}\x{aa80}-\x{aaaf}\x{aab1}\x{aab5}\x{aab6}\x{aab9}-\x{aabd}\x{aac0}\x{aac2}\x{aadb}-\x{aadd}\x{aae0}-\x{aaea}\x{aaf2}-\x{aaf4}\x{ab01}-\x{ab06}\x{ab09}-\x{ab0e}\x{ab11}-\x{ab16}\x{ab20}-\x{ab26}\x{ab28}-\x{ab2e}\x{abc0}-\x{abe2}\x{ac00}-\x{d7a3}\x{d7b0}-\x{d7c6}\x{d7cb}-\x{d7fb}\x{f900}-\x{fa6d}\x{fa70}-\x{fad9}\x{fb00}-\x{fb06}\x{fb13}-\x{fb17}\x{fb1d}\x{fb1f}-\x{fb28}\x{fb2a}-\x{fb36}\x{fb38}-\x{fb3c}\x{fb3e}\x{fb40}\x{fb41}\x{fb43}\x{fb44}\x{fb46}-\x{fbb1}\x{fbd3}-\x{fd3d}\x{fd50}-\x{fd8f}\x{fd92}-\x{fdc7}\x{fdf0}-\x{fdfb}\x{fe70}-\x{fe74}\x{fe76}-\x{fefc}\x{ff21}-\x{ff3a}\x{ff41}-\x{ff5a}\x{ff66}-\x{ffbe}\x{ffc2}-\x{ffc7}\x{ffca}-\x{ffcf}\x{ffd2}-\x{ffd7}\x{ffda}-\x{ffdc}][$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\x{02c1}\x{02c6}-\x{02d1}\x{02e0}-\x{02e4}\x{02ec}\x{02ee}\x{0370}-\x{0374}\x{0376}\x{0377}\x{037a}-\x{037d}\x{0386}\x{0388}-\x{038a}\x{038c}\x{038e}-\x{03a1}\x{03a3}-\x{03f5}\x{03f7}-\x{0481}\x{048a}-\x{0527}\x{0531}-\x{0556}\x{0559}\x{0561}-\x{0587}\x{05d0}-\x{05ea}\x{05f0}-\x{05f2}\x{0620}-\x{064a}\x{066e}\x{066f}\x{0671}-\x{06d3}\x{06d5}\x{06e5}\x{06e6}\x{06ee}\x{06ef}\x{06fa}-\x{06fc}\x{06ff}\x{0710}\x{0712}-\x{072f}\x{074d}-\x{07a5}\x{07b1}\x{07ca}-\x{07ea}\x{07f4}\x{07f5}\x{07fa}\x{0800}-\x{0815}\x{081a}\x{0824}\x{0828}\x{0840}-\x{0858}\x{08a0}\x{08a2}-\x{08ac}\x{0904}-\x{0939}\x{093d}\x{0950}\x{0958}-\x{0961}\x{0971}-\x{0977}\x{0979}-\x{097f}\x{0985}-\x{098c}\x{098f}\x{0990}\x{0993}-\x{09a8}\x{09aa}-\x{09b0}\x{09b2}\x{09b6}-\x{09b9}\x{09bd}\x{09ce}\x{09dc}\x{09dd}\x{09df}-\x{09e1}\x{09f0}\x{09f1}\x{0a05}-\x{0a0a}\x{0a0f}\x{0a10}\x{0a13}-\x{0a28}\x{0a2a}-\x{0a30}\x{0a32}\x{0a33}\x{0a35}\x{0a36}\x{0a38}\x{0a39}\x{0a59}-\x{0a5c}\x{0a5e}\x{0a72}-\x{0a74}\x{0a85}-\x{0a8d}\x{0a8f}-\x{0a91}\x{0a93}-\x{0aa8}\x{0aaa}-\x{0ab0}\x{0ab2}\x{0ab3}\x{0ab5}-\x{0ab9}\x{0abd}\x{0ad0}\x{0ae0}\x{0ae1}\x{0b05}-\x{0b0c}\x{0b0f}\x{0b10}\x{0b13}-\x{0b28}\x{0b2a}-\x{0b30}\x{0b32}\x{0b33}\x{0b35}-\x{0b39}\x{0b3d}\x{0b5c}\x{0b5d}\x{0b5f}-\x{0b61}\x{0b71}\x{0b83}\x{0b85}-\x{0b8a}\x{0b8e}-\x{0b90}\x{0b92}-\x{0b95}\x{0b99}\x{0b9a}\x{0b9c}\x{0b9e}\x{0b9f}\x{0ba3}\x{0ba4}\x{0ba8}-\x{0baa}\x{0bae}-\x{0bb9}\x{0bd0}\x{0c05}-\x{0c0c}\x{0c0e}-\x{0c10}\x{0c12}-\x{0c28}\x{0c2a}-\x{0c33}\x{0c35}-\x{0c39}\x{0c3d}\x{0c58}\x{0c59}\x{0c60}\x{0c61}\x{0c85}-\x{0c8c}\x{0c8e}-\x{0c90}\x{0c92}-\x{0ca8}\x{0caa}-\x{0cb3}\x{0cb5}-\x{0cb9}\x{0cbd}\x{0cde}\x{0ce0}\x{0ce1}\x{0cf1}\x{0cf2}\x{0d05}-\x{0d0c}\x{0d0e}-\x{0d10}\x{0d12}-\x{0d3a}\x{0d3d}\x{0d4e}\x{0d60}\x{0d61}\x{0d7a}-\x{0d7f}\x{0d85}-\x{0d96}\x{0d9a}-\x{0db1}\x{0db3}-\x{0dbb}\x{0dbd}\x{0dc0}-\x{0dc6}\x{0e01}-\x{0e30}\x{0e32}\x{0e33}\x{0e40}-\x{0e46}\x{0e81}\x{0e82}\x{0e84}\x{0e87}\x{0e88}\x{0e8a}\x{0e8d}\x{0e94}-\x{0e97}\x{0e99}-\x{0e9f}\x{0ea1}-\x{0ea3}\x{0ea5}\x{0ea7}\x{0eaa}\x{0eab}\x{0ead}-\x{0eb0}\x{0eb2}\x{0eb3}\x{0ebd}\x{0ec0}-\x{0ec4}\x{0ec6}\x{0edc}-\x{0edf}\x{0f00}\x{0f40}-\x{0f47}\x{0f49}-\x{0f6c}\x{0f88}-\x{0f8c}\x{1000}-\x{102a}\x{103f}\x{1050}-\x{1055}\x{105a}-\x{105d}\x{1061}\x{1065}\x{1066}\x{106e}-\x{1070}\x{1075}-\x{1081}\x{108e}\x{10a0}-\x{10c5}\x{10c7}\x{10cd}\x{10d0}-\x{10fa}\x{10fc}-\x{1248}\x{124a}-\x{124d}\x{1250}-\x{1256}\x{1258}\x{125a}-\x{125d}\x{1260}-\x{1288}\x{128a}-\x{128d}\x{1290}-\x{12b0}\x{12b2}-\x{12b5}\x{12b8}-\x{12be}\x{12c0}\x{12c2}-\x{12c5}\x{12c8}-\x{12d6}\x{12d8}-\x{1310}\x{1312}-\x{1315}\x{1318}-\x{135a}\x{1380}-\x{138f}\x{13a0}-\x{13f4}\x{1401}-\x{166c}\x{166f}-\x{167f}\x{1681}-\x{169a}\x{16a0}-\x{16ea}\x{16ee}-\x{16f0}\x{1700}-\x{170c}\x{170e}-\x{1711}\x{1720}-\x{1731}\x{1740}-\x{1751}\x{1760}-\x{176c}\x{176e}-\x{1770}\x{1780}-\x{17b3}\x{17d7}\x{17dc}\x{1820}-\x{1877}\x{1880}-\x{18a8}\x{18aa}\x{18b0}-\x{18f5}\x{1900}-\x{191c}\x{1950}-\x{196d}\x{1970}-\x{1974}\x{1980}-\x{19ab}\x{19c1}-\x{19c7}\x{1a00}-\x{1a16}\x{1a20}-\x{1a54}\x{1aa7}\x{1b05}-\x{1b33}\x{1b45}-\x{1b4b}\x{1b83}-\x{1ba0}\x{1bae}\x{1baf}\x{1bba}-\x{1be5}\x{1c00}-\x{1c23}\x{1c4d}-\x{1c4f}\x{1c5a}-\x{1c7d}\x{1ce9}-\x{1cec}\x{1cee}-\x{1cf1}\x{1cf5}\x{1cf6}\x{1d00}-\x{1dbf}\x{1e00}-\x{1f15}\x{1f18}-\x{1f1d}\x{1f20}-\x{1f45}\x{1f48}-\x{1f4d}\x{1f50}-\x{1f57}\x{1f59}\x{1f5b}\x{1f5d}\x{1f5f}-\x{1f7d}\x{1f80}-\x{1fb4}\x{1fb6}-\x{1fbc}\x{1fbe}\x{1fc2}-\x{1fc4}\x{1fc6}-\x{1fcc}\x{1fd0}-\x{1fd3}\x{1fd6}-\x{1fdb}\x{1fe0}-\x{1fec}\x{1ff2}-\x{1ff4}\x{1ff6}-\x{1ffc}\x{2071}\x{207f}\x{2090}-\x{209c}\x{2102}\x{2107}\x{210a}-\x{2113}\x{2115}\x{2119}-\x{211d}\x{2124}\x{2126}\x{2128}\x{212a}-\x{212d}\x{212f}-\x{2139}\x{213c}-\x{213f}\x{2145}-\x{2149}\x{214e}\x{2160}-\x{2188}\x{2c00}-\x{2c2e}\x{2c30}-\x{2c5e}\x{2c60}-\x{2ce4}\x{2ceb}-\x{2cee}\x{2cf2}\x{2cf3}\x{2d00}-\x{2d25}\x{2d27}\x{2d2d}\x{2d30}-\x{2d67}\x{2d6f}\x{2d80}-\x{2d96}\x{2da0}-\x{2da6}\x{2da8}-\x{2dae}\x{2db0}-\x{2db6}\x{2db8}-\x{2dbe}\x{2dc0}-\x{2dc6}\x{2dc8}-\x{2dce}\x{2dd0}-\x{2dd6}\x{2dd8}-\x{2dde}\x{2e2f}\x{3005}-\x{3007}\x{3021}-\x{3029}\x{3031}-\x{3035}\x{3038}-\x{303c}\x{3041}-\x{3096}\x{309d}-\x{309f}\x{30a1}-\x{30fa}\x{30fc}-\x{30ff}\x{3105}-\x{312d}\x{3131}-\x{318e}\x{31a0}-\x{31ba}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}\x{4e00}-\x{9fcc}\x{a000}-\x{a48c}\x{a4d0}-\x{a4fd}\x{a500}-\x{a60c}\x{a610}-\x{a61f}\x{a62a}\x{a62b}\x{a640}-\x{a66e}\x{a67f}-\x{a697}\x{a6a0}-\x{a6ef}\x{a717}-\x{a71f}\x{a722}-\x{a788}\x{a78b}-\x{a78e}\x{a790}-\x{a793}\x{a7a0}-\x{a7aa}\x{a7f8}-\x{a801}\x{a803}-\x{a805}\x{a807}-\x{a80a}\x{a80c}-\x{a822}\x{a840}-\x{a873}\x{a882}-\x{a8b3}\x{a8f2}-\x{a8f7}\x{a8fb}\x{a90a}-\x{a925}\x{a930}-\x{a946}\x{a960}-\x{a97c}\x{a984}-\x{a9b2}\x{a9cf}\x{aa00}-\x{aa28}\x{aa40}-\x{aa42}\x{aa44}-\x{aa4b}\x{aa60}-\x{aa76}\x{aa7a}\x{aa80}-\x{aaaf}\x{aab1}\x{aab5}\x{aab6}\x{aab9}-\x{aabd}\x{aac0}\x{aac2}\x{aadb}-\x{aadd}\x{aae0}-\x{aaea}\x{aaf2}-\x{aaf4}\x{ab01}-\x{ab06}\x{ab09}-\x{ab0e}\x{ab11}-\x{ab16}\x{ab20}-\x{ab26}\x{ab28}-\x{ab2e}\x{abc0}-\x{abe2}\x{ac00}-\x{d7a3}\x{d7b0}-\x{d7c6}\x{d7cb}-\x{d7fb}\x{f900}-\x{fa6d}\x{fa70}-\x{fad9}\x{fb00}-\x{fb06}\x{fb13}-\x{fb17}\x{fb1d}\x{fb1f}-\x{fb28}\x{fb2a}-\x{fb36}\x{fb38}-\x{fb3c}\x{fb3e}\x{fb40}\x{fb41}\x{fb43}\x{fb44}\x{fb46}-\x{fbb1}\x{fbd3}-\x{fd3d}\x{fd50}-\x{fd8f}\x{fd92}-\x{fdc7}\x{fdf0}-\x{fdfb}\x{fe70}-\x{fe74}\x{fe76}-\x{fefc}\x{ff21}-\x{ff3a}\x{ff41}-\x{ff5a}\x{ff66}-\x{ffbe}\x{ffc2}-\x{ffc7}\x{ffca}-\x{ffcf}\x{ffd2}-\x{ffd7}\x{ffda}-\x{ffdc}0-9\x{0300}-\x{036f}\x{0483}-\x{0487}\x{0591}-\x{05bd}\x{05bf}\x{05c1}\x{05c2}\x{05c4}\x{05c5}\x{05c7}\x{0610}-\x{061a}\x{064b}-\x{0669}\x{0670}\x{06d6}-\x{06dc}\x{06df}-\x{06e4}\x{06e7}\x{06e8}\x{06ea}-\x{06ed}\x{06f0}-\x{06f9}\x{0711}\x{0730}-\x{074a}\x{07a6}-\x{07b0}\x{07c0}-\x{07c9}\x{07eb}-\x{07f3}\x{0816}-\x{0819}\x{081b}-\x{0823}\x{0825}-\x{0827}\x{0829}-\x{082d}\x{0859}-\x{085b}\x{08e4}-\x{08fe}\x{0900}-\x{0903}\x{093a}-\x{093c}\x{093e}-\x{094f}\x{0951}-\x{0957}\x{0962}\x{0963}\x{0966}-\x{096f}\x{0981}-\x{0983}\x{09bc}\x{09be}-\x{09c4}\x{09c7}\x{09c8}\x{09cb}-\x{09cd}\x{09d7}\x{09e2}\x{09e3}\x{09e6}-\x{09ef}\x{0a01}-\x{0a03}\x{0a3c}\x{0a3e}-\x{0a42}\x{0a47}\x{0a48}\x{0a4b}-\x{0a4d}\x{0a51}\x{0a66}-\x{0a71}\x{0a75}\x{0a81}-\x{0a83}\x{0abc}\x{0abe}-\x{0ac5}\x{0ac7}-\x{0ac9}\x{0acb}-\x{0acd}\x{0ae2}\x{0ae3}\x{0ae6}-\x{0aef}\x{0b01}-\x{0b03}\x{0b3c}\x{0b3e}-\x{0b44}\x{0b47}\x{0b48}\x{0b4b}-\x{0b4d}\x{0b56}\x{0b57}\x{0b62}\x{0b63}\x{0b66}-\x{0b6f}\x{0b82}\x{0bbe}-\x{0bc2}\x{0bc6}-\x{0bc8}\x{0bca}-\x{0bcd}\x{0bd7}\x{0be6}-\x{0bef}\x{0c01}-\x{0c03}\x{0c3e}-\x{0c44}\x{0c46}-\x{0c48}\x{0c4a}-\x{0c4d}\x{0c55}\x{0c56}\x{0c62}\x{0c63}\x{0c66}-\x{0c6f}\x{0c82}\x{0c83}\x{0cbc}\x{0cbe}-\x{0cc4}\x{0cc6}-\x{0cc8}\x{0cca}-\x{0ccd}\x{0cd5}\x{0cd6}\x{0ce2}\x{0ce3}\x{0ce6}-\x{0cef}\x{0d02}\x{0d03}\x{0d3e}-\x{0d44}\x{0d46}-\x{0d48}\x{0d4a}-\x{0d4d}\x{0d57}\x{0d62}\x{0d63}\x{0d66}-\x{0d6f}\x{0d82}\x{0d83}\x{0dca}\x{0dcf}-\x{0dd4}\x{0dd6}\x{0dd8}-\x{0ddf}\x{0df2}\x{0df3}\x{0e31}\x{0e34}-\x{0e3a}\x{0e47}-\x{0e4e}\x{0e50}-\x{0e59}\x{0eb1}\x{0eb4}-\x{0eb9}\x{0ebb}\x{0ebc}\x{0ec8}-\x{0ecd}\x{0ed0}-\x{0ed9}\x{0f18}\x{0f19}\x{0f20}-\x{0f29}\x{0f35}\x{0f37}\x{0f39}\x{0f3e}\x{0f3f}\x{0f71}-\x{0f84}\x{0f86}\x{0f87}\x{0f8d}-\x{0f97}\x{0f99}-\x{0fbc}\x{0fc6}\x{102b}-\x{103e}\x{1040}-\x{1049}\x{1056}-\x{1059}\x{105e}-\x{1060}\x{1062}-\x{1064}\x{1067}-\x{106d}\x{1071}-\x{1074}\x{1082}-\x{108d}\x{108f}-\x{109d}\x{135d}-\x{135f}\x{1712}-\x{1714}\x{1732}-\x{1734}\x{1752}\x{1753}\x{1772}\x{1773}\x{17b4}-\x{17d3}\x{17dd}\x{17e0}-\x{17e9}\x{180b}-\x{180d}\x{1810}-\x{1819}\x{18a9}\x{1920}-\x{192b}\x{1930}-\x{193b}\x{1946}-\x{194f}\x{19b0}-\x{19c0}\x{19c8}\x{19c9}\x{19d0}-\x{19d9}\x{1a17}-\x{1a1b}\x{1a55}-\x{1a5e}\x{1a60}-\x{1a7c}\x{1a7f}-\x{1a89}\x{1a90}-\x{1a99}\x{1b00}-\x{1b04}\x{1b34}-\x{1b44}\x{1b50}-\x{1b59}\x{1b6b}-\x{1b73}\x{1b80}-\x{1b82}\x{1ba1}-\x{1bad}\x{1bb0}-\x{1bb9}\x{1be6}-\x{1bf3}\x{1c24}-\x{1c37}\x{1c40}-\x{1c49}\x{1c50}-\x{1c59}\x{1cd0}-\x{1cd2}\x{1cd4}-\x{1ce8}\x{1ced}\x{1cf2}-\x{1cf4}\x{1dc0}-\x{1de6}\x{1dfc}-\x{1dff}\x{200c}\x{200d}\x{203f}\x{2040}\x{2054}\x{20d0}-\x{20dc}\x{20e1}\x{20e5}-\x{20f0}\x{2cef}-\x{2cf1}\x{2d7f}\x{2de0}-\x{2dff}\x{302a}-\x{302f}\x{3099}\x{309a}\x{a620}-\x{a629}\x{a66f}\x{a674}-\x{a67d}\x{a69f}\x{a6f0}\x{a6f1}\x{a802}\x{a806}\x{a80b}\x{a823}-\x{a827}\x{a880}\x{a881}\x{a8b4}-\x{a8c4}\x{a8d0}-\x{a8d9}\x{a8e0}-\x{a8f1}\x{a900}-\x{a909}\x{a926}-\x{a92d}\x{a947}-\x{a953}\x{a980}-\x{a983}\x{a9b3}-\x{a9c0}\x{a9d0}-\x{a9d9}\x{aa29}-\x{aa36}\x{aa43}\x{aa4c}\x{aa4d}\x{aa50}-\x{aa59}\x{aa7b}\x{aab0}\x{aab2}-\x{aab4}\x{aab7}\x{aab8}\x{aabe}\x{aabf}\x{aac1}\x{aaeb}-\x{aaef}\x{aaf5}\x{aaf6}\x{abe3}-\x{abea}\x{abec}\x{abed}\x{abf0}-\x{abf9}\x{fb1e}\x{fe00}-\x{fe0f}\x{fe20}-\x{fe26}\x{fe33}\x{fe34}\x{fe4d}-\x{fe4f}\x{ff10}-\x{ff19}\x{ff3f}]*\b';
26
+
27
+	/**
28
+	 * Full list of JavaScript reserved words.
29
+	 * Will be loaded from /data/js/keywords_reserved.txt.
30
+	 *
31
+	 * @see https://mathiasbynens.be/notes/reserved-keywords
32
+	 *
33
+	 * @var string[]
34
+	 */
35
+	protected $keywordsReserved = array();
36
+
37
+	/**
38
+	 * List of JavaScript reserved words that accept a <variable, value, ...>
39
+	 * after them. Some end of lines are not the end of a statement, like with
40
+	 * these keywords.
41
+	 *
42
+	 * E.g.: we shouldn't insert a ; after this else
43
+	 * else
44
+	 *     console.log('this is quite fine')
45
+	 *
46
+	 * Will be loaded from /data/js/keywords_before.txt
47
+	 *
48
+	 * @var string[]
49
+	 */
50
+	protected $keywordsBefore = array();
51
+
52
+	/**
53
+	 * List of JavaScript reserved words that accept a <variable, value, ...>
54
+	 * before them. Some end of lines are not the end of a statement, like when
55
+	 * continued by one of these keywords on the newline.
56
+	 *
57
+	 * E.g.: we shouldn't insert a ; before this instanceof
58
+	 * variable
59
+	 *     instanceof String
60
+	 *
61
+	 * Will be loaded from /data/js/keywords_after.txt
62
+	 *
63
+	 * @var string[]
64
+	 */
65
+	protected $keywordsAfter = array();
66
+
67
+	/**
68
+	 * List of all JavaScript operators.
69
+	 *
70
+	 * Will be loaded from /data/js/operators.txt
71
+	 *
72
+	 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
73
+	 *
74
+	 * @var string[]
75
+	 */
76
+	protected $operators = array();
77
+
78
+	/**
79
+	 * List of JavaScript operators that accept a <variable, value, ...> after
80
+	 * them. Some end of lines are not the end of a statement, like with these
81
+	 * operators.
82
+	 *
83
+	 * Note: Most operators are fine, we've only removed !, ++ and --.
84
+	 * There can't be a newline separating ! and whatever it is negating.
85
+	 * ++ & -- have to be joined with the value they're in-/decrementing.
86
+	 *
87
+	 * Will be loaded from /data/js/operators_before.txt
88
+	 *
89
+	 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
90
+	 *
91
+	 * @var string[]
92
+	 */
93
+	protected $operatorsBefore = array();
94
+
95
+	/**
96
+	 * List of JavaScript operators that accept a <variable, value, ...> before
97
+	 * them. Some end of lines are not the end of a statement, like when
98
+	 * continued by one of these operators on the newline.
99
+	 *
100
+	 * Note: Most operators are fine, we've only removed ), ], ++ and --.
101
+	 * ++ & -- have to be joined with the value they're in-/decrementing.
102
+	 * ) & ] are "special" in that they have lots or usecases. () for example
103
+	 * is used for function calls, for grouping, in if () and for (), ...
104
+	 *
105
+	 * Will be loaded from /data/js/operators_after.txt
106
+	 *
107
+	 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
108
+	 *
109
+	 * @var string[]
110
+	 */
111
+	protected $operatorsAfter = array();
112
+
113
+	/**
114
+	 * {@inheritdoc}
115
+	 */
116
+	public function __construct()
117
+	{
118
+		call_user_func_array(array('parent', '__construct'), func_get_args());
119
+
120
+		$dataDir = __DIR__.'/../data/js/';
121
+		$options = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES;
122
+		$this->keywordsReserved = file($dataDir.'keywords_reserved.txt', $options);
123
+		$this->keywordsBefore = file($dataDir.'keywords_before.txt', $options);
124
+		$this->keywordsAfter = file($dataDir.'keywords_after.txt', $options);
125
+		$this->operators = file($dataDir.'operators.txt', $options);
126
+		$this->operatorsBefore = file($dataDir.'operators_before.txt', $options);
127
+		$this->operatorsAfter = file($dataDir.'operators_after.txt', $options);
128
+	}
129
+
130
+	/**
131
+	 * Minify the data.
132
+	 * Perform JS optimizations.
133
+	 *
134
+	 * @param string[optional] $path Path to write the data to
135
+	 *
136
+	 * @return string The minified data
137
+	 */
138
+	public function execute($path = null)
139
+	{
140
+		$content = '';
141
+
142
+		// loop files
143
+		foreach ($this->data as $source => $js) {
144
+			/*
145 145
              * Combine js: separating the scripts by a ;
146 146
              * I'm also adding a newline: it will be eaten when whitespace is
147 147
              * stripped, but we need to make sure we're not just appending
@@ -149,10 +149,10 @@  discard block
 block discarded – undo
149 149
              * singe-line comment on the last line (in which case it would also
150 150
              * be seen as part of that comment)
151 151
              */
152
-            $content .= $js."\n;";
153
-        }
152
+			$content .= $js."\n;";
153
+		}
154 154
 
155
-        /*
155
+		/*
156 156
          * Let's first take out strings, comments and regular expressions.
157 157
          * All of these can contain JS code-like characters, and we should make
158 158
          * sure any further magic ignores anything inside of these.
@@ -163,164 +163,164 @@  discard block
 block discarded – undo
163 163
          * Comments will be removed altogether, strings and regular expressions
164 164
          * will be replaced by placeholder text, which we'll restore later.
165 165
          */
166
-        $this->extractStrings('\'"`');
167
-        $this->stripComments();
168
-        $this->extractRegex();
169
-        $content = $this->replace($content);
166
+		$this->extractStrings('\'"`');
167
+		$this->stripComments();
168
+		$this->extractRegex();
169
+		$content = $this->replace($content);
170 170
 
171
-        $content = $this->propertyNotation($content);
172
-        $content = $this->shortenBools($content);
173
-        $content = $this->stripWhitespace($content);
171
+		$content = $this->propertyNotation($content);
172
+		$content = $this->shortenBools($content);
173
+		$content = $this->stripWhitespace($content);
174 174
 
175
-        /*
175
+		/*
176 176
          * Earlier, we extracted strings & regular expressions and replaced them
177 177
          * with placeholder text. This will restore them.
178 178
          */
179
-        $content = $this->restoreExtractedData($content);
180
-
181
-        return $content;
182
-    }
183
-
184
-    /**
185
-     * Strip comments from source code.
186
-     */
187
-    protected function stripComments()
188
-    {
189
-        // single-line comments
190
-        $this->registerPattern('/\/\/.*$/m', '');
191
-
192
-        // multi-line comments
193
-        $this->registerPattern('/\/\*.*?\*\//s', '');
194
-    }
195
-
196
-    /**
197
-     * JS can have /-delimited regular expressions, like: /ab+c/.match(string).
198
-     *
199
-     * The content inside the regex can contain characters that may be confused
200
-     * for JS code: e.g. it could contain whitespace it needs to match & we
201
-     * don't want to strip whitespace in there.
202
-     *
203
-     * The regex can be pretty simple: we don't have to care about comments,
204
-     * (which also use slashes) because stripComments() will have stripped those
205
-     * already.
206
-     *
207
-     * This method will replace all string content with simple REGEX#
208
-     * placeholder text, so we've rid all regular expressions from characters
209
-     * that may be misinterpreted. Original regex content will be saved in
210
-     * $this->extracted and after doing all other minifying, we can restore the
211
-     * original content via restoreRegex()
212
-     */
213
-    protected function extractRegex()
214
-    {
215
-        // PHP only supports $this inside anonymous functions since 5.4
216
-        $minifier = $this;
217
-        $callback = function ($match) use ($minifier) {
218
-            $count = count($minifier->extracted);
219
-            $placeholder = '/'.$count.'/';
220
-            $minifier->extracted[$placeholder] = $match[0];
221
-
222
-            return $placeholder;
223
-        };
224
-
225
-        $pattern = '\/.+?(?<!\\\\)(\\\\\\\\)*\/[gimy]*(?![0-9a-zA-Z\/])';
226
-
227
-        // a regular expression can only be followed by a few operators or some
228
-        // of the RegExp methods (a `\` followed by a variable or value is
229
-        // likely part of a division, not a regex)
230
-        $after = '[\.,;\)\}]';
231
-        $methods = '\.(exec|test|match|search|replace|split)\(';
232
-        $this->registerPattern('/'.$pattern.'(?=\s*('.$after.'|'.$methods.'))/', $callback);
233
-
234
-        // 1 more edge case: a regex can be followed by a lot more operators or
235
-        // keywords if there's a newline (ASI) in between, where the operator
236
-        // actually starts a new statement
237
-        // (https://github.com/matthiasmullie/minify/issues/56)
238
-        $operators = $this->getOperatorsForRegex($this->operatorsBefore, '/');
239
-        $operators += $this->getOperatorsForRegex($this->keywordsReserved, '/');
240
-        $this->registerPattern('/'.$pattern.'\s*\n(?=\s*('.implode('|', $operators).'))/', $callback);
241
-    }
242
-
243
-    /**
244
-     * Strip whitespace.
245
-     *
246
-     * We won't strip *all* whitespace, but as much as possible. The thing that
247
-     * we'll preserve are newlines we're unsure about.
248
-     * JavaScript doesn't require statements to be terminated with a semicolon.
249
-     * It will automatically fix missing semicolons with ASI (automatic semi-
250
-     * colon insertion) at the end of line causing errors (without semicolon.)
251
-     *
252
-     * Because it's sometimes hard to tell if a newline is part of a statement
253
-     * that should be terminated or not, we'll just leave some of them alone.
254
-     *
255
-     * @param string $content The content to strip the whitespace for
256
-     *
257
-     * @return string
258
-     */
259
-    protected function stripWhitespace($content)
260
-    {
261
-        // uniform line endings, make them all line feed
262
-        $content = str_replace(array("\r\n", "\r"), "\n", $content);
263
-
264
-        // collapse all non-line feed whitespace into a single space
265
-        $content = preg_replace('/[^\S\n]+/', ' ', $content);
266
-
267
-        // strip leading & trailing whitespace
268
-        $content = str_replace(array(" \n", "\n "), "\n", $content);
269
-
270
-        // collapse consecutive line feeds into just 1
271
-        $content = preg_replace('/\n+/', "\n", $content);
272
-
273
-        $operatorsBefore = $this->getOperatorsForRegex($this->operatorsBefore, '/');
274
-        $operatorsAfter = $this->getOperatorsForRegex($this->operatorsAfter, '/');
275
-        $operators = $this->getOperatorsForRegex($this->operators, '/');
276
-        $keywordsBefore = $this->getKeywordsForRegex($this->keywordsBefore, '/');
277
-        $keywordsAfter = $this->getKeywordsForRegex($this->keywordsAfter, '/');
278
-
279
-        // strip whitespace that ends in (or next line begin with) an operator
280
-        // that allows statements to be broken up over multiple lines
281
-        unset($operatorsBefore['+'], $operatorsBefore['-'], $operatorsAfter['+'], $operatorsAfter['-']);
282
-        $content = preg_replace(
283
-            array(
284
-                '/('.implode('|', $operatorsBefore).')\s+/',
285
-                '/\s+('.implode('|', $operatorsAfter).')/',
286
-            ), '\\1', $content
287
-        );
288
-
289
-        // make sure + and - can't be mistaken for, or joined into ++ and --
290
-        $content = preg_replace(
291
-            array(
292
-                '/(?<![\+\-])\s*([\+\-])(?![\+\-])/',
293
-                '/(?<![\+\-])([\+\-])\s*(?![\+\-])/',
294
-            ), '\\1', $content
295
-        );
296
-
297
-        // collapse whitespace around reserved words into single space
298
-        $content = preg_replace('/(^|[;\}\s])\K('.implode('|', $keywordsBefore).')\s+/', '\\2 ', $content);
299
-        $content = preg_replace('/\s+('.implode('|', $keywordsAfter).')(?=([;\{\s]|$))/', ' \\1', $content);
300
-
301
-        /*
179
+		$content = $this->restoreExtractedData($content);
180
+
181
+		return $content;
182
+	}
183
+
184
+	/**
185
+	 * Strip comments from source code.
186
+	 */
187
+	protected function stripComments()
188
+	{
189
+		// single-line comments
190
+		$this->registerPattern('/\/\/.*$/m', '');
191
+
192
+		// multi-line comments
193
+		$this->registerPattern('/\/\*.*?\*\//s', '');
194
+	}
195
+
196
+	/**
197
+	 * JS can have /-delimited regular expressions, like: /ab+c/.match(string).
198
+	 *
199
+	 * The content inside the regex can contain characters that may be confused
200
+	 * for JS code: e.g. it could contain whitespace it needs to match & we
201
+	 * don't want to strip whitespace in there.
202
+	 *
203
+	 * The regex can be pretty simple: we don't have to care about comments,
204
+	 * (which also use slashes) because stripComments() will have stripped those
205
+	 * already.
206
+	 *
207
+	 * This method will replace all string content with simple REGEX#
208
+	 * placeholder text, so we've rid all regular expressions from characters
209
+	 * that may be misinterpreted. Original regex content will be saved in
210
+	 * $this->extracted and after doing all other minifying, we can restore the
211
+	 * original content via restoreRegex()
212
+	 */
213
+	protected function extractRegex()
214
+	{
215
+		// PHP only supports $this inside anonymous functions since 5.4
216
+		$minifier = $this;
217
+		$callback = function ($match) use ($minifier) {
218
+			$count = count($minifier->extracted);
219
+			$placeholder = '/'.$count.'/';
220
+			$minifier->extracted[$placeholder] = $match[0];
221
+
222
+			return $placeholder;
223
+		};
224
+
225
+		$pattern = '\/.+?(?<!\\\\)(\\\\\\\\)*\/[gimy]*(?![0-9a-zA-Z\/])';
226
+
227
+		// a regular expression can only be followed by a few operators or some
228
+		// of the RegExp methods (a `\` followed by a variable or value is
229
+		// likely part of a division, not a regex)
230
+		$after = '[\.,;\)\}]';
231
+		$methods = '\.(exec|test|match|search|replace|split)\(';
232
+		$this->registerPattern('/'.$pattern.'(?=\s*('.$after.'|'.$methods.'))/', $callback);
233
+
234
+		// 1 more edge case: a regex can be followed by a lot more operators or
235
+		// keywords if there's a newline (ASI) in between, where the operator
236
+		// actually starts a new statement
237
+		// (https://github.com/matthiasmullie/minify/issues/56)
238
+		$operators = $this->getOperatorsForRegex($this->operatorsBefore, '/');
239
+		$operators += $this->getOperatorsForRegex($this->keywordsReserved, '/');
240
+		$this->registerPattern('/'.$pattern.'\s*\n(?=\s*('.implode('|', $operators).'))/', $callback);
241
+	}
242
+
243
+	/**
244
+	 * Strip whitespace.
245
+	 *
246
+	 * We won't strip *all* whitespace, but as much as possible. The thing that
247
+	 * we'll preserve are newlines we're unsure about.
248
+	 * JavaScript doesn't require statements to be terminated with a semicolon.
249
+	 * It will automatically fix missing semicolons with ASI (automatic semi-
250
+	 * colon insertion) at the end of line causing errors (without semicolon.)
251
+	 *
252
+	 * Because it's sometimes hard to tell if a newline is part of a statement
253
+	 * that should be terminated or not, we'll just leave some of them alone.
254
+	 *
255
+	 * @param string $content The content to strip the whitespace for
256
+	 *
257
+	 * @return string
258
+	 */
259
+	protected function stripWhitespace($content)
260
+	{
261
+		// uniform line endings, make them all line feed
262
+		$content = str_replace(array("\r\n", "\r"), "\n", $content);
263
+
264
+		// collapse all non-line feed whitespace into a single space
265
+		$content = preg_replace('/[^\S\n]+/', ' ', $content);
266
+
267
+		// strip leading & trailing whitespace
268
+		$content = str_replace(array(" \n", "\n "), "\n", $content);
269
+
270
+		// collapse consecutive line feeds into just 1
271
+		$content = preg_replace('/\n+/', "\n", $content);
272
+
273
+		$operatorsBefore = $this->getOperatorsForRegex($this->operatorsBefore, '/');
274
+		$operatorsAfter = $this->getOperatorsForRegex($this->operatorsAfter, '/');
275
+		$operators = $this->getOperatorsForRegex($this->operators, '/');
276
+		$keywordsBefore = $this->getKeywordsForRegex($this->keywordsBefore, '/');
277
+		$keywordsAfter = $this->getKeywordsForRegex($this->keywordsAfter, '/');
278
+
279
+		// strip whitespace that ends in (or next line begin with) an operator
280
+		// that allows statements to be broken up over multiple lines
281
+		unset($operatorsBefore['+'], $operatorsBefore['-'], $operatorsAfter['+'], $operatorsAfter['-']);
282
+		$content = preg_replace(
283
+			array(
284
+				'/('.implode('|', $operatorsBefore).')\s+/',
285
+				'/\s+('.implode('|', $operatorsAfter).')/',
286
+			), '\\1', $content
287
+		);
288
+
289
+		// make sure + and - can't be mistaken for, or joined into ++ and --
290
+		$content = preg_replace(
291
+			array(
292
+				'/(?<![\+\-])\s*([\+\-])(?![\+\-])/',
293
+				'/(?<![\+\-])([\+\-])\s*(?![\+\-])/',
294
+			), '\\1', $content
295
+		);
296
+
297
+		// collapse whitespace around reserved words into single space
298
+		$content = preg_replace('/(^|[;\}\s])\K('.implode('|', $keywordsBefore).')\s+/', '\\2 ', $content);
299
+		$content = preg_replace('/\s+('.implode('|', $keywordsAfter).')(?=([;\{\s]|$))/', ' \\1', $content);
300
+
301
+		/*
302 302
          * We didn't strip whitespace after a couple of operators because they
303 303
          * could be used in different contexts and we can't be sure it's ok to
304 304
          * strip the newlines. However, we can safely strip any non-line feed
305 305
          * whitespace that follows them.
306 306
          */
307
-        $operatorsDiffBefore = array_diff($operators, $operatorsBefore);
308
-        $operatorsDiffAfter = array_diff($operators, $operatorsAfter);
309
-        $content = preg_replace('/('.implode('|', $operatorsDiffBefore).')[^\S\n]+/', '\\1', $content);
310
-        $content = preg_replace('/[^\S\n]+('.implode('|', $operatorsDiffAfter).')/', '\\1', $content);
307
+		$operatorsDiffBefore = array_diff($operators, $operatorsBefore);
308
+		$operatorsDiffAfter = array_diff($operators, $operatorsAfter);
309
+		$content = preg_replace('/('.implode('|', $operatorsDiffBefore).')[^\S\n]+/', '\\1', $content);
310
+		$content = preg_replace('/[^\S\n]+('.implode('|', $operatorsDiffAfter).')/', '\\1', $content);
311 311
 
312
-        /*
312
+		/*
313 313
          * Get rid of double semicolons, except where they can be used like:
314 314
          * "for(v=1,_=b;;)", "for(v=1;;v++)" or "for(;;ja||(ja=true))".
315 315
          * I'll safeguard these double semicolons inside for-loops by
316 316
          * temporarily replacing them with an invalid condition: they won't have
317 317
          * a double semicolon and will be easy to spot to restore afterwards.
318 318
          */
319
-        $content = preg_replace('/\bfor\(([^;]*);;([^;]*)\)/', 'for(\\1;-;\\2)', $content);
320
-        $content = preg_replace('/;+/', ';', $content);
321
-        $content = preg_replace('/\bfor\(([^;]*);-;([^;]*)\)/', 'for(\\1;;\\2)', $content);
319
+		$content = preg_replace('/\bfor\(([^;]*);;([^;]*)\)/', 'for(\\1;-;\\2)', $content);
320
+		$content = preg_replace('/;+/', ';', $content);
321
+		$content = preg_replace('/\bfor\(([^;]*);-;([^;]*)\)/', 'for(\\1;;\\2)', $content);
322 322
 
323
-        /*
323
+		/*
324 324
          * Next, we'll be removing all semicolons where ASI kicks in.
325 325
          * for-loops however, can have an empty body (ending in only a
326 326
          * semicolon), like: `for(i=1;i<3;i++);`
@@ -330,9 +330,9 @@  discard block
 block discarded – undo
330 330
          * I'm going to double that semicolon (if any) so after the next line,
331 331
          * which strips semicolons here & there, we're still left with this one.
332 332
          */
333
-        $content = preg_replace('/(for\([^;]*;[^;]*;[^;\{]*\));(\}|$)/s', '\\1;;\\2', $content);
333
+		$content = preg_replace('/(for\([^;]*;[^;]*;[^;\{]*\));(\}|$)/s', '\\1;;\\2', $content);
334 334
 
335
-        /*
335
+		/*
336 336
          * We also can't strip empty else-statements. Even though they're
337 337
          * useless and probably shouldn't be in the code in the first place, we
338 338
          * shouldn't be stripping the `;` that follows it as it breaks the code.
@@ -340,114 +340,114 @@  discard block
 block discarded – undo
340 340
          *
341 341
          * @see https://github.com/matthiasmullie/minify/issues/91
342 342
          */
343
-        $content = preg_replace('/else;/s', '', $content);
343
+		$content = preg_replace('/else;/s', '', $content);
344 344
 
345
-        /*
345
+		/*
346 346
          * We also don't really want to terminate statements followed by closing
347 347
          * curly braces (which we've ignored completely up until now) or end-of-
348 348
          * script: ASI will kick in here & we're all about minifying.
349 349
          * Semicolons at beginning of the file don't make any sense either.
350 350
          */
351
-        $content = preg_replace('/;(\}|$)/s', '\\1', $content);
352
-        $content = ltrim($content, ';');
353
-
354
-        // get rid of remaining whitespace af beginning/end
355
-        return trim($content);
356
-    }
357
-
358
-    /**
359
-     * We'll strip whitespace around certain operators with regular expressions.
360
-     * This will prepare the given array by escaping all characters.
361
-     *
362
-     * @param string[] $operators
363
-     * @param string   $delimiter
364
-     *
365
-     * @return string[]
366
-     */
367
-    protected function getOperatorsForRegex(array $operators, $delimiter = '/')
368
-    {
369
-        // escape operators for use in regex
370
-        $delimiter = array_fill(0, count($operators), $delimiter);
371
-        $escaped = array_map('preg_quote', $operators, $delimiter);
372
-
373
-        $operators = array_combine($operators, $escaped);
374
-
375
-        // ignore + & - for now, they'll get special treatment
376
-        unset($operators['+'], $operators['-']);
377
-
378
-        // dot can not just immediately follow a number; it can be confused for
379
-        // decimal point, or calling a method on it, e.g. 42 .toString()
380
-        $operators['.'] = '(?<![0-9]\s)\.';
381
-
382
-        // don't confuse = with other assignment shortcuts (e.g. +=)
383
-        $chars = preg_quote('+-*\=<>%&|');
384
-        $operators['='] = '(?<!['.$chars.'])\=';
385
-
386
-        return $operators;
387
-    }
388
-
389
-    /**
390
-     * We'll strip whitespace around certain keywords with regular expressions.
391
-     * This will prepare the given array by escaping all characters.
392
-     *
393
-     * @param string[] $keywords
394
-     * @param string   $delimiter
395
-     *
396
-     * @return string[]
397
-     */
398
-    protected function getKeywordsForRegex(array $keywords, $delimiter = '/')
399
-    {
400
-        // escape keywords for use in regex
401
-        $delimiter = array_fill(0, count($keywords), $delimiter);
402
-        $escaped = array_map('preg_quote', $keywords, $delimiter);
403
-
404
-        // add word boundaries
405
-        array_walk($keywords, function ($value) {
406
-            return '\b'.$value.'\b';
407
-        });
408
-
409
-        $keywords = array_combine($keywords, $escaped);
410
-
411
-        return $keywords;
412
-    }
413
-
414
-    /**
415
-     * Replaces all occurrences of array['key'] by array.key.
416
-     *
417
-     * @param string $content
418
-     *
419
-     * @return string
420
-     */
421
-    protected function propertyNotation($content)
422
-    {
423
-        // PHP only supports $this inside anonymous functions since 5.4
424
-        $minifier = $this;
425
-        $keywords = $this->keywordsReserved;
426
-        $callback = function ($match) use ($minifier, $keywords) {
427
-            $property = trim($minifier->extracted[$match[1]], '\'"');
428
-
429
-            /*
351
+		$content = preg_replace('/;(\}|$)/s', '\\1', $content);
352
+		$content = ltrim($content, ';');
353
+
354
+		// get rid of remaining whitespace af beginning/end
355
+		return trim($content);
356
+	}
357
+
358
+	/**
359
+	 * We'll strip whitespace around certain operators with regular expressions.
360
+	 * This will prepare the given array by escaping all characters.
361
+	 *
362
+	 * @param string[] $operators
363
+	 * @param string   $delimiter
364
+	 *
365
+	 * @return string[]
366
+	 */
367
+	protected function getOperatorsForRegex(array $operators, $delimiter = '/')
368
+	{
369
+		// escape operators for use in regex
370
+		$delimiter = array_fill(0, count($operators), $delimiter);
371
+		$escaped = array_map('preg_quote', $operators, $delimiter);
372
+
373
+		$operators = array_combine($operators, $escaped);
374
+
375
+		// ignore + & - for now, they'll get special treatment
376
+		unset($operators['+'], $operators['-']);
377
+
378
+		// dot can not just immediately follow a number; it can be confused for
379
+		// decimal point, or calling a method on it, e.g. 42 .toString()
380
+		$operators['.'] = '(?<![0-9]\s)\.';
381
+
382
+		// don't confuse = with other assignment shortcuts (e.g. +=)
383
+		$chars = preg_quote('+-*\=<>%&|');
384
+		$operators['='] = '(?<!['.$chars.'])\=';
385
+
386
+		return $operators;
387
+	}
388
+
389
+	/**
390
+	 * We'll strip whitespace around certain keywords with regular expressions.
391
+	 * This will prepare the given array by escaping all characters.
392
+	 *
393
+	 * @param string[] $keywords
394
+	 * @param string   $delimiter
395
+	 *
396
+	 * @return string[]
397
+	 */
398
+	protected function getKeywordsForRegex(array $keywords, $delimiter = '/')
399
+	{
400
+		// escape keywords for use in regex
401
+		$delimiter = array_fill(0, count($keywords), $delimiter);
402
+		$escaped = array_map('preg_quote', $keywords, $delimiter);
403
+
404
+		// add word boundaries
405
+		array_walk($keywords, function ($value) {
406
+			return '\b'.$value.'\b';
407
+		});
408
+
409
+		$keywords = array_combine($keywords, $escaped);
410
+
411
+		return $keywords;
412
+	}
413
+
414
+	/**
415
+	 * Replaces all occurrences of array['key'] by array.key.
416
+	 *
417
+	 * @param string $content
418
+	 *
419
+	 * @return string
420
+	 */
421
+	protected function propertyNotation($content)
422
+	{
423
+		// PHP only supports $this inside anonymous functions since 5.4
424
+		$minifier = $this;
425
+		$keywords = $this->keywordsReserved;
426
+		$callback = function ($match) use ($minifier, $keywords) {
427
+			$property = trim($minifier->extracted[$match[1]], '\'"');
428
+
429
+			/*
430 430
              * Check if the property is a reserved keyword. In this context (as
431 431
              * property of an object literal/array) it shouldn't matter, but IE8
432 432
              * freaks out with "Expected identifier".
433 433
              */
434
-            if (in_array($property, $keywords)) {
435
-                return $match[0];
436
-            }
434
+			if (in_array($property, $keywords)) {
435
+				return $match[0];
436
+			}
437 437
 
438
-            /*
438
+			/*
439 439
              * See if the property is in a variable-like format (e.g.
440 440
              * array['key-here'] can't be replaced by array.key-here since '-'
441 441
              * is not a valid character there.
442 442
              */
443
-            if (!preg_match('/^'.$minifier::REGEX_VARIABLE.'$/u', $property)) {
444
-                return $match[0];
445
-            }
443
+			if (!preg_match('/^'.$minifier::REGEX_VARIABLE.'$/u', $property)) {
444
+				return $match[0];
445
+			}
446 446
 
447
-            return '.'.$property;
448
-        };
447
+			return '.'.$property;
448
+		};
449 449
 
450
-        /*
450
+		/*
451 451
          * Figure out if previous character is a variable name (of the array
452 452
          * we want to use property notation on) - this is to make sure
453 453
          * standalone ['value'] arrays aren't confused for keys-of-an-array.
@@ -455,61 +455,61 @@  discard block
 block discarded – undo
455 455
          * regex implementation doesn't allow unfixed-length look-behind
456 456
          * assertions.
457 457
          */
458
-        preg_match('/(\[[^\]]+\])[^\]]*$/', static::REGEX_VARIABLE, $previousChar);
459
-        $previousChar = $previousChar[1];
458
+		preg_match('/(\[[^\]]+\])[^\]]*$/', static::REGEX_VARIABLE, $previousChar);
459
+		$previousChar = $previousChar[1];
460 460
 
461
-        /*
461
+		/*
462 462
          * Make sure word preceding the ['value'] is not a keyword, e.g.
463 463
          * return['x']. Because -again- PHP's regex implementation doesn't allow
464 464
          * unfixed-length look-behind assertions, I'm just going to do a lot of
465 465
          * separate look-behind assertions, one for each keyword.
466 466
          */
467
-        $keywords = $this->getKeywordsForRegex($keywords);
468
-        $keywords = '(?<!'.implode(')(?<!', $keywords).')';
469
-
470
-        return preg_replace_callback('/(?<='.$previousChar.'|\])'.$keywords.'\[\s*(([\'"])[0-9]+\\2)\s*\]/u', $callback, $content);
471
-    }
472
-
473
-    /**
474
-     * Replaces true & false by !0 and !1.
475
-     *
476
-     * @param string $content
477
-     *
478
-     * @return string
479
-     */
480
-    protected function shortenBools($content)
481
-    {
482
-        $content = preg_replace('/\btrue\b(?!:)/', '!0', $content);
483
-        $content = preg_replace('/\bfalse\b(?!:)/', '!1', $content);
484
-
485
-        // for(;;) is exactly the same as while(true)
486
-        $content = preg_replace('/\bwhile\(!0\){/', 'for(;;){', $content);
487
-
488
-        // now make sure we didn't turn any do ... while(true) into do ... for(;;)
489
-        preg_match_all('/\bdo\b/', $content, $dos, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
490
-
491
-        // go backward to make sure positional offsets aren't altered when $content changes
492
-        $dos = array_reverse($dos);
493
-        foreach ($dos as $do) {
494
-            $offsetDo = $do[0][1];
495
-
496
-            // find all `while` (now `for`) following `do`: one of those must be
497
-            // associated with the `do` and be turned back into `while`
498
-            preg_match_all('/\bfor\(;;\)/', $content, $whiles, PREG_OFFSET_CAPTURE | PREG_SET_ORDER, $offsetDo);
499
-            foreach ($whiles as $while) {
500
-                $offsetWhile = $while[0][1];
501
-
502
-                $open = substr_count($content, '{', $offsetDo, $offsetWhile - $offsetDo);
503
-                $close = substr_count($content, '}', $offsetDo, $offsetWhile - $offsetDo);
504
-                if ($open === $close) {
505
-                    // only restore `while` if amount of `{` and `}` are the same;
506
-                    // otherwise, that `for` isn't associated with this `do`
507
-                    $content = substr_replace($content, 'while(!0)', $offsetWhile, strlen('for(;;)'));
508
-                    break;
509
-                }
510
-            }
511
-        }
512
-
513
-        return $content;
514
-    }
467
+		$keywords = $this->getKeywordsForRegex($keywords);
468
+		$keywords = '(?<!'.implode(')(?<!', $keywords).')';
469
+
470
+		return preg_replace_callback('/(?<='.$previousChar.'|\])'.$keywords.'\[\s*(([\'"])[0-9]+\\2)\s*\]/u', $callback, $content);
471
+	}
472
+
473
+	/**
474
+	 * Replaces true & false by !0 and !1.
475
+	 *
476
+	 * @param string $content
477
+	 *
478
+	 * @return string
479
+	 */
480
+	protected function shortenBools($content)
481
+	{
482
+		$content = preg_replace('/\btrue\b(?!:)/', '!0', $content);
483
+		$content = preg_replace('/\bfalse\b(?!:)/', '!1', $content);
484
+
485
+		// for(;;) is exactly the same as while(true)
486
+		$content = preg_replace('/\bwhile\(!0\){/', 'for(;;){', $content);
487
+
488
+		// now make sure we didn't turn any do ... while(true) into do ... for(;;)
489
+		preg_match_all('/\bdo\b/', $content, $dos, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
490
+
491
+		// go backward to make sure positional offsets aren't altered when $content changes
492
+		$dos = array_reverse($dos);
493
+		foreach ($dos as $do) {
494
+			$offsetDo = $do[0][1];
495
+
496
+			// find all `while` (now `for`) following `do`: one of those must be
497
+			// associated with the `do` and be turned back into `while`
498
+			preg_match_all('/\bfor\(;;\)/', $content, $whiles, PREG_OFFSET_CAPTURE | PREG_SET_ORDER, $offsetDo);
499
+			foreach ($whiles as $while) {
500
+				$offsetWhile = $while[0][1];
501
+
502
+				$open = substr_count($content, '{', $offsetDo, $offsetWhile - $offsetDo);
503
+				$close = substr_count($content, '}', $offsetDo, $offsetWhile - $offsetDo);
504
+				if ($open === $close) {
505
+					// only restore `while` if amount of `{` and `}` are the same;
506
+					// otherwise, that `for` isn't associated with this `do`
507
+					$content = substr_replace($content, 'while(!0)', $offsetWhile, strlen('for(;;)'));
508
+					break;
509
+				}
510
+			}
511
+		}
512
+
513
+		return $content;
514
+	}
515 515
 }
Please login to merge, or discard this patch.
Sources/Subscriptions-PayPal.php 1 patch
Braces   +83 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
 // This won't be dedicated without this - this must exist in each gateway!
15 15
 // SMF Payment Gateway: paypal
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Class for returning available form data for this gateway
@@ -118,8 +119,7 @@  discard block
 block discarded – undo
118 119
 		{
119 120
 			$return_data['hidden']['p3'] = 1;
120 121
 			$return_data['hidden']['t3'] = strtoupper(substr($period, 0, 1));
121
-		}
122
-		else
122
+		} else
123 123
 		{
124 124
 			preg_match('~(\d*)(\w)~', $sub_data['real_length'], $match);
125 125
 			$unit = $match[1];
@@ -130,14 +130,15 @@  discard block
 block discarded – undo
130 130
 		}
131 131
 
132 132
 		// If it's repeatable do some javascript to respect this idea.
133
-		if (!empty($sub_data['repeatable']))
134
-			$return_data['javascript'] = '
133
+		if (!empty($sub_data['repeatable'])) {
134
+					$return_data['javascript'] = '
135 135
 				document.write(\'<label for="do_paypal_recur"><input type="checkbox" name="do_paypal_recur" id="do_paypal_recur" checked onclick="switchPaypalRecur();" class="input_check">' . $txt['paid_make_recurring'] . '</label><br>\');
136 136
 
137 137
 				function switchPaypalRecur()
138 138
 				{
139 139
 					document.getElementById("paypal_cmd").value = document.getElementById("do_paypal_recur").checked ? "_xclick-subscriptions" : "_xclick";
140 140
 				}';
141
+		}
141 142
 
142 143
 		return $return_data;
143 144
 	}
@@ -160,20 +161,24 @@  discard block
 block discarded – undo
160 161
 		global $modSettings;
161 162
 
162 163
 		// Has the user set up an email address?
163
-		if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email'])))
164
-			return false;
164
+		if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email']))) {
165
+					return false;
166
+		}
165 167
 		// Check the correct transaction types are even here.
166
-		if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email'])))
167
-			return false;
168
+		if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email']))) {
169
+					return false;
170
+		}
168 171
 		// Correct email address?
169
-		if (!isset($_POST['business']))
170
-			$_POST['business'] = $_POST['receiver_email'];
172
+		if (!isset($_POST['business'])) {
173
+					$_POST['business'] = $_POST['receiver_email'];
174
+		}
171 175
 
172 176
 		// Are we testing?
173
-		if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails'])))))
174
-			return false;
175
-		elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails']))))
176
-			return false;
177
+		if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) {
178
+					return false;
179
+		} elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails'])))) {
180
+					return false;
181
+		}
177 182
 		return true;
178 183
 	}
179 184
 
@@ -192,15 +197,17 @@  discard block
 block discarded – undo
192 197
 		global $modSettings, $txt;
193 198
 
194 199
 		// Put this to some default value.
195
-		if (!isset($_POST['txn_type']))
196
-			$_POST['txn_type'] = '';
200
+		if (!isset($_POST['txn_type'])) {
201
+					$_POST['txn_type'] = '';
202
+		}
197 203
 
198 204
 		// Build the request string - starting with the minimum requirement.
199 205
 		$requestString = 'cmd=_notify-validate';
200 206
 
201 207
 		// Now my dear, add all the posted bits in the order we got them
202
-		foreach ($_POST as $k => $v)
203
-			$requestString .= '&' . $k . '=' . urlencode($v);
208
+		foreach ($_POST as $k => $v) {
209
+					$requestString .= '&' . $k . '=' . urlencode($v);
210
+		}
204 211
 
205 212
 		// Can we use curl?
206 213
 		if (function_exists('curl_init') && $curl = curl_init((!empty($modSettings['paidsubs_test']) ? 'https://www.sandbox.' : 'https://www.') . 'paypal.com/cgi-bin/webscr'))
@@ -240,14 +247,16 @@  discard block
 block discarded – undo
240 247
 			$header .= 'Connection: close' . "\r\n\r\n";
241 248
 
242 249
 			// Open the connection.
243
-			if (!empty($modSettings['paidsubs_test']))
244
-				$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
245
-			else
246
-				$fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
250
+			if (!empty($modSettings['paidsubs_test'])) {
251
+							$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
252
+			} else {
253
+							$fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
254
+			}
247 255
 
248 256
 			// Did it work?
249
-			if (!$fp)
250
-				generateSubscriptionError($txt['paypal_could_not_connect']);
257
+			if (!$fp) {
258
+							generateSubscriptionError($txt['paypal_could_not_connect']);
259
+			}
251 260
 
252 261
 			// Put the data to the port.
253 262
 			fputs($fp, $header . $requestString);
@@ -256,8 +265,9 @@  discard block
 block discarded – undo
256 265
 			while (!feof($fp))
257 266
 			{
258 267
 				$this->return_data = fgets($fp, 1024);
259
-				if (strcmp(trim($this->return_data), 'VERIFIED') === 0)
260
-					break;
268
+				if (strcmp(trim($this->return_data), 'VERIFIED') === 0) {
269
+									break;
270
+				}
261 271
 			}
262 272
 
263 273
 			// Clean up.
@@ -265,28 +275,34 @@  discard block
 block discarded – undo
265 275
 		}
266 276
 
267 277
 		// If this isn't verified then give up...
268
-		if (strcmp(trim($this->return_data), 'VERIFIED') !== 0)
269
-			exit;
278
+		if (strcmp(trim($this->return_data), 'VERIFIED') !== 0) {
279
+					exit;
280
+		}
270 281
 
271 282
 		// Check that this is intended for us.
272
-		if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails'])))))
273
-			exit;
283
+		if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) {
284
+					exit;
285
+		}
274 286
 
275 287
 		// Is this a subscription - and if so is it a secondary payment that we need to process?
276 288
 		// If so, make sure we get it in the expected format. Seems PayPal sometimes sends it without urlencoding.
277
-		if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false)
278
-			$_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']);
279
-		if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false))
280
-			// Calculate the subscription it relates to!
289
+		if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false) {
290
+					$_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']);
291
+		}
292
+		if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false)) {
293
+					// Calculate the subscription it relates to!
281 294
 			$this->_findSubscription();
295
+		}
282 296
 
283 297
 		// Verify the currency!
284
-		if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code']))
285
-			exit;
298
+		if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code'])) {
299
+					exit;
300
+		}
286 301
 
287 302
 		// Can't exist if it doesn't contain anything.
288
-		if (empty($_POST['item_number']))
289
-			exit;
303
+		if (empty($_POST['item_number'])) {
304
+					exit;
305
+		}
290 306
 
291 307
 		// Return the id_sub and id_member
292 308
 		return explode('+', $_POST['item_number']);
@@ -299,10 +315,11 @@  discard block
 block discarded – undo
299 315
 	 */
300 316
 	public function isRefund()
301 317
 	{
302
-		if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed'))
303
-			return true;
304
-		else
305
-			return false;
318
+		if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed')) {
319
+					return true;
320
+		} else {
321
+					return false;
322
+		}
306 323
 	}
307 324
 
308 325
 	/**
@@ -312,10 +329,11 @@  discard block
 block discarded – undo
312 329
 	 */
313 330
 	public function isSubscription()
314 331
 	{
315
-		if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed')
316
-			return true;
317
-		else
318
-			return false;
332
+		if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed') {
333
+					return true;
334
+		} else {
335
+					return false;
336
+		}
319 337
 	}
320 338
 
321 339
 	/**
@@ -325,10 +343,11 @@  discard block
 block discarded – undo
325 343
 	 */
326 344
 	public function isPayment()
327 345
 	{
328
-		if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept')
329
-			return true;
330
-		else
331
-			return false;
346
+		if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept') {
347
+					return true;
348
+		} else {
349
+					return false;
350
+		}
332 351
 	}
333 352
 
334 353
 	/**
@@ -341,10 +360,11 @@  discard block
 block discarded – undo
341 360
 		// subscr_cancel is sent when the user cancels, subscr_eot is sent when the subscription reaches final payment
342 361
 		// Neither require us to *do* anything as per performCancel().
343 362
 		// subscr_eot, if sent, indicates an end of payments term.
344
-		if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot')
345
-			return true;
346
-		else
347
-			return false;
363
+		if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot') {
364
+					return true;
365
+		} else {
366
+					return false;
367
+		}
348 368
 	}
349 369
 
350 370
 	/**
@@ -409,8 +429,9 @@  discard block
 block discarded – undo
409 429
 		global $smcFunc;
410 430
 
411 431
 		// Assume we have this?
412
-		if (empty($_POST['subscr_id']))
413
-			return false;
432
+		if (empty($_POST['subscr_id'])) {
433
+					return false;
434
+		}
414 435
 
415 436
 		// Do we have this in the database?
416 437
 		$request = $smcFunc['db_query']('', '
@@ -439,11 +460,12 @@  discard block
 block discarded – undo
439 460
 						'payer_email' => $_POST['payer_email'],
440 461
 					)
441 462
 				);
442
-				if ($smcFunc['db_num_rows']($request) === 0)
443
-					return false;
463
+				if ($smcFunc['db_num_rows']($request) === 0) {
464
+									return false;
465
+				}
466
+			} else {
467
+							return false;
444 468
 			}
445
-			else
446
-				return false;
447 469
 		}
448 470
 		list ($member_id, $subscription_id) = $smcFunc['db_fetch_row']($request);
449 471
 		$_POST['item_number'] = $member_id . '+' . $subscription_id;
Please login to merge, or discard this patch.
Sources/Subs-Package.php 1 patch
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
 {
@@ -3255,7 +3255,7 @@  discard block
 block discarded – undo
3255 3255
 	 * https://php.net/crc32#79567
3256 3256
 	 *
3257 3257
 	 * @param string $number
3258
-	 * @return string The crc32
3258
+	 * @return integer The crc32
3259 3259
 	 */
3260 3260
 	function smf_crc32($number)
3261 3261
 	{
Please login to merge, or discard this patch.
Sources/ReCaptcha/RequestMethod/Curl.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -32,43 +32,43 @@
 block discarded – undo
32 32
 class Curl
33 33
 {
34 34
 
35
-    /**
36
-     * @see https://php.net/curl_init
37
-     * @param string $url
38
-     * @return resource cURL handle
39
-     */
40
-    public function init($url = null)
41
-    {
42
-        return curl_init($url);
43
-    }
35
+	/**
36
+	 * @see https://php.net/curl_init
37
+	 * @param string $url
38
+	 * @return resource cURL handle
39
+	 */
40
+	public function init($url = null)
41
+	{
42
+		return curl_init($url);
43
+	}
44 44
 
45
-    /**
46
-     * @see https://php.net/curl_setopt_array
47
-     * @param resource $ch
48
-     * @param array $options
49
-     * @return bool
50
-     */
51
-    public function setoptArray($ch, array $options)
52
-    {
53
-        return curl_setopt_array($ch, $options);
54
-    }
45
+	/**
46
+	 * @see https://php.net/curl_setopt_array
47
+	 * @param resource $ch
48
+	 * @param array $options
49
+	 * @return bool
50
+	 */
51
+	public function setoptArray($ch, array $options)
52
+	{
53
+		return curl_setopt_array($ch, $options);
54
+	}
55 55
 
56
-    /**
57
-     * @see https://php.net/curl_exec
58
-     * @param resource $ch
59
-     * @return mixed
60
-     */
61
-    public function exec($ch)
62
-    {
63
-        return curl_exec($ch);
64
-    }
56
+	/**
57
+	 * @see https://php.net/curl_exec
58
+	 * @param resource $ch
59
+	 * @return mixed
60
+	 */
61
+	public function exec($ch)
62
+	{
63
+		return curl_exec($ch);
64
+	}
65 65
 
66
-    /**
67
-     * @see https://php.net/curl_close
68
-     * @param resource $ch
69
-     */
70
-    public function close($ch)
71
-    {
72
-        curl_close($ch);
73
-    }
66
+	/**
67
+	 * @see https://php.net/curl_close
68
+	 * @param resource $ch
69
+	 */
70
+	public function close($ch)
71
+	{
72
+		curl_close($ch);
73
+	}
74 74
 }
Please login to merge, or discard this patch.