Completed
Pull Request — release-2.1 (#4985)
by Fran
06:10
created
other/install.php 2 patches
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1697,8 +1697,7 @@  discard block
 block discarded – undo
1697 1697
 	updateStats('topic');
1698 1698
 
1699 1699
 	// This function is needed to do the updateStats('subject') call.
1700
-	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1701
-		function($string){
1700
+	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1702 1701
 			global $sourcedir;
1703 1702
 			if (function_exists('mb_strtolower'))
1704 1703
 				return mb_strtolower($string, 'UTF-8');
@@ -1767,7 +1766,7 @@  discard block
 block discarded – undo
1767 1766
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1768 1767
 		{
1769 1768
 			// Set the ten lines to nothing.
1770
-			for ($j=0; $j < 10; $j++)
1769
+			for ($j = 0; $j < 10; $j++)
1771 1770
 				$settingsArray[$i++] = '';
1772 1771
 
1773 1772
 			continue;
Please login to merge, or discard this patch.
Braces   +470 added lines, -350 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;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting for fatal errors.
154 160
 	error_reporting(E_ERROR | E_PARSE);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -230,10 +239,11 @@  discard block
 block discarded – undo
230 239
 		// Now just redirect to a blank.png...
231 240
 		$secure = false;
232 241
 
233
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
234
-			$secure = true;
235
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
236
-			$secure = true;
242
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
243
+					$secure = true;
244
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
245
+					$secure = true;
246
+		}
237 247
 
238 248
 		header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
239 249
 		exit;
@@ -244,10 +254,11 @@  discard block
 block discarded – undo
244 254
 	{
245 255
 		// Get PHP's default timezone, if set
246 256
 		$ini_tz = ini_get('date.timezone');
247
-		if (!empty($ini_tz))
248
-			$timezone_id = $ini_tz;
249
-		else
250
-			$timezone_id = '';
257
+		if (!empty($ini_tz)) {
258
+					$timezone_id = $ini_tz;
259
+		} else {
260
+					$timezone_id = '';
261
+		}
251 262
 
252 263
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
253 264
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -277,8 +288,9 @@  discard block
 block discarded – undo
277 288
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
278 289
 		while ($entry = $dir->read())
279 290
 		{
280
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
281
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
291
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
292
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
293
+			}
282 294
 		}
283 295
 		$dir->close();
284 296
 	}
@@ -325,10 +337,11 @@  discard block
 block discarded – undo
325 337
 	}
326 338
 
327 339
 	// Override the language file?
328
-	if (isset($_GET['lang_file']))
329
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
331
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
340
+	if (isset($_GET['lang_file'])) {
341
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
342
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
343
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
344
+	}
332 345
 
333 346
 	// Make sure it exists, if it doesn't reset it.
334 347
 	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']))
@@ -337,8 +350,9 @@  discard block
 block discarded – undo
337 350
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
338 351
 
339 352
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
340
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
341
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
353
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
354
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
355
+		}
342 356
 	}
343 357
 
344 358
 	// And now include the actual language file itself.
@@ -355,15 +369,18 @@  discard block
 block discarded – undo
355 369
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings;
356 370
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist;
357 371
 
358
-	if (empty($sourcedir))
359
-		$sourcedir = dirname(__FILE__) . '/Sources';
372
+	if (empty($sourcedir)) {
373
+			$sourcedir = dirname(__FILE__) . '/Sources';
374
+	}
360 375
 
361 376
 	// Need this to check whether we need the database password.
362 377
 	require(dirname(__FILE__) . '/Settings.php');
363
-	if (!defined('SMF'))
364
-		define('SMF', 1);
365
-	if (empty($smcFunc))
366
-		$smcFunc = array();
378
+	if (!defined('SMF')) {
379
+			define('SMF', 1);
380
+	}
381
+	if (empty($smcFunc)) {
382
+			$smcFunc = array();
383
+	}
367 384
 
368 385
 	$modSettings['disableQueryCheck'] = true;
369 386
 
@@ -371,8 +388,9 @@  discard block
 block discarded – undo
371 388
 	if (!$db_connection)
372 389
 	{
373 390
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
374
-		if (version_compare(PHP_VERSION, '5', '<'))
375
-			require_once($sourcedir . '/Subs-Compat.php');
391
+		if (version_compare(PHP_VERSION, '5', '<')) {
392
+					require_once($sourcedir . '/Subs-Compat.php');
393
+		}
376 394
 
377 395
 		$db_options = array('persist' => $db_persist);
378 396
 		$port = '';
@@ -383,19 +401,20 @@  discard block
 block discarded – undo
383 401
 			if ($db_type == 'mysql')
384 402
 			{
385 403
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
386
-			}
387
-			elseif ($db_type == 'postgresql')
404
+			} elseif ($db_type == 'postgresql')
388 405
 			{
389 406
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
390 407
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
391 408
 			}
392 409
 		}
393 410
 
394
-		if (!empty($port))
395
-			$db_options['port'] = $port;
411
+		if (!empty($port)) {
412
+					$db_options['port'] = $port;
413
+		}
396 414
 
397
-		if (!$db_connection)
398
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
415
+		if (!$db_connection) {
416
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
417
+		}
399 418
 	}
400 419
 }
401 420
 
@@ -423,8 +442,9 @@  discard block
 block discarded – undo
423 442
 		// @todo REMOVE THIS!!
424 443
 		else
425 444
 		{
426
-			if (function_exists('doStep' . $_GET['step']))
427
-				call_user_func('doStep' . $_GET['step']);
445
+			if (function_exists('doStep' . $_GET['step'])) {
446
+							call_user_func('doStep' . $_GET['step']);
447
+			}
428 448
 		}
429 449
 		// Show the footer.
430 450
 		template_install_below();
@@ -442,8 +462,9 @@  discard block
 block discarded – undo
442 462
 	$incontext['sub_template'] = 'welcome_message';
443 463
 
444 464
 	// Done the submission?
445
-	if (isset($_POST['contbutt']))
446
-		return true;
465
+	if (isset($_POST['contbutt'])) {
466
+			return true;
467
+	}
447 468
 
448 469
 	// See if we think they have already installed it?
449 470
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -451,14 +472,17 @@  discard block
 block discarded – undo
451 472
 		$probably_installed = 0;
452 473
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
453 474
 		{
454
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
455
-				$probably_installed++;
456
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
457
-				$probably_installed++;
475
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
476
+							$probably_installed++;
477
+			}
478
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
479
+							$probably_installed++;
480
+			}
458 481
 		}
459 482
 
460
-		if ($probably_installed == 2)
461
-			$incontext['warning'] = $txt['error_already_installed'];
483
+		if ($probably_installed == 2) {
484
+					$incontext['warning'] = $txt['error_already_installed'];
485
+		}
462 486
 	}
463 487
 
464 488
 	// Is some database support even compiled in?
@@ -473,45 +497,54 @@  discard block
 block discarded – undo
473 497
 				$databases[$key]['supported'] = false;
474 498
 				$notFoundSQLFile = true;
475 499
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
500
+			} else {
501
+							$incontext['supported_databases'][] = $db;
476 502
 			}
477
-			else
478
-				$incontext['supported_databases'][] = $db;
479 503
 		}
480 504
 	}
481 505
 
482 506
 	// Check the PHP version.
483
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
484
-		$error = 'error_php_too_low';
507
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
508
+			$error = 'error_php_too_low';
509
+	}
485 510
 	// Make sure we have a supported database
486
-	elseif (empty($incontext['supported_databases']))
487
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
511
+	elseif (empty($incontext['supported_databases'])) {
512
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
513
+	}
488 514
 	// How about session support?  Some crazy sysadmin remove it?
489
-	elseif (!function_exists('session_start'))
490
-		$error = 'error_session_missing';
515
+	elseif (!function_exists('session_start')) {
516
+			$error = 'error_session_missing';
517
+	}
491 518
 	// Make sure they uploaded all the files.
492
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
493
-		$error = 'error_missing_files';
519
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
520
+			$error = 'error_missing_files';
521
+	}
494 522
 	// Very simple check on the session.save_path for Windows.
495 523
 	// @todo Move this down later if they don't use database-driven sessions?
496
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
497
-		$error = 'error_session_save_path';
524
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
525
+			$error = 'error_session_save_path';
526
+	}
498 527
 
499 528
 	// Since each of the three messages would look the same, anyway...
500
-	if (isset($error))
501
-		$incontext['error'] = $txt[$error];
529
+	if (isset($error)) {
530
+			$incontext['error'] = $txt[$error];
531
+	}
502 532
 
503 533
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
504
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
505
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
534
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
535
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
536
+	}
506 537
 
507 538
 	// Confirm mbstring is loaded...
508
-	if (!extension_loaded('mbstring'))
509
-		$incontext['error'] = $txt['install_no_mbstring'];
539
+	if (!extension_loaded('mbstring')) {
540
+			$incontext['error'] = $txt['install_no_mbstring'];
541
+	}
510 542
 
511 543
 	// Check for https stream support.
512 544
 	$supported_streams = stream_get_wrappers();
513
-	if (!in_array('https', $supported_streams))
514
-		$incontext['warning'] = $txt['install_no_https'];
545
+	if (!in_array('https', $supported_streams)) {
546
+			$incontext['warning'] = $txt['install_no_https'];
547
+	}
515 548
 
516 549
 	return false;
517 550
 }
@@ -536,12 +569,14 @@  discard block
 block discarded – undo
536 569
 		'Settings_bak.php',
537 570
 	);
538 571
 
539
-	foreach ($incontext['detected_languages'] as $lang => $temp)
540
-		$extra_files[] = 'Themes/default/languages/' . $lang;
572
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
573
+			$extra_files[] = 'Themes/default/languages/' . $lang;
574
+	}
541 575
 
542 576
 	// With mod_security installed, we could attempt to fix it with .htaccess.
543
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
544
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
577
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
578
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
579
+	}
545 580
 
546 581
 	$failed_files = array();
547 582
 
@@ -553,20 +588,23 @@  discard block
 block discarded – undo
553 588
 		foreach ($writable_files as $file)
554 589
 		{
555 590
 			// Some files won't exist, try to address up front
556
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
557
-				@touch(dirname(__FILE__) . '/' . $file);
591
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
592
+							@touch(dirname(__FILE__) . '/' . $file);
593
+			}
558 594
 			// NOW do the writable check...
559 595
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
560 596
 			{
561 597
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
562 598
 
563 599
 				// Well, 755 hopefully worked... if not, try 777.
564
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
565
-					$failed_files[] = $file;
600
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
601
+									$failed_files[] = $file;
602
+				}
566 603
 			}
567 604
 		}
568
-		foreach ($extra_files as $file)
569
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
605
+		foreach ($extra_files as $file) {
606
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
607
+		}
570 608
 	}
571 609
 	// Windows is trickier.  Let's try opening for r+...
572 610
 	else
@@ -576,30 +614,35 @@  discard block
 block discarded – undo
576 614
 		foreach ($writable_files as $file)
577 615
 		{
578 616
 			// Folders can't be opened for write... but the index.php in them can ;)
579
-			if (is_dir(dirname(__FILE__) . '/' . $file))
580
-				$file .= '/index.php';
617
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
618
+							$file .= '/index.php';
619
+			}
581 620
 
582 621
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
583 622
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
584 623
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
585 624
 
586 625
 			// Hmm, okay, try just for write in that case...
587
-			if (!is_resource($fp))
588
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
626
+			if (!is_resource($fp)) {
627
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
628
+			}
589 629
 
590
-			if (!is_resource($fp))
591
-				$failed_files[] = $file;
630
+			if (!is_resource($fp)) {
631
+							$failed_files[] = $file;
632
+			}
592 633
 
593 634
 			@fclose($fp);
594 635
 		}
595
-		foreach ($extra_files as $file)
596
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
636
+		foreach ($extra_files as $file) {
637
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
638
+		}
597 639
 	}
598 640
 
599 641
 	$failure = count($failed_files) >= 1;
600 642
 
601
-	if (!isset($_SERVER))
602
-		return !$failure;
643
+	if (!isset($_SERVER)) {
644
+			return !$failure;
645
+	}
603 646
 
604 647
 	// Put the list into context.
605 648
 	$incontext['failed_files'] = $failed_files;
@@ -647,19 +690,23 @@  discard block
 block discarded – undo
647 690
 
648 691
 		if (!isset($ftp) || $ftp->error !== false)
649 692
 		{
650
-			if (!isset($ftp))
651
-				$ftp = new ftp_connection(null);
693
+			if (!isset($ftp)) {
694
+							$ftp = new ftp_connection(null);
695
+			}
652 696
 			// Save the error so we can mess with listing...
653
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
654
-				$incontext['ftp_errors'][] = $ftp->last_message;
697
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
698
+							$incontext['ftp_errors'][] = $ftp->last_message;
699
+			}
655 700
 
656 701
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
657 702
 
658
-			if (empty($_POST['ftp_path']) && $found_path)
659
-				$_POST['ftp_path'] = $detect_path;
703
+			if (empty($_POST['ftp_path']) && $found_path) {
704
+							$_POST['ftp_path'] = $detect_path;
705
+			}
660 706
 
661
-			if (!isset($_POST['ftp_username']))
662
-				$_POST['ftp_username'] = $username;
707
+			if (!isset($_POST['ftp_username'])) {
708
+							$_POST['ftp_username'] = $username;
709
+			}
663 710
 
664 711
 			// Set the username etc, into context.
665 712
 			$incontext['ftp'] = array(
@@ -671,8 +718,7 @@  discard block
 block discarded – undo
671 718
 			);
672 719
 
673 720
 			return false;
674
-		}
675
-		else
721
+		} else
676 722
 		{
677 723
 			$_SESSION['installer_temp_ftp'] = array(
678 724
 				'server' => $_POST['ftp_server'],
@@ -686,10 +732,12 @@  discard block
 block discarded – undo
686 732
 
687 733
 			foreach ($failed_files as $file)
688 734
 			{
689
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
690
-					$ftp->chmod($file, 0755);
691
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
692
-					$ftp->chmod($file, 0777);
735
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
736
+									$ftp->chmod($file, 0755);
737
+				}
738
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
739
+									$ftp->chmod($file, 0777);
740
+				}
693 741
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
694 742
 				{
695 743
 					$failed_files_updated[] = $file;
@@ -745,15 +793,17 @@  discard block
 block discarded – undo
745 793
 
746 794
 			if (!$foundOne)
747 795
 			{
748
-				if (isset($db['default_host']))
749
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
796
+				if (isset($db['default_host'])) {
797
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
798
+				}
750 799
 				if (isset($db['default_user']))
751 800
 				{
752 801
 					$incontext['db']['user'] = ini_get($db['default_user']);
753 802
 					$incontext['db']['name'] = ini_get($db['default_user']);
754 803
 				}
755
-				if (isset($db['default_password']))
756
-					$incontext['db']['pass'] = ini_get($db['default_password']);
804
+				if (isset($db['default_password'])) {
805
+									$incontext['db']['pass'] = ini_get($db['default_password']);
806
+				}
757 807
 
758 808
 				// For simplicity and less confusion, leave the port blank by default
759 809
 				$incontext['db']['port'] = '';
@@ -772,10 +822,10 @@  discard block
 block discarded – undo
772 822
 		$incontext['db']['server'] = $_POST['db_server'];
773 823
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
774 824
 
775
-		if (!empty($_POST['db_port']))
776
-			$incontext['db']['port'] = $_POST['db_port'];
777
-	}
778
-	else
825
+		if (!empty($_POST['db_port'])) {
826
+					$incontext['db']['port'] = $_POST['db_port'];
827
+		}
828
+	} else
779 829
 	{
780 830
 		$incontext['db']['prefix'] = 'smf_';
781 831
 	}
@@ -811,10 +861,11 @@  discard block
 block discarded – undo
811 861
 		if (!empty($_POST['db_port']))
812 862
 		{
813 863
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
814
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
815
-				$vars['db_port'] = (int) $_POST['db_port'];
816
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
817
-				$vars['db_port'] = (int) $_POST['db_port'];
864
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
865
+							$vars['db_port'] = (int) $_POST['db_port'];
866
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
867
+							$vars['db_port'] = (int) $_POST['db_port'];
868
+			}
818 869
 		}
819 870
 
820 871
 		// God I hope it saved!
@@ -827,8 +878,9 @@  discard block
 block discarded – undo
827 878
 		// Make sure it works.
828 879
 		require(dirname(__FILE__) . '/Settings.php');
829 880
 
830
-		if (empty($sourcedir))
831
-			$sourcedir = dirname(__FILE__) . '/Sources';
881
+		if (empty($sourcedir)) {
882
+					$sourcedir = dirname(__FILE__) . '/Sources';
883
+		}
832 884
 
833 885
 		// Better find the database file!
834 886
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -838,18 +890,21 @@  discard block
 block discarded – undo
838 890
 		}
839 891
 
840 892
 		// Now include it for database functions!
841
-		if (!defined('SMF'))
842
-			define('SMF', 1);
893
+		if (!defined('SMF')) {
894
+					define('SMF', 1);
895
+		}
843 896
 
844 897
 		$modSettings['disableQueryCheck'] = true;
845
-		if (empty($smcFunc))
846
-			$smcFunc = array();
898
+		if (empty($smcFunc)) {
899
+					$smcFunc = array();
900
+		}
847 901
 
848 902
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
849 903
 
850 904
 		// What - running PHP4? The shame!
851
-		if (version_compare(PHP_VERSION, '5', '<'))
852
-			require_once($sourcedir . '/Subs-Compat.php');
905
+		if (version_compare(PHP_VERSION, '5', '<')) {
906
+					require_once($sourcedir . '/Subs-Compat.php');
907
+		}
853 908
 
854 909
 		// Attempt a connection.
855 910
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -937,12 +992,14 @@  discard block
 block discarded – undo
937 992
 	$incontext['page_title'] = $txt['install_settings'];
938 993
 
939 994
 	// Let's see if we got the database type correct.
940
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
941
-		$db_type = $_POST['db_type'];
995
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
996
+			$db_type = $_POST['db_type'];
997
+	}
942 998
 
943 999
 	// Else we'd better be able to get the connection.
944
-	else
945
-		load_database();
1000
+	else {
1001
+			load_database();
1002
+	}
946 1003
 
947 1004
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
948 1005
 
@@ -951,10 +1008,11 @@  discard block
 block discarded – undo
951 1008
 
952 1009
 		$secure = false;
953 1010
 
954
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
955
-			$secure = true;
956
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
957
-			$secure = true;
1011
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1012
+					$secure = true;
1013
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
1014
+					$secure = true;
1015
+		}
958 1016
 
959 1017
 	// Now, to put what we've learned together... and add a path.
960 1018
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -986,18 +1044,21 @@  discard block
 block discarded – undo
986 1044
 	// Submitting?
987 1045
 	if (isset($_POST['boardurl']))
988 1046
 	{
989
-		if (substr($_POST['boardurl'], -10) == '/index.php')
990
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
991
-		elseif (substr($_POST['boardurl'], -1) == '/')
992
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
993
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
994
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1047
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1048
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1049
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1050
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1051
+		}
1052
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1053
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1054
+		}
995 1055
 
996 1056
 		//Make sure boardurl is aligned with ssl setting
997
-		if (empty($_POST['force_ssl']))
998
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
999
-		else
1000
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1057
+		if (empty($_POST['force_ssl'])) {
1058
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1059
+		} else {
1060
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1061
+		}
1001 1062
 
1002 1063
 		// Save these variables.
1003 1064
 		$vars = array(
@@ -1036,10 +1097,10 @@  discard block
 block discarded – undo
1036 1097
 			{
1037 1098
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1038 1099
 				return false;
1039
-			}
1040
-			else
1041
-				// Set the character set here.
1100
+			} else {
1101
+							// Set the character set here.
1042 1102
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1103
+			}
1043 1104
 		}
1044 1105
 
1045 1106
 		// Good, skip on.
@@ -1059,8 +1120,9 @@  discard block
 block discarded – undo
1059 1120
 	$incontext['continue'] = 1;
1060 1121
 
1061 1122
 	// Already done?
1062
-	if (isset($_POST['pop_done']))
1063
-		return true;
1123
+	if (isset($_POST['pop_done'])) {
1124
+			return true;
1125
+	}
1064 1126
 
1065 1127
 	// Reload settings.
1066 1128
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1078,8 +1140,9 @@  discard block
 block discarded – undo
1078 1140
 	$modSettings = array();
1079 1141
 	if ($result !== false)
1080 1142
 	{
1081
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1082
-			$modSettings[$row['variable']] = $row['value'];
1143
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1144
+					$modSettings[$row['variable']] = $row['value'];
1145
+		}
1083 1146
 		$smcFunc['db_free_result']($result);
1084 1147
 
