Completed
Push — release-2.1 ( 286127...e6c696 )
by Mathias
11s
created
other/install.php 1 patch
Braces   +438 added lines, -326 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -83,12 +84,14 @@  discard block
 block discarded – undo
83 84
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
84 85
 
85 86
 			// Is it reserved?
86
-			if ($value == 'pg_')
87
-				return $txt['error_db_prefix_reserved'];
87
+			if ($value == 'pg_') {
88
+							return $txt['error_db_prefix_reserved'];
89
+			}
88 90
 
89 91
 			// Is the prefix numeric?
90
-			if (preg_match('~^\d~', $value))
91
-				return $txt['error_db_prefix_numeric'];
92
+			if (preg_match('~^\d~', $value)) {
93
+							return $txt['error_db_prefix_numeric'];
94
+			}
92 95
 
93 96
 			return true;
94 97
 		},
@@ -135,10 +138,11 @@  discard block
 block discarded – undo
135 138
 		$incontext['skip'] = false;
136 139
 
137 140
 		// Call the step and if it returns false that means pause!
138
-		if (function_exists($step[2]) && $step[2]() === false)
139
-			break;
140
-		elseif (function_exists($step[2]))
141
-			$incontext['current_step']++;
141
+		if (function_exists($step[2]) && $step[2]() === false) {
142
+					break;
143
+		} elseif (function_exists($step[2])) {
144
+					$incontext['current_step']++;
145
+		}
142 146
 
143 147
 		// No warnings pass on.
144 148
 		$incontext['warning'] = '';
@@ -154,12 +158,14 @@  discard block
 block discarded – undo
154 158
 	global $databases, $incontext;
155 159
 
156 160
 	// Just so people using older versions of PHP aren't left in the cold.
157
-	if (!isset($_SERVER['PHP_SELF']))
158
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
161
+	if (!isset($_SERVER['PHP_SELF'])) {
162
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
163
+	}
159 164
 
160 165
 	// Turn off magic quotes runtime and enable error reporting.
161
-	if (function_exists('set_magic_quotes_runtime'))
162
-		@set_magic_quotes_runtime(0);
166
+	if (function_exists('set_magic_quotes_runtime')) {
167
+			@set_magic_quotes_runtime(0);
168
+	}
163 169
 	error_reporting(E_ALL);
164 170
 
165 171
 	// Fun.  Low PHP version...
@@ -173,21 +179,23 @@  discard block
 block discarded – undo
173 179
 	{
174 180
 		ob_start();
175 181
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
178
-		if (function_exists('session_start'))
179
-			@session_start();
180
-	}
181
-	else
182
+		if (ini_get('session.save_handler') == 'user') {
183
+					@ini_set('session.save_handler', 'files');
184
+		}
185
+		if (function_exists('session_start')) {
186
+					@session_start();
187
+		}
188
+	} else
182 189
 	{
183 190
 		ob_start('ob_gzhandler');
184 191
 
185
-		if (ini_get('session.save_handler') == 'user')
186
-			@ini_set('session.save_handler', 'files');
192
+		if (ini_get('session.save_handler') == 'user') {
193
+					@ini_set('session.save_handler', 'files');
194
+		}
187 195
 		session_start();
188 196
 
189
-		if (!headers_sent())
190
-			echo '<!DOCTYPE html>
197
+		if (!headers_sent()) {
198
+					echo '<!DOCTYPE html>
191 199
 <html>
192 200
 	<head>
193 201
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -196,6 +204,7 @@  discard block
 block discarded – undo
196 204
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
197 205
 	</body>
198 206
 </html>';
207
+		}
199 208
 		exit;
200 209
 	}
201 210
 
@@ -204,16 +213,18 @@  discard block
 block discarded – undo
204 213
 	{
205 214
 		$incontext['remote_files_available'] = false;
206 215
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
207
-		if ($test)
208
-			$incontext['remote_files_available'] = true;
216
+		if ($test) {
217
+					$incontext['remote_files_available'] = true;
218
+		}
209 219
 		@fclose($test);
210 220
 	}
211 221
 
212 222
 	// Add slashes, as long as they aren't already being added.
213
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
214
-		foreach ($_POST as $k => $v)
223
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
224
+			foreach ($_POST as $k => $v)
215 225
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
216 226
 				$_POST[$k] = addslashes($v);
227
+	}
217 228
 
218 229
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
219 230
 	if (isset($_GET['delete']))
@@ -234,8 +245,7 @@  discard block
 block discarded – undo
234 245
 			$ftp->close();
235 246
 
236 247
 			unset($_SESSION['installer_temp_ftp']);
237
-		}
238
-		else
248
+		} else
239 249
 		{
240 250
 			@unlink(__FILE__);
241 251
 
@@ -256,10 +266,11 @@  discard block
 block discarded – undo
256 266
 	{
257 267
 		// Get PHP's default timezone, if set
258 268
 		$ini_tz = ini_get('date.timezone');
259
-		if (!empty($ini_tz))
260
-			$timezone_id = $ini_tz;
261
-		else
262
-			$timezone_id = '';
269
+		if (!empty($ini_tz)) {
270
+					$timezone_id = $ini_tz;
271
+		} else {
272
+					$timezone_id = '';
273
+		}
263 274
 
264 275
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
265 276
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -289,8 +300,9 @@  discard block
 block discarded – undo
289 300
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
290 301
 		while ($entry = $dir->read())
291 302
 		{
292
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
293
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
303
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
304
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
305
+			}
294 306
 		}
295 307
 		$dir->close();
296 308
 	}
@@ -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.
@@ -351,15 +365,18 @@  discard block
 block discarded – undo
351 365
 	global $db_prefix, $db_connection, $sourcedir;
352 366
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
353 367
 
354
-	if (empty($sourcedir))
355
-		$sourcedir = dirname(__FILE__) . '/Sources';
368
+	if (empty($sourcedir)) {
369
+			$sourcedir = dirname(__FILE__) . '/Sources';
370
+	}
356 371
 
357 372
 	// Need this to check whether we need the database password.
358 373
 	require(dirname(__FILE__) . '/Settings.php');
359
-	if (!defined('SMF'))
360
-		define('SMF', 1);
361
-	if (empty($smcFunc))
362
-		$smcFunc = array();
374
+	if (!defined('SMF')) {
375
+			define('SMF', 1);
376
+	}
377
+	if (empty($smcFunc)) {
378
+			$smcFunc = array();
379
+	}
363 380
 
364 381
 	$modSettings['disableQueryCheck'] = true;
365 382
 
@@ -367,8 +384,9 @@  discard block
 block discarded – undo
367 384
 	if (!$db_connection)
368 385
 	{
369 386
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
370
-		if (version_compare(PHP_VERSION, '5', '<'))
371
-			require_once($sourcedir . '/Subs-Compat.php');
387
+		if (version_compare(PHP_VERSION, '5', '<')) {
388
+					require_once($sourcedir . '/Subs-Compat.php');
389
+		}
372 390
 
373 391
 		$db_options = array('persist' => $db_persist);
374 392
 		$port = '';
@@ -379,19 +397,20 @@  discard block
 block discarded – undo
379 397
 			if ($db_type == 'mysql' || $db_type == 'mysqli')
380 398
 			{
381 399
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
382
-			}
383
-			elseif ($db_type == 'postgresql')
400
+			} elseif ($db_type == 'postgresql')
384 401
 			{
385 402
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
386 403
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
387 404
 			}
388 405
 		}
389 406
 
390
-		if (!empty($port))
391
-			$db_options['port'] = $port;
407
+		if (!empty($port)) {
408
+					$db_options['port'] = $port;
409
+		}
392 410
 
393
-		if (!$db_connection)
394
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
411
+		if (!$db_connection) {
412
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
413
+		}
395 414
 	}
396 415
 }
397 416
 
@@ -419,8 +438,9 @@  discard block
 block discarded – undo
419 438
 		// @todo REMOVE THIS!!
420 439
 		else
421 440
 		{
422
-			if (function_exists('doStep' . $_GET['step']))
423
-				call_user_func('doStep' . $_GET['step']);
441
+			if (function_exists('doStep' . $_GET['step'])) {
442
+							call_user_func('doStep' . $_GET['step']);
443
+			}
424 444
 		}
425 445
 		// Show the footer.
426 446
 		template_install_below();
@@ -438,8 +458,9 @@  discard block
 block discarded – undo
438 458
 	$incontext['sub_template'] = 'welcome_message';
439 459
 
440 460
 	// Done the submission?
441
-	if (isset($_POST['contbutt']))
442
-		return true;
461
+	if (isset($_POST['contbutt'])) {
462
+			return true;
463
+	}
443 464
 
444 465
 	// See if we think they have already installed it?
445 466
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -447,14 +468,17 @@  discard block
 block discarded – undo
447 468
 		$probably_installed = 0;
448 469
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
449 470
 		{
450
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
451
-				$probably_installed++;
452
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
453
-				$probably_installed++;
471
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
472
+							$probably_installed++;
473
+			}
474
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
475
+							$probably_installed++;
476
+			}
454 477
 		}
455 478
 
456
-		if ($probably_installed == 2)
457
-			$incontext['warning'] = $txt['error_already_installed'];
479
+		if ($probably_installed == 2) {
480
+					$incontext['warning'] = $txt['error_already_installed'];
481
+		}
458 482
 	}
459 483
 
460 484
 	// Is some database support even compiled in?
@@ -469,8 +493,7 @@  discard block
 block discarded – undo
469 493
 				$databases[$key]['supported'] = false;
470 494
 				$notFoundSQLFile = true;
471 495
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
472
-			}
473
-			else
496
+			} else
474 497
 			{
475 498
 				$db_type = $key;
476 499
 				$incontext['supported_databases'][] = $db;
@@ -479,29 +502,36 @@  discard block
 block discarded – undo
479 502
 	}
480 503
 
481 504
 	// Check the PHP version.
482
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
483
-		$error = 'error_php_too_low';
505
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
506
+			$error = 'error_php_too_low';
507
+	}
484 508
 	// Make sure we have a supported database
485
-	elseif (empty($incontext['supported_databases']))
486
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
509
+	elseif (empty($incontext['supported_databases'])) {
510
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
511
+	}
487 512
 	// How about session support?  Some crazy sysadmin remove it?
488
-	elseif (!function_exists('session_start'))
489
-		$error = 'error_session_missing';
513
+	elseif (!function_exists('session_start')) {
514
+			$error = 'error_session_missing';
515
+	}
490 516
 	// Make sure they uploaded all the files.
491
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
492
-		$error = 'error_missing_files';
517
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
518
+			$error = 'error_missing_files';
519
+	}
493 520
 	// Very simple check on the session.save_path for Windows.
494 521
 	// @todo Move this down later if they don't use database-driven sessions?
495
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
496
-		$error = 'error_session_save_path';
522
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
523
+			$error = 'error_session_save_path';
524
+	}
497 525
 
498 526
 	// Since each of the three messages would look the same, anyway...
499
-	if (isset($error))
500
-		$incontext['error'] = $txt[$error];
527
+	if (isset($error)) {
528
+			$incontext['error'] = $txt[$error];
529
+	}
501 530
 
502 531
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
503
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
504
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
532
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
533
+			$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
+	}
505 535
 
506 536
 	return false;
507 537
 }
@@ -524,15 +554,18 @@  discard block
 block discarded – undo
524 554
 		'agreement.txt',
525 555
 		'Settings.php'
526 556
 	);
527
-	if (file_exists(dirname(__FILE__) . '/Settings_bak.php'))
528
-		$writable_files[] = 'Settings_bak.php';
557
+	if (file_exists(dirname(__FILE__) . '/Settings_bak.php')) {
558
+			$writable_files[] = 'Settings_bak.php';
559
+	}
529 560
 
530
-	foreach ($incontext['detected_languages'] as $lang => $temp)
531
-		$extra_files[] = 'Themes/default/languages/' . $lang;
561
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
562
+			$extra_files[] = 'Themes/default/languages/' . $lang;
563
+	}
532 564
 
533 565
 	// With mod_security installed, we could attempt to fix it with .htaccess.
534
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
535
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
566
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
567
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
568
+	}
536 569
 
537 570
 	$failed_files = array();
538 571
 
@@ -548,12 +581,14 @@  discard block
 block discarded – undo
548 581
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
549 582
 
550 583
 				// Well, 755 hopefully worked... if not, try 777.
551
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
552
-					$failed_files[] = $file;
584
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
585
+									$failed_files[] = $file;
586
+				}
553 587
 			}
554 588
 		}
555
-		foreach ($extra_files as $file)
556
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
589
+		foreach ($extra_files as $file) {
590
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
591
+		}
557 592
 	}
558 593
 	// Windows is trickier.  Let's try opening for r+...
559 594
 	else
@@ -563,30 +598,35 @@  discard block
 block discarded – undo
563 598
 		foreach ($writable_files as $file)
564 599
 		{
565 600
 			// Folders can't be opened for write... but the index.php in them can ;)
566
-			if (is_dir(dirname(__FILE__) . '/' . $file))
567
-				$file .= '/index.php';
601
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
602
+							$file .= '/index.php';
603
+			}
568 604
 
569 605
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
570 606
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
571 607
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
572 608
 
573 609
 			// Hmm, okay, try just for write in that case...
574
-			if (!is_resource($fp))
575
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
610
+			if (!is_resource($fp)) {
611
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
612
+			}
576 613
 
577
-			if (!is_resource($fp))
578
-				$failed_files[] = $file;
614
+			if (!is_resource($fp)) {
615
+							$failed_files[] = $file;
616
+			}
579 617
 
580 618
 			@fclose($fp);
581 619
 		}
582
-		foreach ($extra_files as $file)
583
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
620
+		foreach ($extra_files as $file) {
621
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
622
+		}
584 623
 	}
585 624
 
586 625
 	$failure = count($failed_files) >= 1;
587 626
 
588
-	if (!isset($_SERVER))
589
-		return !$failure;
627
+	if (!isset($_SERVER)) {
628
+			return !$failure;
629
+	}
590 630
 
591 631
 	// Put the list into context.
592 632
 	$incontext['failed_files'] = $failed_files;
@@ -634,19 +674,23 @@  discard block
 block discarded – undo
634 674
 
635 675
 		if (!isset($ftp) || $ftp->error !== false)
636 676
 		{
637
-			if (!isset($ftp))
638
-				$ftp = new ftp_connection(null);
677
+			if (!isset($ftp)) {
678
+							$ftp = new ftp_connection(null);
679
+			}
639 680
 			// Save the error so we can mess with listing...
640
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
641
-				$incontext['ftp_errors'][] = $ftp->last_message;
681
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
682
+							$incontext['ftp_errors'][] = $ftp->last_message;
683
+			}
642 684
 
643 685
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
644 686
 
645
-			if (empty($_POST['ftp_path']) && $found_path)
646
-				$_POST['ftp_path'] = $detect_path;
687
+			if (empty($_POST['ftp_path']) && $found_path) {
688
+							$_POST['ftp_path'] = $detect_path;
689
+			}
647 690
 
648
-			if (!isset($_POST['ftp_username']))
649
-				$_POST['ftp_username'] = $username;
691
+			if (!isset($_POST['ftp_username'])) {
692
+							$_POST['ftp_username'] = $username;
693
+			}
650 694
 
651 695
 			// Set the username etc, into context.
652 696
 			$incontext['ftp'] = array(
@@ -658,8 +702,7 @@  discard block
 block discarded – undo
658 702
 			);
659 703
 
660 704
 			return false;
661
-		}
662
-		else
705
+		} else
663 706
 		{
664 707
 			$_SESSION['installer_temp_ftp'] = array(
665 708
 				'server' => $_POST['ftp_server'],
@@ -673,10 +716,12 @@  discard block
 block discarded – undo
673 716
 
674 717
 			foreach ($failed_files as $file)
675 718
 			{
676
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
677
-					$ftp->chmod($file, 0755);
678
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
679
-					$ftp->chmod($file, 0777);
719
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
720
+									$ftp->chmod($file, 0755);
721
+				}
722
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
723
+									$ftp->chmod($file, 0777);
724
+				}
680 725
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
681 726
 				{
682 727
 					$failed_files_updated[] = $file;
@@ -731,15 +776,17 @@  discard block
 block discarded – undo
731 776
 
732 777
 			if (!$foundOne)
733 778
 			{
734
-				if (isset($db['default_host']))
735
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
779
+				if (isset($db['default_host'])) {
780
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
781
+				}
736 782
 				if (isset($db['default_user']))
737 783
 				{
738 784
 					$incontext['db']['user'] = ini_get($db['default_user']);
739 785
 					$incontext['db']['name'] = ini_get($db['default_user']);
740 786
 				}
741
-				if (isset($db['default_password']))
742
-					$incontext['db']['pass'] = ini_get($db['default_password']);
787
+				if (isset($db['default_password'])) {
788
+									$incontext['db']['pass'] = ini_get($db['default_password']);
789
+				}
743 790
 
744 791
 				// For simplicity and less confusion, leave the port blank by default
745 792
 				$incontext['db']['port'] = '';
@@ -758,10 +805,10 @@  discard block
 block discarded – undo
758 805
 		$incontext['db']['server'] = $_POST['db_server'];
759 806
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
760 807
 
761
-		if (!empty($_POST['db_port']))
762
-			$incontext['db']['port'] = $_POST['db_port'];
763
-	}
764
-	else
808
+		if (!empty($_POST['db_port'])) {
809
+					$incontext['db']['port'] = $_POST['db_port'];
810
+		}
811
+	} else
765 812
 	{
766 813
 		$incontext['db']['prefix'] = 'smf_';
767 814
 	}
@@ -797,10 +844,11 @@  discard block
 block discarded – undo
797 844
 		if (!empty($_POST['db_port']))
798 845
 		{
799 846
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
800
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
801
-				$vars['db_port'] = (int) $_POST['db_port'];
802
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
803
-				$vars['db_port'] = (int) $_POST['db_port'];
847
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
848
+							$vars['db_port'] = (int) $_POST['db_port'];
849
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
850
+							$vars['db_port'] = (int) $_POST['db_port'];
851
+			}
804 852
 		}
805 853
 
806 854
 		// God I hope it saved!
@@ -813,8 +861,9 @@  discard block
 block discarded – undo
813 861
 		// Make sure it works.
814 862
 		require(dirname(__FILE__) . '/Settings.php');
815 863
 
816
-		if (empty($sourcedir))
817
-			$sourcedir = dirname(__FILE__) . '/Sources';
864
+		if (empty($sourcedir)) {
865
+					$sourcedir = dirname(__FILE__) . '/Sources';
866
+		}
818 867
 
819 868
 		// Better find the database file!
820 869
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -824,18 +873,21 @@  discard block
 block discarded – undo
824 873
 		}
825 874
 
826 875
 		// Now include it for database functions!
827
-		if (!defined('SMF'))
828
-			define('SMF', 1);
876
+		if (!defined('SMF')) {
877
+					define('SMF', 1);
878
+		}
829 879
 
830 880
 		$modSettings['disableQueryCheck'] = true;
831
-		if (empty($smcFunc))
832
-			$smcFunc = array();
881
+		if (empty($smcFunc)) {
882
+					$smcFunc = array();
883
+		}
833 884
 
834 885
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
835 886
 
836 887
 		// What - running PHP4? The shame!
837
-		if (version_compare(PHP_VERSION, '5', '<'))
838
-			require_once($sourcedir . '/Subs-Compat.php');
888
+		if (version_compare(PHP_VERSION, '5', '<')) {
889
+					require_once($sourcedir . '/Subs-Compat.php');
890
+		}
839 891
 
840 892
 		// Attempt a connection.
841 893
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -923,12 +975,14 @@  discard block
 block discarded – undo
923 975
 	$incontext['page_title'] = $txt['install_settings'];
924 976
 
925 977
 	// Let's see if we got the database type correct.
926
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
927
-		$db_type = $_POST['db_type'];
978
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
979
+			$db_type = $_POST['db_type'];
980
+	}
928 981
 
929 982
 	// Else we'd better be able to get the connection.
930
-	else
931
-		load_database();
983
+	else {
984
+			load_database();
985
+	}
932 986
 
933 987
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
934 988
 
@@ -948,12 +1002,14 @@  discard block
 block discarded – undo
948 1002
 	// Submitting?
949 1003
 	if (isset($_POST['boardurl']))
950 1004
 	{
951
-		if (substr($_POST['boardurl'], -10) == '/index.php')
952
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
953
-		elseif (substr($_POST['boardurl'], -1) == '/')
954
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
955
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
956
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1005
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1006
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1007
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1008
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1009
+		}
1010
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1011
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1012
+		}
957 1013
 
958 1014
 		// Save these variables.
959 1015
 		$vars = array(
@@ -984,10 +1040,10 @@  discard block
 block discarded – undo
984 1040
 			{
985 1041
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
986 1042
 				return false;
987
-			}
988
-			else
989
-				// Set the character set here.
1043
+			} else {
1044
+							// Set the character set here.
990 1045
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1046
+			}
991 1047
 		}
992 1048
 
993 1049
 		// Good, skip on.
@@ -1007,8 +1063,9 @@  discard block
 block discarded – undo
1007 1063
 	$incontext['continue'] = 1;
1008 1064
 
1009 1065
 	// Already done?
1010
-	if (isset($_POST['pop_done']))
1011
-		return true;
1066
+	if (isset($_POST['pop_done'])) {
1067
+			return true;
1068
+	}
1012 1069
 
1013 1070
 	// Reload settings.
1014 1071
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1026,8 +1083,9 @@  discard block
 block discarded – undo
1026 1083
 	$modSettings = array();
1027 1084
 	if ($result !== false)
1028 1085
 	{
1029
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1030
-			$modSettings[$row['variable']] = $row['value'];
1086
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1087
+					$modSettings[$row['variable']] = $row['value'];
1088
+		}
1031 1089
 		$smcFunc['db_free_result']($result);
1032 1090
 
1033 1091
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1040,20 +1098,22 @@  discard block
 block discarded – undo
1040 1098
 	$modSettings['disableQueryCheck'] = true;
1041 1099
 
1042 1100
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1043
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1044
-		$smcFunc['db_query']('', '
1101
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1102
+			$smcFunc['db_query']('', '
1045 1103
 			SET NAMES {string:utf8}',
1046 1104
 			array(
1047 1105
 				'db_error_skip' => true,
1048 1106
 				'utf8' => 'utf8',
1049 1107
 			)
1050 1108
 		);
1109
+	}
1051 1110
 
1052 1111
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1053
-	if (substr(__DIR__, -1) == '\\')
1054
-		$attachdir = __DIR__ . 'attachments';
1055
-	else
1056
-		$attachdir = __DIR__ . '/attachments';
1112
+	if (substr(__DIR__, -1) == '\\') {
1113
+			$attachdir = __DIR__ . 'attachments';
1114
+	} else {
1115
+			$attachdir = __DIR__ . '/attachments';
1116
+	}
1057 1117
 
1058 1118
 	$replaces = array(
1059 1119
 		'{$db_prefix}' => $db_prefix,
@@ -1070,8 +1130,9 @@  discard block
 block discarded – undo
1070 1130
 
1071 1131
 	foreach ($txt as $key => $value)
1072 1132
 	{
1073
-		if (substr($key, 0, 8) == 'default_')
1074
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1133
+		if (substr($key, 0, 8) == 'default_') {
1134
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1135
+		}
1075 1136
 	}
1076 1137
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1077 1138
 
@@ -1086,8 +1147,9 @@  discard block
 block discarded – undo
1086 1147
 
1087 1148
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1088 1149
 		{
1089
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1090
-				$engines[] = $row['Engine'];
1150
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1151
+							$engines[] = $row['Engine'];
1152
+			}
1091 1153
 		}
1092 1154
 
1093 1155
 		// Done with this now
@@ -1111,8 +1173,7 @@  discard block
 block discarded – undo
1111 1173
 			$replaces['START TRANSACTION;'] = '';
1112 1174
 			$replaces['COMMIT;'] = '';
1113 1175
 		}
1114
-	}
1115
-	else
1176
+	} else
1116 1177
 	{
1117 1178
 		$has_innodb = false;
1118 1179
 	}
@@ -1134,21 +1195,24 @@  discard block
 block discarded – undo
1134 1195
 	foreach ($sql_lines as $count => $line)
1135 1196
 	{
1136 1197
 		// No comments allowed!
1137
-		if (substr(trim($line), 0, 1) != '#')
1138
-			$current_statement .= "\n" . rtrim($line);
1198
+		if (substr(trim($line), 0, 1) != '#') {
1199
+					$current_statement .= "\n" . rtrim($line);
1200
+		}
1139 1201
 
1140 1202
 		// Is this the end of the query string?
1141
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1142
-			continue;
1203
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1204
+					continue;
1205
+		}
1143 1206
 
1144 1207
 		// Does this table already exist?  If so, don't insert more data into it!
1145 1208
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1146 1209
 		{
1147 1210
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1148
-			if (!empty($matches[0]))
1149
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1150
-			else
1151
-				$incontext['sql_results']['insert_dups']++;
1211
+			if (!empty($matches[0])) {
1212
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1213
+			} else {
1214
+							$incontext['sql_results']['insert_dups']++;
1215
+			}
1152 1216
 
1153 1217
 			$current_statement = '';
1154 1218
 			continue;
@@ -1157,8 +1221,9 @@  discard block
 block discarded – undo
1157 1221
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1158 1222
 		{
1159 1223
 			// Use the appropriate function based on the DB type
1160
-			if ($db_type == 'mysql' || $db_type =='mysqli')
1161
-				$db_errorno = $db_type . '_errno';
1224
+			if ($db_type == 'mysql' || $db_type =='mysqli') {
1225
+							$db_errorno = $db_type . '_errno';
1226
+			}
1162 1227
 
1163 1228
 			// Error 1050: Table already exists!
1164 1229
 			// @todo Needs to be made better!
@@ -1173,18 +1238,18 @@  discard block
 block discarded – undo
1173 1238
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1174 1239
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1175 1240
 			}
1176
-		}
1177
-		else
1241
+		} else
1178 1242
 		{
1179
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1180
-				$incontext['sql_results']['tables']++;
1181
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1243
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1244
+							$incontext['sql_results']['tables']++;
1245
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1182 1246
 			{
1183 1247
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1184
-				if (!empty($matches[0]))
1185
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1186
-				else
1187
-					$incontext['sql_results']['inserts']++;
1248
+				if (!empty($matches[0])) {
1249
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1250
+				} else {
1251
+									$incontext['sql_results']['inserts']++;
1252
+				}
1188 1253
 			}
1189 1254
 		}
1190 1255
 
@@ -1197,15 +1262,17 @@  discard block
 block discarded – undo
1197 1262
 	// Sort out the context for the SQL.
1198 1263
 	foreach ($incontext['sql_results'] as $key => $number)
1199 1264
 	{
1200
-		if ($number == 0)
1201
-			unset($incontext['sql_results'][$key]);
1202
-		else
1203
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1265
+		if ($number == 0) {
1266
+					unset($incontext['sql_results'][$key]);
1267
+		} else {
1268
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1269
+		}
1204 1270
 	}
1205 1271
 
1206 1272
 	// Make sure UTF will be used globally.
1207
-	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'])))
1208
-		$newSettings[] = array('global_character_set', 'UTF-8');
1273
+	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']))) {
1274
+			$newSettings[] = array('global_character_set', 'UTF-8');
1275
+	}
1209 1276
 
1210 1277
 	// Maybe we can auto-detect better cookie settings?
1211 1278
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1216,16 +1283,20 @@  discard block
 block discarded – undo
1216 1283
 		$globalCookies = false;
1217 1284
 
1218 1285
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1219
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1220
-			$globalCookies = true;
1286
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1287
+					$globalCookies = true;
1288
+		}
1221 1289
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1222
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1223
-			$localCookies = true;
1290
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1291
+					$localCookies = true;
1292
+		}
1224 1293
 
1225
-		if ($globalCookies)
1226
-			$newSettings[] = array('globalCookies', '1');
1227
-		if ($localCookies)
1228
-			$newSettings[] = array('localCookies', '1');
1294
+		if ($globalCookies) {
1295
+					$newSettings[] = array('globalCookies', '1');
1296
+		}
1297
+		if ($localCookies) {
1298
+					$newSettings[] = array('localCookies', '1');
1299
+		}
1229 1300
 	}
1230 1301
 
1231 1302
 	// Are we allowing stat collection?
@@ -1241,32 +1312,36 @@  discard block
 block discarded – undo
1241 1312
 			fwrite($fp, $out);
1242 1313
 
1243 1314
 			$return_data = '';
1244
-			while (!feof($fp))
1245
-				$return_data .= fgets($fp, 128);
1315
+			while (!feof($fp)) {
1316
+							$return_data .= fgets($fp, 128);
1317
+			}
1246 1318
 
1247 1319
 			fclose($fp);
1248 1320
 
1249 1321
 			// Get the unique site ID.
1250 1322
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1251 1323
 
1252
-			if (!empty($ID[1]))
1253
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1324
+			if (!empty($ID[1])) {
1325
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1326
+			}
1254 1327
 		}
1255 1328
 	}
1256 1329
 
1257 1330
 	// Are we enabling SSL?
1258
-	if (!empty($_POST['force_ssl']))
1259
-		$newSettings[] = array('force_ssl', 2);
1331
+	if (!empty($_POST['force_ssl'])) {
1332
+			$newSettings[] = array('force_ssl', 2);
1333
+	}
1260 1334
 
1261 1335
 	// Setting a timezone is required.
1262 1336
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1263 1337
 	{
1264 1338
 		// Get PHP's default timezone, if set
1265 1339
 		$ini_tz = ini_get('date.timezone');
1266
-		if (!empty($ini_tz))
1267
-			$timezone_id = $ini_tz;
1268
-		else
1269
-			$timezone_id = '';
1340
+		if (!empty($ini_tz)) {
1341
+					$timezone_id = $ini_tz;
1342
+		} else {
1343
+					$timezone_id = '';
1344
+		}
1270 1345
 
1271 1346
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1272 1347
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1275,8 +1350,9 @@  discard block
 block discarded – undo
1275 1350
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1276 1351
 		}
1277 1352
 
1278
-		if (date_default_timezone_set($timezone_id))
1279
-			$newSettings[] = array('default_timezone', $timezone_id);
1353
+		if (date_default_timezone_set($timezone_id)) {
1354
+					$newSettings[] = array('default_timezone', $timezone_id);
1355
+		}
1280 1356
 	}
1281 1357
 
1282 1358
 	if (!empty($newSettings))
@@ -1307,16 +1383,18 @@  discard block
 block discarded – undo
1307 1383
 	}
1308 1384
 
1309 1385
 	// MySQL specific stuff
1310
-	if (substr($db_type, 0, 5) != 'mysql')
1311
-		return false;
1386
+	if (substr($db_type, 0, 5) != 'mysql') {
1387
+			return false;
1388
+	}
1312 1389
 
1313 1390
 	// Find database user privileges.
1314 1391
 	$privs = array();
1315 1392
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1316 1393
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1317 1394
 	{
1318
-		if ($row['Privilege'] == 'Alter')
1319
-			$privs[] = $row['Privilege'];
1395
+		if ($row['Privilege'] == 'Alter') {
1396
+					$privs[] = $row['Privilege'];
1397
+		}
1320 1398
 	}
1321 1399
 	$smcFunc['db_free_result']($get_privs);
1322 1400
 
@@ -1346,8 +1424,9 @@  discard block
 block discarded – undo
1346 1424
 	$incontext['continue'] = 1;
1347 1425
 
1348 1426
 	// Skipping?
1349
-	if (!empty($_POST['skip']))
1350
-		return true;
1427
+	if (!empty($_POST['skip'])) {
1428
+			return true;
1429
+	}
1351 1430
 
1352 1431
 	// Need this to check whether we need the database password.
1353 1432
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1361,18 +1440,22 @@  discard block
 block discarded – undo
1361 1440
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1362 1441
 		function($string){
1363 1442
 			global $sourcedir;
1364
-			if (function_exists('mb_strtolower'))
1365
-				return mb_strtolower($string, 'UTF-8');
1443
+			if (function_exists('mb_strtolower')) {
1444
+							return mb_strtolower($string, 'UTF-8');
1445
+			}
1366 1446
 			require_once($sourcedir . '/Subs-Charset.php');
1367 1447
 			return utf8_strtolower($string);
1368 1448
 		};
1369 1449
 
1370
-	if (!isset($_POST['username']))
1371
-		$_POST['username'] = '';
1372
-	if (!isset($_POST['email']))
1373
-		$_POST['email'] = '';
1374
-	if (!isset($_POST['server_email']))
1375
-		$_POST['server_email'] = '';
1450
+	if (!isset($_POST['username'])) {
1451
+			$_POST['username'] = '';
1452
+	}
1453
+	if (!isset($_POST['email'])) {
1454
+			$_POST['email'] = '';
1455
+	}
1456
+	if (!isset($_POST['server_email'])) {
1457
+			$_POST['server_email'] = '';
1458
+	}
1376 1459
 
1377 1460
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1378 1461
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1391,8 +1474,9 @@  discard block
 block discarded – undo
1391 1474
 			'admin_group' => 1,
1392 1475
 		)
1393 1476
 	);
1394
-	if ($smcFunc['db_num_rows']($request) != 0)
1395
-		$incontext['skip'] = 1;
1477
+	if ($smcFunc['db_num_rows']($request) != 0) {
1478
+			$incontext['skip'] = 1;
1479
+	}
1396 1480
 	$smcFunc['db_free_result']($request);
1397 1481
 
1398 1482
 	// Trying to create an account?
@@ -1423,8 +1507,9 @@  discard block
 block discarded – undo
1423 1507
 		}
1424 1508
 
1425 1509
 		// Update the webmaster's email?
1426
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1427
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1510
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1511
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1512
+		}
1428 1513
 
1429 1514
 		// Work out whether we're going to have dodgy characters and remove them.
1430 1515
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1447,32 +1532,27 @@  discard block
 block discarded – undo
1447 1532
 			$smcFunc['db_free_result']($result);
1448 1533
 
1449 1534
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1450
-		}
1451
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1535
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1452 1536
 		{
1453 1537
 			// Try the previous step again.
1454 1538
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1455 1539
 			return false;
1456
-		}
1457
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1540
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1458 1541
 		{
1459 1542
 			// Try the previous step again.
1460 1543
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1461 1544
 			return false;
1462
-		}
1463
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1545
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1464 1546
 		{
1465 1547
 			// One step back, this time fill out a proper admin email address.
1466 1548
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1467 1549
 			return false;
1468
-		}
1469
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1550
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1470 1551
 		{
1471 1552
 			// One step back, this time fill out a proper admin email address.
1472 1553
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1473 1554
 			return false;
1474
-		}
1475
-		elseif ($_POST['username'] != '')
1555
+		} elseif ($_POST['username'] != '')
1476 1556
 		{
1477 1557
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1478 1558
 
@@ -1547,17 +1627,19 @@  discard block
 block discarded – undo
1547 1627
 	require_once($sourcedir . '/Subs-Auth.php');
1548 1628
 
1549 1629
 	// Bring a warning over.
1550
-	if (!empty($incontext['account_existed']))
1551
-		$incontext['warning'] = $incontext['account_existed'];
1630
+	if (!empty($incontext['account_existed'])) {
1631
+			$incontext['warning'] = $incontext['account_existed'];
1632
+	}
1552 1633
 
1553
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1554
-		$smcFunc['db_query']('', '
1634
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1635
+			$smcFunc['db_query']('', '
1555 1636
 			SET NAMES {string:db_character_set}',
1556 1637
 			array(
1557 1638
 				'db_character_set' => $db_character_set,
1558 1639
 				'db_error_skip' => true,
1559 1640
 			)
1560 1641
 		);
1642
+	}
1561 1643
 
1562 1644
 	// As track stats is by default enabled let's add some activity.
1563 1645
 	$smcFunc['db_insert']('ignore',
@@ -1578,14 +1660,16 @@  discard block
 block discarded – undo
1578 1660
 	// Only proceed if we can load the data.
1579 1661
 	if ($request)
1580 1662
 	{
1581
-		while ($row = $smcFunc['db_fetch_row']($request))
1582
-			$modSettings[$row[0]] = $row[1];
1663
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1664
+					$modSettings[$row[0]] = $row[1];
1665
+		}
1583 1666
 		$smcFunc['db_free_result']($request);
1584 1667
 	}
1585 1668
 
1586 1669
 	// Automatically log them in ;)
1587
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1588
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1670
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1671
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1672
+	}
1589 1673
 
1590 1674
 	$result = $smcFunc['db_query']('', '
1591 1675
 		SELECT value
@@ -1596,13 +1680,14 @@  discard block
 block discarded – undo
1596 1680
 			'db_error_skip' => true,
1597 1681
 		)
1598 1682
 	);
1599
-	if ($smcFunc['db_num_rows']($result) != 0)
1600
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1683
+	if ($smcFunc['db_num_rows']($result) != 0) {
1684
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1685
+	}
1601 1686
 	$smcFunc['db_free_result']($result);
1602 1687
 
1603
-	if (empty($db_sessions))
1604
-		$_SESSION['admin_time'] = time();
1605
-	else
1688
+	if (empty($db_sessions)) {
1689
+			$_SESSION['admin_time'] = time();
1690
+	} else
1606 1691
 	{
1607 1692
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1608 1693
 
@@ -1626,8 +1711,9 @@  discard block
 block discarded – undo
1626 1711
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1627 1712
 		function($string){
1628 1713
 			global $sourcedir;
1629
-			if (function_exists('mb_strtolower'))
1630
-				return mb_strtolower($string, 'UTF-8');
1714
+			if (function_exists('mb_strtolower')) {
1715
+							return mb_strtolower($string, 'UTF-8');
1716
+			}
1631 1717
 			require_once($sourcedir . '/Subs-Charset.php');
1632 1718
 			return utf8_strtolower($string);
1633 1719
 		};
@@ -1643,8 +1729,9 @@  discard block
 block discarded – undo
1643 1729
 		)
1644 1730
 	);
1645 1731
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1646
-	if ($smcFunc['db_num_rows']($request) > 0)
1647
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1732
+	if ($smcFunc['db_num_rows']($request) > 0) {
1733
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1734
+	}
1648 1735
 	$smcFunc['db_free_result']($request);
1649 1736
 
1650 1737
 	// Now is the perfect time to fetch the SM files.
@@ -1663,8 +1750,9 @@  discard block
 block discarded – undo
1663 1750
 
1664 1751
 	// Check if we need some stupid MySQL fix.
1665 1752
 	$server_version = $smcFunc['db_server_info']();
1666
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1667
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1753
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1754
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1755
+	}
1668 1756
 
1669 1757
 	// Some final context for the template.
1670 1758
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1684,8 +1772,9 @@  discard block
 block discarded – undo
1684 1772
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1685 1773
 
1686 1774
 	// @todo Do we just want to read the file in clean, and split it this way always?
1687
-	if (count($settingsArray) == 1)
1688
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1775
+	if (count($settingsArray) == 1) {
1776
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1777
+	}
1689 1778
 
1690 1779
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1691 1780
 	{
@@ -1700,19 +1789,22 @@  discard block
 block discarded – undo
1700 1789
 			continue;
1701 1790
 		}
1702 1791
 
1703
-		if (trim($settingsArray[$i]) == '?' . '>')
1704
-			$settingsArray[$i] = '';
1792
+		if (trim($settingsArray[$i]) == '?' . '>') {
1793
+					$settingsArray[$i] = '';
1794
+		}
1705 1795
 
1706 1796
 		// Don't trim or bother with it if it's not a variable.
1707
-		if (substr($settingsArray[$i], 0, 1) != '$')
1708
-			continue;
1797
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1798
+					continue;
1799
+		}
1709 1800
 
1710 1801
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1711 1802
 
1712
-		foreach ($vars as $var => $val)
1713
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1803
+		foreach ($vars as $var => $val) {
1804
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1714 1805
 			{
1715 1806
 				$comment = strstr($settingsArray[$i], '#');
1807
+		}
1716 1808
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1717 1809
 				unset($vars[$var]);
1718 1810
 			}
@@ -1722,36 +1814,41 @@  discard block
 block discarded – undo
1722 1814
 	if (!empty($vars))
1723 1815
 	{
1724 1816
 		$settingsArray[$i++] = '';
1725
-		foreach ($vars as $var => $val)
1726
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1817
+		foreach ($vars as $var => $val) {
1818
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1819
+		}
1727 1820
 	}
1728 1821
 
1729 1822
 	// Blank out the file - done to fix a oddity with some servers.
1730 1823
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1731
-	if (!$fp)
1732
-		return false;
1824
+	if (!$fp) {
1825
+			return false;
1826
+	}
1733 1827
 	fclose($fp);
1734 1828
 
1735 1829
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1736 1830
 
1737 1831
 	// Gotta have one of these ;)
1738
-	if (trim($settingsArray[0]) != '<?php')
1739
-		fwrite($fp, "<?php\n");
1832
+	if (trim($settingsArray[0]) != '<?php') {
1833
+			fwrite($fp, "<?php\n");
1834
+	}
1740 1835
 
1741 1836
 	$lines = count($settingsArray);
1742 1837
 	for ($i = 0; $i < $lines - 1; $i++)
1743 1838
 	{
1744 1839
 		// Don't just write a bunch of blank lines.
1745
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1746
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1840
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1841
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1842
+		}
1747 1843
 	}
1748 1844
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1749 1845
 	fclose($fp);
1750 1846
 
1751 1847
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1752 1848
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1753
-	if (function_exists('opcache_invalidate'))
1754
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1849
+	if (function_exists('opcache_invalidate')) {
1850
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1851
+	}
1755 1852
 
1756 1853
 	return true;
1757 1854
 }
@@ -1776,9 +1873,9 @@  discard block
 block discarded – undo
1776 1873
 	SecFilterScanPOST Off
1777 1874
 </IfModule>';
1778 1875
 
1779
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1780
-		return true;
1781
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1876
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1877
+			return true;
1878
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1782 1879
 	{
1783 1880
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1784 1881
 
@@ -1790,29 +1887,28 @@  discard block
 block discarded – undo
1790 1887
 				fwrite($ht_handle, $htaccess_addition);
1791 1888
 				fclose($ht_handle);
1792 1889
 				return true;
1890
+			} else {
1891
+							return false;
1793 1892
 			}
1794
-			else
1795
-				return false;
1893
+		} else {
1894
+					return true;
1796 1895
 		}
1797
-		else
1798
-			return true;
1799
-	}
1800
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1801
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1802
-	elseif (is_writable(dirname(__FILE__)))
1896
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1897
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1898
+	} elseif (is_writable(dirname(__FILE__)))
1803 1899
 	{
1804 1900
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1805 1901
 		{
1806 1902
 			fwrite($ht_handle, $htaccess_addition);
1807 1903
 			fclose($ht_handle);
1808 1904
 			return true;
1905
+		} else {
1906
+					return false;
1809 1907
 		}
1810
-		else
1908
+	} else {
1811 1909
 			return false;
1812 1910
 	}
1813
-	else
1814
-		return false;
1815
-}
1911
+	}
1816 1912
 
1817 1913
 function template_install_above()
1818 1914
 {
@@ -1850,9 +1946,10 @@  discard block
 block discarded – undo
1850 1946
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1851 1947
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1852 1948
 
1853
-		foreach ($incontext['detected_languages'] as $lang => $name)
1854
-			echo '
1949
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1950
+					echo '
1855 1951
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1952
+		}
1856 1953
 
1857 1954
 		echo '
1858 1955
 								</select>
@@ -1872,9 +1969,10 @@  discard block
 block discarded – undo
1872 1969
 						<h2>', $txt['upgrade_progress'], '</h2>
1873 1970
 						<ul>';
1874 1971
 
1875
-	foreach ($incontext['steps'] as $num => $step)
1876
-		echo '
1972
+	foreach ($incontext['steps'] as $num => $step) {
1973
+			echo '
1877 1974
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1975
+	}
1878 1976
 
1879 1977
 	echo '
1880 1978
 						</ul>
@@ -1899,20 +1997,23 @@  discard block
 block discarded – undo
1899 1997
 		echo '
1900 1998
 								<div>';
1901 1999
 
1902
-		if (!empty($incontext['continue']))
1903
-			echo '
2000
+		if (!empty($incontext['continue'])) {
2001
+					echo '
1904 2002
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1905
-		if (!empty($incontext['skip']))
1906
-			echo '
2003
+		}
2004
+		if (!empty($incontext['skip'])) {
2005
+					echo '
1907 2006
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
2007
+		}
1908 2008
 		echo '
1909 2009
 								</div>';
1910 2010
 	}
1911 2011
 
1912 2012
 	// Show the closing form tag and other data only if not in the last step
1913
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1914
-		echo '
2013
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2014
+			echo '
1915 2015
 							</form>';
2016
+	}
1916 2017
 
1917 2018
 	echo '
1918 2019
 						</div>
@@ -1947,13 +2048,15 @@  discard block
 block discarded – undo
1947 2048
 		</div>';
1948 2049
 
1949 2050
 	// Show the warnings, or not.
1950
-	if (template_warning_divs())
1951
-		echo '
2051
+	if (template_warning_divs()) {
2052
+			echo '
1952 2053
 		<h3>', $txt['install_all_lovely'], '</h3>';
2054
+	}
1953 2055
 
1954 2056
 	// Say we want the continue button!
1955
-	if (empty($incontext['error']))
1956
-		$incontext['continue'] = 1;
2057
+	if (empty($incontext['error'])) {
2058
+			$incontext['continue'] = 1;
2059
+	}
1957 2060
 
1958 2061
 	// For the latest version stuff.
1959 2062
 	echo '
@@ -1987,8 +2090,8 @@  discard block
 block discarded – undo
1987 2090
 	global $txt, $incontext;
1988 2091
 
1989 2092
 	// Errors are very serious..
1990
-	if (!empty($incontext['error']))
1991
-		echo '
2093
+	if (!empty($incontext['error'])) {
2094
+			echo '
1992 2095
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1993 2096
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1994 2097
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1996,9 +2099,10 @@  discard block
 block discarded – undo
1996 2099
 				', $incontext['error'], '
1997 2100
 			</div>
1998 2101
 		</div>';
2102
+	}
1999 2103
 	// A warning message?
2000
-	elseif (!empty($incontext['warning']))
2001
-		echo '
2104
+	elseif (!empty($incontext['warning'])) {
2105
+			echo '
2002 2106
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2003 2107
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2004 2108
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2006,6 +2110,7 @@  discard block
 block discarded – undo
2006 2110
 				', $incontext['warning'], '
2007 2111
 			</div>
2008 2112
 		</div>';
2113
+	}
2009 2114
 
2010 2115
 	return empty($incontext['error']) && empty($incontext['warning']);
2011 2116
 }
@@ -2021,27 +2126,30 @@  discard block
 block discarded – undo
2021 2126
 			<li>', $incontext['failed_files']), '</li>
2022 2127
 		</ul>';
2023 2128
 
2024
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2025
-		echo '
2129
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2130
+			echo '
2026 2131
 		<hr>
2027 2132
 		<p>', $txt['chmod_linux_info'], '</p>
2028 2133
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2134
+	}
2029 2135
 
2030 2136
 	// This is serious!
2031
-	if (!template_warning_divs())
2032
-		return;
2137
+	if (!template_warning_divs()) {
2138
+			return;
2139
+	}
2033 2140
 
2034 2141
 	echo '
2035 2142
 		<hr>
2036 2143
 		<p>', $txt['ftp_setup_info'], '</p>';
2037 2144
 
2038
-	if (!empty($incontext['ftp_errors']))
2039
-		echo '
2145
+	if (!empty($incontext['ftp_errors'])) {
2146
+			echo '
2040 2147
 		<div class="error_message">
2041 2148
 			', $txt['error_ftp_no_connect'], '<br><br>
2042 2149
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2043 2150
 		</div>
2044 2151
 		<br>';
2152
+	}
2045 2153
 
2046 2154
 	echo '
2047 2155
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2101,17 +2209,17 @@  discard block
 block discarded – undo
2101 2209
 				<td>
2102 2210
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2103 2211
 
2104
-	foreach ($incontext['supported_databases'] as $key => $db)
2105
-			echo '
2212
+	foreach ($incontext['supported_databases'] as $key => $db) {
2213
+				echo '
2106 2214
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2215
+	}
2107 2216
 
2108 2217
 	echo '
2109 2218
 					</select>
2110 2219
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2111 2220
 				</td>
2112 2221
 			</tr>';
2113
-	}
2114
-	else
2222
+	} else
2115 2223
 	{
2116 2224
 		echo '
2117 2225
 			<tr style="display: none;">
@@ -2303,9 +2411,10 @@  discard block
 block discarded – undo
2303 2411
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2304 2412
 				<ul>';
2305 2413
 
2306
-		foreach ($incontext['failures'] as $line => $fail)
2307
-			echo '
2414
+		foreach ($incontext['failures'] as $line => $fail) {
2415
+					echo '
2308 2416
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2417
+		}
2309 2418
 
2310 2419
 		echo '
2311 2420
 				</ul>';
@@ -2366,15 +2475,16 @@  discard block
 block discarded – undo
2366 2475
 			</tr>
2367 2476
 		</table>';
2368 2477
 
2369
-	if ($incontext['require_db_confirm'])
2370
-		echo '
2478
+	if ($incontext['require_db_confirm']) {
2479
+			echo '
2371 2480
 		<h2>', $txt['user_settings_database'], '</h2>
2372 2481
 		<p>', $txt['user_settings_database_info'], '</p>
2373 2482
 
2374 2483
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2375 2484
 			<input type="password" name="password3" size="30" class="input_password" />
2376 2485
 		</div>';
2377
-}
2486
+	}
2487
+	}
2378 2488
 
2379 2489
 // Tell them it's done, and to delete.
2380 2490
 function template_delete_install()
@@ -2387,14 +2497,15 @@  discard block
 block discarded – undo
2387 2497
 	template_warning_divs();
2388 2498
 
2389 2499
 	// Install directory still writable?
2390
-	if ($incontext['dir_still_writable'])
2391
-		echo '
2500
+	if ($incontext['dir_still_writable']) {
2501
+			echo '
2392 2502
 		<em>', $txt['still_writable'], '</em><br>
2393 2503
 		<br>';
2504
+	}
2394 2505
 
2395 2506
 	// Don't show the box if it's like 99% sure it won't work :P.
2396
-	if ($incontext['probably_delete_install'])
2397
-		echo '
2507
+	if ($incontext['probably_delete_install']) {
2508
+			echo '
2398 2509
 		<div style="margin: 1ex; font-weight: bold;">
2399 2510
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2400 2511
 		</div>
@@ -2410,6 +2521,7 @@  discard block
 block discarded – undo
2410 2521
 			}
2411 2522
 		</script>
2412 2523
 		<br>';
2524
+	}
2413 2525
 
2414 2526
 	echo '
2415 2527
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
Themes/default/Display.template.php 1 patch
Braces   +221 added lines, -151 removed lines patch added patch discarded remove patch
@@ -51,11 +51,13 @@  discard block
 block discarded – undo
51 51
 				<p>';
52 52
 
53 53
 		// Show just numbers...?
54
-		if ($settings['display_who_viewing'] == 1)
55
-				echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
54
+		if ($settings['display_who_viewing'] == 1) {
55
+						echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
56
+		}
56 57
 		// Or show the actual people viewing the topic?
57
-		else
58
-			echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
58
+		else {
59
+					echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
60
+		}
59 61
 
60 62
 		// Now show how many guests are here too.
61 63
 		echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_topic'], '
@@ -93,10 +95,11 @@  discard block
 block discarded – undo
93 95
 						<dt class="', $option['voted_this'] ? ' voted' : '', '">', $option['option'], '</dt>
94 96
 						<dd class="statsbar', $option['voted_this'] ? ' voted' : '', '">';
95 97
 
96
-				if ($context['allow_results_view'])
97
-					echo '
98
+				if ($context['allow_results_view']) {
99
+									echo '
98 100
 							', $option['bar_ndt'], '
99 101
 							<span class="percentage">', $option['votes'], ' (', $option['percent'], '%)</span>';
102
+				}
100 103
 
101 104
 				echo '
102 105
 						</dd>';
@@ -105,9 +108,10 @@  discard block
 block discarded – undo
105 108
 			echo '
106 109
 					</dl>';
107 110
 
108
-			if ($context['allow_results_view'])
109
-				echo '
111
+			if ($context['allow_results_view']) {
112
+							echo '
110 113
 						<p><strong>', $txt['poll_total_voters'], ':</strong> ', $context['poll']['total_votes'], '</p>';
114
+			}
111 115
 		}
112 116
 		// They are allowed to vote! Go to it!
113 117
 		else
@@ -116,17 +120,19 @@  discard block
 block discarded – undo
116 120
 						<form action="', $scripturl, '?action=vote;topic=', $context['current_topic'], '.', $context['start'], ';poll=', $context['poll']['id'], '" method="post" accept-charset="', $context['character_set'], '">';
117 121
 
118 122
 			// Show a warning if they are allowed more than one option.
119
-			if ($context['poll']['allowed_warning'])
120
-				echo '
123
+			if ($context['poll']['allowed_warning']) {
124
+							echo '
121 125
 							<p class="smallpadding">', $context['poll']['allowed_warning'], '</p>';
126
+			}
122 127
 
123 128
 			echo '
124 129
 							<ul class="options">';
125 130
 
126 131
 			// Show each option with its button - a radio likely.
127
-			foreach ($context['poll']['options'] as $option)
128
-				echo '
132
+			foreach ($context['poll']['options'] as $option) {
133
+							echo '
129 134
 								<li>', $option['vote_button'], ' <label for="', $option['id'], '">', $option['option'], '</label></li>';
135
+			}
130 136
 
131 137
 			echo '
132 138
 							</ul>
@@ -138,9 +144,10 @@  discard block
 block discarded – undo
138 144
 		}
139 145
 
140 146
 		// Is the clock ticking?
141
-		if (!empty($context['poll']['expire_time']))
142
-			echo '
147
+		if (!empty($context['poll']['expire_time'])) {
148
+					echo '
143 149
 						<p><strong>', ($context['poll']['is_expired'] ? $txt['poll_expired_on'] : $txt['poll_expires_on']), ':</strong> ', $context['poll']['expire_time'], '</p>';
150
+		}
144 151
 
145 152
 		echo '
146 153
 					</div>
@@ -170,11 +177,13 @@  discard block
 block discarded – undo
170 177
 					<li>
171 178
 						<b class="event_title"><a href="', $scripturl, '?action=calendar;event=', $event['id'], '">', $event['title'], '</a></b>';
172 179
 
173
-			if ($event['can_edit'])
174
-				echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
180
+			if ($event['can_edit']) {
181
+							echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
182
+			}
175 183
 
176
-			if ($event['can_export'])
177
-				echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
184
+			if ($event['can_export']) {
185
+							echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
186
+			}
178 187
 
179 188
 			echo '
180 189
 						<br>';
@@ -182,14 +191,14 @@  discard block
 block discarded – undo
182 191
 			if (!empty($event['allday']))
183 192
 			{
184 193
 				echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
185
-			}
186
-			else
194
+			} else
187 195
 			{
188 196
 				// Display event info relative to user's local timezone
189 197
 				echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
190 198
 
191
-				if ($event['start_date_local'] != $event['end_date_local'])
192
-					echo trim($event['end_date_local']) . ', ';
199
+				if ($event['start_date_local'] != $event['end_date_local']) {
200
+									echo trim($event['end_date_local']) . ', ';
201
+				}
193 202
 
194 203
 				echo trim($event['end_time_local']);
195 204
 
@@ -198,23 +207,27 @@  discard block
 block discarded – undo
198 207
 				{
199 208
 					echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
200 209
 
201
-					if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
202
-						echo trim($event['start_date_orig']), ', ';
210
+					if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) {
211
+											echo trim($event['start_date_orig']), ', ';
212
+					}
203 213
 
204 214
 					echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
205 215
 
206
-					if ($event['start_date_orig'] != $event['end_date_orig'])
207
-						echo trim($event['end_date_orig']) . ', ';
216
+					if ($event['start_date_orig'] != $event['end_date_orig']) {
217
+											echo trim($event['end_date_orig']) . ', ';
218
+					}
208 219
 
209 220
 					echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
210 221
 				}
211 222
 				// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
212
-				else
213
-					echo ' ', $event['tz_abbrev'], '</time>';
223
+				else {
224
+									echo ' ', $event['tz_abbrev'], '</time>';
225
+				}
214 226
 			}
215 227
 
216
-			if (!empty($event['location']))
217
-				echo '<br>', $event['location'];
228
+			if (!empty($event['location'])) {
229
+							echo '<br>', $event['location'];
230
+			}
218 231
 
219 232
 			echo '
220 233
 					</li>';
@@ -252,8 +265,9 @@  discard block
 block discarded – undo
252 265
 	$context['removableMessageIDs'] = array();
253 266
 
254 267
 	// Get all the messages...
255
-	while ($message = $context['get_message']())
256
-		template_single_post($message);
268
+	while ($message = $context['get_message']()) {
269
+			template_single_post($message);
270
+	}
257 271
 
258 272
 	echo '
259 273
 				</form>
@@ -290,8 +304,9 @@  discard block
 block discarded – undo
290 304
 			<div id="display_jump_to">&nbsp;</div>';
291 305
 
292 306
 	// Show quickreply
293
-	if ($context['can_reply'])
294
-	template_quickreply();
307
+	if ($context['can_reply']) {
308
+		template_quickreply();
309
+	}
295 310
 
296 311
 	// User action pop on mobile screen (or actually small screen), this uses responsive css does not check mobile device.
297 312
 	echo '
@@ -304,8 +319,8 @@  discard block
 block discarded – undo
304 319
 			</div>';
305 320
 
306 321
 	// Show the moderation button & pop only if user can moderate
307
-	if ($context['can_moderate_forum'] || $context['user']['is_mod'])
308
-		echo '
322
+	if ($context['can_moderate_forum'] || $context['user']['is_mod']) {
323
+			echo '
309 324
 			<div id="mobile_moderation" class="popup_container">
310 325
 				<div class="popup_window description">
311 326
 					<div class="popup_heading">', $txt['mobile_moderation'],'
@@ -315,6 +330,7 @@  discard block
 block discarded – undo
315 330
 					</div>
316 331
 				</div>
317 332
 			</div>';
333
+	}
318 334
 
319 335
 		echo '
320 336
 				<script>';
@@ -438,9 +454,10 @@  discard block
 block discarded – undo
438 454
 						});
439 455
 					}';
440 456
 
441
-	if (!empty($context['ignoredMsgs']))
442
-		echo '
457
+	if (!empty($context['ignoredMsgs'])) {
458
+			echo '
443 459
 					ignore_toggles([', implode(', ', $context['ignoredMsgs']), '], ', JavaScriptEscape($txt['show_ignore_user_post']), ');';
460
+	}
444 461
 
445 462
 	echo '
446 463
 				</script>';
@@ -457,8 +474,9 @@  discard block
 block discarded – undo
457 474
 
458 475
 	$ignoring = false;
459 476
 
460
-	if ($message['can_remove'])
461
-		$context['removableMessageIDs'][] = $message['id'];
477
+	if ($message['can_remove']) {
478
+			$context['removableMessageIDs'][] = $message['id'];
479
+	}
462 480
 
463 481
 	// Are we ignoring this message?
464 482
 	if (!empty($message['is_ignored']))
@@ -484,9 +502,10 @@  discard block
 block discarded – undo
484 502
 							<div class="custom_fields_above_member">
485 503
 								<ul class="nolist">';
486 504
 
487
-		foreach ($message['custom_fields']['above_member'] as $custom)
488
-			echo '
505
+		foreach ($message['custom_fields']['above_member'] as $custom) {
506
+					echo '
489 507
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
508
+		}
490 509
 
491 510
 		echo '
492 511
 								</ul>
@@ -497,9 +516,10 @@  discard block
 block discarded – undo
497 516
 									<h4>';
498 517
 
499 518
 	// Show online and offline buttons?
500
-	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
501
-		echo '
519
+	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest']) {
520
+			echo '
502 521
 								', $context['can_send_pm'] ? '<a href="' . $message['member']['online']['href'] . '" title="' . $message['member']['online']['label'] . '">' : '', '<span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>', $context['can_send_pm'] ? '</a>' : '';
522
+	}
503 523
 
504 524
 
505 525
 	// Show a link to the member's profile.
@@ -512,51 +532,59 @@  discard block
 block discarded – undo
512 532
 
513 533
 
514 534
 	// Show the user's avatar.
515
-	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
516
-		echo '
535
+	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image'])) {
536
+			echo '
517 537
 								<li class="avatar">
518 538
 									<a href="', $message['member']['href'], '">', $message['member']['avatar']['image'], '</a>
519 539
 								</li>';
540
+	}
520 541
 
521 542
 	// Are there any custom fields below the avatar?
522
-	if (!empty($message['custom_fields']['below_avatar']))
523
-		foreach ($message['custom_fields']['below_avatar'] as $custom)
543
+	if (!empty($message['custom_fields']['below_avatar'])) {
544
+			foreach ($message['custom_fields']['below_avatar'] as $custom)
524 545
 			echo '
525 546
 								<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
547
+	}
526 548
 
527 549
 	// Show the post group icons, but not for guests.
528
-	if (!$message['member']['is_guest'])
529
-		echo '
550
+	if (!$message['member']['is_guest']) {
551
+			echo '
530 552
 								<li class="icons">', $message['member']['group_icons'], '</li>';
553
+	}
531 554
 
532 555
 	// Show the member's primary group (like 'Administrator') if they have one.
533
-	if (!empty($message['member']['group']))
534
-		echo '
556
+	if (!empty($message['member']['group'])) {
557
+			echo '
535 558
 								<li class="membergroup">', $message['member']['group'], '</li>';
559
+	}
536 560
 
537 561
 	// Show the member's custom title, if they have one.
538
-	if (!empty($message['member']['title']))
539
-		echo '
562
+	if (!empty($message['member']['title'])) {
563
+			echo '
540 564
 								<li class="title">', $message['member']['title'], '</li>';
565
+	}
541 566
 
542 567
 	// Don't show these things for guests.
543 568
 	if (!$message['member']['is_guest'])
544 569
 	{
545 570
 
546 571
 		// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
547
-		if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group']))
548
-			echo '
572
+		if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group'])) {
573
+					echo '
549 574
 								<li class="postgroup">', $message['member']['post_group'], '</li>';
575
+		}
550 576
 
551 577
 		// Show how many posts they have made.
552
-		if (!isset($context['disabled_fields']['posts']))
553
-			echo '
578
+		if (!isset($context['disabled_fields']['posts'])) {
579
+					echo '
554 580
 								<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
581
+		}
555 582
 
556 583
 		// Show their personal text?
557
-		if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb']))
558
-			echo '
584
+		if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb'])) {
585
+					echo '
559 586
 								<li class="blurb">', $message['member']['blurb'], '</li>';
587
+		}
560 588
 
561 589
 		// Any custom fields to show as icons?
562 590
 		if (!empty($message['custom_fields']['icons']))
@@ -565,9 +593,10 @@  discard block
 block discarded – undo
565 593
 								<li class="im_icons">
566 594
 									<ol>';
567 595
 
568
-			foreach ($message['custom_fields']['icons'] as $custom)
569
-				echo '
596
+			foreach ($message['custom_fields']['icons'] as $custom) {
597
+							echo '
570 598
 										<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
599
+			}
571 600
 
572 601
 			echo '
573 602
 									</ol>
@@ -582,19 +611,22 @@  discard block
 block discarded – undo
582 611
 									<ol class="profile_icons">';
583 612
 
584 613
 			// Don't show an icon if they haven't specified a website.
585
-			if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website']))
586
-				echo '
614
+			if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website'])) {
615
+							echo '
587 616
 										<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" class="new_win">', ($settings['use_image_buttons'] ? '<span class="generic_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
617
+			}
588 618
 
589 619
 			// Since we know this person isn't a guest, you *can* message them.
590
-			if ($context['can_send_pm'])
591
-				echo '
620
+			if ($context['can_send_pm']) {
621
+							echo '
592 622
 										<li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<span class="generic_icons im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . ' centericon" title="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '"></span> ' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>';
623
+			}
593 624
 
594 625
 			// Show the email if necessary
595
-			if (!empty($message['member']['email']) && $message['member']['show_email'])
596
-				echo '
626
+			if (!empty($message['member']['email']) && $message['member']['show_email']) {
627
+							echo '
597 628
 										<li class="email"><a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
629
+			}
598 630
 
599 631
 				echo '
600 632
 									</ol>
@@ -602,48 +634,56 @@  discard block
 block discarded – undo
602 634
 		}
603 635
 
604 636
 		// Any custom fields for standard placement?
605
-		if (!empty($message['custom_fields']['standard']))
606
-			foreach ($message['custom_fields']['standard'] as $custom)
637
+		if (!empty($message['custom_fields']['standard'])) {
638
+					foreach ($message['custom_fields']['standard'] as $custom)
607 639
 				echo '
608 640
 								<li class="custom ', $custom['col_name'] ,'">', $custom['title'], ': ', $custom['value'], '</li>';
641
+		}
609 642
 
610 643
 	}
611 644
 	// Otherwise, show the guest's email.
612
-	elseif (!empty($message['member']['email']) && $message['member']['show_email'])
613
-		echo '
645
+	elseif (!empty($message['member']['email']) && $message['member']['show_email']) {
646
+			echo '
614 647
 								<li class="email"><a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
648
+	}
615 649
 
616 650
 	// Show the IP to this user for this post - because you can moderate?
617
-	if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip']))
618
-		echo '
651
+	if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip'])) {
652
+			echo '
619 653
 								<li class="poster_ip"><a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">(?)</a></li>';
654
+	}
620 655
 
621 656
 	// Or, should we show it because this is you?
622
-	elseif ($message['can_see_ip'])
623
-		echo '
657
+	elseif ($message['can_see_ip']) {
658
+			echo '
624 659
 								<li class="poster_ip"><a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $message['member']['ip'], '</a></li>';
660
+	}
625 661
 
626 662
 	// Okay, are you at least logged in? Then we can show something about why IPs are logged...
627
-	elseif (!$context['user']['is_guest'])
628
-		echo '
663
+	elseif (!$context['user']['is_guest']) {
664
+			echo '
629 665
 								<li class="poster_ip"><a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a></li>';
666
+	}
630 667
 
631 668
 	// Otherwise, you see NOTHING!
632
-	else
633
-		echo '
669
+	else {
670
+			echo '
634 671
 								<li class="poster_ip">', $txt['logged'], '</li>';
672
+	}
635 673
 
636 674
 	// Are we showing the warning status?
637 675
 	// Don't show these things for guests.
638
-	if (!$message['member']['is_guest'] && $message['member']['can_see_warning'])
639
-		echo '
676
+	if (!$message['member']['is_guest'] && $message['member']['can_see_warning']) {
677
+			echo '
640 678
 								<li class="warning">', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="generic_icons warning_', $message['member']['warning_status'], '"></span> ', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span></li>';
679
+	}
641 680
 
642 681
 	// Are there any custom fields to show at the bottom of the poster info?
643
-	if (!empty($message['custom_fields']['bottom_poster']))
644
-		foreach ($message['custom_fields']['bottom_poster'] as $custom)
682
+	if (!empty($message['custom_fields']['bottom_poster'])) {
683
+			foreach ($message['custom_fields']['bottom_poster'] as $custom)
645 684
 			echo '
646 685
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
686
+	}
647 687
 
648 688
 	// Poster info ends.
649 689
 	echo '
@@ -672,9 +712,10 @@  discard block
 block discarded – undo
672 712
 	echo '
673 713
 									<span class="smalltext modified" id="modified_', $message['id'], '">';
674 714
 
675
-	if (!empty($modSettings['show_modify']) && !empty($message['modified']['name']))
676
-		echo
715
+	if (!empty($modSettings['show_modify']) && !empty($message['modified']['name'])) {
716
+			echo
677 717
 										$message['modified']['last_edit_text'];
718
+	}
678 719
 
679 720
 	echo '
680 721
 									</span>';
@@ -685,22 +726,24 @@  discard block
 block discarded – undo
685 726
 							</div>';
686 727
 
687 728
 	// Ignoring this user? Hide the post.
688
-	if ($ignoring)
689
-		echo '
729
+	if ($ignoring) {
730
+			echo '
690 731
 							<div id="msg_', $message['id'], '_ignored_prompt">
691 732
 								', $txt['ignoring_user'], '
692 733
 								<a href="#" id="msg_', $message['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
693 734
 							</div>';
735
+	}
694 736
 
695 737
 	// Show the post itself, finally!
696 738
 	echo '
697 739
 							<div class="post">';
698 740
 
699
-	if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id'])
700
-		echo '
741
+	if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id']) {
742
+			echo '
701 743
 								<div class="approve_post">
702 744
 									', $txt['post_awaiting_approval'], '
703 745
 								</div>';
746
+	}
704 747
 	echo '
705 748
 								<div class="inner" data-msgid="', $message['id'], '" id="msg_', $message['id'], '"', $ignoring ? ' style="display:none;"' : '', '>', $message['body'], '</div>
706 749
 							</div>';
@@ -717,9 +760,9 @@  discard block
 block discarded – undo
717 760
 		foreach ($message['attachment'] as $attachment)
718 761
 		{
719 762
 			// Do we want this attachment to not be showed here?
720
-			if (!empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']]))
721
-				continue;
722
-			elseif (!$div_output)
763
+			if (!empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']])) {
764
+							continue;
765
+			} elseif (!$div_output)
723 766
 			{
724 767
 				$div_output = true;
725 768
 
@@ -735,9 +778,10 @@  discard block
 block discarded – undo
735 778
 								<fieldset>
736 779
 									<legend>', $txt['attach_awaiting_approve'];
737 780
 
738
-				if ($context['can_approve'])
739
-					echo '
781
+				if ($context['can_approve']) {
782
+									echo '
740 783
 										&nbsp;[<a href="', $scripturl, '?action=attachapprove;sa=all;mid=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve_all'], '</a>]';
784
+				}
741 785
 
742 786
 				echo '
743 787
 									</legend>';
@@ -751,12 +795,13 @@  discard block
 block discarded – undo
751 795
 				echo '
752 796
 										<div class="attachments_top">';
753 797
 
754
-				if ($attachment['thumbnail']['has_thumb'])
755
-					echo '
798
+				if ($attachment['thumbnail']['has_thumb']) {
799
+									echo '
756 800
 											<a href="', $attachment['href'], ';image" id="link_', $attachment['id'], '" onclick="', $attachment['thumbnail']['javascript'], '"><img src="', $attachment['thumbnail']['href'], '" alt="" id="thumb_', $attachment['id'], '" class="atc_img"></a>';
757
-				else
758
-					echo '
801
+				} else {
802
+									echo '
759 803
 											<img src="' . $attachment['href'] . ';image" alt="" width="' . $attachment['width'] . '" height="' . $attachment['height'] . '" class="atc_img">';
804
+				}
760 805
 
761 806
 				echo '
762 807
 										</div>';
@@ -766,9 +811,10 @@  discard block
 block discarded – undo
766 811
 										<div class="attachments_bot">
767 812
 											<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.png" class="centericon" alt="*">&nbsp;' . $attachment['name'] . '</a> ';
768 813
 
769
-			if (!$attachment['is_approved'] && $context['can_approve'])
770
-				echo '
814
+			if (!$attachment['is_approved'] && $context['can_approve']) {
815
+							echo '
771 816
 											[<a href="', $scripturl, '?action=attachapprove;sa=approve;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve'], '</a>]&nbsp;|&nbsp;[<a href="', $scripturl, '?action=attachapprove;sa=reject;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['delete'], '</a>] ';
817
+			}
772 818
 			echo '
773 819
 											<br>', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . '<br>' . sprintf($txt['attach_viewed'], $attachment['downloads']) : '<br>' . sprintf($txt['attach_downloaded'], $attachment['downloads'])), '
774 820
 										</div>';
@@ -777,33 +823,38 @@  discard block
 block discarded – undo
777 823
 									</div>';
778 824
 
779 825
 			// Next attachment line ?
780
-			if (++$i % $attachments_per_line === 0)
781
-				echo '
826
+			if (++$i % $attachments_per_line === 0) {
827
+							echo '
782 828
 									<br>';
829
+			}
783 830
 		}
784 831
 
785 832
 		// If we had unapproved attachments clean up.
786
-		if ($last_approved_state == 0)
787
-			echo '
833
+		if ($last_approved_state == 0) {
834
+					echo '
788 835
 								</fieldset>';
836
+		}
789 837
 
790 838
 		// Only do this if we output a div above - otherwise it'll break things
791
-		if ($div_output)
792
-			echo '
839
+		if ($div_output) {
840
+					echo '
793 841
 							</div>';
842
+		}
794 843
 	}
795 844
 
796 845
 	// And stuff below the attachments.
797
-	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote'])
798
-	echo '
846
+	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote']) {
847
+		echo '
799 848
 							<div class="under_message">';
849
+	}
800 850
 
801 851
 	// Maybe they want to report this post to the moderator(s)?
802
-	if ($context['can_report_moderator'])
803
-		echo '
852
+	if ($context['can_report_moderator']) {
853
+			echo '
804 854
 								<ul class="floatright smalltext">
805 855
 									<li class="report_link"><a href="', $scripturl, '?action=reporttm;topic=', $context['current_topic'], '.', $message['counter'], ';msg=', $message['id'], '">', $txt['report_to_mod'], '</a></li>
806 856
 								</ul>';
857
+	}
807 858
 
808 859
 	// What about likes?
809 860
 	if (!empty($modSettings['enable_likes']))
@@ -844,78 +895,91 @@  discard block
 block discarded – undo
844 895
 								<ul class="quickbuttons">';
845 896
 
846 897
 		// Can they quote? if so they can select and quote as well!
847
-		if ($context['can_quote'])
848
-			echo '
898
+		if ($context['can_quote']) {
899
+					echo '
849 900
 									<li><a href="', $scripturl, '?action=post;quote=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], ';last_msg=', $context['topic_last_message'], '" onclick="return oQuickReply.quote(', $message['id'], ');"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>
850 901
 									<li style="display:none;" id="quoteSelected_', $message['id'], '"><a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'] ,'</a></li>';
902
+		}
851 903
 
852 904
 		// Can the user modify the contents of this post? Show the modify inline image.
853
-		if ($message['can_modify'])
854
-			echo '
905
+		if ($message['can_modify']) {
906
+					echo '
855 907
 									<li class="quick_edit"><a title="', $txt['modify_msg'], '" class="modifybutton" id="modify_button_', $message['id'], '" onclick="oQuickModify.modifyMsg(\'', $message['id'], '\', \'', !empty($modSettings['toggle_subject']), '\')"><span class="generic_icons quick_edit_button"></span>', $txt['quick_edit'], '</a></li>';
908
+		}
856 909
 
857
-		if ($message['can_approve'] || $message['can_unapprove'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'])
858
-			echo '
910
+		if ($message['can_approve'] || $message['can_unapprove'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg']) {
911
+					echo '
859 912
 									<li class="post_options">', $txt['post_options'];
913
+		}
860 914
 
861 915
 		echo '
862 916
 										<ul>';
863 917
 
864 918
 		// Can the user modify the contents of this post?
865
-		if ($message['can_modify'])
866
-			echo '
919
+		if ($message['can_modify']) {
920
+					echo '
867 921
 											<li><a href="', $scripturl, '?action=post;msg=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], '"><span class="generic_icons modify_button"></span>', $txt['modify'], '</a></li>';
922
+		}
868 923
 
869 924
 		// How about... even... remove it entirely?!
870
-		if ($context['can_delete'] && ($context['topic_first_message'] == $message['id']))
871
-			echo '
925
+		if ($context['can_delete'] && ($context['topic_first_message'] == $message['id'])) {
926
+					echo '
872 927
 											<li><a href="', $scripturl, '?action=removetopic2;topic=', $context['current_topic'], '.', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['are_sure_remove_topic'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove_topic'],'</a></li>';
873
-		elseif ($message['can_remove'] && ($context['topic_first_message'] != $message['id']))
874
-			echo '
928
+		} elseif ($message['can_remove'] && ($context['topic_first_message'] != $message['id'])) {
929
+					echo '
875 930
 											<li><a href="', $scripturl, '?action=deletemsg;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message_question'] ,'" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
931
+		}
876 932
 
877 933
 		// What about splitting it off the rest of the topic?
878
-		if ($context['can_split'] && !empty($context['real_num_replies']))
879
-			echo '
934
+		if ($context['can_split'] && !empty($context['real_num_replies'])) {
935
+					echo '
880 936
 											<li><a href="', $scripturl, '?action=splittopics;topic=', $context['current_topic'], '.0;at=', $message['id'], '"><span class="generic_icons split_button"></span>', $txt['split'], '</a></li>';
937
+		}
881 938
 
882 939
 		// Can we issue a warning because of this post? Remember, we can't give guests warnings.
883
-		if ($context['can_issue_warning'] && !$message['is_message_author'] && !$message['member']['is_guest'])
884
-			echo '
940
+		if ($context['can_issue_warning'] && !$message['is_message_author'] && !$message['member']['is_guest']) {
941
+					echo '
885 942
 											<li><a href="', $scripturl, '?action=profile;area=issuewarning;u=', $message['member']['id'], ';msg=', $message['id'], '"><span class="generic_icons warn_button"></span>', $txt['issue_warning'], '</a></li>';
943
+		}
886 944
 
887 945
 		// Can we restore topics?
888
-		if ($context['can_restore_msg'])
889
-			echo '
946
+		if ($context['can_restore_msg']) {
947
+					echo '
890 948
 											<li><a href="', $scripturl, '?action=restoretopic;msgs=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons restore_button"></span>', $txt['restore_message'], '</a></li>';
949
+		}
891 950
 
892 951
 		// Maybe we can approve it, maybe we should?
893
-		if ($message['can_approve'])
894
-			echo '
952
+		if ($message['can_approve']) {
953
+					echo '
895 954
 											<li><a href="', $scripturl, '?action=moderate;area=postmod;sa=approve;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons approve_button"></span>', $txt['approve'], '</a></li>';
955
+		}
896 956
 
897 957
 		// Maybe we can unapprove it?
898
-		if ($message['can_unapprove'])
899
-			echo '
958
+		if ($message['can_unapprove']) {
959
+					echo '
900 960
 											<li><a href="', $scripturl, '?action=moderate;area=postmod;sa=approve;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons unapprove_button"></span>', $txt['unapprove'], '</a></li>';
961
+		}
901 962
 
902 963
 		echo '
903 964
 										</ul>
904 965
 									</li>';
905 966
 
906 967
 		// Show a checkbox for quick moderation?
907
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove'])
908
-			echo '
968
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove']) {
969
+					echo '
909 970
 									<li style="display: none;" id="in_topic_mod_check_', $message['id'], '"></li>';
971
+		}
910 972
 
911
-		if ($message['can_approve'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'])
912
-			echo '
973
+		if ($message['can_approve'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg']) {
974
+					echo '
913 975
 								</ul>';
976
+		}
914 977
 	}
915 978
 
916
-	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote'])
917
-	echo '
979
+	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote']) {
980
+		echo '
918 981
 							</div>';
982
+	}
919 983
 
920 984
 	echo '
921 985
 						</div>
@@ -928,9 +992,10 @@  discard block
 block discarded – undo
928 992
 							<div class="custom_fields_above_signature">
929 993
 								<ul class="nolist">';
930 994
 
931
-		foreach ($message['custom_fields']['above_signature'] as $custom)
932
-			echo '
995
+		foreach ($message['custom_fields']['above_signature'] as $custom) {
996
+					echo '
933 997
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
998
+		}
934 999
 
935 1000
 		echo '
936 1001
 								</ul>
@@ -938,9 +1003,10 @@  discard block
 block discarded – undo
938 1003
 	}
939 1004
 
940 1005
 	// Show the member's signature?
941
-	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
942
-		echo '
1006
+	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled']) {
1007
+			echo '
943 1008
 							<div class="signature" id="msg_', $message['id'], '_signature"', $ignoring ? ' style="display:none;"' : '', '>', $message['member']['signature'], '</div>';
1009
+	}
944 1010
 
945 1011
 
946 1012
 	// Are there any custom profile fields for below the signature?
@@ -950,9 +1016,10 @@  discard block
 block discarded – undo
950 1016
 							<div class="custom_fields_below_signature">
951 1017
 								<ul class="nolist">';
952 1018
 
953
-		foreach ($message['custom_fields']['below_signature'] as $custom)
954
-			echo '
1019
+		foreach ($message['custom_fields']['below_signature'] as $custom) {
1020
+					echo '
955 1021
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
1022
+		}
956 1023
 
957 1024
 		echo '
958 1025
 								</ul>
@@ -1000,8 +1067,8 @@  discard block
 block discarded – undo
1000 1067
 						<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">';
1001 1068
 
1002 1069
 		// Guests just need more.
1003
-		if ($context['user']['is_guest'])
1004
-			echo '
1070
+		if ($context['user']['is_guest']) {
1071
+					echo '
1005 1072
 						<dl id="post_header">
1006 1073
 							<dt>
1007 1074
 								', $txt['name'], ':
@@ -1016,6 +1083,7 @@  discard block
 block discarded – undo
1016 1083
 								<input type="email" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" class="input_text" required>
1017 1084
 							</dd>
1018 1085
 						</dl>';
1086
+		}
1019 1087
 
1020 1088
 		echo '
1021 1089
 						', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message'), '
@@ -1063,8 +1131,8 @@  discard block
 block discarded – undo
1063 1131
 		<br class="clear">';
1064 1132
 
1065 1133
 	// draft autosave available and the user has it enabled?
1066
-	if (!empty($context['drafts_autosave']))
1067
-		echo '
1134
+	if (!empty($context['drafts_autosave'])) {
1135
+			echo '
1068 1136
 			<script>
1069 1137
 				var oDraftAutoSave = new smf_DraftAutoSave({
1070 1138
 					sSelf: \'oDraftAutoSave\',
@@ -1076,10 +1144,12 @@  discard block
 block discarded – undo
1076 1144
 					iFreq: ', (empty($modSettings['masterAutoSaveDraftsDelay']) ? 60000 : $modSettings['masterAutoSaveDraftsDelay'] * 1000), '
1077 1145
 				});
1078 1146
 			</script>';
1147
+	}
1079 1148
 
1080
-	if ($context['show_spellchecking'])
1081
-		echo '
1149
+	if ($context['show_spellchecking']) {
1150
+			echo '
1082 1151
 			<form action="', $scripturl, '?action=spellcheck" method="post" accept-charset="', $context['character_set'], '" name="spell_form" id="spell_form" target="spellWindow"><input type="hidden" name="spellstring" value=""></form>';
1152
+	}
1083 1153
 
1084 1154
 	echo '
1085 1155
 				<script>
Please login to merge, or discard this patch.
Themes/default/Calendar.template.php 1 patch
Braces   +124 added lines, -93 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@  discard block
 block discarded – undo
40 40
 				', template_show_week_grid('main'), '
41 41
 			</div>
42 42
 		';
43
-	}
44
-	else
43
+	} else
45 44
 	{
46 45
 		echo '
47 46
 			<div id="main_grid">
@@ -67,17 +66,19 @@  discard block
 block discarded – undo
67 66
 	global $context, $settings, $txt, $scripturl, $modSettings;
68 67
 
69 68
 	// If the grid doesn't exist, no point in proceeding.
70
-	if (!isset($context['calendar_grid_' . $grid_name]))
71
-		return false;
69
+	if (!isset($context['calendar_grid_' . $grid_name])) {
70
+			return false;
71
+	}
72 72
 
73 73
 	// A handy little pointer variable.
74 74
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
75 75
 
76 76
 	// Some conditions for whether or not we should show the week links *here*.
77
-	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false)))
78
-		$show_week_links = true;
79
-	else
80
-		$show_week_links = false;
77
+	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) {
78
+			$show_week_links = true;
79
+	} else {
80
+			$show_week_links = false;
81
+	}
81 82
 
82 83
 	// Assuming that we've not disabled it, show the title block!
83 84
 	if (empty($calendar_data['disable_title']))
@@ -124,8 +125,9 @@  discard block
 block discarded – undo
124 125
 		echo '<tr>';
125 126
 
126 127
 		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
127
-		if ($show_week_links === true)
128
-			echo '<th>&nbsp;</th>';
128
+		if ($show_week_links === true) {
129
+					echo '<th>&nbsp;</th>';
130
+		}
129 131
 
130 132
 		// Now, loop through each actual day of the week.
131 133
 		foreach ($calendar_data['week_days'] as $day)
@@ -172,29 +174,32 @@  discard block
 block discarded – undo
172 174
 				// Additional classes are given for events, holidays, and birthdays.
173 175
 				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
174 176
 				{
175
-					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1,3)))
176
-						$classes[] = 'events';
177
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2,3)))
178
-						$classes[] = 'events';
177
+					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1,3))) {
178
+											$classes[] = 'events';
179
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2,3))) {
180
+											$classes[] = 'events';
181
+					}
179 182
 				}
180 183
 				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
181 184
 				{
182
-					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1,3)))
183
-						$classes[] = 'holidays';
184
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2,3)))
185
-						$classes[] = 'holidays';
185
+					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1,3))) {
186
+											$classes[] = 'holidays';
187
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2,3))) {
188
+											$classes[] = 'holidays';
189
+					}
186 190
 				}
187 191
 				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
188 192
 				{
189
-					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1,3)))
190
-						$classes[] = 'birthdays';
191
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2,3)))
192
-						$classes[] = 'birthdays';
193
+					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1,3))) {
194
+											$classes[] = 'birthdays';
195
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2,3))) {
196
+											$classes[] = 'birthdays';
197
+					}
193 198
 				}
194
-			}
195
-			else
196
-				// Default Classes (either compact or comfortable and disabled).
199
+			} else {
200
+							// Default Classes (either compact or comfortable and disabled).
197 201
 				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
202
+			}
198 203
 				$classes[] = 'disabled';
199 204
 
200 205
 			// Now, implode the classes for each day.
@@ -208,17 +213,19 @@  discard block
 block discarded – undo
208 213
 				$title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : '';
209 214
 
210 215
 				// The actual day number - be it a link, or just plain old text!
211
-				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
212
-					echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
213
-				else
214
-					echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
216
+				if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
217
+									echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
218
+				} else {
219
+									echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
220
+				}
215 221
 
216 222
 				// A lot of stuff, we're not showing on mini-calendars to conserve space.
217 223
 				if ($is_mini === false)
218 224
 				{
219 225
 					// Holidays are always fun, let's show them!
220
-					if (!empty($day['holidays']))
221
-						echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
226
+					if (!empty($day['holidays'])) {
227
+											echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
228
+					}
222 229
 
223 230
 					// Happy Birthday Dear, Member!
224 231
 					if (!empty($day['birthdays']))
@@ -236,14 +243,16 @@  discard block
 block discarded – undo
236 243
 							echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', ';
237 244
 
238 245
 							// 9...10! Let's stop there.
239
-							if ($birthday_count == 10 && $use_js_hide)
240
-								// !!TODO - Inline CSS and JavaScript should be moved.
246
+							if ($birthday_count == 10 && $use_js_hide) {
247
+															// !!TODO - Inline CSS and JavaScript should be moved.
241 248
 								echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, ';
249
+							}
242 250
 
243 251
 							++$birthday_count;
244 252
 						}
245
-						if ($use_js_hide)
246
-							echo '</span>';
253
+						if ($use_js_hide) {
254
+													echo '</span>';
255
+						}
247 256
 
248 257
 						echo '</div>';
249 258
 					}
@@ -253,8 +262,9 @@  discard block
 block discarded – undo
253 262
 					{
254 263
 						// Sort events by start time (all day events will be listed first)
255 264
 						uasort($day['events'], function ($a, $b) {
256
-						    if ($a['start_timestamp'] == $b['start_timestamp'])
257
-						        return 0;
265
+						    if ($a['start_timestamp'] == $b['start_timestamp']) {
266
+						    						        return 0;
267
+						    }
258 268
 						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
259 269
 						});
260 270
 
@@ -270,17 +280,19 @@  discard block
 block discarded – undo
270 280
 
271 281
 							echo '<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">', $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
272 282
 
273
-							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
274
-								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
275
-							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
276
-								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
277
-							elseif (!empty($event['allday']))
278
-								echo $txt['calendar_allday'];
283
+							if (!empty($event['start_time_local']) && $event['starts_today'] == true) {
284
+															echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
285
+							} elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) {
286
+															echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
287
+							} elseif (!empty($event['allday'])) {
288
+															echo $txt['calendar_allday'];
289
+							}
279 290
 
280 291
 							echo '</span>';
281 292
 
282
-							if (!empty($event['location']))
283
-								echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
293
+							if (!empty($event['location'])) {
294
+															echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
295
+							}
284 296
 
285 297
 							if ($event['can_edit'] || $event['can_export'])
286 298
 							{
@@ -317,10 +329,11 @@  discard block
 block discarded – undo
317 329
 			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
318 330
 			elseif ($is_mini === false)
319 331
 			{
320
-				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
321
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- + 1, '</a>';
322
-				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
323
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
332
+				if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) {
333
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- + 1, '</a>';
334
+				} elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) {
335
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
336
+				}
324 337
 			}
325 338
 
326 339
 			// Close this day and increase var count.
@@ -332,8 +345,9 @@  discard block
 block discarded – undo
332 345
 	}
333 346
 
334 347
 	// Quick Month Navigation + Post Event Link on Main Grids!
335
-	if ($is_mini === false)
336
-		template_calendar_base($show_week_links === true ? 8 : 7);
348
+	if ($is_mini === false) {
349
+			template_calendar_base($show_week_links === true ? 8 : 7);
350
+	}
337 351
 
338 352
 	// The end of our main table.
339 353
 	echo '</table>';
@@ -350,8 +364,9 @@  discard block
 block discarded – undo
350 364
 	global $context, $settings, $txt, $scripturl, $modSettings;
351 365
 
352 366
 	// We might have no reason to proceed, if the variable isn't there.
353
-	if (!isset($context['calendar_grid_' . $grid_name]))
354
-		return false;
367
+	if (!isset($context['calendar_grid_' . $grid_name])) {
368
+			return false;
369
+	}
355 370
 
356 371
 	// Handy pointer.
357 372
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -387,8 +402,9 @@  discard block
 block discarded – undo
387 402
 					}
388 403
 
389 404
 					// The Month Title + Week Number...
390
-					if (!empty($calendar_data['week_title']))
391
-							echo $calendar_data['week_title'];
405
+					if (!empty($calendar_data['week_title'])) {
406
+												echo $calendar_data['week_title'];
407
+					}
392 408
 
393 409
 					echo '
394 410
 					</h3>
@@ -424,10 +440,11 @@  discard block
 block discarded – undo
424 440
 						<tr class="days_wrapper">
425 441
 							<td class="', implode(' ', $classes), ' act_day">';
426 442
 							// Should the day number be a link?
427
-							if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
428
-								echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
429
-							else
430
-								echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
443
+							if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
444
+															echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
445
+							} else {
446
+															echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
447
+							}
431 448
 
432 449
 							echo '</td>
433 450
 							<td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">';
@@ -436,8 +453,9 @@  discard block
 block discarded – undo
436 453
 							{
437 454
 								// Sort events by start time (all day events will be listed first)
438 455
 								uasort($day['events'], function ($a, $b) {
439
-								    if ($a['start_timestamp'] == $b['start_timestamp'])
440
-								        return 0;
456
+								    if ($a['start_timestamp'] == $b['start_timestamp']) {
457
+								    								        return 0;
458
+								    }
441 459
 								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
442 460
 								});
443 461
 
@@ -449,15 +467,17 @@  discard block
 block discarded – undo
449 467
 
450 468
 									echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
451 469
 
452
-									if (!empty($event['start_time_local']))
453
-										echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
454
-									else
455
-										echo $txt['calendar_allday'];
470
+									if (!empty($event['start_time_local'])) {
471
+																			echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
472
+									} else {
473
+																			echo $txt['calendar_allday'];
474
+									}
456 475
 
457 476
 									echo '</span>';
458 477
 
459
-									if (!empty($event['location']))
460
-										echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
478
+									if (!empty($event['location'])) {
479
+																			echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
480
+									}
461 481
 
462 482
 									if (!empty($event_icons_needed))
463 483
 									{
@@ -494,8 +514,7 @@  discard block
 block discarded – undo
494 514
 									</div>
495 515
 									<br class="clear">';
496 516
 								}
497
-							}
498
-							else
517
+							} else
499 518
 							{
500 519
 								if (!empty($context['can_post']))
501 520
 								{
@@ -508,8 +527,9 @@  discard block
 block discarded – undo
508 527
 							echo '</td>
509 528
 							<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
510 529
 							// Show any holidays!
511
-							if (!empty($day['holidays']))
512
-								echo implode('<br>', $day['holidays']);
530
+							if (!empty($day['holidays'])) {
531
+															echo implode('<br>', $day['holidays']);
532
+							}
513 533
 
514 534
 							echo '</td>
515 535
 							<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
@@ -529,8 +549,9 @@  discard block
 block discarded – undo
529 549
 				}
530 550
 
531 551
 				// We'll show the lower column after our last month is shown.
532
-				if ($iteration == $num_months)
533
-					template_calendar_base(4);
552
+				if ($iteration == $num_months) {
553
+									template_calendar_base(4);
554
+				}
534 555
 
535 556
 				// Increase iteration for loop counting.
536 557
 				++$iteration;
@@ -592,8 +613,9 @@  discard block
 block discarded – undo
592 613
 	echo '
593 614
 		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);smc_saveEntities(\'postevent\', [\'evtitle\']);" style="margin: 0;">';
594 615
 
595
-	if (!empty($context['event']['new']))
596
-		echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
616
+	if (!empty($context['event']['new'])) {
617
+			echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
618
+	}
597 619
 
598 620
 	// Start the main table.
599 621
 	echo '
@@ -643,9 +665,10 @@  discard block
 block discarded – undo
643 665
 		{
644 666
 			echo '
645 667
 								<optgroup label="', $category['name'], '">';
646
-			foreach ($category['boards'] as $board)
647
-				echo '
668
+			foreach ($category['boards'] as $board) {
669
+							echo '
648 670
 									<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
671
+			}
649 672
 			echo '
650 673
 								</optgroup>';
651 674
 		}
@@ -681,9 +704,10 @@  discard block
 block discarded – undo
681 704
 							<span class="label">', $txt['calendar_timezone'], '</span>
682 705
 							<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
683 706
 
684
-	foreach ($context['all_timezones'] as $tz => $tzname)
685
-		echo '
707
+	foreach ($context['all_timezones'] as $tz => $tzname) {
708
+			echo '
686 709
 								<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
710
+	}
687 711
 
688 712
 	echo '
689 713
 							</select>
@@ -698,9 +722,10 @@  discard block
 block discarded – undo
698 722
 	echo '
699 723
 				<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">';
700 724
 	// Delete button?
701
-	if (empty($context['event']['new']))
702
-		echo '
725
+	if (empty($context['event']['new'])) {
726
+			echo '
703 727
 				<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button_submit you_sure">';
728
+	}
704 729
 
705 730
 	echo '
706 731
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -744,9 +769,10 @@  discard block
 block discarded – undo
744 769
 
745 770
 		foreach ($context['clockicons'] as $t => $v)
746 771
 		{
747
-			foreach ($v as $i)
748
-				echo '
772
+			foreach ($v as $i) {
773
+							echo '
749 774
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
775
+			}
750 776
 		}
751 777
 
752 778
 		echo '
@@ -771,13 +797,14 @@  discard block
 block discarded – undo
771 797
 
772 798
 		foreach ($context['clockicons'] as $t => $v)
773 799
 		{
774
-			foreach ($v as $i)
775
-				echo '
800
+			foreach ($v as $i) {
801
+							echo '
776 802
 			if (', $t, ' >= ', $i, ')
777 803
 			{
778 804
 				turnon.push("', $t, '_', $i, '");
779 805
 				', $t, ' -= ', $i, ';
780 806
 			}';
807
+			}
781 808
 		}
782 809
 
783 810
 		echo '
@@ -841,9 +868,10 @@  discard block
 block discarded – undo
841 868
 
842 869
 	foreach ($context['clockicons'] as $t => $v)
843 870
 	{
844
-		foreach ($v as $i)
845
-			echo '
871
+		foreach ($v as $i) {
872
+					echo '
846 873
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
874
+		}
847 875
 	}
848 876
 
849 877
 	echo '
@@ -860,13 +888,14 @@  discard block
 block discarded – undo
860 888
 
861 889
 	foreach ($context['clockicons'] as $t => $v)
862 890
 	{
863
-		foreach ($v as $i)
864
-			echo '
891
+		foreach ($v as $i) {
892
+					echo '
865 893
 		if (', $t, ' >= ', $i, ')
866 894
 		{
867 895
 			turnon.push("', $t, '_', $i, '");
868 896
 			', $t, ' -= ', $i, ';
869 897
 		}';
898
+		}
870 899
 	}
871 900
 
872 901
 	echo '
@@ -925,9 +954,10 @@  discard block
 block discarded – undo
925 954
 
926 955
 	foreach ($context['clockicons'] as $t => $v)
927 956
 	{
928
-		foreach ($v as $i)
929
-			echo '
957
+		foreach ($v as $i) {
958
+					echo '
930 959
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
960
+		}
931 961
 	}
932 962
 
933 963
 	echo '
@@ -948,13 +978,14 @@  discard block
 block discarded – undo
948 978
 
949 979
 	foreach ($context['clockicons'] as $t => $v)
950 980
 	{
951
-		foreach ($v as $i)
952
-		echo '
981
+		foreach ($v as $i) {
982
+				echo '
953 983
 		if (', $t, ' >= ', $i, ')
954 984
 		{
955 985
 			turnon.push("', $t, '_', $i, '");
956 986
 			', $t, ' -= ', $i, ';
957 987
 		}';
988
+		}
958 989
 	}
959 990
 
960 991
 	echo '
Please login to merge, or discard this patch.
Themes/default/Post.template.php 1 patch
Braces   +98 added lines, -67 removed lines patch added patch discarded remove patch
@@ -22,22 +22,24 @@  discard block
 block discarded – undo
22 22
 		<script>';
23 23
 
24 24
 	// When using Go Back due to fatal_error, allow the form to be re-submitted with changes.
25
-	if (isBrowser('is_firefox'))
26
-		echo '
25
+	if (isBrowser('is_firefox')) {
26
+			echo '
27 27
 			window.addEventListener("pageshow", reActivate, false);';
28
+	}
28 29
 
29 30
 	// Start with message icons - and any missing from this theme.
30 31
 	echo '
31 32
 			var icon_urls = {';
32
-	foreach ($context['icons'] as $icon)
33
-		echo '
33
+	foreach ($context['icons'] as $icon) {
34
+			echo '
34 35
 				\'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ',';
36
+	}
35 37
 	echo '
36 38
 			};';
37 39
 
38 40
 	// If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations.
39
-	if ($context['make_poll'])
40
-		echo '
41
+	if ($context['make_poll']) {
42
+			echo '
41 43
 			var pollOptionNum = 0, pollTabIndex;
42 44
 			var pollOptionId = ', $context['last_choice_id'], ';
43 45
 			function addPollOption()
@@ -56,11 +58,13 @@  discard block
 block discarded – undo
56 58
 
57 59
 				setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<dt><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>:</dt><dd><input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('" class="input_text"></dd><p id="pollMoreOptions"></p>'), ');
58 60
 			}';
61
+	}
59 62
 
60 63
 	// If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here.
61
-	if ($context['make_event'])
62
-		echo '
64
+	if ($context['make_event']) {
65
+			echo '
63 66
 			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];';
67
+	}
64 68
 
65 69
 	// End of the javascript, start the form and display the link tree.
66 70
 	echo '
@@ -80,9 +84,10 @@  discard block
 block discarded – undo
80 84
 				</div>
81 85
 			</div><br>';
82 86
 
83
-	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board'])))
84
-		echo '
87
+	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board']))) {
88
+			echo '
85 89
 			<input type="hidden" name="eventid" value="', $context['event']['id'], '">';
90
+	}
86 91
 
87 92
 	// Start the main table.
88 93
 	echo '
@@ -117,26 +122,28 @@  discard block
 block discarded – undo
117 122
 	}
118 123
 
119 124
 	// If it's locked, show a message to warn the replier.
120
-	if (!empty($context['locked']))
121
-	echo '
125
+	if (!empty($context['locked'])) {
126
+		echo '
122 127
 					<p class="errorbox">
123 128
 						', $txt['topic_locked_no_reply'], '
124 129
 					</p>';
130
+	}
125 131
 
126
-	if (!empty($modSettings['drafts_post_enabled']))
127
-		echo '
132
+	if (!empty($modSettings['drafts_post_enabled'])) {
133
+			echo '
128 134
 					<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
129 135
 						sprintf($txt['draft_saved'], $scripturl . '?action=profile;u=' . $context['user']['id'] . ';area=showdrafts'), '
130 136
 						', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
131 137
 					</div>';
138
+	}
132 139
 
133 140
 	// The post header... important stuff
134 141
 	echo '
135 142
 					<dl id="post_header">';
136 143
 
137 144
 	// Custom posting fields.
138
-	if (!empty($context['posting_fields']) && is_array($context['posting_fields']))
139
-		foreach ($context['posting_fields'] as $pf)
145
+	if (!empty($context['posting_fields']) && is_array($context['posting_fields'])) {
146
+			foreach ($context['posting_fields'] as $pf)
140 147
 			echo '
141 148
 						<dt>
142 149
 							', $pf['dt'] ,'
@@ -144,6 +151,7 @@  discard block
 block discarded – undo
144 151
 						<dd>
145 152
 							', $pf['dd'] ,'
146 153
 						</dd>';
154
+	}
147 155
 
148 156
 
149 157
 	// Guests have to put in their name and email...
@@ -157,14 +165,15 @@  discard block
 block discarded – undo
157 165
 							<input type="text" name="guestname" size="25" value="', $context['name'], '" tabindex="', $context['tabindex']++, '" class="input_text">
158 166
 						</dd>';
159 167
 
160
-		if (empty($modSettings['guest_post_no_email']))
161
-			echo '
168
+		if (empty($modSettings['guest_post_no_email'])) {
169
+					echo '
162 170
 						<dt>
163 171
 							<span', isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? ' class="error"' : '', ' id="caption_email">', $txt['email'], ':</span>
164 172
 						</dt>
165 173
 						<dd>
166 174
 							<input type="email" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" class="input_text" required>
167 175
 						</dd>';
176
+		}
168 177
 	}
169 178
 
170 179
 	// Now show the subject box for this post.
@@ -182,9 +191,10 @@  discard block
 block discarded – undo
182 191
 							<select name="icon" id="icon" onchange="showimage()">';
183 192
 
184 193
 	// Loop through each message icon allowed, adding it to the drop down list.
185
-	foreach ($context['icons'] as $icon)
186
-		echo '
194
+	foreach ($context['icons'] as $icon) {
195
+			echo '
187 196
 								<option value="', $icon['value'], '"', $icon['value'] == $context['icon'] ? ' selected' : '', '>', $icon['name'], '</option>';
197
+	}
188 198
 
189 199
 	echo '
190 200
 							</select>
@@ -219,9 +229,10 @@  discard block
 block discarded – undo
219 229
 				{
220 230
 					echo '
221 231
 										<optgroup label="', $category['name'], '">';
222
-					foreach ($category['boards'] as $board)
223
-						echo '
232
+					foreach ($category['boards'] as $board) {
233
+											echo '
224 234
 											<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
235
+					}
225 236
 					echo '
226 237
 										</optgroup>';
227 238
 				}
@@ -257,9 +268,10 @@  discard block
 block discarded – undo
257 268
 									<span class="label">', $txt['calendar_timezone'], '</span>
258 269
 									<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
259 270
 
260
-			foreach ($context['all_timezones'] as $tz => $tzname)
261
-				echo '
271
+			foreach ($context['all_timezones'] as $tz => $tzname) {
272
+							echo '
262 273
 										<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
274
+			}
263 275
 
264 276
 			echo '
265 277
 									</select>
@@ -325,14 +337,15 @@  discard block
 block discarded – undo
325 337
 									<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', ' class="input_check">
326 338
 								</dd>';
327 339
 
328
-		if ($context['poll_options']['guest_vote_enabled'])
329
-			echo '
340
+		if ($context['poll_options']['guest_vote_enabled']) {
341
+					echo '
330 342
 								<dt>
331 343
 									<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
332 344
 								</dt>
333 345
 								<dd>
334 346
 									<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked' : '', ' class="input_check">
335 347
 								</dd>';
348
+		}
336 349
 
337 350
 		echo '
338 351
 								<dt>
@@ -353,8 +366,8 @@  discard block
 block discarded – undo
353 366
 					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
354 367
 
355 368
 	// If we're editing and displaying edit details, show a box where they can say why
356
-	if (isset($context['editing']) && $modSettings['show_modify'])
357
-		echo '
369
+	if (isset($context['editing']) && $modSettings['show_modify']) {
370
+			echo '
358 371
 					<dl>
359 372
 						<dt class="clear">
360 373
 							<span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span>
@@ -363,20 +376,23 @@  discard block
 block discarded – undo
363 376
 							<input type="text" name="modify_reason"', isset($context['last_modified_reason']) ? ' value="' . $context['last_modified_reason'] . '"' : '', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text">
364 377
 						</dd>
365 378
 					</dl>';
379
+	}
366 380
 
367 381
 	// If this message has been edited in the past - display when it was.
368
-	if (isset($context['last_modified']))
369
-		echo '
382
+	if (isset($context['last_modified'])) {
383
+			echo '
370 384
 					<div class="padding smalltext">
371 385
 						', $context['last_modified_text'], '
372 386
 					</div>';
387
+	}
373 388
 
374 389
 	// If the admin has enabled the hiding of the additional options - show a link and image for it.
375
-	if (!empty($modSettings['additional_options_collapsable']))
376
-		echo '
390
+	if (!empty($modSettings['additional_options_collapsable'])) {
391
+			echo '
377 392
 					<div id="postAdditionalOptionsHeader">
378 393
 						<strong><a href="#" id="postMoreExpandLink"> ', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong>
379 394
 					</div>';
395
+	}
380 396
 
381 397
 	echo '
382 398
 					<div id="postAdditionalOptions">';
@@ -408,19 +424,21 @@  discard block
 block discarded – undo
408 424
 								<input type="hidden" name="attach_del[]" value="0">
409 425
 								', $txt['uncheck_unwatchd_attach'], ':
410 426
 							</dd>';
411
-		foreach ($context['current_attachments'] as $attachment)
412
-			echo '
427
+		foreach ($context['current_attachments'] as $attachment) {
428
+					echo '
413 429
 							<dd class="smalltext">
414 430
 								<label for="attachment_', $attachment['attachID'], '"><input type="checkbox" id="attachment_', $attachment['attachID'], '" name="attach_del[]" value="', $attachment['attachID'], '"', empty($attachment['unchecked']) ? ' checked' : '', ' class="input_check"> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''),
415 431
 								!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1028) / 1028), 0)) : '', '</label>
416 432
 							</dd>';
433
+		}
417 434
 
418 435
 		echo '
419 436
 						</dl>';
420 437
 
421
-		if (!empty($context['files_in_session_warning']))
422
-			echo '
438
+		if (!empty($context['files_in_session_warning'])) {
439
+					echo '
423 440
 						<div class="smalltext">', $context['files_in_session_warning'], '</div>';
441
+		}
424 442
 	}
425 443
 
426 444
 	// Is the user allowed to post any additional ones? If so give them the boxes to do it!
@@ -473,8 +491,8 @@  discard block
 block discarded – undo
473 491
 								', empty($modSettings['attachmentSizeLimit']) ? '' : ('<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1028 . '">');
474 492
 
475 493
 		// Show more boxes if they aren't approaching that limit.
476
-		if ($context['num_allowed_attachments'] > 1)
477
-			echo '
494
+		if ($context['num_allowed_attachments'] > 1) {
495
+					echo '
478 496
 										<script>
479 497
 											var allowed_attachments = ', $context['num_allowed_attachments'], ';
480 498
 											var current_attachment = 1;
@@ -495,9 +513,10 @@  discard block
 block discarded – undo
495 513
 									</div>
496 514
 								</div>
497 515
 							</dd>';
498
-		else
499
-			echo '
516
+		} else {
517
+					echo '
500 518
 							</dd>';
519
+		}
501 520
 
502 521
 		// Add any template changes for an alternative upload system here.
503 522
 		call_integration_hook('integrate_upload_template');
@@ -506,21 +525,25 @@  discard block
 block discarded – undo
506 525
 							<dd class="smalltext">';
507 526
 
508 527
 		// Show some useful information such as allowed extensions, maximum size and amount of attachments allowed.
509
-		if (!empty($modSettings['attachmentCheckExtensions']))
510
-			echo '
528
+		if (!empty($modSettings['attachmentCheckExtensions'])) {
529
+					echo '
511 530
 								', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br>';
531
+		}
512 532
 
513
-		if (!empty($context['attachment_restrictions']))
514
-			echo '
533
+		if (!empty($context['attachment_restrictions'])) {
534
+					echo '
515 535
 								', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br>';
536
+		}
516 537
 
517
-		if ($context['num_allowed_attachments'] == 0)
518
-			echo '
538
+		if ($context['num_allowed_attachments'] == 0) {
539
+					echo '
519 540
 								', $txt['attach_limit_nag'], '<br>';
541
+		}
520 542
 
521
-		if (!$context['can_post_attachment_unapproved'])
522
-			echo '
543
+		if (!$context['can_post_attachment_unapproved']) {
544
+					echo '
523 545
 								<span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br>';
546
+		}
524 547
 
525 548
 		echo '
526 549
 							</dd>
@@ -543,10 +566,11 @@  discard block
 block discarded – undo
543 566
 							<dt><strong>', $txt['subject'], '</strong></dt>
544 567
 							<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
545 568
 
546
-		foreach ($context['drafts'] as $draft)
547
-			echo '
569
+		foreach ($context['drafts'] as $draft) {
570
+					echo '
548 571
 							<dt>', $draft['link'], '</dt>
549 572
 							<dd>', $draft['poster_time'], '</dd>';
573
+		}
550 574
 		echo '
551 575
 						</dl>
552 576
 					</div>';
@@ -571,9 +595,10 @@  discard block
 block discarded – undo
571 595
 						', template_control_richedit_buttons($context['post_box_name']);
572 596
 
573 597
 	// Option to delete an event if user is editing one.
574
-	if ($context['make_event'] && !$context['event']['new'])
575
-		echo '
598
+	if ($context['make_event'] && !$context['event']['new']) {
599
+			echo '
576 600
 						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button_submit you_sure">';
601
+	}
577 602
 
578 603
 	echo '
579 604
 					</span>
@@ -582,9 +607,10 @@  discard block
 block discarded – undo
582 607
 			<br class="clear">';
583 608
 
584 609
 	// Assuming this isn't a new topic pass across the last message id.
585
-	if (isset($context['topic_last_message']))
586
-		echo '
610
+	if (isset($context['topic_last_message'])) {
611
+			echo '
587 612
 			<input type="hidden" name="last_msg" value="', $context['topic_last_message'], '">';
613
+	}
588 614
 
589 615
 	echo '
590 616
 			<input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '">
@@ -726,9 +752,10 @@  discard block
 block discarded – undo
726 752
 
727 753
 						newPostsHTML += \'<div class="windowbg\' + (++reply_counter % 2 == 0 ? \'2\' : \'\') + \'"><div id="msg\' + newPosts[i].getAttribute("id") + \'"><div class="floatleft"><h5>', $txt['posted_by'], ': \' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + \'</h5><span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> \' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue + \'&nbsp;&#187;</span> <span class="new_posts" id="image_new_\' + newPosts[i].getAttribute("id") + \'">', $txt['new'], '</span></div>\';';
728 754
 
729
-	if ($context['can_quote'])
730
-		echo '
755
+	if ($context['can_quote']) {
756
+			echo '
731 757
 						newPostsHTML += \'<ul class="quickbuttons" id="msg_\' + newPosts[i].getAttribute("id") + \'_quote"><li><a href="#postmodify" onclick="return insertQuoteFast(\\\'\' + newPosts[i].getAttribute("id") + \'\\\');" class="quote_button"><span>', $txt['quote'], '</span><\' + \'/a></li></ul>\';';
758
+	}
732 759
 
733 760
 	echo '
734 761
 						newPostsHTML += \'<br class="clear">\';
@@ -771,8 +798,8 @@  discard block
 block discarded – undo
771 798
 			}';
772 799
 
773 800
 	// Code for showing and hiding additional options.
774
-	if (!empty($modSettings['additional_options_collapsable']))
775
-		echo '
801
+	if (!empty($modSettings['additional_options_collapsable'])) {
802
+			echo '
776 803
 			var oSwapAdditionalOptions = new smc_Toggle({
777 804
 				bToggleEnabled: true,
778 805
 				bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ',
@@ -800,10 +827,11 @@  discard block
 block discarded – undo
800 827
 					}
801 828
 				]
802 829
 			});';
830
+	}
803 831
 
804 832
 	// Code for showing and hiding drafts
805
-	if (!empty($context['drafts']))
806
-		echo '
833
+	if (!empty($context['drafts'])) {
834
+			echo '
807 835
 			var oSwapDraftOptions = new smc_Toggle({
808 836
 				bToggleEnabled: true,
809 837
 				bCurrentlyCollapsed: true,
@@ -825,6 +853,7 @@  discard block
 block discarded – undo
825 853
 					}
826 854
 				]
827 855
 			});';
856
+	}
828 857
 
829 858
 	echo '
830 859
 			var oEditorID = "', $context['post_box_name'] ,'";
@@ -845,8 +874,9 @@  discard block
 block discarded – undo
845 874
 		foreach ($context['previous_posts'] as $post)
846 875
 		{
847 876
 			$ignoring = false;
848
-			if (!empty($post['is_ignored']))
849
-				$ignored_posts[] = $ignoring = $post['id'];
877
+			if (!empty($post['is_ignored'])) {
878
+							$ignored_posts[] = $ignoring = $post['id'];
879
+			}
850 880
 
851 881
 			echo '
852 882
 			<div class="windowbg">
@@ -1029,10 +1059,10 @@  discard block
 block discarded – undo
1029 1059
 		<div id="temporary_posting_area" style="display: none;"></div>
1030 1060
 		<script>';
1031 1061
 
1032
-	if ($context['close_window'])
1033
-		echo '
1062
+	if ($context['close_window']) {
1063
+			echo '
1034 1064
 			window.close();';
1035
-	else
1065
+	} else
1036 1066
 	{
1037 1067
 		// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;).
1038 1068
 		echo '
@@ -1086,11 +1116,12 @@  discard block
 block discarded – undo
1086 1116
 				</p>
1087 1117
 				<ul>';
1088 1118
 
1089
-	foreach ($context['groups'] as $group)
1090
-		echo '
1119
+	foreach ($context['groups'] as $group) {
1120
+			echo '
1091 1121
 					<li>
1092 1122
 						<label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked class="input_check"> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em>
1093 1123
 					</li>';
1124
+	}
1094 1125
 
1095 1126
 	echo '
1096 1127
 					<li>
Please login to merge, or discard this patch.
Sources/Subs-Db-mysqli.php 1 patch
Braces   +246 added lines, -180 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -58,9 +59,11 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource'            => 'smf_is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['persist']))
63
-		$db_server = 'p:' . $db_server;
64
+	if (!empty($db_options['persist'])) {
65
+			$db_server = 'p:' . $db_server;
66
+	}
64 67
 
65 68
 	$connection = mysqli_init();
66 69
 	
@@ -69,31 +72,35 @@  discard block
 block discarded – undo
69 72
 	$success = false;
70 73
 	
71 74
 	if ($connection) {
72
-		if (!empty($db_options['port']))
73
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags);
74
-		else
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags);
75
+		if (!empty($db_options['port'])) {
76
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags);
77
+		} else {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags);
79
+		}
76 80
 	}
77 81
 
78 82
 	// Something's wrong, show an error if its fatal (which we assume it is)
79 83
 	if ($success === false)
80 84
 	{
81
-		if (!empty($db_options['non_fatal']))
82
-			return null;
83
-		else
84
-			display_db_error();
85
+		if (!empty($db_options['non_fatal'])) {
86
+					return null;
87
+		} else {
88
+					display_db_error();
89
+		}
85 90
 	}
86 91
 
87 92
 	// Select the database, unless told not to
88
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
89
-		display_db_error();
93
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
94
+			display_db_error();
95
+	}
90 96
 
91 97
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
92
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
93
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
98
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
99
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
94 100
 		array(),
95 101
 		false
96 102
 	);
103
+	}
97 104
 
98 105
 	return $connection;
99 106
 }
@@ -164,37 +171,46 @@  discard block
 block discarded – undo
164 171
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 172
 
166 173
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
174
+	if (!is_object($connection)) {
175
+			display_db_error();
176
+	}
169 177
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
178
+	if ($matches[1] === 'db_prefix') {
179
+			return $db_prefix;
180
+	}
172 181
 
173
-	if ($matches[1] === 'query_see_board')
174
-		return $user_info['query_see_board'];
182
+	if ($matches[1] === 'query_see_board') {
183
+			return $user_info['query_see_board'];
184
+	}
175 185
 
176
-	if ($matches[1] === 'query_wanna_see_board')
177
-		return $user_info['query_wanna_see_board'];
186
+	if ($matches[1] === 'query_wanna_see_board') {
187
+			return $user_info['query_wanna_see_board'];
188
+	}
178 189
 
179
-	if ($matches[1] === 'empty')
180
-		return '\'\'';
190
+	if ($matches[1] === 'empty') {
191
+			return '\'\'';
192
+	}
181 193
 
182
-	if (!isset($matches[2]))
183
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
194
+	if (!isset($matches[2])) {
195
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
196
+	}
184 197
 
185
-	if ($matches[1] === 'literal')
186
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
198
+	if ($matches[1] === 'literal') {
199
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
200
+	}
187 201
 
188
-	if (!isset($values[$matches[2]]))
189
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
202
+	if (!isset($values[$matches[2]])) {
203
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
204
+	}
190 205
 
191 206
 	$replacement = $values[$matches[2]];
192 207
 
193 208
 	switch ($matches[1])
194 209
 	{
195 210
 		case 'int':
196
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
212
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			}
198 214
 			return (string) (int) $replacement;
199 215
 		break;
200 216
 
@@ -206,56 +222,63 @@  discard block
 block discarded – undo
206 222
 		case 'array_int':
207 223
 			if (is_array($replacement))
208 224
 			{
209
-				if (empty($replacement))
210
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+				if (empty($replacement)) {
226
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+				}
211 228
 
212 229
 				foreach ($replacement as $key => $value)
213 230
 				{
214
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
215
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
232
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+					}
216 234
 
217 235
 					$replacement[$key] = (string) (int) $value;
218 236
 				}
219 237
 
220 238
 				return implode(', ', $replacement);
239
+			} else {
240
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 241
 			}
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224 242
 
225 243
 		break;
226 244
 
227 245
 		case 'array_string':
228 246
 			if (is_array($replacement))
229 247
 			{
230
-				if (empty($replacement))
231
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
248
+				if (empty($replacement)) {
249
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+				}
232 251
 
233
-				foreach ($replacement as $key => $value)
234
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
252
+				foreach ($replacement as $key => $value) {
253
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
254
+				}
235 255
 
236 256
 				return implode(', ', $replacement);
257
+			} else {
258
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 259
 			}
238
-			else
239
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240 260
 		break;
241 261
 
242 262
 		case 'date':
243
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
244
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
245
-			else
246
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
264
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
265
+			} else {
266
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+			}
247 268
 		break;
248 269
 
249 270
 		case 'time':
250
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
251
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
252
-			else
253
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
272
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
273
+			} else {
274
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
275
+			}
254 276
 		break;
255 277
 
256 278
 		case 'float':
257
-			if (!is_numeric($replacement))
258
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+			if (!is_numeric($replacement)) {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
281
+			}
259 282
 			return (string) (float) $replacement;
260 283
 		break;
261 284
 
@@ -269,32 +292,37 @@  discard block
 block discarded – undo
269 292
 		break;
270 293
 
271 294
 		case 'inet':
272
-			if ($replacement == 'null' || $replacement == '')
273
-				return 'null';
274
-			if (!isValidIP($replacement))
275
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295
+			if ($replacement == 'null' || $replacement == '') {
296
+							return 'null';
297
+			}
298
+			if (!isValidIP($replacement)) {
299
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			}
276 301
 			//we don't use the native support of mysql > 5.6.2
277 302
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
278 303
 
279 304
 		case 'array_inet':
280 305
 			if (is_array($replacement))
281 306
 			{
282
-				if (empty($replacement))
283
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+				if (empty($replacement)) {
308
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
309
+				}
284 310
 
285 311
 				foreach ($replacement as $key => $value)
286 312
 				{
287
-					if ($replacement == 'null' || $replacement == '')
288
-						$replacement[$key] = 'null';
289
-					if (!isValidIP($value))
290
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
313
+					if ($replacement == 'null' || $replacement == '') {
314
+											$replacement[$key] = 'null';
315
+					}
316
+					if (!isValidIP($value)) {
317
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					}
291 319
 					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
292 320
 				}
293 321
 
294 322
 				return implode(', ', $replacement);
323
+			} else {
324
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295 325
 			}
296
-			else
297
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
298 326
 		break;
299 327
 
300 328
 		default:
@@ -370,22 +398,25 @@  discard block
 block discarded – undo
370 398
 		// Are we in SSI mode?  If so try that username and password first
371 399
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
372 400
 		{
373
-			if (empty($db_persist))
374
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
375
-			else
376
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
401
+			if (empty($db_persist)) {
402
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
403
+			} else {
404
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
405
+			}
377 406
 		}
378 407
 		// Fall back to the regular username and password if need be
379 408
 		if (!$db_connection)
380 409
 		{
381
-			if (empty($db_persist))
382
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
383
-			else
384
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
410
+			if (empty($db_persist)) {
411
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
412
+			} else {
413
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
414
+			}
385 415
 		}
386 416
 
387
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
388
-			$db_connection = false;
417
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
418
+					$db_connection = false;
419
+		}
389 420
 
390 421
 		$connection = $db_connection;
391 422
 	}
@@ -393,18 +424,20 @@  discard block
 block discarded – undo
393 424
 	// One more query....
394 425
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
395 426
 
396
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
397
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
427
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
428
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
429
+	}
398 430
 
399 431
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
400 432
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
401 433
 	{
402 434
 		// Add before LIMIT
403
-		if ($pos = strpos($db_string, 'LIMIT '))
404
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
405
-		else
406
-			// Append it.
435
+		if ($pos = strpos($db_string, 'LIMIT ')) {
436
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
437
+		} else {
438
+					// Append it.
407 439
 			$db_string .= "\n\t\t\tORDER BY null";
440
+		}
408 441
 	}
409 442
 
410 443
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -426,8 +459,9 @@  discard block
 block discarded – undo
426 459
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
427 460
 
428 461
 		// Initialize $db_cache if not already initialized.
429
-		if (!isset($db_cache))
430
-			$db_cache = array();
462
+		if (!isset($db_cache)) {
463
+					$db_cache = array();
464
+		}
431 465
 
432 466
 		if (!empty($_SESSION['debug_redirect']))
433 467
 		{
@@ -453,17 +487,18 @@  discard block
 block discarded – undo
453 487
 		while (true)
454 488
 		{
455 489
 			$pos = strpos($db_string, '\'', $pos + 1);
456
-			if ($pos === false)
457
-				break;
490
+			if ($pos === false) {
491
+							break;
492
+			}
458 493
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
459 494
 
460 495
 			while (true)
461 496
 			{
462 497
 				$pos1 = strpos($db_string, '\'', $pos + 1);
463 498
 				$pos2 = strpos($db_string, '\\', $pos + 1);
464
-				if ($pos1 === false)
465
-					break;
466
-				elseif ($pos2 === false || $pos2 > $pos1)
499
+				if ($pos1 === false) {
500
+									break;
501
+				} elseif ($pos2 === false || $pos2 > $pos1)
467 502
 				{
468 503
 					$pos = $pos1;
469 504
 					break;
@@ -479,29 +514,35 @@  discard block
 block discarded – undo
479 514
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
480 515
 
481 516
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
482
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
483
-			$fail = true;
517
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
518
+					$fail = true;
519
+		}
484 520
 		// Trying to change passwords, slow us down, or something?
485
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
486
-			$fail = true;
487
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
488
-			$fail = true;
521
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
522
+					$fail = true;
523
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
524
+					$fail = true;
525
+		}
489 526
 
490
-		if (!empty($fail) && function_exists('log_error'))
491
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
527
+		if (!empty($fail) && function_exists('log_error')) {
528
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
529
+		}
492 530
 	}
493 531
 
494
-	if (empty($db_unbuffered))
495
-		$ret = @mysqli_query($connection, $db_string);
496
-	else
497
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
532
+	if (empty($db_unbuffered)) {
533
+			$ret = @mysqli_query($connection, $db_string);
534
+	} else {
535
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
536
+	}
498 537
 
499
-	if ($ret === false && empty($db_values['db_error_skip']))
500
-		$ret = smf_db_error($db_string, $connection);
538
+	if ($ret === false && empty($db_values['db_error_skip'])) {
539
+			$ret = smf_db_error($db_string, $connection);
540
+	}
501 541
 
502 542
 	// Debugging.
503
-	if (isset($db_show_debug) && $db_show_debug === true)
504
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
543
+	if (isset($db_show_debug) && $db_show_debug === true) {
544
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
545
+	}
505 546
 
506 547
 	return $ret;
507 548
 }
@@ -550,12 +591,13 @@  discard block
 block discarded – undo
550 591
 	// Decide which connection to use
551 592
 	$connection = $connection === null ? $db_connection : $connection;
552 593
 
553
-	if ($type == 'begin')
554
-		return @mysqli_query($connection, 'BEGIN');
555
-	elseif ($type == 'rollback')
556
-		return @mysqli_query($connection, 'ROLLBACK');
557
-	elseif ($type == 'commit')
558
-		return @mysqli_query($connection, 'COMMIT');
594
+	if ($type == 'begin') {
595
+			return @mysqli_query($connection, 'BEGIN');
596
+	} elseif ($type == 'rollback') {
597
+			return @mysqli_query($connection, 'ROLLBACK');
598
+	} elseif ($type == 'commit') {
599
+			return @mysqli_query($connection, 'COMMIT');
600
+	}
559 601
 
560 602
 	return false;
561 603
 }
@@ -595,8 +637,9 @@  discard block
 block discarded – undo
595 637
 	//    2013: Lost connection to server during query.
596 638
 
597 639
 	// Log the error.
598
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
599
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
640
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
641
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
642
+	}
600 643
 
601 644
 	// Database error auto fixing ;).
602 645
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -605,8 +648,9 @@  discard block
 block discarded – undo
605 648
 		$old_cache = @$modSettings['cache_enable'];
606 649
 		$modSettings['cache_enable'] = '1';
607 650
 
608
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
609
-			$db_last_error = max(@$db_last_error, $temp);
651
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
652
+					$db_last_error = max(@$db_last_error, $temp);
653
+		}
610 654
 
611 655
 		if (@$db_last_error < time() - 3600 * 24 * 3)
612 656
 		{
@@ -622,8 +666,9 @@  discard block
 block discarded – undo
622 666
 					foreach ($tables as $table)
623 667
 					{
624 668
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
625
-						if (trim($table) != '')
626
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
669
+						if (trim($table) != '') {
670
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
671
+						}
627 672
 					}
628 673
 				}
629 674
 
@@ -632,8 +677,9 @@  discard block
 block discarded – undo
632 677
 			// Table crashed.  Let's try to fix it.
633 678
 			elseif ($query_errno == 1016)
634 679
 			{
635
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
636
-					$fix_tables = array('`' . $match[1] . '`');
680
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
681
+									$fix_tables = array('`' . $match[1] . '`');
682
+				}
637 683
 			}
638 684
 			// Indexes crashed.  Should be easy to fix!
639 685
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -652,13 +698,15 @@  discard block
 block discarded – undo
652 698
 
653 699
 			// Make a note of the REPAIR...
654 700
 			cache_put_data('db_last_error', time(), 600);
655
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
656
-				updateSettingsFile(array('db_last_error' => time()));
701
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
702
+							updateSettingsFile(array('db_last_error' => time()));
703
+			}
657 704
 
658 705
 			// Attempt to find and repair the broken table.
659
-			foreach ($fix_tables as $table)
660
-				$smcFunc['db_query']('', "
706
+			foreach ($fix_tables as $table) {
707
+							$smcFunc['db_query']('', "
661 708
 					REPAIR TABLE $table", false, false);
709
+			}
662 710
 
663 711
 			// And send off an email!
664 712
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -667,11 +715,12 @@  discard block
 block discarded – undo
667 715
 
668 716
 			// Try the query again...?
669 717
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
670
-			if ($ret !== false)
671
-				return $ret;
718
+			if ($ret !== false) {
719
+							return $ret;
720
+			}
721
+		} else {
722
+					$modSettings['cache_enable'] = $old_cache;
672 723
 		}
673
-		else
674
-			$modSettings['cache_enable'] = $old_cache;
675 724
 
676 725
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
677 726
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -681,22 +730,25 @@  discard block
 block discarded – undo
681 730
 				// Are we in SSI mode?  If so try that username and password first
682 731
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
683 732
 				{
684
-					if (empty($db_persist))
685
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
686
-					else
687
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
733
+					if (empty($db_persist)) {
734
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
735
+					} else {
736
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
737
+					}
688 738
 				}
689 739
 				// Fall back to the regular username and password if need be
690 740
 				if (!$db_connection)
691 741
 				{
692
-					if (empty($db_persist))
693
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
694
-					else
695
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
742
+					if (empty($db_persist)) {
743
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
744
+					} else {
745
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
746
+					}
696 747
 				}
697 748
 
698
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
699
-					$db_connection = false;
749
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
750
+									$db_connection = false;
751
+				}
700 752
 			}
701 753
 
702 754
 			if ($db_connection)
@@ -707,24 +759,27 @@  discard block
 block discarded – undo
707 759
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
708 760
 
709 761
 					$new_errno = mysqli_errno($db_connection);
710
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
711
-						break;
762
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
763
+											break;
764
+					}
712 765
 				}
713 766
 
714 767
 				// If it failed again, shucks to be you... we're not trying it over and over.
715
-				if ($ret !== false)
716
-					return $ret;
768
+				if ($ret !== false) {
769
+									return $ret;
770
+				}
717 771
 			}
718 772
 		}
719 773
 		// Are they out of space, perhaps?
720 774
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
721 775
 		{
722
-			if (!isset($txt))
723
-				$query_error .= ' - check database storage space.';
724
-			else
776
+			if (!isset($txt)) {
777
+							$query_error .= ' - check database storage space.';
778
+			} else
725 779
 			{
726
-				if (!isset($txt['mysql_error_space']))
727
-					loadLanguage('Errors');
780
+				if (!isset($txt['mysql_error_space'])) {
781
+									loadLanguage('Errors');
782
+				}
728 783
 
729 784
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
730 785
 			}
@@ -732,15 +787,17 @@  discard block
 block discarded – undo
732 787
 	}
733 788
 
734 789
 	// Nothing's defined yet... just die with it.
735
-	if (empty($context) || empty($txt))
736
-		die($query_error);
790
+	if (empty($context) || empty($txt)) {
791
+			die($query_error);
792
+	}
737 793
 
738 794
 	// Show an error message, if possible.
739 795
 	$context['error_title'] = $txt['database_error'];
740
-	if (allowedTo('admin_forum'))
741
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
742
-	else
743
-		$context['error_message'] = $txt['try_again'];
796
+	if (allowedTo('admin_forum')) {
797
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
798
+	} else {
799
+			$context['error_message'] = $txt['try_again'];
800
+	}
744 801
 
745 802
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
746 803
 	{
@@ -769,25 +826,28 @@  discard block
 block discarded – undo
769 826
 	$connection = $connection === null ? $db_connection : $connection;
770 827
 
771 828
 	// With nothing to insert, simply return.
772
-	if (empty($data))
773
-		return;
829
+	if (empty($data)) {
830
+			return;
831
+	}
774 832
 
775 833
 	// Replace the prefix holder with the actual prefix.
776 834
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
777 835
 
778 836
 	// Inserting data as a single row can be done as a single array.
779
-	if (!is_array($data[array_rand($data)]))
780
-		$data = array($data);
837
+	if (!is_array($data[array_rand($data)])) {
838
+			$data = array($data);
839
+	}
781 840
 
782 841
 	// Create the mold for a single row insert.
783 842
 	$insertData = '(';
784 843
 	foreach ($columns as $columnName => $type)
785 844
 	{
786 845
 		// Are we restricting the length?
787
-		if (strpos($type, 'string-') !== false)
788
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
789
-		else
790
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
846
+		if (strpos($type, 'string-') !== false) {
847
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
848
+		} else {
849
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
850
+		}
791 851
 	}
792 852
 	$insertData = substr($insertData, 0, -2) . ')';
793 853
 
@@ -796,8 +856,9 @@  discard block
 block discarded – undo
796 856
 
797 857
 	// Here's where the variables are injected to the query.
798 858
 	$insertRows = array();
799
-	foreach ($data as $dataRow)
800
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
859
+	foreach ($data as $dataRow) {
860
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
861
+	}
801 862
 
802 863
 	// Determine the method of insertion.
803 864
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -828,8 +889,9 @@  discard block
 block discarded – undo
828 889
  */
829 890
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
830 891
 {
831
-	if (empty($log_message))
832
-		$log_message = $error_message;
892
+	if (empty($log_message)) {
893
+			$log_message = $error_message;
894
+	}
833 895
 
834 896
 	foreach (debug_backtrace() as $step)
835 897
 	{
@@ -848,12 +910,14 @@  discard block
 block discarded – undo
848 910
 	}
849 911
 
850 912
 	// A special case - we want the file and line numbers for debugging.
851
-	if ($error_type == 'return')
852
-		return array($file, $line);
913
+	if ($error_type == 'return') {
914
+			return array($file, $line);
915
+	}
853 916
 
854 917
 	// Is always a critical error.
855
-	if (function_exists('log_error'))
856
-		log_error($log_message, 'critical', $file, $line);
918
+	if (function_exists('log_error')) {
919
+			log_error($log_message, 'critical', $file, $line);
920
+	}
857 921
 
858 922
 	if (function_exists('fatal_error'))
859 923
 	{
@@ -861,12 +925,12 @@  discard block
 block discarded – undo
861 925
 
862 926
 		// Cannot continue...
863 927
 		exit;
928
+	} elseif ($error_type) {
929
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
930
+	} else {
931
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
932
+	}
864 933
 	}
865
-	elseif ($error_type)
866
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
867
-	else
868
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
869
-}
870 934
 
871 935
 /**
872 936
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -883,10 +947,11 @@  discard block
 block discarded – undo
883 947
 		'\\' => '\\\\',
884 948
 	);
885 949
 
886
-	if ($translate_human_wildcards)
887
-		$replacements += array(
950
+	if ($translate_human_wildcards) {
951
+			$replacements += array(
888 952
 			'*' => '%',
889 953
 		);
954
+	}
890 955
 
891 956
 	return strtr($string, $replacements);
892 957
 }
@@ -900,8 +965,9 @@  discard block
 block discarded – undo
900 965
  */
901 966
 function smf_is_resource($result)
902 967
 {
903
-	if ($result instanceof mysqli_result)
904
-		return true;
968
+	if ($result instanceof mysqli_result) {
969
+			return true;
970
+	}
905 971
 
906 972
 	return false;
907 973
 }
Please login to merge, or discard this patch.
Sources/Post.php 1 patch
Braces   +664 added lines, -515 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	$context['auto_notify'] = !empty($context['notify_prefs']['msg_auto_notify']);
56 59
 
57 60
 	// You must be posting to *some* board.
58
-	if (empty($board) && !$context['make_event'])
59
-		fatal_lang_error('no_board', false);
61
+	if (empty($board) && !$context['make_event']) {
62
+			fatal_lang_error('no_board', false);
63
+	}
60 64
 
61 65
 	require_once($sourcedir . '/Subs-Post.php');
62 66
 
@@ -79,10 +83,11 @@  discard block
 block discarded – undo
79 83
 			array(
80 84
 				'msg' => (int) $_REQUEST['msg'],
81 85
 		));
82
-		if ($smcFunc['db_num_rows']($request) != 1)
83
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
84
-		else
85
-			list ($topic) = $smcFunc['db_fetch_row']($request);
86
+		if ($smcFunc['db_num_rows']($request) != 1) {
87
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
88
+		} else {
89
+					list ($topic) = $smcFunc['db_fetch_row']($request);
90
+		}
86 91
 		$smcFunc['db_free_result']($request);
87 92
 	}
88 93
 
@@ -109,33 +114,36 @@  discard block
 block discarded – undo
109 114
 		$smcFunc['db_free_result']($request);
110 115
 
111 116
 		// If this topic already has a poll, they sure can't add another.
112
-		if (isset($_REQUEST['poll']) && $pollID > 0)
113
-			unset($_REQUEST['poll']);
117
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
118
+					unset($_REQUEST['poll']);
119
+		}
114 120
 
115 121
 		if (empty($_REQUEST['msg']))
116 122
 		{
117
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
118
-				is_not_guest();
123
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
124
+							is_not_guest();
125
+			}
119 126
 
120 127
 			// By default the reply will be approved...
121 128
 			$context['becomes_approved'] = true;
122 129
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
123 130
 			{
124
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
125
-					$context['becomes_approved'] = false;
126
-				else
127
-					isAllowedTo('post_reply_any');
128
-			}
129
-			elseif (!allowedTo('post_reply_any'))
131
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
132
+									$context['becomes_approved'] = false;
133
+				} else {
134
+									isAllowedTo('post_reply_any');
135
+				}
136
+			} elseif (!allowedTo('post_reply_any'))
130 137
 			{
131
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
132
-					$context['becomes_approved'] = false;
133
-				else
134
-					isAllowedTo('post_reply_own');
138
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
139
+									$context['becomes_approved'] = false;
140
+				} else {
141
+									isAllowedTo('post_reply_own');
142
+				}
135 143
 			}
144
+		} else {
145
+					$context['becomes_approved'] = true;
136 146
 		}
137
-		else
138
-			$context['becomes_approved'] = true;
139 147
 
140 148
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
141 149
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -147,18 +155,19 @@  discard block
 block discarded – undo
147 155
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
148 156
 
149 157
 		// Check whether this is a really old post being bumped...
150
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
151
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
152
-	}
153
-	else
158
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
159
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
160
+		}
161
+	} else
154 162
 	{
155 163
 		$context['becomes_approved'] = true;
156 164
 		if ((!$context['make_event'] || !empty($board)))
157 165
 		{
158
-			if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
159
-				$context['becomes_approved'] = false;
160
-			else
161
-				isAllowedTo('post_new');
166
+			if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
167
+							$context['becomes_approved'] = false;
168
+			} else {
169
+							isAllowedTo('post_new');
170
+			}
162 171
 		}
163 172
 
164 173
 		$locked = 0;
@@ -196,20 +205,24 @@  discard block
 block discarded – undo
196 205
 	}
197 206
 
198 207
 	// Don't allow a post if it's locked and you aren't all powerful.
199
-	if ($locked && !allowedTo('moderate_board'))
200
-		fatal_lang_error('topic_locked', false);
208
+	if ($locked && !allowedTo('moderate_board')) {
209
+			fatal_lang_error('topic_locked', false);
210
+	}
201 211
 	// Check the users permissions - is the user allowed to add or post a poll?
202 212
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
203 213
 	{
204 214
 		// New topic, new poll.
205
-		if (empty($topic))
206
-			isAllowedTo('poll_post');
215
+		if (empty($topic)) {
216
+					isAllowedTo('poll_post');
217
+		}
207 218
 		// This is an old topic - but it is yours!  Can you add to it?
208
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
209
-			isAllowedTo('poll_add_own');
219
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
220
+					isAllowedTo('poll_add_own');
221
+		}
210 222
 		// If you're not the owner, can you add to any poll?
211
-		else
212
-			isAllowedTo('poll_add_any');
223
+		else {
224
+					isAllowedTo('poll_add_any');
225
+		}
213 226
 
214 227
 		require_once($sourcedir . '/Subs-Members.php');
215 228
 		$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
@@ -238,8 +251,9 @@  discard block
 block discarded – undo
238 251
 	if ($context['make_event'])
239 252
 	{
240 253
 		// They might want to pick a board.
241
-		if (!isset($context['current_board']))
242
-			$context['current_board'] = 0;
254
+		if (!isset($context['current_board'])) {
255
+					$context['current_board'] = 0;
256
+		}
243 257
 
244 258
 		// Start loading up the event info.
245 259
 		$context['event'] = array();
@@ -253,10 +267,11 @@  discard block
 block discarded – undo
253 267
 		isAllowedTo('calendar_post');
254 268
 
255 269
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
256
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
257
-			$time_string = '%k:%M';
258
-		else
259
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
270
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
271
+					$time_string = '%k:%M';
272
+		} else {
273
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
274
+		}
260 275
 
261 276
 		$js_time_string = str_replace(
262 277
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -278,8 +293,7 @@  discard block
 block discarded – undo
278 293
 			require_once($sourcedir . '/Subs-Calendar.php');
279 294
 			$eventProperties = getEventProperties($context['event']['id']);
280 295
 			$context['event'] = array_merge($context['event'], $eventProperties);
281
-		}
282
-		else
296
+		} else
283 297
 		{
284 298
 			// Get the current event information.
285 299
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -287,15 +301,18 @@  discard block
 block discarded – undo
287 301
 			$context['event'] = array_merge($context['event'], $eventProperties);
288 302
 
289 303
 			// Make sure the year and month are in the valid range.
290
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
291
-				fatal_lang_error('invalid_month', false);
292
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
293
-				fatal_lang_error('invalid_year', false);
304
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
305
+							fatal_lang_error('invalid_month', false);
306
+			}
307
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
308
+							fatal_lang_error('invalid_year', false);
309
+			}
294 310
 
295 311
 			// Get a list of boards they can post in.
296 312
 			$boards = boardsAllowedTo('post_new');
297
-			if (empty($boards))
298
-				fatal_lang_error('cannot_post_new', 'user');
313
+			if (empty($boards)) {
314
+							fatal_lang_error('cannot_post_new', 'user');
315
+			}
299 316
 
300 317
 			// Load a list of boards for this event in the context.
301 318
 			require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -414,10 +431,11 @@  discard block
 block discarded – undo
414 431
 
415 432
 			if (!empty($context['new_replies']))
416 433
 			{
417
-				if ($context['new_replies'] == 1)
418
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
419
-				else
420
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
434
+				if ($context['new_replies'] == 1) {
435
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
436
+				} else {
437
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
438
+				}
421 439
 
422 440
 				$post_errors[] = 'new_replies';
423 441
 
@@ -429,9 +447,9 @@  discard block
 block discarded – undo
429 447
 	// Get a response prefix (like 'Re:') in the default forum language.
430 448
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
431 449
 	{
432
-		if ($language === $user_info['language'])
433
-			$context['response_prefix'] = $txt['response_prefix'];
434
-		else
450
+		if ($language === $user_info['language']) {
451
+					$context['response_prefix'] = $txt['response_prefix'];
452
+		} else
435 453
 		{
436 454
 			loadLanguage('index', $language, false);
437 455
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -444,8 +462,9 @@  discard block
 block discarded – undo
444 462
 	// Do we have a body, but an error happened.
445 463
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
446 464
 	{
447
-		if (isset($_REQUEST['quickReply']))
448
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
465
+		if (isset($_REQUEST['quickReply'])) {
466
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
467
+		}
449 468
 
450 469
 		// Validate inputs.
451 470
 		if (empty($context['post_error']))
@@ -453,15 +472,17 @@  discard block
 block discarded – undo
453 472
 			// This means they didn't click Post and get an error.
454 473
 			$really_previewing = true;
455 474
 
456
-		}
457
-		else
475
+		} else
458 476
 		{
459
-			if (!isset($_REQUEST['subject']))
460
-				$_REQUEST['subject'] = '';
461
-			if (!isset($_REQUEST['message']))
462
-				$_REQUEST['message'] = '';
463
-			if (!isset($_REQUEST['icon']))
464
-				$_REQUEST['icon'] = 'xx';
477
+			if (!isset($_REQUEST['subject'])) {
478
+							$_REQUEST['subject'] = '';
479
+			}
480
+			if (!isset($_REQUEST['message'])) {
481
+							$_REQUEST['message'] = '';
482
+			}
483
+			if (!isset($_REQUEST['icon'])) {
484
+							$_REQUEST['icon'] = 'xx';
485
+			}
465 486
 
466 487
 			// They are previewing if they asked to preview (i.e. came from quick reply).
467 488
 			$really_previewing = !empty($_POST['preview']);
@@ -477,8 +498,9 @@  discard block
 block discarded – undo
477 498
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
478 499
 
479 500
 		// Make sure the subject isn't too long - taking into account special characters.
480
-		if ($smcFunc['strlen']($form_subject) > 100)
481
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
501
+		if ($smcFunc['strlen']($form_subject) > 100) {
502
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
503
+		}
482 504
 
483 505
 		if (isset($_REQUEST['poll']))
484 506
 		{
@@ -490,8 +512,9 @@  discard block
 block discarded – undo
490 512
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
491 513
 			foreach ($_POST['options'] as $option)
492 514
 			{
493
-				if (trim($option) == '')
494
-					continue;
515
+				if (trim($option) == '') {
516
+									continue;
517
+				}
495 518
 
496 519
 				$context['choices'][] = array(
497 520
 					'id' => $choice_id++,
@@ -553,13 +576,14 @@  discard block
 block discarded – undo
553 576
 				$context['preview_subject'] = $form_subject;
554 577
 
555 578
 				censorText($context['preview_subject']);
579
+			} else {
580
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
556 581
 			}
557
-			else
558
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
559 582
 
560 583
 			// Protect any CDATA blocks.
561
-			if (isset($_REQUEST['xml']))
562
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
584
+			if (isset($_REQUEST['xml'])) {
585
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
586
+			}
563 587
 		}
564 588
 
565 589
 		// Set up the checkboxes.
@@ -598,29 +622,32 @@  discard block
 block discarded – undo
598 622
 			);
599 623
 			// The message they were trying to edit was most likely deleted.
600 624
 			// @todo Change this error message?
601
-			if ($smcFunc['db_num_rows']($request) == 0)
602
-				fatal_lang_error('no_board', false);
625
+			if ($smcFunc['db_num_rows']($request) == 0) {
626
+							fatal_lang_error('no_board', false);
627
+			}
603 628
 			$row = $smcFunc['db_fetch_assoc']($request);
604 629
 
605 630
 			$attachment_stuff = array($row);
606
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
607
-				$attachment_stuff[] = $row2;
631
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
632
+							$attachment_stuff[] = $row2;
633
+			}
608 634
 			$smcFunc['db_free_result']($request);
609 635
 
610 636
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
611 637
 			{
612 638
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
613
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
614
-					fatal_lang_error('modify_post_time_passed', false);
615
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
616
-					isAllowedTo('modify_replies');
617
-				else
618
-					isAllowedTo('modify_own');
639
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
640
+									fatal_lang_error('modify_post_time_passed', false);
641
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
642
+									isAllowedTo('modify_replies');
643
+				} else {
644
+									isAllowedTo('modify_own');
645
+				}
646
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
647
+							isAllowedTo('modify_replies');
648
+			} else {
649
+							isAllowedTo('modify_any');
619 650
 			}
620
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
621
-				isAllowedTo('modify_replies');
622
-			else
623
-				isAllowedTo('modify_any');
624 651
 
625 652
 			if ($context['can_announce'] && !empty($row['id_action']))
626 653
 			{
@@ -644,8 +671,9 @@  discard block
 block discarded – undo
644 671
 
645 672
 				while ($row = $smcFunc['db_fetch_assoc']($request))
646 673
 				{
647
-					if ($row['filesize'] <= 0)
648
-						continue;
674
+					if ($row['filesize'] <= 0) {
675
+											continue;
676
+					}
649 677
 					$context['current_attachments'][$row['id_attach']] = array(
650 678
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
651 679
 						'size' => $row['filesize'],
@@ -715,29 +743,32 @@  discard block
 block discarded – undo
715 743
 			)
716 744
 		);
717 745
 		// The message they were trying to edit was most likely deleted.
718
-		if ($smcFunc['db_num_rows']($request) == 0)
719
-			fatal_lang_error('no_message', false);
746
+		if ($smcFunc['db_num_rows']($request) == 0) {
747
+					fatal_lang_error('no_message', false);
748
+		}
720 749
 		$row = $smcFunc['db_fetch_assoc']($request);
721 750
 
722 751
 		$attachment_stuff = array($row);
723
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
724
-			$attachment_stuff[] = $row2;
752
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
753
+					$attachment_stuff[] = $row2;
754
+		}
725 755
 		$smcFunc['db_free_result']($request);
726 756
 
727 757
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
728 758
 		{
729 759
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
730
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
731
-				fatal_lang_error('modify_post_time_passed', false);
732
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
733
-				isAllowedTo('modify_replies');
734
-			else
735
-				isAllowedTo('modify_own');
760
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
761
+							fatal_lang_error('modify_post_time_passed', false);
762
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
763
+							isAllowedTo('modify_replies');
764
+			} else {
765
+							isAllowedTo('modify_own');
766
+			}
767
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
768
+					isAllowedTo('modify_replies');
769
+		} else {
770
+					isAllowedTo('modify_any');
736 771
 		}
737
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
738
-			isAllowedTo('modify_replies');
739
-		else
740
-			isAllowedTo('modify_any');
741 772
 
742 773
 		if ($context['can_announce'] && !empty($row['id_action']))
743 774
 		{
@@ -764,15 +795,17 @@  discard block
 block discarded – undo
764 795
 		$context['icon'] = $row['icon'];
765 796
 
766 797
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
767
-		if (!$row['approved'] && !$context['show_approval'])
768
-			$context['show_approval'] = allowedTo('approve_posts');
798
+		if (!$row['approved'] && !$context['show_approval']) {
799
+					$context['show_approval'] = allowedTo('approve_posts');
800
+		}
769 801
 
770 802
 		// Sort the attachments so they are in the order saved
771 803
 		$temp = array();
772 804
 		foreach ($attachment_stuff as $attachment)
773 805
 		{
774
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
775
-				$temp[$attachment['id_attach']] = $attachment;
806
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
807
+							$temp[$attachment['id_attach']] = $attachment;
808
+			}
776 809
 
777 810
 		}
778 811
 		ksort($temp);
@@ -834,14 +867,16 @@  discard block
 block discarded – undo
834 867
 					'is_approved' => 1,
835 868
 				)
836 869
 			);
837
-			if ($smcFunc['db_num_rows']($request) == 0)
838
-				fatal_lang_error('quoted_post_deleted', false);
870
+			if ($smcFunc['db_num_rows']($request) == 0) {
871
+							fatal_lang_error('quoted_post_deleted', false);
872
+			}
839 873
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
840 874
 			$smcFunc['db_free_result']($request);
841 875
 
842 876
 			// Add 'Re: ' to the front of the quoted subject.
843
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
844
-				$form_subject = $context['response_prefix'] . $form_subject;
877
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
878
+							$form_subject = $context['response_prefix'] . $form_subject;
879
+			}
845 880
 
846 881
 			// Censor the message and subject.
847 882
 			censorText($form_message);
@@ -854,10 +889,11 @@  discard block
 block discarded – undo
854 889
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
855 890
 				{
856 891
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
857
-					if ($i % 4 == 0)
858
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m)
892
+					if ($i % 4 == 0) {
893
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m)
859 894
 						{
860 895
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
896
+					}
861 897
 						}, $parts[$i]);
862 898
 				}
863 899
 				$form_message = implode('', $parts);
@@ -866,8 +902,9 @@  discard block
 block discarded – undo
866 902
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
867 903
 
868 904
 			// Remove any nested quotes, if necessary.
869
-			if (!empty($modSettings['removeNestedQuotes']))
870
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
905
+			if (!empty($modSettings['removeNestedQuotes'])) {
906
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
907
+			}
871 908
 
872 909
 			// Add a quote string on the front and end.
873 910
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -879,15 +916,15 @@  discard block
 block discarded – undo
879 916
 			$form_subject = $first_subject;
880 917
 
881 918
 			// Add 'Re: ' to the front of the subject.
882
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
883
-				$form_subject = $context['response_prefix'] . $form_subject;
919
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
920
+							$form_subject = $context['response_prefix'] . $form_subject;
921
+			}
884 922
 
885 923
 			// Censor the subject.
886 924
 			censorText($form_subject);
887 925
 
888 926
 			$form_message = '';
889
-		}
890
-		else
927
+		} else
891 928
 		{
892 929
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
893 930
 			$form_message = '';
@@ -905,13 +942,15 @@  discard block
 block discarded – undo
905 942
 		if (isset($_REQUEST['msg']))
906 943
 		{
907 944
 			$context['attachments']['quantity'] = count($context['current_attachments']);
908
-			foreach ($context['current_attachments'] as $attachment)
909
-				$context['attachments']['total_size'] += $attachment['size'];
945
+			foreach ($context['current_attachments'] as $attachment) {
946
+							$context['attachments']['total_size'] += $attachment['size'];
947
+			}
910 948
 		}
911 949
 
912 950
 		// A bit of house keeping first.
913
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
914
-			unset($_SESSION['temp_attachments']);
951
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
952
+					unset($_SESSION['temp_attachments']);
953
+		}
915 954
 
916 955
 		if (!empty($_SESSION['temp_attachments']))
917 956
 		{
@@ -920,9 +959,10 @@  discard block
 block discarded – undo
920 959
 			{
921 960
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
922 961
 				{
923
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
924
-						if (file_exists($attachment['tmp_name']))
962
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
963
+											if (file_exists($attachment['tmp_name']))
925 964
 							unlink($attachment['tmp_name']);
965
+					}
926 966
 				}
927 967
 				$post_errors[] = 'temp_attachments_gone';
928 968
 				$_SESSION['temp_attachments'] = array();
@@ -936,8 +976,9 @@  discard block
 block discarded – undo
936 976
 					// See if any files still exist before showing the warning message and the files attached.
937 977
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
938 978
 					{
939
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
940
-							continue;
979
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
980
+													continue;
981
+						}
941 982
 
942 983
 						if (file_exists($attachment['tmp_name']))
943 984
 						{
@@ -947,20 +988,21 @@  discard block
 block discarded – undo
947 988
 							break;
948 989
 						}
949 990
 					}
950
-				}
951
-				else
991
+				} else
952 992
 				{
953 993
 					// Since, they don't belong here. Let's inform the user that they exist..
954
-					if (!empty($topic))
955
-						$delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
956
-					else
957
-						$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
994
+					if (!empty($topic)) {
995
+											$delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
996
+					} else {
997
+											$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
998
+					}
958 999
 
959 1000
 					// Compile a list of the files to show the user.
960 1001
 					$file_list = array();
961
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
962
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1002
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1003
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
963 1004
 							$file_list[] =  $attachment['name'];
1005
+					}
964 1006
 
965 1007
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
966 1008
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -972,8 +1014,7 @@  discard block
 block discarded – undo
972 1014
 
973 1015
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
974 1016
 						$context['ignore_temp_attachments'] = true;
975
-					}
976
-					else
1017
+					} else
977 1018
 					{
978 1019
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
979 1020
 						$context['ignore_temp_attachments'] = true;
@@ -981,16 +1022,19 @@  discard block
 block discarded – undo
981 1022
 				}
982 1023
 			}
983 1024
 
984
-			if (!empty($context['we_are_history']))
985
-				$post_errors[] = $context['we_are_history'];
1025
+			if (!empty($context['we_are_history'])) {
1026
+							$post_errors[] = $context['we_are_history'];
1027
+			}
986 1028
 
987 1029
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
988 1030
 			{
989
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
990
-					break;
1031
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1032
+									break;
1033
+				}
991 1034
 
992
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
993
-					continue;
1035
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1036
+									continue;
1037
+				}
994 1038
 
995 1039
 				if ($attachID == 'initial_error')
996 1040
 				{
@@ -1005,15 +1049,17 @@  discard block
 block discarded – undo
1005 1049
 				{
1006 1050
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1007 1051
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1008
-					foreach ($attachment['errors'] as $error)
1009
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1052
+					foreach ($attachment['errors'] as $error) {
1053
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1054
+					}
1010 1055
 					$txt['error_attach_errors'] .= '</div>';
1011 1056
 					$post_errors[] = 'attach_errors';
1012 1057
 
1013 1058
 					// Take out the trash.
1014 1059
 					unset($_SESSION['temp_attachments'][$attachID]);
1015
-					if (file_exists($attachment['tmp_name']))
1016
-						unlink($attachment['tmp_name']);
1060
+					if (file_exists($attachment['tmp_name'])) {
1061
+											unlink($attachment['tmp_name']);
1062
+					}
1017 1063
 					continue;
1018 1064
 				}
1019 1065
 
@@ -1026,8 +1072,9 @@  discard block
 block discarded – undo
1026 1072
 
1027 1073
 				$context['attachments']['quantity']++;
1028 1074
 				$context['attachments']['total_size'] += $attachment['size'];
1029
-				if (!isset($context['files_in_session_warning']))
1030
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1075
+				if (!isset($context['files_in_session_warning'])) {
1076
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1077
+				}
1031 1078
 
1032 1079
 				$context['current_attachments'][$attachID] = array(
1033 1080
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1055,8 +1102,9 @@  discard block
 block discarded – undo
1055 1102
 	}
1056 1103
 
1057 1104
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1058
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1059
-		$post_errors[] = 'need_qr_verification';
1105
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1106
+			$post_errors[] = 'need_qr_verification';
1107
+	}
1060 1108
 
1061 1109
 	/*
1062 1110
 	 * There are two error types: serious and minor. Serious errors
@@ -1073,52 +1121,56 @@  discard block
 block discarded – undo
1073 1121
 	{
1074 1122
 		loadLanguage('Errors');
1075 1123
 		$context['error_type'] = 'minor';
1076
-		foreach ($post_errors as $post_error)
1077
-			if (is_array($post_error))
1124
+		foreach ($post_errors as $post_error) {
1125
+					if (is_array($post_error))
1078 1126
 			{
1079 1127
 				$post_error_id = $post_error[0];
1128
+		}
1080 1129
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1081 1130
 
1082 1131
 				// If it's not a minor error flag it as such.
1083
-				if (!in_array($post_error_id, $minor_errors))
1084
-					$context['error_type'] = 'serious';
1085
-			}
1086
-			else
1132
+				if (!in_array($post_error_id, $minor_errors)) {
1133
+									$context['error_type'] = 'serious';
1134
+				}
1135
+			} else
1087 1136
 			{
1088 1137
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1089 1138
 
1090 1139
 				// If it's not a minor error flag it as such.
1091
-				if (!in_array($post_error, $minor_errors))
1092
-					$context['error_type'] = 'serious';
1140
+				if (!in_array($post_error, $minor_errors)) {
1141
+									$context['error_type'] = 'serious';
1142
+				}
1093 1143
 			}
1094 1144
 	}
1095 1145
 
1096 1146
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1097
-	if (isset($_REQUEST['poll']))
1098
-		$context['page_title'] = $txt['new_poll'];
1099
-	elseif ($context['make_event'])
1100
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1101
-	elseif (isset($_REQUEST['msg']))
1102
-		$context['page_title'] = $txt['modify_msg'];
1103
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1104
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1105
-	elseif (empty($topic))
1106
-		$context['page_title'] = $txt['start_new_topic'];
1107
-	else
1108
-		$context['page_title'] = $txt['post_reply'];
1147
+	if (isset($_REQUEST['poll'])) {
1148
+			$context['page_title'] = $txt['new_poll'];
1149
+	} elseif ($context['make_event']) {
1150
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1151
+	} elseif (isset($_REQUEST['msg'])) {
1152
+			$context['page_title'] = $txt['modify_msg'];
1153
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1154
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1155
+	} elseif (empty($topic)) {
1156
+			$context['page_title'] = $txt['start_new_topic'];
1157
+	} else {
1158
+			$context['page_title'] = $txt['post_reply'];
1159
+	}
1109 1160
 
1110 1161
 	// Build the link tree.
1111
-	if (empty($topic))
1112
-		$context['linktree'][] = array(
1162
+	if (empty($topic)) {
1163
+			$context['linktree'][] = array(
1113 1164
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1114 1165
 		);
1115
-	else
1116
-		$context['linktree'][] = array(
1166
+	} else {
1167
+			$context['linktree'][] = array(
1117 1168
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1118 1169
 			'name' => $form_subject,
1119 1170
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1120 1171
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1121 1172
 		);
1173
+	}
1122 1174
 
1123 1175
 	$context['subject'] = addcslashes($form_subject, '"');
1124 1176
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1162,8 +1214,9 @@  discard block
 block discarded – undo
1162 1214
 	// Message icons - customized icons are off?
1163 1215
 	$context['icons'] = getMessageIcons($board);
1164 1216
 
1165
-	if (!empty($context['icons']))
1166
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1217
+	if (!empty($context['icons'])) {
1218
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1219
+	}
1167 1220
 
1168 1221
 	// Are we starting a poll? if set the poll icon as selected if its available
1169 1222
 	if (isset($_REQUEST['poll']))
@@ -1183,8 +1236,9 @@  discard block
 block discarded – undo
1183 1236
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1184 1237
 	{
1185 1238
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1186
-		if ($context['icons'][$i]['selected'])
1187
-			$context['icon_url'] = $context['icons'][$i]['url'];
1239
+		if ($context['icons'][$i]['selected']) {
1240
+					$context['icon_url'] = $context['icons'][$i]['url'];
1241
+		}
1188 1242
 	}
1189 1243
 	if (empty($context['icon_url']))
1190 1244
 	{
@@ -1198,8 +1252,9 @@  discard block
 block discarded – undo
1198 1252
 		));
1199 1253
 	}
1200 1254
 
1201
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1202
-		getTopic();
1255
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1256
+			getTopic();
1257
+	}
1203 1258
 
1204 1259
 	// If the user can post attachments prepare the warning labels.
1205 1260
 	if ($context['can_post_attachment'])
@@ -1210,15 +1265,17 @@  discard block
 block discarded – undo
1210 1265
 		$context['attachment_restrictions'] = array();
1211 1266
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1212 1267
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1213
-		foreach ($attachmentRestrictionTypes as $type)
1214
-			if (!empty($modSettings[$type]))
1268
+		foreach ($attachmentRestrictionTypes as $type) {
1269
+					if (!empty($modSettings[$type]))
1215 1270
 			{
1216 1271
 				$context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type . ($modSettings[$type] >= 1024 ? '_MB' : '')], comma_format($modSettings[$type], 0));
1272
+		}
1217 1273
 				// Show some numbers. If they exist.
1218
-				if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0)
1219
-					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1220
-				elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0)
1221
-					$context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0));
1274
+				if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0) {
1275
+									$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1276
+				} elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) {
1277
+									$context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0));
1278
+				}
1222 1279
 			}
1223 1280
 	}
1224 1281
 
@@ -1252,8 +1309,8 @@  discard block
 block discarded – undo
1252 1309
 
1253 1310
 	if (!empty($context['current_attachments']))
1254 1311
 	{
1255
-		foreach ($context['current_attachments'] as $key => $mock)
1256
-			addInlineJavaScript('
1312
+		foreach ($context['current_attachments'] as $key => $mock) {
1313
+					addInlineJavaScript('
1257 1314
 	current_attachments.push({
1258 1315
 		name: '. JavaScriptEscape($mock['name']) .',
1259 1316
 		size: '. $mock['size'] .',
@@ -1262,6 +1319,7 @@  discard block
 block discarded – undo
1262 1319
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') .',
1263 1320
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) .'
1264 1321
 	});', true);
1322
+		}
1265 1323
 	}
1266 1324
 
1267 1325
 	// File Upload.
@@ -1306,8 +1364,9 @@  discard block
 block discarded – undo
1306 1364
 	var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) .';', false);
1307 1365
 
1308 1366
 	// Finally, load the template.
1309
-	if (!isset($_REQUEST['xml']))
1310
-		loadTemplate('Post');
1367
+	if (!isset($_REQUEST['xml'])) {
1368
+			loadTemplate('Post');
1369
+	}
1311 1370
 
1312 1371
 	call_integration_hook('integrate_post_end');
1313 1372
 }
@@ -1328,13 +1387,14 @@  discard block
 block discarded – undo
1328 1387
 	// Sneaking off, are we?
1329 1388
 	if (empty($_POST) && empty($topic))
1330 1389
 	{
1331
-		if (empty($_SERVER['CONTENT_LENGTH']))
1332
-			redirectexit('action=post;board=' . $board . '.0');
1333
-		else
1334
-			fatal_lang_error('post_upload_error', false);
1390
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1391
+					redirectexit('action=post;board=' . $board . '.0');
1392
+		} else {
1393
+					fatal_lang_error('post_upload_error', false);
1394
+		}
1395
+	} elseif (empty($_POST) && !empty($topic)) {
1396
+			redirectexit('action=post;topic=' . $topic . '.0');
1335 1397
 	}
1336
-	elseif (empty($_POST) && !empty($topic))
1337
-		redirectexit('action=post;topic=' . $topic . '.0');
1338 1398
 
1339 1399
 	// No need!
1340 1400
 	$context['robot_no_index'] = true;
@@ -1346,8 +1406,9 @@  discard block
 block discarded – undo
1346 1406
 	$post_errors = array();
1347 1407
 
1348 1408
 	// If the session has timed out, let the user re-submit their form.
1349
-	if (checkSession('post', '', false) != '')
1350
-		$post_errors[] = 'session_timeout';
1409
+	if (checkSession('post', '', false) != '') {
1410
+			$post_errors[] = 'session_timeout';
1411
+	}
1351 1412
 
1352 1413
 	// Wrong verification code?
1353 1414
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1357,33 +1418,38 @@  discard block
 block discarded – undo
1357 1418
 			'id' => 'post',
1358 1419
 		);
1359 1420
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1360
-		if (is_array($context['require_verification']))
1361
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1421
+		if (is_array($context['require_verification'])) {
1422
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1423
+		}
1362 1424
 	}
1363 1425
 
1364 1426
 	require_once($sourcedir . '/Subs-Post.php');
1365 1427
 	loadLanguage('Post');
1366 1428
 
1367 1429
 	// Drafts enabled and needed?
1368
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1369
-		require_once($sourcedir . '/Drafts.php');
1430
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1431
+			require_once($sourcedir . '/Drafts.php');
1432
+	}
1370 1433
 
1371 1434
 	// First check to see if they are trying to delete any current attachments.
1372 1435
 	if (isset($_POST['attach_del']))
1373 1436
 	{
1374 1437
 		$keep_temp = array();
1375 1438
 		$keep_ids = array();
1376
-		foreach ($_POST['attach_del'] as $dummy)
1377
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1439
+		foreach ($_POST['attach_del'] as $dummy) {
1440
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1378 1441
 				$keep_temp[] = $dummy;
1379
-			else
1380
-				$keep_ids[] = (int) $dummy;
1442
+		}
1443
+			else {
1444
+							$keep_ids[] = (int) $dummy;
1445
+			}
1381 1446
 
1382
-		if (isset($_SESSION['temp_attachments']))
1383
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1447
+		if (isset($_SESSION['temp_attachments'])) {
1448
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1384 1449
 			{
1385 1450
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1386 1451
 					continue;
1452
+		}
1387 1453
 
1388 1454
 				unset($_SESSION['temp_attachments'][$attachID]);
1389 1455
 				unlink($attachment['tmp_name']);
@@ -1425,24 +1491,28 @@  discard block
 block discarded – undo
1425 1491
 		$smcFunc['db_free_result']($request);
1426 1492
 
1427 1493
 		// Though the topic should be there, it might have vanished.
1428
-		if (!is_array($topic_info))
1429
-			fatal_lang_error('topic_doesnt_exist', 404);
1494
+		if (!is_array($topic_info)) {
1495
+					fatal_lang_error('topic_doesnt_exist', 404);
1496
+		}
1430 1497
 
1431 1498
 		// Did this topic suddenly move? Just checking...
1432
-		if ($topic_info['id_board'] != $board)
1433
-			fatal_lang_error('not_a_topic');
1499
+		if ($topic_info['id_board'] != $board) {
1500
+					fatal_lang_error('not_a_topic');
1501
+		}
1434 1502
 	}
1435 1503
 
1436 1504
 	// Replying to a topic?
1437 1505
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1438 1506
 	{
1439 1507
 		// Don't allow a post if it's locked.
1440
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1441
-			fatal_lang_error('topic_locked', false);
1508
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1509
+					fatal_lang_error('topic_locked', false);
1510
+		}
1442 1511
 
1443 1512
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1444
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1445
-			unset($_REQUEST['poll']);
1513
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1514
+					unset($_REQUEST['poll']);
1515
+		}
1446 1516
 
1447 1517
 		// Do the permissions and approval stuff...
1448 1518
 		$becomesApproved = true;
@@ -1458,44 +1528,43 @@  discard block
 block discarded – undo
1458 1528
 
1459 1529
 			// Set a nice session var...
1460 1530
 			$_SESSION['becomesUnapproved'] = true;
1461
-		}
1462
-
1463
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1531
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1464 1532
 		{
1465
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1466
-				$becomesApproved = false;
1467
-
1468
-			else
1469
-				isAllowedTo('post_reply_any');
1470
-		}
1471
-		elseif (!allowedTo('post_reply_any'))
1533
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1534
+							$becomesApproved = false;
1535
+			} else {
1536
+							isAllowedTo('post_reply_any');
1537
+			}
1538
+		} elseif (!allowedTo('post_reply_any'))
1472 1539
 		{
1473
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1474
-				$becomesApproved = false;
1475
-
1476
-			else
1477
-				isAllowedTo('post_reply_own');
1540
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1541
+							$becomesApproved = false;
1542
+			} else {
1543
+							isAllowedTo('post_reply_own');
1544
+			}
1478 1545
 		}
1479 1546
 
1480 1547
 		if (isset($_POST['lock']))
1481 1548
 		{
1482 1549
 			// Nothing is changed to the lock.
1483
-			if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1484
-				unset($_POST['lock']);
1550
+			if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1551
+							unset($_POST['lock']);
1552
+			}
1485 1553
 
1486 1554
 			// You're have no permission to lock this topic.
1487
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1488
-				unset($_POST['lock']);
1555
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1556
+							unset($_POST['lock']);
1557
+			}
1489 1558
 
1490 1559
 			// You are allowed to (un)lock your own topic only.
1491 1560
 			elseif (!allowedTo('lock_any'))
1492 1561
 			{
1493 1562
 				// You cannot override a moderator lock.
1494
-				if ($topic_info['locked'] == 1)
1495
-					unset($_POST['lock']);
1496
-
1497
-				else
1498
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1563
+				if ($topic_info['locked'] == 1) {
1564
+									unset($_POST['lock']);
1565
+				} else {
1566
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1567
+				}
1499 1568
 			}
1500 1569
 			// Hail mighty moderator, (un)lock this topic immediately.
1501 1570
 			else
@@ -1503,19 +1572,21 @@  discard block
 block discarded – undo
1503 1572
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1504 1573
 
1505 1574
 				// Did someone (un)lock this while you were posting?
1506
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1507
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1575
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1576
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1577
+				}
1508 1578
 			}
1509 1579
 		}
1510 1580
 
1511 1581
 		// So you wanna (un)sticky this...let's see.
1512
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1513
-			unset($_POST['sticky']);
1514
-		elseif (isset($_POST['sticky']))
1582
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1583
+					unset($_POST['sticky']);
1584
+		} elseif (isset($_POST['sticky']))
1515 1585
 		{
1516 1586
 			// Did someone (un)sticky this while you were posting?
1517
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1518
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1587
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1588
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1589
+			}
1519 1590
 		}
1520 1591
 
1521 1592
 		// If drafts are enabled, then pass this off
@@ -1542,26 +1613,31 @@  discard block
 block discarded – undo
1542 1613
 
1543 1614
 		// Do like, the permissions, for safety and stuff...
1544 1615
 		$becomesApproved = true;
1545
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1546
-			$becomesApproved = false;
1547
-		else
1548
-			isAllowedTo('post_new');
1616
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1617
+					$becomesApproved = false;
1618
+		} else {
1619
+					isAllowedTo('post_new');
1620
+		}
1549 1621
 
1550 1622
 		if (isset($_POST['lock']))
1551 1623
 		{
1552 1624
 			// New topics are by default not locked.
1553
-			if (empty($_POST['lock']))
1554
-				unset($_POST['lock']);
1625
+			if (empty($_POST['lock'])) {
1626
+							unset($_POST['lock']);
1627
+			}
1555 1628
 			// Besides, you need permission.
1556
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1557
-				unset($_POST['lock']);
1629
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1630
+							unset($_POST['lock']);
1631
+			}
1558 1632
 			// A moderator-lock (1) can override a user-lock (2).
1559
-			else
1560
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1633
+			else {
1634
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1635
+			}
1561 1636
 		}
1562 1637
 
1563
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1564
-			unset($_POST['sticky']);
1638
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1639
+					unset($_POST['sticky']);
1640
+		}
1565 1641
 
1566 1642
 		// Saving your new topic as a draft first?
1567 1643
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1586,31 +1662,37 @@  discard block
 block discarded – undo
1586 1662
 				'id_msg' => $_REQUEST['msg'],
1587 1663
 			)
1588 1664
 		);
1589
-		if ($smcFunc['db_num_rows']($request) == 0)
1590
-			fatal_lang_error('cant_find_messages', false);
1665
+		if ($smcFunc['db_num_rows']($request) == 0) {
1666
+					fatal_lang_error('cant_find_messages', false);
1667
+		}
1591 1668
 		$row = $smcFunc['db_fetch_assoc']($request);
1592 1669
 		$smcFunc['db_free_result']($request);
1593 1670
 
1594
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1595
-			fatal_lang_error('topic_locked', false);
1671
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1672
+					fatal_lang_error('topic_locked', false);
1673
+		}
1596 1674
 
1597 1675
 		if (isset($_POST['lock']))
1598 1676
 		{
1599 1677
 			// Nothing changes to the lock status.
1600
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1601
-				unset($_POST['lock']);
1678
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1679
+							unset($_POST['lock']);
1680
+			}
1602 1681
 			// You're simply not allowed to (un)lock this.
1603
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1604
-				unset($_POST['lock']);
1682
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1683
+							unset($_POST['lock']);
1684
+			}
1605 1685
 			// You're only allowed to lock your own topics.
1606 1686
 			elseif (!allowedTo('lock_any'))
1607 1687
 			{
1608 1688
 				// You're not allowed to break a moderator's lock.
1609
-				if ($topic_info['locked'] == 1)
1610
-					unset($_POST['lock']);
1689
+				if ($topic_info['locked'] == 1) {
1690
+									unset($_POST['lock']);
1691
+				}
1611 1692
 				// Lock it with a soft lock or unlock it.
1612
-				else
1613
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1693
+				else {
1694
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1695
+				}
1614 1696
 			}
1615 1697
 			// You must be the moderator.
1616 1698
 			else
@@ -1618,44 +1700,46 @@  discard block
 block discarded – undo
1618 1700
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1619 1701
 
1620 1702
 				// Did someone (un)lock this while you were posting?
1621
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1622
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1703
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1704
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1705
+				}
1623 1706
 			}
1624 1707
 		}
1625 1708
 
1626 1709
 		// Change the sticky status of this topic?
1627
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1628
-			unset($_POST['sticky']);
1629
-		elseif (isset($_POST['sticky']))
1710
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1711
+					unset($_POST['sticky']);
1712
+		} elseif (isset($_POST['sticky']))
1630 1713
 		{
1631 1714
 			// Did someone (un)sticky this while you were posting?
1632
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1633
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1715
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1716
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1717
+			}
1634 1718
 		}
1635 1719
 
1636 1720
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1637 1721
 		{
1638
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1639
-				fatal_lang_error('modify_post_time_passed', false);
1640
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1641
-				isAllowedTo('modify_replies');
1642
-			else
1643
-				isAllowedTo('modify_own');
1644
-		}
1645
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1722
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1723
+							fatal_lang_error('modify_post_time_passed', false);
1724
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1725
+							isAllowedTo('modify_replies');
1726
+			} else {
1727
+							isAllowedTo('modify_own');
1728
+			}
1729
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1646 1730
 		{
1647 1731
 			isAllowedTo('modify_replies');
1648 1732
 
1649 1733
 			// If you're modifying a reply, I say it better be logged...
1650 1734
 			$moderationAction = true;
1651
-		}
1652
-		else
1735
+		} else
1653 1736
 		{
1654 1737
 			isAllowedTo('modify_any');
1655 1738
 
1656 1739
 			// Log it, assuming you're not modifying your own post.
1657
-			if ($row['id_member'] != $user_info['id'])
1658
-				$moderationAction = true;
1740
+			if ($row['id_member'] != $user_info['id']) {
1741
+							$moderationAction = true;
1742
+			}
1659 1743
 		}
1660 1744
 
1661 1745
 		// If drafts are enabled, then lets send this off to save
@@ -1692,20 +1776,24 @@  discard block
 block discarded – undo
1692 1776
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1693 1777
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1694 1778
 
1695
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1696
-			$post_errors[] = 'no_name';
1697
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1698
-			$post_errors[] = 'long_name';
1779
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1780
+					$post_errors[] = 'no_name';
1781
+		}
1782
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1783
+					$post_errors[] = 'long_name';
1784
+		}
1699 1785
 
1700 1786
 		if (empty($modSettings['guest_post_no_email']))
1701 1787
 		{
1702 1788
 			// Only check if they changed it!
1703 1789
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1704 1790
 			{
1705
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1706
-					$post_errors[] = 'no_email';
1707
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1708
-					$post_errors[] = 'bad_email';
1791
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1792
+									$post_errors[] = 'no_email';
1793
+				}
1794
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1795
+									$post_errors[] = 'bad_email';
1796
+				}
1709 1797
 			}
1710 1798
 
1711 1799
 			// Now make sure this email address is not banned from posting.
@@ -1721,75 +1809,89 @@  discard block
 block discarded – undo
1721 1809
 	}
1722 1810
 
1723 1811
 	// Coming from the quickReply?
1724
-	if(isset($_POST['quickReply']))
1725
-		$_POST['message'] = $_POST['quickReply'];
1812
+	if(isset($_POST['quickReply'])) {
1813
+			$_POST['message'] = $_POST['quickReply'];
1814
+	}
1726 1815
 
1727 1816
 	// Check the subject and message.
1728
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1729
-		$post_errors[] = 'no_subject';
1730
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1731
-		$post_errors[] = 'no_message';
1732
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1733
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1734
-	else
1817
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1818
+			$post_errors[] = 'no_subject';
1819
+	}
1820
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1821
+			$post_errors[] = 'no_message';
1822
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1823
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1824
+	} else
1735 1825
 	{
1736 1826
 		// Prepare the message a bit for some additional testing.
1737 1827
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1738 1828
 
1739 1829
 		// Preparse code. (Zef)
1740
-		if ($user_info['is_guest'])
1741
-			$user_info['name'] = $_POST['guestname'];
1830
+		if ($user_info['is_guest']) {
1831
+					$user_info['name'] = $_POST['guestname'];
1832
+		}
1742 1833
 		preparsecode($_POST['message']);
1743 1834
 
1744 1835
 		// Let's see if there's still some content left without the tags.
1745
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1746
-			$post_errors[] = 'no_message';
1836
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1837
+					$post_errors[] = 'no_message';
1838
+		}
1839
+	}
1840
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1841
+			$post_errors[] = 'no_event';
1747 1842
 	}
1748
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1749
-		$post_errors[] = 'no_event';
1750 1843
 	// You are not!
1751
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1752
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1844
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1845
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1846
+	}
1753 1847
 
1754 1848
 	// Validate the poll...
1755 1849
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1756 1850
 	{
1757
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1758
-			fatal_lang_error('no_access', false);
1851
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1852
+					fatal_lang_error('no_access', false);
1853
+		}
1759 1854
 
1760 1855
 		// This is a new topic... so it's a new poll.
1761
-		if (empty($topic))
1762
-			isAllowedTo('poll_post');
1856
+		if (empty($topic)) {
1857
+					isAllowedTo('poll_post');
1858
+		}
1763 1859
 		// Can you add to your own topics?
1764
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1765
-			isAllowedTo('poll_add_own');
1860
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1861
+					isAllowedTo('poll_add_own');
1862
+		}
1766 1863
 		// Can you add polls to any topic, then?
1767
-		else
1768
-			isAllowedTo('poll_add_any');
1864
+		else {
1865
+					isAllowedTo('poll_add_any');
1866
+		}
1769 1867
 
1770
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1771
-			$post_errors[] = 'no_question';
1868
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1869
+					$post_errors[] = 'no_question';
1870
+		}
1772 1871
 
1773 1872
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1774 1873
 
1775 1874
 		// Get rid of empty ones.
1776
-		foreach ($_POST['options'] as $k => $option)
1777
-			if ($option == '')
1875
+		foreach ($_POST['options'] as $k => $option) {
1876
+					if ($option == '')
1778 1877
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1878
+		}
1779 1879
 
1780 1880
 		// What are you going to vote between with one choice?!?
1781
-		if (count($_POST['options']) < 2)
1782
-			$post_errors[] = 'poll_few';
1783
-		elseif (count($_POST['options']) > 256)
1784
-			$post_errors[] = 'poll_many';
1881
+		if (count($_POST['options']) < 2) {
1882
+					$post_errors[] = 'poll_few';
1883
+		} elseif (count($_POST['options']) > 256) {
1884
+					$post_errors[] = 'poll_many';
1885
+		}
1785 1886
 	}
1786 1887
 
1787 1888
 	if ($posterIsGuest)
1788 1889
 	{
1789 1890
 		// If user is a guest, make sure the chosen name isn't taken.
1790 1891
 		require_once($sourcedir . '/Subs-Members.php');
1791
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1792
-			$post_errors[] = 'bad_name';
1892
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
1893
+					$post_errors[] = 'bad_name';
1894
+		}
1793 1895
 	}
1794 1896
 	// If the user isn't a guest, get his or her name and email.
1795 1897
 	elseif (!isset($_REQUEST['msg']))
@@ -1820,8 +1922,9 @@  discard block
 block discarded – undo
1820 1922
 	}
1821 1923
 
1822 1924
 	// Make sure the user isn't spamming the board.
1823
-	if (!isset($_REQUEST['msg']))
1824
-		spamProtection('post');
1925
+	if (!isset($_REQUEST['msg'])) {
1926
+			spamProtection('post');
1927
+	}
1825 1928
 
1826 1929
 	// At about this point, we're posting and that's that.
1827 1930
 	ignore_user_abort(true);
@@ -1834,32 +1937,36 @@  discard block
 block discarded – undo
1834 1937
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1835 1938
 
1836 1939
 	// At this point, we want to make sure the subject isn't too long.
1837
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1838
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
1940
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
1941
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
1942
+	}
1839 1943
 
1840 1944
 	// Same with the "why did you edit this" text.
1841
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1842
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
1945
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
1946
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
1947
+	}
1843 1948
 
1844 1949
 	// Make the poll...
1845 1950
 	if (isset($_REQUEST['poll']))
1846 1951
 	{
1847 1952
 		// Make sure that the user has not entered a ridiculous number of options..
1848
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1849
-			$_POST['poll_max_votes'] = 1;
1850
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1851
-			$_POST['poll_max_votes'] = count($_POST['options']);
1852
-		else
1853
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
1953
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
1954
+					$_POST['poll_max_votes'] = 1;
1955
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
1956
+					$_POST['poll_max_votes'] = count($_POST['options']);
1957
+		} else {
1958
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
1959
+		}
1854 1960
 
1855 1961
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1856 1962
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1857 1963
 
1858 1964
 		// Just set it to zero if it's not there..
1859
-		if (!isset($_POST['poll_hide']))
1860
-			$_POST['poll_hide'] = 0;
1861
-		else
1862
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
1965
+		if (!isset($_POST['poll_hide'])) {
1966
+					$_POST['poll_hide'] = 0;
1967
+		} else {
1968
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
1969
+		}
1863 1970
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1864 1971
 
1865 1972
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1868,16 +1975,19 @@  discard block
 block discarded – undo
1868 1975
 		{
1869 1976
 			require_once($sourcedir . '/Subs-Members.php');
1870 1977
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1871
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1872
-				$_POST['poll_guest_vote'] = 0;
1978
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
1979
+							$_POST['poll_guest_vote'] = 0;
1980
+			}
1873 1981
 		}
1874 1982
 
1875 1983
 		// If the user tries to set the poll too far in advance, don't let them.
1876
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1877
-			fatal_lang_error('poll_range_error', false);
1984
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
1985
+					fatal_lang_error('poll_range_error', false);
1986
+		}
1878 1987
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1879
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1880
-			$_POST['poll_hide'] = 1;
1988
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
1989
+					$_POST['poll_hide'] = 1;
1990
+		}
1881 1991
 
1882 1992
 		// Clean up the question and answers.
1883 1993
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1891,13 +2001,15 @@  discard block
 block discarded – undo
1891 2001
 	{
1892 2002
 		$attachIDs = array();
1893 2003
 		$attach_errors = array();
1894
-		if (!empty($context['we_are_history']))
1895
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2004
+		if (!empty($context['we_are_history'])) {
2005
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2006
+		}
1896 2007
 
1897 2008
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
1898 2009
 		{
1899
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1900
-				continue;
2010
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2011
+							continue;
2012
+			}
1901 2013
 
1902 2014
 			// If there was an initial error just show that message.
1903 2015
 			if ($attachID == 'initial_error')
@@ -1926,12 +2038,13 @@  discard block
 block discarded – undo
1926 2038
 				if (createAttachment($attachmentOptions))
1927 2039
 				{
1928 2040
 					$attachIDs[] = $attachmentOptions['id'];
1929
-					if (!empty($attachmentOptions['thumb']))
1930
-						$attachIDs[] = $attachmentOptions['thumb'];
2041
+					if (!empty($attachmentOptions['thumb'])) {
2042
+											$attachIDs[] = $attachmentOptions['thumb'];
2043
+					}
1931 2044
 				}
2045
+			} else {
2046
+							$attach_errors[] = '<dt>&nbsp;</dt>';
1932 2047
 			}
1933
-			else
1934
-				$attach_errors[] = '<dt>&nbsp;</dt>';
1935 2048
 
1936 2049
 			if (!empty($attachmentOptions['errors']))
1937 2050
 			{
@@ -1943,14 +2056,16 @@  discard block
 block discarded – undo
1943 2056
 					if (!is_array($error))
1944 2057
 					{
1945 2058
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
1946
-						if (in_array($error, $log_these))
1947
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2059
+						if (in_array($error, $log_these)) {
2060
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2061
+						}
2062
+					} else {
2063
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
1948 2064
 					}
1949
-					else
1950
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
1951 2065
 				}
1952
-				if (file_exists($attachment['tmp_name']))
1953
-					unlink($attachment['tmp_name']);
2066
+				if (file_exists($attachment['tmp_name'])) {
2067
+									unlink($attachment['tmp_name']);
2068
+				}
1954 2069
 			}
1955 2070
 		}
1956 2071
 		unset($_SESSION['temp_attachments']);
@@ -1991,24 +2106,24 @@  discard block
 block discarded – undo
1991 2106
 		);
1992 2107
 
1993 2108
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2109
+	} else {
2110
+			$id_poll = 0;
1994 2111
 	}
1995
-	else
1996
-		$id_poll = 0;
1997 2112
 
1998 2113
 	// Creating a new topic?
1999 2114
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2000 2115
 
2001 2116
 	// Check the icon.
2002
-	if (!isset($_POST['icon']))
2003
-		$_POST['icon'] = 'xx';
2004
-
2005
-	else
2117
+	if (!isset($_POST['icon'])) {
2118
+			$_POST['icon'] = 'xx';
2119
+	} else
2006 2120
 	{
2007 2121
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2008 2122
 
2009 2123
 		// Need to figure it out if this is a valid icon name.
2010
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2011
-			$_POST['icon'] = 'xx';
2124
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2125
+					$_POST['icon'] = 'xx';
2126
+		}
2012 2127
 	}
2013 2128
 
2014 2129
 	// Collect all parameters for the creation or modification of a post.
@@ -2049,8 +2164,9 @@  discard block
 block discarded – undo
2049 2164
 		}
2050 2165
 
2051 2166
 		// This will save some time...
2052
-		if (empty($approve_has_changed))
2053
-			unset($msgOptions['approved']);
2167
+		if (empty($approve_has_changed)) {
2168
+					unset($msgOptions['approved']);
2169
+		}
2054 2170
 
2055 2171
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2056 2172
 	}
@@ -2059,8 +2175,9 @@  discard block
 block discarded – undo
2059 2175
 	{
2060 2176
 		createPost($msgOptions, $topicOptions, $posterOptions);
2061 2177
 
2062
-		if (isset($topicOptions['id']))
2063
-			$topic = $topicOptions['id'];
2178
+		if (isset($topicOptions['id'])) {
2179
+					$topic = $topicOptions['id'];
2180
+		}
2064 2181
 	}
2065 2182
 
2066 2183
 	// Assign the previously uploaded attachments to the brand new message.
@@ -2072,8 +2189,9 @@  discard block
 block discarded – undo
2072 2189
 	}
2073 2190
 
2074 2191
 	// If we had a draft for this, its time to remove it since it was just posted
2075
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2076
-		DeleteDraft($_POST['id_draft']);
2192
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2193
+			DeleteDraft($_POST['id_draft']);
2194
+	}
2077 2195
 
2078 2196
 	// Editing or posting an event?
2079 2197
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2092,8 +2210,7 @@  discard block
 block discarded – undo
2092 2210
 			'member' => $user_info['id'],
2093 2211
 		);
2094 2212
 		insertEvent($eventOptions);
2095
-	}
2096
-	elseif (isset($_POST['calendar']))
2213
+	} elseif (isset($_POST['calendar']))
2097 2214
 	{
2098 2215
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2099 2216
 
@@ -2121,14 +2238,15 @@  discard block
 block discarded – undo
2121 2238
 		}
2122 2239
 
2123 2240
 		// Delete it?
2124
-		if (isset($_REQUEST['deleteevent']))
2125
-			$smcFunc['db_query']('', '
2241
+		if (isset($_REQUEST['deleteevent'])) {
2242
+					$smcFunc['db_query']('', '
2126 2243
 				DELETE FROM {db_prefix}calendar
2127 2244
 				WHERE id_event = {int:id_event}',
2128 2245
 				array(
2129 2246
 					'id_event' => $_REQUEST['eventid'],
2130 2247
 				)
2131 2248
 			);
2249
+		}
2132 2250
 		// ... or just update it?
2133 2251
 		else
2134 2252
 		{
@@ -2170,9 +2288,8 @@  discard block
 block discarded – undo
2170 2288
 			array($user_info['id'], $topic, 0),
2171 2289
 			array('id_member', 'id_topic', 'id_board')
2172 2290
 		);
2173
-	}
2174
-	elseif (!$newTopic)
2175
-		$smcFunc['db_query']('', '
2291
+	} elseif (!$newTopic) {
2292
+			$smcFunc['db_query']('', '
2176 2293
 			DELETE FROM {db_prefix}log_notify
2177 2294
 			WHERE id_member = {int:current_member}
2178 2295
 				AND id_topic = {int:current_topic}',
@@ -2181,16 +2298,20 @@  discard block
 block discarded – undo
2181 2298
 				'current_topic' => $topic,
2182 2299
 			)
2183 2300
 		);
2301
+	}
2184 2302
 
2185 2303
 	// Log an act of moderation - modifying.
2186
-	if (!empty($moderationAction))
2187
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2304
+	if (!empty($moderationAction)) {
2305
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2306
+	}
2188 2307
 
2189
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2190
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2308
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2309
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2310
+	}
2191 2311
 
2192
-	if (isset($_POST['sticky']))
2193
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2312
+	if (isset($_POST['sticky'])) {
2313
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2314
+	}
2194 2315
 
2195 2316
 	// Returning to the topic?
2196 2317
 	if (!empty($_REQUEST['goback']))
@@ -2209,26 +2330,31 @@  discard block
 block discarded – undo
2209 2330
 		);
2210 2331
 	}
2211 2332
 
2212
-	if ($board_info['num_topics'] == 0)
2213
-		cache_put_data('board-' . $board, null, 120);
2333
+	if ($board_info['num_topics'] == 0) {
2334
+			cache_put_data('board-' . $board, null, 120);
2335
+	}
2214 2336
 
2215 2337
 	call_integration_hook('integrate_post2_end');
2216 2338
 
2217
-	if (!empty($_POST['announce_topic']))
2218
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2339
+	if (!empty($_POST['announce_topic'])) {
2340
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2341
+	}
2219 2342
 
2220
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2221
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2343
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2344
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2345
+	}
2222 2346
 
2223 2347
 	// Return to post if the mod is on.
2224
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2225
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2226
-	elseif (!empty($_REQUEST['goback']))
2227
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2348
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2349
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2350
+	} elseif (!empty($_REQUEST['goback'])) {
2351
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2352
+	}
2228 2353
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2229
-	else
2230
-		redirectexit('board=' . $board . '.0');
2231
-}
2354
+	else {
2355
+			redirectexit('board=' . $board . '.0');
2356
+	}
2357
+	}
2232 2358
 
2233 2359
 /**
2234 2360
  * Handle the announce topic function (action=announce).
@@ -2246,8 +2372,9 @@  discard block
 block discarded – undo
2246 2372
 
2247 2373
 	validateSession();
2248 2374
 
2249
-	if (empty($topic))
2250
-		fatal_lang_error('topic_gone', false);
2375
+	if (empty($topic)) {
2376
+			fatal_lang_error('topic_gone', false);
2377
+	}
2251 2378
 
2252 2379
 	loadLanguage('Post');
2253 2380
 	loadTemplate('Post');
@@ -2274,8 +2401,9 @@  discard block
 block discarded – undo
2274 2401
 	global $txt, $context, $topic, $board, $board_info, $smcFunc;
2275 2402
 
2276 2403
 	$groups = array_merge($board_info['groups'], array(1));
2277
-	foreach ($groups as $id => $group)
2278
-		$groups[$id] = (int) $group;
2404
+	foreach ($groups as $id => $group) {
2405
+			$groups[$id] = (int) $group;
2406
+	}
2279 2407
 
2280 2408
 	$context['groups'] = array();
2281 2409
 	if (in_array(0, $groups))
@@ -2318,8 +2446,9 @@  discard block
 block discarded – undo
2318 2446
 			'group_list' => $groups,
2319 2447
 		)
2320 2448
 	);
2321
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2322
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2449
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2450
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2451
+	}
2323 2452
 	$smcFunc['db_free_result']($request);
2324 2453
 
2325 2454
 	// Get the subject of the topic we're about to announce.
@@ -2361,16 +2490,19 @@  discard block
 block discarded – undo
2361 2490
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2362 2491
 	$groups = array_merge($board_info['groups'], array(1));
2363 2492
 
2364
-	if (isset($_POST['membergroups']))
2365
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2493
+	if (isset($_POST['membergroups'])) {
2494
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2495
+	}
2366 2496
 
2367 2497
 	// Check whether at least one membergroup was selected.
2368
-	if (empty($_POST['who']))
2369
-		fatal_lang_error('no_membergroup_selected');
2498
+	if (empty($_POST['who'])) {
2499
+			fatal_lang_error('no_membergroup_selected');
2500
+	}
2370 2501
 
2371 2502
 	// Make sure all membergroups are integers and can access the board of the announcement.
2372
-	foreach ($_POST['who'] as $id => $mg)
2373
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2503
+	foreach ($_POST['who'] as $id => $mg) {
2504
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2505
+	}
2374 2506
 
2375 2507
 	// Get the topic subject and censor it.
2376 2508
 	$request = $smcFunc['db_query']('', '
@@ -2416,12 +2548,13 @@  discard block
 block discarded – undo
2416 2548
 	if ($smcFunc['db_num_rows']($request) == 0)
2417 2549
 	{
2418 2550
 		logAction('announce_topic', array('topic' => $topic), 'user');
2419
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2420
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2421
-		elseif (!empty($_REQUEST['goback']))
2422
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2423
-		else
2424
-			redirectexit('board=' . $board . '.0');
2551
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2552
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2553
+		} elseif (!empty($_REQUEST['goback'])) {
2554
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2555
+		} else {
2556
+					redirectexit('board=' . $board . '.0');
2557
+		}
2425 2558
 	}
2426 2559
 
2427 2560
 	$announcements = array();
@@ -2440,8 +2573,9 @@  discard block
 block discarded – undo
2440 2573
 	foreach ($rows as $row)
2441 2574
 	{
2442 2575
 		// Force them to have it?
2443
-		if (empty($prefs[$row['id_member']]['announcements']))
2444
-			continue;
2576
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2577
+					continue;
2578
+		}
2445 2579
 
2446 2580
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2447 2581
 
@@ -2469,8 +2603,9 @@  discard block
 block discarded – undo
2469 2603
 	}
2470 2604
 
2471 2605
 	// For each language send a different mail - low priority...
2472
-	foreach ($announcements as $lang => $mail)
2473
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2606
+	foreach ($announcements as $lang => $mail) {
2607
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2608
+	}
2474 2609
 
2475 2610
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2476 2611
 
@@ -2480,9 +2615,10 @@  discard block
 block discarded – undo
2480 2615
 	$context['sub_template'] = 'announcement_send';
2481 2616
 
2482 2617
 	// Go back to the correct language for the user ;).
2483
-	if (!empty($modSettings['userLanguage']))
2484
-		loadLanguage('Post');
2485
-}
2618
+	if (!empty($modSettings['userLanguage'])) {
2619
+			loadLanguage('Post');
2620
+	}
2621
+	}
2486 2622
 
2487 2623
 /**
2488 2624
  * Get the topic for display purposes.
@@ -2495,12 +2631,13 @@  discard block
 block discarded – undo
2495 2631
 {
2496 2632
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2497 2633
 
2498
-	if (isset($_REQUEST['xml']))
2499
-		$limit = '
2634
+	if (isset($_REQUEST['xml'])) {
2635
+			$limit = '
2500 2636
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2501
-	else
2502
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2637
+	} else {
2638
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2503 2639
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2640
+	}
2504 2641
 
2505 2642
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2506 2643
 	$request = $smcFunc['db_query']('', '
@@ -2538,8 +2675,9 @@  discard block
 block discarded – undo
2538 2675
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2539 2676
 		);
2540 2677
 
2541
-		if (!empty($context['new_replies']))
2542
-			$context['new_replies']--;
2678
+		if (!empty($context['new_replies'])) {
2679
+					$context['new_replies']--;
2680
+		}
2543 2681
 	}
2544 2682
 	$smcFunc['db_free_result']($request);
2545 2683
 }
@@ -2556,8 +2694,9 @@  discard block
 block discarded – undo
2556 2694
 	global $sourcedir, $smcFunc;
2557 2695
 
2558 2696
 	loadLanguage('Post');
2559
-	if (!isset($_REQUEST['xml']))
2560
-		loadTemplate('Post');
2697
+	if (!isset($_REQUEST['xml'])) {
2698
+			loadTemplate('Post');
2699
+	}
2561 2700
 
2562 2701
 	include_once($sourcedir . '/Subs-Post.php');
2563 2702
 
@@ -2588,8 +2727,9 @@  discard block
 block discarded – undo
2588 2727
 	$smcFunc['db_free_result']($request);
2589 2728
 
2590 2729
 	$context['sub_template'] = 'quotefast';
2591
-	if (!empty($row))
2592
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2730
+	if (!empty($row)) {
2731
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2732
+	}
2593 2733
 
2594 2734
 	if (!empty($can_view_post))
2595 2735
 	{
@@ -2622,8 +2762,9 @@  discard block
 block discarded – undo
2622 2762
 		}
2623 2763
 
2624 2764
 		// Remove any nested quotes.
2625
-		if (!empty($modSettings['removeNestedQuotes']))
2626
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2765
+		if (!empty($modSettings['removeNestedQuotes'])) {
2766
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2767
+		}
2627 2768
 
2628 2769
 		$lb = "\n";
2629 2770
 
@@ -2649,14 +2790,14 @@  discard block
 block discarded – undo
2649 2790
 				'time' => '',
2650 2791
 			),
2651 2792
 		);
2652
-	}
2653
-	else
2654
-		$context['quote'] = array(
2793
+	} else {
2794
+			$context['quote'] = array(
2655 2795
 			'xml' => '',
2656 2796
 			'mozilla' => '',
2657 2797
 			'text' => '',
2658 2798
 		);
2659
-}
2799
+	}
2800
+	}
2660 2801
 
2661 2802
 /**
2662 2803
  * Used to edit the body or subject of a message inline
@@ -2668,8 +2809,9 @@  discard block
 block discarded – undo
2668 2809
 	global $user_info, $context, $smcFunc, $language, $board_info;
2669 2810
 
2670 2811
 	// We have to have a topic!
2671
-	if (empty($topic))
2672
-		obExit(false);
2812
+	if (empty($topic)) {
2813
+			obExit(false);
2814
+	}
2673 2815
 
2674 2816
 	checkSession('get');
2675 2817
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2695,31 +2837,35 @@  discard block
 block discarded – undo
2695 2837
 			'guest_id' => 0,
2696 2838
 		)
2697 2839
 	);
2698
-	if ($smcFunc['db_num_rows']($request) == 0)
2699
-		fatal_lang_error('no_board', false);
2840
+	if ($smcFunc['db_num_rows']($request) == 0) {
2841
+			fatal_lang_error('no_board', false);
2842
+	}
2700 2843
 	$row = $smcFunc['db_fetch_assoc']($request);
2701 2844
 	$smcFunc['db_free_result']($request);
2702 2845
 
2703 2846
 	// Change either body or subject requires permissions to modify messages.
2704 2847
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2705 2848
 	{
2706
-		if (!empty($row['locked']))
2707
-			isAllowedTo('moderate_board');
2849
+		if (!empty($row['locked'])) {
2850
+					isAllowedTo('moderate_board');
2851
+		}
2708 2852
 
2709 2853
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2710 2854
 		{
2711
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2712
-				fatal_lang_error('modify_post_time_passed', false);
2713
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2714
-				isAllowedTo('modify_replies');
2715
-			else
2716
-				isAllowedTo('modify_own');
2855
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2856
+							fatal_lang_error('modify_post_time_passed', false);
2857
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2858
+							isAllowedTo('modify_replies');
2859
+			} else {
2860
+							isAllowedTo('modify_own');
2861
+			}
2717 2862
 		}
2718 2863
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2719
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2720
-			isAllowedTo('modify_replies');
2721
-		else
2722
-			isAllowedTo('modify_any');
2864
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2865
+					isAllowedTo('modify_replies');
2866
+		} else {
2867
+					isAllowedTo('modify_any');
2868
+		}
2723 2869
 
2724 2870
 		// Only log this action if it wasn't your message.
2725 2871
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2731,10 +2877,10 @@  discard block
 block discarded – undo
2731 2877
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2732 2878
 
2733 2879
 		// Maximum number of characters.
2734
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2735
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2736
-	}
2737
-	elseif (isset($_POST['subject']))
2880
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2881
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2882
+		}
2883
+	} elseif (isset($_POST['subject']))
2738 2884
 	{
2739 2885
 		$post_errors[] = 'no_subject';
2740 2886
 		unset($_POST['subject']);
@@ -2746,13 +2892,11 @@  discard block
 block discarded – undo
2746 2892
 		{
2747 2893
 			$post_errors[] = 'no_message';
2748 2894
 			unset($_POST['message']);
2749
-		}
2750
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2895
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2751 2896
 		{
2752 2897
 			$post_errors[] = 'long_message';
2753 2898
 			unset($_POST['message']);
2754
-		}
2755
-		else
2899
+		} else
2756 2900
 		{
2757 2901
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2758 2902
 
@@ -2768,31 +2912,34 @@  discard block
 block discarded – undo
2768 2912
 
2769 2913
 	if (isset($_POST['lock']))
2770 2914
 	{
2771
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2772
-			unset($_POST['lock']);
2773
-		elseif (!allowedTo('lock_any'))
2915
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
2916
+					unset($_POST['lock']);
2917
+		} elseif (!allowedTo('lock_any'))
2774 2918
 		{
2775
-			if ($row['locked'] == 1)
2776
-				unset($_POST['lock']);
2777
-			else
2778
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
2919
+			if ($row['locked'] == 1) {
2920
+							unset($_POST['lock']);
2921
+			} else {
2922
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
2923
+			}
2924
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
2925
+					unset($_POST['lock']);
2926
+		} else {
2927
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2779 2928
 		}
2780
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2781
-			unset($_POST['lock']);
2782
-		else
2783
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2784 2929
 	}
2785 2930
 
2786
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2787
-		unset($_POST['sticky']);
2931
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
2932
+			unset($_POST['sticky']);
2933
+	}
2788 2934
 
2789 2935
 	if (isset($_POST['modify_reason']))
2790 2936
 	{
2791 2937
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2792 2938
 
2793 2939
 		// Maximum number of characters.
2794
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2795
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2940
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2941
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2942
+		}
2796 2943
 	}
2797 2944
 
2798 2945
 	if (empty($post_errors))
@@ -2829,8 +2976,9 @@  discard block
 block discarded – undo
2829 2976
 			}
2830 2977
 		}
2831 2978
 		// If nothing was changed there's no need to add an entry to the moderation log.
2832
-		else
2833
-			$moderationAction = false;
2979
+		else {
2980
+					$moderationAction = false;
2981
+		}
2834 2982
 
2835 2983
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2836 2984
 
@@ -2848,9 +2996,9 @@  discard block
 block discarded – undo
2848 2996
 			// Get the proper (default language) response prefix first.
2849 2997
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2850 2998
 			{
2851
-				if ($language === $user_info['language'])
2852
-					$context['response_prefix'] = $txt['response_prefix'];
2853
-				else
2999
+				if ($language === $user_info['language']) {
3000
+									$context['response_prefix'] = $txt['response_prefix'];
3001
+				} else
2854 3002
 				{
2855 3003
 					loadLanguage('index', $language, false);
2856 3004
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2872,8 +3020,9 @@  discard block
 block discarded – undo
2872 3020
 			);
2873 3021
 		}
2874 3022
 
2875
-		if (!empty($moderationAction))
2876
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3023
+		if (!empty($moderationAction)) {
3024
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3025
+		}
2877 3026
 	}
2878 3027
 
2879 3028
 	if (isset($_REQUEST['xml']))
@@ -2914,8 +3063,7 @@  discard block
 block discarded – undo
2914 3063
 			);
2915 3064
 
2916 3065
 			censorText($context['message']['subject']);
2917
-		}
2918
-		else
3066
+		} else
2919 3067
 		{
2920 3068
 			$context['message'] = array(
2921 3069
 				'id' => $row['id_msg'],
@@ -2927,15 +3075,16 @@  discard block
 block discarded – undo
2927 3075
 			loadLanguage('Errors');
2928 3076
 			foreach ($post_errors as $post_error)
2929 3077
 			{
2930
-				if ($post_error == 'long_message')
2931
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
2932
-				else
2933
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3078
+				if ($post_error == 'long_message') {
3079
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3080
+				} else {
3081
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3082
+				}
2934 3083
 			}
2935 3084
 		}
3085
+	} else {
3086
+			obExit(false);
3087
+	}
2936 3088
 	}
2937
-	else
2938
-		obExit(false);
2939
-}
2940 3089
 
2941 3090
 ?>
2942 3091
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Calendar.php 1 patch
Braces   +105 added lines, -83 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * Show the calendar.
@@ -47,12 +48,14 @@  discard block
 block discarded – undo
47 48
 		'post' => 'CalendarPost',
48 49
 	);
49 50
 
50
-	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']]))
51
-		return call_helper($subActions[$_GET['sa']]);
51
+	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']])) {
52
+			return call_helper($subActions[$_GET['sa']]);
53
+	}
52 54
 
53 55
 	// You can't do anything if the calendar is off.
54
-	if (empty($modSettings['cal_enabled']))
55
-		fatal_lang_error('calendar_off', false);
56
+	if (empty($modSettings['cal_enabled'])) {
57
+			fatal_lang_error('calendar_off', false);
58
+	}
56 59
 
57 60
 	// This is gonna be needed...
58 61
 	loadTemplate('Calendar');
@@ -97,8 +100,9 @@  discard block
 block discarded – undo
97 100
 	$context['view_week'] = isset($_GET['viewweek']);
98 101
 
99 102
 	// Don't let search engines index weekly calendar pages.
100
-	if ($context['view_week'])
101
-		$context['robot_no_index'] = true;
103
+	if ($context['view_week']) {
104
+			$context['robot_no_index'] = true;
105
+	}
102 106
 
103 107
 	// Get the current day of month...
104 108
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -112,17 +116,20 @@  discard block
 block discarded – undo
112 116
 	);
113 117
 
114 118
 	// Make sure the year and month are in valid ranges.
115
-	if ($curPage['month'] < 1 || $curPage['month'] > 12)
116
-		fatal_lang_error('invalid_month', false);
117
-	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear'])
118
-		fatal_lang_error('invalid_year', false);
119
+	if ($curPage['month'] < 1 || $curPage['month'] > 12) {
120
+			fatal_lang_error('invalid_month', false);
121
+	}
122
+	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) {
123
+			fatal_lang_error('invalid_year', false);
124
+	}
119 125
 	// If we have a day clean that too.
120 126
 	if ($context['view_week'])
121 127
 	{
122 128
 		// Note $isValid is -1 < PHP 5.1
123 129
 		$isValid = mktime(0, 0, 0, $curPage['month'], $curPage['day'], $curPage['year']);
124
-		if ($curPage['day'] > 31 || !$isValid || $isValid == -1)
125
-			fatal_lang_error('invalid_day', false);
130
+		if ($curPage['day'] > 31 || !$isValid || $isValid == -1) {
131
+					fatal_lang_error('invalid_day', false);
132
+		}
126 133
 	}
127 134
 
128 135
 	// Load all the context information needed to show the calendar grid.
@@ -144,21 +151,24 @@  discard block
 block discarded – undo
144 151
 	);
145 152
 
146 153
 	// Load up the main view.
147
-	if ($context['view_week'])
148
-		$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
149
-	else
150
-		$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154
+	if ($context['view_week']) {
155
+			$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
156
+	} else {
157
+			$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
158
+	}
151 159
 
152 160
 	// Load up the previous and next months.
153 161
 	$context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154 162
 
155 163
 	// Only show previous month if it isn't pre-January of the min-year
156
-	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1)
157
-		$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
164
+	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) {
165
+			$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
166
+	}
158 167
 
159 168
 	// Only show next month if it isn't post-December of the max-year
160
-	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12)
161
-		$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
169
+	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) {
170
+			$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
171
+	}
162 172
 
163 173
 	// Basic template stuff.
164 174
 	$context['allow_calendar_event'] = allowedTo('calendar_post');
@@ -191,17 +201,19 @@  discard block
 block discarded – undo
191 201
 		'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year']
192 202
 	);
193 203
 	// If applicable, add the current week to the linktree.
194
-	if ($context['view_week'])
195
-		$context['linktree'][] = array(
204
+	if ($context['view_week']) {
205
+			$context['linktree'][] = array(
196 206
 			'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'],
197 207
 			'name' => $context['calendar_grid_main']['week_title'],
198 208
 		);
209
+	}
199 210
 
200 211
 	// Build the calendar button array.
201 212
 	$context['calendar_buttons'] = array();
202 213
 
203
-	if ($context['can_post'])
204
-		$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
214
+	if ($context['can_post']) {
215
+			$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
216
+	}
205 217
 
206 218
 	// Allow mods to add additional buttons here
207 219
 	call_integration_hook('integrate_calendar_buttons');
@@ -230,14 +242,16 @@  discard block
 block discarded – undo
230 242
 	require_once($sourcedir . '/Subs.php');
231 243
 
232 244
 	// Cast this for safety...
233
-	if (isset($_REQUEST['eventid']))
234
-		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
245
+	if (isset($_REQUEST['eventid'])) {
246
+			$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
247
+	}
235 248
 
236 249
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
237
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
238
-		$time_string = '%k:%M';
239
-	else
240
-		$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
250
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
251
+			$time_string = '%k:%M';
252
+	} else {
253
+			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
254
+	}
241 255
 
242 256
 	$js_time_string = str_replace(
243 257
 		array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -251,12 +265,14 @@  discard block
 block discarded – undo
251 265
 		checkSession();
252 266
 
253 267
 		// Validate the post...
254
-		if (!isset($_POST['link_to_board']))
255
-			validateEventPost();
268
+		if (!isset($_POST['link_to_board'])) {
269
+					validateEventPost();
270
+		}
256 271
 
257 272
 		// If you're not allowed to edit any events, you have to be the poster.
258
-		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any'))
259
-			isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
273
+		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) {
274
+					isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
275
+		}
260 276
 
261 277
 		// New - and directing?
262 278
 		if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked']))
@@ -279,8 +295,9 @@  discard block
 block discarded – undo
279 295
 		}
280 296
 
281 297
 		// Deleting...
282
-		elseif (isset($_REQUEST['deleteevent']))
283
-			removeEvent($_REQUEST['eventid']);
298
+		elseif (isset($_REQUEST['deleteevent'])) {
299
+					removeEvent($_REQUEST['eventid']);
300
+		}
284 301
 
285 302
 		// ... or just update it?
286 303
 		else
@@ -302,14 +319,12 @@  discard block
 block discarded – undo
302 319
 			$d = date_parse($_POST['start_date']);
303 320
 			$year = $d['year'];
304 321
 			$month = $d['month'];
305
-		}
306
-		elseif (isset($_POST['start_datetime']))
322
+		} elseif (isset($_POST['start_datetime']))
307 323
 		{
308 324
 			$d = date_parse($_POST['start_datetime']);
309 325
 			$year = $d['year'];
310 326
 			$month = $d['month'];
311
-		}
312
-		else
327
+		} else
313 328
 		{
314 329
 			$today = getdate();
315 330
 			$year = isset($_POST['year']) ? $_POST['year'] : $today['year'];
@@ -342,13 +357,13 @@  discard block
 block discarded – undo
342 357
 		$context['event'] = array_merge($context['event'], $eventDatetimes);
343 358
 
344 359
 		$context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
345
-	}
346
-	else
360
+	} else
347 361
 	{
348 362
 		$context['event'] = getEventProperties($_REQUEST['eventid']);
349 363
 
350
-		if ($context['event'] === false)
351
-			fatal_lang_error('no_access', false);
364
+		if ($context['event'] === false) {
365
+					fatal_lang_error('no_access', false);
366
+		}
352 367
 
353 368
 		// If it has a board, then they should be editing it within the topic.
354 369
 		if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg']))
@@ -359,10 +374,11 @@  discard block
 block discarded – undo
359 374
 		}
360 375
 
361 376
 		// Make sure the user is allowed to edit this event.
362
-		if ($context['event']['member'] != $user_info['id'])
363
-			isAllowedTo('calendar_edit_any');
364
-		elseif (!allowedTo('calendar_edit_any'))
365
-			isAllowedTo('calendar_edit_own');
377
+		if ($context['event']['member'] != $user_info['id']) {
378
+					isAllowedTo('calendar_edit_any');
379
+		} elseif (!allowedTo('calendar_edit_any')) {
380
+					isAllowedTo('calendar_edit_own');
381
+		}
366 382
 	}
367 383
 
368 384
 	// An all day event? Set up some nice defaults in case the user wants to change that
@@ -396,8 +412,7 @@  discard block
 block discarded – undo
396 412
 	{
397 413
 		// You can post new events but can't link them to anything...
398 414
 		$context['event']['categories'] = array();
399
-	}
400
-	else
415
+	} else
401 416
 	{
402 417
 		// Load the list of boards and categories in the context.
403 418
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -484,12 +499,14 @@  discard block
 block discarded – undo
484 499
 	global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname;
485 500
 
486 501
 	// You can't export if the calendar export feature is off.
487
-	if (empty($modSettings['cal_export']))
488
-		fatal_lang_error('calendar_export_off', false);
502
+	if (empty($modSettings['cal_export'])) {
503
+			fatal_lang_error('calendar_export_off', false);
504
+	}
489 505
 
490 506
 	// Goes without saying that this is required.
491
-	if (!isset($_REQUEST['eventid']))
492
-		fatal_lang_error('no_access', false);
507
+	if (!isset($_REQUEST['eventid'])) {
508
+			fatal_lang_error('no_access', false);
509
+	}
493 510
 
494 511
 	// This is kinda wanted.
495 512
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -497,15 +514,17 @@  discard block
 block discarded – undo
497 514
 	// Load up the event in question and check it exists.
498 515
 	$event = getEventProperties($_REQUEST['eventid']);
499 516
 
500
-	if ($event === false)
501
-		fatal_lang_error('no_access', false);
517
+	if ($event === false) {
518
+			fatal_lang_error('no_access', false);
519
+	}
502 520
 
503 521
 	// Check the title isn't too long - iCal requires some formatting if so.
504 522
 	$title = str_split($event['title'], 30);
505 523
 	foreach ($title as $id => $line)
506 524
 	{
507
-		if ($id != 0)
508
-			$title[$id] = ' ' . $title[$id];
525
+		if ($id != 0) {
526
+					$title[$id] = ' ' . $title[$id];
527
+		}
509 528
 		$title[$id] .= "\n";
510 529
 	}
511 530
 
@@ -518,8 +537,7 @@  discard block
 block discarded – undo
518 537
 	{
519 538
 		$datestart = date_format($start_date, 'Ymd\THis');
520 539
 		$dateend = date_format($end_date, 'Ymd\THis');
521
-	}
522
-	else
540
+	} else
523 541
 	{
524 542
 		$datestart = date_format($start_date, 'Ymd');
525 543
 
@@ -540,15 +558,18 @@  discard block
 block discarded – undo
540 558
 	$filecontents .= 'DTSTART' . (!empty($event['start_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $datestart . "\n";
541 559
 
542 560
 	// event has a duration
543
-	if ($event['start_iso_gmdate'] != $event['end_iso_gmdate'])
544
-		$filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n";
561
+	if ($event['start_iso_gmdate'] != $event['end_iso_gmdate']) {
562
+			$filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n";
563
+	}
545 564
 
546 565
 	// event has changed? advance the sequence for this UID
547
-	if ($event['sequence'] > 0)
548
-		$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
566
+	if ($event['sequence'] > 0) {
567
+			$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
568
+	}
549 569
 
550
-	if (!empty($event['location']))
551
-		$filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n";
570
+	if (!empty($event['location'])) {
571
+			$filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n";
572
+	}
552 573
 
553 574
 	$filecontents .= 'SUMMARY:' . implode('', $title);
554 575
 	$filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n";
@@ -557,23 +578,26 @@  discard block
 block discarded – undo
557 578
 
558 579
 	// Send some standard headers.
559 580
 	ob_end_clean();
560
-	if (!empty($modSettings['enableCompressedOutput']))
561
-		@ob_start('ob_gzhandler');
562
-	else
563
-		ob_start();
581
+	if (!empty($modSettings['enableCompressedOutput'])) {
582
+			@ob_start('ob_gzhandler');
583
+	} else {
584
+			ob_start();
585
+	}
564 586
 
565 587
 	// Send the file headers
566 588
 	header('Pragma: ');
567 589
 	header('Cache-Control: no-cache');
568
-	if (!isBrowser('gecko'))
569
-		header('Content-Transfer-Encoding: binary');
590
+	if (!isBrowser('gecko')) {
591
+			header('Content-Transfer-Encoding: binary');
592
+	}
570 593
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
571 594
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT');
572 595
 	header('Accept-Ranges: bytes');
573 596
 	header('Connection: close');
574 597
 	header('Content-Disposition: attachment; filename="' . $event['title'] . '.ics"');
575
-	if (empty($modSettings['enableCompressedOutput']))
576
-		header('Content-Length: ' . $smcFunc['strlen']($filecontents));
598
+	if (empty($modSettings['enableCompressedOutput'])) {
599
+			header('Content-Length: ' . $smcFunc['strlen']($filecontents));
600
+	}
577 601
 
578 602
 	// This is a calendar item!
579 603
 	header('Content-Type: text/calendar');
@@ -612,20 +636,17 @@  discard block
 block discarded – undo
612 636
 		$context['sub_template'] = 'bcd';
613 637
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD');
614 638
 		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjI6ImgxIjthOjI6e2k6MDtpOjI7aToxO2k6MTt9czoyOiJoMiI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjI6Im0xIjthOjM6e2k6MDtpOjQ7aToxO2k6MjtpOjI7aToxO31zOjI6Im0yIjthOjQ6e2k6MDtpOjg7aToxO2k6NDtpOjI7aToyO2k6MztpOjE7fXM6MjoiczEiO2E6Mzp7aTowO2k6NDtpOjE7aToyO2k6MjtpOjE7fXM6MjoiczIiO2E6NDp7aTowO2k6ODtpOjE7aTo0O2k6MjtpOjI7aTozO2k6MTt9fQ=='));
615
-	}
616
-	elseif (!$omfg && !isset($_REQUEST['time']))
639
+	} elseif (!$omfg && !isset($_REQUEST['time']))
617 640
 	{
618 641
 		$context['sub_template'] = 'hms';
619 642
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary');
620 643
 		$context['clockicons'] = safe_unserialize(base64_decode('YTozOntzOjE6ImgiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czoxOiJtIjthOjY6e2k6MDtpOjMyO2k6MTtpOjE2O2k6MjtpOjg7aTozO2k6NDtpOjQ7aToyO2k6NTtpOjE7fXM6MToicyI7YTo2OntpOjA7aTozMjtpOjE7aToxNjtpOjI7aTo4O2k6MztpOjQ7aTo0O2k6MjtpOjU7aToxO319'));
621
-	}
622
-	elseif ($omfg)
644
+	} elseif ($omfg)
623 645
 	{
624 646
 		$context['sub_template'] = 'omfg';
625 647
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG');
626 648
 		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjQ6InllYXIiO2E6Nzp7aTowO2k6NjQ7aToxO2k6MzI7aToyO2k6MTY7aTozO2k6ODtpOjQ7aTo0O2k6NTtpOjI7aTo2O2k6MTt9czo1OiJtb250aCI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjM6ImRheSI7YTo1OntpOjA7aToxNjtpOjE7aTo4O2k6MjtpOjQ7aTozO2k6MjtpOjQ7aToxO31zOjQ6ImhvdXIiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czozOiJtaW4iO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9czozOiJzZWMiO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9fQ=='));
627
-	}
628
-	elseif (isset($_REQUEST['time']))
649
+	} elseif (isset($_REQUEST['time']))
629 650
 	{
630 651
 		$context['sub_template'] = 'thetime';
631 652
 		$time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']);
@@ -685,12 +706,13 @@  discard block
 block discarded – undo
685 706
 			),
686 707
 		);
687 708
 
688
-		foreach ($context['clockicons'] as $t => $vs)
689
-			foreach ($vs as $v => $dumb)
709
+		foreach ($context['clockicons'] as $t => $vs) {
710
+					foreach ($vs as $v => $dumb)
690 711
 			{
691 712
 				if ($$t >= $v)
692 713
 				{
693 714
 					$$t -= $v;
715
+		}
694 716
 					$context['clockicons'][$t][$v] = true;
695 717
 				}
696 718
 			}
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +230 added lines, -168 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query' => 'smf_db_query',
39 40
 			'db_quote' => 'smf_db_quote',
40 41
 			'db_fetch_assoc' => 'mysql_fetch_assoc',
@@ -58,36 +59,42 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource' => 'is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['port']))
63
-		$db_server .= ':' . $db_options['port'];
64
+	if (!empty($db_options['port'])) {
65
+			$db_server .= ':' . $db_options['port'];
66
+	}
64 67
 	
65 68
 	$flags = 2; //#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
66 69
 
67
-	if (!empty($db_options['persist']))
68
-		$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
69
-	else
70
-		$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
70
+	if (!empty($db_options['persist'])) {
71
+			$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
72
+	} else {
73
+			$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
74
+	}
71 75
 
72 76
 	// Something's wrong, show an error if its fatal (which we assume it is)
73 77
 	if (!$connection)
74 78
 	{
75
-		if (!empty($db_options['non_fatal']))
76
-			return null;
77
-		else
78
-			display_db_error();
79
+		if (!empty($db_options['non_fatal'])) {
80
+					return null;
81
+		} else {
82
+					display_db_error();
83
+		}
79 84
 	}
80 85
 
81 86
 	// Select the database, unless told not to
82
-	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal']))
83
-		display_db_error();
87
+	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) {
88
+			display_db_error();
89
+	}
84 90
 
85 91
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
86
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
87
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
92
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
93
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
88 94
 		array(),
89 95
 		false
90 96
 	);
97
+	}
91 98
 
92 99
 	return $connection;
93 100
 }
@@ -134,37 +141,46 @@  discard block
 block discarded – undo
134 141
 	list ($values, $connection) = $db_callback;
135 142
 
136 143
 	// Connection gone???  This should *never* happen at this point, yet it does :'(
137
-	if (!is_resource($connection))
138
-		display_db_error();
144
+	if (!is_resource($connection)) {
145
+			display_db_error();
146
+	}
139 147
 
140
-	if ($matches[1] === 'db_prefix')
141
-		return $db_prefix;
148
+	if ($matches[1] === 'db_prefix') {
149
+			return $db_prefix;
150
+	}
142 151
 
143
-	if ($matches[1] === 'query_see_board')
144
-		return $user_info['query_see_board'];
152
+	if ($matches[1] === 'query_see_board') {
153
+			return $user_info['query_see_board'];
154
+	}
145 155
 
146
-	if ($matches[1] === 'query_wanna_see_board')
147
-		return $user_info['query_wanna_see_board'];
156
+	if ($matches[1] === 'query_wanna_see_board') {
157
+			return $user_info['query_wanna_see_board'];
158
+	}
148 159
 
149
-	if ($matches[1] === 'empty')
150
-		return '\'\'';
160
+	if ($matches[1] === 'empty') {
161
+			return '\'\'';
162
+	}
151 163
 
152
-	if (!isset($matches[2]))
153
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
164
+	if (!isset($matches[2])) {
165
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
166
+	}
154 167
 
155
-	if ($matches[1] === 'literal')
156
-		return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
168
+	if ($matches[1] === 'literal') {
169
+			return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
170
+	}
157 171
 
158
-	if (!isset($values[$matches[2]]))
159
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
172
+	if (!isset($values[$matches[2]])) {
173
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
174
+	}
160 175
 
161 176
 	$replacement = $values[$matches[2]];
162 177
 
163 178
 	switch ($matches[1])
164 179
 	{
165 180
 		case 'int':
166
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
167
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
182
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+			}
168 184
 			return (string) (int) $replacement;
169 185
 		break;
170 186
 
@@ -176,56 +192,63 @@  discard block
 block discarded – undo
176 192
 		case 'array_int':
177 193
 			if (is_array($replacement))
178 194
 			{
179
-				if (empty($replacement))
180
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195
+				if (empty($replacement)) {
196
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
197
+				}
181 198
 
182 199
 				foreach ($replacement as $key => $value)
183 200
 				{
184
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
185
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
201
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
202
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
203
+					}
186 204
 
187 205
 					$replacement[$key] = (string) (int) $value;
188 206
 				}
189 207
 
190 208
 				return implode(', ', $replacement);
209
+			} else {
210
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
191 211
 			}
192
-			else
193
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
194 212
 
195 213
 		break;
196 214
 
197 215
 		case 'array_string':
198 216
 			if (is_array($replacement))
199 217
 			{
200
-				if (empty($replacement))
201
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+				if (empty($replacement)) {
219
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				}
202 221
 
203
-				foreach ($replacement as $key => $value)
204
-					$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
222
+				foreach ($replacement as $key => $value) {
223
+									$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
224
+				}
205 225
 
206 226
 				return implode(', ', $replacement);
227
+			} else {
228
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
207 229
 			}
208
-			else
209
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210 230
 		break;
211 231
 
212 232
 		case 'date':
213
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
214
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
-			else
216
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
234
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			}
217 238
 		break;
218 239
 
219 240
 		case 'time':
220
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
221
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
242
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
243
+			} else {
244
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+			}
224 246
 		break;
225 247
 
226 248
 		case 'float':
227
-			if (!is_numeric($replacement))
228
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+			if (!is_numeric($replacement)) {
250
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
251
+			}
229 252
 			return (string) (float) $replacement;
230 253
 		break;
231 254
 
@@ -239,32 +262,37 @@  discard block
 block discarded – undo
239 262
 		break;
240 263
 
241 264
 		case 'inet':
242
-			if ($replacement == 'null' || $replacement == '')
243
-				return 'null';
244
-			if (!isValidIP($replacement))
245
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			if ($replacement == 'null' || $replacement == '') {
266
+							return 'null';
267
+			}
268
+			if (!isValidIP($replacement)) {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
246 271
 			//we don't use the native support of mysql > 5.6.2
247 272
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
248 273
 
249 274
 		case 'array_inet':
250 275
 			if (is_array($replacement))
251 276
 			{
252
-				if (empty($replacement))
253
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+				if (empty($replacement)) {
278
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+				}
254 280
 
255 281
 				foreach ($replacement as $key => $value)
256 282
 				{
257
-					if ($replacement == 'null' || $replacement == '')
258
-						$replacement[$key] = 'null';
259
-					if (!isValidIP($value))
260
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
283
+					if ($replacement == 'null' || $replacement == '') {
284
+											$replacement[$key] = 'null';
285
+					}
286
+					if (!isValidIP($value)) {
287
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+					}
261 289
 					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
262 290
 				}
263 291
 
264 292
 				return implode(', ', $replacement);
293
+			} else {
294
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265 295
 			}
266
-			else
267
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268 296
 		break;
269 297
 
270 298
 		default:
@@ -335,18 +363,20 @@  discard block
 block discarded – undo
335 363
 	// One more query....
336 364
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
337 365
 
338
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
339
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
366
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
367
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
368
+	}
340 369
 
341 370
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
342 371
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
343 372
 	{
344 373
 		// Add before LIMIT
345
-		if ($pos = strpos($db_string, 'LIMIT '))
346
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
347
-		else
348
-			// Append it.
374
+		if ($pos = strpos($db_string, 'LIMIT ')) {
375
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
376
+		} else {
377
+					// Append it.
349 378
 			$db_string .= "\n\t\t\tORDER BY null";
379
+		}
350 380
 	}
351 381
 
352 382
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -368,8 +398,9 @@  discard block
 block discarded – undo
368 398
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
369 399
 
370 400
 		// Initialize $db_cache if not already initialized.
371
-		if (!isset($db_cache))
372
-			$db_cache = array();
401
+		if (!isset($db_cache)) {
402
+					$db_cache = array();
403
+		}
373 404
 
374 405
 		if (!empty($_SESSION['debug_redirect']))
375 406
 		{
@@ -395,17 +426,18 @@  discard block
 block discarded – undo
395 426
 		while (true)
396 427
 		{
397 428
 			$pos = strpos($db_string, '\'', $pos + 1);
398
-			if ($pos === false)
399
-				break;
429
+			if ($pos === false) {
430
+							break;
431
+			}
400 432
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
401 433
 
402 434
 			while (true)
403 435
 			{
404 436
 				$pos1 = strpos($db_string, '\'', $pos + 1);
405 437
 				$pos2 = strpos($db_string, '\\', $pos + 1);
406
-				if ($pos1 === false)
407
-					break;
408
-				elseif ($pos2 === false || $pos2 > $pos1)
438
+				if ($pos1 === false) {
439
+									break;
440
+				} elseif ($pos2 === false || $pos2 > $pos1)
409 441
 				{
410 442
 					$pos = $pos1;
411 443
 					break;
@@ -421,29 +453,35 @@  discard block
 block discarded – undo
421 453
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
422 454
 
423 455
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
424
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
425
-			$fail = true;
456
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
457
+					$fail = true;
458
+		}
426 459
 		// Trying to change passwords, slow us down, or something?
427
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
428
-			$fail = true;
429
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
430
-			$fail = true;
460
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
461
+					$fail = true;
462
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
463
+					$fail = true;
464
+		}
431 465
 
432
-		if (!empty($fail) && function_exists('log_error'))
433
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
466
+		if (!empty($fail) && function_exists('log_error')) {
467
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
468
+		}
434 469
 	}
435 470
 
436
-	if (empty($db_unbuffered))
437
-		$ret = @mysql_query($db_string, $connection);
438
-	else
439
-		$ret = @mysql_unbuffered_query($db_string, $connection);
471
+	if (empty($db_unbuffered)) {
472
+			$ret = @mysql_query($db_string, $connection);
473
+	} else {
474
+			$ret = @mysql_unbuffered_query($db_string, $connection);
475
+	}
440 476
 
441
-	if ($ret === false && empty($db_values['db_error_skip']))
442
-		$ret = smf_db_error($db_string, $connection);
477
+	if ($ret === false && empty($db_values['db_error_skip'])) {
478
+			$ret = smf_db_error($db_string, $connection);
479
+	}
443 480
 
444 481
 	// Debugging.
445
-	if (isset($db_show_debug) && $db_show_debug === true)
446
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
482
+	if (isset($db_show_debug) && $db_show_debug === true) {
483
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
484
+	}
447 485
 
448 486
 	return $ret;
449 487
 }
@@ -492,12 +530,13 @@  discard block
 block discarded – undo
492 530
 	// Decide which connection to use
493 531
 	$connection = $connection === null ? $db_connection : $connection;
494 532
 
495
-	if ($type == 'begin')
496
-		return @mysql_query('BEGIN', $connection);
497
-	elseif ($type == 'rollback')
498
-		return @mysql_query('ROLLBACK', $connection);
499
-	elseif ($type == 'commit')
500
-		return @mysql_query('COMMIT', $connection);
533
+	if ($type == 'begin') {
534
+			return @mysql_query('BEGIN', $connection);
535
+	} elseif ($type == 'rollback') {
536
+			return @mysql_query('ROLLBACK', $connection);
537
+	} elseif ($type == 'commit') {
538
+			return @mysql_query('COMMIT', $connection);
539
+	}
501 540
 
502 541
 	return false;
503 542
 }
@@ -537,8 +576,9 @@  discard block
 block discarded – undo
537 576
 	//    2013: Lost connection to server during query.
538 577
 
539 578
 	// Log the error.
540
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
541
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
579
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
580
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
581
+	}
542 582
 
543 583
 	// Database error auto fixing ;).
544 584
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -547,8 +587,9 @@  discard block
 block discarded – undo
547 587
 		$old_cache = @$modSettings['cache_enable'];
548 588
 		$modSettings['cache_enable'] = '1';
549 589
 
550
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
551
-			$db_last_error = max(@$db_last_error, $temp);
590
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
591
+					$db_last_error = max(@$db_last_error, $temp);
592
+		}
552 593
 
553 594
 		if (@$db_last_error < time() - 3600 * 24 * 3)
554 595
 		{
@@ -564,8 +605,9 @@  discard block
 block discarded – undo
564 605
 					foreach ($tables as $table)
565 606
 					{
566 607
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
567
-						if (trim($table) != '')
568
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
608
+						if (trim($table) != '') {
609
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
610
+						}
569 611
 					}
570 612
 				}
571 613
 
@@ -574,8 +616,9 @@  discard block
 block discarded – undo
574 616
 			// Table crashed.  Let's try to fix it.
575 617
 			elseif ($query_errno == 1016)
576 618
 			{
577
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
578
-					$fix_tables = array('`' . $match[1] . '`');
619
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
620
+									$fix_tables = array('`' . $match[1] . '`');
621
+				}
579 622
 			}
580 623
 			// Indexes crashed.  Should be easy to fix!
581 624
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -594,13 +637,15 @@  discard block
 block discarded – undo
594 637
 
595 638
 			// Make a note of the REPAIR...
596 639
 			cache_put_data('db_last_error', time(), 600);
597
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
598
-				updateSettingsFile(array('db_last_error' => time()));
640
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
641
+							updateSettingsFile(array('db_last_error' => time()));
642
+			}
599 643
 
600 644
 			// Attempt to find and repair the broken table.
601
-			foreach ($fix_tables as $table)
602
-				$smcFunc['db_query']('', "
645
+			foreach ($fix_tables as $table) {
646
+							$smcFunc['db_query']('', "
603 647
 					REPAIR TABLE $table", false, false);
648
+			}
604 649
 
605 650
 			// And send off an email!
606 651
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -609,11 +654,12 @@  discard block
 block discarded – undo
609 654
 
610 655
 			// Try the query again...?
611 656
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
612
-			if ($ret !== false)
613
-				return $ret;
657
+			if ($ret !== false) {
658
+							return $ret;
659
+			}
660
+		} else {
661
+					$modSettings['cache_enable'] = $old_cache;
614 662
 		}
615
-		else
616
-			$modSettings['cache_enable'] = $old_cache;
617 663
 
618 664
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
619 665
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -623,22 +669,25 @@  discard block
 block discarded – undo
623 669
 				// Are we in SSI mode?  If so try that username and password first
624 670
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
625 671
 				{
626
-					if (empty($db_persist))
627
-						$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
628
-					else
629
-						$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
672
+					if (empty($db_persist)) {
673
+											$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
674
+					} else {
675
+											$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
676
+					}
630 677
 				}
631 678
 				// Fall back to the regular username and password if need be
632 679
 				if (!$db_connection)
633 680
 				{
634
-					if (empty($db_persist))
635
-						$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
636
-					else
637
-						$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
681
+					if (empty($db_persist)) {
682
+											$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
683
+					} else {
684
+											$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
685
+					}
638 686
 				}
639 687
 
640
-				if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
641
-					$db_connection = false;
688
+				if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) {
689
+									$db_connection = false;
690
+				}
642 691
 			}
643 692
 
644 693
 			if ($db_connection)
@@ -649,24 +698,27 @@  discard block
 block discarded – undo
649 698
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
650 699
 
651 700
 					$new_errno = mysql_errno($db_connection);
652
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
653
-						break;
701
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
702
+											break;
703
+					}
654 704
 				}
655 705
 
656 706
 				// If it failed again, shucks to be you... we're not trying it over and over.
657
-				if ($ret !== false)
658
-					return $ret;
707
+				if ($ret !== false) {
708
+									return $ret;
709
+				}
659 710
 			}
660 711
 		}
661 712
 		// Are they out of space, perhaps?
662 713
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
663 714
 		{
664
-			if (!isset($txt))
665
-				$query_error .= ' - check database storage space.';
666
-			else
715
+			if (!isset($txt)) {
716
+							$query_error .= ' - check database storage space.';
717
+			} else
667 718
 			{
668
-				if (!isset($txt['mysql_error_space']))
669
-					loadLanguage('Errors');
719
+				if (!isset($txt['mysql_error_space'])) {
720
+									loadLanguage('Errors');
721
+				}
670 722
 
671 723
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
672 724
 			}
@@ -674,15 +726,17 @@  discard block
 block discarded – undo
674 726
 	}
675 727
 
676 728
 	// Nothing's defined yet... just die with it.
677
-	if (empty($context) || empty($txt))
678
-		die($query_error);
729
+	if (empty($context) || empty($txt)) {
730
+			die($query_error);
731
+	}
679 732
 
680 733
 	// Show an error message, if possible.
681 734
 	$context['error_title'] = $txt['database_error'];
682
-	if (allowedTo('admin_forum'))
683
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
684
-	else
685
-		$context['error_message'] = $txt['try_again'];
735
+	if (allowedTo('admin_forum')) {
736
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
737
+	} else {
738
+			$context['error_message'] = $txt['try_again'];
739
+	}
686 740
 
687 741
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
688 742
 	{
@@ -711,25 +765,28 @@  discard block
 block discarded – undo
711 765
 	$connection = $connection === null ? $db_connection : $connection;
712 766
 
713 767
 	// With nothing to insert, simply return.
714
-	if (empty($data))
715
-		return;
768
+	if (empty($data)) {
769
+			return;
770
+	}
716 771
 
717 772
 	// Replace the prefix holder with the actual prefix.
718 773
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
719 774
 
720 775
 	// Inserting data as a single row can be done as a single array.
721
-	if (!is_array($data[array_rand($data)]))
722
-		$data = array($data);
776
+	if (!is_array($data[array_rand($data)])) {
777
+			$data = array($data);
778
+	}
723 779
 
724 780
 	// Create the mold for a single row insert.
725 781
 	$insertData = '(';
726 782
 	foreach ($columns as $columnName => $type)
727 783
 	{
728 784
 		// Are we restricting the length?
729
-		if (strpos($type, 'string-') !== false)
730
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
731
-		else
732
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
785
+		if (strpos($type, 'string-') !== false) {
786
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
787
+		} else {
788
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
789
+		}
733 790
 	}
734 791
 	$insertData = substr($insertData, 0, -2) . ')';
735 792
 
@@ -738,8 +795,9 @@  discard block
 block discarded – undo
738 795
 
739 796
 	// Here's where the variables are injected to the query.
740 797
 	$insertRows = array();
741
-	foreach ($data as $dataRow)
742
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
798
+	foreach ($data as $dataRow) {
799
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
800
+	}
743 801
 
744 802
 	// Determine the method of insertion.
745 803
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -770,8 +828,9 @@  discard block
 block discarded – undo
770 828
  */
771 829
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
772 830
 {
773
-	if (empty($log_message))
774
-		$log_message = $error_message;
831
+	if (empty($log_message)) {
832
+			$log_message = $error_message;
833
+	}
775 834
 
776 835
 	foreach (debug_backtrace() as $step)
777 836
 	{
@@ -790,12 +849,14 @@  discard block
 block discarded – undo
790 849
 	}
791 850
 
792 851
 	// A special case - we want the file and line numbers for debugging.
793
-	if ($error_type == 'return')
794
-		return array($file, $line);
852
+	if ($error_type == 'return') {
853
+			return array($file, $line);
854
+	}
795 855
 
796 856
 	// Is always a critical error.
797
-	if (function_exists('log_error'))
798
-		log_error($log_message, 'critical', $file, $line);
857
+	if (function_exists('log_error')) {
858
+			log_error($log_message, 'critical', $file, $line);
859
+	}
799 860
 
800 861
 	if (function_exists('fatal_error'))
801 862
 	{
@@ -803,12 +864,12 @@  discard block
 block discarded – undo
803 864
 
804 865
 		// Cannot continue...
805 866
 		exit;
867
+	} elseif ($error_type) {
868
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
869
+	} else {
870
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
871
+	}
806 872
 	}
807
-	elseif ($error_type)
808
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
809
-	else
810
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
811
-}
812 873
 
813 874
 /**
814 875
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -825,10 +886,11 @@  discard block
 block discarded – undo
825 886
 		'\\' => '\\\\',
826 887
 	);
827 888
 
828
-	if ($translate_human_wildcards)
829
-		$replacements += array(
889
+	if ($translate_human_wildcards) {
890
+			$replacements += array(
830 891
 			'*' => '%',
831 892
 		);
893
+	}
832 894
 
833 895
 	return strtr($string, $replacements);
834 896
 }
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +798 added lines, -602 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,27 +48,35 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65
-		if (!is_array($modSettings['attachmentUploadDir']))
66
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
73
+		if (!is_array($modSettings['attachmentUploadDir'])) {
74
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
75
+		}
67 76
 
68
-		if (!empty($cache_enable))
69
-			cache_put_data('modSettings', $modSettings, 90);
77
+		if (!empty($cache_enable)) {
78
+					cache_put_data('modSettings', $modSettings, 90);
79
+		}
70 80
 	}
71 81
 
72 82
 	$modSettings['cache_enable'] = $cache_enable;
@@ -86,8 +96,9 @@  discard block
 block discarded – undo
86 96
 		};
87 97
 	$fix_utf8mb4 = function ($string) use ($utf8)
88 98
 	{
89
-		if (!$utf8)
90
-			return $string;
99
+		if (!$utf8) {
100
+					return $string;
101
+		}
91 102
 
92 103
 		$i = 0;
93 104
 		$len = strlen($string);
@@ -99,18 +110,15 @@  discard block
 block discarded – undo
99 110
 			{
100 111
 				$new_string .= $string[$i];
101 112
 				$i++;
102
-			}
103
-			elseif ($ord < 224)
113
+			} elseif ($ord < 224)
104 114
 			{
105 115
 				$new_string .= $string[$i] . $string[$i+1];
106 116
 				$i += 2;
107
-			}
108
-			elseif ($ord < 240)
117
+			} elseif ($ord < 240)
109 118
 			{
110 119
 				$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
111 120
 				$i += 3;
112
-			}
113
-			elseif ($ord < 248)
121
+			} elseif ($ord < 248)
114 122
 			{
115 123
 				// Magic happens.
116 124
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -154,8 +162,7 @@  discard block
 block discarded – undo
154 162
 			{
155 163
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
156 164
 				return is_int($result) ? $result + $offset : false;
157
-			}
158
-			else
165
+			} else
159 166
 			{
160 167
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
161 168
 				$needle_size = count($needle_arr);
@@ -164,8 +171,9 @@  discard block
 block discarded – undo
164 171
 				while ((int) $result === $result)
165 172
 				{
166 173
 					$offset += $result;
167
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
168
-						return $offset;
174
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
175
+											return $offset;
176
+					}
169 177
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
170 178
 				}
171 179
 				return false;
@@ -203,8 +211,9 @@  discard block
 block discarded – undo
203 211
 			$string = $ent_check($string);
204 212
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'.  ($utf8 ? 'u' : ''), $string, $matches);
205 213
 			$string = $matches[0];
206
-			while (strlen($string) > $length)
207
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
214
+			while (strlen($string) > $length) {
215
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
216
+			}
208 217
 			return $string;
209 218
 		},
210 219
 		'ucfirst' => $utf8 ? function ($string) use (&$smcFunc)
@@ -214,23 +223,25 @@  discard block
 block discarded – undo
214 223
 		'ucwords' => $utf8 ? function ($string) use (&$smcFunc)
215 224
 		{
216 225
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
217
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
218
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
226
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
227
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
228
+			}
219 229
 			return implode('', $words);
220 230
 		} : 'ucwords',
221 231
 	);
222 232
 
223 233
 	// Setting the timezone is a requirement for some functions.
224
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
225
-		date_default_timezone_set($modSettings['default_timezone']);
226
-	else
234
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
235
+			date_default_timezone_set($modSettings['default_timezone']);
236
+	} else
227 237
 	{
228 238
 		// Get PHP's default timezone, if set
229 239
 		$ini_tz = ini_get('date.timezone');
230
-		if (!empty($ini_tz))
231
-			$modSettings['default_timezone'] = $ini_tz;
232
-		else
233
-			$modSettings['default_timezone'] = '';
240
+		if (!empty($ini_tz)) {
241
+					$modSettings['default_timezone'] = $ini_tz;
242
+		} else {
243
+					$modSettings['default_timezone'] = '';
244
+		}
234 245
 
235 246
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
236 247
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -248,22 +259,26 @@  discard block
 block discarded – undo
248 259
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
249 260
 		{
250 261
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
251
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
252
-				$modSettings['load_average'] = (float) $matches[1];
253
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
254
-				$modSettings['load_average'] = (float) $matches[1];
255
-			else
256
-				unset($modSettings['load_average']);
262
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
263
+							$modSettings['load_average'] = (float) $matches[1];
264
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
265
+							$modSettings['load_average'] = (float) $matches[1];
266
+			} else {
267
+							unset($modSettings['load_average']);
268
+			}
257 269
 
258
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
259
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
270
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
271
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
272
+			}
260 273
 		}
261 274
 
262
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
263
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
275
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
276
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
277
+		}
264 278
 
265
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
266
-			display_loadavg_error();
279
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
280
+					display_loadavg_error();
281
+		}
267 282
 	}
268 283
 
269 284
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -284,8 +299,9 @@  discard block
 block discarded – undo
284 299
 	if (defined('SMF_INTEGRATION_SETTINGS'))
285 300
 	{
286 301
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
287
-		foreach ($integration_settings as $hook => $function)
288
-			add_integration_function($hook, $function, '', false);
302
+		foreach ($integration_settings as $hook => $function) {
303
+					add_integration_function($hook, $function, '', false);
304
+		}
289 305
 	}
290 306
 
291 307
 	// Any files to pre include?
@@ -295,8 +311,9 @@  discard block
 block discarded – undo
295 311
 		foreach ($pre_includes as $include)
296 312
 		{
297 313
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
298
-			if (file_exists($include))
299
-				require_once($include);
314
+			if (file_exists($include)) {
315
+							require_once($include);
316
+			}
300 317
 		}
301 318
 	}
302 319
 
@@ -400,27 +417,28 @@  discard block
 block discarded – undo
400 417
 				break;
401 418
 			}
402 419
 		}
420
+	} else {
421
+			$id_member = 0;
403 422
 	}
404
-	else
405
-		$id_member = 0;
406 423
 
407 424
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
408 425
 	{
409 426
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
410 427
 
411
-		if (empty($cookie_data))
412
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
428
+		if (empty($cookie_data)) {
429
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
430
+		}
413 431
 
414 432
 		list ($id_member, $password) = $cookie_data;
415 433
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
434
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 435
 	{
419 436
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 437
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
421 438
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
439
+		if (empty($cookie_data)) {
440
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
441
+		}
424 442
 
425 443
 		list ($id_member, $password, $login_span) = $cookie_data;
426 444
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +463,34 @@  discard block
 block discarded – undo
445 463
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 464
 			$smcFunc['db_free_result']($request);
447 465
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
449
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
466
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
467
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
468
+			}
450 469
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
470
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
471
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
472
+			}
453 473
 		}
454 474
 
455 475
 		// Did we find 'im?  If not, junk it.
456 476
 		if (!empty($user_settings))
457 477
 		{
458 478
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
479
+			if (!empty($already_verified) && $already_verified === true) {
480
+							$check = true;
481
+			}
461 482
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
483
+			elseif (strlen($password) == 128) {
484
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
485
+			} else {
486
+							$check = false;
487
+			}
466 488
 
467 489
 			// Wrong password or not activated - either way, you're going nowhere.
468 490
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
491
+		} else {
492
+					$id_member = 0;
469 493
 		}
470
-		else
471
-			$id_member = 0;
472 494
 
473 495
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 496
 		if (!$id_member)
@@ -490,13 +512,15 @@  discard block
 block discarded – undo
490 512
 				{
491 513
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
492 514
 
493
-					if (is_null($tfa_data))
494
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
515
+					if (is_null($tfa_data)) {
516
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
517
+					}
495 518
 
496 519
 					list ($tfamember, $tfasecret) = $tfa_data;
497 520
 
498
-					if ((int) $tfamember != $id_member)
499
-						$tfasecret = null;
521
+					if ((int) $tfamember != $id_member) {
522
+											$tfasecret = null;
523
+					}
500 524
 				}
501 525
 
502 526
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -516,10 +540,12 @@  discard block
 block discarded – undo
516 540
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
517 541
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
518 542
 		{
519
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
543
+			if ($modSettings['tfa_mode'] == 2) {
544
+				//only do this if we are just forcing SOME membergroups
520 545
 			{
521 546
 				//Build an array of ALL user membergroups.
522 547
 				$full_groups = array($user_settings['id_group']);
548
+			}
523 549
 				if (!empty($user_settings['additional_groups']))
524 550
 				{
525 551
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -539,15 +565,17 @@  discard block
 block discarded – undo
539 565
 				);
540 566
 				$row = $smcFunc['db_fetch_assoc']($request);
541 567
 				$smcFunc['db_free_result']($request);
568
+			} else {
569
+							$row['total'] = 1;
542 570
 			}
543
-			else
544
-				$row['total'] = 1; //simplifies logics in the next "if"
571
+			//simplifies logics in the next "if"
545 572
 
546 573
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
547 574
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
548 575
 
549
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
550
-				redirectexit('action=profile;area=tfasetup;forced');
576
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
577
+							redirectexit('action=profile;area=tfasetup;forced');
578
+			}
551 579
 		}
552 580
 	}
553 581
 
@@ -584,33 +612,37 @@  discard block
 block discarded – undo
584 612
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
585 613
 				$user_settings['last_login'] = time();
586 614
 
587
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
588
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
615
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
616
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
617
+				}
589 618
 
590
-				if (!empty($modSettings['cache_enable']))
591
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
619
+				if (!empty($modSettings['cache_enable'])) {
620
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
621
+				}
592 622
 			}
623
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
624
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
593 625
 		}
594
-		elseif (empty($_SESSION['id_msg_last_visit']))
595
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
596 626
 
597 627
 		$username = $user_settings['member_name'];
598 628
 
599
-		if (empty($user_settings['additional_groups']))
600
-			$user_info = array(
629
+		if (empty($user_settings['additional_groups'])) {
630
+					$user_info = array(
601 631
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
602 632
 			);
603
-		else
604
-			$user_info = array(
633
+		} else {
634
+					$user_info = array(
605 635
 				'groups' => array_merge(
606 636
 					array($user_settings['id_group'], $user_settings['id_post_group']),
607 637
 					explode(',', $user_settings['additional_groups'])
608 638
 				)
609 639
 			);
640
+		}
610 641
 
611 642
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
612
-		foreach ($user_info['groups'] as $k => $v)
613
-			$user_info['groups'][$k] = (int) $v;
643
+		foreach ($user_info['groups'] as $k => $v) {
644
+					$user_info['groups'][$k] = (int) $v;
645
+		}
614 646
 
615 647
 		// This is a logged in user, so definitely not a spider.
616 648
 		$user_info['possibly_robot'] = false;
@@ -624,8 +656,7 @@  discard block
 block discarded – undo
624 656
 			$time_system = new DateTime('now', $tz_system);
625 657
 			$time_user = new DateTime('now', $tz_user);
626 658
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
627
-		}
628
-		else
659
+		} else
629 660
 		{
630 661
 			// !!! Compatibility.
631 662
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset'];
@@ -639,16 +670,18 @@  discard block
 block discarded – undo
639 670
 		$user_info = array('groups' => array(-1));
640 671
 		$user_settings = array();
641 672
 
642
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
643
-			$_COOKIE[$cookiename] = '';
673
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
674
+					$_COOKIE[$cookiename] = '';
675
+		}
644 676
 
645 677
 		// Expire the 2FA cookie
646 678
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
647 679
 		{
648 680
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
649 681
 
650
-			if (is_null($tfa_data))
651
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
682
+			if (is_null($tfa_data)) {
683
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
684
+			}
652 685
 
653 686
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
654 687
 
@@ -660,19 +693,20 @@  discard block
 block discarded – undo
660 693
 		}
661 694
 
662 695
 		// Create a login token if it doesn't exist yet.
663
-		if (!isset($_SESSION['token']['post-login']))
664
-			createToken('login');
665
-		else
666
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
696
+		if (!isset($_SESSION['token']['post-login'])) {
697
+					createToken('login');
698
+		} else {
699
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
700
+		}
667 701
 
668 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
669 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
670 704
 		{
671 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
672 706
 			$user_info['possibly_robot'] = SpiderCheck();
707
+		} elseif (!empty($modSettings['spider_mode'])) {
708
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
673 709
 		}
674
-		elseif (!empty($modSettings['spider_mode']))
675
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
676 710
 		// If we haven't turned on proper spider hunts then have a guess!
677 711
 		else
678 712
 		{
@@ -720,8 +754,9 @@  discard block
 block discarded – undo
720 754
 	$user_info['groups'] = array_unique($user_info['groups']);
721 755
 
722 756
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
723
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
724
-		unset($user_info['ignoreboards'][$tmp]);
757
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
758
+			unset($user_info['ignoreboards'][$tmp]);
759
+	}
725 760
 
726 761
 	// Allow the user to change their language.
727 762
 	if (!empty($modSettings['userLanguage']))
@@ -734,31 +769,36 @@  discard block
 block discarded – undo
734 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
735 770
 
736 771
 			// Make it permanent for members.
737
-			if (!empty($user_info['id']))
738
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
739
-			else
740
-				$_SESSION['language'] = $user_info['language'];
772
+			if (!empty($user_info['id'])) {
773
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
774
+			} else {
775
+							$_SESSION['language'] = $user_info['language'];
776
+			}
777
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
778
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
741 779
 		}
742
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
743
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
744 780
 	}
745 781
 
746 782
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
747
-	if ($user_info['is_admin'])
748
-		$user_info['query_see_board'] = '1=1';
783
+	if ($user_info['is_admin']) {
784
+			$user_info['query_see_board'] = '1=1';
785
+	}
749 786
 	// Otherwise just the groups in $user_info['groups'].
750
-	else
751
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
787
+	else {
788
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
789
+	}
752 790
 
753 791
 	// Build the list of boards they WANT to see.
754 792
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
755 793
 
756 794
 	// If they aren't ignoring any boards then they want to see all the boards they can see
757
-	if (empty($user_info['ignoreboards']))
758
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
795
+	if (empty($user_info['ignoreboards'])) {
796
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
797
+	}
759 798
 	// Ok I guess they don't want to see all the boards
760
-	else
761
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
799
+	else {
800
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
801
+	}
762 802
 
763 803
 	call_integration_hook('integrate_user_info');
764 804
 }
@@ -816,9 +856,9 @@  discard block
 block discarded – undo
816 856
 		}
817 857
 
818 858
 		// Remember redirection is the key to avoiding fallout from your bosses.
819
-		if (!empty($topic))
820
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
821
-		else
859
+		if (!empty($topic)) {
860
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
861
+		} else
822 862
 		{
823 863
 			loadPermissions();
824 864
 			loadTheme();
@@ -836,10 +876,11 @@  discard block
 block discarded – undo
836 876
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
837 877
 	{
838 878
 		// @todo SLOW?
839
-		if (!empty($topic))
840
-			$temp = cache_get_data('topic_board-' . $topic, 120);
841
-		else
842
-			$temp = cache_get_data('board-' . $board, 120);
879
+		if (!empty($topic)) {
880
+					$temp = cache_get_data('topic_board-' . $topic, 120);
881
+		} else {
882
+					$temp = cache_get_data('board-' . $board, 120);
883
+		}
843 884
 
844 885
 		if (!empty($temp))
845 886
 		{
@@ -877,8 +918,9 @@  discard block
 block discarded – undo
877 918
 			$row = $smcFunc['db_fetch_assoc']($request);
878 919
 
879 920
 			// Set the current board.
880
-			if (!empty($row['id_board']))
881
-				$board = $row['id_board'];
921
+			if (!empty($row['id_board'])) {
922
+							$board = $row['id_board'];
923
+			}
882 924
 
883 925
 			// Basic operating information. (globals... :/)
884 926
 			$board_info = array(
@@ -914,21 +956,23 @@  discard block
 block discarded – undo
914 956
 
915 957
 			do
916 958
 			{
917
-				if (!empty($row['id_moderator']))
918
-					$board_info['moderators'][$row['id_moderator']] = array(
959
+				if (!empty($row['id_moderator'])) {
960
+									$board_info['moderators'][$row['id_moderator']] = array(
919 961
 						'id' => $row['id_moderator'],
920 962
 						'name' => $row['real_name'],
921 963
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
922 964
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
923 965
 					);
966
+				}
924 967
 
925
-				if (!empty($row['id_moderator_group']))
926
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
968
+				if (!empty($row['id_moderator_group'])) {
969
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
927 970
 						'id' => $row['id_moderator_group'],
928 971
 						'name' => $row['group_name'],
929 972
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
930 973
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
931 974
 					);
975
+				}
932 976
 			}
933 977
 			while ($row = $smcFunc['db_fetch_assoc']($request));
934 978
 
@@ -960,12 +1004,12 @@  discard block
 block discarded – undo
960 1004
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
961 1005
 			{
962 1006
 				// @todo SLOW?
963
-				if (!empty($topic))
964
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1007
+				if (!empty($topic)) {
1008
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1009
+				}
965 1010
 				cache_put_data('board-' . $board, $board_info, 120);
966 1011
 			}
967
-		}
968
-		else
1012
+		} else
969 1013
 		{
970 1014
 			// Otherwise the topic is invalid, there are no moderators, etc.
971 1015
 			$board_info = array(
@@ -979,8 +1023,9 @@  discard block
 block discarded – undo
979 1023
 		$smcFunc['db_free_result']($request);
980 1024
 	}
981 1025
 
982
-	if (!empty($topic))
983
-		$_GET['board'] = (int) $board;
1026
+	if (!empty($topic)) {
1027
+			$_GET['board'] = (int) $board;
1028
+	}
984 1029
 
985 1030
 	if (!empty($board))
986 1031
 	{
@@ -990,10 +1035,12 @@  discard block
 block discarded – undo
990 1035
 		// Now check if the user is a moderator.
991 1036
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
992 1037
 
993
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
995
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
996
-			$board_info['error'] = 'access';
1038
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1039
+					$board_info['error'] = 'access';
1040
+		}
1041
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1042
+					$board_info['error'] = 'access';
1043
+		}
997 1044
 
998 1045
 		// Build up the linktree.
999 1046
 		$context['linktree'] = array_merge(
@@ -1016,8 +1063,9 @@  discard block
 block discarded – undo
1016 1063
 	$context['current_board'] = $board;
1017 1064
 
1018 1065
 	// No posting in redirection boards!
1019
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1020
-		$board_info['error'] == 'post_in_redirect';
1066
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1067
+			$board_info['error'] == 'post_in_redirect';
1068
+	}
1021 1069
 
1022 1070
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1023 1071
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1043,24 +1091,23 @@  discard block
 block discarded – undo
1043 1091
 			ob_end_clean();
1044 1092
 			header('HTTP/1.1 403 Forbidden');
1045 1093
 			die;
1046
-		}
1047
-		elseif ($board_info['error'] == 'post_in_redirect')
1094
+		} elseif ($board_info['error'] == 'post_in_redirect')
1048 1095
 		{
1049 1096
 			// Slightly different error message here...
1050 1097
 			fatal_lang_error('cannot_post_redirect', false);
1051
-		}
1052
-		elseif ($user_info['is_guest'])
1098
+		} elseif ($user_info['is_guest'])
1053 1099
 		{
1054 1100
 			loadLanguage('Errors');
1055 1101
 			is_not_guest($txt['topic_gone']);
1102
+		} else {
1103
+					fatal_lang_error('topic_gone', false);
1056 1104
 		}
1057
-		else
1058
-			fatal_lang_error('topic_gone', false);
1059 1105
 	}
1060 1106
 
1061
-	if ($user_info['is_mod'])
1062
-		$user_info['groups'][] = 3;
1063
-}
1107
+	if ($user_info['is_mod']) {
1108
+			$user_info['groups'][] = 3;
1109
+	}
1110
+	}
1064 1111
 
1065 1112
 /**
1066 1113
  * Load this user's permissions.
@@ -1081,8 +1128,9 @@  discard block
 block discarded – undo
1081 1128
 		asort($cache_groups);
1082 1129
 		$cache_groups = implode(',', $cache_groups);
1083 1130
 		// If it's a spider then cache it different.
1084
-		if ($user_info['possibly_robot'])
1085
-			$cache_groups .= '-spider';
1131
+		if ($user_info['possibly_robot']) {
1132
+					$cache_groups .= '-spider';
1133
+		}
1086 1134
 
1087 1135
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1088 1136
 		{
@@ -1090,9 +1138,9 @@  discard block
 block discarded – undo
1090 1138
 			banPermissions();
1091 1139
 
1092 1140
 			return;
1141
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1142
+					list ($user_info['permissions'], $removals) = $temp;
1093 1143
 		}
1094
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1095
-			list ($user_info['permissions'], $removals) = $temp;
1096 1144
 	}
1097 1145
 
1098 1146
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1114,23 +1162,26 @@  discard block
 block discarded – undo
1114 1162
 		$removals = array();
1115 1163
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1116 1164
 		{
1117
-			if (empty($row['add_deny']))
1118
-				$removals[] = $row['permission'];
1119
-			else
1120
-				$user_info['permissions'][] = $row['permission'];
1165
+			if (empty($row['add_deny'])) {
1166
+							$removals[] = $row['permission'];
1167
+			} else {
1168
+							$user_info['permissions'][] = $row['permission'];
1169
+			}
1121 1170
 		}
1122 1171
 		$smcFunc['db_free_result']($request);
1123 1172
 
1124
-		if (isset($cache_groups))
1125
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1173
+		if (isset($cache_groups)) {
1174
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1175
+		}
1126 1176
 	}
1127 1177
 
1128 1178
 	// Get the board permissions.
1129 1179
 	if (!empty($board))
1130 1180
 	{
1131 1181
 		// Make sure the board (if any) has been loaded by loadBoard().
1132
-		if (!isset($board_info['profile']))
1133
-			fatal_lang_error('no_board');
1182
+		if (!isset($board_info['profile'])) {
1183
+					fatal_lang_error('no_board');
1184
+		}
1134 1185
 
1135 1186
 		$request = $smcFunc['db_query']('', '
1136 1187
 			SELECT permission, add_deny
@@ -1146,20 +1197,23 @@  discard block
 block discarded – undo
1146 1197
 		);
1147 1198
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1148 1199
 		{
1149
-			if (empty($row['add_deny']))
1150
-				$removals[] = $row['permission'];
1151
-			else
1152
-				$user_info['permissions'][] = $row['permission'];
1200
+			if (empty($row['add_deny'])) {
1201
+							$removals[] = $row['permission'];
1202
+			} else {
1203
+							$user_info['permissions'][] = $row['permission'];
1204
+			}
1153 1205
 		}
1154 1206
 		$smcFunc['db_free_result']($request);
1155 1207
 	}
1156 1208
 
1157 1209
 	// Remove all the permissions they shouldn't have ;).
1158
-	if (!empty($modSettings['permission_enable_deny']))
1159
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1210
+	if (!empty($modSettings['permission_enable_deny'])) {
1211
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1212
+	}
1160 1213
 
1161
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1162
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1214
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1215
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1216
+	}
1163 1217
 
1164 1218
 	// Banned?  Watch, don't touch..
1165 1219
 	banPermissions();
@@ -1171,17 +1225,18 @@  discard block
 block discarded – undo
1171 1225
 		{
1172 1226
 			require_once($sourcedir . '/Subs-Auth.php');
1173 1227
 			rebuildModCache();
1228
+		} else {
1229
+					$user_info['mod_cache'] = $_SESSION['mc'];
1174 1230
 		}
1175
-		else
1176
-			$user_info['mod_cache'] = $_SESSION['mc'];
1177 1231
 
1178 1232
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1179 1233
 		// For example this drastically simplifies certain changes to the profile area.
1180 1234
 		$user_info['permissions'][] = 'is_not_guest';
1181 1235
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1182 1236
 		$user_info['permissions'][] = 'profile_view_own';
1183
-		if (in_array('profile_view', $user_info['permissions']))
1184
-			$user_info['permissions'][] = 'profile_view_any';
1237
+		if (in_array('profile_view', $user_info['permissions'])) {
1238
+					$user_info['permissions'][] = 'profile_view_any';
1239
+		}
1185 1240
 	}
1186 1241
 }
1187 1242
 
@@ -1199,8 +1254,9 @@  discard block
 block discarded – undo
1199 1254
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1200 1255
 
1201 1256
 	// Can't just look for no users :P.
1202
-	if (empty($users))
1203
-		return array();
1257
+	if (empty($users)) {
1258
+			return array();
1259
+	}
1204 1260
 
1205 1261
 	// Pass the set value
1206 1262
 	$context['loadMemberContext_set'] = $set;
@@ -1215,8 +1271,9 @@  discard block
 block discarded – undo
1215 1271
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1216 1272
 		{
1217 1273
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1218
-			if ($data == null)
1219
-				continue;
1274
+			if ($data == null) {
1275
+							continue;
1276
+			}
1220 1277
 
1221 1278
 			$loaded_ids[] = $data['id_member'];
1222 1279
 			$user_profile[$data['id_member']] = $data;
@@ -1280,13 +1337,16 @@  discard block
 block discarded – undo
1280 1337
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1281 1338
 		{
1282 1339
 			// Take care of proxying avatar if required, do this here for maximum reach
1283
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1284
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1340
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1341
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1342
+			}
1285 1343
 
1286
-			if ( isset($row['member_ip']) )
1287
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1288
-			if ( isset($row['member_ip2']) )
1289
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1344
+			if ( isset($row['member_ip']) ) {
1345
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1346
+			}
1347
+			if ( isset($row['member_ip2']) ) {
1348
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1349
+			}
1290 1350
 			$new_loaded_ids[] = $row['id_member'];
1291 1351
 			$loaded_ids[] = $row['id_member'];
1292 1352
 			$row['options'] = array();
@@ -1305,8 +1365,9 @@  discard block
 block discarded – undo
1305 1365
 				'loaded_ids' => $new_loaded_ids,
1306 1366
 			)
1307 1367
 		);
1308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1309
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1368
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1369
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1370
+		}
1310 1371
 		$smcFunc['db_free_result']($request);
1311 1372
 	}
1312 1373
 
@@ -1317,10 +1378,11 @@  discard block
 block discarded – undo
1317 1378
 	{
1318 1379
 		foreach ($loaded_ids as $a_member)
1319 1380
 		{
1320
-			if (!empty($user_profile[$a_member]['additional_groups']))
1321
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1322
-			else
1323
-				$groups = array($user_profile[$a_member]['id_group']);
1381
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1382
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1383
+			} else {
1384
+							$groups = array($user_profile[$a_member]['id_group']);
1385
+			}
1324 1386
 
1325 1387
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1326 1388
 
@@ -1333,8 +1395,9 @@  discard block
 block discarded – undo
1333 1395
 
1334 1396
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1335 1397
 	{
1336
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1337
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1398
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1399
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1400
+		}
1338 1401
 	}
1339 1402
 
1340 1403
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1360,14 +1423,17 @@  discard block
 block discarded – undo
1360 1423
 		foreach ($temp_mods as $id)
1361 1424
 		{
1362 1425
 			// By popular demand, don't show admins or global moderators as moderators.
1363
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1364
-				$user_profile[$id]['member_group'] = $row['member_group'];
1426
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1427
+							$user_profile[$id]['member_group'] = $row['member_group'];
1428
+			}
1365 1429
 
1366 1430
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1367
-			if (!empty($row['icons']))
1368
-				$user_profile[$id]['icons'] = $row['icons'];
1369
-			if (!empty($row['member_group_color']))
1370
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1431
+			if (!empty($row['icons'])) {
1432
+							$user_profile[$id]['icons'] = $row['icons'];
1433
+			}
1434
+			if (!empty($row['member_group_color'])) {
1435
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1436
+			}
1371 1437
 		}
1372 1438
 	}
1373 1439
 
@@ -1389,12 +1455,14 @@  discard block
 block discarded – undo
1389 1455
 	static $loadedLanguages = array();
1390 1456
 
1391 1457
 	// If this person's data is already loaded, skip it.
1392
-	if (isset($dataLoaded[$user]))
1393
-		return true;
1458
+	if (isset($dataLoaded[$user])) {
1459
+			return true;
1460
+	}
1394 1461
 
1395 1462
 	// We can't load guests or members not loaded by loadMemberData()!
1396
-	if ($user == 0)
1397
-		return false;
1463
+	if ($user == 0) {
1464
+			return false;
1465
+	}
1398 1466
 	if (!isset($user_profile[$user]))
1399 1467
 	{
1400 1468
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1420,12 +1488,16 @@  discard block
 block discarded – undo
1420 1488
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1421 1489
 
1422 1490
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1423
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1491
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1492
+		//icon is set and exists
1424 1493
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1425
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1494
+	} elseif (isset($profile['icons'][1])) {
1495
+		//icon is set and doesn't exist, fallback to default
1426 1496
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1427
-	else //not set, bye bye
1497
+	} else {
1498
+		//not set, bye bye
1428 1499
 		$group_icon_url = '';
1500
+	}
1429 1501
 
1430 1502
 	// These minimal values are always loaded
1431 1503
 	$memberContext[$user] = array(
@@ -1444,8 +1516,9 @@  discard block
 block discarded – undo
1444 1516
 	if ($context['loadMemberContext_set'] != 'minimal')
1445 1517
 	{
1446 1518
 		// Go the extra mile and load the user's native language name.
1447
-		if (empty($loadedLanguages))
1448
-			$loadedLanguages = getLanguages();
1519
+		if (empty($loadedLanguages)) {
1520
+					$loadedLanguages = getLanguages();
1521
+		}
1449 1522
 
1450 1523
 		$memberContext[$user] += array(
1451 1524
 			'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>',
@@ -1499,31 +1572,33 @@  discard block
 block discarded – undo
1499 1572
 	{
1500 1573
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1501 1574
 		{
1502
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1503
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1504
-			else
1505
-				$image = get_gravatar_url($profile['email_address']);
1506
-		}
1507
-		else
1575
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1576
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1577
+			} else {
1578
+							$image = get_gravatar_url($profile['email_address']);
1579
+			}
1580
+		} else
1508 1581
 		{
1509 1582
 			// So it's stored in the member table?
1510 1583
 			if (!empty($profile['avatar']))
1511 1584
 			{
1512 1585
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1586
+			} elseif (!empty($profile['filename'])) {
1587
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1513 1588
 			}
1514
-			elseif (!empty($profile['filename']))
1515
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1516 1589
 			// Right... no avatar...use the default one
1517
-			else
1518
-				$image = $modSettings['avatar_url'] . '/default.png';
1590
+			else {
1591
+							$image = $modSettings['avatar_url'] . '/default.png';
1592
+			}
1519 1593
 		}
1520
-		if (!empty($image))
1521
-			$memberContext[$user]['avatar'] = array(
1594
+		if (!empty($image)) {
1595
+					$memberContext[$user]['avatar'] = array(
1522 1596
 				'name' => $profile['avatar'],
1523 1597
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">',
1524 1598
 				'href' => $image,
1525 1599
 				'url' => $image,
1526 1600
 			);
1601
+		}
1527 1602
 	}
1528 1603
 
1529 1604
 	// Are we also loading the members custom fields into context?
@@ -1531,35 +1606,41 @@  discard block
 block discarded – undo
1531 1606
 	{
1532 1607
 		$memberContext[$user]['custom_fields'] = array();
1533 1608
 
1534
-		if (!isset($context['display_fields']))
1535
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1609
+		if (!isset($context['display_fields'])) {
1610
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1611
+		}
1536 1612
 
1537 1613
 		foreach ($context['display_fields'] as $custom)
1538 1614
 		{
1539
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1540
-				continue;
1615
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1616
+							continue;
1617
+			}
1541 1618
 
1542 1619
 			$value = $profile['options'][$custom['col_name']];
1543 1620
 
1544 1621
 			// Don't show the "disabled" option for the "gender" field.
1545
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1546
-				continue;
1622
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1623
+							continue;
1624
+			}
1547 1625
 
1548 1626
 			// BBC?
1549
-			if ($custom['bbc'])
1550
-				$value = parse_bbc($value);
1627
+			if ($custom['bbc']) {
1628
+							$value = parse_bbc($value);
1629
+			}
1551 1630
 			// ... or checkbox?
1552
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1553
-				$value = $value ? $txt['yes'] : $txt['no'];
1631
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1632
+							$value = $value ? $txt['yes'] : $txt['no'];
1633
+			}
1554 1634
 
1555 1635
 			// Enclosing the user input within some other text?
1556
-			if (!empty($custom['enclose']))
1557
-				$value = strtr($custom['enclose'], array(
1636
+			if (!empty($custom['enclose'])) {
1637
+							$value = strtr($custom['enclose'], array(
1558 1638
 					'{SCRIPTURL}' => $scripturl,
1559 1639
 					'{IMAGES_URL}' => $settings['images_url'],
1560 1640
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1561 1641
 					'{INPUT}' => $value,
1562 1642
 				));
1643
+			}
1563 1644
 
1564 1645
 			$memberContext[$user]['custom_fields'][] = array(
1565 1646
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1586,8 +1667,9 @@  discard block
 block discarded – undo
1586 1667
 	global $smcFunc, $txt, $scripturl, $settings;
1587 1668
 
1588 1669
 	// Do not waste my time...
1589
-	if (empty($users) || empty($params))
1590
-		return false;
1670
+	if (empty($users) || empty($params)) {
1671
+			return false;
1672
+	}
1591 1673
 
1592 1674
 	// Make sure it's an array.
1593 1675
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1611,31 +1693,36 @@  discard block
 block discarded – undo
1611 1693
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1612 1694
 	{
1613 1695
 		// BBC?
1614
-		if (!empty($row['bbc']))
1615
-			$row['value'] = parse_bbc($row['value']);
1696
+		if (!empty($row['bbc'])) {
1697
+					$row['value'] = parse_bbc($row['value']);
1698
+		}
1616 1699
 
1617 1700
 		// ... or checkbox?
1618
-		elseif (isset($row['type']) && $row['type'] == 'check')
1619
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1701
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1702
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1703
+		}
1620 1704
 
1621 1705
 		// Enclosing the user input within some other text?
1622
-		if (!empty($row['enclose']))
1623
-			$row['value'] = strtr($row['enclose'], array(
1706
+		if (!empty($row['enclose'])) {
1707
+					$row['value'] = strtr($row['enclose'], array(
1624 1708
 				'{SCRIPTURL}' => $scripturl,
1625 1709
 				'{IMAGES_URL}' => $settings['images_url'],
1626 1710
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1627 1711
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1628 1712
 			));
1713
+		}
1629 1714
 
1630 1715
 		// Send a simple array if there is just 1 param
1631
-		if (count($params) == 1)
1632
-			$return[$row['id_member']] = $row;
1716
+		if (count($params) == 1) {
1717
+					$return[$row['id_member']] = $row;
1718
+		}
1633 1719
 
1634 1720
 		// More than 1? knock yourself out...
1635 1721
 		else
1636 1722
 		{
1637
-			if (!isset($return[$row['id_member']]))
1638
-				$return[$row['id_member']] = array();
1723
+			if (!isset($return[$row['id_member']])) {
1724
+							$return[$row['id_member']] = array();
1725
+			}
1639 1726
 
1640 1727
 			$return[$row['id_member']][$row['variable']] = $row;
1641 1728
 		}
@@ -1669,8 +1756,9 @@  discard block
 block discarded – undo
1669 1756
 	global $context;
1670 1757
 
1671 1758
 	// Don't know any browser!
1672
-	if (empty($context['browser']))
1673
-		detectBrowser();
1759
+	if (empty($context['browser'])) {
1760
+			detectBrowser();
1761
+	}
1674 1762
 
1675 1763
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1676 1764
 }
@@ -1688,8 +1776,9 @@  discard block
 block discarded – undo
1688 1776
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1689 1777
 
1690 1778
 	// The theme was specified by parameter.
1691
-	if (!empty($id_theme))
1692
-		$id_theme = (int) $id_theme;
1779
+	if (!empty($id_theme)) {
1780
+			$id_theme = (int) $id_theme;
1781
+	}
1693 1782
 	// The theme was specified by REQUEST.
1694 1783
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1695 1784
 	{
@@ -1697,51 +1786,58 @@  discard block
 block discarded – undo
1697 1786
 		$_SESSION['id_theme'] = $id_theme;
1698 1787
 	}
1699 1788
 	// The theme was specified by REQUEST... previously.
1700
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1701
-		$id_theme = (int) $_SESSION['id_theme'];
1789
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1790
+			$id_theme = (int) $_SESSION['id_theme'];
1791
+	}
1702 1792
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1703
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1704
-		$id_theme = $user_info['theme'];
1793
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1794
+			$id_theme = $user_info['theme'];
1795
+	}
1705 1796
 	// The theme was specified by the board.
1706
-	elseif (!empty($board_info['theme']))
1707
-		$id_theme = $board_info['theme'];
1797
+	elseif (!empty($board_info['theme'])) {
1798
+			$id_theme = $board_info['theme'];
1799
+	}
1708 1800
 	// The theme is the forum's default.
1709
-	else
1710
-		$id_theme = $modSettings['theme_guests'];
1801
+	else {
1802
+			$id_theme = $modSettings['theme_guests'];
1803
+	}
1711 1804
 
1712 1805
 	// Verify the id_theme... no foul play.
1713 1806
 	// Always allow the board specific theme, if they are overriding.
1714
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1715
-		$id_theme = $board_info['theme'];
1807
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1808
+			$id_theme = $board_info['theme'];
1809
+	}
1716 1810
 	// If they have specified a particular theme to use with SSI allow it to be used.
1717
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1718
-		$id_theme = (int) $id_theme;
1719
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1811
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1812
+			$id_theme = (int) $id_theme;
1813
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1720 1814
 	{
1721 1815
 		$themes = explode(',', $modSettings['enableThemes']);
1722
-		if (!in_array($id_theme, $themes))
1723
-			$id_theme = $modSettings['theme_guests'];
1724
-		else
1816
+		if (!in_array($id_theme, $themes)) {
1817
+					$id_theme = $modSettings['theme_guests'];
1818
+		} else {
1819
+					$id_theme = (int) $id_theme;
1820
+		}
1821
+	} else {
1725 1822
 			$id_theme = (int) $id_theme;
1726 1823
 	}
1727
-	else
1728
-		$id_theme = (int) $id_theme;
1729 1824
 
1730 1825
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1731 1826
 
1732 1827
 	// Disable image proxy if we don't have SSL enabled
1733
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1734
-		$image_proxy_enabled = false;
1828
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1829
+			$image_proxy_enabled = false;
1830
+	}
1735 1831
 
1736 1832
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1737 1833
 	{
1738 1834
 		$themeData = $temp;
1739 1835
 		$flag = true;
1836
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1837
+			$themeData = $temp + array($member => array());
1838
+	} else {
1839
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1740 1840
 	}
1741
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1742
-		$themeData = $temp + array($member => array());
1743
-	else
1744
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1745 1841
 
1746 1842
 	if (empty($flag))
1747 1843
 	{
@@ -1760,31 +1856,37 @@  discard block
 block discarded – undo
1760 1856
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1761 1857
 		{
1762 1858
 			// There are just things we shouldn't be able to change as members.
1763
-			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1764
-				continue;
1859
+			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1860
+							continue;
1861
+			}
1765 1862
 
1766 1863
 			// If this is the theme_dir of the default theme, store it.
1767
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1768
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1864
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1865
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1866
+			}
1769 1867
 
1770 1868
 			// If this isn't set yet, is a theme option, or is not the default theme..
1771
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1772
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1869
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1870
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1871
+			}
1773 1872
 		}
1774 1873
 		$smcFunc['db_free_result']($result);
1775 1874
 
1776
-		if (!empty($themeData[-1]))
1777
-			foreach ($themeData[-1] as $k => $v)
1875
+		if (!empty($themeData[-1])) {
1876
+					foreach ($themeData[-1] as $k => $v)
1778 1877
 			{
1779 1878
 				if (!isset($themeData[$member][$k]))
1780 1879
 					$themeData[$member][$k] = $v;
1880
+		}
1781 1881
 			}
1782 1882
 
1783
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1784
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1883
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1884
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1885
+		}
1785 1886
 		// Only if we didn't already load that part of the cache...
1786
-		elseif (!isset($temp))
1787
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1887
+		elseif (!isset($temp)) {
1888
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1889
+		}
1788 1890
 	}
1789 1891
 
1790 1892
 	$settings = $themeData[0];
@@ -1801,20 +1903,24 @@  discard block
 block discarded – undo
1801 1903
 	$settings['template_dirs'][] = $settings['theme_dir'];
1802 1904
 
1803 1905
 	// Based on theme (if there is one).
1804
-	if (!empty($settings['base_theme_dir']))
1805
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1906
+	if (!empty($settings['base_theme_dir'])) {
1907
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1908
+	}
1806 1909
 
1807 1910
 	// Lastly the default theme.
1808
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1809
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1911
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1912
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1913
+	}
1810 1914
 
1811
-	if (!$initialize)
1812
-		return;
1915
+	if (!$initialize) {
1916
+			return;
1917
+	}
1813 1918
 
1814 1919
 	// Check to see if we're forcing SSL
1815 1920
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1816
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1817
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1921
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1922
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1923
+	}
1818 1924
 
1819 1925
 	// Check to see if they're accessing it from the wrong place.
1820 1926
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1822,8 +1928,9 @@  discard block
 block discarded – undo
1822 1928
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1823 1929
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1824 1930
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1825
-		if ($temp != '/')
1826
-			$detected_url .= $temp;
1931
+		if ($temp != '/') {
1932
+					$detected_url .= $temp;
1933
+		}
1827 1934
 	}
1828 1935
 	if (isset($detected_url) && $detected_url != $boardurl)
1829 1936
 	{
@@ -1835,8 +1942,9 @@  discard block
 block discarded – undo
1835 1942
 			foreach ($aliases as $alias)
1836 1943
 			{
1837 1944
 				// Rip off all the boring parts, spaces, etc.
1838
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1839
-					$do_fix = true;
1945
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1946
+									$do_fix = true;
1947
+				}
1840 1948
 			}
1841 1949
 		}
1842 1950
 
@@ -1844,20 +1952,22 @@  discard block
 block discarded – undo
1844 1952
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1845 1953
 		{
1846 1954
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1847
-			if (empty($_GET))
1848
-				redirectexit('wwwRedirect');
1849
-			else
1955
+			if (empty($_GET)) {
1956
+							redirectexit('wwwRedirect');
1957
+			} else
1850 1958
 			{
1851 1959
 				list ($k, $v) = each($_GET);
1852 1960
 
1853
-				if ($k != 'wwwRedirect')
1854
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1961
+				if ($k != 'wwwRedirect') {
1962
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1963
+				}
1855 1964
 			}
1856 1965
 		}
1857 1966
 
1858 1967
 		// #3 is just a check for SSL...
1859
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1860
-			$do_fix = true;
1968
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1969
+					$do_fix = true;
1970
+		}
1861 1971
 
1862 1972
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1863 1973
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1891,8 +2001,9 @@  discard block
 block discarded – undo
1891 2001
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1892 2002
 				}
1893 2003
 			}
1894
-			foreach ($context['linktree'] as $k => $dummy)
1895
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2004
+			foreach ($context['linktree'] as $k => $dummy) {
2005
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2006
+			}
1896 2007
 		}
1897 2008
 	}
1898 2009
 	// Set up the contextual user array.
@@ -1911,16 +2022,16 @@  discard block
 block discarded – undo
1911 2022
 			'email' => $user_info['email'],
1912 2023
 			'ignoreusers' => $user_info['ignoreusers'],
1913 2024
 		);
1914
-		if (!$context['user']['is_guest'])
1915
-			$context['user']['name'] = $user_info['name'];
1916
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1917
-			$context['user']['name'] = $txt['guest_title'];
2025
+		if (!$context['user']['is_guest']) {
2026
+					$context['user']['name'] = $user_info['name'];
2027
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2028
+					$context['user']['name'] = $txt['guest_title'];
2029
+		}
1918 2030
 
1919 2031
 		// Determine the current smiley set.
1920 2032
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1921 2033
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1922
-	}
1923
-	else
2034
+	} else
1924 2035
 	{
1925 2036
 		$context['user'] = array(
1926 2037
 			'id' => -1,
@@ -1936,18 +2047,24 @@  discard block
 block discarded – undo
1936 2047
 	}
1937 2048
 
1938 2049
 	// Some basic information...
1939
-	if (!isset($context['html_headers']))
1940
-		$context['html_headers'] = '';
1941
-	if (!isset($context['javascript_files']))
1942
-		$context['javascript_files'] = array();
1943
-	if (!isset($context['css_files']))
1944
-		$context['css_files'] = array();
1945
-	if (!isset($context['css_header']))
1946
-		$context['css_header'] = array();
1947
-	if (!isset($context['javascript_inline']))
1948
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1949
-	if (!isset($context['javascript_vars']))
1950
-		$context['javascript_vars'] = array();
2050
+	if (!isset($context['html_headers'])) {
2051
+			$context['html_headers'] = '';
2052
+	}
2053
+	if (!isset($context['javascript_files'])) {
2054
+			$context['javascript_files'] = array();
2055
+	}
2056
+	if (!isset($context['css_files'])) {
2057
+			$context['css_files'] = array();
2058
+	}
2059
+	if (!isset($context['css_header'])) {
2060
+			$context['css_header'] = array();
2061
+	}
2062
+	if (!isset($context['javascript_inline'])) {
2063
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2064
+	}
2065
+	if (!isset($context['javascript_vars'])) {
2066
+			$context['javascript_vars'] = array();
2067
+	}
1951 2068
 
1952 2069
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1953 2070
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1959,8 +2076,9 @@  discard block
 block discarded – undo
1959 2076
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1960 2077
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1961 2078
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1962
-	if (isset($modSettings['load_average']))
1963
-		$context['load_average'] = $modSettings['load_average'];
2079
+	if (isset($modSettings['load_average'])) {
2080
+			$context['load_average'] = $modSettings['load_average'];
2081
+	}
1964 2082
 
1965 2083
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1966 2084
 	detectBrowser();
@@ -1974,8 +2092,9 @@  discard block
 block discarded – undo
1974 2092
 	// This allows sticking some HTML on the page output - useful for controls.
1975 2093
 	$context['insert_after_template'] = '';
1976 2094
 
1977
-	if (!isset($txt))
1978
-		$txt = array();
2095
+	if (!isset($txt)) {
2096
+			$txt = array();
2097
+	}
1979 2098
 
1980 2099
 	$simpleActions = array(
1981 2100
 		'findmember',
@@ -2021,9 +2140,10 @@  discard block
 block discarded – undo
2021 2140
 
2022 2141
 	// See if theres any extra param to check.
2023 2142
 	$requiresXML = false;
2024
-	foreach ($extraParams as $key => $extra)
2025
-		if (isset($_REQUEST[$extra]))
2143
+	foreach ($extraParams as $key => $extra) {
2144
+			if (isset($_REQUEST[$extra]))
2026 2145
 			$requiresXML = true;
2146
+	}
2027 2147
 
2028 2148
 	// Output is fully XML, so no need for the index template.
2029 2149
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2038,37 +2158,39 @@  discard block
 block discarded – undo
2038 2158
 	{
2039 2159
 		loadLanguage('index+Modifications');
2040 2160
 		$context['template_layers'] = array();
2041
-	}
2042
-
2043
-	else
2161
+	} else
2044 2162
 	{
2045 2163
 		// Custom templates to load, or just default?
2046
-		if (isset($settings['theme_templates']))
2047
-			$templates = explode(',', $settings['theme_templates']);
2048
-		else
2049
-			$templates = array('index');
2164
+		if (isset($settings['theme_templates'])) {
2165
+					$templates = explode(',', $settings['theme_templates']);
2166
+		} else {
2167
+					$templates = array('index');
2168
+		}
2050 2169
 
2051 2170
 		// Load each template...
2052
-		foreach ($templates as $template)
2053
-			loadTemplate($template);
2171
+		foreach ($templates as $template) {
2172
+					loadTemplate($template);
2173
+		}
2054 2174
 
2055 2175
 		// ...and attempt to load their associated language files.
2056 2176
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2057 2177
 		loadLanguage($required_files, '', false);
2058 2178
 
2059 2179
 		// Custom template layers?
2060
-		if (isset($settings['theme_layers']))
2061
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2062
-		else
2063
-			$context['template_layers'] = array('html', 'body');
2180
+		if (isset($settings['theme_layers'])) {
2181
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2182
+		} else {
2183
+					$context['template_layers'] = array('html', 'body');
2184
+		}
2064 2185
 	}
2065 2186
 
2066 2187
 	// Initialize the theme.
2067 2188
 	loadSubTemplate('init', 'ignore');
2068 2189
 
2069 2190
 	// Allow overriding the board wide time/number formats.
2070
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2071
-		$user_info['time_format'] = $txt['time_format'];
2191
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2192
+			$user_info['time_format'] = $txt['time_format'];
2193
+	}
2072 2194
 
2073 2195
 	// Set the character set from the template.
2074 2196
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2076,12 +2198,14 @@  discard block
 block discarded – undo
2076 2198
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2077 2199
 
2078 2200
 	// Guests may still need a name.
2079
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2080
-		$context['user']['name'] = $txt['guest_title'];
2201
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2202
+			$context['user']['name'] = $txt['guest_title'];
2203
+	}
2081 2204
 
2082 2205
 	// Any theme-related strings that need to be loaded?
2083
-	if (!empty($settings['require_theme_strings']))
2084
-		loadLanguage('ThemeStrings', '', false);
2206
+	if (!empty($settings['require_theme_strings'])) {
2207
+			loadLanguage('ThemeStrings', '', false);
2208
+	}
2085 2209
 
2086 2210
 	// Make a special URL for the language.
2087 2211
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2092,8 +2216,9 @@  discard block
 block discarded – undo
2092 2216
 	// Here is my luvly Responsive CSS
2093 2217
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2094 2218
 
2095
-	if ($context['right_to_left'])
2096
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2219
+	if ($context['right_to_left']) {
2220
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2221
+	}
2097 2222
 
2098 2223
 	// We allow theme variants, because we're cool.
2099 2224
 	$context['theme_variant'] = '';
@@ -2101,14 +2226,17 @@  discard block
 block discarded – undo
2101 2226
 	if (!empty($settings['theme_variants']))
2102 2227
 	{
2103 2228
 		// Overriding - for previews and that ilk.
2104
-		if (!empty($_REQUEST['variant']))
2105
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2229
+		if (!empty($_REQUEST['variant'])) {
2230
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2231
+		}
2106 2232
 		// User selection?
2107
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2108
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2233
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2234
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2235
+		}
2109 2236
 		// If not a user variant, select the default.
2110
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2111
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2237
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2238
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2239
+		}
2112 2240
 
2113 2241
 		// Do this to keep things easier in the templates.
2114 2242
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2117,20 +2245,23 @@  discard block
 block discarded – undo
2117 2245
 		if (!empty($context['theme_variant']))
2118 2246
 		{
2119 2247
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2120
-			if ($context['right_to_left'])
2121
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2248
+			if ($context['right_to_left']) {
2249
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2250
+			}
2122 2251
 		}
2123 2252
 	}
2124 2253
 
2125 2254
 	// Let's be compatible with old themes!
2126
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2127
-		$context['template_layers'] = array('main');
2255
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2256
+			$context['template_layers'] = array('main');
2257
+	}
2128 2258
 
2129 2259
 	$context['tabindex'] = 1;
2130 2260
 
2131 2261
 	// Compatibility.
2132
-	if (!isset($settings['theme_version']))
2133
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2262
+	if (!isset($settings['theme_version'])) {
2263
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2264
+	}
2134 2265
 
2135 2266
 	// Default JS variables for use in every theme
2136 2267
 	$context['javascript_vars'] = array(
@@ -2149,18 +2280,18 @@  discard block
 block discarded – undo
2149 2280
 	);
2150 2281
 
2151 2282
 	// Add the JQuery library to the list of files to load.
2152
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2153
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2154
-
2155
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2156
-		loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2157
-
2158
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2159
-		loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2283
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2284
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2285
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2286
+			loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2287
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2288
+			loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2289
+	}
2160 2290
 
2161 2291
 	// Auto loading? template_javascript() will take care of the local half of this.
2162
-	else
2163
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2292
+	else {
2293
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2294
+	}
2164 2295
 
2165 2296
 	// Queue our JQuery plugins!
2166 2297
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2183,12 +2314,12 @@  discard block
 block discarded – undo
2183 2314
 			require_once($sourcedir . '/ScheduledTasks.php');
2184 2315
 
2185 2316
 			// What to do, what to do?!
2186
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2187
-				AutoTask();
2188
-			else
2189
-				ReduceMailQueue();
2190
-		}
2191
-		else
2317
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2318
+							AutoTask();
2319
+			} else {
2320
+							ReduceMailQueue();
2321
+			}
2322
+		} else
2192 2323
 		{
2193 2324
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2194 2325
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2239,8 +2370,9 @@  discard block
 block discarded – undo
2239 2370
 		foreach ($theme_includes as $include)
2240 2371
 		{
2241 2372
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2242
-			if (file_exists($include))
2243
-				require_once($include);
2373
+			if (file_exists($include)) {
2374
+							require_once($include);
2375
+			}
2244 2376
 		}
2245 2377
 	}
2246 2378
 
@@ -2270,16 +2402,19 @@  discard block
 block discarded – undo
2270 2402
 	// Do any style sheets first, cause we're easy with those.
2271 2403
 	if (!empty($style_sheets))
2272 2404
 	{
2273
-		if (!is_array($style_sheets))
2274
-			$style_sheets = array($style_sheets);
2405
+		if (!is_array($style_sheets)) {
2406
+					$style_sheets = array($style_sheets);
2407
+		}
2275 2408
 
2276
-		foreach ($style_sheets as $sheet)
2277
-			loadCSSFile($sheet . '.css', array(), $sheet);
2409
+		foreach ($style_sheets as $sheet) {
2410
+					loadCSSFile($sheet . '.css', array(), $sheet);
2411
+		}
2278 2412
 	}
2279 2413
 
2280 2414
 	// No template to load?
2281
-	if ($template_name === false)
2282
-		return true;
2415
+	if ($template_name === false) {
2416
+			return true;
2417
+	}
2283 2418
 
2284 2419
 	$loaded = false;
2285 2420
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2294,12 +2429,14 @@  discard block
 block discarded – undo
2294 2429
 
2295 2430
 	if ($loaded)
2296 2431
 	{
2297
-		if ($db_show_debug === true)
2298
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2432
+		if ($db_show_debug === true) {
2433
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2434
+		}
2299 2435
 
2300 2436
 		// If they have specified an initialization function for this template, go ahead and call it now.
2301
-		if (function_exists('template_' . $template_name . '_init'))
2302
-			call_user_func('template_' . $template_name . '_init');
2437
+		if (function_exists('template_' . $template_name . '_init')) {
2438
+					call_user_func('template_' . $template_name . '_init');
2439
+		}
2303 2440
 	}
2304 2441
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2305 2442
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2319,13 +2456,14 @@  discard block
 block discarded – undo
2319 2456
 		loadTemplate($template_name);
2320 2457
 	}
2321 2458
 	// Cause an error otherwise.
2322
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2323
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2324
-	elseif ($fatal)
2325
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2326
-	else
2327
-		return false;
2328
-}
2459
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2460
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2461
+	} elseif ($fatal) {
2462
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2463
+	} else {
2464
+			return false;
2465
+	}
2466
+	}
2329 2467
 
2330 2468
 /**
2331 2469
  * Load a sub-template.
@@ -2343,17 +2481,19 @@  discard block
 block discarded – undo
2343 2481
 {
2344 2482
 	global $context, $txt, $db_show_debug;
2345 2483
 
2346
-	if ($db_show_debug === true)
2347
-		$context['debug']['sub_templates'][] = $sub_template_name;
2484
+	if ($db_show_debug === true) {
2485
+			$context['debug']['sub_templates'][] = $sub_template_name;
2486
+	}
2348 2487
 
2349 2488
 	// Figure out what the template function is named.
2350 2489
 	$theme_function = 'template_' . $sub_template_name;
2351
-	if (function_exists($theme_function))
2352
-		$theme_function();
2353
-	elseif ($fatal === false)
2354
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2355
-	elseif ($fatal !== 'ignore')
2356
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2490
+	if (function_exists($theme_function)) {
2491
+			$theme_function();
2492
+	} elseif ($fatal === false) {
2493
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2494
+	} elseif ($fatal !== 'ignore') {
2495
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2496
+	}
2357 2497
 
2358 2498
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2359 2499
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2390,8 +2530,9 @@  discard block
 block discarded – undo
2390 2530
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2391 2531
 
2392 2532
 	// If this is an external file, automatically set this to false.
2393
-	if (!empty($params['external']))
2394
-		$params['minimize'] = false;
2533
+	if (!empty($params['external'])) {
2534
+			$params['minimize'] = false;
2535
+	}
2395 2536
 
2396 2537
 	// Account for shorthand like admin.css?alp21 filenames
2397 2538
 	$has_seed = strpos($fileName, '.css?');
@@ -2408,13 +2549,10 @@  discard block
 block discarded – undo
2408 2549
 			{
2409 2550
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2410 2551
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2552
+			} else {
2553
+							$fileUrl = false;
2411 2554
 			}
2412
-
2413
-			else
2414
-				$fileUrl = false;
2415
-		}
2416
-
2417
-		else
2555
+		} else
2418 2556
 		{
2419 2557
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2420 2558
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2429,12 +2567,14 @@  discard block
 block discarded – undo
2429 2567
 	}
2430 2568
 
2431 2569
 	// Add it to the array for use in the template
2432
-	if (!empty($fileName))
2433
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2570
+	if (!empty($fileName)) {
2571
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2572
+	}
2434 2573
 
2435
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2436
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2437
-}
2574
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2575
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2576
+	}
2577
+	}
2438 2578
 
2439 2579
 /**
2440 2580
  * Add a block of inline css code to be executed later
@@ -2451,8 +2591,9 @@  discard block
 block discarded – undo
2451 2591
 	global $context;
2452 2592
 
2453 2593
 	// Gotta add something...
2454
-	if (empty($css))
2455
-		return false;
2594
+	if (empty($css)) {
2595
+			return false;
2596
+	}
2456 2597
 
2457 2598
 	$context['css_header'][] = $css;
2458 2599
 }
@@ -2487,8 +2628,9 @@  discard block
 block discarded – undo
2487 2628
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2488 2629
 
2489 2630
 	// If this is an external file, automatically set this to false.
2490
-	if (!empty($params['external']))
2491
-		$params['minimize'] = false;
2631
+	if (!empty($params['external'])) {
2632
+			$params['minimize'] = false;
2633
+	}
2492 2634
 
2493 2635
 	// Account for shorthand like admin.js?alp21 filenames
2494 2636
 	$has_seed = strpos($fileName, '.js?');
@@ -2505,16 +2647,12 @@  discard block
 block discarded – undo
2505 2647
 			{
2506 2648
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2507 2649
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2508
-			}
2509
-
2510
-			else
2650
+			} else
2511 2651
 			{
2512 2652
 				$fileUrl = false;
2513 2653
 				$filePath = false;
2514 2654
 			}
2515
-		}
2516
-
2517
-		else
2655
+		} else
2518 2656
 		{
2519 2657
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2520 2658
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2529,9 +2667,10 @@  discard block
 block discarded – undo
2529 2667
 	}
2530 2668
 
2531 2669
 	// Add it to the array for use in the template
2532
-	if (!empty($fileName))
2533
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2534
-}
2670
+	if (!empty($fileName)) {
2671
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2672
+	}
2673
+	}
2535 2674
 
2536 2675
 /**
2537 2676
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2545,9 +2684,10 @@  discard block
 block discarded – undo
2545 2684
 {
2546 2685
 	global $context;
2547 2686
 
2548
-	if (!empty($key) && (!empty($value) || $value === '0'))
2549
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2550
-}
2687
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2688
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2689
+	}
2690
+	}
2551 2691
 
2552 2692
 /**
2553 2693
  * Add a block of inline Javascript code to be executed later
@@ -2564,8 +2704,9 @@  discard block
 block discarded – undo
2564 2704
 {
2565 2705
 	global $context;
2566 2706
 
2567
-	if (empty($javascript))
2568
-		return false;
2707
+	if (empty($javascript)) {
2708
+			return false;
2709
+	}
2569 2710
 
2570 2711
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2571 2712
 }
@@ -2586,15 +2727,18 @@  discard block
 block discarded – undo
2586 2727
 	static $already_loaded = array();
2587 2728
 
2588 2729
 	// Default to the user's language.
2589
-	if ($lang == '')
2590
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2730
+	if ($lang == '') {
2731
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2732
+	}
2591 2733
 
2592 2734
 	// Do we want the English version of language file as fallback?
2593
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2594
-		loadLanguage($template_name, 'english', false);
2735
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2736
+			loadLanguage($template_name, 'english', false);
2737
+	}
2595 2738
 
2596
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2597
-		return $lang;
2739
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2740
+			return $lang;
2741
+	}
2598 2742
 
2599 2743
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2600 2744
 	if (empty($settings['default_theme_dir']))
@@ -2605,8 +2749,9 @@  discard block
 block discarded – undo
2605 2749
 
2606 2750
 	// What theme are we in?
2607 2751
 	$theme_name = basename($settings['theme_url']);
2608
-	if (empty($theme_name))
2609
-		$theme_name = 'unknown';
2752
+	if (empty($theme_name)) {
2753
+			$theme_name = 'unknown';
2754
+	}
2610 2755
 
2611 2756
 	// For each file open it up and write it out!
2612 2757
 	foreach (explode('+', $template_name) as $template)
@@ -2685,8 +2830,9 @@  discard block
 block discarded – undo
2685 2830
 	}
2686 2831
 
2687 2832
 	// Keep track of what we're up to soldier.
2688
-	if ($db_show_debug === true)
2689
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2833
+	if ($db_show_debug === true) {
2834
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2835
+	}
2690 2836
 
2691 2837
 	// Remember what we have loaded, and in which language.
2692 2838
 	$already_loaded[$template_name] = $lang;
@@ -2732,8 +2878,9 @@  discard block
 block discarded – undo
2732 2878
 				)
2733 2879
 			);
2734 2880
 			// In the EXTREMELY unlikely event this happens, give an error message.
2735
-			if ($smcFunc['db_num_rows']($result) == 0)
2736
-				fatal_lang_error('parent_not_found', 'critical');
2881
+			if ($smcFunc['db_num_rows']($result) == 0) {
2882
+							fatal_lang_error('parent_not_found', 'critical');
2883
+			}
2737 2884
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2738 2885
 			{
2739 2886
 				if (!isset($boards[$row['id_board']]))
@@ -2750,8 +2897,8 @@  discard block
 block discarded – undo
2750 2897
 					);
2751 2898
 				}
2752 2899
 				// If a moderator exists for this board, add that moderator for all children too.
2753
-				if (!empty($row['id_moderator']))
2754
-					foreach ($boards as $id => $dummy)
2900
+				if (!empty($row['id_moderator'])) {
2901
+									foreach ($boards as $id => $dummy)
2755 2902
 					{
2756 2903
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2757 2904
 							'id' => $row['id_moderator'],
@@ -2759,11 +2906,12 @@  discard block
 block discarded – undo
2759 2906
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2760 2907
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2761 2908
 						);
2909
+				}
2762 2910
 					}
2763 2911
 
2764 2912
 				// If a moderator group exists for this board, add that moderator group for all children too
2765
-				if (!empty($row['id_moderator_group']))
2766
-					foreach ($boards as $id => $dummy)
2913
+				if (!empty($row['id_moderator_group'])) {
2914
+									foreach ($boards as $id => $dummy)
2767 2915
 					{
2768 2916
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2769 2917
 							'id' => $row['id_moderator_group'],
@@ -2771,6 +2919,7 @@  discard block
 block discarded – undo
2771 2919
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2772 2920
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2773 2921
 						);
2922
+				}
2774 2923
 					}
2775 2924
 			}
2776 2925
 			$smcFunc['db_free_result']($result);
@@ -2798,23 +2947,27 @@  discard block
 block discarded – undo
2798 2947
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2799 2948
 	{
2800 2949
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2801
-		if (empty($smcFunc['ucwords']))
2802
-			reloadSettings();
2950
+		if (empty($smcFunc['ucwords'])) {
2951
+					reloadSettings();
2952
+		}
2803 2953
 
2804 2954
 		// If we don't have our theme information yet, let's get it.
2805
-		if (empty($settings['default_theme_dir']))
2806
-			loadTheme(0, false);
2955
+		if (empty($settings['default_theme_dir'])) {
2956
+					loadTheme(0, false);
2957
+		}
2807 2958
 
2808 2959
 		// Default language directories to try.
2809 2960
 		$language_directories = array(
2810 2961
 			$settings['default_theme_dir'] . '/languages',
2811 2962
 		);
2812
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2813
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2963
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2964
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2965
+		}
2814 2966
 
2815 2967
 		// We possibly have a base theme directory.
2816
-		if (!empty($settings['base_theme_dir']))
2817
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2968
+		if (!empty($settings['base_theme_dir'])) {
2969
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2970
+		}
2818 2971
 
2819 2972
 		// Remove any duplicates.
2820 2973
 		$language_directories = array_unique($language_directories);
@@ -2828,20 +2981,21 @@  discard block
 block discarded – undo
2828 2981
 		foreach ($language_directories as $language_dir)
2829 2982
 		{
2830 2983
 			// Can't look in here... doesn't exist!
2831
-			if (!file_exists($language_dir))
2832
-				continue;
2984
+			if (!file_exists($language_dir)) {
2985
+							continue;
2986
+			}
2833 2987
 
2834 2988
 			$dir = dir($language_dir);
2835 2989
 			while ($entry = $dir->read())
2836 2990
 			{
2837 2991
 				// Look for the index language file....
2838
-				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches))
2839
-					continue;
2840
-
2841
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2842
-					$langName = $langList[$matches[1]];
2992
+				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) {
2993
+									continue;
2994
+				}
2843 2995
 
2844
-				else
2996
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
2997
+									$langName = $langList[$matches[1]];
2998
+				} else
2845 2999
 				{
2846 3000
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2847 3001
 
@@ -2884,20 +3038,23 @@  discard block
 block discarded – undo
2884 3038
 		}
2885 3039
 
2886 3040
 		// Do we need to store the lang list?
2887
-		if (empty($langList))
2888
-			updateSettings(array('langList' => json_encode($catchLang)));
3041
+		if (empty($langList)) {
3042
+					updateSettings(array('langList' => json_encode($catchLang)));
3043
+		}
2889 3044
 
2890 3045
 		// Favoring UTF8? Then prevent us from selecting non-UTF8 versions.
2891 3046
 		if ($favor_utf8)
2892 3047
 		{
2893
-			foreach ($context['languages'] as $lang)
2894
-				if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
3048
+			foreach ($context['languages'] as $lang) {
3049
+							if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2895 3050
 					unset($context['languages'][$lang['filename']]);
3051
+			}
2896 3052
 		}
2897 3053
 
2898 3054
 		// Let's cash in on this deal.
2899
-		if (!empty($modSettings['cache_enable']))
2900
-			cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3055
+		if (!empty($modSettings['cache_enable'])) {
3056
+					cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3057
+		}
2901 3058
 	}
2902 3059
 
2903 3060
 	return $context['languages'];
@@ -2920,8 +3077,9 @@  discard block
 block discarded – undo
2920 3077
 	global $modSettings, $options, $txt;
2921 3078
 	static $censor_vulgar = null, $censor_proper;
2922 3079
 
2923
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2924
-		return $text;
3080
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3081
+			return $text;
3082
+	}
2925 3083
 
2926 3084
 	// If they haven't yet been loaded, load them.
2927 3085
 	if ($censor_vulgar == null)
@@ -2949,9 +3107,9 @@  discard block
 block discarded – undo
2949 3107
 	{
2950 3108
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2951 3109
 		$text = $func($censor_vulgar, $censor_proper, $text);
3110
+	} else {
3111
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2952 3112
 	}
2953
-	else
2954
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2955 3113
 
2956 3114
 	return $text;
2957 3115
 }
@@ -2977,38 +3135,42 @@  discard block
 block discarded – undo
2977 3135
 	@ini_set('track_errors', '1');
2978 3136
 
2979 3137
 	// Don't include the file more than once, if $once is true.
2980
-	if ($once && in_array($filename, $templates))
2981
-		return;
3138
+	if ($once && in_array($filename, $templates)) {
3139
+			return;
3140
+	}
2982 3141
 	// Add this file to the include list, whether $once is true or not.
2983
-	else
2984
-		$templates[] = $filename;
3142
+	else {
3143
+			$templates[] = $filename;
3144
+	}
2985 3145
 
2986 3146
 	// Are we going to use eval?
2987 3147
 	if (empty($modSettings['disableTemplateEval']))
2988 3148
 	{
2989 3149
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2990 3150
 		$settings['current_include_filename'] = $filename;
2991
-	}
2992
-	else
3151
+	} else
2993 3152
 	{
2994 3153
 		$file_found = file_exists($filename);
2995 3154
 
2996
-		if ($once && $file_found)
2997
-			require_once($filename);
2998
-		elseif ($file_found)
2999
-			require($filename);
3155
+		if ($once && $file_found) {
3156
+					require_once($filename);
3157
+		} elseif ($file_found) {
3158
+					require($filename);
3159
+		}
3000 3160
 	}
3001 3161
 
3002 3162
 	if ($file_found !== true)
3003 3163
 	{
3004 3164
 		ob_end_clean();
3005
-		if (!empty($modSettings['enableCompressedOutput']))
3006
-			@ob_start('ob_gzhandler');
3007
-		else
3008
-			ob_start();
3165
+		if (!empty($modSettings['enableCompressedOutput'])) {
3166
+					@ob_start('ob_gzhandler');
3167
+		} else {
3168
+					ob_start();
3169
+		}
3009 3170
 
3010
-		if (isset($_GET['debug']))
3011
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3171
+		if (isset($_GET['debug'])) {
3172
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3173
+		}
3012 3174
 
3013 3175
 		// Don't cache error pages!!
3014 3176
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3027,12 +3189,13 @@  discard block
 block discarded – undo
3027 3189
 		echo '<!DOCTYPE html>
3028 3190
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3029 3191
 	<head>';
3030
-		if (isset($context['character_set']))
3031
-			echo '
3192
+		if (isset($context['character_set'])) {
3193
+					echo '
3032 3194
 		<meta charset="', $context['character_set'], '">';
3195
+		}
3033 3196
 
3034
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3035
-			echo '
3197
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3198
+					echo '
3036 3199
 		<title>', $mtitle, '</title>
3037 3200
 	</head>
3038 3201
 	<body>
@@ -3040,8 +3203,8 @@  discard block
 block discarded – undo
3040 3203
 		', $mmessage, '
3041 3204
 	</body>
3042 3205
 </html>';
3043
-		elseif (!allowedTo('admin_forum'))
3044
-			echo '
3206
+		} elseif (!allowedTo('admin_forum')) {
3207
+					echo '
3045 3208
 		<title>', $txt['template_parse_error'], '</title>
3046 3209
 	</head>
3047 3210
 	<body>
@@ -3049,15 +3212,17 @@  discard block
 block discarded – undo
3049 3212
 		', $txt['template_parse_error_message'], '
3050 3213
 	</body>
3051 3214
 </html>';
3052
-		else
3215
+		} else
3053 3216
 		{
3054 3217
 			require_once($sourcedir . '/Subs-Package.php');
3055 3218
 
3056 3219
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3057
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3058
-				$error = $php_errormsg;
3059
-			if (empty($error))
3060
-				$error = $txt['template_parse_errmsg'];
3220
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3221
+							$error = $php_errormsg;
3222
+			}
3223
+			if (empty($error)) {
3224
+							$error = $txt['template_parse_errmsg'];
3225
+			}
3061 3226
 
3062 3227
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3063 3228
 
@@ -3068,11 +3233,12 @@  discard block
 block discarded – undo
3068 3233
 		<h3>', $txt['template_parse_error'], '</h3>
3069 3234
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3070 3235
 
3071
-			if (!empty($error))
3072
-				echo '
3236
+			if (!empty($error)) {
3237
+							echo '
3073 3238
 		<hr>
3074 3239
 
3075 3240
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3241
+			}
3076 3242
 
3077 3243
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3078 3244
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3082,10 +3248,11 @@  discard block
 block discarded – undo
3082 3248
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3083 3249
 
3084 3250
 				// Fix the PHP code stuff...
3085
-				if (!isBrowser('gecko'))
3086
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3087
-				else
3088
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3251
+				if (!isBrowser('gecko')) {
3252
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3253
+				} else {
3254
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3255
+				}
3089 3256
 
3090 3257
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3091 3258
 				$j = -1;
@@ -3093,8 +3260,9 @@  discard block
 block discarded – undo
3093 3260
 				{
3094 3261
 					$j++;
3095 3262
 
3096
-					if (substr_count($line, '<br>') == 0)
3097
-						continue;
3263
+					if (substr_count($line, '<br>') == 0) {
3264
+											continue;
3265
+					}
3098 3266
 
3099 3267
 					$n = substr_count($line, '<br>');
3100 3268
 					for ($i = 0; $i < $n; $i++)
@@ -3113,38 +3281,42 @@  discard block
 block discarded – undo
3113 3281
 				// Figure out what the color coding was before...
3114 3282
 				$line = max($match[1] - 9, 1);
3115 3283
 				$last_line = '';
3116
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3117
-					if (strpos($data2[$line2], '<') !== false)
3284
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3285
+									if (strpos($data2[$line2], '<') !== false)
3118 3286
 					{
3119 3287
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3120 3288
 							$last_line = $color_match[1];
3289
+				}
3121 3290
 						break;
3122 3291
 					}
3123 3292
 
3124 3293
 				// Show the relevant lines...
3125 3294
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3126 3295
 				{
3127
-					if ($line == $match[1])
3128
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3296
+					if ($line == $match[1]) {
3297
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3298
+					}
3129 3299
 
3130 3300
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3131
-					if (isset($data2[$line]) && $data2[$line] != '')
3132
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3301
+					if (isset($data2[$line]) && $data2[$line] != '') {
3302
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3303
+					}
3133 3304
 
3134 3305
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3135 3306
 					{
3136 3307
 						$last_line = $color_match[1];
3137 3308
 						echo '</', substr($last_line, 1, 4), '>';
3309
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3310
+											$last_line = '';
3311
+					} elseif ($last_line != '' && $data2[$line] != '') {
3312
+											echo '</', substr($last_line, 1, 4), '>';
3138 3313
 					}
3139
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3140
-						$last_line = '';
3141
-					elseif ($last_line != '' && $data2[$line] != '')
3142
-						echo '</', substr($last_line, 1, 4), '>';
3143 3314
 
3144
-					if ($line == $match[1])
3145
-						echo '</pre></div><pre style="margin: 0;">';
3146
-					else
3147
-						echo "\n";
3315
+					if ($line == $match[1]) {
3316
+											echo '</pre></div><pre style="margin: 0;">';
3317
+					} else {
3318
+											echo "\n";
3319
+					}
3148 3320
 				}
3149 3321
 
3150 3322
 				echo '</pre></div>';
@@ -3168,8 +3340,9 @@  discard block
 block discarded – undo
3168 3340
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3169 3341
 
3170 3342
 	// Figure out what type of database we are using.
3171
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3172
-		$db_type = 'mysql';
3343
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3344
+			$db_type = 'mysql';
3345
+	}
3173 3346
 
3174 3347
 	// Load the file for the database.
3175 3348
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3177,8 +3350,9 @@  discard block
 block discarded – undo
3177 3350
 	$db_options = array();
3178 3351
 
3179 3352
 	// Add in the port if needed
3180
-	if (!empty($db_port))
3181
-		$db_options['port'] = $db_port;
3353
+	if (!empty($db_port)) {
3354
+			$db_options['port'] = $db_port;
3355
+	}
3182 3356
 
3183 3357
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3184 3358
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3197,13 +3371,15 @@  discard block
 block discarded – undo
3197 3371
 	}
3198 3372
 
3199 3373
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3200
-	if (!$db_connection)
3201
-		display_db_error();
3374
+	if (!$db_connection) {
3375
+			display_db_error();
3376
+	}
3202 3377
 
3203 3378
 	// If in SSI mode fix up the prefix.
3204
-	if (SMF == 'SSI')
3205
-		db_fix_prefix($db_prefix, $db_name);
3206
-}
3379
+	if (SMF == 'SSI') {
3380
+			db_fix_prefix($db_prefix, $db_name);
3381
+	}
3382
+	}
3207 3383
 
3208 3384
 /**
3209 3385
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3217,10 +3393,11 @@  discard block
 block discarded – undo
3217 3393
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3218 3394
 
3219 3395
 	// Not overriding this and we have a cacheAPI, send it back.
3220
-	if (empty($overrideCache) && is_object($cacheAPI))
3221
-		return $cacheAPI;
3222
-	elseif (is_null($cacheAPI))
3223
-		$cacheAPI = false;
3396
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3397
+			return $cacheAPI;
3398
+	} elseif (is_null($cacheAPI)) {
3399
+			$cacheAPI = false;
3400
+	}
3224 3401
 
3225 3402
 	// Make sure our class is in session.
3226 3403
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3241,8 +3418,9 @@  discard block
 block discarded – undo
3241 3418
 		if (!$testAPI->isSupported())
3242 3419
 		{
3243 3420
 			// Can we save ourselves?
3244
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3245
-				return loadCacheAccelerator(null, false);
3421
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3422
+							return loadCacheAccelerator(null, false);
3423
+			}
3246 3424
 			return false;
3247 3425
 		}
3248 3426
 
@@ -3254,9 +3432,9 @@  discard block
 block discarded – undo
3254 3432
 		{
3255 3433
 			$cacheAPI = $testAPI;
3256 3434
 			return $cacheAPI;
3435
+		} else {
3436
+					return $testAPI;
3257 3437
 		}
3258
-		else
3259
-			return $testAPI;
3260 3438
 	}
3261 3439
 }
3262 3440
 
@@ -3276,8 +3454,9 @@  discard block
 block discarded – undo
3276 3454
 
3277 3455
 	// @todo Why are we doing this if caching is disabled?
3278 3456
 
3279
-	if (function_exists('call_integration_hook'))
3280
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3457
+	if (function_exists('call_integration_hook')) {
3458
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3459
+	}
3281 3460
 
3282 3461
 	/* Refresh the cache if either:
3283 3462
 		1. Caching is disabled.
@@ -3291,16 +3470,19 @@  discard block
 block discarded – undo
3291 3470
 		require_once($sourcedir . '/' . $file);
3292 3471
 		$cache_block = call_user_func_array($function, $params);
3293 3472
 
3294
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3295
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3473
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3474
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3475
+		}
3296 3476
 	}
3297 3477
 
3298 3478
 	// Some cached data may need a freshening up after retrieval.
3299
-	if (!empty($cache_block['post_retri_eval']))
3300
-		eval($cache_block['post_retri_eval']);
3479
+	if (!empty($cache_block['post_retri_eval'])) {
3480
+			eval($cache_block['post_retri_eval']);
3481
+	}
3301 3482
 
3302
-	if (function_exists('call_integration_hook'))
3303
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3483
+	if (function_exists('call_integration_hook')) {
3484
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3485
+	}
3304 3486
 
3305 3487
 	return $cache_block['data'];
3306 3488
 }
@@ -3327,8 +3509,9 @@  discard block
 block discarded – undo
3327 3509
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3328 3510
 	global $cache_hits, $cache_count, $db_show_debug;
3329 3511
 
3330
-	if (empty($cache_enable) || empty($cacheAPI))
3331
-		return;
3512
+	if (empty($cache_enable) || empty($cacheAPI)) {
3513
+			return;
3514
+	}
3332 3515
 
3333 3516
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3334 3517
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3341,12 +3524,14 @@  discard block
 block discarded – undo
3341 3524
 	$value = $value === null ? null : json_encode($value);
3342 3525
 	$cacheAPI->putData($key, $value, $ttl);
3343 3526
 
3344
-	if (function_exists('call_integration_hook'))
3345
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3527
+	if (function_exists('call_integration_hook')) {
3528
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3529
+	}
3346 3530
 
3347
-	if (isset($db_show_debug) && $db_show_debug === true)
3348
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3349
-}
3531
+	if (isset($db_show_debug) && $db_show_debug === true) {
3532
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3533
+	}
3534
+	}
3350 3535
 
3351 3536
 /**
3352 3537
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3362,8 +3547,9 @@  discard block
 block discarded – undo
3362 3547
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3363 3548
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3364 3549
 
3365
-	if (empty($cache_enable) || empty($cacheAPI))
3366
-		return;
3550
+	if (empty($cache_enable) || empty($cacheAPI)) {
3551
+			return;
3552
+	}
3367 3553
 
3368 3554
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3369 3555
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3383,16 +3569,18 @@  discard block
 block discarded – undo
3383 3569
 
3384 3570
 		if (empty($value))
3385 3571
 		{
3386
-			if (!is_array($cache_misses))
3387
-				$cache_misses = array();
3572
+			if (!is_array($cache_misses)) {
3573
+							$cache_misses = array();
3574
+			}
3388 3575
 
3389 3576
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3390 3577
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3391 3578
 		}
3392 3579
 	}
3393 3580
 
3394
-	if (function_exists('call_integration_hook') && isset($value))
3395
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3581
+	if (function_exists('call_integration_hook') && isset($value)) {
3582
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3583
+	}
3396 3584
 
3397 3585
 	return empty($value) ? null : smf_json_decode($value, true);
3398 3586
 }
@@ -3414,8 +3602,9 @@  discard block
 block discarded – undo
3414 3602
 	global $cachedir, $sourcedir, $modSettings, $cacheAPI;
3415 3603
 
3416 3604
 	// If we can't get to the API, can't do this.
3417
-	if (empty($cacheAPI))
3418
-		return false;
3605
+	if (empty($cacheAPI)) {
3606
+			return false;
3607
+	}
3419 3608
 
3420 3609
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3421 3610
 	$value = $cacheAPI->cleanCache($type);
@@ -3440,8 +3629,9 @@  discard block
 block discarded – undo
3440 3629
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3441 3630
 
3442 3631
 	// Come on!
3443
-	if (empty($data))
3444
-		return array();
3632
+	if (empty($data)) {
3633
+			return array();
3634
+	}
3445 3635
 
3446 3636
 	// Set a nice default var.
3447 3637
 	$image = '';
@@ -3449,11 +3639,11 @@  discard block
 block discarded – undo
3449 3639
 	// Gravatar has been set as mandatory!
3450 3640
 	if (!empty($modSettings['gravatarOverride']))
3451 3641
 	{
3452
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3453
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3454
-
3455
-		else if (!empty($data['email']))
3456
-			$image = get_gravatar_url($data['email']);
3642
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3643
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3644
+		} else if (!empty($data['email'])) {
3645
+					$image = get_gravatar_url($data['email']);
3646
+		}
3457 3647
 	}
3458 3648
 
3459 3649
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3465,54 +3655,60 @@  discard block
 block discarded – undo
3465 3655
 			// Gravatar.
3466 3656
 			if (stristr($data['avatar'], 'gravatar://'))
3467 3657
 			{
3468
-				if ($data['avatar'] == 'gravatar://')
3469
-					$image = get_gravatar_url($data['email']);
3470
-
3471
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3472
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3658
+				if ($data['avatar'] == 'gravatar://') {
3659
+									$image = get_gravatar_url($data['email']);
3660
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3661
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3662
+				}
3473 3663
 			}
3474 3664
 
3475 3665
 			// External url.
3476 3666
 			else
3477 3667
 			{
3478 3668
 				// Using ssl?
3479
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3480
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3669
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3670
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3671
+				}
3481 3672
 
3482 3673
 				// Just a plain external url.
3483
-				else
3484
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3674
+				else {
3675
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3676
+				}
3485 3677
 			}
3486 3678
 		}
3487 3679
 
3488 3680
 		// Perhaps this user has an attachment as avatar...
3489
-		else if (!empty($data['filename']))
3490
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3681
+		else if (!empty($data['filename'])) {
3682
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3683
+		}
3491 3684
 
3492 3685
 		// Right... no avatar... use our default image.
3493
-		else
3494
-			$image = $modSettings['avatar_url'] . '/default.png';
3686
+		else {
3687
+					$image = $modSettings['avatar_url'] . '/default.png';
3688
+		}
3495 3689
 	}
3496 3690
 
3497 3691
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3498 3692
 
3499 3693
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3500
-	if (!empty($image))
3501
-		return array(
3694
+	if (!empty($image)) {
3695
+			return array(
3502 3696
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3503 3697
 			'image' => '<img class="avatar" src="' . $image . '" />',
3504 3698
 			'href' => $image,
3505 3699
 			'url' => $image,
3506 3700
 		);
3701
+	}
3507 3702
 
3508 3703
 	// Fallback to make life easier for everyone...
3509
-	else
3510
-		return array(
3704
+	else {
3705
+			return array(
3511 3706
 			'name' => '',
3512 3707
 			'image' => '',
3513 3708
 			'href' => '',
3514 3709
 			'url' => '',
3515 3710
 		);
3516
-}
3711
+	}
3712
+	}
3517 3713
 
3518 3714
 ?>
3519 3715
\ No newline at end of file
Please login to merge, or discard this patch.