1085 1148
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1092,20 +1155,22 @@  discard block
 block discarded – undo
1092 1155
 	$modSettings['disableQueryCheck'] = true;
1093 1156
 
1094 1157
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1095
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1096
-		$smcFunc['db_query']('', '
1158
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1159
+			$smcFunc['db_query']('', '
1097 1160
 			SET NAMES {string:utf8}',
1098 1161
 			array(
1099 1162
 				'db_error_skip' => true,
1100 1163
 				'utf8' => 'utf8',
1101 1164
 			)
1102 1165
 		);
1166
+	}
1103 1167
 
1104 1168
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1105
-	if (substr(__DIR__, -1) == '\\')
1106
-		$attachdir = __DIR__ . 'attachments';
1107
-	else
1108
-		$attachdir = __DIR__ . '/attachments';
1169
+	if (substr(__DIR__, -1) == '\\') {
1170
+			$attachdir = __DIR__ . 'attachments';
1171
+	} else {
1172
+			$attachdir = __DIR__ . '/attachments';
1173
+	}
1109 1174
 
1110 1175
 	$replaces = array(
1111 1176
 		'{$db_prefix}' => $db_prefix,
@@ -1122,8 +1187,9 @@  discard block
 block discarded – undo
1122 1187
 
1123 1188
 	foreach ($txt as $key => $value)
1124 1189
 	{
1125
-		if (substr($key, 0, 8) == 'default_')
1126
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1190
+		if (substr($key, 0, 8) == 'default_') {
1191
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1192
+		}
1127 1193
 	}
1128 1194
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1129 1195
 
@@ -1138,8 +1204,9 @@  discard block
 block discarded – undo
1138 1204
 
1139 1205
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1140 1206
 		{
1141
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1142
-				$engines[] = $row['Engine'];
1207
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1208
+							$engines[] = $row['Engine'];
1209
+			}
1143 1210
 		}
1144 1211
 
1145 1212
 		// Done with this now
@@ -1163,8 +1230,7 @@  discard block
 block discarded – undo
1163 1230
 			$replaces['START TRANSACTION;'] = '';
1164 1231
 			$replaces['COMMIT;'] = '';
1165 1232
 		}
1166
-	}
1167
-	else
1233
+	} else
1168 1234
 	{
1169 1235
 		$has_innodb = false;
1170 1236
 	}
@@ -1186,21 +1252,24 @@  discard block
 block discarded – undo
1186 1252
 	foreach ($sql_lines as $count => $line)
1187 1253
 	{
1188 1254
 		// No comments allowed!
1189
-		if (substr(trim($line), 0, 1) != '#')
1190
-			$current_statement .= "\n" . rtrim($line);
1255
+		if (substr(trim($line), 0, 1) != '#') {
1256
+					$current_statement .= "\n" . rtrim($line);
1257
+		}
1191 1258
 
1192 1259
 		// Is this the end of the query string?
1193
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1194
-			continue;
1260
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1261
+					continue;
1262
+		}
1195 1263
 
1196 1264
 		// Does this table already exist?  If so, don't insert more data into it!
1197 1265
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1198 1266
 		{
1199 1267
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1200
-			if (!empty($matches[0]))
1201
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1202
-			else
1203
-				$incontext['sql_results']['insert_dups']++;
1268
+			if (!empty($matches[0])) {
1269
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1270
+			} else {
1271
+							$incontext['sql_results']['insert_dups']++;
1272
+			}
1204 1273
 
1205 1274
 			$current_statement = '';
1206 1275
 			continue;
@@ -1209,8 +1278,9 @@  discard block
 block discarded – undo
1209 1278
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1210 1279
 		{
1211 1280
 			// Use the appropriate function based on the DB type
1212
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1213
-				$db_errorno = $db_type . '_errno';
1281
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1282
+							$db_errorno = $db_type . '_errno';
1283
+			}
1214 1284
 
1215 1285
 			// Error 1050: Table already exists!
1216 1286
 			// @todo Needs to be made better!
@@ -1225,18 +1295,18 @@  discard block
 block discarded – undo
1225 1295
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1226 1296
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1227 1297
 			}
1228
-		}
1229
-		else
1298
+		} else
1230 1299
 		{
1231
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1232
-				$incontext['sql_results']['tables']++;
1233
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1300
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1301
+							$incontext['sql_results']['tables']++;
1302
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1234 1303
 			{
1235 1304
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1236
-				if (!empty($matches[0]))
1237
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1238
-				else
1239
-					$incontext['sql_results']['inserts']++;
1305
+				if (!empty($matches[0])) {
1306
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1307
+				} else {
1308
+									$incontext['sql_results']['inserts']++;
1309
+				}
1240 1310
 			}
1241 1311
 		}
1242 1312
 
@@ -1249,15 +1319,17 @@  discard block
 block discarded – undo
1249 1319
 	// Sort out the context for the SQL.
1250 1320
 	foreach ($incontext['sql_results'] as $key => $number)
1251 1321
 	{
1252
-		if ($number == 0)
1253
-			unset($incontext['sql_results'][$key]);
1254
-		else
1255
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1322
+		if ($number == 0) {
1323
+					unset($incontext['sql_results'][$key]);
1324
+		} else {
1325
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1326
+		}
1256 1327
 	}
1257 1328
 
1258 1329
 	// Make sure UTF will be used globally.
1259
-	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'])))
1260
-		$newSettings[] = array('global_character_set', 'UTF-8');
1330
+	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']))) {
1331
+			$newSettings[] = array('global_character_set', 'UTF-8');
1332
+	}
1261 1333
 
1262 1334
 	// Auto-detect local & global cookie settings
1263 1335
 	$url_parts = parse_url($boardurl);
@@ -1286,15 +1358,19 @@  discard block
 block discarded – undo
1286 1358
 
1287 1359
 		// Look for subfolder, if found, set localCookie
1288 1360
 		// Checking for len > 1 ensures you don't have just a slash...
1289
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1290
-			$localCookies = '1';
1361
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1362
+					$localCookies = '1';
1363
+		}
1291 1364
 
1292
-		if (isset($globalCookies))
1293
-			$newSettings[] = array('globalCookies', $globalCookies);
1294
-		if (isset($globalCookiesDomain))
1295
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1296
-		if (isset($localCookies))
1297
-			$newSettings[] = array('localCookies', $localCookies);
1365
+		if (isset($globalCookies)) {
1366
+					$newSettings[] = array('globalCookies', $globalCookies);
1367
+		}
1368
+		if (isset($globalCookiesDomain)) {
1369
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1370
+		}
1371
+		if (isset($localCookies)) {
1372
+					$newSettings[] = array('localCookies', $localCookies);
1373
+		}
1298 1374
 	}
1299 1375
 
1300 1376
 	// Are we allowing stat collection?
@@ -1312,16 +1388,17 @@  discard block
 block discarded – undo
1312 1388
 			fwrite($fp, $out);
1313 1389
 
1314 1390
 			$return_data = '';
1315
-			while (!feof($fp))
1316
-				$return_data .= fgets($fp, 128);
1391
+			while (!feof($fp)) {
1392
+							$return_data .= fgets($fp, 128);
1393
+			}
1317 1394
 
1318 1395
 			fclose($fp);
1319 1396
 
1320 1397
 			// Get the unique site ID.
1321 1398
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1322 1399
 
1323
-			if (!empty($ID[1]))
1324
-				$smcFunc['db_insert']('replace',
1400
+			if (!empty($ID[1])) {
1401
+							$smcFunc['db_insert']('replace',
1325 1402
 					$db_prefix . 'settings',
1326 1403
 					array('variable' => 'string', 'value' => 'string'),
1327 1404
 					array(
@@ -1330,11 +1407,12 @@  discard block
 block discarded – undo
1330 1407
 					),
1331 1408
 					array('variable')
1332 1409
 				);
1410
+			}
1333 1411
 		}
1334 1412
 	}
1335 1413
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1336
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1337
-		$smcFunc['db_query']('', '
1414
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1415
+			$smcFunc['db_query']('', '
1338 1416
 			DELETE FROM {db_prefix}settings
1339 1417
 			WHERE variable = {string:enable_sm_stats}',
1340 1418
 			array(
@@ -1342,20 +1420,23 @@  discard block
 block discarded – undo
1342 1420
 				'db_error_skip' => true,
1343 1421
 			)
1344 1422
 		);
1423
+	}
1345 1424
 
1346 1425
 	// Are we enabling SSL?
1347
-	if (!empty($_POST['force_ssl']))
1348
-		$newSettings[] = array('force_ssl', 1);
1426
+	if (!empty($_POST['force_ssl'])) {
1427
+			$newSettings[] = array('force_ssl', 1);
1428
+	}
1349 1429
 
1350 1430
 	// Setting a timezone is required.
1351 1431
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1352 1432
 	{
1353 1433
 		// Get PHP's default timezone, if set
1354 1434
 		$ini_tz = ini_get('date.timezone');
1355
-		if (!empty($ini_tz))
1356
-			$timezone_id = $ini_tz;
1357
-		else
1358
-			$timezone_id = '';
1435
+		if (!empty($ini_tz)) {
1436
+					$timezone_id = $ini_tz;
1437
+		} else {
1438
+					$timezone_id = '';
1439
+		}
1359 1440
 
1360 1441
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1361 1442
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1364,8 +1445,9 @@  discard block
 block discarded – undo
1364 1445
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1365 1446
 		}
1366 1447
 
1367
-		if (date_default_timezone_set($timezone_id))
1368
-			$newSettings[] = array('default_timezone', $timezone_id);
1448
+		if (date_default_timezone_set($timezone_id)) {
1449
+					$newSettings[] = array('default_timezone', $timezone_id);
1450
+		}
1369 1451
 	}
1370 1452
 
1371 1453
 	if (!empty($newSettings))
@@ -1396,16 +1478,18 @@  discard block
 block discarded – undo
1396 1478
 	}
1397 1479
 
1398 1480
 	// MySQL specific stuff
1399
-	if (substr($db_type, 0, 5) != 'mysql')
1400
-		return false;
1481
+	if (substr($db_type, 0, 5) != 'mysql') {
1482
+			return false;
1483
+	}
1401 1484
 
1402 1485
 	// Find database user privileges.
1403 1486
 	$privs = array();
1404 1487
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1405 1488
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1406 1489
 	{
1407
-		if ($row['Privilege'] == 'Alter')
1408
-			$privs[] = $row['Privilege'];
1490
+		if ($row['Privilege'] == 'Alter') {
1491
+					$privs[] = $row['Privilege'];
1492
+		}
1409 1493
 	}
1410 1494
 	$smcFunc['db_free_result']($get_privs);
1411 1495
 
@@ -1435,8 +1519,9 @@  discard block
 block discarded – undo
1435 1519
 	$incontext['continue'] = 1;
1436 1520
 
1437 1521
 	// Skipping?
1438
-	if (!empty($_POST['skip']))
1439
-		return true;
1522
+	if (!empty($_POST['skip'])) {
1523
+			return true;
1524
+	}
1440 1525
 
1441 1526
 	// Need this to check whether we need the database password.
1442 1527
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1453,18 +1538,22 @@  discard block
 block discarded – undo
1453 1538
 	// We need this to properly hash the password for Admin
1454 1539
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1455 1540
 			global $sourcedir;
1456
-			if (function_exists('mb_strtolower'))
1457
-				return mb_strtolower($string, 'UTF-8');
1541
+			if (function_exists('mb_strtolower')) {
1542
+							return mb_strtolower($string, 'UTF-8');
1543
+			}
1458 1544
 			require_once($sourcedir . '/Subs-Charset.php');
1459 1545
 			return utf8_strtolower($string);
1460 1546
 		};
1461 1547
 
1462
-	if (!isset($_POST['username']))
1463
-		$_POST['username'] = '';
1464
-	if (!isset($_POST['email']))
1465
-		$_POST['email'] = '';
1466
-	if (!isset($_POST['server_email']))
1467
-		$_POST['server_email'] = '';
1548
+	if (!isset($_POST['username'])) {
1549
+			$_POST['username'] = '';
1550
+	}
1551
+	if (!isset($_POST['email'])) {
1552
+			$_POST['email'] = '';
1553
+	}
1554
+	if (!isset($_POST['server_email'])) {
1555
+			$_POST['server_email'] = '';
1556
+	}
1468 1557
 
1469 1558
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1470 1559
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1483,8 +1572,9 @@  discard block
 block discarded – undo
1483 1572
 			'admin_group' => 1,
1484 1573
 		)
1485 1574
 	);
1486
-	if ($smcFunc['db_num_rows']($request) != 0)
1487
-		$incontext['skip'] = 1;
1575
+	if ($smcFunc['db_num_rows']($request) != 0) {
1576
+			$incontext['skip'] = 1;
1577
+	}
1488 1578
 	$smcFunc['db_free_result']($request);
1489 1579
 
1490 1580
 	// Trying to create an account?
@@ -1515,8 +1605,9 @@  discard block
 block discarded – undo
1515 1605
 		}
1516 1606
 
1517 1607
 		// Update the webmaster's email?
1518
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1519
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1608
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1609
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1610
+		}
1520 1611
 
1521 1612
 		// Work out whether we're going to have dodgy characters and remove them.
1522 1613
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1539,32 +1630,27 @@  discard block
 block discarded – undo
1539 1630
 			$smcFunc['db_free_result']($result);
1540 1631
 
1541 1632
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1542
-		}
1543
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1633
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1544 1634
 		{
1545 1635
 			// Try the previous step again.
1546 1636
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1547 1637
 			return false;
1548
-		}
1549
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1638
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1550 1639
 		{
1551 1640
 			// Try the previous step again.
1552 1641
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1553 1642
 			return false;
1554
-		}
1555
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1643
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1556 1644
 		{
1557 1645
 			// One step back, this time fill out a proper admin email address.
1558 1646
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1559 1647
 			return false;
1560
-		}
1561
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1648
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1562 1649
 		{
1563 1650
 			// One step back, this time fill out a proper admin email address.
1564 1651
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1565 1652
 			return false;
1566
-		}
1567
-		elseif ($_POST['username'] != '')
1653
+		} elseif ($_POST['username'] != '')
1568 1654
 		{
1569 1655
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1570 1656
 
@@ -1632,17 +1718,19 @@  discard block
 block discarded – undo
1632 1718
 	reloadSettings();
1633 1719
 
1634 1720
 	// Bring a warning over.
1635
-	if (!empty($incontext['account_existed']))
1636
-		$incontext['warning'] = $incontext['account_existed'];
1721
+	if (!empty($incontext['account_existed'])) {
1722
+			$incontext['warning'] = $incontext['account_existed'];
1723
+	}
1637 1724
 
1638
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1639
-		$smcFunc['db_query']('', '
1725
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1726
+			$smcFunc['db_query']('', '
1640 1727
 			SET NAMES {string:db_character_set}',
1641 1728
 			array(
1642 1729
 				'db_character_set' => $db_character_set,
1643 1730
 				'db_error_skip' => true,
1644 1731
 			)
1645 1732
 		);
1733
+	}
1646 1734
 
1647 1735
 	// As track stats is by default enabled let's add some activity.
1648 1736
 	$smcFunc['db_insert']('ignore',
@@ -1663,14 +1751,16 @@  discard block
 block discarded – undo
1663 1751
 	// Only proceed if we can load the data.
1664 1752
 	if ($request)
1665 1753
 	{
1666
-		while ($row = $smcFunc['db_fetch_row']($request))
1667
-			$modSettings[$row[0]] = $row[1];
1754
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1755
+					$modSettings[$row[0]] = $row[1];
1756
+		}
1668 1757
 		$smcFunc['db_free_result']($request);
1669 1758
 	}
1670 1759
 
1671 1760
 	// Automatically log them in ;)
1672
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1673
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1761
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1762
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1763
+	}
1674 1764
 
1675 1765
 	$result = $smcFunc['db_query']('', '
1676 1766
 		SELECT value
@@ -1681,13 +1771,14 @@  discard block
 block discarded – undo
1681 1771
 			'db_error_skip' => true,
1682 1772
 		)
1683 1773
 	);
1684
-	if ($smcFunc['db_num_rows']($result) != 0)
1685
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1774
+	if ($smcFunc['db_num_rows']($result) != 0) {
1775
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1776
+	}
1686 1777
 	$smcFunc['db_free_result']($result);
1687 1778
 
1688
-	if (empty($db_sessions))
1689
-		$_SESSION['admin_time'] = time();
1690
-	else
1779
+	if (empty($db_sessions)) {
1780
+			$_SESSION['admin_time'] = time();
1781
+	} else
1691 1782
 	{
1692 1783
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1693 1784
 
@@ -1711,8 +1802,9 @@  discard block
 block discarded – undo
1711 1802
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1712 1803
 		function($string){
1713 1804
 			global $sourcedir;
1714
-			if (function_exists('mb_strtolower'))
1715
-				return mb_strtolower($string, 'UTF-8');
1805
+			if (function_exists('mb_strtolower')) {
1806
+							return mb_strtolower($string, 'UTF-8');
1807
+			}
1716 1808
 			require_once($sourcedir . '/Subs-Charset.php');
1717 1809
 			return utf8_strtolower($string);
1718 1810
 		};
@@ -1728,8 +1820,9 @@  discard block
 block discarded – undo
1728 1820
 		)
1729 1821
 	);
1730 1822
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1731
-	if ($smcFunc['db_num_rows']($request) > 0)
1732
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1823
+	if ($smcFunc['db_num_rows']($request) > 0) {
1824
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1825
+	}
1733 1826
 	$smcFunc['db_free_result']($request);
1734 1827
 
1735 1828
 	// Now is the perfect time to fetch the SM files.
@@ -1748,8 +1841,9 @@  discard block
 block discarded – undo
1748 1841
 
1749 1842
 	// Check if we need some stupid MySQL fix.
1750 1843
 	$server_version = $smcFunc['db_server_info']();
1751
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1752
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1844
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1845
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1846
+	}
1753 1847
 
1754 1848
 	// Some final context for the template.
1755 1849
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1769,8 +1863,9 @@  discard block
 block discarded – undo
1769 1863
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1770 1864
 
1771 1865
 	// @todo Do we just want to read the file in clean, and split it this way always?
1772
-	if (count($settingsArray) == 1)
1773
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1866
+	if (count($settingsArray) == 1) {
1867
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1868
+	}
1774 1869
 
1775 1870
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1776 1871
 	{
@@ -1778,25 +1873,29 @@  discard block
 block discarded – undo
1778 1873
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1779 1874
 		{
1780 1875
 			// Set the ten lines to nothing.
1781
-			for ($j=0; $j < 10; $j++)
1782
-				$settingsArray[$i++] = '';
1876
+			for ($j=0; $j < 10; $j++) {
1877
+							$settingsArray[$i++] = '';
1878
+			}
1783 1879
 
1784 1880
 			continue;
1785 1881
 		}
1786 1882
 
1787
-		if (trim($settingsArray[$i]) == '?' . '>')
1788
-			$settingsArray[$i] = '';
1883
+		if (trim($settingsArray[$i]) == '?' . '>') {
1884
+					$settingsArray[$i] = '';
1885
+		}
1789 1886
 
1790 1887
 		// Don't trim or bother with it if it's not a variable.
1791
-		if (substr($settingsArray[$i], 0, 1) != '$')
1792
-			continue;
1888
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1889
+					continue;
1890
+		}
1793 1891
 
1794 1892
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1795 1893
 
1796
-		foreach ($vars as $var => $val)
1797
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1894
+		foreach ($vars as $var => $val) {
1895
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1798 1896
 			{
1799 1897
 				$comment = strstr($settingsArray[$i], '#');
1898
+		}
1800 1899
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1801 1900
 				unset($vars[$var]);
1802 1901
 			}
@@ -1806,36 +1905,41 @@  discard block
 block discarded – undo
1806 1905
 	if (!empty($vars))
1807 1906
 	{
1808 1907
 		$settingsArray[$i++] = '';
1809
-		foreach ($vars as $var => $val)
1810
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1908
+		foreach ($vars as $var => $val) {
1909
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1910
+		}
1811 1911
 	}
1812 1912
 
1813 1913
 	// Blank out the file - done to fix a oddity with some servers.
1814 1914
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1815
-	if (!$fp)
1816
-		return false;
1915
+	if (!$fp) {
1916
+			return false;
1917
+	}
1817 1918
 	fclose($fp);
1818 1919
 
1819 1920
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1820 1921
 
1821 1922
 	// Gotta have one of these ;)
1822
-	if (trim($settingsArray[0]) != '<?php')
1823
-		fwrite($fp, "<?php\n");
1923
+	if (trim($settingsArray[0]) != '<?php') {
1924
+			fwrite($fp, "<?php\n");
1925
+	}
1824 1926
 
1825 1927
 	$lines = count($settingsArray);
1826 1928
 	for ($i = 0; $i < $lines - 1; $i++)
1827 1929
 	{
1828 1930
 		// Don't just write a bunch of blank lines.
1829
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1830
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1931
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1932
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1933
+		}
1831 1934
 	}
1832 1935
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1833 1936
 	fclose($fp);
1834 1937
 
1835 1938
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1836 1939
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1837
-	if (function_exists('opcache_invalidate'))
1838
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1940
+	if (function_exists('opcache_invalidate')) {
1941
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1942
+	}
1839 1943
 
1840 1944
 	return true;
1841 1945
 }
@@ -1845,10 +1949,11 @@  discard block
 block discarded – undo
1845 1949
 	global $cachedir;
1846 1950
 
1847 1951
 	// Write out the db_last_error file with the error timestamp
1848
-	if (!empty($cachedir) && is_writable($cachedir))
1849
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1850
-	else
1851
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1952
+	if (!empty($cachedir) && is_writable($cachedir)) {
1953
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1954
+	} else {
1955
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1956
+	}
1852 1957
 
1853 1958
 	return true;
1854 1959
 }
@@ -1865,9 +1970,9 @@  discard block
 block discarded – undo
1865 1970
 	SecFilterScanPOST Off
1866 1971
 </IfModule>';
1867 1972
 
1868
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1869
-		return true;
1870
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1973
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1974
+			return true;
1975
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1871 1976
 	{
1872 1977
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1873 1978
 
@@ -1879,29 +1984,28 @@  discard block
 block discarded – undo
1879 1984
 				fwrite($ht_handle, $htaccess_addition);
1880 1985
 				fclose($ht_handle);
1881 1986
 				return true;
1987
+			} else {
1988
+							return false;
1882 1989
 			}
1883
-			else
1884
-				return false;
1990
+		} else {
1991
+					return true;
1885 1992
 		}
1886
-		else
1887
-			return true;
1888
-	}
1889
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1890
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1891
-	elseif (is_writable(dirname(__FILE__)))
1993
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1994
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1995
+	} elseif (is_writable(dirname(__FILE__)))
1892 1996
 	{
1893 1997
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1894 1998
 		{
1895 1999
 			fwrite($ht_handle, $htaccess_addition);
1896 2000
 			fclose($ht_handle);
1897 2001
 			return true;
2002
+		} else {
2003
+					return false;
1898 2004
 		}
1899
-		else
2005
+	} else {
1900 2006
 			return false;
1901 2007
 	}
1902
-	else
1903
-		return false;
1904
-}
2008
+	}
1905 2009
 
1906 2010
 function template_install_above()
1907 2011
 {
@@ -1940,9 +2044,10 @@  discard block
 block discarded – undo
1940 2044
 							<label for="installer_language">', $txt['installer_language'], ':</label>
1941 2045
 							<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1942 2046
 
1943
-		foreach ($incontext['detected_languages'] as $lang => $name)
1944
-			echo '
2047
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2048
+					echo '
1945 2049
 								<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2050
+		}
1946 2051
 
1947 2052
 		echo '
1948 2053
 							</select>
@@ -1962,9 +2067,10 @@  discard block
 block discarded – undo
1962 2067
 					<h2>', $txt['upgrade_progress'], '</h2>
1963 2068
 					<ul>';
1964 2069
 
1965
-	foreach ($incontext['steps'] as $num => $step)
1966
-		echo '
2070
+	foreach ($incontext['steps'] as $num => $step) {
2071
+			echo '
1967 2072
 						<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2073
+	}
1968 2074
 
1969 2075
 	echo '
1970 2076
 					</ul>
@@ -1990,20 +2096,23 @@  discard block
 block discarded – undo
1990 2096
 		echo '
1991 2097
 							<div class="floatright">';
1992 2098
 
1993
-		if (!empty($incontext['continue']))
1994
-			echo '
2099
+		if (!empty($incontext['continue'])) {
2100
+					echo '
1995 2101
 								<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">';
1996
-		if (!empty($incontext['skip']))
1997
-			echo '
2102
+		}
2103
+		if (!empty($incontext['skip'])) {
2104
+					echo '
1998 2105
 								<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">';
2106
+		}
1999 2107
 		echo '
2000 2108
 							</div>';
2001 2109
 	}
2002 2110
 
2003 2111
 	// Show the closing form tag and other data only if not in the last step
2004
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
2005
-		echo '
2112
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2113
+			echo '
2006 2114
 						</form>';
2115
+	}
2007 2116
 
2008 2117
 	echo '
2009 2118
 					</div><!-- .panel -->
@@ -2036,13 +2145,15 @@  discard block
 block discarded – undo
2036 2145
 		</div>';
2037 2146
 
2038 2147
 	// Show the warnings, or not.
2039
-	if (template_warning_divs())
2040
-		echo '
2148
+	if (template_warning_divs()) {
2149
+			echo '
2041 2150
 		<h3>', $txt['install_all_lovely'], '</h3>';
2151
+	}
2042 2152
 
2043 2153
 	// Say we want the continue button!
2044
-	if (empty($incontext['error']))
2045
-		$incontext['continue'] = 1;
2154
+	if (empty($incontext['error'])) {
2155
+			$incontext['continue'] = 1;
2156
+	}
2046 2157
 
2047 2158
 	// For the latest version stuff.
2048 2159
 	echo '
@@ -2076,19 +2187,21 @@  discard block
 block discarded – undo
2076 2187
 	global $txt, $incontext;
2077 2188
 
2078 2189
 	// Errors are very serious..
2079
-	if (!empty($incontext['error']))
2080
-		echo '
2190
+	if (!empty($incontext['error'])) {
2191
+			echo '
2081 2192
 		<div class="errorbox">
2082 2193
 			<h3>', $txt['upgrade_critical_error'], '</h3>
2083 2194
 			', $incontext['error'], '
2084 2195
 		</div>';
2196
+	}
2085 2197
 	// A warning message?
2086
-	elseif (!empty($incontext['warning']))
2087
-		echo '
2198
+	elseif (!empty($incontext['warning'])) {
2199
+			echo '
2088 2200
 		<div class="errorbox">
2089 2201
 			<h3>', $txt['upgrade_warning'], '</h3>
2090 2202
 			', $incontext['warning'], '
2091 2203
 		</div>';
2204
+	}
2092 2205
 
2093 2206
 	return empty($incontext['error']) && empty($incontext['warning']);
2094 2207
 }
@@ -2104,26 +2217,29 @@  discard block
 block discarded – undo
2104 2217
 			<li>', $incontext['failed_files']), '</li>
2105 2218
 		</ul>';
2106 2219
 
2107
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2108
-		echo '
2220
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2221
+			echo '
2109 2222
 		<hr>
2110 2223
 		<p>', $txt['chmod_linux_info'], '</p>
2111 2224
 		<samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>';
2225
+	}
2112 2226
 
2113 2227
 	// This is serious!
2114
-	if (!template_warning_divs())
2115
-		return;
2228
+	if (!template_warning_divs()) {
2229
+			return;
2230
+	}
2116 2231
 
2117 2232
 	echo '
2118 2233
 		<hr>
2119 2234
 		<p>', $txt['ftp_setup_info'], '</p>';
2120 2235
 
2121
-	if (!empty($incontext['ftp_errors']))
2122
-		echo '
2236
+	if (!empty($incontext['ftp_errors'])) {
2237
+			echo '
2123 2238
 		<div class="error_message">
2124 2239
 			', $txt['error_ftp_no_connect'], '<br><br>
2125 2240
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2126 2241
 		</div>';
2242
+	}
2127 2243
 
2128 2244
 	echo '
2129 2245
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2192,16 +2308,16 @@  discard block
 block discarded – undo
2192 2308
 			<dd>
2193 2309
 				<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2194 2310
 
2195
-	foreach ($incontext['supported_databases'] as $key => $db)
2196
-			echo '
2311
+	foreach ($incontext['supported_databases'] as $key => $db) {
2312
+				echo '
2197 2313
 					<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2314
+	}
2198 2315
 
2199 2316
 	echo '
2200 2317
 				</select>
2201 2318
 				<div class="smalltext">', $txt['db_settings_type_info'], '</div>
2202 2319
 			</dd>';
2203
-	}
2204
-	else
2320
+	} else
2205 2321
 	{
2206 2322
 		echo '
2207 2323
 			<dd>
@@ -2376,9 +2492,10 @@  discard block
 block discarded – undo
2376 2492
 		<div class="red">', $txt['error_db_queries'], '</div>
2377 2493
 		<ul>';
2378 2494
 
2379
-		foreach ($incontext['failures'] as $line => $fail)
2380
-			echo '
2495
+		foreach ($incontext['failures'] as $line => $fail) {
2496
+					echo '
2381 2497
 			<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2498
+		}
2382 2499
 
2383 2500
 		echo '
2384 2501
 		</ul>';
@@ -2443,15 +2560,16 @@  discard block
 block discarded – undo
2443 2560
 			</dd>
2444 2561
 		</dl>';
2445 2562
 
2446
-	if ($incontext['require_db_confirm'])
2447
-		echo '
2563
+	if ($incontext['require_db_confirm']) {
2564
+			echo '
2448 2565
 		<h2>', $txt['user_settings_database'], '</h2>
2449 2566
 		<p>', $txt['user_settings_database_info'], '</p>
2450 2567
 
2451 2568
 		<div class="lefttext">
2452 2569
 			<input type="password" name="password3" size="30">
2453 2570
 		</div>';
2454
-}
2571
+	}
2572
+	}
2455 2573
 
2456 2574
 // Tell them it's done, and to delete.
2457 2575
 function template_delete_install()
@@ -2464,13 +2582,14 @@  discard block
 block discarded – undo
2464 2582
 	template_warning_divs();
2465 2583
 
2466 2584
 	// Install directory still writable?
2467
-	if ($incontext['dir_still_writable'])
2468
-		echo '
2585
+	if ($incontext['dir_still_writable']) {
2586
+			echo '
2469 2587
 		<p><em>', $txt['still_writable'], '</em></p>';
2588
+	}
2470 2589
 
2471 2590
 	// Don't show the box if it's like 99% sure it won't work :P.
2472
-	if ($incontext['probably_delete_install'])
2473
-		echo '
2591
+	if ($incontext['probably_delete_install']) {
2592
+			echo '
2474 2593
 		<label>
2475 2594
 			<input type="checkbox" id="delete_self" onclick="doTheDelete();">
2476 2595
 			<strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong>
@@ -2486,6 +2605,7 @@  discard block
 block discarded – undo
2486 2605
 				theCheck.disabled = true;
2487 2606
 			}
2488 2607
 		</script>';
2608
+	}
2489 2609
 
2490 2610
 	echo '
2491 2611
 		<p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p>
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -430,8 +430,8 @@
 block discarded – undo
430 430
 	$real_name = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
431 431
 
432 432
 	// Searches.
433
-	$member_name_search = $member_name . ' ' . $comparison . ' ' . implode( ' OR ' . $member_name . ' ' . $comparison . ' ', $names_list);
434
-	$real_name_search = $real_name . ' ' . $comparison . ' ' . implode( ' OR ' . $real_name . ' ' . $comparison . ' ', $names_list);
433
+	$member_name_search = $member_name . ' ' . $comparison . ' ' . implode(' OR ' . $member_name . ' ' . $comparison . ' ', $names_list);
434
+	$real_name_search = $real_name . ' ' . $comparison . ' ' . implode(' OR ' . $real_name . ' ' . $comparison . ' ', $names_list);
435 435
 
436 436
 	// Search by username, display name, and email address.
437 437
 	$request = $smcFunc['db_query']('', '
Please login to merge, or discard this patch.
Braces   +165 added lines, -119 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -47,8 +48,9 @@  discard block
 block discarded – undo
47 48
 	if (isset($_COOKIE[$cookiename]))
48 49
 	{
49 50
 		// First check for 2.1 json-format cookie
50
-		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1)
51
-			list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
51
+		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1) {
52
+					list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
53
+		}
52 54
 
53 55
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
54 56
 		elseif (preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;(i:3;i:\d;)?~', $_COOKIE[$cookiename]) === 1)
@@ -58,15 +60,17 @@  discard block
 block discarded – undo
58 60
 			$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
59 61
 
60 62
 			// Maybe we need to temporarily pretend to be using local cookies
61
-			if ($cookie_state == 0 && $old_state == 1)
62
-				list($old_domain, $old_path) = url_parts(true, false);
63
-			else
64
-				list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
63
+			if ($cookie_state == 0 && $old_state == 1) {
64
+							list($old_domain, $old_path) = url_parts(true, false);
65
+			} else {
66
+							list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
67
+			}
65 68
 		}
66 69
 
67 70
 		// Out with the old, in with the new!
68
-		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1])
69
-			smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
71
+		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1]) {
72
+					smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
73
+		}
70 74
 	}
71 75
 
72 76
 	// Get the data and path to set it on.
@@ -82,8 +86,9 @@  discard block
 block discarded – undo
82 86
 	smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], $cookie_url[0]);
83 87
 
84 88
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
85
-	if (empty($id) && !empty($modSettings['globalCookies']))
86
-		smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
89
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
90
+			smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
91
+	}
87 92
 
88 93
 	// Any alias URLs?  This is mainly for use with frames, etc.
89 94
 	if (!empty($modSettings['forum_alias_urls']))
@@ -99,8 +104,9 @@  discard block
 block discarded – undo
99 104
 
100 105
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
101 106
 
102
-			if ($cookie_url[0] == '')
103
-				$cookie_url[0] = strtok($alias, '/');
107
+			if ($cookie_url[0] == '') {
108
+							$cookie_url[0] = strtok($alias, '/');
109
+			}
104 110
 
105 111
 			$alias_data = $smcFunc['json_decode']($data, true);
106 112
 			$alias_data[3] = $cookie_url[0];
@@ -159,8 +165,9 @@  discard block
 block discarded – undo
159 165
 	smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], $cookie_url[0]);
160 166
 
161 167
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
162
-	if (empty($id) && !empty($modSettings['globalCookies']))
163
-		smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], '');
168
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
169
+			smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], '');
170
+	}
164 171
 
165 172
 	$_COOKIE[$identifier] = $data;
166 173
 }
@@ -182,23 +189,28 @@  discard block
 block discarded – undo
182 189
 	$parsed_url = parse_url($boardurl);
183 190
 
184 191
 	// Is local cookies off?
185
-	if (empty($parsed_url['path']) || !$local)
186
-		$parsed_url['path'] = '';
192
+	if (empty($parsed_url['path']) || !$local) {
193
+			$parsed_url['path'] = '';
194
+	}
187 195
 
188
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
189
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
196
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
197
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
198
+	}
190 199
 
191 200
 	// Globalize cookies across domains (filter out IP-addresses)?
192
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
193
-		$parsed_url['host'] = '.' . $parts[1];
201
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
202
+			$parsed_url['host'] = '.' . $parts[1];
203
+	}
194 204
 
195 205
 	// We shouldn't use a host at all if both options are off.
196
-	elseif (!$local && !$global)
197
-		$parsed_url['host'] = '';
206
+	elseif (!$local && !$global) {
207
+			$parsed_url['host'] = '';
208
+	}
198 209
 
199 210
 	// The host also shouldn't be set if there aren't any dots in it.
200
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
201
-		$parsed_url['host'] = '';
211
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
212
+			$parsed_url['host'] = '';
213
+	}
202 214
 
203 215
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
204 216
 }
@@ -217,8 +229,9 @@  discard block
 block discarded – undo
217 229
 	createToken('login');
218 230
 
219 231
 	// Never redirect to an attachment
220
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
221
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
232
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
233
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
234
+	}
222 235
 
223 236
 	$context['sub_template'] = 'kick_guest';
224 237
 	$context['page_title'] = $txt['login'];
@@ -273,10 +286,12 @@  discard block
 block discarded – undo
273 286
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
274 287
 		log_error($txt['security_wrong'], 'critical');
275 288
 
276
-		if (isset($_POST[$type . '_hash_pass']))
277
-			unset($_POST[$type . '_hash_pass']);
278
-		if (isset($_POST[$type . '_pass']))
279
-			unset($_POST[$type . '_pass']);
289
+		if (isset($_POST[$type . '_hash_pass'])) {
290
+					unset($_POST[$type . '_hash_pass']);
291
+		}
292
+		if (isset($_POST[$type . '_pass'])) {
293
+					unset($_POST[$type . '_pass']);
294
+		}
280 295
 
281 296
 		$context['incorrect_password'] = true;
282 297
 	}
@@ -289,15 +304,17 @@  discard block
 block discarded – undo
289 304
 
290 305
 	// Now go through $_POST.  Make sure the session hash is sent.
291 306
 	$_POST[$context['session_var']] = $context['session_id'];
292
-	foreach ($_POST as $k => $v)
293
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
307
+	foreach ($_POST as $k => $v) {
308
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
309
+	}
294 310
 
295 311
 	// Now we'll use the admin_login sub template of the Login template.
296 312
 	$context['sub_template'] = 'admin_login';
297 313
 
298 314
 	// And title the page something like "Login".
299
-	if (!isset($context['page_title']))
300
-		$context['page_title'] = $txt['login'];
315
+	if (!isset($context['page_title'])) {
316
+			$context['page_title'] = $txt['login'];
317
+	}
301 318
 
302 319
 	// The type of action.
303 320
 	$context['sessionCheckType'] = $type;
@@ -320,14 +337,15 @@  discard block
 block discarded – undo
320 337
 {
321 338
 	global $smcFunc;
322 339
 
323
-	if (!is_array($v))
324
-		return '
340
+	if (!is_array($v)) {
341
+			return '
325 342
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
326
-	else
343
+	} else
327 344
 	{
328 345
 		$ret = '';
329
-		foreach ($v as $k2 => $v2)
330
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
346
+		foreach ($v as $k2 => $v2) {
347
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
348
+		}
331 349
 
332 350
 		return $ret;
333 351
 	}
@@ -354,18 +372,20 @@  discard block
 block discarded – undo
354 372
 		foreach ($get as $k => $v)
355 373
 		{
356 374
 			// Only if it's not already in the $scripturl!
357
-			if (!isset($temp[$k]))
358
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
375
+			if (!isset($temp[$k])) {
376
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
377
+			}
359 378
 			// If it changed, put it out there, but with an ampersand.
360
-			elseif ($temp[$k] != $get[$k])
361
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
379
+			elseif ($temp[$k] != $get[$k]) {
380
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
381
+			}
362 382
 		}
363
-	}
364
-	else
383
+	} else
365 384
 	{
366 385
 		// Add up all the data from $_GET into get_data.
367
-		foreach ($get as $k => $v)
368
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
386
+		foreach ($get as $k => $v) {
387
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
388
+		}
369 389
 	}
370 390
 
371 391
 	$query_string = substr($query_string, 0, -1);
@@ -388,8 +408,9 @@  discard block
 block discarded – undo
388 408
 	global $scripturl, $user_info, $smcFunc;
389 409
 
390 410
 	// If it's not already an array, make it one.
391
-	if (!is_array($names))
392
-		$names = explode(',', $names);
411
+	if (!is_array($names)) {
412
+			$names = explode(',', $names);
413
+	}
393 414
 
394 415
 	$maybe_email = false;
395 416
 	$names_list = array();
@@ -401,10 +422,11 @@  discard block
 block discarded – undo
401 422
 		$maybe_email |= strpos($name, '@') !== false;
402 423
 
403 424
 		// Make it so standard wildcards will work. (* and ?)
404
-		if ($use_wildcards)
405
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
406
-		else
407
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
425
+		if ($use_wildcards) {
426
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
427
+		} else {
428
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
429
+		}
408 430
 
409 431
 		$names_list[] = '{string:lookup_name_' . $i . '}';
410 432
 		$where_params['lookup_name_' . $i] = $names[$i];
@@ -417,11 +439,12 @@  discard block
 block discarded – undo
417 439
 	$results = array();
418 440
 
419 441
 	// This ensures you can't search someones email address if you can't see it.
420
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
421
-		$email_condition = '
442
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
443
+			$email_condition = '
422 444
 			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
423
-	else
424
-		$email_condition = '';
445
+	} else {
446
+			$email_condition = '';
447
+	}
425 448
 
426 449
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
427 450
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -480,10 +503,11 @@  discard block
 block discarded – undo
480 503
 	$context['template_layers'] = array();
481 504
 	$context['sub_template'] = 'find_members';
482 505
 
483
-	if (isset($_REQUEST['search']))
484
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
485
-	else
486
-		$_REQUEST['start'] = 0;
506
+	if (isset($_REQUEST['search'])) {
507
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
508
+	} else {
509
+			$_REQUEST['start'] = 0;
510
+	}
487 511
 
488 512
 	// Allow the user to pass the input to be added to to the box.
489 513
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -524,10 +548,10 @@  discard block
 block discarded – undo
524 548
 		);
525 549
 
526 550
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
551
+	} else {
552
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
553
+	}
527 554
 	}
528
-	else
529
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
530
-}
531 555
 
532 556
 /**
533 557
  * Outputs each member name on its own line.
@@ -543,8 +567,9 @@  discard block
 block discarded – undo
543 567
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
544 568
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
545 569
 
546
-	if (function_exists('iconv'))
547
-		header('content-type: text/plain; charset=UTF-8');
570
+	if (function_exists('iconv')) {
571
+			header('content-type: text/plain; charset=UTF-8');
572
+	}
548 573
 
549 574
 	$request = $smcFunc['db_query']('', '
550 575
 		SELECT real_name
@@ -564,14 +589,16 @@  discard block
 block discarded – undo
564 589
 		if (function_exists('iconv'))
565 590
 		{
566 591
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
567
-			if ($utf8)
568
-				$row['real_name'] = $utf8;
592
+			if ($utf8) {
593
+							$row['real_name'] = $utf8;
594
+			}
569 595
 		}
570 596
 
571 597
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
572 598
 
573
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
574
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
599
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
600
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
601
+		}
575 602
 
576 603
 		echo $row['real_name'], "\n";
577 604
 	}
@@ -628,9 +655,9 @@  discard block
 block discarded – undo
628 655
 
629 656
 		// Update the database...
630 657
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
658
+	} else {
659
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
631 660
 	}
632
-	else
633
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
634 661
 
635 662
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
636 663
 
@@ -661,31 +688,37 @@  discard block
 block discarded – undo
661 688
 	$errors = array();
662 689
 
663 690
 	// Don't use too long a name.
664
-	if ($smcFunc['strlen']($username) > 25)
665
-		$errors[] = array('lang', 'error_long_name');
691
+	if ($smcFunc['strlen']($username) > 25) {
692
+			$errors[] = array('lang', 'error_long_name');
693
+	}
666 694
 
667 695
 	// No name?!  How can you register with no name?
668
-	if ($username == '')
669
-		$errors[] = array('lang', 'need_username');
696
+	if ($username == '') {
697
+			$errors[] = array('lang', 'need_username');
698
+	}
670 699
 
671 700
 	// Only these characters are permitted.
672
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
673
-		$errors[] = array('lang', 'error_invalid_characters_username');
701
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
702
+			$errors[] = array('lang', 'error_invalid_characters_username');
703
+	}
674 704
 
675
-	if (stristr($username, $txt['guest_title']) !== false)
676
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
705
+	if (stristr($username, $txt['guest_title']) !== false) {
706
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
707
+	}
677 708
 
678 709
 	if ($check_reserved_name)
679 710
 	{
680 711
 		require_once($sourcedir . '/Subs-Members.php');
681
-		if (isReservedName($username, $memID, false))
682
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
712
+		if (isReservedName($username, $memID, false)) {
713
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
714
+		}
683 715
 	}
684 716
 
685
-	if ($return_error)
686
-		return $errors;
687
-	elseif (empty($errors))
688
-		return null;
717
+	if ($return_error) {
718
+			return $errors;
719
+	} elseif (empty($errors)) {
720
+			return null;
721
+	}
689 722
 
690 723
 	loadLanguage('Errors');
691 724
 	$error = $errors[0];
@@ -711,22 +744,26 @@  discard block
 block discarded – undo
711 744
 	global $modSettings, $smcFunc;
712 745
 
713 746
 	// Perform basic requirements first.
714
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
715
-		return 'short';
747
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
748
+			return 'short';
749
+	}
716 750
 
717 751
 	// Is this enough?
718
-	if (empty($modSettings['password_strength']))
719
-		return null;
752
+	if (empty($modSettings['password_strength'])) {
753
+			return null;
754
+	}
720 755
 
721 756
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
722
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
723
-		return 'restricted_words';
724
-	elseif ($smcFunc['strpos']($password, $username) !== false)
725
-		return 'restricted_words';
757
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
758
+			return 'restricted_words';
759
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
760
+			return 'restricted_words';
761
+	}
726 762
 
727 763
 	// If just medium, we're done.
728
-	if ($modSettings['password_strength'] == 1)
729
-		return null;
764
+	if ($modSettings['password_strength'] == 1) {
765
+			return null;
766
+	}
730 767
 
731 768
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
732 769
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -758,14 +795,16 @@  discard block
 block discarded – undo
758 795
 			)
759 796
 		);
760 797
 		$groups = array();
761
-		while ($row = $smcFunc['db_fetch_assoc']($request))
762
-			$groups[] = $row['id_group'];
798
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
799
+					$groups[] = $row['id_group'];
800
+		}
763 801
 		$smcFunc['db_free_result']($request);
764 802
 
765
-		if (empty($groups))
766
-			$group_query = '0=1';
767
-		else
768
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
803
+		if (empty($groups)) {
804
+					$group_query = '0=1';
805
+		} else {
806
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
807
+		}
769 808
 	}
770 809
 
771 810
 	// Then, same again, just the boards this time!
@@ -775,10 +814,11 @@  discard block
 block discarded – undo
775 814
 	{
776 815
 		$boards = boardsAllowedTo('moderate_board', true);
777 816
 
778
-		if (empty($boards))
779
-			$board_query = '0=1';
780
-		else
781
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
817
+		if (empty($boards)) {
818
+					$board_query = '0=1';
819
+		} else {
820
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
821
+		}
782 822
 	}
783 823
 
784 824
 	// What boards are they the moderator of?
@@ -793,8 +833,9 @@  discard block
 block discarded – undo
793 833
 				'current_member' => $user_info['id'],
794 834
 			)
795 835
 		);
796
-		while ($row = $smcFunc['db_fetch_assoc']($request))
797
-			$boards_mod[] = $row['id_board'];
836
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
837
+					$boards_mod[] = $row['id_board'];
838
+		}
798 839
 		$smcFunc['db_free_result']($request);
799 840
 
800 841
 		// Can any of the groups they're in moderate any of the boards?
@@ -806,8 +847,9 @@  discard block
 block discarded – undo
806 847
 				'groups' => $user_info['groups'],
807 848
 			)
808 849
 		);
809
-		while ($row = $smcFunc['db_fetch_assoc']($request))
810
-			$boards_mod[] = $row['id_board'];
850
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
851
+					$boards_mod[] = $row['id_board'];
852
+		}
811 853
 		$smcFunc['db_free_result']($request);
812 854
 
813 855
 		// Just in case we've got duplicates here...
@@ -852,10 +894,12 @@  discard block
 block discarded – undo
852 894
 	global $modSettings;
853 895
 
854 896
 	// In case a customization wants to override the default settings
855
-	if ($httponly === null)
856
-		$httponly = !empty($modSettings['httponlyCookies']);
857
-	if ($secure === null)
858
-		$secure = !empty($modSettings['secureCookies']);
897
+	if ($httponly === null) {
898
+			$httponly = !empty($modSettings['httponlyCookies']);
899
+	}
900
+	if ($secure === null) {
901
+			$secure = !empty($modSettings['secureCookies']);
902
+	}
859 903
 
860 904
 	// Intercept cookie?
861 905
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -875,8 +919,9 @@  discard block
 block discarded – undo
875 919
 function hash_password($username, $password, $cost = null)
876 920
 {
877 921
 	global $sourcedir, $smcFunc, $modSettings;
878
-	if (!function_exists('password_hash'))
879
-		require_once($sourcedir . '/Subs-Password.php');
922
+	if (!function_exists('password_hash')) {
923
+			require_once($sourcedir . '/Subs-Password.php');
924
+	}
880 925
 
881 926
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
882 927
 
@@ -908,8 +953,9 @@  discard block
 block discarded – undo
908 953
 function hash_verify_password($username, $password, $hash)
909 954
 {
910 955
 	global $sourcedir, $smcFunc;
911
-	if (!function_exists('password_verify'))
912
-		require_once($sourcedir . '/Subs-Password.php');
956
+	if (!function_exists('password_verify')) {
957
+			require_once($sourcedir . '/Subs-Password.php');
958
+	}
913 959
 
914 960
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
915 961
 }
Please login to merge, or discard this patch.
Sources/Display.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -899,13 +899,13 @@
 block discarded – undo
899 899
 		if ($start_char === 'C')
900 900
 			$limit_seek = $limit;
901 901
 		else
902
-			$limit_seek  = $limit + 1;
902
+			$limit_seek = $limit + 1;
903 903
 
904 904
 		$request = $smcFunc['db_query']('', '
905 905
 			SELECT id_msg, id_member, approved
906 906
 			FROM {db_prefix}messages
907 907
 			WHERE id_topic = {int:current_topic}
908
-			AND id_msg '. $page_operator . ' {int:page_id}'. (!$modSettings['postmod_active'] || $approve_posts ? '' : '
908
+			AND id_msg '. $page_operator . ' {int:page_id}' . (!$modSettings['postmod_active'] || $approve_posts ? '' : '
909 909
 			AND (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . '
910 910
 			ORDER BY id_msg ' . ($ascending_seek ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '
911 911
 			LIMIT {int:limit}'),
Please login to merge, or discard this patch.
Braces   +298 added lines, -219 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -365,9 +370,10 @@  discard block
 block discarded – undo
365 370
 		list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
366 371
 		$sig_limits = explode(',', $sig_limits);
367 372
 
368
-		if (!empty($sig_limits[5]) || !empty($sig_limits[6]))
369
-			addInlineCss('
373
+		if (!empty($sig_limits[5]) || !empty($sig_limits[6])) {
374
+					addInlineCss('
370 375
 	.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}');
376
+		}
371 377
 	}
372 378
 
373 379
 	// Censor the title...
@@ -405,21 +411,25 @@  discard block
 block discarded – undo
405 411
 		);
406 412
 		while ($row = $smcFunc['db_fetch_assoc']($request))
407 413
 		{
408
-			if (empty($row['id_member']))
409
-				continue;
414
+			if (empty($row['id_member'])) {
415
+							continue;
416
+			}
410 417
 
411
-			if (!empty($row['online_color']))
412
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
413
-			else
414
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
418
+			if (!empty($row['online_color'])) {
419
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
420
+			} else {
421
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
422
+			}
415 423
 
416 424
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
417
-			if ($is_buddy)
418
-				$link = '<strong>' . $link . '</strong>';
425
+			if ($is_buddy) {
426
+							$link = '<strong>' . $link . '</strong>';
427
+			}
419 428
 
420 429
 			// Add them both to the list and to the more detailed list.
421
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
422
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
430
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
431
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
432
+			}
423 433
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
424 434
 				'id' => $row['id_member'],
425 435
 				'username' => $row['member_name'],
@@ -431,8 +441,9 @@  discard block
 block discarded – undo
431 441
 				'hidden' => empty($row['show_online']),
432 442
 			);
433 443
 
434
-			if (empty($row['show_online']))
435
-				$context['view_num_hidden']++;
444
+			if (empty($row['show_online'])) {
445
+							$context['view_num_hidden']++;
446
+			}
436 447
 		}
437 448
 
438 449
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -446,11 +457,13 @@  discard block
 block discarded – undo
446 457
 
447 458
 	// If all is set, but not allowed... just unset it.
448 459
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
449
-	if (isset($_REQUEST['all']) && !$can_show_all)
450
-		unset($_REQUEST['all']);
460
+	if (isset($_REQUEST['all']) && !$can_show_all) {
461
+			unset($_REQUEST['all']);
462
+	}
451 463
 	// Otherwise, it must be allowed... so pretend start was -1.
452
-	elseif (isset($_REQUEST['all']))
453
-		$_REQUEST['start'] = -1;
464
+	elseif (isset($_REQUEST['all'])) {
465
+			$_REQUEST['start'] = -1;
466
+	}
454 467
 
455 468
 	// Construct the page index, allowing for the .START method...
456 469
 	$context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
@@ -487,8 +500,9 @@  discard block
 block discarded – undo
487 500
 			$_REQUEST['start'] = 0;
488 501
 		}
489 502
 		// They aren't using it, but the *option* is there, at least.
490
-		else
491
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
503
+		else {
504
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
505
+		}
492 506
 	}
493 507
 
494 508
 	// Build the link tree.
@@ -504,14 +518,16 @@  discard block
 block discarded – undo
504 518
 	if (!empty($board_info['moderators']))
505 519
 	{
506 520
 		// Add a link for each moderator...
507
-		foreach ($board_info['moderators'] as $mod)
508
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
521
+		foreach ($board_info['moderators'] as $mod) {
522
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
523
+		}
509 524
 	}
510 525
 	if (!empty($board_info['moderator_groups']))
511 526
 	{
512 527
 		// Add a link for each moderator group as well...
513
-		foreach ($board_info['moderator_groups'] as $mod_group)
514
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
528
+		foreach ($board_info['moderator_groups'] as $mod_group) {
529
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
530
+		}
515 531
 	}
516 532
 
517 533
 	if (!empty($context['link_moderators']))
@@ -542,9 +558,9 @@  discard block
 block discarded – undo
542 558
 	// For quick reply we need a response prefix in the default forum language.
543 559
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
544 560
 	{
545
-		if ($language === $user_info['language'])
546
-			$context['response_prefix'] = $txt['response_prefix'];
547
-		else
561
+		if ($language === $user_info['language']) {
562
+					$context['response_prefix'] = $txt['response_prefix'];
563
+		} else
548 564
 		{
549 565
 			loadLanguage('index', $language, false);
550 566
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -576,8 +592,9 @@  discard block
 block discarded – undo
576 592
 			list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
577 593
 
578 594
 			// Sanity check
579
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
580
-				continue;
595
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
596
+							continue;
597
+			}
581 598
 
582 599
 			$linked_calendar_event = array(
583 600
 				'id' => $row['id_event'],
@@ -626,8 +643,9 @@  discard block
 block discarded – undo
626 643
 		}
627 644
 		$smcFunc['db_free_result']($request);
628 645
 
629
-		if (!empty($context['linked_calendar_events']))
630
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
646
+		if (!empty($context['linked_calendar_events'])) {
647
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
648
+		}
631 649
 	}
632 650
 
633 651
 	// Create the poll info if it exists.
@@ -651,9 +669,9 @@  discard block
 block discarded – undo
651 669
 	}
652 670
 
653 671
 	// Create the poll info if it exists and is valid.
654
-	if ($context['is_poll'] && empty($pollinfo))
655
-		$context['is_poll'] = false;
656
-	elseif ($context['is_poll'])
672
+	if ($context['is_poll'] && empty($pollinfo)) {
673
+			$context['is_poll'] = false;
674
+	} elseif ($context['is_poll'])
657 675
 	{
658 676
 		$request = $smcFunc['db_query']('', '
659 677
 			SELECT COUNT(DISTINCT id_member) AS total
@@ -696,8 +714,9 @@  discard block
 block discarded – undo
696 714
 		$smcFunc['db_free_result']($request);
697 715
 
698 716
 		// Got we multi choice?
699
-		if ($pollinfo['max_votes'] > 1)
700
-			$realtotal = $pollinfo['total'];
717
+		if ($pollinfo['max_votes'] > 1) {
718
+					$realtotal = $pollinfo['total'];
719
+		}
701 720
 
702 721
 		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
703 722
 		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
@@ -710,20 +729,21 @@  discard block
 block discarded – undo
710 729
 				foreach ($guestinfo as $i => $guestvoted)
711 730
 				{
712 731
 					$guestvoted = explode(',', $guestvoted);
713
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
714
-						break;
732
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
733
+											break;
734
+					}
715 735
 				}
716 736
 				// Has the poll been reset since guest voted?
717 737
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
718 738
 				{
719 739
 					// Remove the poll info from the cookie to allow guest to vote again
720 740
 					unset($guestinfo[$i]);
721
-					if (!empty($guestinfo))
722
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
723
-					else
724
-						unset($_COOKIE['guest_poll_vote']);
725
-				}
726
-				else
741
+					if (!empty($guestinfo)) {
742
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
743
+					} else {
744
+											unset($_COOKIE['guest_poll_vote']);
745
+					}
746
+				} else
727 747
 				{
728 748
 					// What did they vote for?
729 749
 					unset($guestvoted[0], $guestvoted[1]);
@@ -837,23 +857,29 @@  discard block
 block discarded – undo
837 857
 		// Build the poll moderation button array.
838 858
 		$context['poll_buttons'] = array();
839 859
 
840
-		if ($context['allow_return_vote'])
841
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
860
+		if ($context['allow_return_vote']) {
861
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
862
+		}
842 863
 
843
-		if ($context['show_view_results_button'])
844
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
864
+		if ($context['show_view_results_button']) {
865
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
866
+		}
845 867
 
846
-		if ($context['allow_change_vote'])
847
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
868
+		if ($context['allow_change_vote']) {
869
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
870
+		}
848 871
 
849
-		if ($context['allow_lock_poll'])
850
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
872
+		if ($context['allow_lock_poll']) {
873
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
874
+		}
851 875
 
852
-		if ($context['allow_edit_poll'])
853
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
876
+		if ($context['allow_edit_poll']) {
877
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
878
+		}
854 879
 
855
-		if ($context['can_remove_poll'])
856
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
880
+		if ($context['can_remove_poll']) {
881
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
882
+		}
857 883
 
858 884
 		// Allow mods to add additional buttons here
859 885
 		call_integration_hook('integrate_poll_buttons');
@@ -889,9 +915,9 @@  discard block
 block discarded – undo
889 915
 	{
890 916
 		$start_char = 'C';
891 917
 		$page_id = $ascending ? $context['topicinfo']['id_first_msg'] : $context['topicinfo']['id_last_msg'];
918
+	} else {
919
+			$start_char = null;
892 920
 	}
893
-	else
894
-		$start_char = null;
895 921
 
896 922
 	$limit = $context['messages_per_page'];
897 923
 
@@ -905,17 +931,17 @@  discard block
 block discarded – undo
905 931
 		{
906 932
 			$ascending_seek = true;
907 933
 			$page_operator = $ascending ? '>=' : '<=';
908
-		}
909
-		else
934
+		} else
910 935
 		{
911 936
 			$ascending_seek = false;
912 937
 			$page_operator = $ascending ? '<=' : '>=';
913 938
 		}
914 939
 
915
-		if ($start_char === 'C')
916
-			$limit_seek = $limit;
917
-		else
918
-			$limit_seek  = $limit + 1;
940
+		if ($start_char === 'C') {
941
+					$limit_seek = $limit;
942
+		} else {
943
+					$limit_seek  = $limit + 1;
944
+		}
919 945
 
920 946
 		$request = $smcFunc['db_query']('', '
921 947
 			SELECT id_msg, id_member, approved
@@ -938,21 +964,23 @@  discard block
 block discarded – undo
938 964
 		$found_msg = false;
939 965
 
940 966
 		// Fallback
941
-		if ($smcFunc['db_num_rows']($request) < 1)
942
-			unset($start_char);
943
-		else
967
+		if ($smcFunc['db_num_rows']($request) < 1) {
968
+					unset($start_char);
969
+		} else
944 970
 		{
945 971
 			while ($row = $smcFunc['db_fetch_assoc']($request))
946 972
 			{
947 973
 				// Check if the start msg is in our result
948
-				if ($row['id_msg'] == $page_id)
949
-					$found_msg = true;
974
+				if ($row['id_msg'] == $page_id) {
975
+									$found_msg = true;
976
+				}
950 977
 
951 978
 				// Skip the the start msg if we not in mode C
952 979
 				if ($start_char === 'C' || $row['id_msg'] != $page_id)
953 980
 				{
954
-					if (!empty($row['id_member']))
955
-						$all_posters[$row['id_msg']] = $row['id_member'];
981
+					if (!empty($row['id_member'])) {
982
+											$all_posters[$row['id_msg']] = $row['id_member'];
983
+					}
956 984
 
957 985
 					$messages[] = $row['id_msg'];
958 986
 				}
@@ -968,8 +996,9 @@  discard block
 block discarded – undo
968 996
 		}
969 997
 
970 998
 		// Before Page bring in the right order
971
-		if (!empty($start_char) && $start_char === 'L')
972
-			krsort($messages);
999
+		if (!empty($start_char) && $start_char === 'L') {
1000
+					krsort($messages);
1001
+		}
973 1002
 	}
974 1003
 
975 1004
 	// Jump to page
@@ -1004,14 +1033,16 @@  discard block
 block discarded – undo
1004 1033
 
1005 1034
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1006 1035
 		{
1007
-			if (!empty($row['id_member']))
1008
-				$all_posters[$row['id_msg']] = $row['id_member'];
1036
+			if (!empty($row['id_member'])) {
1037
+							$all_posters[$row['id_msg']] = $row['id_member'];
1038
+			}
1009 1039
 			$messages[] = $row['id_msg'];
1010 1040
 		}
1011 1041
 
1012 1042
 		// Sort the messages into the correct display order
1013
-		if (!$ascending)
1014
-			sort($messages);
1043
+		if (!$ascending) {
1044
+					sort($messages);
1045
+		}
1015 1046
 	}
1016 1047
 
1017 1048
 	// Remember the paging data for next time
@@ -1031,8 +1062,9 @@  discard block
 block discarded – undo
1031 1062
 	if (!$user_info['is_guest'] && !empty($messages))
1032 1063
 	{
1033 1064
 		$mark_at_msg = max($messages);
1034
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
1035
-			$mark_at_msg = $modSettings['maxMsgID'];
1065
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
1066
+					$mark_at_msg = $modSettings['maxMsgID'];
1067
+		}
1036 1068
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
1037 1069
 		{
1038 1070
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -1064,8 +1096,9 @@  discard block
 block discarded – undo
1064 1096
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1065 1097
 		{
1066 1098
 			// Find if this topic is marked for notification...
1067
-			if (!empty($row['id_topic']))
1068
-				$context['is_marked_notify'] = true;
1099
+			if (!empty($row['id_topic'])) {
1100
+							$context['is_marked_notify'] = true;
1101
+			}
1069 1102
 
1070 1103
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
1071 1104
 			if (!empty($row['sent']) && $do_once)
@@ -1087,8 +1120,9 @@  discard block
 block discarded – undo
1087 1120
 		}
1088 1121
 
1089 1122
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
1090
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
1091
-			$_SESSION['topicseen_cache'][$board]--;
1123
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
1124
+					$_SESSION['topicseen_cache'][$board]--;
1125
+		}
1092 1126
 		// Mark board as seen if this is the only new topic.
1093 1127
 		elseif (isset($_REQUEST['topicseen']))
1094 1128
 		{
@@ -1112,14 +1146,16 @@  discard block
 block discarded – undo
1112 1146
 			$smcFunc['db_free_result']($request);
1113 1147
 
1114 1148
 			// If there're no real new topics in this board, mark the board as seen.
1115
-			if (empty($numNewTopics))
1116
-				$_REQUEST['boardseen'] = true;
1117
-			else
1118
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1149
+			if (empty($numNewTopics)) {
1150
+							$_REQUEST['boardseen'] = true;
1151
+			} else {
1152
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1153
+			}
1119 1154
 		}
1120 1155
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
1121
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
1122
-			$_SESSION['topicseen_cache'][$board]--;
1156
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1157
+					$_SESSION['topicseen_cache'][$board]--;
1158
+		}
1123 1159
 
1124 1160
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
1125 1161
 		if (isset($_REQUEST['boardseen']))
@@ -1176,23 +1212,26 @@  discard block
 block discarded – undo
1176 1212
 			$temp = array();
1177 1213
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1178 1214
 			{
1179
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1180
-					continue;
1215
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1216
+									continue;
1217
+				}
1181 1218
 
1182 1219
 				$temp[$row['id_attach']] = $row;
1183 1220
 				$temp[$row['id_attach']]['topic'] = $topic;
1184 1221
 				$temp[$row['id_attach']]['board'] = $board;
1185 1222
 
1186
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1187
-					$context['loaded_attachments'][$row['id_msg']] = array();
1223
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1224
+									$context['loaded_attachments'][$row['id_msg']] = array();
1225
+				}
1188 1226
 			}
1189 1227
 			$smcFunc['db_free_result']($request);
1190 1228
 
1191 1229
 			// This is better than sorting it with the query...
1192 1230
 			ksort($temp);
1193 1231
 
1194
-			foreach ($temp as $row)
1195
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1232
+			foreach ($temp as $row) {
1233
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1234
+			}
1196 1235
 		}
1197 1236
 
1198 1237
 		$msg_parameters = array(
@@ -1219,21 +1258,23 @@  discard block
 block discarded – undo
1219 1258
 		);
1220 1259
 
1221 1260
 		// And the likes
1222
-		if (!empty($modSettings['enable_likes']))
1223
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1261
+		if (!empty($modSettings['enable_likes'])) {
1262
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1263
+		}
1224 1264
 
1225 1265
 		// Go to the last message if the given time is beyond the time of the last message.
1226
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1227
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1266
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1267
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1268
+		}
1228 1269
 
1229 1270
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1230 1271
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1231
-		if (empty($options['view_newest_first']))
1232
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1233
-		else
1234
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1235
-	}
1236
-	else
1272
+		if (empty($options['view_newest_first'])) {
1273
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1274
+		} else {
1275
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1276
+		}
1277
+	} else
1237 1278
 	{
1238 1279
 		$messages_request = false;
1239 1280
 		$context['first_message'] = 0;
@@ -1268,8 +1309,9 @@  discard block
 block discarded – undo
1268 1309
 		'can_restore_msg' => 'move_any',
1269 1310
 		'can_like' => 'likes_like',
1270 1311
 	);
1271
-	foreach ($common_permissions as $contextual => $perm)
1272
-		$context[$contextual] = allowedTo($perm);
1312
+	foreach ($common_permissions as $contextual => $perm) {
1313
+			$context[$contextual] = allowedTo($perm);
1314
+	}
1273 1315
 
1274 1316
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1275 1317
 	$anyown_permissions = array(
@@ -1282,8 +1324,9 @@  discard block
 block discarded – undo
1282 1324
 		'can_reply_unapproved' => 'post_unapproved_replies',
1283 1325
 		'can_view_warning' => 'profile_warning',
1284 1326
 	);
1285
-	foreach ($anyown_permissions as $contextual => $perm)
1286
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1327
+	foreach ($anyown_permissions as $contextual => $perm) {
1328
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1329
+	}
1287 1330
 
1288 1331
 	if (!$user_info['is_admin'] && $context['can_move'] && !$modSettings['topic_move_any'])
1289 1332
 	{
@@ -1329,8 +1372,9 @@  discard block
 block discarded – undo
1329 1372
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1330 1373
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1331 1374
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1332
-	if (!empty($context['drafts_save']))
1333
-		loadLanguage('Drafts');
1375
+	if (!empty($context['drafts_save'])) {
1376
+			loadLanguage('Drafts');
1377
+	}
1334 1378
 
1335 1379
 	// When was the last time this topic was replied to?  Should we warn them about it?
1336 1380
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1391,26 +1435,31 @@  discard block
 block discarded – undo
1391 1435
 	// Message icons - customized icons are off?
1392 1436
 	$context['icons'] = getMessageIcons($board);
1393 1437
 
1394
-	if (!empty($context['icons']))
1395
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1438
+	if (!empty($context['icons'])) {
1439
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1440
+	}
1396 1441
 
1397 1442
 	// Build the normal button array.
1398 1443
 	$context['normal_buttons'] = array();
1399 1444
 
1400
-	if ($context['can_reply'])
1401
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1445
+	if ($context['can_reply']) {
1446
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1447
+	}
1402 1448
 
1403
-	if ($context['can_add_poll'])
1404
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1449
+	if ($context['can_add_poll']) {
1450
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1451
+	}
1405 1452
 
1406
-	if ($context['can_mark_unread'])
1407
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1453
+	if ($context['can_mark_unread']) {
1454
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1455
+	}
1408 1456
 
1409
-	if ($context['can_print'])
1410
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1457
+	if ($context['can_print']) {
1458
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1459
+	}
1411 1460
 
1412
-	if ($context['can_set_notify'])
1413
-		$context['normal_buttons']['notify'] = array(
1461
+	if ($context['can_set_notify']) {
1462
+			$context['normal_buttons']['notify'] = array(
1414 1463
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1415 1464
 			'sub_buttons' => array(
1416 1465
 				array(
@@ -1432,38 +1481,47 @@  discard block
 block discarded – undo
1432 1481
 				),
1433 1482
 			),
1434 1483
 		);
1484
+	}
1435 1485
 
1436 1486
 	// Build the mod button array
1437 1487
 	$context['mod_buttons'] = array();
1438 1488
 
1439
-	if ($context['can_move'])
1440
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1489
+	if ($context['can_move']) {
1490
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1491
+	}
1441 1492
 
1442
-	if ($context['can_delete'])
1443
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1493
+	if ($context['can_delete']) {
1494
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1495
+	}
1444 1496
 
1445
-	if ($context['can_lock'])
1446
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_locked'] ? 'unlock' : 'lock') . ';' . $context['session_var'] . '=' . $context['session_id']);
1497
+	if ($context['can_lock']) {
1498
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_locked'] ? 'unlock' : 'lock') . ';' . $context['session_var'] . '=' . $context['session_id']);
1499
+	}
1447 1500
 
1448
-	if ($context['can_sticky'])
1449
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_sticky'] ? 'nonsticky' : 'sticky') . ';' . $context['session_var'] . '=' . $context['session_id']);
1501
+	if ($context['can_sticky']) {
1502
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_sticky'] ? 'nonsticky' : 'sticky') . ';' . $context['session_var'] . '=' . $context['session_id']);
1503
+	}
1450 1504
 
1451
-	if ($context['can_merge'])
1452
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1505
+	if ($context['can_merge']) {
1506
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1507
+	}
1453 1508
 
1454
-	if ($context['calendar_post'])
1455
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1509
+	if ($context['calendar_post']) {
1510
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1511
+	}
1456 1512
 
1457 1513
 	// Restore topic. eh?  No monkey business.
1458
-	if ($context['can_restore_topic'])
1459
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1514
+	if ($context['can_restore_topic']) {
1515
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1516
+	}
1460 1517
 
1461 1518
 	// Show a message in case a recently posted message became unapproved.
1462 1519
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1463 1520
 
1464 1521
 	// Don't want to show this forever...
1465
-	if ($context['becomesUnapproved'])
1466
-		unset($_SESSION['becomesUnapproved']);
1522
+	if ($context['becomesUnapproved']) {
1523
+			unset($_SESSION['becomesUnapproved']);
1524
+	}
1467 1525
 
1468 1526
 	// Allow adding new mod buttons easily.
1469 1527
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1472,12 +1530,14 @@  discard block
 block discarded – undo
1472 1530
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1473 1531
 
1474 1532
 	// Load the drafts js file
1475
-	if ($context['drafts_autosave'])
1476
-		loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts');
1533
+	if ($context['drafts_autosave']) {
1534
+			loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts');
1535
+	}
1477 1536
 
1478 1537
 	// Spellcheck
1479
-	if ($context['show_spellchecking'])
1480
-		loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
1538
+	if ($context['show_spellchecking']) {
1539
+			loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
1540
+	}
1481 1541
 
1482 1542
 	// topic.js
1483 1543
 	loadJavaScriptFile('topic.js', array('defer' => false, 'minimize' => true), 'smf_topic');
@@ -1511,16 +1571,19 @@  discard block
 block discarded – undo
1511 1571
 	static $counter = null;
1512 1572
 
1513 1573
 	// If the query returned false, bail.
1514
-	if ($messages_request == false)
1515
-		return false;
1574
+	if ($messages_request == false) {
1575
+			return false;
1576
+	}
1516 1577
 
1517 1578
 	// Remember which message this is.  (ie. reply #83)
1518
-	if ($counter === null || $reset)
1519
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1579
+	if ($counter === null || $reset) {
1580
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1581
+	}
1520 1582
 
1521 1583
 	// Start from the beginning...
1522
-	if ($reset)
1523
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1584
+	if ($reset) {
1585
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1586
+	}
1524 1587
 
1525 1588
 	// Attempt to get the next message.
1526 1589
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1534,19 +1597,21 @@  discard block
 block discarded – undo
1534 1597
 	if (empty($context['icon_sources']))
1535 1598
 	{
1536 1599
 		$context['icon_sources'] = array();
1537
-		foreach ($context['stable_icons'] as $icon)
1538
-			$context['icon_sources'][$icon] = 'images_url';
1600
+		foreach ($context['stable_icons'] as $icon) {
1601
+					$context['icon_sources'][$icon] = 'images_url';
1602
+		}
1539 1603
 	}
1540 1604
 
1541 1605
 	// Message Icon Management... check the images exist.
1542 1606
 	if (empty($modSettings['messageIconChecks_disable']))
1543 1607
 	{
1544 1608
 		// If the current icon isn't known, then we need to do something...
1545
-		if (!isset($context['icon_sources'][$message['icon']]))
1546
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1609
+		if (!isset($context['icon_sources'][$message['icon']])) {
1610
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1611
+		}
1612
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1613
+			$context['icon_sources'][$message['icon']] = 'images_url';
1547 1614
 	}
1548
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1549
-		$context['icon_sources'][$message['icon']] = 'images_url';
1550 1615
 
1551 1616
 	// If you're a lazy bum, you probably didn't give a subject...
1552 1617
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1571,8 +1636,7 @@  discard block
 block discarded – undo
1571 1636
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1572 1637
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1573 1638
 		$memberContext[$message['id_member']]['is_guest'] = true;
1574
-	}
1575
-	else
1639
+	} else
1576 1640
 	{
1577 1641
 		// Define this here to make things a bit more readable
1578 1642
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1595,8 +1659,9 @@  discard block
 block discarded – undo
1595 1659
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1596 1660
 
1597 1661
 	// If it's in the recycle bin we need to override whatever icon we did have.
1598
-	if (!empty($board_info['recycle']))
1599
-		$message['icon'] = 'recycled';
1662
+	if (!empty($board_info['recycle'])) {
1663
+			$message['icon'] = 'recycled';
1664
+	}
1600 1665
 
1601 1666
 	require_once($sourcedir . '/Subs-Attachments.php');
1602 1667
 
@@ -1640,32 +1705,36 @@  discard block
 block discarded – undo
1640 1705
 	}
1641 1706
 
1642 1707
 	// Are likes enable?
1643
-	if (!empty($modSettings['enable_likes']))
1644
-		$output['likes'] = array(
1708
+	if (!empty($modSettings['enable_likes'])) {
1709
+			$output['likes'] = array(
1645 1710
 			'count' => $message['likes'],
1646 1711
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1647 1712
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1648 1713
 		);
1714
+	}
1649 1715
 
1650 1716
 	// Is this user the message author?
1651 1717
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1652
-	if (!empty($output['modified']['name']))
1653
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1718
+	if (!empty($output['modified']['name'])) {
1719
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1720
+	}
1654 1721
 
1655 1722
 	// Did they give a reason for editing?
1656
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1657
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1723
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1724
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1725
+	}
1658 1726
 
1659 1727
 	// Any custom profile fields?
1660
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1661
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1728
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1729
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1662 1730
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1731
+	}
1663 1732
 
1664
-	if (empty($options['view_newest_first']))
1665
-		$counter++;
1666
-
1667
-	else
1668
-		$counter--;
1733
+	if (empty($options['view_newest_first'])) {
1734
+			$counter++;
1735
+	} else {
1736
+			$counter--;
1737
+	}
1669 1738
 
1670 1739
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1671 1740
 
@@ -1691,8 +1760,9 @@  discard block
 block discarded – undo
1691 1760
  */
1692 1761
 function approved_attach_sort($a, $b)
1693 1762
 {
1694
-	if ($a['is_approved'] == $b['is_approved'])
1695
-		return 0;
1763
+	if ($a['is_approved'] == $b['is_approved']) {
1764
+			return 0;
1765
+	}
1696 1766
 
1697 1767
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1698 1768
 }
@@ -1709,16 +1779,19 @@  discard block
 block discarded – undo
1709 1779
 
1710 1780
 	require_once($sourcedir . '/RemoveTopic.php');
1711 1781
 
1712
-	if (empty($_REQUEST['msgs']))
1713
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1782
+	if (empty($_REQUEST['msgs'])) {
1783
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1784
+	}
1714 1785
 
1715 1786
 	$messages = array();
1716
-	foreach ($_REQUEST['msgs'] as $dummy)
1717
-		$messages[] = (int) $dummy;
1787
+	foreach ($_REQUEST['msgs'] as $dummy) {
1788
+			$messages[] = (int) $dummy;
1789
+	}
1718 1790
 
1719 1791
 	// We are restoring messages. We handle this in another place.
1720
-	if (isset($_REQUEST['restore_selected']))
1721
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1792
+	if (isset($_REQUEST['restore_selected'])) {
1793
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1794
+	}
1722 1795
 	if (isset($_REQUEST['split_selection']))
1723 1796
 	{
1724 1797
 		$request = $smcFunc['db_query']('', '
@@ -1737,8 +1810,9 @@  discard block
 block discarded – undo
1737 1810
 	}
1738 1811
 
1739 1812
 	// Allowed to delete any message?
1740
-	if (allowedTo('delete_any'))
1741
-		$allowed_all = true;
1813
+	if (allowedTo('delete_any')) {
1814
+			$allowed_all = true;
1815
+	}
1742 1816
 	// Allowed to delete replies to their messages?
1743 1817
 	elseif (allowedTo('delete_replies'))
1744 1818
 	{
@@ -1755,13 +1829,14 @@  discard block
 block discarded – undo
1755 1829
 		$smcFunc['db_free_result']($request);
1756 1830
 
1757 1831
 		$allowed_all = $starter == $user_info['id'];
1832
+	} else {
1833
+			$allowed_all = false;
1758 1834
 	}
1759
-	else
1760
-		$allowed_all = false;
1761 1835
 
1762 1836
 	// Make sure they're allowed to delete their own messages, if not any.
1763
-	if (!$allowed_all)
1764
-		isAllowedTo('delete_own');
1837
+	if (!$allowed_all) {
1838
+			isAllowedTo('delete_own');
1839
+	}
1765 1840
 
1766 1841
 	// Allowed to remove which messages?
1767 1842
 	$request = $smcFunc['db_query']('', '
@@ -1781,8 +1856,9 @@  discard block
 block discarded – undo
1781 1856
 	$messages = array();
1782 1857
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1783 1858
 	{
1784
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1785
-			continue;
1859
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1860
+					continue;
1861
+		}
1786 1862
 
1787 1863
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1788 1864
 	}
@@ -1805,17 +1881,20 @@  discard block
 block discarded – undo
1805 1881
 	foreach ($messages as $message => $info)
1806 1882
 	{
1807 1883
 		// Just skip the first message - if it's not the last.
1808
-		if ($message == $first_message && $message != $last_message)
1809
-			continue;
1884
+		if ($message == $first_message && $message != $last_message) {
1885
+					continue;
1886
+		}
1810 1887
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1811
-		elseif ($message == $first_message)
1812
-			$topicGone = true;
1888
+		elseif ($message == $first_message) {
1889
+					$topicGone = true;
1890
+		}
1813 1891
 
1814 1892
 		removeMessage($message);
1815 1893
 
1816 1894
 		// Log this moderation action ;).
1817
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1818
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1895
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1896
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1897
+		}
1819 1898
 	}
1820 1899
 
1821 1900
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Smileys/alienine/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Logging.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,21 +23,21 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return array The truncated array
25 25
  */
26
-function truncateArray($arr, $max_length=1900)
26
+function truncateArray($arr, $max_length = 1900)
27 27
 {
28 28
 	$curr_length = 0;
29 29
 	foreach ($arr as $key => $value)
30 30
 		if (is_array($value))
31 31
 			foreach ($value as $key2 => $value2)
32
-				$curr_length += strlen ($value2);
32
+				$curr_length += strlen($value2);
33 33
 		else
34
-			$curr_length += strlen ($value);
34
+			$curr_length += strlen($value);
35 35
 	if ($curr_length <= $max_length)
36 36
 		return $arr;
37 37
 	else
38 38
 	{
39 39
 		// Truncate each element's value to a reasonable length
40
-		$param_max = floor($max_length/count($arr));
40
+		$param_max = floor($max_length / count($arr));
41 41
 		foreach ($arr as $key => &$value)
42 42
 			if (is_array($value))
43 43
 				foreach ($value as $key2 => &$value2)
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	if (filemtime($cachedir . '/db_last_error.php') === $last_db_error_change)
208 208
 	{
209 209
 		// Write the change
210
-		$write_db_change =  '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>';
210
+		$write_db_change = '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>';
211 211
 		$written_bytes = file_put_contents($cachedir . '/db_last_error.php', $write_db_change, LOCK_EX);
212 212
 
213 213
 		// survey says ...
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 	', $txt['debug_language_files'], count($context['debug']['language_files']), ': <em>', implode('</em>, <em>', $context['debug']['language_files']), '</em>.<br>
281 281
 	', $txt['debug_stylesheets'], count($context['debug']['sheets']), ': <em>', implode('</em>, <em>', $context['debug']['sheets']), '</em>.<br>
282 282
 	', $txt['debug_hooks'], empty($context['debug']['hooks']) ? 0 : count($context['debug']['hooks']) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_hooks\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_hooks" style="display: none;"><em>' . implode('</em>, <em>', $context['debug']['hooks']), '</em></span>)', '<br>
283
-	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
283
+	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">' . $txt['debug_show'] . '</a><span id="debug_instances" style="display: none;"><em>' . implode('</em>, <em>', array_keys($context['debug']['instances'])) . '</em></span>)' . '<br>') : ''), '
284 284
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
285 285
 
286 286
 	if (function_exists('memory_get_peak_usage'))
Please login to merge, or discard this patch.
Braces   +154 added lines, -111 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Truncate the GET array to a specified length
@@ -26,24 +27,28 @@  discard block
 block discarded – undo
26 27
 function truncateArray($arr, $max_length=1900)
27 28
 {
28 29
 	$curr_length = 0;
29
-	foreach ($arr as $key => $value)
30
-		if (is_array($value))
30
+	foreach ($arr as $key => $value) {
31
+			if (is_array($value))
31 32
 			foreach ($value as $key2 => $value2)
32 33
 				$curr_length += strlen ($value2);
33
-		else
34
-			$curr_length += strlen ($value);
35
-	if ($curr_length <= $max_length)
36
-		return $arr;
37
-	else
34
+	}
35
+		else {
36
+					$curr_length += strlen ($value);
37
+		}
38
+	if ($curr_length <= $max_length) {
39
+			return $arr;
40
+	} else
38 41
 	{
39 42
 		// Truncate each element's value to a reasonable length
40 43
 		$param_max = floor($max_length/count($arr));
41
-		foreach ($arr as $key => &$value)
42
-			if (is_array($value))
44
+		foreach ($arr as $key => &$value) {
45
+					if (is_array($value))
43 46
 				foreach ($value as $key2 => &$value2)
44 47
 					$value2 = substr($value2, 0, $param_max - strlen($key) - 5);
45
-			else
46
-				$value = substr($value, 0, $param_max - strlen($key) - 5);
48
+		}
49
+			else {
50
+							$value = substr($value, 0, $param_max - strlen($key) - 5);
51
+			}
47 52
 		return $arr;
48 53
 	}
49 54
 }
@@ -65,8 +70,9 @@  discard block
 block discarded – undo
65 70
 		// Don't update for every page - this isn't wholly accurate but who cares.
66 71
 		if ($topic)
67 72
 		{
68
-			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic)
69
-				$force = false;
73
+			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) {
74
+							$force = false;
75
+			}
70 76
 			$_SESSION['last_topic_id'] = $topic;
71 77
 		}
72 78
 	}
@@ -79,22 +85,24 @@  discard block
 block discarded – undo
79 85
 	}
80 86
 
81 87
 	// Don't mark them as online more than every so often.
82
-	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force)
83
-		return;
88
+	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) {
89
+			return;
90
+	}
84 91
 
85 92
 	if (!empty($modSettings['who_enabled']))
86 93
 	{
87 94
 		$encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
88 95
 
89 96
 		// In the case of a dlattach action, session_var may not be set.
90
-		if (!isset($context['session_var']))
91
-			$context['session_var'] = $_SESSION['session_var'];
97
+		if (!isset($context['session_var'])) {
98
+					$context['session_var'] = $_SESSION['session_var'];
99
+		}
92 100
 
93 101
 		unset($encoded_get['sesc'], $encoded_get[$context['session_var']]);
94 102
 		$encoded_get = $smcFunc['json_encode']($encoded_get);
103
+	} else {
104
+			$encoded_get = '';
95 105
 	}
96
-	else
97
-		$encoded_get = '';
98 106
 
99 107
 	// Guests use 0, members use their session ID.
100 108
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
@@ -134,17 +142,18 @@  discard block
 block discarded – undo
134 142
 		);
135 143
 
136 144
 		// Guess it got deleted.
137
-		if ($smcFunc['db_affected_rows']() == 0)
145
+		if ($smcFunc['db_affected_rows']() == 0) {
146
+					$_SESSION['log_time'] = 0;
147
+		}
148
+	} else {
138 149
 			$_SESSION['log_time'] = 0;
139 150
 	}
140
-	else
141
-		$_SESSION['log_time'] = 0;
142 151
 
143 152
 	// Otherwise, we have to delete and insert.
144 153
 	if (empty($_SESSION['log_time']))
145 154
 	{
146
-		if ($do_delete || !empty($user_info['id']))
147
-			$smcFunc['db_query']('', '
155
+		if ($do_delete || !empty($user_info['id'])) {
156
+					$smcFunc['db_query']('', '
148 157
 				DELETE FROM {db_prefix}log_online
149 158
 				WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'),
150 159
 				array(
@@ -152,6 +161,7 @@  discard block
 block discarded – undo
152 161
 					'log_time' => time() - $modSettings['lastActive'] * 60,
153 162
 				)
154 163
 			);
164
+		}
155 165
 
156 166
 		$smcFunc['db_insert']($do_delete ? 'ignore' : 'replace',
157 167
 			'{db_prefix}log_online',
@@ -165,21 +175,24 @@  discard block
 block discarded – undo
165 175
 	$_SESSION['log_time'] = time();
166 176
 
167 177
 	// Well, they are online now.
168
-	if (empty($_SESSION['timeOnlineUpdated']))
169
-		$_SESSION['timeOnlineUpdated'] = time();
178
+	if (empty($_SESSION['timeOnlineUpdated'])) {
179
+			$_SESSION['timeOnlineUpdated'] = time();
180
+	}
170 181
 
171 182
 	// Set their login time, if not already done within the last minute.
172 183
 	if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa'))))
173 184
 	{
174 185
 		// Don't count longer than 15 minutes.
175
-		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
176
-			$_SESSION['timeOnlineUpdated'] = time();
186
+		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) {
187
+					$_SESSION['timeOnlineUpdated'] = time();
188
+		}
177 189
 
178 190
 		$user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
179 191
 		updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in']));
180 192
 
181
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
182
-			cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
193
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
194
+					cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
195
+		}
183 196
 
184 197
 		$user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
185 198
 		$_SESSION['timeOnlineUpdated'] = time();
@@ -216,8 +229,7 @@  discard block
 block discarded – undo
216 229
 			// Oops. maybe we have no more disk space left, or some other troubles, troubles...
217 230
 			// Copy the file back and run for your life!
218 231
 			@copy($cachedir . '/db_last_error_bak.php', $cachedir . '/db_last_error.php');
219
-		}
220
-		else
232
+		} else
221 233
 		{
222 234
 			@touch($boarddir . '/' . 'Settings.php');
223 235
 			return true;
@@ -237,22 +249,27 @@  discard block
 block discarded – undo
237 249
 	global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt;
238 250
 
239 251
 	// Add to Settings.php if you want to show the debugging information.
240
-	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery'))
241
-		return;
252
+	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) {
253
+			return;
254
+	}
242 255
 
243
-	if (empty($_SESSION['view_queries']))
244
-		$_SESSION['view_queries'] = 0;
245
-	if (empty($context['debug']['language_files']))
246
-		$context['debug']['language_files'] = array();
247
-	if (empty($context['debug']['sheets']))
248
-		$context['debug']['sheets'] = array();
256
+	if (empty($_SESSION['view_queries'])) {
257
+			$_SESSION['view_queries'] = 0;
258
+	}
259
+	if (empty($context['debug']['language_files'])) {
260
+			$context['debug']['language_files'] = array();
261
+	}
262
+	if (empty($context['debug']['sheets'])) {
263
+			$context['debug']['sheets'] = array();
264
+	}
249 265
 
250 266
 	$files = get_included_files();
251 267
 	$total_size = 0;
252 268
 	for ($i = 0, $n = count($files); $i < $n; $i++)
253 269
 	{
254
-		if (file_exists($files[$i]))
255
-			$total_size += filesize($files[$i]);
270
+		if (file_exists($files[$i])) {
271
+					$total_size += filesize($files[$i]);
272
+		}
256 273
 		$files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)'));
257 274
 	}
258 275
 
@@ -261,8 +278,9 @@  discard block
 block discarded – undo
261 278
 	{
262 279
 		foreach ($db_cache as $q => $query_data)
263 280
 		{
264
-			if (!empty($query_data['w']))
265
-				$warnings += count($query_data['w']);
281
+			if (!empty($query_data['w'])) {
282
+							$warnings += count($query_data['w']);
283
+			}
266 284
 		}
267 285
 
268 286
 		$_SESSION['debug'] = &$db_cache;
@@ -283,12 +301,14 @@  discard block
 block discarded – undo
283 301
 	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
284 302
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
285 303
 
286
-	if (function_exists('memory_get_peak_usage'))
287
-		echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
304
+	if (function_exists('memory_get_peak_usage')) {
305
+			echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
306
+	}
288 307
 
289 308
 	// What tokens are active?
290
-	if (isset($_SESSION['token']))
291
-		echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
309
+	if (isset($_SESSION['token'])) {
310
+			echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
311
+	}
292 312
 
293 313
 	if (!empty($modSettings['cache_enable']) && !empty($cache_hits))
294 314
 	{
@@ -302,10 +322,12 @@  discard block
 block discarded – undo
302 322
 			$total_t += $cache_hit['t'];
303 323
 			$total_s += $cache_hit['s'];
304 324
 		}
305
-		if (!isset($cache_misses))
306
-			$cache_misses = array();
307
-		foreach ($cache_misses as $missed)
308
-			$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
325
+		if (!isset($cache_misses)) {
326
+					$cache_misses = array();
327
+		}
328
+		foreach ($cache_misses as $missed) {
329
+					$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
330
+		}
309 331
 
310 332
 		echo '
311 333
 	', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br>
@@ -316,38 +338,44 @@  discard block
 block discarded – undo
316 338
 	<a href="', $scripturl, '?action=viewquery" target="_blank" rel="noopener">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br>
317 339
 	<br>';
318 340
 
319
-	if ($_SESSION['view_queries'] == 1 && !empty($db_cache))
320
-		foreach ($db_cache as $q => $query_data)
341
+	if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) {
342
+			foreach ($db_cache as $q => $query_data)
321 343
 		{
322 344
 			$is_select = strpos(trim($query_data['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($query_data['q'])) != 0;
345
+	}
323 346
 			// Temporary tables created in earlier queries are not explainable.
324 347
 			if ($is_select)
325 348
 			{
326
-				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp)
327
-					if (strpos(trim($query_data['q']), $tmp) !== false)
349
+				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
350
+									if (strpos(trim($query_data['q']), $tmp) !== false)
328 351
 					{
329 352
 						$is_select = false;
353
+				}
330 354
 						break;
331 355
 					}
332 356
 			}
333 357
 			// But actual creation of the temporary tables are.
334
-			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0)
335
-				$is_select = true;
358
+			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0) {
359
+							$is_select = true;
360
+			}
336 361
 
337 362
 			// Make the filenames look a bit better.
338
-			if (isset($query_data['f']))
339
-				$query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']);
363
+			if (isset($query_data['f'])) {
364
+							$query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']);
365
+			}
340 366
 
341 367
 			echo '
342 368
 	<strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" rel="noopener" style="text-decoration: none;">' : '', nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', $smcFunc['htmlspecialchars'](ltrim($query_data['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br>
343 369
 	&nbsp;&nbsp;&nbsp;';
344
-			if (!empty($query_data['f']) && !empty($query_data['l']))
345
-				echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']);
370
+			if (!empty($query_data['f']) && !empty($query_data['l'])) {
371
+							echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']);
372
+			}
346 373
 
347
-			if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at']))
348
-				echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>';
349
-			elseif (isset($query_data['t']))
350
-				echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>';
374
+			if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) {
375
+							echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>';
376
+			} elseif (isset($query_data['t'])) {
377
+							echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>';
378
+			}
351 379
 			echo '
352 380
 	<br>';
353 381
 		}
@@ -372,12 +400,14 @@  discard block
 block discarded – undo
372 400
 	global $modSettings, $smcFunc;
373 401
 	static $cache_stats = array();
374 402
 
375
-	if (empty($modSettings['trackStats']))
376
-		return false;
377
-	if (!empty($stats))
378
-		return $cache_stats = array_merge($cache_stats, $stats);
379
-	elseif (empty($cache_stats))
380
-		return false;
403
+	if (empty($modSettings['trackStats'])) {
404
+			return false;
405
+	}
406
+	if (!empty($stats)) {
407
+			return $cache_stats = array_merge($cache_stats, $stats);
408
+	} elseif (empty($cache_stats)) {
409
+			return false;
410
+	}
381 411
 
382 412
 	$setStringUpdate = '';
383 413
 	$insert_keys = array();
@@ -390,10 +420,11 @@  discard block
 block discarded – undo
390 420
 		$setStringUpdate .= '
391 421
 			' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ',';
392 422
 
393
-		if ($change === '+')
394
-			$cache_stats[$field] = 1;
395
-		else
396
-			$update_parameters[$field] = $change;
423
+		if ($change === '+') {
424
+					$cache_stats[$field] = 1;
425
+		} else {
426
+					$update_parameters[$field] = $change;
427
+		}
397 428
 		$insert_keys[$field] = 'int';
398 429
 	}
399 430
 
@@ -457,43 +488,50 @@  discard block
 block discarded – undo
457 488
 	);
458 489
 
459 490
 	// Make sure this particular log is enabled first...
460
-	if (empty($modSettings['modlog_enabled']))
461
-		unset ($log_types['moderate']);
462
-	if (empty($modSettings['userlog_enabled']))
463
-		unset ($log_types['user']);
464
-	if (empty($modSettings['adminlog_enabled']))
465
-		unset ($log_types['admin']);
491
+	if (empty($modSettings['modlog_enabled'])) {
492
+			unset ($log_types['moderate']);
493
+	}
494
+	if (empty($modSettings['userlog_enabled'])) {
495
+			unset ($log_types['user']);
496
+	}
497
+	if (empty($modSettings['adminlog_enabled'])) {
498
+			unset ($log_types['admin']);
499
+	}
466 500
 
467 501
 	call_integration_hook('integrate_log_types', array(&$log_types));
468 502
 
469 503
 	foreach ($logs as $log)
470 504
 	{
471
-		if (!isset($log_types[$log['log_type']]))
472
-			return false;
505
+		if (!isset($log_types[$log['log_type']])) {
506
+					return false;
507
+		}
473 508
 
474
-		if (!is_array($log['extra']))
475
-			trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
509
+		if (!is_array($log['extra'])) {
510
+					trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
511
+		}
476 512
 
477 513
 		// Pull out the parts we want to store separately, but also make sure that the data is proper
478 514
 		if (isset($log['extra']['topic']))
479 515
 		{
480
-			if (!is_numeric($log['extra']['topic']))
481
-				trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
516
+			if (!is_numeric($log['extra']['topic'])) {
517
+							trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
518
+			}
482 519
 			$topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic'];
483 520
 			unset($log['extra']['topic']);
521
+		} else {
522
+					$topic_id = 0;
484 523
 		}
485
-		else
486
-			$topic_id = 0;
487 524
 
488 525
 		if (isset($log['extra']['message']))
489 526
 		{
490
-			if (!is_numeric($log['extra']['message']))
491
-				trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
527
+			if (!is_numeric($log['extra']['message'])) {
528
+							trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
529
+			}
492 530
 			$msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message'];
493 531
 			unset($log['extra']['message']);
532
+		} else {
533
+					$msg_id = 0;
494 534
 		}
495
-		else
496
-			$msg_id = 0;
497 535
 
498 536
 		// @todo cache this?
499 537
 		// Is there an associated report on this?
@@ -520,23 +558,26 @@  discard block
 block discarded – undo
520 558
 			$smcFunc['db_free_result']($request);
521 559
 		}
522 560
 
523
-		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member']))
524
-			trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
561
+		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) {
562
+					trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
563
+		}
525 564
 
526 565
 		if (isset($log['extra']['board']))
527 566
 		{
528
-			if (!is_numeric($log['extra']['board']))
529
-				trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
567
+			if (!is_numeric($log['extra']['board'])) {
568
+							trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
569
+			}
530 570
 			$board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board'];
531 571
 			unset($log['extra']['board']);
572
+		} else {
573
+					$board_id = 0;
532 574
 		}
533
-		else
534
-			$board_id = 0;
535 575
 
536 576
 		if (isset($log['extra']['board_to']))
537 577
 		{
538
-			if (!is_numeric($log['extra']['board_to']))
539
-				trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
578
+			if (!is_numeric($log['extra']['board_to'])) {
579
+							trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
580
+			}
540 581
 			if (empty($board_id))
541 582
 			{
542 583
 				$board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to'];
@@ -544,15 +585,17 @@  discard block
 block discarded – undo
544 585
 			}
545 586
 		}
546 587
 
547
-		if (isset($log['extra']['member_affected']))
548
-			$memID = $log['extra']['member_affected'];
549
-		else
550
-			$memID = $user_info['id'];
588
+		if (isset($log['extra']['member_affected'])) {
589
+					$memID = $log['extra']['member_affected'];
590
+		} else {
591
+					$memID = $user_info['id'];
592
+		}
551 593
 		
552
-		if (isset($user_info['ip']))
553
-			$memIP = $user_info['ip'];
554
-		else
555
-			$memIP = 'null';
594
+		if (isset($user_info['ip'])) {
595
+					$memIP = $user_info['ip'];
596
+		} else {
597
+					$memIP = 'null';
598
+		}
556 599
 
557 600
 		$inserts[] = array(
558 601
 			time(), $log_types[$log['log_type']], $memID, $memIP, $log['action'],
Please login to merge, or discard this patch.
Sources/ManageMembers.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 			// INET.
361 361
 			elseif ($param_info['type'] == 'inet')
362 362
 			{
363
-				if(count($search_params[$param_name]) === 1)
363
+				if (count($search_params[$param_name]) === 1)
364 364
 				{
365 365
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' = {inet:' . $param_name . '})';
366 366
 					$where_params[$param_name] = $search_params[$param_name][0];
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
 				elseif (count($search_params[$param_name]) === 2)
369 369
 				{
370 370
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' <= {inet:' . $param_name . '_high} and ' . $param_info['db_fields'][0] . ' >= {inet:' . $param_name . '_low})';
371
-					$where_params[$param_name.'_low'] = $search_params[$param_name]['low'];
372
-					$where_params[$param_name.'_high'] = $search_params[$param_name]['high'];
371
+					$where_params[$param_name . '_low'] = $search_params[$param_name]['low'];
372
+					$where_params[$param_name . '_high'] = $search_params[$param_name]['high'];
373 373
 				}
374 374
 				
375 375
 			}
Please login to merge, or discard this patch.
Braces   +163 added lines, -122 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main entrance point for the Manage Members screen.
@@ -62,16 +63,18 @@  discard block
 block discarded – undo
62 63
 	$context['activation_numbers'] = array();
63 64
 	$context['awaiting_activation'] = 0;
64 65
 	$context['awaiting_approval'] = 0;
65
-	while ($row = $smcFunc['db_fetch_assoc']($request))
66
-		$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
66
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
67
+			$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
68
+	}
67 69
 	$smcFunc['db_free_result']($request);
68 70
 
69 71
 	foreach ($context['activation_numbers'] as $activation_type => $total_members)
70 72
 	{
71
-		if (in_array($activation_type, array(0, 2)))
72
-			$context['awaiting_activation'] += $total_members;
73
-		elseif (in_array($activation_type, array(3, 4, 5)))
74
-			$context['awaiting_approval'] += $total_members;
73
+		if (in_array($activation_type, array(0, 2))) {
74
+					$context['awaiting_activation'] += $total_members;
75
+		} elseif (in_array($activation_type, array(3, 4, 5))) {
76
+					$context['awaiting_approval'] += $total_members;
77
+		}
75 78
 	}
76 79
 
77 80
 	// For the page header... do we show activation?
@@ -124,8 +127,9 @@  discard block
 block discarded – undo
124 127
 	}
125 128
 	if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve'))
126 129
 	{
127
-		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate'))
128
-			$context['tabs']['search']['is_last'] = true;
130
+		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) {
131
+					$context['tabs']['search']['is_last'] = true;
132
+		}
129 133
 		unset($context['tabs']['approve']);
130 134
 	}
131 135
 
@@ -157,8 +161,9 @@  discard block
 block discarded – undo
157 161
 		foreach ($_POST['delete'] as $key => $value)
158 162
 		{
159 163
 			// Don't delete yourself, idiot.
160
-			if ($value != $user_info['id'])
161
-				$delete[$key] = (int) $value;
164
+			if ($value != $user_info['id']) {
165
+							$delete[$key] = (int) $value;
166
+			}
162 167
 		}
163 168
 
164 169
 		if (!empty($delete))
@@ -194,17 +199,18 @@  discard block
 block discarded – undo
194 199
 		);
195 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
196 201
 		{
197
-			if ($row['min_posts'] == -1)
198
-				$context['membergroups'][] = array(
202
+			if ($row['min_posts'] == -1) {
203
+							$context['membergroups'][] = array(
199 204
 					'id' => $row['id_group'],
200 205
 					'name' => $row['group_name'],
201 206
 					'can_be_additional' => true
202 207
 				);
203
-			else
204
-				$context['postgroups'][] = array(
208
+			} else {
209
+							$context['postgroups'][] = array(
205 210
 					'id' => $row['id_group'],
206 211
 					'name' => $row['group_name']
207 212
 				);
213
+			}
208 214
 		}
209 215
 		$smcFunc['db_free_result']($request);
210 216
 
@@ -276,14 +282,15 @@  discard block
 block discarded – undo
276 282
 		call_integration_hook('integrate_view_members_params', array(&$params));
277 283
 
278 284
 		$search_params = array();
279
-		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types']))
280
-			$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
281
-		elseif (!empty($_POST))
285
+		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) {
286
+					$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
287
+		} elseif (!empty($_POST))
282 288
 		{
283 289
 			$search_params['types'] = $_POST['types'];
284
-			foreach ($params as $param_name => $param_info)
285
-				if (isset($_POST[$param_name]))
290
+			foreach ($params as $param_name => $param_info) {
291
+							if (isset($_POST[$param_name]))
286 292
 					$search_params[$param_name] = $_POST[$param_name];
293
+			}
287 294
 		}
288 295
 
289 296
 		$search_url_params = isset($search_params) ? base64_encode($smcFunc['json_encode']($search_params)) : null;
@@ -296,34 +303,38 @@  discard block
 block discarded – undo
296 303
 		foreach ($params as $param_name => $param_info)
297 304
 		{
298 305
 			// Not filled in?
299
-			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '')
300
-				continue;
306
+			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') {
307
+							continue;
308
+			}
301 309
 
302 310
 			// Make sure numeric values are really numeric.
303
-			if (in_array($param_info['type'], array('int', 'age')))
304
-				$search_params[$param_name] = (int) $search_params[$param_name];
311
+			if (in_array($param_info['type'], array('int', 'age'))) {
312
+							$search_params[$param_name] = (int) $search_params[$param_name];
313
+			}
305 314
 			// Date values have to match the specified format.
306 315
 			elseif ($param_info['type'] == 'date')
307 316
 			{
308 317
 				// Check if this date format is valid.
309
-				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
310
-					continue;
318
+				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) {
319
+									continue;
320
+				}
311 321
 
312 322
 				$search_params[$param_name] = strtotime($search_params[$param_name]);
313
-			}
314
-			elseif ($param_info['type'] == 'inet')
323
+			} elseif ($param_info['type'] == 'inet')
315 324
 			{
316 325
 				$search_params[$param_name] = ip2range($search_params[$param_name]);
317
-				if (empty($search_params[$param_name]))
318
-					continue;
326
+				if (empty($search_params[$param_name])) {
327
+									continue;
328
+				}
319 329
 			}
320 330
 
321 331
 			// Those values that are in some kind of range (<, <=, =, >=, >).
322 332
 			if (!empty($param_info['range']))
323 333
 			{
324 334
 				// Default to '=', just in case...
325
-				if (empty($range_trans[$search_params['types'][$param_name]]))
326
-					$search_params['types'][$param_name] = '=';
335
+				if (empty($range_trans[$search_params['types'][$param_name]])) {
336
+									$search_params['types'][$param_name] = '=';
337
+				}
327 338
 
328 339
 				// Handle special case 'age'.
329 340
 				if ($param_info['type'] == 'age')
@@ -351,16 +362,17 @@  discard block
 block discarded – undo
351 362
 				elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=')
352 363
 				{
353 364
 					$query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400);
365
+				} else {
366
+									$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
354 367
 				}
355
-				else
356
-					$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
357 368
 			}
358 369
 			// Checkboxes.
359 370
 			elseif ($param_info['type'] == 'checkbox')
360 371
 			{
361 372
 				// Each checkbox or no checkbox at all is checked -> ignore.
362
-				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values']))
363
-					continue;
373
+				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) {
374
+									continue;
375
+				}
364 376
 
365 377
 				$query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})';
366 378
 				$where_params[$param_name . '_check'] = $search_params[$param_name];
@@ -372,24 +384,23 @@  discard block
 block discarded – undo
372 384
 				{
373 385
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' = {inet:' . $param_name . '})';
374 386
 					$where_params[$param_name] = $search_params[$param_name][0];
375
-				}
376
-				elseif (count($search_params[$param_name]) === 2)
387
+				} elseif (count($search_params[$param_name]) === 2)
377 388
 				{
378 389
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' <= {inet:' . $param_name . '_high} and ' . $param_info['db_fields'][0] . ' >= {inet:' . $param_name . '_low})';
379 390
 					$where_params[$param_name.'_low'] = $search_params[$param_name]['low'];
380 391
 					$where_params[$param_name.'_high'] = $search_params[$param_name]['high'];
381 392
 				}
382 393
 				
383
-			}
384
-			elseif ($param_info['type'] != 'groups')
394
+			} elseif ($param_info['type'] != 'groups')
385 395
 			{
386 396
 				// Replace the wildcard characters ('*' and '?') into MySQL ones.
387 397
 				$parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')));
388 398
 
389
-				if ($smcFunc['db_case_sensitive'])
390
-					$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
391
-				else
392
-					$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
399
+				if ($smcFunc['db_case_sensitive']) {
400
+									$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
401
+				} else {
402
+									$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
403
+				}
393 404
 				$where_params[$param_name . '_normal'] = '%' . $parameter . '%';
394 405
 			}
395 406
 		}
@@ -405,16 +416,18 @@  discard block
 block discarded – undo
405 416
 		}
406 417
 
407 418
 		// Additional membergroups (these are only relevant if not all primary groups where selected!).
408
-		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1])))
409
-			foreach ($search_params['membergroups'][2] as $mg)
419
+		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) {
420
+					foreach ($search_params['membergroups'][2] as $mg)
410 421
 			{
411 422
 				$mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0';
423
+		}
412 424
 				$where_params['add_group_' . $mg] = $mg;
413 425
 			}
414 426
 
415 427
 		// Combine the one or two membergroup parts into one query part linked with an OR.
416
-		if (!empty($mg_query_parts))
417
-			$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
428
+		if (!empty($mg_query_parts)) {
429
+					$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
430
+		}
418 431
 
419 432
 		// Get all selected post count related membergroups.
420 433
 		if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups']))
@@ -426,9 +439,9 @@  discard block
 block discarded – undo
426 439
 		// Construct the where part of the query.
427 440
 		$where = empty($query_parts) ? '1=1' : implode('
428 441
 			AND ', $query_parts);
442
+	} else {
443
+			$search_url_params = null;
429 444
 	}
430
-	else
431
-		$search_url_params = null;
432 445
 
433 446
 	// Construct the additional URL part with the query info in it.
434 447
 	$context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : '';
@@ -551,28 +564,32 @@  discard block
 block discarded – undo
551 564
 					'function' => function($rowData) use ($txt)
552 565
 					{
553 566
 						// Calculate number of days since last online.
554
-						if (empty($rowData['last_login']))
555
-							$difference = $txt['never'];
556
-						else
567
+						if (empty($rowData['last_login'])) {
568
+													$difference = $txt['never'];
569
+						} else
557 570
 						{
558 571
 							$num_days_difference = jeffsdatediff($rowData['last_login']);
559 572
 
560 573
 							// Today.
561
-							if (empty($num_days_difference))
562
-								$difference = $txt['viewmembers_today'];
574
+							if (empty($num_days_difference)) {
575
+															$difference = $txt['viewmembers_today'];
576
+							}
563 577
 
564 578
 							// Yesterday.
565
-							elseif ($num_days_difference == 1)
566
-								$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
579
+							elseif ($num_days_difference == 1) {
580
+															$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
581
+							}
567 582
 
568 583
 							// X days ago.
569
-							else
570
-								$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
584
+							else {
585
+															$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
586
+							}
571 587
 						}
572 588
 
573 589
 						// Show it in italics if they're not activated...
574
-						if ($rowData['is_activated'] % 10 != 1)
575
-							$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
590
+						if ($rowData['is_activated'] % 10 != 1) {
591
+													$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
592
+						}
576 593
 
577 594
 						return $difference;
578 595
 					},
@@ -624,8 +641,9 @@  discard block
 block discarded – undo
624 641
 	);
625 642
 
626 643
 	// Without enough permissions, don't show 'delete members' checkboxes.
627
-	if (!allowedTo('profile_remove_any'))
628
-		unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
644
+	if (!allowedTo('profile_remove_any')) {
645
+			unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
646
+	}
629 647
 
630 648
 	require_once($sourcedir . '/Subs-List.php');
631 649
 	createList($listOptions);
@@ -668,17 +686,18 @@  discard block
 block discarded – undo
668 686
 	);
669 687
 	while ($row = $smcFunc['db_fetch_assoc']($request))
670 688
 	{
671
-		if ($row['min_posts'] == -1)
672
-			$context['membergroups'][] = array(
689
+		if ($row['min_posts'] == -1) {
690
+					$context['membergroups'][] = array(
673 691
 				'id' => $row['id_group'],
674 692
 				'name' => $row['group_name'],
675 693
 				'can_be_additional' => true
676 694
 			);
677
-		else
678
-			$context['postgroups'][] = array(
695
+		} else {
696
+					$context['postgroups'][] = array(
679 697
 				'id' => $row['id_group'],
680 698
 				'name' => $row['group_name']
681 699
 			);
700
+		}
682 701
 	}
683 702
 	$smcFunc['db_free_result']($request);
684 703
 
@@ -705,8 +724,9 @@  discard block
 block discarded – undo
705 724
 	$context['page_title'] = $txt['admin_members'];
706 725
 	$context['sub_template'] = 'admin_browse';
707 726
 	$context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
708
-	if (isset($context['tabs'][$context['browse_type']]))
709
-		$context['tabs'][$context['browse_type']]['is_selected'] = true;
727
+	if (isset($context['tabs'][$context['browse_type']])) {
728
+			$context['tabs'][$context['browse_type']]['is_selected'] = true;
729
+	}
710 730
 
711 731
 	// Allowed filters are those we can have, in theory.
712 732
 	$context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
@@ -717,18 +737,20 @@  discard block
 block discarded – undo
717 737
 	foreach ($context['activation_numbers'] as $type => $amount)
718 738
 	{
719 739
 		// We have some of these...
720
-		if (in_array($type, $context['allowed_filters']) && $amount > 0)
721
-			$context['available_filters'][] = array(
740
+		if (in_array($type, $context['allowed_filters']) && $amount > 0) {
741
+					$context['available_filters'][] = array(
722 742
 				'type' => $type,
723 743
 				'amount' => $amount,
724 744
 				'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
725 745
 				'selected' => $type == $context['current_filter']
726 746
 			);
747
+		}
727 748
 	}
728 749
 
729 750
 	// If the filter was not sent, set it to whatever has people in it!
730
-	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
731
-		$context['current_filter'] = $context['available_filters'][0]['type'];
751
+	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) {
752
+			$context['current_filter'] = $context['available_filters'][0]['type'];
753
+	}
732 754
 
733 755
 	// This little variable is used to determine if we should flag where we are looking.
734 756
 	$context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
@@ -743,44 +765,47 @@  discard block
 block discarded – undo
743 765
 	);
744 766
 
745 767
 	// Are we showing duplicate information?
746
-	if (isset($_GET['showdupes']))
747
-		$_SESSION['showdupes'] = (int) $_GET['showdupes'];
768
+	if (isset($_GET['showdupes'])) {
769
+			$_SESSION['showdupes'] = (int) $_GET['showdupes'];
770
+	}
748 771
 	$context['show_duplicates'] = !empty($_SESSION['showdupes']);
749 772
 
750 773
 	// Determine which actions we should allow on this page.
751 774
 	if ($context['browse_type'] == 'approve')
752 775
 	{
753 776
 		// If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
754
-		if ($context['current_filter'] == 4)
755
-			$context['allowed_actions'] = array(
777
+		if ($context['current_filter'] == 4) {
778
+					$context['allowed_actions'] = array(
756 779
 				'reject' => $txt['admin_browse_w_approve_deletion'],
757 780
 				'ok' => $txt['admin_browse_w_reject'],
758 781
 			);
759
-		else
760
-			$context['allowed_actions'] = array(
782
+		} else {
783
+					$context['allowed_actions'] = array(
761 784
 				'ok' => $txt['admin_browse_w_approve'],
762 785
 				'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
763 786
 				'require_activation' => $txt['admin_browse_w_approve_require_activate'],
764 787
 				'reject' => $txt['admin_browse_w_reject'],
765 788
 				'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
766 789
 			);
767
-	}
768
-	elseif ($context['browse_type'] == 'activate')
769
-		$context['allowed_actions'] = array(
790
+		}
791
+	} elseif ($context['browse_type'] == 'activate') {
792
+			$context['allowed_actions'] = array(
770 793
 			'ok' => $txt['admin_browse_w_activate'],
771 794
 			'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
772 795
 			'delete' => $txt['admin_browse_w_delete'],
773 796
 			'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
774 797
 			'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
775 798
 		);
799
+	}
776 800
 
777 801
 	// Create an option list for actions allowed to be done with selected members.
778 802
 	$allowed_actions = '
779 803
 			<option selected value="">' . $txt['admin_browse_with_selected'] . ':</option>
780 804
 			<option value="" disabled>-----------------------------</option>';
781
-	foreach ($context['allowed_actions'] as $key => $desc)
782
-		$allowed_actions .= '
805
+	foreach ($context['allowed_actions'] as $key => $desc) {
806
+			$allowed_actions .= '
783 807
 			<option value="' . $key . '">' . $desc . '</option>';
808
+	}
784 809
 
785 810
 	// Setup the Javascript function for selecting an action for the list.
786 811
 	$javascript = '
@@ -792,15 +817,16 @@  discard block
 block discarded – undo
792 817
 			var message = "";';
793 818
 
794 819
 	// We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
795
-	if ($context['current_filter'] == 4)
796
-		$javascript .= '
820
+	if ($context['current_filter'] == 4) {
821
+			$javascript .= '
797 822
 			if (document.forms.postForm.todo.value.indexOf("reject") != -1)
798 823
 				message = "' . $txt['admin_browse_w_delete'] . '";
799 824
 			else
800 825
 				message = "' . $txt['admin_browse_w_reject'] . '";';
826
+	}
801 827
 	// Otherwise a nice standard message.
802
-	else
803
-		$javascript .= '
828
+	else {
829
+			$javascript .= '
804 830
 			if (document.forms.postForm.todo.value.indexOf("delete") != -1)
805 831
 				message = "' . $txt['admin_browse_w_delete'] . '";
806 832
 			else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
@@ -809,6 +835,7 @@  discard block
 block discarded – undo
809 835
 				message = "' . $txt['admin_browse_w_remind'] . '";
810 836
 			else
811 837
 				message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
838
+	}
812 839
 	$javascript .= '
813 840
 			if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
814 841
 				document.forms.postForm.submit();
@@ -941,10 +968,11 @@  discard block
 block discarded – undo
941 968
 						$member_links = array();
942 969
 						foreach ($rowData['duplicate_members'] as $member)
943 970
 						{
944
-							if ($member['id'])
945
-								$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
946
-							else
947
-								$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
971
+							if ($member['id']) {
972
+															$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
973
+							} else {
974
+															$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
975
+							}
948 976
 						}
949 977
 						return implode(', ', $member_links);
950 978
 					},
@@ -993,14 +1021,16 @@  discard block
 block discarded – undo
993 1021
 	);
994 1022
 
995 1023
 	// Pick what column to actually include if we're showing duplicates.
996
-	if ($context['show_duplicates'])
997
-		unset($listOptions['columns']['email']);
998
-	else
999
-		unset($listOptions['columns']['duplicates']);
1024
+	if ($context['show_duplicates']) {
1025
+			unset($listOptions['columns']['email']);
1026
+	} else {
1027
+			unset($listOptions['columns']['duplicates']);
1028
+	}
1000 1029
 
1001 1030
 	// Only show hostname on duplicates as it takes a lot of time.
1002
-	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
1003
-		unset($listOptions['columns']['hostname']);
1031
+	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) {
1032
+			unset($listOptions['columns']['hostname']);
1033
+	}
1004 1034
 
1005 1035
 	// Is there any need to show filters?
1006 1036
 	if (isset($context['available_filters']) && count($context['available_filters']) > 1)
@@ -1008,9 +1038,10 @@  discard block
 block discarded – undo
1008 1038
 		$filterOptions = '
1009 1039
 			<strong>' . $txt['admin_browse_filter_by'] . ':</strong>
1010 1040
 			<select name="filter" onchange="this.form.submit();">';
1011
-		foreach ($context['available_filters'] as $filter)
1012
-			$filterOptions .= '
1041
+		foreach ($context['available_filters'] as $filter) {
1042
+					$filterOptions .= '
1013 1043
 				<option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
1044
+		}
1014 1045
 		$filterOptions .= '
1015 1046
 			</select>
1016 1047
 			<noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button"></noscript>';
@@ -1022,12 +1053,13 @@  discard block
 block discarded – undo
1022 1053
 	}
1023 1054
 
1024 1055
 	// What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
1025
-	if (!empty($context['show_filter']) && !empty($context['available_filters']))
1026
-		$listOptions['additional_rows'][] = array(
1056
+	if (!empty($context['show_filter']) && !empty($context['available_filters'])) {
1057
+			$listOptions['additional_rows'][] = array(
1027 1058
 			'position' => 'above_column_headers',
1028 1059
 			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'],
1029 1060
 			'class' => 'smalltext floatright',
1030 1061
 		);
1062
+	}
1031 1063
 
1032 1064
 	// Now that we have all the options, create the list.
1033 1065
 	require_once($sourcedir . '/Subs-List.php');
@@ -1057,12 +1089,14 @@  discard block
 block discarded – undo
1057 1089
 	$current_filter = (int) $_REQUEST['orig_filter'];
1058 1090
 
1059 1091
 	// If we are applying a filter do just that - then redirect.
1060
-	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
1061
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1092
+	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) {
1093
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1094
+	}
1062 1095
 
1063 1096
 	// Nothing to do?
1064
-	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
1065
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1097
+	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) {
1098
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1099
+	}
1066 1100
 
1067 1101
 	// Are we dealing with members who have been waiting for > set amount of time?
1068 1102
 	if (isset($_POST['time_passed']))
@@ -1075,8 +1109,9 @@  discard block
 block discarded – undo
1075 1109
 	else
1076 1110
 	{
1077 1111
 		$members = array();
1078
-		foreach ($_POST['todoAction'] as $id)
1079
-			$members[] = (int) $id;
1112
+		foreach ($_POST['todoAction'] as $id) {
1113
+					$members[] = (int) $id;
1114
+		}
1080 1115
 		$condition = '
1081 1116
 			AND id_member IN ({array_int:members})';
1082 1117
 	}
@@ -1097,8 +1132,9 @@  discard block
 block discarded – undo
1097 1132
 	$member_count = $smcFunc['db_num_rows']($request);
1098 1133
 
1099 1134
 	// If no results then just return!
1100
-	if ($member_count == 0)
1101
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1135
+	if ($member_count == 0) {
1136
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1137
+	}
1102 1138
 
1103 1139
 	$member_info = array();
1104 1140
 	$members = array();
@@ -1137,8 +1173,9 @@  discard block
 block discarded – undo
1137 1173
 		// Do we have to let the integration code know about the activations?
1138 1174
 		if (!empty($modSettings['integrate_activate']))
1139 1175
 		{
1140
-			foreach ($member_info as $member)
1141
-				call_integration_hook('integrate_activate', array($member['username']));
1176
+			foreach ($member_info as $member) {
1177
+							call_integration_hook('integrate_activate', array($member['username']));
1178
+			}
1142 1179
 		}
1143 1180
 
1144 1181
 		// Check for email.
@@ -1268,20 +1305,23 @@  discard block
 block discarded – undo
1268 1305
 		$log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member';
1269 1306
 
1270 1307
 		require_once($sourcedir . '/Logging.php');
1271
-		foreach ($member_info as $member)
1272
-			logAction($log_action, array('member' => $member['id']), 'admin');
1308
+		foreach ($member_info as $member) {
1309
+					logAction($log_action, array('member' => $member['id']), 'admin');
1310
+		}
1273 1311
 	}
1274 1312
 
1275 1313
 	// Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
1276
-	if (in_array($current_filter, array(3, 4, 5)))
1277
-		updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1314
+	if (in_array($current_filter, array(3, 4, 5))) {
1315
+			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1316
+	}
1278 1317
 
1279 1318
 	// Update the member's stats. (but, we know the member didn't change their name.)
1280 1319
 	updateStats('member', false);
1281 1320
 
1282 1321
 	// If they haven't been deleted, update the post group statistics on them...
1283
-	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
1284
-		updateStats('postgroups', $members);
1322
+	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) {
1323
+			updateStats('postgroups', $members);
1324
+	}
1285 1325
 
1286 1326
 	redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1287 1327
 }
@@ -1306,10 +1346,11 @@  discard block
 block discarded – undo
1306 1346
 	$dis = time() - $old;
1307 1347
 
1308 1348
 	// Before midnight?
1309
-	if ($dis < $sinceMidnight)
1310
-		return 0;
1311
-	else
1312
-		$dis -= $sinceMidnight;
1349
+	if ($dis < $sinceMidnight) {
1350
+			return 0;
1351
+	} else {
1352
+			$dis -= $sinceMidnight;
1353
+	}
1313 1354
 
1314 1355
 	// Divide out the seconds in a day to get the number of days.
1315 1356
 	return ceil($dis / (24 * 60 * 60));
Please login to merge, or discard this patch.
Packages/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
cron.php 1 patch
Braces   +36 added lines, -28 removed lines patch added patch discarded remove patch
@@ -41,37 +41,43 @@  discard block
 block discarded – undo
41 41
 define('TIME_START', microtime(true));
42 42
 
43 43
 // Just being safe...
44
-foreach (array('db_character_set', 'cachedir') as $variable)
44
+foreach (array('db_character_set', 'cachedir') as $variable) {
45 45
 	if (isset($GLOBALS[$variable]))
46 46
 		unset($GLOBALS[$variable]);
47
+}
47 48
 
48 49
 // Get the forum's settings for database and file paths.
49 50
 require_once(dirname(__FILE__) . '/Settings.php');
50 51
 
51 52
 // Make absolutely sure the cache directory is defined.
52
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
53
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
53 54
 	$cachedir = $boarddir . '/cache';
55
+}
54 56
 
55 57
 // Don't do john didley if the forum's been shut down competely.
56
-if ($maintenance == 2)
58
+if ($maintenance == 2) {
57 59
 	die($mmessage);
60
+}
58 61
 
59 62
 // Fix for using the current directory as a path.
60
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
63
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
61 64
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
65
+}
62 66
 
63 67
 // Have we already turned this off? If so, exist gracefully.
64
-if (file_exists($cachedir . '/cron.lock'))
68
+if (file_exists($cachedir . '/cron.lock')) {
65 69
 	obExit_cron();
70
+}
66 71
 
67 72
 // Before we go any further, if this is not a CLI request, we need to do some checking.
68 73
 if (!FROM_CLI)
69 74
 {
70 75
 	// We will clean up $_GET shortly. But we want to this ASAP.
71 76
 	$ts = isset($_GET['ts']) ? (int) $_GET['ts'] : 0;
72
-	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20)
73
-		obExit_cron();
74
-}
77
+	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) {
78
+			obExit_cron();
79
+	}
80
+	}
75 81
 
76 82
 // Load the most important includes. In general, a background should be loading its own dependencies.
77 83
 require_once($sourcedir . '/Errors.php');
@@ -123,8 +129,9 @@  discard block
 block discarded – undo
123 129
 	global $smcFunc;
124 130
 
125 131
 	// Check we haven't run over our time limit.
126
-	if (microtime(true) - TIME_START > MAX_CRON_TIME)
127
-		return false;
132
+	if (microtime(true) - TIME_START > MAX_CRON_TIME) {
133
+			return false;
134
+	}
128 135
 
129 136
 	// Try to find a task. Specifically, try to find one that hasn't been claimed previously, or failing that,
130 137
 	// a task that was claimed but failed for whatever reason and failed long enough ago. We should not care
@@ -159,14 +166,12 @@  discard block
 block discarded – undo
159 166
 			// Update the time and go back.
160 167
 			$row['claimed_time'] = time();
161 168
 			return $row;
162
-		}
163
-		else
169
+		} else
164 170
 		{
165 171
 			// Uh oh, we just missed it. Try to claim another one, and let it fall through if there aren't any.
166 172
 			return fetch_task();
167 173
 		}
168
-	}
169
-	else
174
+	} else
170 175
 	{
171 176
 		// No dice. Clean up and go home.
172 177
 		$smcFunc['db_free_result']($request);
@@ -187,8 +192,9 @@  discard block
 block discarded – undo
187 192
 	if (!empty($task_details['task_file']))
188 193
 	{
189 194
 		$include = strtr(trim($task_details['task_file']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
190
-		if (file_exists($include))
191
-			require_once($include);
195
+		if (file_exists($include)) {
196
+					require_once($include);
197
+		}
192 198
 	}
193 199
 
194 200
 	if (empty($task_details['task_class']))
@@ -204,8 +210,7 @@  discard block
 block discarded – undo
204 210
 		$details = empty($task_details['task_data']) ? array() : $smcFunc['json_decode']($task_details['task_data'], true);
205 211
 		$bgtask = new $task_details['task_class']($details);
206 212
 		return $bgtask->execute();
207
-	}
208
-	else
213
+	} else
209 214
 	{
210 215
 		log_error('Invalid background task specified: (class: ' . $task_details['task_class'] . ', ' . (empty($task_details['task_file']) ? ' no file' : ' to load ' . $task_details['task_file']) . ')');
211 216
 		return true; // So we clear it from the queue.
@@ -224,8 +229,9 @@  discard block
 block discarded – undo
224 229
 	$scripturl = $boardurl . '/index.php';
225 230
 
226 231
 	// These keys shouldn't be set...ever.
227
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
228
-		die('Invalid request variable.');
232
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
233
+			die('Invalid request variable.');
234
+	}
229 235
 
230 236
 	// Save some memory.. (since we don't use these anyway.)
231 237
 	unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']);
@@ -246,26 +252,28 @@  discard block
 block discarded – undo
246 252
 	global $modSettings;
247 253
 
248 254
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5
249
-	if (error_reporting() == 0)
250
-		return;
255
+	if (error_reporting() == 0) {
256
+			return;
257
+	}
251 258
 
252 259
 	$error_type = 'cron';
253 260
 
254 261
 	log_error($error_level . ': ' . $error_string, $error_type, $file, $line);
255 262
 
256 263
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
257
-	if ($error_level % 255 == E_ERROR)
258
-		die('No direct access...');
259
-}
264
+	if ($error_level % 255 == E_ERROR) {
265
+			die('No direct access...');
266
+	}
267
+	}
260 268
 
261 269
 /**
262 270
  * The exit function
263 271
  */
264 272
 function obExit_cron()
265 273
 {
266
-	if (FROM_CLI)
267
-		die(0);
268
-	else
274
+	if (FROM_CLI) {
275
+			die(0);
276
+	} else
269 277
 	{
270 278
 		header('content-type: image/gif');
271 279
 		die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
Please login to merge, or discard this patch.
Sources/Attachments.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 		// Just send a generic message.
77 77
 		else
78 78
 			$this->setResponse(array(
79
-				'text' => $this->_sa == 'add' ? 'attach_error_title' :   'attached_file_deleted_error',
79
+				'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error',
80 80
 				'type' => 'error',
81 81
 				'data' => false,
82 82
 			));
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 			// Gotta urlencode the filename.
411 411
 			if ($this->_attachResults)
412 412
 				foreach ($this->_attachResults as $k => $v)
413
-					$this->_attachResults[$k]['name'] =  urlencode($this->_attachResults[$k]['name']);
413
+					$this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']);
414 414
 
415 415
 			$this->_response = array(
416 416
 				'files' => $this->_attachResults ? $this->_attachResults : false,
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 			ob_start();
438 438
 
439 439
 		// Set the header.
440
-		header('content-type: application/json; charset='. $context['character_set'] .'');
440
+		header('content-type: application/json; charset=' . $context['character_set'] . '');
441 441
 
442 442
 		echo $smcFunc['json_encode']($this->_response ? $this->_response : array());
443 443
 
Please login to merge, or discard this patch.
Braces   +102 added lines, -75 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 class Attachments
20 21
 {
@@ -70,16 +71,18 @@  discard block
 block discarded – undo
70 71
 
71 72
 		$this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false;
72 73
 
73
-		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions))
74
-			$this->{$this->_sa}();
74
+		if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) {
75
+					$this->{$this->_sa}();
76
+		}
75 77
 
76 78
 		// Just send a generic message.
77
-		else
78
-			$this->setResponse(array(
79
+		else {
80
+					$this->setResponse(array(
79 81
 				'text' => $this->_sa == 'add' ? 'attach_error_title' :   'attached_file_deleted_error',
80 82
 				'type' => 'error',
81 83
 				'data' => false,
82 84
 			));
85
+		}
83 86
 
84 87
 		// Back to the future, oh, to the browser!
85 88
 		$this->sendResponse();
@@ -95,12 +98,13 @@  discard block
 block discarded – undo
95 98
 		$attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0;
96 99
 
97 100
 		// Need something to work with.
98
-		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID])))
99
-			return $this->setResponse(array(
101
+		if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) {
102
+					return $this->setResponse(array(
100 103
 				'text' => 'attached_file_deleted_error',
101 104
 				'type' => 'error',
102 105
 				'data' => false,
103 106
 			));
107
+		}
104 108
 
105 109
 		// Lets pass some params and see what happens :P
106 110
 		$affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true);
@@ -119,19 +123,21 @@  discard block
 block discarded – undo
119 123
 	public function add()
120 124
 	{
121 125
 		// You gotta be able to post attachments.
122
-		if (!$this->_canPostAttachment)
123
-			return $this->setResponse(array(
126
+		if (!$this->_canPostAttachment) {
127
+					return $this->setResponse(array(
124 128
 				'text' => 'attached_file_cannot',
125 129
 				'type' => 'error',
126 130
 				'data' => false,
127 131
 			));
132
+		}
128 133
 
129 134
 		// Process them at once!
130 135
 		$this->processAttachments();
131 136
 
132 137
 		// The attachments was created and moved the the right folder, time to update the DB.
133
-		if (!empty($_SESSION['temp_attachments']))
134
-			$this->createAtttach();
138
+		if (!empty($_SESSION['temp_attachments'])) {
139
+					$this->createAtttach();
140
+		}
135 141
 
136 142
 		// Set the response.
137 143
 		$this->setResponse();
@@ -144,8 +150,9 @@  discard block
 block discarded – undo
144 150
 	{
145 151
 		global $context, $modSettings, $smcFunc, $user_info, $txt;
146 152
 
147
-		if (!isset($_FILES['attachment']['name']))
148
-			$_FILES['attachment']['tmp_name'] = array();
153
+		if (!isset($_FILES['attachment']['name'])) {
154
+					$_FILES['attachment']['tmp_name'] = array();
155
+		}
149 156
 
150 157
 		// If there are attachments, calculate the total size and how many.
151 158
 		$context['attachments']['total_size'] = 0;
@@ -155,25 +162,30 @@  discard block
 block discarded – undo
155 162
 		if (isset($_REQUEST['msg']))
156 163
 		{
157 164
 			$context['attachments']['quantity'] = count($context['current_attachments']);
158
-			foreach ($context['current_attachments'] as $attachment)
159
-				$context['attachments']['total_size'] += $attachment['size'];
165
+			foreach ($context['current_attachments'] as $attachment) {
166
+							$context['attachments']['total_size'] += $attachment['size'];
167
+			}
160 168
 		}
161 169
 
162 170
 		// A bit of house keeping first.
163
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
164
-			unset($_SESSION['temp_attachments']);
171
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
172
+					unset($_SESSION['temp_attachments']);
173
+		}
165 174
 
166 175
 		// Our infamous SESSION var, we are gonna have soo much fun with it!
167
-		if (!isset($_SESSION['temp_attachments']))
168
-			$_SESSION['temp_attachments'] = array();
176
+		if (!isset($_SESSION['temp_attachments'])) {
177
+					$_SESSION['temp_attachments'] = array();
178
+		}
169 179
 
170 180
 		// Make sure we're uploading to the right place.
171
-		if (!empty($modSettings['automanage_attachments']))
172
-			automanage_attachments_check_directory();
181
+		if (!empty($modSettings['automanage_attachments'])) {
182
+					automanage_attachments_check_directory();
183
+		}
173 184
 
174 185
 		// Is the attachments folder actually there?
175
-		if (!empty($context['dir_creation_error']))
176
-			$this->_generalErrors[] = $context['dir_creation_error'];
186
+		if (!empty($context['dir_creation_error'])) {
187
+					$this->_generalErrors[] = $context['dir_creation_error'];
188
+		}
177 189
 
178 190
 		// The current attach folder ha some issues...
179 191
 		elseif (!is_dir($this->_attchDir))
@@ -198,13 +210,12 @@  discard block
 block discarded – undo
198 210
 			);
199 211
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
200 212
 			$smcFunc['db_free_result']($request);
201
-		}
202
-
203
-		else
204
-			$context['attachments'] = array(
213
+		} else {
214
+					$context['attachments'] = array(
205 215
 				'quantity' => 0,
206 216
 				'total_size' => 0,
207 217
 			);
218
+		}
208 219
 
209 220
 		// Check for other general errors here.
210 221
 
@@ -212,9 +223,10 @@  discard block
 block discarded – undo
212 223
 		if (!empty($this->_generalErrors))
213 224
 		{
214 225
 			// And delete the files 'cos they ain't going nowhere.
215
-			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
216
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
226
+			foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
227
+							if (file_exists($_FILES['attachment']['tmp_name'][$n]))
217 228
 					unlink($_FILES['attachment']['tmp_name'][$n]);
229
+			}
218 230
 
219 231
 			$_FILES['attachment']['tmp_name'] = array();
220 232
 
@@ -225,26 +237,29 @@  discard block
 block discarded – undo
225 237
 		// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
226 238
 		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
227 239
 		{
228
-			if ($_FILES['attachment']['name'][$n] == '')
229
-				continue;
240
+			if ($_FILES['attachment']['name'][$n] == '') {
241
+							continue;
242
+			}
230 243
 
231 244
 			// First, let's first check for PHP upload errors.
232 245
 			$errors = array();
233 246
 			if (!empty($_FILES['attachment']['error'][$n]))
234 247
 			{
235
-				if ($_FILES['attachment']['error'][$n] == 2)
236
-					$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
237
-
238
-				else
239
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
248
+				if ($_FILES['attachment']['error'][$n] == 2) {
249
+									$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
250
+				} else {
251
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
252
+				}
240 253
 
241 254
 				// Log this one, because...
242
-				if ($_FILES['attachment']['error'][$n] == 6)
243
-					log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
255
+				if ($_FILES['attachment']['error'][$n] == 6) {
256
+									log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
257
+				}
244 258
 
245 259
 				// Weird, no errors were cached, still fill out a generic one.
246
-				if (empty($errors))
247
-					$errors[] = 'attach_php_error';
260
+				if (empty($errors)) {
261
+									$errors[] = 'attach_php_error';
262
+				}
248 263
 			}
249 264
 
250 265
 			// Try to move and rename the file before doing any more checks on it.
@@ -256,8 +271,9 @@  discard block
 block discarded – undo
256 271
 			{
257 272
 				// The reported MIME type of the attachment might not be reliable.
258 273
 				// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
259
-				if (function_exists('mime_content_type'))
260
-					$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
274
+				if (function_exists('mime_content_type')) {
275
+									$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
276
+				}
261 277
 
262 278
 				$_SESSION['temp_attachments'][$attachID] = array(
263 279
 					'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -269,16 +285,18 @@  discard block
 block discarded – undo
269 285
 				);
270 286
 
271 287
 				// Move the file to the attachments folder with a temp name for now.
272
-				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
273
-					smf_chmod($destName, 0644);
288
+				if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
289
+									smf_chmod($destName, 0644);
290
+				}
274 291
 
275 292
 				// This is madness!!
276 293
 				else
277 294
 				{
278 295
 					// File couldn't be moved.
279 296
 					$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
280
-					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
281
-						unlink($_FILES['attachment']['tmp_name'][$n]);
297
+					if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
298
+											unlink($_FILES['attachment']['tmp_name'][$n]);
299
+					}
282 300
 				}
283 301
 			}
284 302
 
@@ -291,13 +309,15 @@  discard block
 block discarded – undo
291 309
 					'errors' => $errors,
292 310
 				);
293 311
 
294
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
295
-					unlink($_FILES['attachment']['tmp_name'][$n]);
312
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
313
+									unlink($_FILES['attachment']['tmp_name'][$n]);
314
+				}
296 315
 			}
297 316
 
298 317
 			// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
299
-			if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
300
-				attachmentChecks($attachID);
318
+			if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
319
+							attachmentChecks($attachID);
320
+			}
301 321
 		}
302 322
 
303 323
 		// Mod authors, finally a hook to hang an alternate attachment upload system upon
@@ -344,14 +364,15 @@  discard block
 block discarded – undo
344 364
 
345 365
 					$_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID'];
346 366
 
347
-					if (!empty($attachmentOptions['thumb']))
348
-						$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
367
+					if (!empty($attachmentOptions['thumb'])) {
368
+											$_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb'];
369
+					}
349 370
 
350
-					if ($this->_msg)
351
-						assignAttachments($_SESSION['already_attached'], $this->_msg);
371
+					if ($this->_msg) {
372
+											assignAttachments($_SESSION['already_attached'], $this->_msg);
373
+					}
352 374
 				}
353
-			}
354
-			else
375
+			} else
355 376
 			{
356 377
 				// Sort out the errors for display and delete any associated files.
357 378
 				$log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file');
@@ -363,14 +384,16 @@  discard block
 block discarded – undo
363 384
 					if (!is_array($error))
364 385
 					{
365 386
 						$attachmentOptions['errors'][] = $txt[$error];
366
-						if (in_array($error, $log_these))
367
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
387
+						if (in_array($error, $log_these)) {
388
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
389
+						}
390
+					} else {
391
+											$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
368 392
 					}
369
-					else
370
-						$attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]);
371 393
 				}
372
-				if (file_exists($attachment['tmp_name']))
373
-					unlink($attachment['tmp_name']);
394
+				if (file_exists($attachment['tmp_name'])) {
395
+									unlink($attachment['tmp_name']);
396
+				}
374 397
 			}
375 398
 
376 399
 			// You don't need to know.
@@ -382,8 +405,9 @@  discard block
 block discarded – undo
382 405
 		}
383 406
 
384 407
 		// Temp save this on the db.
385
-		if (!empty($_SESSION['already_attached']))
386
-			$this->_attachSuccess = $_SESSION['already_attached'];
408
+		if (!empty($_SESSION['already_attached'])) {
409
+					$this->_attachSuccess = $_SESSION['already_attached'];
410
+		}
387 411
 
388 412
 		unset($_SESSION['temp_attachments']);
389 413
 	}
@@ -403,14 +427,16 @@  discard block
 block discarded – undo
403 427
 		if ($this->_sa == 'add')
404 428
 		{
405 429
 			// Is there any generic errors? made some sense out of them!
406
-			if ($this->_generalErrors)
407
-				foreach ($this->_generalErrors as $k => $v)
430
+			if ($this->_generalErrors) {
431
+							foreach ($this->_generalErrors as $k => $v)
408 432
 					$this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]);
433
+			}
409 434
 
410 435
 			// Gotta urlencode the filename.
411
-			if ($this->_attachResults)
412
-				foreach ($this->_attachResults as $k => $v)
436
+			if ($this->_attachResults) {
437
+							foreach ($this->_attachResults as $k => $v)
413 438
 					$this->_attachResults[$k]['name'] =  urlencode($this->_attachResults[$k]['name']);
439
+			}
414 440
 
415 441
 			$this->_response = array(
416 442
 				'files' => $this->_attachResults ? $this->_attachResults : false,
@@ -419,9 +445,10 @@  discard block
 block discarded – undo
419 445
 		}
420 446
 
421 447
 		// Rest of us mere mortals gets no special treatment...
422
-		elseif (!empty($data))
423
-			if (!empty($data['text']) && !empty($txt[$data['text']]))
448
+		elseif (!empty($data)) {
449
+					if (!empty($data['text']) && !empty($txt[$data['text']]))
424 450
 				$this->_response['text'] = $txt[$data['text']];
451
+		}
425 452
 	}
426 453
 
427 454
 	protected function sendResponse()
@@ -430,11 +457,11 @@  discard block
 block discarded – undo
430 457
 
431 458
 		ob_end_clean();
432 459
 
433
-		if (!empty($modSettings['CompressedOutput']))
434
-			@ob_start('ob_gzhandler');
435
-
436
-		else
437
-			ob_start();
460
+		if (!empty($modSettings['CompressedOutput'])) {
461
+					@ob_start('ob_gzhandler');
462
+		} else {
463
+					ob_start();
464
+		}
438 465
 
439 466
 		// Set the header.
440 467
 		header('content-type: application/json; charset='. $context['character_set'] .'');
Please login to merge, or discard this patch.