Completed
Pull Request — release-2.1 (#4090)
by Rick
08:48
created
Sources/Profile-Modify.php 1 patch
Braces   +694 added lines, -518 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '0001-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '0001-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
112
+					}
113
+				} else {
114
+									$value = '0001-01-01';
110 115
 				}
111
-				else
112
-					$value = '0001-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '0001-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '0001-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function(&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function(&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function(&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function(&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -882,9 +921,9 @@  discard block
 block discarded – undo
882 921
 	if ($context['user']['is_owner'])
883 922
 	{
884 923
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
924
+	} else {
925
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
885 926
 	}
886
-	else
887
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
888 927
 
889 928
 	// Arrays of all the changes - makes things easier.
890 929
 	$profile_bools = array();
@@ -895,22 +934,25 @@  discard block
 block discarded – undo
895 934
 		'ignore_boards',
896 935
 	);
897 936
 
898
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
899
-		$_POST['ignore_brd'] = array();
937
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
938
+			$_POST['ignore_brd'] = array();
939
+	}
900 940
 
901 941
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
902 942
 	if (isset($_POST['ignore_brd']))
903 943
 	{
904
-		if (!is_array($_POST['ignore_brd']))
905
-			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
944
+		if (!is_array($_POST['ignore_brd'])) {
945
+					$_POST['ignore_brd'] = array($_POST['ignore_brd']);
946
+		}
906 947
 
907 948
 		foreach ($_POST['ignore_brd'] as $k => $d)
908 949
 		{
909 950
 			$d = (int) $d;
910
-			if ($d != 0)
911
-				$_POST['ignore_brd'][$k] = $d;
912
-			else
913
-				unset($_POST['ignore_brd'][$k]);
951
+			if ($d != 0) {
952
+							$_POST['ignore_brd'][$k] = $d;
953
+			} else {
954
+							unset($_POST['ignore_brd'][$k]);
955
+			}
914 956
 		}
915 957
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
916 958
 		unset($_POST['ignore_brd']);
@@ -923,21 +965,26 @@  discard block
 block discarded – undo
923 965
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
924 966
 		//makeAvatarChanges($memID, $post_errors);
925 967
 
926
-		if (!empty($_REQUEST['sa']))
927
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
968
+		if (!empty($_REQUEST['sa'])) {
969
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
970
+		}
928 971
 
929
-		foreach ($profile_bools as $var)
930
-			if (isset($_POST[$var]))
972
+		foreach ($profile_bools as $var) {
973
+					if (isset($_POST[$var]))
931 974
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
932
-		foreach ($profile_ints as $var)
933
-			if (isset($_POST[$var]))
975
+		}
976
+		foreach ($profile_ints as $var) {
977
+					if (isset($_POST[$var]))
934 978
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
935
-		foreach ($profile_floats as $var)
936
-			if (isset($_POST[$var]))
979
+		}
980
+		foreach ($profile_floats as $var) {
981
+					if (isset($_POST[$var]))
937 982
 				$profile_vars[$var] = (float) $_POST[$var];
938
-		foreach ($profile_strings as $var)
939
-			if (isset($_POST[$var]))
983
+		}
984
+		foreach ($profile_strings as $var) {
985
+					if (isset($_POST[$var]))
940 986
 				$profile_vars[$var] = $_POST[$var];
987
+		}
941 988
 	}
942 989
 }
943 990
 
@@ -971,8 +1018,9 @@  discard block
 block discarded – undo
971 1018
 	);
972 1019
 
973 1020
 	// Can't change reserved vars.
974
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
975
-		fatal_lang_error('no_access', false);
1021
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1022
+			fatal_lang_error('no_access', false);
1023
+	}
976 1024
 
977 1025
 	// Don't allow any overriding of custom fields with default or non-default options.
978 1026
 	$request = $smcFunc['db_query']('', '
@@ -984,8 +1032,9 @@  discard block
 block discarded – undo
984 1032
 		)
985 1033
 	);
986 1034
 	$custom_fields = array();
987
-	while ($row = $smcFunc['db_fetch_assoc']($request))
988
-		$custom_fields[] = $row['col_name'];
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$custom_fields[] = $row['col_name'];
1037
+	}
989 1038
 	$smcFunc['db_free_result']($request);
990 1039
 
991 1040
 	// These are the theme changes...
@@ -994,33 +1043,39 @@  discard block
 block discarded – undo
994 1043
 	{
995 1044
 		foreach ($_POST['options'] as $opt => $val)
996 1045
 		{
997
-			if (in_array($opt, $custom_fields))
998
-				continue;
1046
+			if (in_array($opt, $custom_fields)) {
1047
+							continue;
1048
+			}
999 1049
 
1000 1050
 			// These need to be controlled.
1001
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1002
-				$val = max(0, min($val, 50));
1051
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1052
+							$val = max(0, min($val, 50));
1053
+			}
1003 1054
 			// We don't set this per theme anymore.
1004
-			elseif ($opt == 'allow_no_censored')
1005
-				continue;
1055
+			elseif ($opt == 'allow_no_censored') {
1056
+							continue;
1057
+			}
1006 1058
 
1007 1059
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1008 1060
 		}
1009 1061
 	}
1010 1062
 
1011 1063
 	$erase_options = array();
1012
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1013
-		foreach ($_POST['default_options'] as $opt => $val)
1064
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1065
+			foreach ($_POST['default_options'] as $opt => $val)
1014 1066
 		{
1015 1067
 			if (in_array($opt, $custom_fields))
1016 1068
 				continue;
1069
+	}
1017 1070
 
1018 1071
 			// These need to be controlled.
1019
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1020
-				$val = max(0, min($val, 50));
1072
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1073
+							$val = max(0, min($val, 50));
1074
+			}
1021 1075
 			// Only let admins and owners change the censor.
1022
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1023
-					continue;
1076
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1077
+								continue;
1078
+			}
1024 1079
 
1025 1080
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1026 1081
 			$erase_options[] = $opt;
@@ -1056,8 +1111,9 @@  discard block
 block discarded – undo
1056 1111
 
1057 1112
 		// Admins can choose any theme, even if it's not enabled...
1058 1113
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1059
-		foreach ($themes as $t)
1060
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1114
+		foreach ($themes as $t) {
1115
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1116
+		}
1061 1117
 	}
1062 1118
 }
1063 1119
 
@@ -1076,8 +1132,9 @@  discard block
 block discarded – undo
1076 1132
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1077 1133
 	{
1078 1134
 		// Make sure only integers are deleted.
1079
-		foreach ($_POST['notify_boards'] as $index => $id)
1080
-			$_POST['notify_boards'][$index] = (int) $id;
1135
+		foreach ($_POST['notify_boards'] as $index => $id) {
1136
+					$_POST['notify_boards'][$index] = (int) $id;
1137
+		}
1081 1138
 
1082 1139
 		// id_board = 0 is reserved for topic notifications.
1083 1140
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1096,8 +1153,9 @@  discard block
 block discarded – undo
1096 1153
 	// We are editing topic notifications......
1097 1154
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1098 1155
 	{
1099
-		foreach ($_POST['notify_topics'] as $index => $id)
1100
-			$_POST['notify_topics'][$index] = (int) $id;
1156
+		foreach ($_POST['notify_topics'] as $index => $id) {
1157
+					$_POST['notify_topics'][$index] = (int) $id;
1158
+		}
1101 1159
 
1102 1160
 		// Make sure there are no zeros left.
1103 1161
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1111,16 +1169,18 @@  discard block
 block discarded – undo
1111 1169
 				'selected_member' => $memID,
1112 1170
 			)
1113 1171
 		);
1114
-		foreach ($_POST['notify_topics'] as $topic)
1115
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1172
+		foreach ($_POST['notify_topics'] as $topic) {
1173
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1174
+		}
1116 1175
 	}
1117 1176
 
1118 1177
 	// We are removing topic preferences
1119 1178
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1120 1179
 	{
1121 1180
 		$prefs = array();
1122
-		foreach ($_POST['notify_topics'] as $topic)
1123
-			$prefs[] = 'topic_notify_' . $topic;
1181
+		foreach ($_POST['notify_topics'] as $topic) {
1182
+					$prefs[] = 'topic_notify_' . $topic;
1183
+		}
1124 1184
 		deleteNotifyPrefs($memID, $prefs);
1125 1185
 	}
1126 1186
 
@@ -1128,8 +1188,9 @@  discard block
 block discarded – undo
1128 1188
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1129 1189
 	{
1130 1190
 		$prefs = array();
1131
-		foreach ($_POST['notify_boards'] as $board)
1132
-			$prefs[] = 'board_notify_' . $board;
1191
+		foreach ($_POST['notify_boards'] as $board) {
1192
+					$prefs[] = 'board_notify_' . $board;
1193
+		}
1133 1194
 		deleteNotifyPrefs($memID, $prefs);
1134 1195
 	}
1135 1196
 }
@@ -1150,8 +1211,9 @@  discard block
 block discarded – undo
1150 1211
 
1151 1212
 	$errors = array();
1152 1213
 
1153
-	if ($sanitize && isset($_POST['customfield']))
1154
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1214
+	if ($sanitize && isset($_POST['customfield'])) {
1215
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1216
+	}
1155 1217
 
1156 1218
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1157 1219
 
@@ -1176,48 +1238,49 @@  discard block
 block discarded – undo
1176 1238
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1177 1239
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1178 1240
 		*/
1179
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1180
-			continue;
1241
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1242
+					continue;
1243
+		}
1181 1244
 
1182 1245
 		// Validate the user data.
1183
-		if ($row['field_type'] == 'check')
1184
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1185
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1246
+		if ($row['field_type'] == 'check') {
1247
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1248
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1186 1249
 		{
1187 1250
 			$value = $row['default_value'];
1188
-			foreach (explode(',', $row['field_options']) as $k => $v)
1189
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1251
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1252
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1190 1253
 					$value = $v;
1254
+			}
1191 1255
 		}
1192 1256
 		// Otherwise some form of text!
1193 1257
 		else
1194 1258
 		{
1195 1259
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1196
-			if ($row['field_length'])
1197
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1260
+			if ($row['field_length']) {
1261
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1262
+			}
1198 1263
 
1199 1264
 			// Any masks?
1200 1265
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
1201 1266
 			{
1202 1267
 				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1203 1268
 				{
1204
-					if ($returnErrors)
1205
-						$errors[] = 'custom_field_mail_fail';
1206
-
1207
-					else
1208
-						$value = '';
1209
-				}
1210
-				elseif ($row['mask'] == 'number')
1269
+					if ($returnErrors) {
1270
+											$errors[] = 'custom_field_mail_fail';
1271
+					} else {
1272
+											$value = '';
1273
+					}
1274
+				} elseif ($row['mask'] == 'number')
1211 1275
 				{
1212 1276
 					$value = (int) $value;
1213
-				}
1214
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1277
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1215 1278
 				{
1216
-					if ($returnErrors)
1217
-						$errors[] = 'custom_field_regex_fail';
1218
-
1219
-					else
1220
-						$value = '';
1279
+					if ($returnErrors) {
1280
+											$errors[] = 'custom_field_regex_fail';
1281
+					} else {
1282
+											$value = '';
1283
+					}
1221 1284
 				}
1222 1285
 			}
1223 1286
 		}
@@ -1243,8 +1306,9 @@  discard block
 block discarded – undo
1243 1306
 
1244 1307
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1245 1308
 
1246
-	if (!empty($hook_errors) && is_array($hook_errors))
1247
-		$errors = array_merge($errors, $hook_errors);
1309
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1310
+			$errors = array_merge($errors, $hook_errors);
1311
+	}
1248 1312
 
1249 1313
 	// Make those changes!
1250 1314
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1262,9 +1326,10 @@  discard block
 block discarded – undo
1262 1326
 		}
1263 1327
 	}
1264 1328
 
1265
-	if ($returnErrors)
1266
-		return $errors;
1267
-}
1329
+	if ($returnErrors) {
1330
+			return $errors;
1331
+	}
1332
+	}
1268 1333
 
1269 1334
 /**
1270 1335
  * Show all the users buddies, as well as a add/delete interface.
@@ -1276,8 +1341,9 @@  discard block
 block discarded – undo
1276 1341
 	global $context, $txt, $modSettings;
1277 1342
 
1278 1343
 	// Do a quick check to ensure people aren't getting here illegally!
1279
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1280
-		fatal_lang_error('no_access', false);
1344
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1345
+			fatal_lang_error('no_access', false);
1346
+	}
1281 1347
 
1282 1348
 	// Can we email the user direct?
1283 1349
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1307,9 +1373,10 @@  discard block
 block discarded – undo
1307 1373
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1308 1374
 	$call = call_helper($subActions[$context['list_area']][0], true);
1309 1375
 
1310
-	if (!empty($call))
1311
-		call_user_func($call, $memID);
1312
-}
1376
+	if (!empty($call)) {
1377
+			call_user_func($call, $memID);
1378
+	}
1379
+	}
1313 1380
 
1314 1381
 /**
1315 1382
  * Show all the users buddies, as well as a add/delete interface.
@@ -1323,9 +1390,10 @@  discard block
 block discarded – undo
1323 1390
 
1324 1391
 	// For making changes!
1325 1392
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1326
-	foreach ($buddiesArray as $k => $dummy)
1327
-		if ($dummy == '')
1393
+	foreach ($buddiesArray as $k => $dummy) {
1394
+			if ($dummy == '')
1328 1395
 			unset($buddiesArray[$k]);
1396
+	}
1329 1397
 
1330 1398
 	// Removing a buddy?
1331 1399
 	if (isset($_GET['remove']))
@@ -1337,10 +1405,11 @@  discard block
 block discarded – undo
1337 1405
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1338 1406
 
1339 1407
 		// Heh, I'm lazy, do it the easy way...
1340
-		foreach ($buddiesArray as $key => $buddy)
1341
-			if ($buddy == (int) $_GET['remove'])
1408
+		foreach ($buddiesArray as $key => $buddy) {
1409
+					if ($buddy == (int) $_GET['remove'])
1342 1410
 			{
1343 1411
 				unset($buddiesArray[$key]);
1412
+		}
1344 1413
 				$_SESSION['prf-save'] = true;
1345 1414
 			}
1346 1415
 
@@ -1350,8 +1419,7 @@  discard block
 block discarded – undo
1350 1419
 
1351 1420
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1352 1421
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1353
-	}
1354
-	elseif (isset($_POST['new_buddy']))
1422
+	} elseif (isset($_POST['new_buddy']))
1355 1423
 	{
1356 1424
 		checkSession();
1357 1425
 
@@ -1364,8 +1432,9 @@  discard block
 block discarded – undo
1364 1432
 		{
1365 1433
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1366 1434
 
1367
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1368
-				unset($new_buddies[$k]);
1435
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1436
+							unset($new_buddies[$k]);
1437
+			}
1369 1438
 		}
1370 1439
 
1371 1440
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1385,16 +1454,18 @@  discard block
 block discarded – undo
1385 1454
 				)
1386 1455
 			);
1387 1456
 
1388
-			if ($smcFunc['db_num_rows']($request) != 0)
1389
-				$_SESSION['prf-save'] = true;
1457
+			if ($smcFunc['db_num_rows']($request) != 0) {
1458
+							$_SESSION['prf-save'] = true;
1459
+			}
1390 1460
 
1391 1461
 			// Add the new member to the buddies array.
1392 1462
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1393 1463
 			{
1394
-				if (in_array($row['id_member'], $buddiesArray))
1395
-					continue;
1396
-				else
1397
-					$buddiesArray[] = (int) $row['id_member'];
1464
+				if (in_array($row['id_member'], $buddiesArray)) {
1465
+									continue;
1466
+				} else {
1467
+									$buddiesArray[] = (int) $row['id_member'];
1468
+				}
1398 1469
 			}
1399 1470
 			$smcFunc['db_free_result']($request);
1400 1471
 
@@ -1424,18 +1495,20 @@  discard block
 block discarded – undo
1424 1495
 
1425 1496
 	$context['custom_pf'] = array();
1426 1497
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1427
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1428
-		if (!isset($disabled_fields[$row['col_name']]))
1498
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1499
+			if (!isset($disabled_fields[$row['col_name']]))
1429 1500
 			$context['custom_pf'][$row['col_name']] = array(
1430 1501
 				'label' => $row['field_name'],
1431 1502
 				'type' => $row['field_type'],
1432 1503
 				'bbc' => !empty($row['bbc']),
1433 1504
 				'enclose' => $row['enclose'],
1434 1505
 			);
1506
+	}
1435 1507
 
1436 1508
 	// Gotta disable the gender option.
1437
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled')
1438
-		unset($context['custom_pf']['cust_gender']);
1509
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') {
1510
+			unset($context['custom_pf']['cust_gender']);
1511
+	}
1439 1512
 
1440 1513
 	$smcFunc['db_free_result']($request);
1441 1514
 
@@ -1452,8 +1525,9 @@  discard block
 block discarded – undo
1452 1525
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1453 1526
 			)
1454 1527
 		);
1455
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1456
-			$buddies[] = $row['id_member'];
1528
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1529
+					$buddies[] = $row['id_member'];
1530
+		}
1457 1531
 		$smcFunc['db_free_result']($result);
1458 1532
 	}
1459 1533
 
@@ -1481,30 +1555,32 @@  discard block
 block discarded – undo
1481 1555
 					continue;
1482 1556
 				}
1483 1557
 
1484
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1485
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1486
-
1487
-				elseif ($column['type'] == 'check')
1488
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1558
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1559
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1560
+				} elseif ($column['type'] == 'check') {
1561
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1562
+				}
1489 1563
 
1490 1564
 				// Enclosing the user input within some other text?
1491
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1492
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1565
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1566
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1493 1567
 						'{SCRIPTURL}' => $scripturl,
1494 1568
 						'{IMAGES_URL}' => $settings['images_url'],
1495 1569
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1496 1570
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1497 1571
 					));
1572
+				}
1498 1573
 			}
1499 1574
 		}
1500 1575
 	}
1501 1576
 
1502 1577
 	if (isset($_SESSION['prf-save']))
1503 1578
 	{
1504
-		if ($_SESSION['prf-save'] === true)
1505
-			$context['saved_successful'] = true;
1506
-		else
1507
-			$context['saved_failed'] = $_SESSION['prf-save'];
1579
+		if ($_SESSION['prf-save'] === true) {
1580
+					$context['saved_successful'] = true;
1581
+		} else {
1582
+					$context['saved_failed'] = $_SESSION['prf-save'];
1583
+		}
1508 1584
 
1509 1585
 		unset($_SESSION['prf-save']);
1510 1586
 	}
@@ -1524,9 +1600,10 @@  discard block
 block discarded – undo
1524 1600
 
1525 1601
 	// For making changes!
1526 1602
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1527
-	foreach ($ignoreArray as $k => $dummy)
1528
-		if ($dummy == '')
1603
+	foreach ($ignoreArray as $k => $dummy) {
1604
+			if ($dummy == '')
1529 1605
 			unset($ignoreArray[$k]);
1606
+	}
1530 1607
 
1531 1608
 	// Removing a member from the ignore list?
1532 1609
 	if (isset($_GET['remove']))
@@ -1536,10 +1613,11 @@  discard block
 block discarded – undo
1536 1613
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1537 1614
 
1538 1615
 		// Heh, I'm lazy, do it the easy way...
1539
-		foreach ($ignoreArray as $key => $id_remove)
1540
-			if ($id_remove == (int) $_GET['remove'])
1616
+		foreach ($ignoreArray as $key => $id_remove) {
1617
+					if ($id_remove == (int) $_GET['remove'])
1541 1618
 			{
1542 1619
 				unset($ignoreArray[$key]);
1620
+		}
1543 1621
 				$_SESSION['prf-save'] = true;
1544 1622
 			}
1545 1623
 
@@ -1549,8 +1627,7 @@  discard block
 block discarded – undo
1549 1627
 
1550 1628
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1551 1629
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1552
-	}
1553
-	elseif (isset($_POST['new_ignore']))
1630
+	} elseif (isset($_POST['new_ignore']))
1554 1631
 	{
1555 1632
 		checkSession();
1556 1633
 		// Prepare the string for extraction...
@@ -1562,8 +1639,9 @@  discard block
 block discarded – undo
1562 1639
 		{
1563 1640
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1564 1641
 
1565
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1566
-				unset($new_entries[$k]);
1642
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1643
+							unset($new_entries[$k]);
1644
+			}
1567 1645
 		}
1568 1646
 
1569 1647
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1581,16 +1659,18 @@  discard block
 block discarded – undo
1581 1659
 				)
1582 1660
 			);
1583 1661
 
1584
-			if ($smcFunc['db_num_rows']($request) != 0)
1585
-				$_SESSION['prf-save'] = true;
1662
+			if ($smcFunc['db_num_rows']($request) != 0) {
1663
+							$_SESSION['prf-save'] = true;
1664
+			}
1586 1665
 
1587 1666
 			// Add the new member to the buddies array.
1588 1667
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1589 1668
 			{
1590
-				if (in_array($row['id_member'], $ignoreArray))
1591
-					continue;
1592
-				else
1593
-					$ignoreArray[] = (int) $row['id_member'];
1669
+				if (in_array($row['id_member'], $ignoreArray)) {
1670
+									continue;
1671
+				} else {
1672
+									$ignoreArray[] = (int) $row['id_member'];
1673
+				}
1594 1674
 			}
1595 1675
 			$smcFunc['db_free_result']($request);
1596 1676
 
@@ -1619,8 +1699,9 @@  discard block
 block discarded – undo
1619 1699
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1620 1700
 			)
1621 1701
 		);
1622
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1623
-			$ignored[] = $row['id_member'];
1702
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1703
+					$ignored[] = $row['id_member'];
1704
+		}
1624 1705
 		$smcFunc['db_free_result']($result);
1625 1706
 	}
1626 1707
 
@@ -1639,10 +1720,11 @@  discard block
 block discarded – undo
1639 1720
 
1640 1721
 	if (isset($_SESSION['prf-save']))
1641 1722
 	{
1642
-		if ($_SESSION['prf-save'] === true)
1643
-			$context['saved_successful'] = true;
1644
-		else
1645
-			$context['saved_failed'] = $_SESSION['prf-save'];
1723
+		if ($_SESSION['prf-save'] === true) {
1724
+					$context['saved_successful'] = true;
1725
+		} else {
1726
+					$context['saved_failed'] = $_SESSION['prf-save'];
1727
+		}
1646 1728
 
1647 1729
 		unset($_SESSION['prf-save']);
1648 1730
 	}
@@ -1658,8 +1740,9 @@  discard block
 block discarded – undo
1658 1740
 	global $context, $txt;
1659 1741
 
1660 1742
 	loadThemeOptions($memID);
1661
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1662
-		loadCustomFields($memID, 'account');
1743
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1744
+			loadCustomFields($memID, 'account');
1745
+	}
1663 1746
 
1664 1747
 	$context['sub_template'] = 'edit_options';
1665 1748
 	$context['page_desc'] = $txt['account_info'];
@@ -1686,8 +1769,9 @@  discard block
 block discarded – undo
1686 1769
 	global $context, $txt;
1687 1770
 
1688 1771
 	loadThemeOptions($memID);
1689
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1690
-		loadCustomFields($memID, 'forumprofile');
1772
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1773
+			loadCustomFields($memID, 'forumprofile');
1774
+	}
1691 1775
 
1692 1776
 	$context['sub_template'] = 'edit_options';
1693 1777
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1720,18 +1804,21 @@  discard block
 block discarded – undo
1720 1804
 	$dirs = array();
1721 1805
 	$files = array();
1722 1806
 
1723
-	if (!$dir)
1724
-		return array();
1807
+	if (!$dir) {
1808
+			return array();
1809
+	}
1725 1810
 
1726 1811
 	while ($line = $dir->read())
1727 1812
 	{
1728
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1729
-			continue;
1813
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1814
+					continue;
1815
+		}
1730 1816
 
1731
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1732
-			$dirs[] = $line;
1733
-		else
1734
-			$files[] = $line;
1817
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1818
+					$dirs[] = $line;
1819
+		} else {
1820
+					$files[] = $line;
1821
+		}
1735 1822
 	}
1736 1823
 	$dir->close();
1737 1824
 
@@ -1752,14 +1839,15 @@  discard block
 block discarded – undo
1752 1839
 	foreach ($dirs as $line)
1753 1840
 	{
1754 1841
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1755
-		if (!empty($tmp))
1756
-			$result[] = array(
1842
+		if (!empty($tmp)) {
1843
+					$result[] = array(
1757 1844
 				'filename' => $smcFunc['htmlspecialchars']($line),
1758 1845
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1759 1846
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1760 1847
 				'is_dir' => true,
1761 1848
 				'files' => $tmp
1762 1849
 		);
1850
+		}
1763 1851
 		unset($tmp);
1764 1852
 	}
1765 1853
 
@@ -1769,8 +1857,9 @@  discard block
 block discarded – undo
1769 1857
 		$extension = substr(strrchr($line, '.'), 1);
1770 1858
 
1771 1859
 		// Make sure it is an image.
1772
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1773
-			continue;
1860
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1861
+					continue;
1862
+		}
1774 1863
 
1775 1864
 		$result[] = array(
1776 1865
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1778,8 +1867,9 @@  discard block
 block discarded – undo
1778 1867
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1779 1868
 			'is_dir' => false
1780 1869
 		);
1781
-		if ($level == 1)
1782
-			$context['avatar_list'][] = $directory . '/' . $line;
1870
+		if ($level == 1) {
1871
+					$context['avatar_list'][] = $directory . '/' . $line;
1872
+		}
1783 1873
 	}
1784 1874
 
1785 1875
 	return $result;
@@ -1798,8 +1888,9 @@  discard block
 block discarded – undo
1798 1888
 	loadSubTemplate('options');
1799 1889
 
1800 1890
 	loadThemeOptions($memID);
1801
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1802
-		loadCustomFields($memID, 'theme');
1891
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1892
+			loadCustomFields($memID, 'theme');
1893
+	}
1803 1894
 
1804 1895
 	$context['sub_template'] = 'edit_options';
1805 1896
 	$context['page_desc'] = $txt['theme_info'];
@@ -1853,16 +1944,19 @@  discard block
 block discarded – undo
1853 1944
 {
1854 1945
 	global $txt, $context, $modSettings, $smcFunc, $sourcedir;
1855 1946
 
1856
-	if (!isset($context['token_check']))
1857
-		$context['token_check'] = 'profile-nt' . $memID;
1947
+	if (!isset($context['token_check'])) {
1948
+			$context['token_check'] = 'profile-nt' . $memID;
1949
+	}
1858 1950
 
1859 1951
 	is_not_guest();
1860
-	if (!$context['user']['is_owner'])
1861
-		isAllowedTo('profile_extra_any');
1952
+	if (!$context['user']['is_owner']) {
1953
+			isAllowedTo('profile_extra_any');
1954
+	}
1862 1955
 
1863 1956
 	// Set the post action if we're coming from the profile...
1864
-	if (!isset($context['action']))
1865
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1957
+	if (!isset($context['action'])) {
1958
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1959
+	}
1866 1960
 
1867 1961
 	// What options are set
1868 1962
 	loadThemeOptions($memID);
@@ -1949,28 +2043,34 @@  discard block
 block discarded – undo
1949 2043
 	);
1950 2044
 
1951 2045
 	// There are certain things that are disabled at the group level.
1952
-	if (empty($modSettings['cal_enabled']))
1953
-		unset($alert_types['calendar']);
2046
+	if (empty($modSettings['cal_enabled'])) {
2047
+			unset($alert_types['calendar']);
2048
+	}
1954 2049
 
1955 2050
 	// Disable paid subscriptions at group level if they're disabled
1956
-	if (empty($modSettings['paid_enabled']))
1957
-		unset($alert_types['paidsubs']);
2051
+	if (empty($modSettings['paid_enabled'])) {
2052
+			unset($alert_types['paidsubs']);
2053
+	}
1958 2054
 
1959 2055
 	// Disable membergroup requests at group level if they're disabled
1960
-	if (empty($modSettings['show_group_membership']))
1961
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2056
+	if (empty($modSettings['show_group_membership'])) {
2057
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2058
+	}
1962 2059
 
1963 2060
 	// Disable mentions if they're disabled
1964
-	if (empty($modSettings['enable_mentions']))
1965
-		unset($alert_types['msg']['msg_mention']);
2061
+	if (empty($modSettings['enable_mentions'])) {
2062
+			unset($alert_types['msg']['msg_mention']);
2063
+	}
1966 2064
 
1967 2065
 	// Disable likes if they're disabled
1968
-	if (empty($modSettings['enable_likes']))
1969
-		unset($alert_types['msg']['msg_like']);
2066
+	if (empty($modSettings['enable_likes'])) {
2067
+			unset($alert_types['msg']['msg_like']);
2068
+	}
1970 2069
 
1971 2070
 	// Disable buddy requests if they're disabled
1972
-	if (empty($modSettings['enable_buddylist']))
1973
-		unset($alert_types['members']['buddy_request']);
2071
+	if (empty($modSettings['enable_buddylist'])) {
2072
+			unset($alert_types['members']['buddy_request']);
2073
+	}
1974 2074
 
1975 2075
 	// Now, now, we could pass this through global but we should really get into the habit of
1976 2076
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -1998,15 +2098,17 @@  discard block
 block discarded – undo
1998 2098
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
1999 2099
 		}
2000 2100
 
2001
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2002
-			unset($alert_types['members']['request_group']);
2101
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2102
+					unset($alert_types['members']['request_group']);
2103
+		}
2003 2104
 
2004 2105
 		foreach ($alert_types as $group => $items)
2005 2106
 		{
2006 2107
 			foreach ($items as $alert_key => $alert_value)
2007 2108
 			{
2008
-				if (!isset($alert_value['permission']))
2009
-					continue;
2109
+				if (!isset($alert_value['permission'])) {
2110
+									continue;
2111
+				}
2010 2112
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2011 2113
 				{
2012 2114
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2014,12 +2116,14 @@  discard block
 block discarded – undo
2014 2116
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2015 2117
 				}
2016 2118
 
2017
-				if (!$perms_cache[$alert_value['permission']['name']])
2018
-					unset ($alert_types[$group][$alert_key]);
2119
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2120
+									unset ($alert_types[$group][$alert_key]);
2121
+				}
2019 2122
 			}
2020 2123
 
2021
-			if (empty($alert_types[$group]))
2022
-				unset ($alert_types[$group]);
2124
+			if (empty($alert_types[$group])) {
2125
+							unset ($alert_types[$group]);
2126
+			}
2023 2127
 		}
2024 2128
 	}
2025 2129
 
@@ -2051,9 +2155,9 @@  discard block
 block discarded – undo
2051 2155
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2052 2156
 						break;
2053 2157
 					case 'select':
2054
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2055
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2056
-						else
2158
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2159
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2160
+						} else
2057 2161
 						{
2058 2162
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2059 2163
 							$keys = array_keys($this_option['opts']);
@@ -2073,23 +2177,28 @@  discard block
 block discarded – undo
2073 2177
 				$this_value = 0;
2074 2178
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2075 2179
 				{
2076
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2077
-						$this_value |= $bitvalue;
2180
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2181
+											$this_value |= $bitvalue;
2182
+					}
2183
+				}
2184
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2185
+									$update_prefs[$item_key] = $this_value;
2078 2186
 				}
2079
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2080
-					$update_prefs[$item_key] = $this_value;
2081 2187
 			}
2082 2188
 		}
2083 2189
 
2084
-		if (!empty($_POST['opt_alert_timeout']))
2085
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2190
+		if (!empty($_POST['opt_alert_timeout'])) {
2191
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2192
+		}
2086 2193
 
2087
-		if (!empty($_POST['notify_announcements']))
2088
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2194
+		if (!empty($_POST['notify_announcements'])) {
2195
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2196
+		}
2089 2197
 
2090 2198
 		setNotifyPrefs((int) $memID, $update_prefs);
2091
-		foreach ($update_prefs as $pref => $value)
2092
-			$context['alert_prefs'][$pref] = $value;
2199
+		foreach ($update_prefs as $pref => $value) {
2200
+					$context['alert_prefs'][$pref] = $value;
2201
+		}
2093 2202
 
2094 2203
 		makeNotificationChanges($memID);
2095 2204
 
@@ -2119,8 +2228,9 @@  discard block
 block discarded – undo
2119 2228
 
2120 2229
 	// Now we're all set up.
2121 2230
 	is_not_guest();
2122
-	if (!$context['user']['is_owner'])
2123
-		fatal_error('no_access');
2231
+	if (!$context['user']['is_owner']) {
2232
+			fatal_error('no_access');
2233
+	}
2124 2234
 
2125 2235
 	checkSession('get');
2126 2236
 
@@ -2152,8 +2262,9 @@  discard block
 block discarded – undo
2152 2262
 {
2153 2263
 	global $smcFunc;
2154 2264
 
2155
-	if (empty($toMark) || empty($memID))
2156
-		return false;
2265
+	if (empty($toMark) || empty($memID)) {
2266
+			return false;
2267
+	}
2157 2268
 
2158 2269
 	$toMark = (array) $toMark;
2159 2270
 
@@ -2187,8 +2298,9 @@  discard block
 block discarded – undo
2187 2298
 {
2188 2299
 	global $smcFunc;
2189 2300
 
2190
-	if (empty($toDelete))
2191
-		return false;
2301
+	if (empty($toDelete)) {
2302
+			return false;
2303
+	}
2192 2304
 
2193 2305
 	$toDelete = (array) $toDelete;
2194 2306
 
@@ -2223,8 +2335,9 @@  discard block
 block discarded – undo
2223 2335
 {
2224 2336
 	global $smcFunc;
2225 2337
 
2226
-	if (empty($memID))
2227
-		return false;
2338
+	if (empty($memID)) {
2339
+			return false;
2340
+	}
2228 2341
 
2229 2342
 	$request = $smcFunc['db_query']('', '
2230 2343
 		SELECT id_alert
@@ -2301,8 +2414,9 @@  discard block
 block discarded – undo
2301 2414
 					{
2302 2415
 						$link = $topic['link'];
2303 2416
 
2304
-						if ($topic['new'])
2305
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2417
+						if ($topic['new']) {
2418
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2419
+						}
2306 2420
 
2307 2421
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2308 2422
 
@@ -2453,8 +2567,9 @@  discard block
 block discarded – undo
2453 2567
 					{
2454 2568
 						$link = $board['link'];
2455 2569
 
2456
-						if ($board['new'])
2457
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2570
+						if ($board['new']) {
2571
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2572
+						}
2458 2573
 
2459 2574
 						return $link;
2460 2575
 					},
@@ -2654,8 +2769,8 @@  discard block
 block discarded – undo
2654 2769
 		)
2655 2770
 	);
2656 2771
 	$notification_boards = array();
2657
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2658
-		$notification_boards[] = array(
2772
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2773
+			$notification_boards[] = array(
2659 2774
 			'id' => $row['id_board'],
2660 2775
 			'name' => $row['name'],
2661 2776
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2663,6 +2778,7 @@  discard block
 block discarded – undo
2663 2778
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2664 2779
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2665 2780
 		);
2781
+	}
2666 2782
 	$smcFunc['db_free_result']($request);
2667 2783
 
2668 2784
 	return $notification_boards;
@@ -2677,17 +2793,18 @@  discard block
 block discarded – undo
2677 2793
 {
2678 2794
 	global $context, $options, $cur_profile, $smcFunc;
2679 2795
 
2680
-	if (isset($_POST['default_options']))
2681
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2796
+	if (isset($_POST['default_options'])) {
2797
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2798
+	}
2682 2799
 
2683 2800
 	if ($context['user']['is_owner'])
2684 2801
 	{
2685 2802
 		$context['member']['options'] = $options;
2686
-		if (isset($_POST['options']) && is_array($_POST['options']))
2687
-			foreach ($_POST['options'] as $k => $v)
2803
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2804
+					foreach ($_POST['options'] as $k => $v)
2688 2805
 				$context['member']['options'][$k] = $v;
2689
-	}
2690
-	else
2806
+		}
2807
+	} else
2691 2808
 	{
2692 2809
 		$request = $smcFunc['db_query']('', '
2693 2810
 			SELECT id_member, variable, value
@@ -2708,8 +2825,9 @@  discard block
 block discarded – undo
2708 2825
 				continue;
2709 2826
 			}
2710 2827
 
2711
-			if (isset($_POST['options'][$row['variable']]))
2712
-				$row['value'] = $_POST['options'][$row['variable']];
2828
+			if (isset($_POST['options'][$row['variable']])) {
2829
+							$row['value'] = $_POST['options'][$row['variable']];
2830
+			}
2713 2831
 			$context['member']['options'][$row['variable']] = $row['value'];
2714 2832
 		}
2715 2833
 		$smcFunc['db_free_result']($request);
@@ -2717,8 +2835,9 @@  discard block
 block discarded – undo
2717 2835
 		// Load up the default theme options for any missing.
2718 2836
 		foreach ($temp as $k => $v)
2719 2837
 		{
2720
-			if (!isset($context['member']['options'][$k]))
2721
-				$context['member']['options'][$k] = $v;
2838
+			if (!isset($context['member']['options'][$k])) {
2839
+							$context['member']['options'][$k] = $v;
2840
+			}
2722 2841
 		}
2723 2842
 	}
2724 2843
 }
@@ -2733,8 +2852,9 @@  discard block
 block discarded – undo
2733 2852
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2734 2853
 
2735 2854
 	// Have the admins enabled this option?
2736
-	if (empty($modSettings['allow_ignore_boards']))
2737
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2855
+	if (empty($modSettings['allow_ignore_boards'])) {
2856
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2857
+	}
2738 2858
 
2739 2859
 	// Find all the boards this user is allowed to see.
2740 2860
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2754,12 +2874,13 @@  discard block
 block discarded – undo
2754 2874
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2755 2875
 	{
2756 2876
 		// This category hasn't been set up yet..
2757
-		if (!isset($context['categories'][$row['id_cat']]))
2758
-			$context['categories'][$row['id_cat']] = array(
2877
+		if (!isset($context['categories'][$row['id_cat']])) {
2878
+					$context['categories'][$row['id_cat']] = array(
2759 2879
 				'id' => $row['id_cat'],
2760 2880
 				'name' => $row['cat_name'],
2761 2881
 				'boards' => array()
2762 2882
 			);
2883
+		}
2763 2884
 
2764 2885
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2765 2886
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2789,18 +2910,20 @@  discard block
 block discarded – undo
2789 2910
 	}
2790 2911
 
2791 2912
 	$max_boards = ceil(count($temp_boards) / 2);
2792
-	if ($max_boards == 1)
2793
-		$max_boards = 2;
2913
+	if ($max_boards == 1) {
2914
+			$max_boards = 2;
2915
+	}
2794 2916
 
2795 2917
 	// Now, alternate them so they can be shown left and right ;).
2796 2918
 	$context['board_columns'] = array();
2797 2919
 	for ($i = 0; $i < $max_boards; $i++)
2798 2920
 	{
2799 2921
 		$context['board_columns'][] = $temp_boards[$i];
2800
-		if (isset($temp_boards[$i + $max_boards]))
2801
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2802
-		else
2803
-			$context['board_columns'][] = array();
2922
+		if (isset($temp_boards[$i + $max_boards])) {
2923
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2924
+		} else {
2925
+					$context['board_columns'][] = array();
2926
+		}
2804 2927
 	}
2805 2928
 
2806 2929
 	loadThemeOptions($memID);
@@ -2869,8 +2992,9 @@  discard block
 block discarded – undo
2869 2992
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2870 2993
 	{
2871 2994
 		// We should skip the administrator group if they don't have the admin_forum permission!
2872
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2873
-			continue;
2995
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
2996
+					continue;
2997
+		}
2874 2998
 
2875 2999
 		$context['member_groups'][$row['id_group']] = array(
2876 3000
 			'id' => $row['id_group'],
@@ -2916,16 +3040,17 @@  discard block
 block discarded – undo
2916 3040
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2917 3041
 	// Warning message for signature image limits?
2918 3042
 	$context['signature_warning'] = '';
2919
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2920
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2921
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2922
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3043
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3044
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3045
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3046
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3047
+	}
2923 3048
 
2924 3049
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2925 3050
 
2926
-	if (empty($context['do_preview']))
2927
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2928
-	else
3051
+	if (empty($context['do_preview'])) {
3052
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3053
+	} else
2929 3054
 	{
2930 3055
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2931 3056
 		$validation = profileValidateSignature($signature);
@@ -2935,8 +3060,9 @@  discard block
 block discarded – undo
2935 3060
 			$context['post_errors'] = array();
2936 3061
 		}
2937 3062
 		$context['post_errors'][] = 'signature_not_yet_saved';
2938
-		if ($validation !== true && $validation !== false)
2939
-			$context['post_errors'][] = $validation;
3063
+		if ($validation !== true && $validation !== false) {
3064
+					$context['post_errors'][] = $validation;
3065
+		}
2940 3066
 
2941 3067
 		censorText($context['member']['signature']);
2942 3068
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2946,8 +3072,9 @@  discard block
 block discarded – undo
2946 3072
 	}
2947 3073
 
2948 3074
 	// Load the spell checker?
2949
-	if ($context['show_spellchecking'])
2950
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3075
+	if ($context['show_spellchecking']) {
3076
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3077
+	}
2951 3078
 
2952 3079
 	return true;
2953 3080
 }
@@ -2981,8 +3108,7 @@  discard block
 block discarded – undo
2981 3108
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
2982 3109
 		);
2983 3110
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
2984
-	}
2985
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3111
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
2986 3112
 	{
2987 3113
 		$context['member']['avatar'] += array(
2988 3114
 			'choice' => 'upload',
@@ -2992,33 +3118,34 @@  discard block
 block discarded – undo
2992 3118
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
2993 3119
 	}
2994 3120
 	// Use "avatar_original" here so we show what the user entered even if the image proxy is enabled
2995
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
2996
-		$context['member']['avatar'] += array(
3121
+	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3122
+			$context['member']['avatar'] += array(
2997 3123
 			'choice' => 'external',
2998 3124
 			'server_pic' => 'blank.png',
2999 3125
 			'external' => $cur_profile['avatar_original']
3000 3126
 		);
3001
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3002
-		$context['member']['avatar'] += array(
3127
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3128
+			$context['member']['avatar'] += array(
3003 3129
 			'choice' => 'server_stored',
3004 3130
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3005 3131
 			'external' => 'http://'
3006 3132
 		);
3007
-	else
3008
-		$context['member']['avatar'] += array(
3133
+	} else {
3134
+			$context['member']['avatar'] += array(
3009 3135
 			'choice' => 'none',
3010 3136
 			'server_pic' => 'blank.png',
3011 3137
 			'external' => 'http://'
3012 3138
 		);
3139
+	}
3013 3140
 
3014 3141
 	// Get a list of all the avatars.
3015 3142
 	if ($context['member']['avatar']['allow_server_stored'])
3016 3143
 	{
3017 3144
 		$context['avatar_list'] = array();
3018 3145
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3146
+	} else {
3147
+			$context['avatars'] = array();
3019 3148
 	}
3020
-	else
3021
-		$context['avatars'] = array();
3022 3149
 
3023 3150
 	// Second level selected avatar...
3024 3151
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3047,19 +3174,22 @@  discard block
 block discarded – undo
3047 3174
 			)
3048 3175
 		);
3049 3176
 		$protected_groups = array(1);
3050
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3051
-			$protected_groups[] = $row['id_group'];
3177
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3178
+					$protected_groups[] = $row['id_group'];
3179
+		}
3052 3180
 		$smcFunc['db_free_result']($request);
3053 3181
 
3054 3182
 		$protected_groups = array_unique($protected_groups);
3055 3183
 	}
3056 3184
 
3057 3185
 	// The account page allows the change of your id_group - but not to a protected group!
3058
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3059
-		$value = (int) $value;
3186
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3187
+			$value = (int) $value;
3188
+	}
3060 3189
 	// ... otherwise it's the old group sir.
3061
-	else
3062
-		$value = $old_profile['id_group'];
3190
+	else {
3191
+			$value = $old_profile['id_group'];
3192
+	}
3063 3193
 
3064 3194
 	// Find the additional membergroups (if any)
3065 3195
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3068,16 +3198,18 @@  discard block
 block discarded – undo
3068 3198
 		foreach ($_POST['additional_groups'] as $group_id)
3069 3199
 		{
3070 3200
 			$group_id = (int) $group_id;
3071
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3072
-				$additional_groups[] = $group_id;
3201
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3202
+							$additional_groups[] = $group_id;
3203
+			}
3073 3204
 		}
3074 3205
 
3075 3206
 		// Put the protected groups back in there if you don't have permission to take them away.
3076 3207
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3077 3208
 		foreach ($old_additional_groups as $group_id)
3078 3209
 		{
3079
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3080
-				$additional_groups[] = $group_id;
3210
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3211
+							$additional_groups[] = $group_id;
3212
+			}
3081 3213
 		}
3082 3214
 
3083 3215
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3109,18 +3241,20 @@  discard block
 block discarded – undo
3109 3241
 			list ($another) = $smcFunc['db_fetch_row']($request);
3110 3242
 			$smcFunc['db_free_result']($request);
3111 3243
 
3112
-			if (empty($another))
3113
-				fatal_lang_error('at_least_one_admin', 'critical');
3244
+			if (empty($another)) {
3245
+							fatal_lang_error('at_least_one_admin', 'critical');
3246
+			}
3114 3247
 		}
3115 3248
 	}
3116 3249
 
3117 3250
 	// If we are changing group status, update permission cache as necessary.
3118 3251
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3119 3252
 	{
3120
-		if ($context['user']['is_owner'])
3121
-			$_SESSION['mc']['time'] = 0;
3122
-		else
3123
-			updateSettings(array('settings_updated' => time()));
3253
+		if ($context['user']['is_owner']) {
3254
+					$_SESSION['mc']['time'] = 0;
3255
+		} else {
3256
+					updateSettings(array('settings_updated' => time()));
3257
+		}
3124 3258
 	}
3125 3259
 
3126 3260
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3141,8 +3275,9 @@  discard block
 block discarded – undo
3141 3275
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3142 3276
 
3143 3277
 	$memID = $context['id_member'];
3144
-	if (empty($memID) && !empty($context['password_auth_failed']))
3145
-		return false;
3278
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3279
+			return false;
3280
+	}
3146 3281
 
3147 3282
 	require_once($sourcedir . '/ManageAttachments.php');
3148 3283
 
@@ -3153,8 +3288,9 @@  discard block
 block discarded – undo
3153 3288
 	$downloadedExternalAvatar = false;
3154 3289
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3155 3290
 	{
3156
-		if (!is_writable($uploadDir))
3157
-			fatal_lang_error('attachments_no_write', 'critical');
3291
+		if (!is_writable($uploadDir)) {
3292
+					fatal_lang_error('attachments_no_write', 'critical');
3293
+		}
3158 3294
 
3159 3295
 		require_once($sourcedir . '/Subs-Package.php');
3160 3296
 
@@ -3198,19 +3334,18 @@  discard block
 block discarded – undo
3198 3334
 
3199 3335
 		// Get rid of their old avatar. (if uploaded.)
3200 3336
 		removeAttachments(array('id_member' => $memID));
3201
-	}
3202
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3337
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3203 3338
 	{
3204 3339
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3205
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3206
-			$profile_vars['avatar'] = 'gravatar://';
3207
-		else
3208
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3340
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3341
+					$profile_vars['avatar'] = 'gravatar://';
3342
+		} else {
3343
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3344
+		}
3209 3345
 
3210 3346
 		// Get rid of their old avatar. (if uploaded.)
3211 3347
 		removeAttachments(array('id_member' => $memID));
3212
-	}
3213
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3348
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3214 3349
 	{
3215 3350
 		// We need these clean...
3216 3351
 		$cur_profile['id_attach'] = 0;
@@ -3222,11 +3357,13 @@  discard block
 block discarded – undo
3222 3357
 
3223 3358
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3224 3359
 
3225
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3226
-			$profile_vars['avatar'] = '';
3360
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3361
+					$profile_vars['avatar'] = '';
3362
+		}
3227 3363
 		// Trying to make us do something we'll regret?
3228
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3229
-			return 'bad_avatar_invalid_url';
3364
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3365
+					return 'bad_avatar_invalid_url';
3366
+		}
3230 3367
 		// Should we check dimensions?
3231 3368
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3232 3369
 		{
@@ -3236,9 +3373,9 @@  discard block
 block discarded – undo
3236 3373
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3237 3374
 			{
3238 3375
 				// Houston, we have a problem. The avatar is too large!!
3239
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3240
-					return 'bad_avatar_too_large';
3241
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3376
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3377
+									return 'bad_avatar_too_large';
3378
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3242 3379
 				{
3243 3380
 					// @todo remove this if appropriate
3244 3381
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3248,26 +3385,27 @@  discard block
 block discarded – undo
3248 3385
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3249 3386
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3250 3387
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3388
+					} else {
3389
+											return 'bad_avatar';
3251 3390
 					}
3252
-					else
3253
-						return 'bad_avatar';
3254 3391
 				}
3255 3392
 			}
3256 3393
 		}
3257
-	}
3258
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3394
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3259 3395
 	{
3260 3396
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3261 3397
 		{
3262 3398
 			// Get the dimensions of the image.
3263 3399
 			if (!$downloadedExternalAvatar)
3264 3400
 			{
3265
-				if (!is_writable($uploadDir))
3266
-					fatal_lang_error('attachments_no_write', 'critical');
3401
+				if (!is_writable($uploadDir)) {
3402
+									fatal_lang_error('attachments_no_write', 'critical');
3403
+				}
3267 3404
 
3268 3405
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3269
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3270
-					fatal_lang_error('attach_timeout', 'critical');
3406
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3407
+									fatal_lang_error('attach_timeout', 'critical');
3408
+				}
3271 3409
 
3272 3410
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3273 3411
 			}
@@ -3380,17 +3518,19 @@  discard block
 block discarded – undo
3380 3518
 			$profile_vars['avatar'] = '';
3381 3519
 
3382 3520
 			// Delete any temporary file.
3383
-			if (file_exists($_FILES['attachment']['tmp_name']))
3384
-				@unlink($_FILES['attachment']['tmp_name']);
3521
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3522
+							@unlink($_FILES['attachment']['tmp_name']);
3523
+			}
3385 3524
 		}
3386 3525
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3387
-		else
3526
+		else {
3527
+					$profile_vars['avatar'] = '';
3528
+		}
3529
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3530
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3531
+	} else {
3388 3532
 			$profile_vars['avatar'] = '';
3389 3533
 	}
3390
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3391
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3392
-	else
3393
-		$profile_vars['avatar'] = '';
3394 3534
 
3395 3535
 	// Setup the profile variables so it shows things right on display!
3396 3536
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3438,9 +3578,9 @@  discard block
 block discarded – undo
3438 3578
 		$smiley_parsed = $unparsed_signature;
3439 3579
 		parsesmileys($smiley_parsed);
3440 3580
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3441
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3442
-			return 'signature_allow_smileys';
3443
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3581
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3582
+					return 'signature_allow_smileys';
3583
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3444 3584
 		{
3445 3585
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3446 3586
 			return 'signature_max_smileys';
@@ -3453,14 +3593,15 @@  discard block
 block discarded – undo
3453 3593
 			{
3454 3594
 				$limit_broke = 0;
3455 3595
 				// Attempt to allow all sizes of abuse, so to speak.
3456
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3457
-					$limit_broke = $sig_limits[7] . 'px';
3458
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3459
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3460
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3461
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3462
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3463
-					$limit_broke = 'large';
3596
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3597
+									$limit_broke = $sig_limits[7] . 'px';
3598
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3599
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3600
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3601
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3602
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3603
+									$limit_broke = 'large';
3604
+				}
3464 3605
 
3465 3606
 				if ($limit_broke)
3466 3607
 				{
@@ -3502,24 +3643,26 @@  discard block
 block discarded – undo
3502 3643
 					$width = -1; $height = -1;
3503 3644
 
3504 3645
 					// Does it have predefined restraints? Width first.
3505
-					if ($matches[6][$key])
3506
-						$matches[2][$key] = $matches[6][$key];
3646
+					if ($matches[6][$key]) {
3647
+											$matches[2][$key] = $matches[6][$key];
3648
+					}
3507 3649
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3508 3650
 					{
3509 3651
 						$width = $sig_limits[5];
3510 3652
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3653
+					} elseif ($matches[2][$key]) {
3654
+											$width = $matches[2][$key];
3511 3655
 					}
3512
-					elseif ($matches[2][$key])
3513
-						$width = $matches[2][$key];
3514 3656
 					// ... and height.
3515 3657
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3516 3658
 					{
3517 3659
 						$height = $sig_limits[6];
3518
-						if ($width != -1)
3519
-							$width = $width * ($height / $matches[4][$key]);
3660
+						if ($width != -1) {
3661
+													$width = $width * ($height / $matches[4][$key]);
3662
+						}
3663
+					} elseif ($matches[4][$key]) {
3664
+											$height = $matches[4][$key];
3520 3665
 					}
3521
-					elseif ($matches[4][$key])
3522
-						$height = $matches[4][$key];
3523 3666
 
3524 3667
 					// If the dimensions are still not fixed - we need to check the actual image.
3525 3668
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3537,21 +3680,24 @@  discard block
 block discarded – undo
3537 3680
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3538 3681
 							{
3539 3682
 								$height = $sig_limits[6];
3540
-								if ($width == -1)
3541
-									$width = $sizes[0];
3683
+								if ($width == -1) {
3684
+																	$width = $sizes[0];
3685
+								}
3542 3686
 								$width = $width * ($height / $sizes[1]);
3687
+							} elseif ($width != -1) {
3688
+															$height = $sizes[1];
3543 3689
 							}
3544
-							elseif ($width != -1)
3545
-								$height = $sizes[1];
3546 3690
 						}
3547 3691
 					}
3548 3692
 
3549 3693
 					// Did we come up with some changes? If so remake the string.
3550
-					if ($width != -1 || $height != -1)
3551
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3694
+					if ($width != -1 || $height != -1) {
3695
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3696
+					}
3697
+				}
3698
+				if (!empty($replaces)) {
3699
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3552 3700
 				}
3553
-				if (!empty($replaces))
3554
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3555 3701
 			}
3556 3702
 		}
3557 3703
 
@@ -3595,10 +3741,12 @@  discard block
 block discarded – undo
3595 3741
 	$email = strtr($email, array('&#039;' => '\''));
3596 3742
 
3597 3743
 	// Check the name and email for validity.
3598
-	if (trim($email) == '')
3599
-		return 'no_email';
3600
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3601
-		return 'bad_email';
3744
+	if (trim($email) == '') {
3745
+			return 'no_email';
3746
+	}
3747
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3748
+			return 'bad_email';
3749
+	}
3602 3750
 
3603 3751
 	// Email addresses should be and stay unique.
3604 3752
 	$request = $smcFunc['db_query']('', '
@@ -3613,8 +3761,9 @@  discard block
 block discarded – undo
3613 3761
 		)
3614 3762
 	);
3615 3763
 
3616
-	if ($smcFunc['db_num_rows']($request) > 0)
3617
-		return 'email_taken';
3764
+	if ($smcFunc['db_num_rows']($request) > 0) {
3765
+			return 'email_taken';
3766
+	}
3618 3767
 	$smcFunc['db_free_result']($request);
3619 3768
 
3620 3769
 	return true;
@@ -3627,8 +3776,9 @@  discard block
 block discarded – undo
3627 3776
 {
3628 3777
 	global $modSettings, $context, $cur_profile;
3629 3778
 
3630
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3631
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3779
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3780
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3781
+	}
3632 3782
 
3633 3783
 	loadUserSettings();
3634 3784
 	writeLog();
@@ -3644,8 +3794,9 @@  discard block
 block discarded – undo
3644 3794
 	require_once($sourcedir . '/Subs-Post.php');
3645 3795
 
3646 3796
 	// Shouldn't happen but just in case.
3647
-	if (empty($profile_vars['email_address']))
3648
-		return;
3797
+	if (empty($profile_vars['email_address'])) {
3798
+			return;
3799
+	}
3649 3800
 
3650 3801
 	$replacements = array(
3651 3802
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3668,8 +3819,9 @@  discard block
 block discarded – undo
3668 3819
 	$_SESSION['log_time'] = 0;
3669 3820
 	$_SESSION['login_' . $cookiename] = json_encode(array(0, '', 0));
3670 3821
 
3671
-	if (isset($_COOKIE[$cookiename]))
3672
-		$_COOKIE[$cookiename] = '';
3822
+	if (isset($_COOKIE[$cookiename])) {
3823
+			$_COOKIE[$cookiename] = '';
3824
+	}
3673 3825
 
3674 3826
 	loadUserSettings();
3675 3827
 
@@ -3702,11 +3854,13 @@  discard block
 block discarded – undo
3702 3854
 	$groups[] = $curMember['id_group'];
3703 3855
 
3704 3856
 	// Ensure the query doesn't croak!
3705
-	if (empty($groups))
3706
-		$groups = array(0);
3857
+	if (empty($groups)) {
3858
+			$groups = array(0);
3859
+	}
3707 3860
 	// Just to be sure...
3708
-	foreach ($groups as $k => $v)
3709
-		$groups[$k] = (int) $v;
3861
+	foreach ($groups as $k => $v) {
3862
+			$groups[$k] = (int) $v;
3863
+	}
3710 3864
 
3711 3865
 	// Get all the membergroups they can join.
3712 3866
 	$request = $smcFunc['db_query']('', '
@@ -3736,12 +3890,14 @@  discard block
 block discarded – undo
3736 3890
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3737 3891
 	{
3738 3892
 		// Can they edit their primary group?
3739
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3740
-			$context['can_edit_primary'] = true;
3893
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3894
+					$context['can_edit_primary'] = true;
3895
+		}
3741 3896
 
3742 3897
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3743
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3744
-			continue;
3898
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3899
+					continue;
3900
+		}
3745 3901
 
3746 3902
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3747 3903
 			'id' => $row['id_group'],
@@ -3770,13 +3926,15 @@  discard block
 block discarded – undo
3770 3926
 	);
3771 3927
 
3772 3928
 	// No changing primary one unless you have enough groups!
3773
-	if (count($context['groups']['member']) < 2)
3774
-		$context['can_edit_primary'] = false;
3929
+	if (count($context['groups']['member']) < 2) {
3930
+			$context['can_edit_primary'] = false;
3931
+	}
3775 3932
 
3776 3933
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3777
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3778
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3779
-}
3934
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3935
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3936
+	}
3937
+	}
3780 3938
 
3781 3939
 /**
3782 3940
  * This function actually makes all the group changes
@@ -3791,10 +3949,12 @@  discard block
 block discarded – undo
3791 3949
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3792 3950
 
3793 3951
 	// Let's be extra cautious...
3794
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3795
-		isAllowedTo('manage_membergroups');
3796
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3797
-		fatal_lang_error('no_access', false);
3952
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3953
+			isAllowedTo('manage_membergroups');
3954
+	}
3955
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3956
+			fatal_lang_error('no_access', false);
3957
+	}
3798 3958
 
3799 3959
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3800 3960
 
@@ -3813,8 +3973,9 @@  discard block
 block discarded – undo
3813 3973
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3814 3974
 
3815 3975
 	// Sanity check!!
3816
-	if ($group_id == 1)
3817
-		isAllowedTo('admin_forum');
3976
+	if ($group_id == 1) {
3977
+			isAllowedTo('admin_forum');
3978
+	}
3818 3979
 	// Protected groups too!
3819 3980
 	else
3820 3981
 	{
@@ -3831,8 +3992,9 @@  discard block
 block discarded – undo
3831 3992
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3832 3993
 		$smcFunc['db_free_result']($request);
3833 3994
 
3834
-		if ($is_protected == 1)
3835
-			isAllowedTo('admin_forum');
3995
+		if ($is_protected == 1) {
3996
+					isAllowedTo('admin_forum');
3997
+		}
3836 3998
 	}
3837 3999
 
3838 4000
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3854,36 +4016,43 @@  discard block
 block discarded – undo
3854 4016
 			$group_name = $row['group_name'];
3855 4017
 
3856 4018
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3857
-			if ($changeType == 'request' && $row['group_type'] != 2)
3858
-				fatal_lang_error('no_access', false);
4019
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4020
+							fatal_lang_error('no_access', false);
4021
+			}
3859 4022
 			// What about leaving a requestable group we are not a member of?
3860
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3861
-				fatal_lang_error('no_access', false);
3862
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3863
-				fatal_lang_error('no_access', false);
4023
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4024
+							fatal_lang_error('no_access', false);
4025
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4026
+							fatal_lang_error('no_access', false);
4027
+			}
3864 4028
 
3865 4029
 			// We can't change the primary group if this is hidden!
3866
-			if ($row['hidden'] == 2)
3867
-				$canChangePrimary = false;
4030
+			if ($row['hidden'] == 2) {
4031
+							$canChangePrimary = false;
4032
+			}
3868 4033
 		}
3869 4034
 
3870 4035
 		// If this is their old primary, can we change it?
3871
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3872
-			$canChangePrimary = 1;
4036
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4037
+					$canChangePrimary = 1;
4038
+		}
3873 4039
 
3874 4040
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3875
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3876
-			$canChangePrimary = false;
4041
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4042
+					$canChangePrimary = false;
4043
+		}
3877 4044
 
3878 4045
 		// If this is the one we are acting on, can we even act?
3879
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3880
-			$canChangePrimary = false;
4046
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4047
+					$canChangePrimary = false;
4048
+		}
3881 4049
 	}
3882 4050
 	$smcFunc['db_free_result']($request);
3883 4051
 
3884 4052
 	// Didn't find the target?
3885
-	if (!$foundTarget)
3886
-		fatal_lang_error('no_access', false);
4053
+	if (!$foundTarget) {
4054
+			fatal_lang_error('no_access', false);
4055
+	}
3887 4056
 
3888 4057
 	// Final security check, don't allow users to promote themselves to admin.
3889 4058
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3903,8 +4072,9 @@  discard block
 block discarded – undo
3903 4072
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3904 4073
 		$smcFunc['db_free_result']($request);
3905 4074
 
3906
-		if ($disallow)
3907
-			isAllowedTo('admin_forum');
4075
+		if ($disallow) {
4076
+					isAllowedTo('admin_forum');
4077
+		}
3908 4078
 	}
3909 4079
 
3910 4080
 	// If we're requesting, add the note then return.
@@ -3922,8 +4092,9 @@  discard block
 block discarded – undo
3922 4092
 				'status_open' => 0,
3923 4093
 			)
3924 4094
 		);
3925
-		if ($smcFunc['db_num_rows']($request) != 0)
3926
-			fatal_lang_error('profile_error_already_requested_group');
4095
+		if ($smcFunc['db_num_rows']($request) != 0) {
4096
+					fatal_lang_error('profile_error_already_requested_group');
4097
+		}
3927 4098
 		$smcFunc['db_free_result']($request);
3928 4099
 
3929 4100
 		// Log the request.
@@ -3957,10 +4128,11 @@  discard block
 block discarded – undo
3957 4128
 		// Are we leaving?
3958 4129
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3959 4130
 		{
3960
-			if ($old_profile['id_group'] == $group_id)
3961
-				$newPrimary = 0;
3962
-			else
3963
-				unset($addGroups[$group_id]);
4131
+			if ($old_profile['id_group'] == $group_id) {
4132
+							$newPrimary = 0;
4133
+			} else {
4134
+							unset($addGroups[$group_id]);
4135
+			}
3964 4136
 		}
3965 4137
 		// ... if not, must be joining.
3966 4138
 		else
@@ -3968,36 +4140,42 @@  discard block
 block discarded – undo
3968 4140
 			// Can we change the primary, and do we want to?
3969 4141
 			if ($canChangePrimary)
3970 4142
 			{
3971
-				if ($old_profile['id_group'] != 0)
3972
-					$addGroups[$old_profile['id_group']] = -1;
4143
+				if ($old_profile['id_group'] != 0) {
4144
+									$addGroups[$old_profile['id_group']] = -1;
4145
+				}
3973 4146
 				$newPrimary = $group_id;
3974 4147
 			}
3975 4148
 			// Otherwise it's an additional group...
3976
-			else
3977
-				$addGroups[$group_id] = -1;
4149
+			else {
4150
+							$addGroups[$group_id] = -1;
4151
+			}
3978 4152
 		}
3979 4153
 	}
3980 4154
 	// Finally, we must be setting the primary.
3981 4155
 	elseif ($canChangePrimary)
3982 4156
 	{
3983
-		if ($old_profile['id_group'] != 0)
3984
-			$addGroups[$old_profile['id_group']] = -1;
3985
-		if (isset($addGroups[$group_id]))
3986
-			unset($addGroups[$group_id]);
4157
+		if ($old_profile['id_group'] != 0) {
4158
+					$addGroups[$old_profile['id_group']] = -1;
4159
+		}
4160
+		if (isset($addGroups[$group_id])) {
4161
+					unset($addGroups[$group_id]);
4162
+		}
3987 4163
 		$newPrimary = $group_id;
3988 4164
 	}
3989 4165
 
3990 4166
 	// Finally, we can make the changes!
3991
-	foreach ($addGroups as $id => $dummy)
3992
-		if (empty($id))
4167
+	foreach ($addGroups as $id => $dummy) {
4168
+			if (empty($id))
3993 4169
 			unset($addGroups[$id]);
4170
+	}
3994 4171
 	$addGroups = implode(',', array_flip($addGroups));
3995 4172
 
3996 4173
 	// Ensure that we don't cache permissions if the group is changing.
3997
-	if ($context['user']['is_owner'])
3998
-		$_SESSION['mc']['time'] = 0;
3999
-	else
4000
-		updateSettings(array('settings_updated' => time()));
4174
+	if ($context['user']['is_owner']) {
4175
+			$_SESSION['mc']['time'] = 0;
4176
+	} else {
4177
+			updateSettings(array('settings_updated' => time()));
4178
+	}
4001 4179
 
4002 4180
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4003 4181
 
@@ -4020,8 +4198,9 @@  discard block
 block discarded – undo
4020 4198
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4021 4199
 	{
4022 4200
 		// Check to ensure we're forcing SSL for authentication
4023
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
4024
-			fatal_lang_error('login_ssl_required');
4201
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
4202
+					fatal_lang_error('login_ssl_required');
4203
+		}
4025 4204
 
4026 4205
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4027 4206
 		// we do not want too much AJAX to confuse them.
@@ -4058,8 +4237,7 @@  discard block
 block discarded – undo
4058 4237
 				$context['sub_template'] = 'tfasetup_backup';
4059 4238
 
4060 4239
 				return;
4061
-			}
4062
-			else
4240
+			} else
4063 4241
 			{
4064 4242
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4065 4243
 				$context['tfa_error'] = !$valid_code;
@@ -4067,8 +4245,7 @@  discard block
 block discarded – undo
4067 4245
 				$context['tfa_pass_value'] = $_POST['passwd'];
4068 4246
 				$context['tfa_value'] = $_POST['tfa_code'];
4069 4247
 			}
4070
-		}
4071
-		else
4248
+		} else
4072 4249
 		{
4073 4250
 			$totp = new \TOTP\Auth();
4074 4251
 			$secret = $totp->generateCode();
@@ -4078,17 +4255,16 @@  discard block
 block discarded – undo
4078 4255
 		}
4079 4256
 
4080 4257
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4081
-	}
4082
-	elseif (isset($_REQUEST['disable']))
4258
+	} elseif (isset($_REQUEST['disable']))
4083 4259
 	{
4084 4260
 		updateMemberData($memID, array(
4085 4261
 			'tfa_secret' => '',
4086 4262
 			'tfa_backup' => '',
4087 4263
 		));
4088 4264
 		redirectexit('action=profile;area=account;u=' . $memID);
4265
+	} else {
4266
+			redirectexit('action=profile;area=account;u=' . $memID);
4267
+	}
4089 4268
 	}
4090
-	else
4091
-		redirectexit('action=profile;area=account;u=' . $memID);
4092
-}
4093 4269
 
4094 4270
 ?>
4095 4271
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/RepairBoards.php 1 patch
Braces   +119 added lines, -85 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
  * Finds or repairs errors in the database to fix possible problems.
@@ -50,8 +51,9 @@  discard block
 block discarded – undo
50 51
 	);
51 52
 
52 53
 	// Start displaying errors without fixing them.
53
-	if (isset($_GET['fixErrors']))
54
-		checkSession('get');
54
+	if (isset($_GET['fixErrors'])) {
55
+			checkSession('get');
56
+	}
55 57
 
56 58
 	// Will want this.
57 59
 	loadForumTests();
@@ -69,11 +71,11 @@  discard block
 block discarded – undo
69 71
 			$_SESSION['repairboards_to_fix'] = $context['to_fix'];
70 72
 			$_SESSION['repairboards_to_fix2'] = null;
71 73
 
72
-			if (empty($context['repair_errors']))
73
-				$context['repair_errors'][] = '???';
74
+			if (empty($context['repair_errors'])) {
75
+							$context['repair_errors'][] = '???';
76
+			}
74 77
 		}
75
-	}
76
-	else
78
+	} else
77 79
 	{
78 80
 		$context['error_search'] = false;
79 81
 		$context['to_fix'] = isset($_SESSION['repairboards_to_fix']) ? $_SESSION['repairboards_to_fix'] : array();
@@ -120,16 +122,19 @@  discard block
 block discarded – undo
120 122
 
121 123
 	// More time, I need more time!
122 124
 	@set_time_limit(600);
123
-	if (function_exists('apache_reset_timeout'))
124
-		@apache_reset_timeout();
125
+	if (function_exists('apache_reset_timeout')) {
126
+			@apache_reset_timeout();
127
+	}
125 128
 
126 129
 	// Errr, wait.  How much time has this taken already?
127
-	if (!$force && time() - array_sum(explode(' ', $time_start)) < 3)
128
-		return;
130
+	if (!$force && time() - array_sum(explode(' ', $time_start)) < 3) {
131
+			return;
132
+	}
129 133
 
130 134
 	// Restore the query cache if interested.
131
-	if (!empty($db_temp_cache))
132
-		$db_cache = $db_temp_cache;
135
+	if (!empty($db_temp_cache)) {
136
+			$db_cache = $db_temp_cache;
137
+	}
133 138
 
134 139
 	$context['continue_get_data'] = '?action=admin;area=repairboards' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id'];
135 140
 	$context['page_title'] = $txt['not_done_title'];
@@ -138,10 +143,11 @@  discard block
 block discarded – undo
138 143
 	$context['sub_template'] = 'not_done';
139 144
 
140 145
 	// Change these two if more steps are added!
141
-	if (empty($max_substep))
142
-		$context['continue_percent'] = round(($_GET['step'] * 100) / $context['total_steps']);
143
-	else
144
-		$context['continue_percent'] = round((($_GET['step'] + ($_GET['substep'] / $max_substep)) * 100) / $context['total_steps']);
146
+	if (empty($max_substep)) {
147
+			$context['continue_percent'] = round(($_GET['step'] * 100) / $context['total_steps']);
148
+	} else {
149
+			$context['continue_percent'] = round((($_GET['step'] + ($_GET['substep'] / $max_substep)) * 100) / $context['total_steps']);
150
+	}
145 151
 
146 152
 	// Never more than 100%!
147 153
 	$context['continue_percent'] = min($context['continue_percent'], 100);
@@ -612,8 +618,9 @@  discard block
 block discarded – undo
612 618
 				$row['myid_last_msg'] = (int) $row['myid_last_msg'];
613 619
 
614 620
 				// Not really a problem?
615
-				if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved'])
616
-					return false;
621
+				if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) {
622
+									return false;
623
+				}
617 624
 
618 625
 				$memberStartedID = (int) getMsgMemberID($row['myid_first_msg']);
619 626
 				$memberUpdatedID = (int) getMsgMemberID($row['myid_last_msg']);
@@ -637,15 +644,19 @@  discard block
 block discarded – undo
637 644
 			'message_function' => function ($row) use ($txt, &$context)
638 645
 			{
639 646
 				// A pretend error?
640
-				if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved'])
641
-					return false;
647
+				if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) {
648
+									return false;
649
+				}
642 650
 
643
-				if ($row['id_first_msg'] != $row['myid_first_msg'])
644
-					$context['repair_errors'][] = sprintf($txt['repair_stats_topics_1'], $row['id_topic'], $row['id_first_msg']);
645
-				if ($row['id_last_msg'] != $row['myid_last_msg'])
646
-					$context['repair_errors'][] = sprintf($txt['repair_stats_topics_2'], $row['id_topic'], $row['id_last_msg']);
647
-				if ($row['approved'] != $row['firstmsg_approved'])
648
-					$context['repair_errors'][] = sprintf($txt['repair_stats_topics_5'], $row['id_topic']);
651
+				if ($row['id_first_msg'] != $row['myid_first_msg']) {
652
+									$context['repair_errors'][] = sprintf($txt['repair_stats_topics_1'], $row['id_topic'], $row['id_first_msg']);
653
+				}
654
+				if ($row['id_last_msg'] != $row['myid_last_msg']) {
655
+									$context['repair_errors'][] = sprintf($txt['repair_stats_topics_2'], $row['id_topic'], $row['id_last_msg']);
656
+				}
657
+				if ($row['approved'] != $row['firstmsg_approved']) {
658
+									$context['repair_errors'][] = sprintf($txt['repair_stats_topics_5'], $row['id_topic']);
659
+				}
649 660
 
650 661
 				return true;
651 662
 			},
@@ -675,8 +686,9 @@  discard block
 block discarded – undo
675 686
 				$row['my_num_replies'] = (int) $row['my_num_replies'];
676 687
 
677 688
 				// Not really a problem?
678
-				if ($row['my_num_replies'] == $row['num_replies'])
679
-					return false;
689
+				if ($row['my_num_replies'] == $row['num_replies']) {
690
+									return false;
691
+				}
680 692
 
681 693
 				$smcFunc['db_query']('', '
682 694
 					UPDATE {db_prefix}topics
@@ -695,11 +707,13 @@  discard block
 block discarded – undo
695 707
 				global $txt, $context;
696 708
 
697 709
 				// Just joking?
698
-				if ($row['my_num_replies'] == $row['num_replies'])
699
-					return false;
710
+				if ($row['my_num_replies'] == $row['num_replies']) {
711
+									return false;
712
+				}
700 713
 
701
-				if ($row['num_replies'] != $row['my_num_replies'])
702
-					$context['repair_errors'][] = sprintf($txt['repair_stats_topics_3'], $row['id_topic'], $row['num_replies']);
714
+				if ($row['num_replies'] != $row['my_num_replies']) {
715
+									$context['repair_errors'][] = sprintf($txt['repair_stats_topics_3'], $row['id_topic'], $row['num_replies']);
716
+				}
703 717
 
704 718
 				return true;
705 719
 
@@ -1290,8 +1304,9 @@  discard block
 block discarded – undo
1290 1304
 				$inserts = array();
1291 1305
 				while ($row = $smcFunc['db_fetch_assoc']($result))
1292 1306
 				{
1293
-					foreach (text2words($row['subject']) as $word)
1294
-						$inserts[] = array($word, $row['id_topic']);
1307
+					foreach (text2words($row['subject']) as $word) {
1308
+											$inserts[] = array($word, $row['id_topic']);
1309
+					}
1295 1310
 					if (count($inserts) > 500)
1296 1311
 					{
1297 1312
 						$smcFunc['db_insert']('ignore',
@@ -1305,13 +1320,14 @@  discard block
 block discarded – undo
1305 1320
 
1306 1321
 				}
1307 1322
 
1308
-				if (!empty($inserts))
1309
-					$smcFunc['db_insert']('ignore',
1323
+				if (!empty($inserts)) {
1324
+									$smcFunc['db_insert']('ignore',
1310 1325
 						'{db_prefix}log_search_subjects',
1311 1326
 						array('word' => 'string', 'id_topic' => 'int'),
1312 1327
 						$inserts,
1313 1328
 						array('word', 'id_topic')
1314 1329
 					);
1330
+				}
1315 1331
 
1316 1332
 		},
1317 1333
 			'message_function' => function ($row)
@@ -1581,8 +1597,9 @@  discard block
 block discarded – undo
1581 1597
 		$current_step++;
1582 1598
 
1583 1599
 		// Already done this?
1584
-		if ($_GET['step'] > $current_step)
1585
-			continue;
1600
+		if ($_GET['step'] > $current_step) {
1601
+					continue;
1602
+		}
1586 1603
 
1587 1604
 		// If we're fixing it but it ain't broke why try?
1588 1605
 		if ($do_fix && !in_array($error_type, $to_fix))
@@ -1611,14 +1628,16 @@  discard block
 block discarded – undo
1611 1628
 		while (!$done)
1612 1629
 		{
1613 1630
 			// Make sure there's at least one ID to test.
1614
-			if (isset($test['substeps']) && empty($step_max))
1615
-				break;
1631
+			if (isset($test['substeps']) && empty($step_max)) {
1632
+							break;
1633
+			}
1616 1634
 
1617 1635
 			// What is the testing query (Changes if we are testing or fixing)
1618
-			if (!$do_fix)
1619
-				$test_query = 'check_query';
1620
-			else
1621
-				$test_query = isset($test['fix_query']) ? 'fix_query' : 'check_query';
1636
+			if (!$do_fix) {
1637
+							$test_query = 'check_query';
1638
+			} else {
1639
+							$test_query = isset($test['fix_query']) ? 'fix_query' : 'check_query';
1640
+			}
1622 1641
 
1623 1642
 			// Do the test...
1624 1643
 			$request = $smcFunc['db_query']('',
@@ -1628,10 +1647,11 @@  discard block
 block discarded – undo
1628 1647
 			);
1629 1648
 
1630 1649
 			// Does it need a fix?
1631
-			if (!empty($test['check_type']) && $test['check_type'] == 'count')
1632
-				list ($needs_fix) = $smcFunc['db_fetch_row']($request);
1633
-			else
1634
-				$needs_fix = $smcFunc['db_num_rows']($request);
1650
+			if (!empty($test['check_type']) && $test['check_type'] == 'count') {
1651
+							list ($needs_fix) = $smcFunc['db_fetch_row']($request);
1652
+			} else {
1653
+							$needs_fix = $smcFunc['db_num_rows']($request);
1654
+			}
1635 1655
 
1636 1656
 			$total_queries++;
1637 1657
 
@@ -1643,8 +1663,9 @@  discard block
 block discarded – undo
1643 1663
 					// Assume need to fix.
1644 1664
 					$found_errors = true;
1645 1665
 
1646
-					if (isset($test['message']))
1647
-						$context['repair_errors'][] = $txt[$test['message']];
1666
+					if (isset($test['message'])) {
1667
+											$context['repair_errors'][] = $txt[$test['message']];
1668
+					}
1648 1669
 
1649 1670
 					// One per row!
1650 1671
 					elseif (isset($test['messages']))
@@ -1654,10 +1675,11 @@  discard block
 block discarded – undo
1654 1675
 							$variables = $test['messages'];
1655 1676
 							foreach ($variables as $k => $v)
1656 1677
 							{
1657
-								if ($k == 0 && isset($txt[$v]))
1658
-									$variables[$k] = $txt[$v];
1659
-								elseif ($k > 0 && isset($row[$v]))
1660
-									$variables[$k] = $row[$v];
1678
+								if ($k == 0 && isset($txt[$v])) {
1679
+																	$variables[$k] = $txt[$v];
1680
+								} elseif ($k > 0 && isset($row[$v])) {
1681
+																	$variables[$k] = $row[$v];
1682
+								}
1661 1683
 							}
1662 1684
 							$context['repair_errors'][] = call_user_func_array('sprintf', $variables);
1663 1685
 						}
@@ -1668,13 +1690,15 @@  discard block
 block discarded – undo
1668 1690
 					{
1669 1691
 						// Find out if there are actually errors.
1670 1692
 						$found_errors = false;
1671
-						while ($row = $smcFunc['db_fetch_assoc']($request))
1672
-							$found_errors |= $test['message_function']($row);
1693
+						while ($row = $smcFunc['db_fetch_assoc']($request)) {
1694
+													$found_errors |= $test['message_function']($row);
1695
+						}
1673 1696
 					}
1674 1697
 
1675 1698
 					// Actually have something to fix?
1676
-					if ($found_errors)
1677
-						$to_fix[] = $error_type;
1699
+					if ($found_errors) {
1700
+											$to_fix[] = $error_type;
1701
+					}
1678 1702
 				}
1679 1703
 
1680 1704
 				// We want to fix, we need to fix - so work out what exactly to do!
@@ -1684,8 +1708,9 @@  discard block
 block discarded – undo
1684 1708
 					if (isset($test['fix_collect']))
1685 1709
 					{
1686 1710
 						$ids = array();
1687
-						while ($row = $smcFunc['db_fetch_assoc']($request))
1688
-							$ids[] = $row[$test['fix_collect']['index']];
1711
+						while ($row = $smcFunc['db_fetch_assoc']($request)) {
1712
+													$ids[] = $row[$test['fix_collect']['index']];
1713
+						}
1689 1714
 						if (!empty($ids))
1690 1715
 						{
1691 1716
 							// Fix it!
@@ -1694,30 +1719,34 @@  discard block
 block discarded – undo
1694 1719
 					}
1695 1720
 
1696 1721
 					// Simply executing a fix it query?
1697
-					elseif (isset($test['fix_it_query']))
1698
-						$smcFunc['db_query']('',
1722
+					elseif (isset($test['fix_it_query'])) {
1723
+											$smcFunc['db_query']('',
1699 1724
 							$test['fix_it_query'],
1700 1725
 							array(
1701 1726
 							)
1702 1727
 						);
1728
+					}
1703 1729
 
1704 1730
 					// Do we have some processing to do?
1705 1731
 					elseif (isset($test['fix_processing']))
1706 1732
 					{
1707
-						while ($row = $smcFunc['db_fetch_assoc']($request))
1708
-							$test['fix_processing']($row);
1733
+						while ($row = $smcFunc['db_fetch_assoc']($request)) {
1734
+													$test['fix_processing']($row);
1735
+						}
1709 1736
 					}
1710 1737
 
1711 1738
 					// What about the full set of processing?
1712
-					elseif (isset($test['fix_full_processing']))
1713
-						$test['fix_full_processing']($request);
1739
+					elseif (isset($test['fix_full_processing'])) {
1740
+											$test['fix_full_processing']($request);
1741
+					}
1714 1742
 
1715 1743
 					// Do we have other things we need to fix as a result?
1716 1744
 					if (!empty($test['force_fix']))
1717 1745
 					{
1718
-						foreach ($test['force_fix'] as $item)
1719
-							if (!in_array($item, $to_fix))
1746
+						foreach ($test['force_fix'] as $item) {
1747
+													if (!in_array($item, $to_fix))
1720 1748
 								$to_fix[] = $item;
1749
+						}
1721 1750
 					}
1722 1751
 				}
1723 1752
 			}
@@ -1735,16 +1764,17 @@  discard block
 block discarded – undo
1735 1764
 				if ($_GET['substep'] <= $step_max)
1736 1765
 				{
1737 1766
 					pauseRepairProcess($to_fix, $error_type, $step_max);
1767
+				} else {
1768
+									$done = true;
1738 1769
 				}
1739
-				else
1740
-					$done = true;
1770
+			} else {
1771
+							$done = true;
1741 1772
 			}
1742
-			else
1743
-				$done = true;
1744 1773
 
1745 1774
 			// Don't allow more than 1000 queries at a time.
1746
-			if ($total_queries >= 1000)
1747
-				pauseRepairProcess($to_fix, $error_type, $step_max, true);
1775
+			if ($total_queries >= 1000) {
1776
+							pauseRepairProcess($to_fix, $error_type, $step_max, true);
1777
+			}
1748 1778
 		}
1749 1779
 
1750 1780
 		// Keep going.
@@ -1757,8 +1787,9 @@  discard block
 block discarded – undo
1757 1787
 		if ($do_fix)
1758 1788
 		{
1759 1789
 			$key = array_search($error_type, $to_fix);
1760
-			if ($key !== false && isset($to_fix[$key]))
1761
-				unset($to_fix[$key]);
1790
+			if ($key !== false && isset($to_fix[$key])) {
1791
+							unset($to_fix[$key]);
1792
+			}
1762 1793
 		}
1763 1794
 
1764 1795
 		// Are we done?
@@ -1781,10 +1812,11 @@  discard block
 block discarded – undo
1781 1812
 	static $createOnce = false;
1782 1813
 
1783 1814
 	// Have we already created it?
1784
-	if ($createOnce)
1785
-		return;
1786
-	else
1787
-		$createOnce = true;
1815
+	if ($createOnce) {
1816
+			return;
1817
+	} else {
1818
+			$createOnce = true;
1819
+	}
1788 1820
 
1789 1821
 	// Back to the forum's default language.
1790 1822
 	loadLanguage('Admin', $language);
@@ -1799,8 +1831,9 @@  discard block
 block discarded – undo
1799 1831
 			'cat_name' => $txt['salvaged_category_name'],
1800 1832
 		)
1801 1833
 	);
1802
-	if ($smcFunc['db_num_rows']($result) != 0)
1803
-		list ($salvageCatID) = $smcFunc['db_fetch_row']($result);
1834
+	if ($smcFunc['db_num_rows']($result) != 0) {
1835
+			list ($salvageCatID) = $smcFunc['db_fetch_row']($result);
1836
+	}
1804 1837
 	$smcFunc['db_free_result']($result);
1805 1838
 
1806 1839
 	if (empty($salvageCatID))
@@ -1832,8 +1865,9 @@  discard block
 block discarded – undo
1832 1865
 			'board_name' => $txt['salvaged_board_name'],
1833 1866
 		)
1834 1867
 	);
1835
-	if ($smcFunc['db_num_rows']($result) != 0)
1836
-		list ($salvageBoardID) = $smcFunc['db_fetch_row']($result);
1868
+	if ($smcFunc['db_num_rows']($result) != 0) {
1869
+			list ($salvageBoardID) = $smcFunc['db_fetch_row']($result);
1870
+	}
1837 1871
 	$smcFunc['db_free_result']($result);
1838 1872
 
1839 1873
 	if (empty($salvageBoardID))
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, $smcFunc)
88 98
 	{
89
-		if (!$utf8 || $smcFunc['db_mb4'])
90
-			return $string;
99
+		if (!$utf8 || $smcFunc['db_mb4']) {
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;
@@ -1283,13 +1340,16 @@  discard block
 block discarded – undo
1283 1340
 			$row['avatar_original'] = $row['avatar'];
1284 1341
 
1285 1342
 			// Take care of proxying avatar if required, do this here for maximum reach
1286
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1287
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1343
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1344
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1345
+			}
1288 1346
 
1289
-			if (isset($row['member_ip']))
1290
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1291
-			if (isset($row['member_ip2']))
1292
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1347
+			if (isset($row['member_ip'])) {
1348
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1349
+			}
1350
+			if (isset($row['member_ip2'])) {
1351
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1352
+			}
1293 1353
 			$new_loaded_ids[] = $row['id_member'];
1294 1354
 			$loaded_ids[] = $row['id_member'];
1295 1355
 			$row['options'] = array();
@@ -1308,8 +1368,9 @@  discard block
 block discarded – undo
1308 1368
 				'loaded_ids' => $new_loaded_ids,
1309 1369
 			)
1310 1370
 		);
1311
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1312
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1371
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1372
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1373
+		}
1313 1374
 		$smcFunc['db_free_result']($request);
1314 1375
 	}
1315 1376
 
@@ -1320,10 +1381,11 @@  discard block
 block discarded – undo
1320 1381
 	{
1321 1382
 		foreach ($loaded_ids as $a_member)
1322 1383
 		{
1323
-			if (!empty($user_profile[$a_member]['additional_groups']))
1324
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1325
-			else
1326
-				$groups = array($user_profile[$a_member]['id_group']);
1384
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1385
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1386
+			} else {
1387
+							$groups = array($user_profile[$a_member]['id_group']);
1388
+			}
1327 1389
 
1328 1390
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1329 1391
 
@@ -1336,8 +1398,9 @@  discard block
 block discarded – undo
1336 1398
 
1337 1399
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1338 1400
 	{
1339
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1340
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1401
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1402
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1403
+		}
1341 1404
 	}
1342 1405
 
1343 1406
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1363,14 +1426,17 @@  discard block
 block discarded – undo
1363 1426
 		foreach ($temp_mods as $id)
1364 1427
 		{
1365 1428
 			// By popular demand, don't show admins or global moderators as moderators.
1366
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1367
-				$user_profile[$id]['member_group'] = $row['member_group'];
1429
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1430
+							$user_profile[$id]['member_group'] = $row['member_group'];
1431
+			}
1368 1432
 
1369 1433
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1370
-			if (!empty($row['icons']))
1371
-				$user_profile[$id]['icons'] = $row['icons'];
1372
-			if (!empty($row['member_group_color']))
1373
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1434
+			if (!empty($row['icons'])) {
1435
+							$user_profile[$id]['icons'] = $row['icons'];
1436
+			}
1437
+			if (!empty($row['member_group_color'])) {
1438
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1439
+			}
1374 1440
 		}
1375 1441
 	}
1376 1442
 
@@ -1392,12 +1458,14 @@  discard block
 block discarded – undo
1392 1458
 	static $loadedLanguages = array();
1393 1459
 
1394 1460
 	// If this person's data is already loaded, skip it.
1395
-	if (isset($dataLoaded[$user]))
1396
-		return true;
1461
+	if (isset($dataLoaded[$user])) {
1462
+			return true;
1463
+	}
1397 1464
 
1398 1465
 	// We can't load guests or members not loaded by loadMemberData()!
1399
-	if ($user == 0)
1400
-		return false;
1466
+	if ($user == 0) {
1467
+			return false;
1468
+	}
1401 1469
 	if (!isset($user_profile[$user]))
1402 1470
 	{
1403 1471
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1423,12 +1491,16 @@  discard block
 block discarded – undo
1423 1491
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1424 1492
 
1425 1493
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1426
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1494
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1495
+		//icon is set and exists
1427 1496
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1428
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1497
+	} elseif (isset($profile['icons'][1])) {
1498
+		//icon is set and doesn't exist, fallback to default
1429 1499
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1430
-	else //not set, bye bye
1500
+	} else {
1501
+		//not set, bye bye
1431 1502
 		$group_icon_url = '';
1503
+	}
1432 1504
 
1433 1505
 	// These minimal values are always loaded
1434 1506
 	$memberContext[$user] = array(
@@ -1447,8 +1519,9 @@  discard block
 block discarded – undo
1447 1519
 	if ($context['loadMemberContext_set'] != 'minimal')
1448 1520
 	{
1449 1521
 		// Go the extra mile and load the user's native language name.
1450
-		if (empty($loadedLanguages))
1451
-			$loadedLanguages = getLanguages();
1522
+		if (empty($loadedLanguages)) {
1523
+					$loadedLanguages = getLanguages();
1524
+		}
1452 1525
 
1453 1526
 		$memberContext[$user] += array(
1454 1527
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1502,31 +1575,33 @@  discard block
 block discarded – undo
1502 1575
 	{
1503 1576
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1504 1577
 		{
1505
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1506
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1507
-			else
1508
-				$image = get_gravatar_url($profile['email_address']);
1509
-		}
1510
-		else
1578
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1579
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1580
+			} else {
1581
+							$image = get_gravatar_url($profile['email_address']);
1582
+			}
1583
+		} else
1511 1584
 		{
1512 1585
 			// So it's stored in the member table?
1513 1586
 			if (!empty($profile['avatar']))
1514 1587
 			{
1515 1588
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1589
+			} elseif (!empty($profile['filename'])) {
1590
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1516 1591
 			}
1517
-			elseif (!empty($profile['filename']))
1518
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1519 1592
 			// Right... no avatar...use the default one
1520
-			else
1521
-				$image = $modSettings['avatar_url'] . '/default.png';
1593
+			else {
1594
+							$image = $modSettings['avatar_url'] . '/default.png';
1595
+			}
1522 1596
 		}
1523
-		if (!empty($image))
1524
-			$memberContext[$user]['avatar'] = array(
1597
+		if (!empty($image)) {
1598
+					$memberContext[$user]['avatar'] = array(
1525 1599
 				'name' => $profile['avatar'],
1526 1600
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1527 1601
 				'href' => $image,
1528 1602
 				'url' => $image,
1529 1603
 			);
1604
+		}
1530 1605
 	}
1531 1606
 
1532 1607
 	// Are we also loading the members custom fields into context?
@@ -1534,35 +1609,41 @@  discard block
 block discarded – undo
1534 1609
 	{
1535 1610
 		$memberContext[$user]['custom_fields'] = array();
1536 1611
 
1537
-		if (!isset($context['display_fields']))
1538
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1612
+		if (!isset($context['display_fields'])) {
1613
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1614
+		}
1539 1615
 
1540 1616
 		foreach ($context['display_fields'] as $custom)
1541 1617
 		{
1542
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1543
-				continue;
1618
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1619
+							continue;
1620
+			}
1544 1621
 
1545 1622
 			$value = $profile['options'][$custom['col_name']];
1546 1623
 
1547 1624
 			// Don't show the "disabled" option for the "gender" field.
1548
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1549
-				continue;
1625
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1626
+							continue;
1627
+			}
1550 1628
 
1551 1629
 			// BBC?
1552
-			if ($custom['bbc'])
1553
-				$value = parse_bbc($value);
1630
+			if ($custom['bbc']) {
1631
+							$value = parse_bbc($value);
1632
+			}
1554 1633
 			// ... or checkbox?
1555
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1556
-				$value = $value ? $txt['yes'] : $txt['no'];
1634
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1635
+							$value = $value ? $txt['yes'] : $txt['no'];
1636
+			}
1557 1637
 
1558 1638
 			// Enclosing the user input within some other text?
1559
-			if (!empty($custom['enclose']))
1560
-				$value = strtr($custom['enclose'], array(
1639
+			if (!empty($custom['enclose'])) {
1640
+							$value = strtr($custom['enclose'], array(
1561 1641
 					'{SCRIPTURL}' => $scripturl,
1562 1642
 					'{IMAGES_URL}' => $settings['images_url'],
1563 1643
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1564 1644
 					'{INPUT}' => $value,
1565 1645
 				));
1646
+			}
1566 1647
 
1567 1648
 			$memberContext[$user]['custom_fields'][] = array(
1568 1649
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1589,8 +1670,9 @@  discard block
 block discarded – undo
1589 1670
 	global $smcFunc, $txt, $scripturl, $settings;
1590 1671
 
1591 1672
 	// Do not waste my time...
1592
-	if (empty($users) || empty($params))
1593
-		return false;
1673
+	if (empty($users) || empty($params)) {
1674
+			return false;
1675
+	}
1594 1676
 
1595 1677
 	// Make sure it's an array.
1596 1678
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1614,31 +1696,36 @@  discard block
 block discarded – undo
1614 1696
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1615 1697
 	{
1616 1698
 		// BBC?
1617
-		if (!empty($row['bbc']))
1618
-			$row['value'] = parse_bbc($row['value']);
1699
+		if (!empty($row['bbc'])) {
1700
+					$row['value'] = parse_bbc($row['value']);
1701
+		}
1619 1702
 
1620 1703
 		// ... or checkbox?
1621
-		elseif (isset($row['type']) && $row['type'] == 'check')
1622
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1704
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1705
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1706
+		}
1623 1707
 
1624 1708
 		// Enclosing the user input within some other text?
1625
-		if (!empty($row['enclose']))
1626
-			$row['value'] = strtr($row['enclose'], array(
1709
+		if (!empty($row['enclose'])) {
1710
+					$row['value'] = strtr($row['enclose'], array(
1627 1711
 				'{SCRIPTURL}' => $scripturl,
1628 1712
 				'{IMAGES_URL}' => $settings['images_url'],
1629 1713
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1630 1714
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1631 1715
 			));
1716
+		}
1632 1717
 
1633 1718
 		// Send a simple array if there is just 1 param
1634
-		if (count($params) == 1)
1635
-			$return[$row['id_member']] = $row;
1719
+		if (count($params) == 1) {
1720
+					$return[$row['id_member']] = $row;
1721
+		}
1636 1722
 
1637 1723
 		// More than 1? knock yourself out...
1638 1724
 		else
1639 1725
 		{
1640
-			if (!isset($return[$row['id_member']]))
1641
-				$return[$row['id_member']] = array();
1726
+			if (!isset($return[$row['id_member']])) {
1727
+							$return[$row['id_member']] = array();
1728
+			}
1642 1729
 
1643 1730
 			$return[$row['id_member']][$row['variable']] = $row;
1644 1731
 		}
@@ -1672,8 +1759,9 @@  discard block
 block discarded – undo
1672 1759
 	global $context;
1673 1760
 
1674 1761
 	// Don't know any browser!
1675
-	if (empty($context['browser']))
1676
-		detectBrowser();
1762
+	if (empty($context['browser'])) {
1763
+			detectBrowser();
1764
+	}
1677 1765
 
1678 1766
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1679 1767
 }
@@ -1691,8 +1779,9 @@  discard block
 block discarded – undo
1691 1779
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1692 1780
 
1693 1781
 	// The theme was specified by parameter.
1694
-	if (!empty($id_theme))
1695
-		$id_theme = (int) $id_theme;
1782
+	if (!empty($id_theme)) {
1783
+			$id_theme = (int) $id_theme;
1784
+	}
1696 1785
 	// The theme was specified by REQUEST.
1697 1786
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1698 1787
 	{
@@ -1700,51 +1789,58 @@  discard block
 block discarded – undo
1700 1789
 		$_SESSION['id_theme'] = $id_theme;
1701 1790
 	}
1702 1791
 	// The theme was specified by REQUEST... previously.
1703
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1704
-		$id_theme = (int) $_SESSION['id_theme'];
1792
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1793
+			$id_theme = (int) $_SESSION['id_theme'];
1794
+	}
1705 1795
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1706
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1707
-		$id_theme = $user_info['theme'];
1796
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1797
+			$id_theme = $user_info['theme'];
1798
+	}
1708 1799
 	// The theme was specified by the board.
1709
-	elseif (!empty($board_info['theme']))
1710
-		$id_theme = $board_info['theme'];
1800
+	elseif (!empty($board_info['theme'])) {
1801
+			$id_theme = $board_info['theme'];
1802
+	}
1711 1803
 	// The theme is the forum's default.
1712
-	else
1713
-		$id_theme = $modSettings['theme_guests'];
1804
+	else {
1805
+			$id_theme = $modSettings['theme_guests'];
1806
+	}
1714 1807
 
1715 1808
 	// Verify the id_theme... no foul play.
1716 1809
 	// Always allow the board specific theme, if they are overriding.
1717
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1718
-		$id_theme = $board_info['theme'];
1810
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1811
+			$id_theme = $board_info['theme'];
1812
+	}
1719 1813
 	// If they have specified a particular theme to use with SSI allow it to be used.
1720
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1721
-		$id_theme = (int) $id_theme;
1722
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1814
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1815
+			$id_theme = (int) $id_theme;
1816
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1723 1817
 	{
1724 1818
 		$themes = explode(',', $modSettings['enableThemes']);
1725
-		if (!in_array($id_theme, $themes))
1726
-			$id_theme = $modSettings['theme_guests'];
1727
-		else
1819
+		if (!in_array($id_theme, $themes)) {
1820
+					$id_theme = $modSettings['theme_guests'];
1821
+		} else {
1822
+					$id_theme = (int) $id_theme;
1823
+		}
1824
+	} else {
1728 1825
 			$id_theme = (int) $id_theme;
1729 1826
 	}
1730
-	else
1731
-		$id_theme = (int) $id_theme;
1732 1827
 
1733 1828
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1734 1829
 
1735 1830
 	// Disable image proxy if we don't have SSL enabled
1736
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1737
-		$image_proxy_enabled = false;
1831
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1832
+			$image_proxy_enabled = false;
1833
+	}
1738 1834
 
1739 1835
 	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'])
1740 1836
 	{
1741 1837
 		$themeData = $temp;
1742 1838
 		$flag = true;
1839
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1840
+			$themeData = $temp + array($member => array());
1841
+	} else {
1842
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1743 1843
 	}
1744
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1745
-		$themeData = $temp + array($member => array());
1746
-	else
1747
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1748 1844
 
1749 1845
 	if (empty($flag))
1750 1846
 	{
@@ -1763,31 +1859,37 @@  discard block
 block discarded – undo
1763 1859
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1764 1860
 		{
1765 1861
 			// There are just things we shouldn't be able to change as members.
1766
-			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')))
1767
-				continue;
1862
+			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'))) {
1863
+							continue;
1864
+			}
1768 1865
 
1769 1866
 			// If this is the theme_dir of the default theme, store it.
1770
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1771
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1867
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1868
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1869
+			}
1772 1870
 
1773 1871
 			// If this isn't set yet, is a theme option, or is not the default theme..
1774
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1775
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1872
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1873
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1874
+			}
1776 1875
 		}
1777 1876
 		$smcFunc['db_free_result']($result);
1778 1877
 
1779
-		if (!empty($themeData[-1]))
1780
-			foreach ($themeData[-1] as $k => $v)
1878
+		if (!empty($themeData[-1])) {
1879
+					foreach ($themeData[-1] as $k => $v)
1781 1880
 			{
1782 1881
 				if (!isset($themeData[$member][$k]))
1783 1882
 					$themeData[$member][$k] = $v;
1883
+		}
1784 1884
 			}
1785 1885
 
1786
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1787
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1886
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1887
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1888
+		}
1788 1889
 		// Only if we didn't already load that part of the cache...
1789
-		elseif (!isset($temp))
1790
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1890
+		elseif (!isset($temp)) {
1891
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1892
+		}
1791 1893
 	}
1792 1894
 
1793 1895
 	$settings = $themeData[0];
@@ -1804,20 +1906,24 @@  discard block
 block discarded – undo
1804 1906
 	$settings['template_dirs'][] = $settings['theme_dir'];
1805 1907
 
1806 1908
 	// Based on theme (if there is one).
1807
-	if (!empty($settings['base_theme_dir']))
1808
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1909
+	if (!empty($settings['base_theme_dir'])) {
1910
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1911
+	}
1809 1912
 
1810 1913
 	// Lastly the default theme.
1811
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1812
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1914
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1915
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1916
+	}
1813 1917
 
1814
-	if (!$initialize)
1815
-		return;
1918
+	if (!$initialize) {
1919
+			return;
1920
+	}
1816 1921
 
1817 1922
 	// Check to see if we're forcing SSL
1818 1923
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1819
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1820
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1924
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1925
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1926
+	}
1821 1927
 
1822 1928
 	// Check to see if they're accessing it from the wrong place.
1823 1929
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1825,8 +1931,9 @@  discard block
 block discarded – undo
1825 1931
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1826 1932
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1827 1933
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1828
-		if ($temp != '/')
1829
-			$detected_url .= $temp;
1934
+		if ($temp != '/') {
1935
+					$detected_url .= $temp;
1936
+		}
1830 1937
 	}
1831 1938
 	if (isset($detected_url) && $detected_url != $boardurl)
1832 1939
 	{
@@ -1838,8 +1945,9 @@  discard block
 block discarded – undo
1838 1945
 			foreach ($aliases as $alias)
1839 1946
 			{
1840 1947
 				// Rip off all the boring parts, spaces, etc.
1841
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1842
-					$do_fix = true;
1948
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1949
+									$do_fix = true;
1950
+				}
1843 1951
 			}
1844 1952
 		}
1845 1953
 
@@ -1847,20 +1955,22 @@  discard block
 block discarded – undo
1847 1955
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1848 1956
 		{
1849 1957
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1850
-			if (empty($_GET))
1851
-				redirectexit('wwwRedirect');
1852
-			else
1958
+			if (empty($_GET)) {
1959
+							redirectexit('wwwRedirect');
1960
+			} else
1853 1961
 			{
1854 1962
 				list ($k, $v) = each($_GET);
1855 1963
 
1856
-				if ($k != 'wwwRedirect')
1857
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1964
+				if ($k != 'wwwRedirect') {
1965
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1966
+				}
1858 1967
 			}
1859 1968
 		}
1860 1969
 
1861 1970
 		// #3 is just a check for SSL...
1862
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1863
-			$do_fix = true;
1971
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1972
+					$do_fix = true;
1973
+		}
1864 1974
 
1865 1975
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1866 1976
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1894,8 +2004,9 @@  discard block
 block discarded – undo
1894 2004
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1895 2005
 				}
1896 2006
 			}
1897
-			foreach ($context['linktree'] as $k => $dummy)
1898
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2007
+			foreach ($context['linktree'] as $k => $dummy) {
2008
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2009
+			}
1899 2010
 		}
1900 2011
 	}
1901 2012
 	// Set up the contextual user array.
@@ -1914,16 +2025,16 @@  discard block
 block discarded – undo
1914 2025
 			'email' => $user_info['email'],
1915 2026
 			'ignoreusers' => $user_info['ignoreusers'],
1916 2027
 		);
1917
-		if (!$context['user']['is_guest'])
1918
-			$context['user']['name'] = $user_info['name'];
1919
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1920
-			$context['user']['name'] = $txt['guest_title'];
2028
+		if (!$context['user']['is_guest']) {
2029
+					$context['user']['name'] = $user_info['name'];
2030
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2031
+					$context['user']['name'] = $txt['guest_title'];
2032
+		}
1921 2033
 
1922 2034
 		// Determine the current smiley set.
1923 2035
 		$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'];
1924 2036
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1925
-	}
1926
-	else
2037
+	} else
1927 2038
 	{
1928 2039
 		$context['user'] = array(
1929 2040
 			'id' => -1,
@@ -1939,18 +2050,24 @@  discard block
 block discarded – undo
1939 2050
 	}
1940 2051
 
1941 2052
 	// Some basic information...
1942
-	if (!isset($context['html_headers']))
1943
-		$context['html_headers'] = '';
1944
-	if (!isset($context['javascript_files']))
1945
-		$context['javascript_files'] = array();
1946
-	if (!isset($context['css_files']))
1947
-		$context['css_files'] = array();
1948
-	if (!isset($context['css_header']))
1949
-		$context['css_header'] = array();
1950
-	if (!isset($context['javascript_inline']))
1951
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1952
-	if (!isset($context['javascript_vars']))
1953
-		$context['javascript_vars'] = array();
2053
+	if (!isset($context['html_headers'])) {
2054
+			$context['html_headers'] = '';
2055
+	}
2056
+	if (!isset($context['javascript_files'])) {
2057
+			$context['javascript_files'] = array();
2058
+	}
2059
+	if (!isset($context['css_files'])) {
2060
+			$context['css_files'] = array();
2061
+	}
2062
+	if (!isset($context['css_header'])) {
2063
+			$context['css_header'] = array();
2064
+	}
2065
+	if (!isset($context['javascript_inline'])) {
2066
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2067
+	}
2068
+	if (!isset($context['javascript_vars'])) {
2069
+			$context['javascript_vars'] = array();
2070
+	}
1954 2071
 
1955 2072
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1956 2073
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1962,8 +2079,9 @@  discard block
 block discarded – undo
1962 2079
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1963 2080
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1964 2081
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1965
-	if (isset($modSettings['load_average']))
1966
-		$context['load_average'] = $modSettings['load_average'];
2082
+	if (isset($modSettings['load_average'])) {
2083
+			$context['load_average'] = $modSettings['load_average'];
2084
+	}
1967 2085
 
1968 2086
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1969 2087
 	detectBrowser();
@@ -1977,8 +2095,9 @@  discard block
 block discarded – undo
1977 2095
 	// This allows sticking some HTML on the page output - useful for controls.
1978 2096
 	$context['insert_after_template'] = '';
1979 2097
 
1980
-	if (!isset($txt))
1981
-		$txt = array();
2098
+	if (!isset($txt)) {
2099
+			$txt = array();
2100
+	}
1982 2101
 
1983 2102
 	$simpleActions = array(
1984 2103
 		'findmember',
@@ -2024,9 +2143,10 @@  discard block
 block discarded – undo
2024 2143
 
2025 2144
 	// See if theres any extra param to check.
2026 2145
 	$requiresXML = false;
2027
-	foreach ($extraParams as $key => $extra)
2028
-		if (isset($_REQUEST[$extra]))
2146
+	foreach ($extraParams as $key => $extra) {
2147
+			if (isset($_REQUEST[$extra]))
2029 2148
 			$requiresXML = true;
2149
+	}
2030 2150
 
2031 2151
 	// Output is fully XML, so no need for the index template.
2032 2152
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2041,37 +2161,39 @@  discard block
 block discarded – undo
2041 2161
 	{
2042 2162
 		loadLanguage('index+Modifications');
2043 2163
 		$context['template_layers'] = array();
2044
-	}
2045
-
2046
-	else
2164
+	} else
2047 2165
 	{
2048 2166
 		// Custom templates to load, or just default?
2049
-		if (isset($settings['theme_templates']))
2050
-			$templates = explode(',', $settings['theme_templates']);
2051
-		else
2052
-			$templates = array('index');
2167
+		if (isset($settings['theme_templates'])) {
2168
+					$templates = explode(',', $settings['theme_templates']);
2169
+		} else {
2170
+					$templates = array('index');
2171
+		}
2053 2172
 
2054 2173
 		// Load each template...
2055
-		foreach ($templates as $template)
2056
-			loadTemplate($template);
2174
+		foreach ($templates as $template) {
2175
+					loadTemplate($template);
2176
+		}
2057 2177
 
2058 2178
 		// ...and attempt to load their associated language files.
2059 2179
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2060 2180
 		loadLanguage($required_files, '', false);
2061 2181
 
2062 2182
 		// Custom template layers?
2063
-		if (isset($settings['theme_layers']))
2064
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2065
-		else
2066
-			$context['template_layers'] = array('html', 'body');
2183
+		if (isset($settings['theme_layers'])) {
2184
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2185
+		} else {
2186
+					$context['template_layers'] = array('html', 'body');
2187
+		}
2067 2188
 	}
2068 2189
 
2069 2190
 	// Initialize the theme.
2070 2191
 	loadSubTemplate('init', 'ignore');
2071 2192
 
2072 2193
 	// Allow overriding the board wide time/number formats.
2073
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2074
-		$user_info['time_format'] = $txt['time_format'];
2194
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2195
+			$user_info['time_format'] = $txt['time_format'];
2196
+	}
2075 2197
 
2076 2198
 	// Set the character set from the template.
2077 2199
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2079,12 +2201,14 @@  discard block
 block discarded – undo
2079 2201
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2080 2202
 
2081 2203
 	// Guests may still need a name.
2082
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2083
-		$context['user']['name'] = $txt['guest_title'];
2204
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2205
+			$context['user']['name'] = $txt['guest_title'];
2206
+	}
2084 2207
 
2085 2208
 	// Any theme-related strings that need to be loaded?
2086
-	if (!empty($settings['require_theme_strings']))
2087
-		loadLanguage('ThemeStrings', '', false);
2209
+	if (!empty($settings['require_theme_strings'])) {
2210
+			loadLanguage('ThemeStrings', '', false);
2211
+	}
2088 2212
 
2089 2213
 	// Make a special URL for the language.
2090 2214
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2095,8 +2219,9 @@  discard block
 block discarded – undo
2095 2219
 	// Here is my luvly Responsive CSS
2096 2220
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2097 2221
 
2098
-	if ($context['right_to_left'])
2099
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2222
+	if ($context['right_to_left']) {
2223
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2224
+	}
2100 2225
 
2101 2226
 	// We allow theme variants, because we're cool.
2102 2227
 	$context['theme_variant'] = '';
@@ -2104,14 +2229,17 @@  discard block
 block discarded – undo
2104 2229
 	if (!empty($settings['theme_variants']))
2105 2230
 	{
2106 2231
 		// Overriding - for previews and that ilk.
2107
-		if (!empty($_REQUEST['variant']))
2108
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2232
+		if (!empty($_REQUEST['variant'])) {
2233
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2234
+		}
2109 2235
 		// User selection?
2110
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2111
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2236
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2237
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2238
+		}
2112 2239
 		// If not a user variant, select the default.
2113
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2114
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2240
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2241
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2242
+		}
2115 2243
 
2116 2244
 		// Do this to keep things easier in the templates.
2117 2245
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2120,20 +2248,23 @@  discard block
 block discarded – undo
2120 2248
 		if (!empty($context['theme_variant']))
2121 2249
 		{
2122 2250
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2123
-			if ($context['right_to_left'])
2124
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2251
+			if ($context['right_to_left']) {
2252
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2253
+			}
2125 2254
 		}
2126 2255
 	}
2127 2256
 
2128 2257
 	// Let's be compatible with old themes!
2129
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2130
-		$context['template_layers'] = array('main');
2258
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2259
+			$context['template_layers'] = array('main');
2260
+	}
2131 2261
 
2132 2262
 	$context['tabindex'] = 1;
2133 2263
 
2134 2264
 	// Compatibility.
2135
-	if (!isset($settings['theme_version']))
2136
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2265
+	if (!isset($settings['theme_version'])) {
2266
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2267
+	}
2137 2268
 
2138 2269
 	// Default JS variables for use in every theme
2139 2270
 	$context['javascript_vars'] = array(
@@ -2152,18 +2283,18 @@  discard block
 block discarded – undo
2152 2283
 	);
2153 2284
 
2154 2285
 	// Add the JQuery library to the list of files to load.
2155
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2156
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2157
-
2158
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2159
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2160
-
2161
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2162
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2286
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2287
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2288
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2289
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2290
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2291
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2292
+	}
2163 2293
 
2164 2294
 	// Auto loading? template_javascript() will take care of the local half of this.
2165
-	else
2166
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2295
+	else {
2296
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2297
+	}
2167 2298
 
2168 2299
 	// Queue our JQuery plugins!
2169 2300
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2186,12 +2317,12 @@  discard block
 block discarded – undo
2186 2317
 			require_once($sourcedir . '/ScheduledTasks.php');
2187 2318
 
2188 2319
 			// What to do, what to do?!
2189
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2190
-				AutoTask();
2191
-			else
2192
-				ReduceMailQueue();
2193
-		}
2194
-		else
2320
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2321
+							AutoTask();
2322
+			} else {
2323
+							ReduceMailQueue();
2324
+			}
2325
+		} else
2195 2326
 		{
2196 2327
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2197 2328
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2242,8 +2373,9 @@  discard block
 block discarded – undo
2242 2373
 		foreach ($theme_includes as $include)
2243 2374
 		{
2244 2375
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2245
-			if (file_exists($include))
2246
-				require_once($include);
2376
+			if (file_exists($include)) {
2377
+							require_once($include);
2378
+			}
2247 2379
 		}
2248 2380
 	}
2249 2381
 
@@ -2273,16 +2405,19 @@  discard block
 block discarded – undo
2273 2405
 	// Do any style sheets first, cause we're easy with those.
2274 2406
 	if (!empty($style_sheets))
2275 2407
 	{
2276
-		if (!is_array($style_sheets))
2277
-			$style_sheets = array($style_sheets);
2408
+		if (!is_array($style_sheets)) {
2409
+					$style_sheets = array($style_sheets);
2410
+		}
2278 2411
 
2279
-		foreach ($style_sheets as $sheet)
2280
-			loadCSSFile($sheet . '.css', array(), $sheet);
2412
+		foreach ($style_sheets as $sheet) {
2413
+					loadCSSFile($sheet . '.css', array(), $sheet);
2414
+		}
2281 2415
 	}
2282 2416
 
2283 2417
 	// No template to load?
2284
-	if ($template_name === false)
2285
-		return true;
2418
+	if ($template_name === false) {
2419
+			return true;
2420
+	}
2286 2421
 
2287 2422
 	$loaded = false;
2288 2423
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2297,12 +2432,14 @@  discard block
 block discarded – undo
2297 2432
 
2298 2433
 	if ($loaded)
2299 2434
 	{
2300
-		if ($db_show_debug === true)
2301
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2435
+		if ($db_show_debug === true) {
2436
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2437
+		}
2302 2438
 
2303 2439
 		// If they have specified an initialization function for this template, go ahead and call it now.
2304
-		if (function_exists('template_' . $template_name . '_init'))
2305
-			call_user_func('template_' . $template_name . '_init');
2440
+		if (function_exists('template_' . $template_name . '_init')) {
2441
+					call_user_func('template_' . $template_name . '_init');
2442
+		}
2306 2443
 	}
2307 2444
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2308 2445
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2322,13 +2459,14 @@  discard block
 block discarded – undo
2322 2459
 		loadTemplate($template_name);
2323 2460
 	}
2324 2461
 	// Cause an error otherwise.
2325
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2326
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2327
-	elseif ($fatal)
2328
-		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'));
2329
-	else
2330
-		return false;
2331
-}
2462
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2463
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2464
+	} elseif ($fatal) {
2465
+			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'));
2466
+	} else {
2467
+			return false;
2468
+	}
2469
+	}
2332 2470
 
2333 2471
 /**
2334 2472
  * Load a sub-template.
@@ -2346,17 +2484,19 @@  discard block
 block discarded – undo
2346 2484
 {
2347 2485
 	global $context, $txt, $db_show_debug;
2348 2486
 
2349
-	if ($db_show_debug === true)
2350
-		$context['debug']['sub_templates'][] = $sub_template_name;
2487
+	if ($db_show_debug === true) {
2488
+			$context['debug']['sub_templates'][] = $sub_template_name;
2489
+	}
2351 2490
 
2352 2491
 	// Figure out what the template function is named.
2353 2492
 	$theme_function = 'template_' . $sub_template_name;
2354
-	if (function_exists($theme_function))
2355
-		$theme_function();
2356
-	elseif ($fatal === false)
2357
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2358
-	elseif ($fatal !== 'ignore')
2359
-		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'));
2493
+	if (function_exists($theme_function)) {
2494
+			$theme_function();
2495
+	} elseif ($fatal === false) {
2496
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2497
+	} elseif ($fatal !== 'ignore') {
2498
+			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'));
2499
+	}
2360 2500
 
2361 2501
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2362 2502
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2393,8 +2533,9 @@  discard block
 block discarded – undo
2393 2533
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2394 2534
 
2395 2535
 	// If this is an external file, automatically set this to false.
2396
-	if (!empty($params['external']))
2397
-		$params['minimize'] = false;
2536
+	if (!empty($params['external'])) {
2537
+			$params['minimize'] = false;
2538
+	}
2398 2539
 
2399 2540
 	// Account for shorthand like admin.css?alp21 filenames
2400 2541
 	$has_seed = strpos($fileName, '.css?');
@@ -2411,13 +2552,10 @@  discard block
 block discarded – undo
2411 2552
 			{
2412 2553
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2413 2554
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2555
+			} else {
2556
+							$fileUrl = false;
2414 2557
 			}
2415
-
2416
-			else
2417
-				$fileUrl = false;
2418
-		}
2419
-
2420
-		else
2558
+		} else
2421 2559
 		{
2422 2560
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2423 2561
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2432,12 +2570,14 @@  discard block
 block discarded – undo
2432 2570
 	}
2433 2571
 
2434 2572
 	// Add it to the array for use in the template
2435
-	if (!empty($fileName))
2436
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2573
+	if (!empty($fileName)) {
2574
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2575
+	}
2437 2576
 
2438
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2439
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2440
-}
2577
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2578
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2579
+	}
2580
+	}
2441 2581
 
2442 2582
 /**
2443 2583
  * Add a block of inline css code to be executed later
@@ -2454,8 +2594,9 @@  discard block
 block discarded – undo
2454 2594
 	global $context;
2455 2595
 
2456 2596
 	// Gotta add something...
2457
-	if (empty($css))
2458
-		return false;
2597
+	if (empty($css)) {
2598
+			return false;
2599
+	}
2459 2600
 
2460 2601
 	$context['css_header'][] = $css;
2461 2602
 }
@@ -2490,8 +2631,9 @@  discard block
 block discarded – undo
2490 2631
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2491 2632
 
2492 2633
 	// If this is an external file, automatically set this to false.
2493
-	if (!empty($params['external']))
2494
-		$params['minimize'] = false;
2634
+	if (!empty($params['external'])) {
2635
+			$params['minimize'] = false;
2636
+	}
2495 2637
 
2496 2638
 	// Account for shorthand like admin.js?alp21 filenames
2497 2639
 	$has_seed = strpos($fileName, '.js?');
@@ -2508,16 +2650,12 @@  discard block
 block discarded – undo
2508 2650
 			{
2509 2651
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2510 2652
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2511
-			}
2512
-
2513
-			else
2653
+			} else
2514 2654
 			{
2515 2655
 				$fileUrl = false;
2516 2656
 				$filePath = false;
2517 2657
 			}
2518
-		}
2519
-
2520
-		else
2658
+		} else
2521 2659
 		{
2522 2660
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2523 2661
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2532,9 +2670,10 @@  discard block
 block discarded – undo
2532 2670
 	}
2533 2671
 
2534 2672
 	// Add it to the array for use in the template
2535
-	if (!empty($fileName))
2536
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2537
-}
2673
+	if (!empty($fileName)) {
2674
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2675
+	}
2676
+	}
2538 2677
 
2539 2678
 /**
2540 2679
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2548,9 +2687,10 @@  discard block
 block discarded – undo
2548 2687
 {
2549 2688
 	global $context;
2550 2689
 
2551
-	if (!empty($key) && (!empty($value) || $value === '0'))
2552
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2553
-}
2690
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2691
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2692
+	}
2693
+	}
2554 2694
 
2555 2695
 /**
2556 2696
  * Add a block of inline Javascript code to be executed later
@@ -2567,8 +2707,9 @@  discard block
 block discarded – undo
2567 2707
 {
2568 2708
 	global $context;
2569 2709
 
2570
-	if (empty($javascript))
2571
-		return false;
2710
+	if (empty($javascript)) {
2711
+			return false;
2712
+	}
2572 2713
 
2573 2714
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2574 2715
 }
@@ -2589,15 +2730,18 @@  discard block
 block discarded – undo
2589 2730
 	static $already_loaded = array();
2590 2731
 
2591 2732
 	// Default to the user's language.
2592
-	if ($lang == '')
2593
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2733
+	if ($lang == '') {
2734
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2735
+	}
2594 2736
 
2595 2737
 	// Do we want the English version of language file as fallback?
2596
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2597
-		loadLanguage($template_name, 'english', false);
2738
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2739
+			loadLanguage($template_name, 'english', false);
2740
+	}
2598 2741
 
2599
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2600
-		return $lang;
2742
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2743
+			return $lang;
2744
+	}
2601 2745
 
2602 2746
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2603 2747
 	if (empty($settings['default_theme_dir']))
@@ -2608,8 +2752,9 @@  discard block
 block discarded – undo
2608 2752
 
2609 2753
 	// What theme are we in?
2610 2754
 	$theme_name = basename($settings['theme_url']);
2611
-	if (empty($theme_name))
2612
-		$theme_name = 'unknown';
2755
+	if (empty($theme_name)) {
2756
+			$theme_name = 'unknown';
2757
+	}
2613 2758
 
2614 2759
 	// For each file open it up and write it out!
2615 2760
 	foreach (explode('+', $template_name) as $template)
@@ -2651,8 +2796,9 @@  discard block
 block discarded – undo
2651 2796
 				$found = true;
2652 2797
 
2653 2798
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2654
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2655
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2799
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2800
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2801
+				}
2656 2802
 				
2657 2803
 				break;
2658 2804
 			}
@@ -2692,8 +2838,9 @@  discard block
 block discarded – undo
2692 2838
 	}
2693 2839
 
2694 2840
 	// Keep track of what we're up to soldier.
2695
-	if ($db_show_debug === true)
2696
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2841
+	if ($db_show_debug === true) {
2842
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2843
+	}
2697 2844
 
2698 2845
 	// Remember what we have loaded, and in which language.
2699 2846
 	$already_loaded[$template_name] = $lang;
@@ -2739,8 +2886,9 @@  discard block
 block discarded – undo
2739 2886
 				)
2740 2887
 			);
2741 2888
 			// In the EXTREMELY unlikely event this happens, give an error message.
2742
-			if ($smcFunc['db_num_rows']($result) == 0)
2743
-				fatal_lang_error('parent_not_found', 'critical');
2889
+			if ($smcFunc['db_num_rows']($result) == 0) {
2890
+							fatal_lang_error('parent_not_found', 'critical');
2891
+			}
2744 2892
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2745 2893
 			{
2746 2894
 				if (!isset($boards[$row['id_board']]))
@@ -2757,8 +2905,8 @@  discard block
 block discarded – undo
2757 2905
 					);
2758 2906
 				}
2759 2907
 				// If a moderator exists for this board, add that moderator for all children too.
2760
-				if (!empty($row['id_moderator']))
2761
-					foreach ($boards as $id => $dummy)
2908
+				if (!empty($row['id_moderator'])) {
2909
+									foreach ($boards as $id => $dummy)
2762 2910
 					{
2763 2911
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2764 2912
 							'id' => $row['id_moderator'],
@@ -2766,11 +2914,12 @@  discard block
 block discarded – undo
2766 2914
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2767 2915
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2768 2916
 						);
2917
+				}
2769 2918
 					}
2770 2919
 
2771 2920
 				// If a moderator group exists for this board, add that moderator group for all children too
2772
-				if (!empty($row['id_moderator_group']))
2773
-					foreach ($boards as $id => $dummy)
2921
+				if (!empty($row['id_moderator_group'])) {
2922
+									foreach ($boards as $id => $dummy)
2774 2923
 					{
2775 2924
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2776 2925
 							'id' => $row['id_moderator_group'],
@@ -2778,6 +2927,7 @@  discard block
 block discarded – undo
2778 2927
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2779 2928
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2780 2929
 						);
2930
+				}
2781 2931
 					}
2782 2932
 			}
2783 2933
 			$smcFunc['db_free_result']($result);
@@ -2804,23 +2954,27 @@  discard block
 block discarded – undo
2804 2954
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2805 2955
 	{
2806 2956
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2807
-		if (empty($smcFunc['ucwords']))
2808
-			reloadSettings();
2957
+		if (empty($smcFunc['ucwords'])) {
2958
+					reloadSettings();
2959
+		}
2809 2960
 
2810 2961
 		// If we don't have our theme information yet, let's get it.
2811
-		if (empty($settings['default_theme_dir']))
2812
-			loadTheme(0, false);
2962
+		if (empty($settings['default_theme_dir'])) {
2963
+					loadTheme(0, false);
2964
+		}
2813 2965
 
2814 2966
 		// Default language directories to try.
2815 2967
 		$language_directories = array(
2816 2968
 			$settings['default_theme_dir'] . '/languages',
2817 2969
 		);
2818
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2819
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2970
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2971
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2972
+		}
2820 2973
 
2821 2974
 		// We possibly have a base theme directory.
2822
-		if (!empty($settings['base_theme_dir']))
2823
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2975
+		if (!empty($settings['base_theme_dir'])) {
2976
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2977
+		}
2824 2978
 
2825 2979
 		// Remove any duplicates.
2826 2980
 		$language_directories = array_unique($language_directories);
@@ -2834,20 +2988,21 @@  discard block
 block discarded – undo
2834 2988
 		foreach ($language_directories as $language_dir)
2835 2989
 		{
2836 2990
 			// Can't look in here... doesn't exist!
2837
-			if (!file_exists($language_dir))
2838
-				continue;
2991
+			if (!file_exists($language_dir)) {
2992
+							continue;
2993
+			}
2839 2994
 
2840 2995
 			$dir = dir($language_dir);
2841 2996
 			while ($entry = $dir->read())
2842 2997
 			{
2843 2998
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2844
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2845
-					continue;
2846
-
2847
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2848
-					$langName = $langList[$matches[1]];
2999
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3000
+									continue;
3001
+				}
2849 3002
 
2850
-				else
3003
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3004
+									$langName = $langList[$matches[1]];
3005
+				} else
2851 3006
 				{
2852 3007
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2853 3008
 
@@ -2888,12 +3043,14 @@  discard block
 block discarded – undo
2888 3043
 		}
2889 3044
 
2890 3045
 		// Do we need to store the lang list?
2891
-		if (empty($langList))
2892
-			updateSettings(array('langList' => json_encode($catchLang)));
3046
+		if (empty($langList)) {
3047
+					updateSettings(array('langList' => json_encode($catchLang)));
3048
+		}
2893 3049
 
2894 3050
 		// Let's cash in on this deal.
2895
-		if (!empty($modSettings['cache_enable']))
2896
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3051
+		if (!empty($modSettings['cache_enable'])) {
3052
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3053
+		}
2897 3054
 	}
2898 3055
 
2899 3056
 	return $context['languages'];
@@ -2916,8 +3073,9 @@  discard block
 block discarded – undo
2916 3073
 	global $modSettings, $options, $txt;
2917 3074
 	static $censor_vulgar = null, $censor_proper;
2918 3075
 
2919
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2920
-		return $text;
3076
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3077
+			return $text;
3078
+	}
2921 3079
 
2922 3080
 	// If they haven't yet been loaded, load them.
2923 3081
 	if ($censor_vulgar == null)
@@ -2945,9 +3103,9 @@  discard block
 block discarded – undo
2945 3103
 	{
2946 3104
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2947 3105
 		$text = $func($censor_vulgar, $censor_proper, $text);
3106
+	} else {
3107
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2948 3108
 	}
2949
-	else
2950
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2951 3109
 
2952 3110
 	return $text;
2953 3111
 }
@@ -2973,38 +3131,42 @@  discard block
 block discarded – undo
2973 3131
 	@ini_set('track_errors', '1');
2974 3132
 
2975 3133
 	// Don't include the file more than once, if $once is true.
2976
-	if ($once && in_array($filename, $templates))
2977
-		return;
3134
+	if ($once && in_array($filename, $templates)) {
3135
+			return;
3136
+	}
2978 3137
 	// Add this file to the include list, whether $once is true or not.
2979
-	else
2980
-		$templates[] = $filename;
3138
+	else {
3139
+			$templates[] = $filename;
3140
+	}
2981 3141
 
2982 3142
 	// Are we going to use eval?
2983 3143
 	if (empty($modSettings['disableTemplateEval']))
2984 3144
 	{
2985 3145
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2986 3146
 		$settings['current_include_filename'] = $filename;
2987
-	}
2988
-	else
3147
+	} else
2989 3148
 	{
2990 3149
 		$file_found = file_exists($filename);
2991 3150
 
2992
-		if ($once && $file_found)
2993
-			require_once($filename);
2994
-		elseif ($file_found)
2995
-			require($filename);
3151
+		if ($once && $file_found) {
3152
+					require_once($filename);
3153
+		} elseif ($file_found) {
3154
+					require($filename);
3155
+		}
2996 3156
 	}
2997 3157
 
2998 3158
 	if ($file_found !== true)
2999 3159
 	{
3000 3160
 		ob_end_clean();
3001
-		if (!empty($modSettings['enableCompressedOutput']))
3002
-			@ob_start('ob_gzhandler');
3003
-		else
3004
-			ob_start();
3161
+		if (!empty($modSettings['enableCompressedOutput'])) {
3162
+					@ob_start('ob_gzhandler');
3163
+		} else {
3164
+					ob_start();
3165
+		}
3005 3166
 
3006
-		if (isset($_GET['debug']))
3007
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3167
+		if (isset($_GET['debug'])) {
3168
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3169
+		}
3008 3170
 
3009 3171
 		// Don't cache error pages!!
3010 3172
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3023,12 +3185,13 @@  discard block
 block discarded – undo
3023 3185
 		echo '<!DOCTYPE html>
3024 3186
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3025 3187
 	<head>';
3026
-		if (isset($context['character_set']))
3027
-			echo '
3188
+		if (isset($context['character_set'])) {
3189
+					echo '
3028 3190
 		<meta charset="', $context['character_set'], '">';
3191
+		}
3029 3192
 
3030
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3031
-			echo '
3193
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3194
+					echo '
3032 3195
 		<title>', $mtitle, '</title>
3033 3196
 	</head>
3034 3197
 	<body>
@@ -3036,8 +3199,8 @@  discard block
 block discarded – undo
3036 3199
 		', $mmessage, '
3037 3200
 	</body>
3038 3201
 </html>';
3039
-		elseif (!allowedTo('admin_forum'))
3040
-			echo '
3202
+		} elseif (!allowedTo('admin_forum')) {
3203
+					echo '
3041 3204
 		<title>', $txt['template_parse_error'], '</title>
3042 3205
 	</head>
3043 3206
 	<body>
@@ -3045,15 +3208,17 @@  discard block
 block discarded – undo
3045 3208
 		', $txt['template_parse_error_message'], '
3046 3209
 	</body>
3047 3210
 </html>';
3048
-		else
3211
+		} else
3049 3212
 		{
3050 3213
 			require_once($sourcedir . '/Subs-Package.php');
3051 3214
 
3052 3215
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3053
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3054
-				$error = $php_errormsg;
3055
-			if (empty($error))
3056
-				$error = $txt['template_parse_errmsg'];
3216
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3217
+							$error = $php_errormsg;
3218
+			}
3219
+			if (empty($error)) {
3220
+							$error = $txt['template_parse_errmsg'];
3221
+			}
3057 3222
 
3058 3223
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3059 3224
 
@@ -3064,11 +3229,12 @@  discard block
 block discarded – undo
3064 3229
 		<h3>', $txt['template_parse_error'], '</h3>
3065 3230
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3066 3231
 
3067
-			if (!empty($error))
3068
-				echo '
3232
+			if (!empty($error)) {
3233
+							echo '
3069 3234
 		<hr>
3070 3235
 
3071 3236
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3237
+			}
3072 3238
 
3073 3239
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3074 3240
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3078,10 +3244,11 @@  discard block
 block discarded – undo
3078 3244
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3079 3245
 
3080 3246
 				// Fix the PHP code stuff...
3081
-				if (!isBrowser('gecko'))
3082
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3083
-				else
3084
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3247
+				if (!isBrowser('gecko')) {
3248
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3249
+				} else {
3250
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3251
+				}
3085 3252
 
3086 3253
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3087 3254
 				$j = -1;
@@ -3089,8 +3256,9 @@  discard block
 block discarded – undo
3089 3256
 				{
3090 3257
 					$j++;
3091 3258
 
3092
-					if (substr_count($line, '<br>') == 0)
3093
-						continue;
3259
+					if (substr_count($line, '<br>') == 0) {
3260
+											continue;
3261
+					}
3094 3262
 
3095 3263
 					$n = substr_count($line, '<br>');
3096 3264
 					for ($i = 0; $i < $n; $i++)
@@ -3109,38 +3277,42 @@  discard block
 block discarded – undo
3109 3277
 				// Figure out what the color coding was before...
3110 3278
 				$line = max($match[1] - 9, 1);
3111 3279
 				$last_line = '';
3112
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3113
-					if (strpos($data2[$line2], '<') !== false)
3280
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3281
+									if (strpos($data2[$line2], '<') !== false)
3114 3282
 					{
3115 3283
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3116 3284
 							$last_line = $color_match[1];
3285
+				}
3117 3286
 						break;
3118 3287
 					}
3119 3288
 
3120 3289
 				// Show the relevant lines...
3121 3290
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3122 3291
 				{
3123
-					if ($line == $match[1])
3124
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3292
+					if ($line == $match[1]) {
3293
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3294
+					}
3125 3295
 
3126 3296
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3127
-					if (isset($data2[$line]) && $data2[$line] != '')
3128
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3297
+					if (isset($data2[$line]) && $data2[$line] != '') {
3298
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3299
+					}
3129 3300
 
3130 3301
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3131 3302
 					{
3132 3303
 						$last_line = $color_match[1];
3133 3304
 						echo '</', substr($last_line, 1, 4), '>';
3305
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3306
+											$last_line = '';
3307
+					} elseif ($last_line != '' && $data2[$line] != '') {
3308
+											echo '</', substr($last_line, 1, 4), '>';
3134 3309
 					}
3135
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3136
-						$last_line = '';
3137
-					elseif ($last_line != '' && $data2[$line] != '')
3138
-						echo '</', substr($last_line, 1, 4), '>';
3139 3310
 
3140
-					if ($line == $match[1])
3141
-						echo '</pre></div><pre style="margin: 0;">';
3142
-					else
3143
-						echo "\n";
3311
+					if ($line == $match[1]) {
3312
+											echo '</pre></div><pre style="margin: 0;">';
3313
+					} else {
3314
+											echo "\n";
3315
+					}
3144 3316
 				}
3145 3317
 
3146 3318
 				echo '</pre></div>';
@@ -3164,8 +3336,9 @@  discard block
 block discarded – undo
3164 3336
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3165 3337
 
3166 3338
 	// Figure out what type of database we are using.
3167
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3168
-		$db_type = 'mysql';
3339
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3340
+			$db_type = 'mysql';
3341
+	}
3169 3342
 
3170 3343
 	// Load the file for the database.
3171 3344
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3173,8 +3346,9 @@  discard block
 block discarded – undo
3173 3346
 	$db_options = array();
3174 3347
 
3175 3348
 	// Add in the port if needed
3176
-	if (!empty($db_port))
3177
-		$db_options['port'] = $db_port;
3349
+	if (!empty($db_port)) {
3350
+			$db_options['port'] = $db_port;
3351
+	}
3178 3352
 
3179 3353
 	// 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.
3180 3354
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3193,13 +3367,15 @@  discard block
 block discarded – undo
3193 3367
 	}
3194 3368
 
3195 3369
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3196
-	if (!$db_connection)
3197
-		display_db_error();
3370
+	if (!$db_connection) {
3371
+			display_db_error();
3372
+	}
3198 3373
 
3199 3374
 	// If in SSI mode fix up the prefix.
3200
-	if (SMF == 'SSI')
3201
-		db_fix_prefix($db_prefix, $db_name);
3202
-}
3375
+	if (SMF == 'SSI') {
3376
+			db_fix_prefix($db_prefix, $db_name);
3377
+	}
3378
+	}
3203 3379
 
3204 3380
 /**
3205 3381
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3213,10 +3389,11 @@  discard block
 block discarded – undo
3213 3389
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3214 3390
 
3215 3391
 	// Not overriding this and we have a cacheAPI, send it back.
3216
-	if (empty($overrideCache) && is_object($cacheAPI))
3217
-		return $cacheAPI;
3218
-	elseif (is_null($cacheAPI))
3219
-		$cacheAPI = false;
3392
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3393
+			return $cacheAPI;
3394
+	} elseif (is_null($cacheAPI)) {
3395
+			$cacheAPI = false;
3396
+	}
3220 3397
 
3221 3398
 	// Make sure our class is in session.
3222 3399
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3237,8 +3414,9 @@  discard block
 block discarded – undo
3237 3414
 		if (!$testAPI->isSupported())
3238 3415
 		{
3239 3416
 			// Can we save ourselves?
3240
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3241
-				return loadCacheAccelerator(null, false);
3417
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3418
+							return loadCacheAccelerator(null, false);
3419
+			}
3242 3420
 			return false;
3243 3421
 		}
3244 3422
 
@@ -3250,9 +3428,9 @@  discard block
 block discarded – undo
3250 3428
 		{
3251 3429
 			$cacheAPI = $testAPI;
3252 3430
 			return $cacheAPI;
3431
+		} else {
3432
+					return $testAPI;
3253 3433
 		}
3254
-		else
3255
-			return $testAPI;
3256 3434
 	}
3257 3435
 }
3258 3436
 
@@ -3272,8 +3450,9 @@  discard block
 block discarded – undo
3272 3450
 
3273 3451
 	// @todo Why are we doing this if caching is disabled?
3274 3452
 
3275
-	if (function_exists('call_integration_hook'))
3276
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3453
+	if (function_exists('call_integration_hook')) {
3454
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3455
+	}
3277 3456
 
3278 3457
 	/* Refresh the cache if either:
3279 3458
 		1. Caching is disabled.
@@ -3287,16 +3466,19 @@  discard block
 block discarded – undo
3287 3466
 		require_once($sourcedir . '/' . $file);
3288 3467
 		$cache_block = call_user_func_array($function, $params);
3289 3468
 
3290
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3291
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3469
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3470
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3471
+		}
3292 3472
 	}
3293 3473
 
3294 3474
 	// Some cached data may need a freshening up after retrieval.
3295
-	if (!empty($cache_block['post_retri_eval']))
3296
-		eval($cache_block['post_retri_eval']);
3475
+	if (!empty($cache_block['post_retri_eval'])) {
3476
+			eval($cache_block['post_retri_eval']);
3477
+	}
3297 3478
 
3298
-	if (function_exists('call_integration_hook'))
3299
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3479
+	if (function_exists('call_integration_hook')) {
3480
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3481
+	}
3300 3482
 
3301 3483
 	return $cache_block['data'];
3302 3484
 }
@@ -3323,8 +3505,9 @@  discard block
 block discarded – undo
3323 3505
 	global $cache_enable, $cacheAPI;
3324 3506
 	global $cache_hits, $cache_count, $db_show_debug;
3325 3507
 
3326
-	if (empty($cache_enable) || empty($cacheAPI))
3327
-		return;
3508
+	if (empty($cache_enable) || empty($cacheAPI)) {
3509
+			return;
3510
+	}
3328 3511
 
3329 3512
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3330 3513
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3337,12 +3520,14 @@  discard block
 block discarded – undo
3337 3520
 	$value = $value === null ? null : json_encode($value);
3338 3521
 	$cacheAPI->putData($key, $value, $ttl);
3339 3522
 
3340
-	if (function_exists('call_integration_hook'))
3341
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3523
+	if (function_exists('call_integration_hook')) {
3524
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3525
+	}
3342 3526
 
3343
-	if (isset($db_show_debug) && $db_show_debug === true)
3344
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3345
-}
3527
+	if (isset($db_show_debug) && $db_show_debug === true) {
3528
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3529
+	}
3530
+	}
3346 3531
 
3347 3532
 /**
3348 3533
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3358,8 +3543,9 @@  discard block
 block discarded – undo
3358 3543
 	global $cache_enable, $cacheAPI;
3359 3544
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3360 3545
 
3361
-	if (empty($cache_enable) || empty($cacheAPI))
3362
-		return;
3546
+	if (empty($cache_enable) || empty($cacheAPI)) {
3547
+			return;
3548
+	}
3363 3549
 
3364 3550
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3365 3551
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3379,16 +3565,18 @@  discard block
 block discarded – undo
3379 3565
 
3380 3566
 		if (empty($value))
3381 3567
 		{
3382
-			if (!is_array($cache_misses))
3383
-				$cache_misses = array();
3568
+			if (!is_array($cache_misses)) {
3569
+							$cache_misses = array();
3570
+			}
3384 3571
 
3385 3572
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3386 3573
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3387 3574
 		}
3388 3575
 	}
3389 3576
 
3390
-	if (function_exists('call_integration_hook') && isset($value))
3391
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3577
+	if (function_exists('call_integration_hook') && isset($value)) {
3578
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3579
+	}
3392 3580
 
3393 3581
 	return empty($value) ? null : smf_json_decode($value, true);
3394 3582
 }
@@ -3410,8 +3598,9 @@  discard block
 block discarded – undo
3410 3598
 	global $cacheAPI;
3411 3599
 
3412 3600
 	// If we can't get to the API, can't do this.
3413
-	if (empty($cacheAPI))
3414
-		return;
3601
+	if (empty($cacheAPI)) {
3602
+			return;
3603
+	}
3415 3604
 
3416 3605
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3417 3606
 	$cacheAPI->cleanCache($type);
@@ -3436,8 +3625,9 @@  discard block
 block discarded – undo
3436 3625
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3437 3626
 
3438 3627
 	// Come on!
3439
-	if (empty($data))
3440
-		return array();
3628
+	if (empty($data)) {
3629
+			return array();
3630
+	}
3441 3631
 
3442 3632
 	// Set a nice default var.
3443 3633
 	$image = '';
@@ -3445,11 +3635,11 @@  discard block
 block discarded – undo
3445 3635
 	// Gravatar has been set as mandatory!
3446 3636
 	if (!empty($modSettings['gravatarOverride']))
3447 3637
 	{
3448
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3449
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3450
-
3451
-		else if (!empty($data['email']))
3452
-			$image = get_gravatar_url($data['email']);
3638
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3639
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3640
+		} else if (!empty($data['email'])) {
3641
+					$image = get_gravatar_url($data['email']);
3642
+		}
3453 3643
 	}
3454 3644
 
3455 3645
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3461,54 +3651,60 @@  discard block
 block discarded – undo
3461 3651
 			// Gravatar.
3462 3652
 			if (stristr($data['avatar'], 'gravatar://'))
3463 3653
 			{
3464
-				if ($data['avatar'] == 'gravatar://')
3465
-					$image = get_gravatar_url($data['email']);
3466
-
3467
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3468
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3654
+				if ($data['avatar'] == 'gravatar://') {
3655
+									$image = get_gravatar_url($data['email']);
3656
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3657
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3658
+				}
3469 3659
 			}
3470 3660
 
3471 3661
 			// External url.
3472 3662
 			else
3473 3663
 			{
3474 3664
 				// Using ssl?
3475
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3476
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3665
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3666
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3667
+				}
3477 3668
 
3478 3669
 				// Just a plain external url.
3479
-				else
3480
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3670
+				else {
3671
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3672
+				}
3481 3673
 			}
3482 3674
 		}
3483 3675
 
3484 3676
 		// Perhaps this user has an attachment as avatar...
3485
-		else if (!empty($data['filename']))
3486
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3677
+		else if (!empty($data['filename'])) {
3678
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3679
+		}
3487 3680
 
3488 3681
 		// Right... no avatar... use our default image.
3489
-		else
3490
-			$image = $modSettings['avatar_url'] . '/default.png';
3682
+		else {
3683
+					$image = $modSettings['avatar_url'] . '/default.png';
3684
+		}
3491 3685
 	}
3492 3686
 
3493 3687
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3494 3688
 
3495 3689
 	// 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.
3496
-	if (!empty($image))
3497
-		return array(
3690
+	if (!empty($image)) {
3691
+			return array(
3498 3692
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3499 3693
 			'image' => '<img class="avatar" src="' . $image . '" />',
3500 3694
 			'href' => $image,
3501 3695
 			'url' => $image,
3502 3696
 		);
3697
+	}
3503 3698
 
3504 3699
 	// Fallback to make life easier for everyone...
3505
-	else
3506
-		return array(
3700
+	else {
3701
+			return array(
3507 3702
 			'name' => '',
3508 3703
 			'image' => '',
3509 3704
 			'href' => '',
3510 3705
 			'url' => '',
3511 3706
 		);
3512
-}
3707
+	}
3708
+	}
3513 3709
 
3514 3710
 ?>
3515 3711
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/CacheAPI-sqlite.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,14 +25,14 @@
 block discarded – undo
25 25
 	 */
26 26
 	private $cachedir = null;
27 27
 
28
-    /**
29
-     * @var SQLite3
30
-     */
28
+	/**
29
+	 * @var SQLite3
30
+	 */
31 31
 	private $cacheDB = null;
32 32
 
33
-    /**
34
-     * @var int
35
-     */
33
+	/**
34
+	 * @var int
35
+	 */
36 36
 	private $cacheTime = 0;
37 37
 
38 38
 	public function __construct()
Please login to merge, or discard this patch.
Sources/CacheAPI-apcu.php 1 patch
Braces   +10 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * Our Cache API class
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 	{
28 29
 		$supported = function_exists('apcu_fetch') && function_exists('apcu_store');
29 30
 
30
-		if ($test)
31
-			return $supported;
31
+		if ($test) {
32
+					return $supported;
33
+		}
32 34
 		return parent::isSupported() && $supported;
33 35
 	}
34 36
 
@@ -50,10 +52,11 @@  discard block
 block discarded – undo
50 52
 		$key = $this->prefix . strtr($key, ':/', '-_');
51 53
 
52 54
 		// An extended key is needed to counteract a bug in APC.
53
-		if ($value === null)
54
-			return apcu_delete($key . 'smf');
55
-		else
56
-			return apcu_store($key . 'smf', $value, $ttl);
55
+		if ($value === null) {
56
+					return apcu_delete($key . 'smf');
57
+		} else {
58
+					return apcu_store($key . 'smf', $value, $ttl);
59
+		}
57 60
 	}
58 61
 
59 62
 	/**
Please login to merge, or discard this patch.
Sources/tasks/Birthday-Notify.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@
 block discarded – undo
18 18
  */
19 19
 class Birthday_Notify_Background extends SMF_BackgroundTask
20 20
 {
21
-    /**
22
-     * This executes the task. It loads up the birthdays, figures out the greeting, etc.
23
-     * @return bool Always returns true
24
-     */
21
+	/**
22
+	 * This executes the task. It loads up the birthdays, figures out the greeting, etc.
23
+	 * @return bool Always returns true
24
+	 */
25 25
 	public function execute()
26 26
  	{
27 27
 		global $txt, $smcFunc, $txtBirthdayEmails, $modSettings, $sourcedir;
Please login to merge, or discard this patch.
Sources/MoveTopic.php 1 patch
Braces   +101 added lines, -72 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
  * This function allows to move a topic, making sure to ask the moderator
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 {
33 34
 	global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir;
34 35
 
35
-	if (empty($topic))
36
-		fatal_lang_error('no_access', false);
36
+	if (empty($topic)) {
37
+			fatal_lang_error('no_access', false);
38
+	}
37 39
 
38 40
 	$request = $smcFunc['db_query']('', '
39 41
 		SELECT t.id_member_started, ms.subject, t.approved
@@ -49,8 +51,9 @@  discard block
 block discarded – undo
49 51
 	$smcFunc['db_free_result']($request);
50 52
 
51 53
 	// Can they see it - if not approved?
52
-	if ($modSettings['postmod_active'] && !$context['is_approved'])
53
-		isAllowedTo('approve_posts');
54
+	if ($modSettings['postmod_active'] && !$context['is_approved']) {
55
+			isAllowedTo('approve_posts');
56
+	}
54 57
 
55 58
 	// Permission check!
56 59
 	// @todo
@@ -59,9 +62,9 @@  discard block
 block discarded – undo
59 62
 		if ($id_member_started == $user_info['id'])
60 63
 		{
61 64
 			isAllowedTo('move_own');
65
+		} else {
66
+					isAllowedTo('move_any');
62 67
 		}
63
-		else
64
-			isAllowedTo('move_any');
65 68
 	}
66 69
 
67 70
 	$context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any'];
@@ -83,11 +86,13 @@  discard block
 block discarded – undo
83 86
 		'not_redirection' => true,
84 87
 	);
85 88
 
86
-	if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board)
87
-		$options['selected_board'] = $_SESSION['move_to_topic'];
89
+	if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) {
90
+			$options['selected_board'] = $_SESSION['move_to_topic'];
91
+	}
88 92
 
89
-	if (!$context['move_any'])
90
-		$options['included_boards'] = $boards;
93
+	if (!$context['move_any']) {
94
+			$options['included_boards'] = $boards;
95
+	}
91 96
 
92 97
 	require_once($sourcedir . '/Subs-MessageIndex.php');
93 98
 	$context['categories'] = getBoardList($options);
@@ -138,12 +143,14 @@  discard block
 block discarded – undo
138 143
 	global $txt, $topic, $scripturl, $sourcedir, $context;
139 144
 	global $board, $language, $user_info, $smcFunc;
140 145
 
141
-	if (empty($topic))
142
-		fatal_lang_error('no_access', false);
146
+	if (empty($topic)) {
147
+			fatal_lang_error('no_access', false);
148
+	}
143 149
 
144 150
 	// You can't choose to have a redirection topic and use an empty reason.
145
-	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == ''))
146
-		fatal_lang_error('movetopic_no_reason', false);
151
+	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) {
152
+			fatal_lang_error('movetopic_no_reason', false);
153
+	}
147 154
 
148 155
 	moveTopicConcurrence();
149 156
 
@@ -163,16 +170,18 @@  discard block
 block discarded – undo
163 170
 	$smcFunc['db_free_result']($request);
164 171
 
165 172
 	// Can they see it?
166
-	if (!$context['is_approved'])
167
-		isAllowedTo('approve_posts');
173
+	if (!$context['is_approved']) {
174
+			isAllowedTo('approve_posts');
175
+	}
168 176
 
169 177
 	// Can they move topics on this board?
170 178
 	if (!allowedTo('move_any'))
171 179
 	{
172
-		if ($id_member_started == $user_info['id'])
173
-			isAllowedTo('move_own');
174
-		else
175
-			isAllowedTo('move_any');
180
+		if ($id_member_started == $user_info['id']) {
181
+					isAllowedTo('move_own');
182
+		} else {
183
+					isAllowedTo('move_any');
184
+		}
176 185
 	}
177 186
 
178 187
 	checkSession();
@@ -197,8 +206,9 @@  discard block
 block discarded – undo
197 206
 			'blank_redirect' => '',
198 207
 		)
199 208
 	);
200
-	if ($smcFunc['db_num_rows']($request) == 0)
201
-		fatal_lang_error('no_board');
209
+	if ($smcFunc['db_num_rows']($request) == 0) {
210
+			fatal_lang_error('no_board');
211
+	}
202 212
 	list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request);
203 213
 	$smcFunc['db_free_result']($request);
204 214
 
@@ -210,8 +220,9 @@  discard block
 block discarded – undo
210 220
 	{
211 221
 		$_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => ''));
212 222
 		// Keep checking the length.
213
-		if ($smcFunc['strlen']($_POST['custom_subject']) > 100)
214
-			$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
223
+		if ($smcFunc['strlen']($_POST['custom_subject']) > 100) {
224
+					$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
225
+		}
215 226
 
216 227
 		// If it's still valid move onwards and upwards.
217 228
 		if ($_POST['custom_subject'] != '')
@@ -221,9 +232,9 @@  discard block
 block discarded – undo
221 232
 				// Get a response prefix, but in the forum's default language.
222 233
 				if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
223 234
 				{
224
-					if ($language === $user_info['language'])
225
-						$context['response_prefix'] = $txt['response_prefix'];
226
-					else
235
+					if ($language === $user_info['language']) {
236
+											$context['response_prefix'] = $txt['response_prefix'];
237
+					} else
227 238
 					{
228 239
 						loadLanguage('index', $language, false);
229 240
 						$context['response_prefix'] = $txt['response_prefix'];
@@ -263,8 +274,9 @@  discard block
 block discarded – undo
263 274
 	if (isset($_POST['postRedirect']))
264 275
 	{
265 276
 		// Should be in the boardwide language.
266
-		if ($user_info['language'] != $language)
267
-			loadLanguage('index', $language);
277
+		if ($user_info['language'] != $language) {
278
+					loadLanguage('index', $language);
279
+		}
268 280
 
269 281
 		$_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES);
270 282
 		preparsecode($_POST['reason']);
@@ -328,8 +340,9 @@  discard block
 block discarded – undo
328 340
 		$posters = array();
329 341
 		while ($row = $smcFunc['db_fetch_assoc']($request))
330 342
 		{
331
-			if (!isset($posters[$row['id_member']]))
332
-				$posters[$row['id_member']] = 0;
343
+			if (!isset($posters[$row['id_member']])) {
344
+							$posters[$row['id_member']] = 0;
345
+			}
333 346
 
334 347
 			$posters[$row['id_member']]++;
335 348
 		}
@@ -338,11 +351,13 @@  discard block
 block discarded – undo
338 351
 		foreach ($posters as $id_member => $posts)
339 352
 		{
340 353
 			// The board we're moving from counted posts, but not to.
341
-			if (empty($pcounter_from))
342
-				updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
354
+			if (empty($pcounter_from)) {
355
+							updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
356
+			}
343 357
 			// The reverse: from didn't, to did.
344
-			else
345
-				updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
358
+			else {
359
+							updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
360
+			}
346 361
 		}
347 362
 	}
348 363
 
@@ -350,17 +365,19 @@  discard block
 block discarded – undo
350 365
 	moveTopics($topic, $_POST['toboard']);
351 366
 
352 367
 	// Log that they moved this topic.
353
-	if (!allowedTo('move_own') || $id_member_started != $user_info['id'])
354
-		logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
368
+	if (!allowedTo('move_own') || $id_member_started != $user_info['id']) {
369
+			logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
370
+	}
355 371
 	// Notify people that this topic has been moved?
356 372
 	sendNotifications($topic, 'move');
357 373
 
358 374
 	// Why not go back to the original board in case they want to keep moving?
359
-	if (!isset($_REQUEST['goback']))
360
-		redirectexit('board=' . $board . '.0');
361
-	else
362
-		redirectexit('topic=' . $topic . '.0');
363
-}
375
+	if (!isset($_REQUEST['goback'])) {
376
+			redirectexit('board=' . $board . '.0');
377
+	} else {
378
+			redirectexit('topic=' . $topic . '.0');
379
+	}
380
+	}
364 381
 
365 382
 /**
366 383
  * Moves one or more topics to a specific board. (doesn't check permissions.)
@@ -376,18 +393,21 @@  discard block
 block discarded – undo
376 393
 	global $sourcedir, $user_info, $modSettings, $smcFunc;
377 394
 
378 395
 	// Empty array?
379
-	if (empty($topics))
380
-		return;
396
+	if (empty($topics)) {
397
+			return;
398
+	}
381 399
 
382 400
 	// Only a single topic.
383
-	if (is_numeric($topics))
384
-		$topics = array($topics);
401
+	if (is_numeric($topics)) {
402
+			$topics = array($topics);
403
+	}
385 404
 
386 405
 	$fromBoards = array();
387 406
 
388 407
 	// Destination board empty or equal to 0?
389
-	if (empty($toBoard))
390
-		return;
408
+	if (empty($toBoard)) {
409
+			return;
410
+	}
391 411
 
392 412
 	// Are we moving to the recycle board?
393 413
 	$isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard;
@@ -395,8 +415,9 @@  discard block
 block discarded – undo
395 415
 	// Callback for search APIs to do their thing
396 416
 	require_once($sourcedir . '/Search.php');
397 417
 	$searchAPI = findSearchAPI();
398
-	if ($searchAPI->supportsMethod('topicsMoved'))
399
-		$searchAPI->topicsMoved($topics, $toBoard);
418
+	if ($searchAPI->supportsMethod('topicsMoved')) {
419
+			$searchAPI->topicsMoved($topics, $toBoard);
420
+	}
400 421
 
401 422
 	// Determine the source boards...
402 423
 	$request = $smcFunc['db_query']('', '
@@ -410,8 +431,9 @@  discard block
 block discarded – undo
410 431
 		)
411 432
 	);
412 433
 	// Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards.
413
-	if ($smcFunc['db_num_rows']($request) == 0)
414
-		return;
434
+	if ($smcFunc['db_num_rows']($request) == 0) {
435
+			return;
436
+	}
415 437
 	while ($row = $smcFunc['db_fetch_assoc']($request))
416 438
 	{
417 439
 		if (!isset($fromBoards[$row['id_board']]['num_posts']))
@@ -429,10 +451,11 @@  discard block
 block discarded – undo
429 451
 		$fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
430 452
 
431 453
 		// Add the topics to the right type.
432
-		if ($row['approved'])
433
-			$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
434
-		else
435
-			$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
454
+		if ($row['approved']) {
455
+					$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
456
+		} else {
457
+					$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
458
+		}
436 459
 	}
437 460
 	$smcFunc['db_free_result']($request);
438 461
 
@@ -558,13 +581,14 @@  discard block
 block discarded – undo
558 581
 			)
559 582
 		);
560 583
 		$approval_msgs = array();
561
-		while ($row = $smcFunc['db_fetch_assoc']($request))
562
-			$approval_msgs[] = $row['id_msg'];
584
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
585
+					$approval_msgs[] = $row['id_msg'];
586
+		}
563 587
 		$smcFunc['db_free_result']($request);
564 588
 
565 589
 		// Empty the approval queue for these, as we're going to approve them next.
566
-		if (!empty($approval_msgs))
567
-			$smcFunc['db_query']('', '
590
+		if (!empty($approval_msgs)) {
591
+					$smcFunc['db_query']('', '
568 592
 				DELETE FROM {db_prefix}approval_queue
569 593
 				WHERE id_msg IN ({array_int:message_list})
570 594
 					AND id_attach = {int:id_attach}',
@@ -573,6 +597,7 @@  discard block
 block discarded – undo
573 597
 					'id_attach' => 0,
574 598
 				)
575 599
 			);
600
+		}
576 601
 
577 602
 		// Get all the current max and mins.
578 603
 		$request = $smcFunc['db_query']('', '
@@ -606,8 +631,8 @@  discard block
 block discarded – undo
606 631
 		while ($row = $smcFunc['db_fetch_assoc']($request))
607 632
 		{
608 633
 			// If not, update.
609
-			if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max'])
610
-				$smcFunc['db_query']('', '
634
+			if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) {
635
+							$smcFunc['db_query']('', '
611 636
 					UPDATE {db_prefix}topics
612 637
 					SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg}
613 638
 					WHERE id_topic = {int:selected_topic}',
@@ -617,6 +642,7 @@  discard block
 block discarded – undo
617 642
 						'selected_topic' => $row['id_topic'],
618 643
 					)
619 644
 				);
645
+			}
620 646
 		}
621 647
 		$smcFunc['db_free_result']($request);
622 648
 	}
@@ -675,9 +701,10 @@  discard block
 block discarded – undo
675 701
 	}
676 702
 
677 703
 	// Update the cache?
678
-	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
679
-		foreach ($topics as $topic_id)
704
+	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) {
705
+			foreach ($topics as $topic_id)
680 706
 			cache_put_data('topic_board-' . $topic_id, null, 120);
707
+	}
681 708
 
682 709
 	require_once($sourcedir . '/Subs-Post.php');
683 710
 
@@ -701,15 +728,17 @@  discard block
 block discarded – undo
701 728
 {
702 729
 	global $board, $topic, $smcFunc, $scripturl;
703 730
 
704
-	if (isset($_GET['current_board']))
705
-		$move_from = (int) $_GET['current_board'];
731
+	if (isset($_GET['current_board'])) {
732
+			$move_from = (int) $_GET['current_board'];
733
+	}
706 734
 
707
-	if (empty($move_from) || empty($board) || empty($topic))
708
-		return true;
735
+	if (empty($move_from) || empty($board) || empty($topic)) {
736
+			return true;
737
+	}
709 738
 
710
-	if ($move_from == $board)
711
-		return true;
712
-	else
739
+	if ($move_from == $board) {
740
+			return true;
741
+	} else
713 742
 	{
714 743
 		$request = $smcFunc['db_query']('', '
715 744
 			SELECT m.subject, b.name
Please login to merge, or discard this patch.
Sources/ManageSmileys.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1593,7 +1593,7 @@
 block discarded – undo
1593 1593
 	// Do the actual install
1594 1594
 	else
1595 1595
 	{
1596
-	    // @TODO Does this call have side effects? ($actions is not used)
1596
+		// @TODO Does this call have side effects? ($actions is not used)
1597 1597
 		$actions = parsePackageInfo($smileyInfo['xml'], false, 'install');
1598 1598
 		foreach ($context['actions'] as $action)
1599 1599
 		{
Please login to merge, or discard this patch.
Braces   +297 added lines, -211 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This is the dispatcher of smileys administration.
@@ -91,8 +92,9 @@  discard block
 block discarded – undo
91 92
 	);
92 93
 
93 94
 	// Some settings may not be enabled, disallow these from the tabs as appropriate.
94
-	if (empty($modSettings['messageIcons_enable']))
95
-		$context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
95
+	if (empty($modSettings['messageIcons_enable'])) {
96
+			$context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
97
+	}
96 98
 	if (empty($modSettings['smiley_enable']))
97 99
 	{
98 100
 		$context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true;
@@ -125,8 +127,9 @@  discard block
 block discarded – undo
125 127
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
126 128
 
127 129
 	$smiley_context = array();
128
-	foreach ($smiley_sets as $i => $set)
129
-		$smiley_context[$set] = $set_names[$i];
130
+	foreach ($smiley_sets as $i => $set) {
131
+			$smiley_context[$set] = $set_names[$i];
132
+	}
130 133
 
131 134
 	// All the settings for the page...
132 135
 	$config_vars = array(
@@ -147,8 +150,9 @@  discard block
 block discarded – undo
147 150
 
148 151
 	call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars));
149 152
 
150
-	if ($return_config)
151
-		return $config_vars;
153
+	if ($return_config) {
154
+			return $config_vars;
155
+	}
152 156
 
153 157
 	// Setup the basics of the settings template.
154 158
 	require_once($sourcedir . '/ManageServer.php');
@@ -207,8 +211,9 @@  discard block
 block discarded – undo
207 211
 			foreach ($_POST['smiley_set'] as $id => $val)
208 212
 			{
209 213
 				// If this is the set you've marked as default, or the only one remaining, you can't delete it
210
-				if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id]))
211
-					unset($set_paths[$id], $set_names[$id]);
214
+				if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) {
215
+									unset($set_paths[$id], $set_names[$id]);
216
+				}
212 217
 			}
213 218
 
214 219
 			// Shortcut... array_merge() on a single array resets the numeric keys
@@ -222,8 +227,9 @@  discard block
 block discarded – undo
222 227
 			));
223 228
 		}
224 229
 		// Add a new smiley set.
225
-		elseif (!empty($_POST['add']))
226
-			$context['sub_action'] = 'modifyset';
230
+		elseif (!empty($_POST['add'])) {
231
+					$context['sub_action'] = 'modifyset';
232
+		}
227 233
 		// Create or modify a smiley set.
228 234
 		elseif (isset($_POST['set']))
229 235
 		{
@@ -233,8 +239,9 @@  discard block
 block discarded – undo
233 239
 			// Create a new smiley set.
234 240
 			if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path']))
235 241
 			{
236
-				if (in_array($_POST['smiley_sets_path'], $set_paths))
237
-					fatal_lang_error('smiley_set_already_exists');
242
+				if (in_array($_POST['smiley_sets_path'], $set_paths)) {
243
+									fatal_lang_error('smiley_set_already_exists');
244
+				}
238 245
 
239 246
 				updateSettings(array(
240 247
 					'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'],
@@ -246,12 +253,14 @@  discard block
 block discarded – undo
246 253
 			else
247 254
 			{
248 255
 				// Make sure the smiley set exists.
249
-				if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']]))
250
-					fatal_lang_error('smiley_set_not_found');
256
+				if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) {
257
+									fatal_lang_error('smiley_set_not_found');
258
+				}
251 259
 
252 260
 				// Make sure the path is not yet used by another smileyset.
253
-				if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']])
254
-					fatal_lang_error('smiley_set_path_already_used');
261
+				if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) {
262
+									fatal_lang_error('smiley_set_path_already_used');
263
+				}
255 264
 
256 265
 				$set_paths[$_POST['set']] = $_POST['smiley_sets_path'];
257 266
 				$set_names[$_POST['set']] = $_POST['smiley_sets_name'];
@@ -263,8 +272,9 @@  discard block
 block discarded – undo
263 272
 			}
264 273
 
265 274
 			// The user might have checked to also import smileys.
266
-			if (!empty($_POST['smiley_sets_import']))
267
-				ImportSmileys($_POST['smiley_sets_path']);
275
+			if (!empty($_POST['smiley_sets_import'])) {
276
+							ImportSmileys($_POST['smiley_sets_path']);
277
+			}
268 278
 		}
269 279
 		cache_put_data('parsing_smileys', null, 480);
270 280
 		cache_put_data('posting_smileys', null, 480);
@@ -273,13 +283,14 @@  discard block
 block discarded – undo
273 283
 	// Load all available smileysets...
274 284
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
275 285
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
276
-	foreach ($context['smiley_sets'] as $i => $set)
277
-		$context['smiley_sets'][$i] = array(
286
+	foreach ($context['smiley_sets'] as $i => $set) {
287
+			$context['smiley_sets'][$i] = array(
278 288
 			'id' => $i,
279 289
 			'path' => $smcFunc['htmlspecialchars']($set),
280 290
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
281 291
 			'selected' => $set == $modSettings['smiley_sets_default']
282 292
 		);
293
+	}
283 294
 
284 295
 	// Importing any smileys from an existing set?
285 296
 	if ($context['sub_action'] == 'import')
@@ -290,8 +301,9 @@  discard block
 block discarded – undo
290 301
 		$_GET['set'] = (int) $_GET['set'];
291 302
 
292 303
 		// Sanity check - then import.
293
-		if (isset($context['smiley_sets'][$_GET['set']]))
294
-			ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
304
+		if (isset($context['smiley_sets'][$_GET['set']])) {
305
+					ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
306
+		}
295 307
 
296 308
 		// Force the process to continue.
297 309
 		$context['sub_action'] = 'modifyset';
@@ -301,15 +313,15 @@  discard block
 block discarded – undo
301 313
 	if ($context['sub_action'] == 'modifyset')
302 314
 	{
303 315
 		$_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set'];
304
-		if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']]))
305
-			$context['current_set'] = array(
316
+		if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) {
317
+					$context['current_set'] = array(
306 318
 				'id' => '-1',
307 319
 				'path' => '',
308 320
 				'name' => '',
309 321
 				'selected' => false,
310 322
 				'is_new' => true,
311 323
 			);
312
-		else
324
+		} else
313 325
 		{
314 326
 			$context['current_set'] = &$context['smiley_sets'][$_GET['set']];
315 327
 			$context['current_set']['is_new'] = false;
@@ -321,13 +333,15 @@  discard block
 block discarded – undo
321 333
 				$dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']);
322 334
 				while ($entry = $dir->read())
323 335
 				{
324
-					if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
325
-						$smileys[strtolower($entry)] = $entry;
336
+					if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
337
+											$smileys[strtolower($entry)] = $entry;
338
+					}
326 339
 				}
327 340
 				$dir->close();
328 341
 
329
-				if (empty($smileys))
330
-					fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name']));
342
+				if (empty($smileys)) {
343
+									fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name']));
344
+				}
331 345
 
332 346
 				// Exclude the smileys that are already in the database.
333 347
 				$request = $smcFunc['db_query']('', '
@@ -338,9 +352,10 @@  discard block
 block discarded – undo
338 352
 						'smiley_list' => $smileys,
339 353
 					)
340 354
 				);
341
-				while ($row = $smcFunc['db_fetch_assoc']($request))
342
-					if (isset($smileys[strtolower($row['filename'])]))
355
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
356
+									if (isset($smileys[strtolower($row['filename'])]))
343 357
 						unset($smileys[strtolower($row['filename'])]);
358
+				}
344 359
 				$smcFunc['db_free_result']($request);
345 360
 
346 361
 				$context['current_set']['can_import'] = count($smileys);
@@ -355,13 +370,14 @@  discard block
 block discarded – undo
355 370
 			$dir = dir($modSettings['smileys_dir']);
356 371
 			while ($entry = $dir->read())
357 372
 			{
358
-				if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry))
359
-					$context['smiley_set_dirs'][] = array(
373
+				if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) {
374
+									$context['smiley_set_dirs'][] = array(
360 375
 						'id' => $entry,
361 376
 						'path' => $modSettings['smileys_dir'] . '/' . $entry,
362 377
 						'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])),
363 378
 						'current' => $entry == $context['current_set']['path'],
364 379
 					);
380
+				}
365 381
 			}
366 382
 			$dir->close();
367 383
 		}
@@ -371,8 +387,9 @@  discard block
 block discarded – undo
371 387
 	createToken('admin-mss', 'request');
372 388
 
373 389
 	// In case we need to import smileys, we need to add the token in now.
374
-	if (isset($context['current_set']['import_url']))
375
-		$context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token'];
390
+	if (isset($context['current_set']['import_url'])) {
391
+			$context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token'];
392
+	}
376 393
 
377 394
 	$listOptions = array(
378 395
 		'id' => 'smiley_set_list',
@@ -510,21 +527,23 @@  discard block
 block discarded – undo
510 527
 		$cols['name'][] = $set_names[$i];
511 528
 	}
512 529
 	$sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC;
513
-	if (substr($sort, 0, 4) === 'name')
514
-		array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']);
515
-	elseif (substr($sort, 0, 4) === 'path')
516
-		array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']);
517
-	else
518
-		array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']);
530
+	if (substr($sort, 0, 4) === 'name') {
531
+			array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']);
532
+	} elseif (substr($sort, 0, 4) === 'path') {
533
+			array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']);
534
+	} else {
535
+			array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']);
536
+	}
519 537
 
520 538
 	$smiley_sets = array();
521
-	foreach ($cols['id'] as $i => $id)
522
-		$smiley_sets[] = array(
539
+	foreach ($cols['id'] as $i => $id) {
540
+			$smiley_sets[] = array(
523 541
 			'id' => $id,
524 542
 			'path' => $cols['path'][$i],
525 543
 			'name' => $cols['name'][$i],
526 544
 			'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default']
527 545
 		);
546
+	}
528 547
 
529 548
 	return $smiley_sets;
530 549
 }
@@ -553,13 +572,14 @@  discard block
 block discarded – undo
553 572
 	$context['smileys_dir_found'] = is_dir($context['smileys_dir']);
554 573
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
555 574
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
556
-	foreach ($context['smiley_sets'] as $i => $set)
557
-		$context['smiley_sets'][$i] = array(
575
+	foreach ($context['smiley_sets'] as $i => $set) {
576
+			$context['smiley_sets'][$i] = array(
558 577
 			'id' => $i,
559 578
 			'path' => $smcFunc['htmlspecialchars']($set),
560 579
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
561 580
 			'selected' => $set == $modSettings['smiley_sets_default']
562 581
 		);
582
+	}
563 583
 
564 584
 	// Submitting a form?
565 585
 	if (isset($_POST[$context['session_var']], $_POST['smiley_code']))
@@ -575,8 +595,9 @@  discard block
 block discarded – undo
575 595
 		$_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']);
576 596
 
577 597
 		// Make sure some code was entered.
578
-		if (empty($_POST['smiley_code']))
579
-			fatal_lang_error('smiley_has_no_code');
598
+		if (empty($_POST['smiley_code'])) {
599
+					fatal_lang_error('smiley_has_no_code');
600
+		}
580 601
 
581 602
 		// Check whether the new code has duplicates. It should be unique.
582 603
 		$request = $smcFunc['db_query']('', '
@@ -588,8 +609,9 @@  discard block
 block discarded – undo
588 609
 				'smiley_code' => $_POST['smiley_code'],
589 610
 			)
590 611
 		);
591
-		if ($smcFunc['db_num_rows']($request) > 0)
592
-			fatal_lang_error('smiley_not_unique');
612
+		if ($smcFunc['db_num_rows']($request) > 0) {
613
+					fatal_lang_error('smiley_not_unique');
614
+		}
593 615
 		$smcFunc['db_free_result']($request);
594 616
 
595 617
 		// If we are uploading - check all the smiley sets are writable!
@@ -598,38 +620,44 @@  discard block
 block discarded – undo
598 620
 			$writeErrors = array();
599 621
 			foreach ($context['smiley_sets'] as $set)
600 622
 			{
601
-				if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path'])))
602
-					$writeErrors[] = $set['path'];
623
+				if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) {
624
+									$writeErrors[] = $set['path'];
625
+				}
626
+			}
627
+			if (!empty($writeErrors)) {
628
+							fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
603 629
 			}
604
-			if (!empty($writeErrors))
605
-				fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
606 630
 		}
607 631
 
608 632
 		// Uploading just one smiley for all of them?
609 633
 		if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '')
610 634
 		{
611
-			if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name'])))
612
-				fatal_lang_error('smileys_upload_error');
635
+			if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) {
636
+							fatal_lang_error('smileys_upload_error');
637
+			}
613 638
 
614 639
 			// Sorry, no spaces, dots, or anything else but letters allowed.
615 640
 			$_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']);
616 641
 
617 642
 			// We only allow image files - it's THAT simple - no messing around here...
618
-			if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes))
619
-				fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
643
+			if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) {
644
+							fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
645
+			}
620 646
 
621 647
 			// We only need the filename...
622 648
 			$destName = basename($_FILES['uploadSmiley']['name']);
623 649
 
624 650
 			// Make sure they aren't trying to upload a nasty file - for their own good here!
625
-			if (in_array(strtolower($destName), $disabledFiles))
626
-				fatal_lang_error('smileys_upload_error_illegal');
651
+			if (in_array(strtolower($destName), $disabledFiles)) {
652
+							fatal_lang_error('smileys_upload_error_illegal');
653
+			}
627 654
 
628 655
 			// Check if the file already exists... and if not move it to EVERY smiley set directory.
629 656
 			$i = 0;
630 657
 			// Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?)
631
-			while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName))
632
-				$i++;
658
+			while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) {
659
+							$i++;
660
+			}
633 661
 
634 662
 			// Okay, we're going to put the smiley right here, since it's not there yet!
635 663
 			if (isset($context['smiley_sets'][$i]['path']))
@@ -644,8 +672,9 @@  discard block
 block discarded – undo
644 672
 					$currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName;
645 673
 
646 674
 					// The file is already there!  Don't overwrite it!
647
-					if (file_exists($currentPath))
648
-						continue;
675
+					if (file_exists($currentPath)) {
676
+											continue;
677
+					}
649 678
 
650 679
 					// Okay, so copy the first one we made to here.
651 680
 					copy($smileyLocation, $currentPath);
@@ -662,13 +691,15 @@  discard block
 block discarded – undo
662 691
 			$newName = '';
663 692
 			foreach ($_FILES as $name => $data)
664 693
 			{
665
-				if ($_FILES[$name]['name'] == '')
666
-					fatal_lang_error('smileys_upload_error_blank');
694
+				if ($_FILES[$name]['name'] == '') {
695
+									fatal_lang_error('smileys_upload_error_blank');
696
+				}
667 697
 
668
-				if (empty($newName))
669
-					$newName = basename($_FILES[$name]['name']);
670
-				elseif (basename($_FILES[$name]['name']) != $newName)
671
-					fatal_lang_error('smileys_upload_error_name');
698
+				if (empty($newName)) {
699
+									$newName = basename($_FILES[$name]['name']);
700
+				} elseif (basename($_FILES[$name]['name']) != $newName) {
701
+									fatal_lang_error('smileys_upload_error_name');
702
+				}
672 703
 			}
673 704
 
674 705
 			foreach ($context['smiley_sets'] as $i => $set)
@@ -676,31 +707,36 @@  discard block
 block discarded – undo
676 707
 				$set['name'] = un_htmlspecialchars($set['name']);
677 708
 				$set['path'] = un_htmlspecialchars($set['path']);
678 709
 
679
-				if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '')
680
-					continue;
710
+				if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') {
711
+									continue;
712
+				}
681 713
 
682 714
 				// Got one...
683
-				if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name'])))
684
-					fatal_lang_error('smileys_upload_error');
715
+				if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) {
716
+									fatal_lang_error('smileys_upload_error');
717
+				}
685 718
 
686 719
 				// Sorry, no spaces, dots, or anything else but letters allowed.
687 720
 				$_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']);
688 721
 
689 722
 				// We only allow image files - it's THAT simple - no messing around here...
690
-				if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes))
691
-					fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
723
+				if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) {
724
+									fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
725
+				}
692 726
 
693 727
 				// We only need the filename...
694 728
 				$destName = basename($_FILES['individual_' . $set['name']]['name']);
695 729
 
696 730
 				// Make sure they aren't trying to upload a nasty file - for their own good here!
697
-				if (in_array(strtolower($destName), $disabledFiles))
698
-					fatal_lang_error('smileys_upload_error_illegal');
731
+				if (in_array(strtolower($destName), $disabledFiles)) {
732
+									fatal_lang_error('smileys_upload_error_illegal');
733
+				}
699 734
 
700 735
 				// If the file exists - ignore it.
701 736
 				$smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName;
702
-				if (file_exists($smileyLocation))
703
-					continue;
737
+				if (file_exists($smileyLocation)) {
738
+									continue;
739
+				}
704 740
 
705 741
 				// Finally - move the image!
706 742
 				move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation);
@@ -712,8 +748,9 @@  discard block
 block discarded – undo
712 748
 		}
713 749
 
714 750
 		// Also make sure a filename was given.
715
-		if (empty($_POST['smiley_filename']))
716
-			fatal_lang_error('smiley_has_no_filename');
751
+		if (empty($_POST['smiley_filename'])) {
752
+					fatal_lang_error('smiley_has_no_filename');
753
+		}
717 754
 
718 755
 		// Find the position on the right.
719 756
 		$smiley_order = '0';
@@ -732,8 +769,9 @@  discard block
 block discarded – undo
732 769
 			list ($smiley_order) = $smcFunc['db_fetch_row']($request);
733 770
 			$smcFunc['db_free_result']($request);
734 771
 
735
-			if (empty($smiley_order))
736
-				$smiley_order = '0';
772
+			if (empty($smiley_order)) {
773
+							$smiley_order = '0';
774
+			}
737 775
 		}
738 776
 		$smcFunc['db_insert']('',
739 777
 			'{db_prefix}smileys',
@@ -761,17 +799,19 @@  discard block
 block discarded – undo
761 799
 	{
762 800
 		foreach ($context['smiley_sets'] as $smiley_set)
763 801
 		{
764
-			if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
765
-				continue;
802
+			if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) {
803
+							continue;
804
+			}
766 805
 
767 806
 			$dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
768 807
 			while ($entry = $dir->read())
769 808
 			{
770
-				if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
771
-					$context['filenames'][strtolower($entry)] = array(
809
+				if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
810
+									$context['filenames'][strtolower($entry)] = array(
772 811
 						'id' => $smcFunc['htmlspecialchars']($entry),
773 812
 						'selected' => false,
774 813
 					);
814
+				}
775 815
 			}
776 816
 			$dir->close();
777 817
 		}
@@ -809,17 +849,19 @@  discard block
 block discarded – undo
809 849
 		// Changing the selected smileys?
810 850
 		if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys']))
811 851
 		{
812
-			foreach ($_POST['checked_smileys'] as $id => $smiley_id)
813
-				$_POST['checked_smileys'][$id] = (int) $smiley_id;
852
+			foreach ($_POST['checked_smileys'] as $id => $smiley_id) {
853
+							$_POST['checked_smileys'][$id] = (int) $smiley_id;
854
+			}
814 855
 
815
-			if ($_POST['smiley_action'] == 'delete')
816
-				$smcFunc['db_query']('', '
856
+			if ($_POST['smiley_action'] == 'delete') {
857
+							$smcFunc['db_query']('', '
817 858
 					DELETE FROM {db_prefix}smileys
818 859
 					WHERE id_smiley IN ({array_int:checked_smileys})',
819 860
 					array(
820 861
 						'checked_smileys' => $_POST['checked_smileys'],
821 862
 					)
822 863
 				);
864
+			}
823 865
 			// Changing the status of the smiley?
824 866
 			else
825 867
 			{
@@ -829,8 +871,8 @@  discard block
 block discarded – undo
829 871
 					'hidden' => 1,
830 872
 					'popup' => 2
831 873
 				);
832
-				if (isset($displayTypes[$_POST['smiley_action']]))
833
-					$smcFunc['db_query']('', '
874
+				if (isset($displayTypes[$_POST['smiley_action']])) {
875
+									$smcFunc['db_query']('', '
834 876
 						UPDATE {db_prefix}smileys
835 877
 						SET hidden = {int:display_type}
836 878
 						WHERE id_smiley IN ({array_int:checked_smileys})',
@@ -839,6 +881,7 @@  discard block
 block discarded – undo
839 881
 							'display_type' => $displayTypes[$_POST['smiley_action']],
840 882
 						)
841 883
 					);
884
+				}
842 885
 			}
843 886
 		}
844 887
 		// Create/modify a smiley.
@@ -864,12 +907,14 @@  discard block
 block discarded – undo
864 907
 				$_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location'];
865 908
 
866 909
 				// Make sure some code was entered.
867
-				if (empty($_POST['smiley_code']))
868
-					fatal_lang_error('smiley_has_no_code');
910
+				if (empty($_POST['smiley_code'])) {
911
+									fatal_lang_error('smiley_has_no_code');
912
+				}
869 913
 
870 914
 				// Also make sure a filename was given.
871
-				if (empty($_POST['smiley_filename']))
872
-					fatal_lang_error('smiley_has_no_filename');
915
+				if (empty($_POST['smiley_filename'])) {
916
+									fatal_lang_error('smiley_has_no_filename');
917
+				}
873 918
 
874 919
 				// Check whether the new code has duplicates. It should be unique.
875 920
 				$request = $smcFunc['db_query']('', '
@@ -883,8 +928,9 @@  discard block
 block discarded – undo
883 928
 						'smiley_code' => $_POST['smiley_code'],
884 929
 					)
885 930
 				);
886
-				if ($smcFunc['db_num_rows']($request) > 0)
887
-					fatal_lang_error('smiley_not_unique');
931
+				if ($smcFunc['db_num_rows']($request) > 0) {
932
+									fatal_lang_error('smiley_not_unique');
933
+				}
888 934
 				$smcFunc['db_free_result']($request);
889 935
 
890 936
 				$smcFunc['db_query']('', '
@@ -913,13 +959,14 @@  discard block
 block discarded – undo
913 959
 	// Load all known smiley sets.
914 960
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
915 961
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
916
-	foreach ($context['smiley_sets'] as $i => $set)
917
-		$context['smiley_sets'][$i] = array(
962
+	foreach ($context['smiley_sets'] as $i => $set) {
963
+			$context['smiley_sets'][$i] = array(
918 964
 			'id' => $i,
919 965
 			'path' => $smcFunc['htmlspecialchars']($set),
920 966
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
921 967
 			'selected' => $set == $modSettings['smiley_sets_default']
922 968
 		);
969
+	}
923 970
 
924 971
 	// Prepare overview of all (custom) smileys.
925 972
 	if ($context['sub_action'] == 'editsmileys')
@@ -935,9 +982,10 @@  discard block
 block discarded – undo
935 982
 		// Create a list of options for selecting smiley sets.
936 983
 		$smileyset_option_list = '
937 984
 			<select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">';
938
-		foreach ($context['smiley_sets'] as $smiley_set)
939
-			$smileyset_option_list .= '
985
+		foreach ($context['smiley_sets'] as $smiley_set) {
986
+					$smileyset_option_list .= '
940 987
 				<option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>';
988
+		}
941 989
 		$smileyset_option_list .= '
942 990
 			</select>';
943 991
 
@@ -999,12 +1047,13 @@  discard block
 block discarded – undo
999 1047
 					'data' => array(
1000 1048
 						'function' => function ($rowData) use ($txt)
1001 1049
 						{
1002
-							if (empty($rowData['hidden']))
1003
-								return $txt['smileys_location_form'];
1004
-							elseif ($rowData['hidden'] == 1)
1005
-								return $txt['smileys_location_hidden'];
1006
-							else
1007
-								return $txt['smileys_location_popup'];
1050
+							if (empty($rowData['hidden'])) {
1051
+															return $txt['smileys_location_form'];
1052
+							} elseif ($rowData['hidden'] == 1) {
1053
+															return $txt['smileys_location_hidden'];
1054
+							} else {
1055
+															return $txt['smileys_location_popup'];
1056
+							}
1008 1057
 						},
1009 1058
 					),
1010 1059
 					'sort' => array(
@@ -1019,19 +1068,22 @@  discard block
 block discarded – undo
1019 1068
 					'data' => array(
1020 1069
 						'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc)
1021 1070
 						{
1022
-							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir']))
1023
-								return $smcFunc['htmlspecialchars']($rowData['description']);
1071
+							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) {
1072
+															return $smcFunc['htmlspecialchars']($rowData['description']);
1073
+							}
1024 1074
 
1025 1075
 							// Check if there are smileys missing in some sets.
1026 1076
 							$missing_sets = array();
1027
-							foreach ($context['smiley_sets'] as $smiley_set)
1028
-								if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename'])))
1077
+							foreach ($context['smiley_sets'] as $smiley_set) {
1078
+															if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename'])))
1029 1079
 									$missing_sets[] = $smiley_set['path'];
1080
+							}
1030 1081
 
1031 1082
 							$description = $smcFunc['htmlspecialchars']($rowData['description']);
1032 1083
 
1033
-							if (!empty($missing_sets))
1034
-								$description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets));
1084
+							if (!empty($missing_sets)) {
1085
+															$description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets));
1086
+							}
1035 1087
 
1036 1088
 							return $description;
1037 1089
 						},
@@ -1147,13 +1199,14 @@  discard block
 block discarded – undo
1147 1199
 		$context['smileys_dir_found'] = is_dir($context['smileys_dir']);
1148 1200
 		$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
1149 1201
 		$set_names = explode("\n", $modSettings['smiley_sets_names']);
1150
-		foreach ($context['smiley_sets'] as $i => $set)
1151
-			$context['smiley_sets'][$i] = array(
1202
+		foreach ($context['smiley_sets'] as $i => $set) {
1203
+					$context['smiley_sets'][$i] = array(
1152 1204
 				'id' => $i,
1153 1205
 				'path' => $smcFunc['htmlspecialchars']($set),
1154 1206
 				'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
1155 1207
 				'selected' => $set == $modSettings['smiley_sets_default']
1156 1208
 			);
1209
+		}
1157 1210
 
1158 1211
 		$context['selected_set'] = $modSettings['smiley_sets_default'];
1159 1212
 
@@ -1163,17 +1216,19 @@  discard block
 block discarded – undo
1163 1216
 		{
1164 1217
 			foreach ($context['smiley_sets'] as $smiley_set)
1165 1218
 			{
1166
-				if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
1167
-					continue;
1219
+				if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) {
1220
+									continue;
1221
+				}
1168 1222
 
1169 1223
 				$dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
1170 1224
 				while ($entry = $dir->read())
1171 1225
 				{
1172
-					if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
1173
-						$context['filenames'][strtolower($entry)] = array(
1226
+					if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
1227
+											$context['filenames'][strtolower($entry)] = array(
1174 1228
 							'id' => $smcFunc['htmlspecialchars']($entry),
1175 1229
 							'selected' => false,
1176 1230
 						);
1231
+					}
1177 1232
 				}
1178 1233
 				$dir->close();
1179 1234
 			}
@@ -1188,8 +1243,9 @@  discard block
 block discarded – undo
1188 1243
 				'current_smiley' => (int) $_REQUEST['smiley'],
1189 1244
 			)
1190 1245
 		);
1191
-		if ($smcFunc['db_num_rows']($request) != 1)
1192
-			fatal_lang_error('smiley_not_found');
1246
+		if ($smcFunc['db_num_rows']($request) != 1) {
1247
+					fatal_lang_error('smiley_not_found');
1248
+		}
1193 1249
 		$context['current_smiley'] = $smcFunc['db_fetch_assoc']($request);
1194 1250
 		$smcFunc['db_free_result']($request);
1195 1251
 
@@ -1197,8 +1253,9 @@  discard block
 block discarded – undo
1197 1253
 		$context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']);
1198 1254
 		$context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']);
1199 1255
 
1200
-		if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])]))
1201
-			$context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
1256
+		if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) {
1257
+					$context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
1258
+		}
1202 1259
 	}
1203 1260
 }
1204 1261
 
@@ -1223,8 +1280,9 @@  discard block
 block discarded – undo
1223 1280
 		)
1224 1281
 	);
1225 1282
 	$smileys = array();
1226
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1227
-		$smileys[] = $row;
1283
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1284
+			$smileys[] = $row;
1285
+	}
1228 1286
 	$smcFunc['db_free_result']($request);
1229 1287
 
1230 1288
 	return $smileys;
@@ -1264,8 +1322,9 @@  discard block
 block discarded – undo
1264 1322
 		$_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2;
1265 1323
 		$_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source'];
1266 1324
 
1267
-		if (empty($_GET['source']))
1268
-			fatal_lang_error('smiley_not_found');
1325
+		if (empty($_GET['source'])) {
1326
+					fatal_lang_error('smiley_not_found');
1327
+		}
1269 1328
 
1270 1329
 		if (!empty($_GET['after']))
1271 1330
 		{
@@ -1281,12 +1340,12 @@  discard block
 block discarded – undo
1281 1340
 					'after_smiley' => $_GET['after'],
1282 1341
 				)
1283 1342
 			);
1284
-			if ($smcFunc['db_num_rows']($request) != 1)
1285
-				fatal_lang_error('smiley_not_found');
1343
+			if ($smcFunc['db_num_rows']($request) != 1) {
1344
+							fatal_lang_error('smiley_not_found');
1345
+			}
1286 1346
 			list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request);
1287 1347
 			$smcFunc['db_free_result']($request);
1288
-		}
1289
-		else
1348
+		} else
1290 1349
 		{
1291 1350
 			$smiley_row = (int) $_GET['row'];
1292 1351
 			$smiley_order = -1;
@@ -1360,14 +1419,15 @@  discard block
 block discarded – undo
1360 1419
 	$context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move'];
1361 1420
 
1362 1421
 	// Make sure all rows are sequential.
1363
-	foreach (array_keys($context['smileys']) as $location)
1364
-		$context['smileys'][$location] = array(
1422
+	foreach (array_keys($context['smileys']) as $location) {
1423
+			$context['smileys'][$location] = array(
1365 1424
 			'id' => $location,
1366 1425
 			'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'],
1367 1426
 			'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'],
1368 1427
 			'last_row' => count($context['smileys'][$location]['rows']),
1369 1428
 			'rows' => array_values($context['smileys'][$location]['rows']),
1370 1429
 		);
1430
+	}
1371 1431
 
1372 1432
 	// Check & fix smileys that are not ordered properly in the database.
1373 1433
 	foreach (array_keys($context['smileys']) as $location)
@@ -1392,8 +1452,8 @@  discard block
 block discarded – undo
1392 1452
 				$context['smileys'][$location]['rows'][$id][0]['row'] = $id;
1393 1453
 			}
1394 1454
 			// Make sure the smiley order is always sequential.
1395
-			foreach ($smiley_row as $order_id => $smiley)
1396
-				if ($order_id != $smiley['order'])
1455
+			foreach ($smiley_row as $order_id => $smiley) {
1456
+							if ($order_id != $smiley['order'])
1397 1457
 					$smcFunc['db_query']('', '
1398 1458
 						UPDATE {db_prefix}smileys
1399 1459
 						SET smiley_order = {int:new_order}
@@ -1403,6 +1463,7 @@  discard block
 block discarded – undo
1403 1463
 							'current_smiley' => $smiley['id'],
1404 1464
 						)
1405 1465
 					);
1466
+			}
1406 1467
 		}
1407 1468
 	}
1408 1469
 
@@ -1436,19 +1497,20 @@  discard block
 block discarded – undo
1436 1497
 
1437 1498
 		// Check that the smiley is from simplemachines.org, for now... maybe add mirroring later.
1438 1499
 		// @ TODO: Our current xml files serve http links.  Allowing both for now until we serve https.
1439
-		if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false)
1440
-			fatal_lang_error('not_on_simplemachines');
1500
+		if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) {
1501
+					fatal_lang_error('not_on_simplemachines');
1502
+		}
1441 1503
 
1442 1504
 		$destination = $packagesdir . '/' . $base_name;
1443 1505
 
1444
-		if (file_exists($destination))
1445
-			fatal_lang_error('package_upload_error_exists');
1506
+		if (file_exists($destination)) {
1507
+					fatal_lang_error('package_upload_error_exists');
1508
+		}
1446 1509
 
1447 1510
 		// Let's copy it to the Packages directory
1448 1511
 		file_put_contents($destination, fetch_web_data($_REQUEST['set_gz']));
1449 1512
 		$testing = true;
1450
-	}
1451
-	elseif (isset($_REQUEST['package']))
1513
+	} elseif (isset($_REQUEST['package']))
1452 1514
 	{
1453 1515
 		$base_name = basename($_REQUEST['package']);
1454 1516
 		$name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.'));
@@ -1457,12 +1519,14 @@  discard block
 block discarded – undo
1457 1519
 		$destination = $packagesdir . '/' . basename($_REQUEST['package']);
1458 1520
 	}
1459 1521
 
1460
-	if (empty($destination) || !file_exists($destination))
1461
-		fatal_lang_error('package_no_file', false);
1522
+	if (empty($destination) || !file_exists($destination)) {
1523
+			fatal_lang_error('package_no_file', false);
1524
+	}
1462 1525
 
1463 1526
 	// Make sure temp directory exists and is empty.
1464
-	if (file_exists($packagesdir . '/temp'))
1465
-		deltree($packagesdir . '/temp', false);
1527
+	if (file_exists($packagesdir . '/temp')) {
1528
+			deltree($packagesdir . '/temp', false);
1529
+	}
1466 1530
 
1467 1531
 	if (!mktree($packagesdir . '/temp', 0755))
1468 1532
 	{
@@ -1474,31 +1538,37 @@  discard block
 block discarded – undo
1474 1538
 			create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true));
1475 1539
 
1476 1540
 			deltree($packagesdir . '/temp', false);
1477
-			if (!mktree($packagesdir . '/temp', 0777))
1478
-				fatal_lang_error('package_cant_download', false);
1541
+			if (!mktree($packagesdir . '/temp', 0777)) {
1542
+							fatal_lang_error('package_cant_download', false);
1543
+			}
1479 1544
 		}
1480 1545
 	}
1481 1546
 
1482 1547
 	$extracted = read_tgz_file($destination, $packagesdir . '/temp');
1483
-	if (!$extracted)
1484
-		fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name));
1485
-	if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml'))
1486
-		foreach ($extracted as $file)
1548
+	if (!$extracted) {
1549
+			fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name));
1550
+	}
1551
+	if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) {
1552
+			foreach ($extracted as $file)
1487 1553
 			if (basename($file['filename']) == 'package-info.xml')
1488 1554
 			{
1489 1555
 				$base_path = dirname($file['filename']) . '/';
1556
+	}
1490 1557
 				break;
1491 1558
 			}
1492 1559
 
1493
-	if (!isset($base_path))
1494
-		$base_path = '';
1560
+	if (!isset($base_path)) {
1561
+			$base_path = '';
1562
+	}
1495 1563
 
1496
-	if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml'))
1497
-		fatal_lang_error('package_get_error_missing_xml', false);
1564
+	if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) {
1565
+			fatal_lang_error('package_get_error_missing_xml', false);
1566
+	}
1498 1567
 
1499 1568
 	$smileyInfo = getPackageInfo($context['filename']);
1500
-	if (!is_array($smileyInfo))
1501
-		fatal_lang_error($smileyInfo);
1569
+	if (!is_array($smileyInfo)) {
1570
+			fatal_lang_error($smileyInfo);
1571
+	}
1502 1572
 
1503 1573
 	// See if it is installed?
1504 1574
 	$request = $smcFunc['db_query']('', '
@@ -1514,8 +1584,9 @@  discard block
 block discarded – undo
1514 1584
 		)
1515 1585
 	);
1516 1586
 
1517
-	if ($smcFunc['db_num_rows']($request) > 0)
1518
-		fatal_lang_error('package_installed_warning1');
1587
+	if ($smcFunc['db_num_rows']($request) > 0) {
1588
+			fatal_lang_error('package_installed_warning1');
1589
+	}
1519 1590
 
1520 1591
 	// Everything is fine, now it's time to do something
1521 1592
 	$actions = parsePackageInfo($smileyInfo['xml'], true, 'install');
@@ -1530,23 +1601,23 @@  discard block
 block discarded – undo
1530 1601
 		if ($action['type'] == 'readme' || $action['type'] == 'license')
1531 1602
 		{
1532 1603
 			$type = 'package_' . $action['type'];
1533
-			if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename']))
1534
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r"));
1535
-			elseif (file_exists($action['filename']))
1536
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
1604
+			if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) {
1605
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r"));
1606
+			} elseif (file_exists($action['filename'])) {
1607
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
1608
+			}
1537 1609
 
1538 1610
 			if (!empty($action['parse_bbc']))
1539 1611
 			{
1540 1612
 				require_once($sourcedir . '/Subs-Post.php');
1541 1613
 				preparsecode($context[$type]);
1542 1614
 				$context[$type] = parse_bbc($context[$type]);
1615
+			} else {
1616
+							$context[$type] = nl2br($context[$type]);
1543 1617
 			}
1544
-			else
1545
-				$context[$type] = nl2br($context[$type]);
1546 1618
 
1547 1619
 			continue;
1548
-		}
1549
-		elseif ($action['type'] == 'require-dir')
1620
+		} elseif ($action['type'] == 'require-dir')
1550 1621
 		{
1551 1622
 			// Do this one...
1552 1623
 			$thisAction = array(
@@ -1565,12 +1636,12 @@  discard block
 block discarded – undo
1565 1636
 				);
1566 1637
 			}
1567 1638
 			// @todo None given?
1568
-			if (empty($thisAction['description']))
1569
-				$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
1639
+			if (empty($thisAction['description'])) {
1640
+							$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
1641
+			}
1570 1642
 
1571 1643
 			$context['actions'][] = $thisAction;
1572
-		}
1573
-		elseif ($action['type'] == 'credits')
1644
+		} elseif ($action['type'] == 'credits')
1574 1645
 		{
1575 1646
 			// Time to build the billboard
1576 1647
 			$credits_tag = array(
@@ -1630,12 +1701,14 @@  discard block
 block discarded – undo
1630 1701
 		cache_put_data('posting_smileys', null, 480);
1631 1702
 	}
1632 1703
 
1633
-	if (file_exists($packagesdir . '/temp'))
1634
-		deltree($packagesdir . '/temp');
1704
+	if (file_exists($packagesdir . '/temp')) {
1705
+			deltree($packagesdir . '/temp');
1706
+	}
1635 1707
 
1636
-	if (!$testing)
1637
-		redirectexit('action=admin;area=smileys');
1638
-}
1708
+	if (!$testing) {
1709
+			redirectexit('action=admin;area=smileys');
1710
+	}
1711
+	}
1639 1712
 
1640 1713
 /**
1641 1714
  * A function to import new smileys from an existing directory into the database.
@@ -1646,15 +1719,17 @@  discard block
 block discarded – undo
1646 1719
 {
1647 1720
 	global $modSettings, $smcFunc;
1648 1721
 
1649
-	if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath))
1650
-		fatal_lang_error('smiley_set_unable_to_import');
1722
+	if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) {
1723
+			fatal_lang_error('smiley_set_unable_to_import');
1724
+	}
1651 1725
 
1652 1726
 	$smileys = array();
1653 1727
 	$dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath);
1654 1728
 	while ($entry = $dir->read())
1655 1729
 	{
1656
-		if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
1657
-			$smileys[strtolower($entry)] = $entry;
1730
+		if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
1731
+					$smileys[strtolower($entry)] = $entry;
1732
+		}
1658 1733
 	}
1659 1734
 	$dir->close();
1660 1735
 
@@ -1667,9 +1742,10 @@  discard block
 block discarded – undo
1667 1742
 			'smiley_list' => $smileys,
1668 1743
 		)
1669 1744
 	);
1670
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1671
-		if (isset($smileys[strtolower($row['filename'])]))
1745
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1746
+			if (isset($smileys[strtolower($row['filename'])]))
1672 1747
 			unset($smileys[strtolower($row['filename'])]);
1748
+	}
1673 1749
 	$smcFunc['db_free_result']($request);
1674 1750
 
1675 1751
 	$request = $smcFunc['db_query']('', '
@@ -1686,9 +1762,10 @@  discard block
 block discarded – undo
1686 1762
 	$smcFunc['db_free_result']($request);
1687 1763
 
1688 1764
 	$new_smileys = array();
1689
-	foreach ($smileys as $smiley)
1690
-		if (strlen($smiley) <= 48)
1765
+	foreach ($smileys as $smiley) {
1766
+			if (strlen($smiley) <= 48)
1691 1767
 			$new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order);
1768
+	}
1692 1769
 
1693 1770
 	if (!empty($new_smileys))
1694 1771
 	{
@@ -1753,8 +1830,9 @@  discard block
 block discarded – undo
1753 1830
 		if (isset($_POST['delete']) && !empty($_POST['checked_icons']))
1754 1831
 		{
1755 1832
 			$deleteIcons = array();
1756
-			foreach ($_POST['checked_icons'] as $icon)
1757
-				$deleteIcons[] = (int) $icon;
1833
+			foreach ($_POST['checked_icons'] as $icon) {
1834
+							$deleteIcons[] = (int) $icon;
1835
+			}
1758 1836
 
1759 1837
 			// Do the actual delete!
1760 1838
 			$smcFunc['db_query']('', '
@@ -1771,35 +1849,41 @@  discard block
 block discarded – undo
1771 1849
 			$_GET['icon'] = (int) $_GET['icon'];
1772 1850
 
1773 1851
 			// Do some preperation with the data... like check the icon exists *somewhere*
1774
-			if (strpos($_POST['icon_filename'], '.png') !== false)
1775
-				$_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
1776
-			if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png'))
1777
-				fatal_lang_error('icon_not_found');
1852
+			if (strpos($_POST['icon_filename'], '.png') !== false) {
1853
+							$_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
1854
+			}
1855
+			if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) {
1856
+							fatal_lang_error('icon_not_found');
1857
+			}
1778 1858
 			// There is a 16 character limit on message icons...
1779
-			elseif (strlen($_POST['icon_filename']) > 16)
1780
-				fatal_lang_error('icon_name_too_long');
1781
-			elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon']))
1782
-				fatal_lang_error('icon_after_itself');
1859
+			elseif (strlen($_POST['icon_filename']) > 16) {
1860
+							fatal_lang_error('icon_name_too_long');
1861
+			} elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) {
1862
+							fatal_lang_error('icon_after_itself');
1863
+			}
1783 1864
 
1784 1865
 			// First do the sorting... if this is an edit reduce the order of everything after it by one ;)
1785 1866
 			if ($_GET['icon'] != 0)
1786 1867
 			{
1787 1868
 				$oldOrder = $context['icons'][$_GET['icon']]['true_order'];
1788
-				foreach ($context['icons'] as $id => $data)
1789
-					if ($data['true_order'] > $oldOrder)
1869
+				foreach ($context['icons'] as $id => $data) {
1870
+									if ($data['true_order'] > $oldOrder)
1790 1871
 						$context['icons'][$id]['true_order']--;
1872
+				}
1791 1873
 			}
1792 1874
 
1793 1875
 			// If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql)
1794
-			if (empty($_GET['icon']) && empty($context['icons']))
1795
-				$_GET['icon'] = 1;
1876
+			if (empty($_GET['icon']) && empty($context['icons'])) {
1877
+							$_GET['icon'] = 1;
1878
+			}
1796 1879
 
1797 1880
 			// Get the new order.
1798 1881
 			$newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1;
1799 1882
 			// Do the same, but with the one that used to be after this icon, done to avoid conflict.
1800
-			foreach ($context['icons'] as $id => $data)
1801
-				if ($data['true_order'] >= $newOrder)
1883
+			foreach ($context['icons'] as $id => $data) {
1884
+							if ($data['true_order'] >= $newOrder)
1802 1885
 					$context['icons'][$id]['true_order']++;
1886
+			}
1803 1887
 
1804 1888
 			// Finally set the current icon's position!
1805 1889
 			$context['icons'][$_GET['icon']]['true_order'] = $newOrder;
@@ -1817,8 +1901,7 @@  discard block
 block discarded – undo
1817 1901
 				if ($id != 0)
1818 1902
 				{
1819 1903
 					$iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
1820
-				}
1821
-				else
1904
+				} else
1822 1905
 				{
1823 1906
 					$iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
1824 1907
 				}
@@ -1843,8 +1926,9 @@  discard block
 block discarded – undo
1843 1926
 		}
1844 1927
 
1845 1928
 		// Unless we're adding a new thing, we'll escape
1846
-		if (!isset($_POST['add']))
1847
-			redirectexit('action=admin;area=smileys;sa=editicons');
1929
+		if (!isset($_POST['add'])) {
1930
+					redirectexit('action=admin;area=smileys;sa=editicons');
1931
+		}
1848 1932
 	}
1849 1933
 
1850 1934
 	$context[$context['admin_menu_name']]['current_subsection'] = 'editicons';
@@ -1954,8 +2038,9 @@  discard block
 block discarded – undo
1954 2038
 		$context['new_icon'] = !isset($_GET['icon']);
1955 2039
 
1956 2040
 		// Get the properties of the current icon from the icon list.
1957
-		if (!$context['new_icon'])
1958
-			$context['icon'] = $context['icons'][$_GET['icon']];
2041
+		if (!$context['new_icon']) {
2042
+					$context['icon'] = $context['icons'][$_GET['icon']];
2043
+		}
1959 2044
 
1960 2045
 		// Get a list of boards needed for assigning this icon to a specific board.
1961 2046
 		$boardListOptions = array(
@@ -1989,8 +2074,9 @@  discard block
 block discarded – undo
1989 2074
 	);
1990 2075
 
1991 2076
 	$message_icons = array();
1992
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1993
-		$message_icons[] = $row;
2077
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2078
+			$message_icons[] = $row;
2079
+	}
1994 2080
 	$smcFunc['db_free_result']($request);
1995 2081
 
1996 2082
 	return $message_icons;
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +435 added lines, -324 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 			
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 			
66
-			if ($charcode == 'UTF8')			
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -74,12 +76,14 @@  discard block
 block discarded – undo
74 76
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
75 77
 
76 78
 			// Is it reserved?
77
-			if ($value == 'pg_')
78
-				return $txt['error_db_prefix_reserved'];
79
+			if ($value == 'pg_') {
80
+							return $txt['error_db_prefix_reserved'];
81
+			}
79 82
 
80 83
 			// Is the prefix numeric?
81
-			if (preg_match('~^\d~', $value))
82
-				return $txt['error_db_prefix_numeric'];
84
+			if (preg_match('~^\d~', $value)) {
85
+							return $txt['error_db_prefix_numeric'];
86
+			}
83 87
 
84 88
 			return true;
85 89
 		},
@@ -124,10 +128,11 @@  discard block
 block discarded – undo
124 128
 		$incontext['skip'] = false;
125 129
 
126 130
 		// Call the step and if it returns false that means pause!
127
-		if (function_exists($step[2]) && $step[2]() === false)
128
-			break;
129
-		elseif (function_exists($step[2]))
130
-			$incontext['current_step']++;
131
+		if (function_exists($step[2]) && $step[2]() === false) {
132
+					break;
133
+		} elseif (function_exists($step[2])) {
134
+					$incontext['current_step']++;
135
+		}
131 136
 
132 137
 		// No warnings pass on.
133 138
 		$incontext['warning'] = '';
@@ -143,8 +148,9 @@  discard block
 block discarded – undo
143 148
 	global $databases;
144 149
 
145 150
 	// Just so people using older versions of PHP aren't left in the cold.
146
-	if (!isset($_SERVER['PHP_SELF']))
147
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
151
+	if (!isset($_SERVER['PHP_SELF'])) {
152
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
153
+	}
148 154
 
149 155
 	// Enable error reporting.
150 156
 	error_reporting(E_ALL);
@@ -160,21 +166,23 @@  discard block
 block discarded – undo
160 166
 	{
161 167
 		ob_start();
162 168
 
163
-		if (ini_get('session.save_handler') == 'user')
164
-			@ini_set('session.save_handler', 'files');
165
-		if (function_exists('session_start'))
166
-			@session_start();
167
-	}
168
-	else
169
+		if (ini_get('session.save_handler') == 'user') {
170
+					@ini_set('session.save_handler', 'files');
171
+		}
172
+		if (function_exists('session_start')) {
173
+					@session_start();
174
+		}
175
+	} else
169 176
 	{
170 177
 		ob_start('ob_gzhandler');
171 178
 
172
-		if (ini_get('session.save_handler') == 'user')
173
-			@ini_set('session.save_handler', 'files');
179
+		if (ini_get('session.save_handler') == 'user') {
180
+					@ini_set('session.save_handler', 'files');
181
+		}
174 182
 		session_start();
175 183
 
176
-		if (!headers_sent())
177
-			echo '<!DOCTYPE html>
184
+		if (!headers_sent()) {
185
+					echo '<!DOCTYPE html>
178 186
 <html>
179 187
 	<head>
180 188
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -183,14 +191,16 @@  discard block
 block discarded – undo
183 191
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
184 192
 	</body>
185 193
 </html>';
194
+		}
186 195
 		exit;
187 196
 	}
188 197
 
189 198
 	// Add slashes, as long as they aren't already being added.
190
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
191
-		foreach ($_POST as $k => $v)
199
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
200
+			foreach ($_POST as $k => $v)
192 201
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
193 202
 				$_POST[$k] = addslashes($v);
203
+	}
194 204
 
195 205
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
196 206
 	if (isset($_GET['delete']))
@@ -211,8 +221,7 @@  discard block
 block discarded – undo
211 221
 			$ftp->close();
212 222
 
213 223
 			unset($_SESSION['installer_temp_ftp']);
214
-		}
215
-		else
224
+		} else
216 225
 		{
217 226
 			@unlink(__FILE__);
218 227
 
@@ -233,10 +242,11 @@  discard block
 block discarded – undo
233 242
 	{
234 243
 		// Get PHP's default timezone, if set
235 244
 		$ini_tz = ini_get('date.timezone');
236
-		if (!empty($ini_tz))
237
-			$timezone_id = $ini_tz;
238
-		else
239
-			$timezone_id = '';
245
+		if (!empty($ini_tz)) {
246
+					$timezone_id = $ini_tz;
247
+		} else {
248
+					$timezone_id = '';
249
+		}
240 250
 
241 251
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
242 252
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -266,8 +276,9 @@  discard block
 block discarded – undo
266 276
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
267 277
 		while ($entry = $dir->read())
268 278
 		{
269
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
270
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
279
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
280
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
281
+			}
271 282
 		}
272 283
 		$dir->close();
273 284
 	}
@@ -302,10 +313,11 @@  discard block
 block discarded – undo
302 313
 	}
303 314
 
304 315
 	// Override the language file?
305
-	if (isset($_GET['lang_file']))
306
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
307
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
308
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
316
+	if (isset($_GET['lang_file'])) {
317
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
318
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
319
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
320
+	}
309 321
 
310 322
 	// Make sure it exists, if it doesn't reset it.
311 323
 	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']))
@@ -314,8 +326,9 @@  discard block
 block discarded – undo
314 326
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
315 327
 
316 328
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
317
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
318
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
329
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
330
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
331
+		}
319 332
 	}
320 333
 
321 334
 	// And now include the actual language file itself.
@@ -328,15 +341,18 @@  discard block
 block discarded – undo
328 341
 	global $db_prefix, $db_connection, $sourcedir;
329 342
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
330 343
 
331
-	if (empty($sourcedir))
332
-		$sourcedir = dirname(__FILE__) . '/Sources';
344
+	if (empty($sourcedir)) {
345
+			$sourcedir = dirname(__FILE__) . '/Sources';
346
+	}
333 347
 
334 348
 	// Need this to check whether we need the database password.
335 349
 	require(dirname(__FILE__) . '/Settings.php');
336
-	if (!defined('SMF'))
337
-		define('SMF', 1);
338
-	if (empty($smcFunc))
339
-		$smcFunc = array();
350
+	if (!defined('SMF')) {
351
+			define('SMF', 1);
352
+	}
353
+	if (empty($smcFunc)) {
354
+			$smcFunc = array();
355
+	}
340 356
 
341 357
 	$modSettings['disableQueryCheck'] = true;
342 358
 
@@ -344,8 +360,9 @@  discard block
 block discarded – undo
344 360
 	if (!$db_connection)
345 361
 	{
346 362
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
347
-		if (version_compare(PHP_VERSION, '5', '<'))
348
-			require_once($sourcedir . '/Subs-Compat.php');
363
+		if (version_compare(PHP_VERSION, '5', '<')) {
364
+					require_once($sourcedir . '/Subs-Compat.php');
365
+		}
349 366
 
350 367
 		$db_options = array('persist' => $db_persist);
351 368
 		$port = '';
@@ -356,19 +373,20 @@  discard block
 block discarded – undo
356 373
 			if ($db_type == 'mysql')
357 374
 			{
358 375
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
359
-			}
360
-			elseif ($db_type == 'postgresql')
376
+			} elseif ($db_type == 'postgresql')
361 377
 			{
362 378
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
363 379
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
364 380
 			}
365 381
 		}
366 382
 
367
-		if (!empty($port))
368
-			$db_options['port'] = $port;
383
+		if (!empty($port)) {
384
+					$db_options['port'] = $port;
385
+		}
369 386
 
370
-		if (!$db_connection)
371
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
387
+		if (!$db_connection) {
388
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
389
+		}
372 390
 	}
373 391
 }
374 392
 
@@ -396,8 +414,9 @@  discard block
 block discarded – undo
396 414
 		// @todo REMOVE THIS!!
397 415
 		else
398 416
 		{
399
-			if (function_exists('doStep' . $_GET['step']))
400
-				call_user_func('doStep' . $_GET['step']);
417
+			if (function_exists('doStep' . $_GET['step'])) {
418
+							call_user_func('doStep' . $_GET['step']);
419
+			}
401 420
 		}
402 421
 		// Show the footer.
403 422
 		template_install_below();
@@ -415,8 +434,9 @@  discard block
 block discarded – undo
415 434
 	$incontext['sub_template'] = 'welcome_message';
416 435
 
417 436
 	// Done the submission?
418
-	if (isset($_POST['contbutt']))
419
-		return true;
437
+	if (isset($_POST['contbutt'])) {
438
+			return true;
439
+	}
420 440
 
421 441
 	// See if we think they have already installed it?
422 442
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -424,14 +444,17 @@  discard block
 block discarded – undo
424 444
 		$probably_installed = 0;
425 445
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
426 446
 		{
427
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
428
-				$probably_installed++;
429
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
430
-				$probably_installed++;
447
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
448
+							$probably_installed++;
449
+			}
450
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
451
+							$probably_installed++;
452
+			}
431 453
 		}
432 454
 
433
-		if ($probably_installed == 2)
434
-			$incontext['warning'] = $txt['error_already_installed'];
455
+		if ($probably_installed == 2) {
456
+					$incontext['warning'] = $txt['error_already_installed'];
457
+		}
435 458
 	}
436 459
 
437 460
 	// Is some database support even compiled in?
@@ -446,36 +469,43 @@  discard block
 block discarded – undo
446 469
 				$databases[$key]['supported'] = false;
447 470
 				$notFoundSQLFile = true;
448 471
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
472
+			} else {
473
+							$incontext['supported_databases'][] = $db;
449 474
 			}
450
-			else
451
-				$incontext['supported_databases'][] = $db;
452 475
 		}
453 476
 	}
454 477
 
455 478
 	// Check the PHP version.
456
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
457
-		$error = 'error_php_too_low';
479
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
480
+			$error = 'error_php_too_low';
481
+	}
458 482
 	// Make sure we have a supported database
459
-	elseif (empty($incontext['supported_databases']))
460
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
483
+	elseif (empty($incontext['supported_databases'])) {
484
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
485
+	}
461 486
 	// How about session support?  Some crazy sysadmin remove it?
462
-	elseif (!function_exists('session_start'))
463
-		$error = 'error_session_missing';
487
+	elseif (!function_exists('session_start')) {
488
+			$error = 'error_session_missing';
489
+	}
464 490
 	// Make sure they uploaded all the files.
465
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
466
-		$error = 'error_missing_files';
491
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
492
+			$error = 'error_missing_files';
493
+	}
467 494
 	// Very simple check on the session.save_path for Windows.
468 495
 	// @todo Move this down later if they don't use database-driven sessions?
469
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
470
-		$error = 'error_session_save_path';
496
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
497
+			$error = 'error_session_save_path';
498
+	}
471 499
 
472 500
 	// Since each of the three messages would look the same, anyway...
473
-	if (isset($error))
474
-		$incontext['error'] = $txt[$error];
501
+	if (isset($error)) {
502
+			$incontext['error'] = $txt[$error];
503
+	}
475 504
 
476 505
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
477
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
478
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
506
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
507
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
508
+	}
479 509
 
480 510
 	return false;
481 511
 }
@@ -501,12 +531,14 @@  discard block
 block discarded – undo
501 531
 		'db_last_error.php',
502 532
 	);
503 533
 
504
-	foreach ($incontext['detected_languages'] as $lang => $temp)
505
-		$extra_files[] = 'Themes/default/languages/' . $lang;
534
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
535
+			$extra_files[] = 'Themes/default/languages/' . $lang;
536
+	}
506 537
 
507 538
 	// With mod_security installed, we could attempt to fix it with .htaccess.
508
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
509
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
539
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
540
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
541
+	}
510 542
 
511 543
 	$failed_files = array();
512 544
 
@@ -522,12 +554,14 @@  discard block
 block discarded – undo
522 554
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
523 555
 
524 556
 				// Well, 755 hopefully worked... if not, try 777.
525
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
526
-					$failed_files[] = $file;
557
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
558
+									$failed_files[] = $file;
559
+				}
527 560
 			}
528 561
 		}
529
-		foreach ($extra_files as $file)
530
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
562
+		foreach ($extra_files as $file) {
563
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
564
+		}
531 565
 	}
532 566
 	// Windows is trickier.  Let's try opening for r+...
533 567
 	else
@@ -537,30 +571,35 @@  discard block
 block discarded – undo
537 571
 		foreach ($writable_files as $file)
538 572
 		{
539 573
 			// Folders can't be opened for write... but the index.php in them can ;)
540
-			if (is_dir(dirname(__FILE__) . '/' . $file))
541
-				$file .= '/index.php';
574
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
575
+							$file .= '/index.php';
576
+			}
542 577
 
543 578
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
544 579
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
545 580
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
546 581
 
547 582
 			// Hmm, okay, try just for write in that case...
548
-			if (!is_resource($fp))
549
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
583
+			if (!is_resource($fp)) {
584
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
585
+			}
550 586
 
551
-			if (!is_resource($fp))
552
-				$failed_files[] = $file;
587
+			if (!is_resource($fp)) {
588
+							$failed_files[] = $file;
589
+			}
553 590
 
554 591
 			@fclose($fp);
555 592
 		}
556
-		foreach ($extra_files as $file)
557
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
593
+		foreach ($extra_files as $file) {
594
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
595
+		}
558 596
 	}
559 597
 
560 598
 	$failure = count($failed_files) >= 1;
561 599
 
562
-	if (!isset($_SERVER))
563
-		return !$failure;
600
+	if (!isset($_SERVER)) {
601
+			return !$failure;
602
+	}
564 603
 
565 604
 	// Put the list into context.
566 605
 	$incontext['failed_files'] = $failed_files;
@@ -608,19 +647,23 @@  discard block
 block discarded – undo
608 647
 
609 648
 		if (!isset($ftp) || $ftp->error !== false)
610 649
 		{
611
-			if (!isset($ftp))
612
-				$ftp = new ftp_connection(null);
650
+			if (!isset($ftp)) {
651
+							$ftp = new ftp_connection(null);
652
+			}
613 653
 			// Save the error so we can mess with listing...
614
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
615
-				$incontext['ftp_errors'][] = $ftp->last_message;
654
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
655
+							$incontext['ftp_errors'][] = $ftp->last_message;
656
+			}
616 657
 
617 658
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
618 659
 
619
-			if (empty($_POST['ftp_path']) && $found_path)
620
-				$_POST['ftp_path'] = $detect_path;
660
+			if (empty($_POST['ftp_path']) && $found_path) {
661
+							$_POST['ftp_path'] = $detect_path;
662
+			}
621 663
 
622
-			if (!isset($_POST['ftp_username']))
623
-				$_POST['ftp_username'] = $username;
664
+			if (!isset($_POST['ftp_username'])) {
665
+							$_POST['ftp_username'] = $username;
666
+			}
624 667
 
625 668
 			// Set the username etc, into context.
626 669
 			$incontext['ftp'] = array(
@@ -632,8 +675,7 @@  discard block
 block discarded – undo
632 675
 			);
633 676
 
634 677
 			return false;
635
-		}
636
-		else
678
+		} else
637 679
 		{
638 680
 			$_SESSION['installer_temp_ftp'] = array(
639 681
 				'server' => $_POST['ftp_server'],
@@ -647,10 +689,12 @@  discard block
 block discarded – undo
647 689
 
648 690
 			foreach ($failed_files as $file)
649 691
 			{
650
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
651
-					$ftp->chmod($file, 0755);
652
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
653
-					$ftp->chmod($file, 0777);
692
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
693
+									$ftp->chmod($file, 0755);
694
+				}
695
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
696
+									$ftp->chmod($file, 0777);
697
+				}
654 698
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
655 699
 				{
656 700
 					$failed_files_updated[] = $file;
@@ -705,15 +749,17 @@  discard block
 block discarded – undo
705 749
 
706 750
 			if (!$foundOne)
707 751
 			{
708
-				if (isset($db['default_host']))
709
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
752
+				if (isset($db['default_host'])) {
753
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
754
+				}
710 755
 				if (isset($db['default_user']))
711 756
 				{
712 757
 					$incontext['db']['user'] = ini_get($db['default_user']);
713 758
 					$incontext['db']['name'] = ini_get($db['default_user']);
714 759
 				}
715
-				if (isset($db['default_password']))
716
-					$incontext['db']['pass'] = ini_get($db['default_password']);
760
+				if (isset($db['default_password'])) {
761
+									$incontext['db']['pass'] = ini_get($db['default_password']);
762
+				}
717 763
 
718 764
 				// For simplicity and less confusion, leave the port blank by default
719 765
 				$incontext['db']['port'] = '';
@@ -732,10 +778,10 @@  discard block
 block discarded – undo
732 778
 		$incontext['db']['server'] = $_POST['db_server'];
733 779
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
734 780
 
735
-		if (!empty($_POST['db_port']))
736
-			$incontext['db']['port'] = $_POST['db_port'];
737
-	}
738
-	else
781
+		if (!empty($_POST['db_port'])) {
782
+					$incontext['db']['port'] = $_POST['db_port'];
783
+		}
784
+	} else
739 785
 	{
740 786
 		$incontext['db']['prefix'] = 'smf_';
741 787
 	}
@@ -771,10 +817,11 @@  discard block
 block discarded – undo
771 817
 		if (!empty($_POST['db_port']))
772 818
 		{
773 819
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
774
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
775
-				$vars['db_port'] = (int) $_POST['db_port'];
776
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
777
-				$vars['db_port'] = (int) $_POST['db_port'];
820
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
821
+							$vars['db_port'] = (int) $_POST['db_port'];
822
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
823
+							$vars['db_port'] = (int) $_POST['db_port'];
824
+			}
778 825
 		}
779 826
 
780 827
 		// God I hope it saved!
@@ -787,8 +834,9 @@  discard block
 block discarded – undo
787 834
 		// Make sure it works.
788 835
 		require(dirname(__FILE__) . '/Settings.php');
789 836
 
790
-		if (empty($sourcedir))
791
-			$sourcedir = dirname(__FILE__) . '/Sources';
837
+		if (empty($sourcedir)) {
838
+					$sourcedir = dirname(__FILE__) . '/Sources';
839
+		}
792 840
 
793 841
 		// Better find the database file!
794 842
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -798,18 +846,21 @@  discard block
 block discarded – undo
798 846
 		}
799 847
 
800 848
 		// Now include it for database functions!
801
-		if (!defined('SMF'))
802
-			define('SMF', 1);
849
+		if (!defined('SMF')) {
850
+					define('SMF', 1);
851
+		}
803 852
 
804 853
 		$modSettings['disableQueryCheck'] = true;
805
-		if (empty($smcFunc))
806
-			$smcFunc = array();
854
+		if (empty($smcFunc)) {
855
+					$smcFunc = array();
856
+		}
807 857
 
808 858
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
809 859
 
810 860
 		// What - running PHP4? The shame!
811
-		if (version_compare(PHP_VERSION, '5', '<'))
812
-			require_once($sourcedir . '/Subs-Compat.php');
861
+		if (version_compare(PHP_VERSION, '5', '<')) {
862
+					require_once($sourcedir . '/Subs-Compat.php');
863
+		}
813 864
 
814 865
 		// Attempt a connection.
815 866
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -897,12 +948,14 @@  discard block
 block discarded – undo
897 948
 	$incontext['page_title'] = $txt['install_settings'];
898 949
 
899 950
 	// Let's see if we got the database type correct.
900
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
901
-		$db_type = $_POST['db_type'];
951
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
952
+			$db_type = $_POST['db_type'];
953
+	}
902 954
 
903 955
 	// Else we'd better be able to get the connection.
904
-	else
905
-		load_database();
956
+	else {
957
+			load_database();
958
+	}
906 959
 
907 960
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
908 961
 
@@ -922,12 +975,14 @@  discard block
 block discarded – undo
922 975
 	// Submitting?
923 976
 	if (isset($_POST['boardurl']))
924 977
 	{
925
-		if (substr($_POST['boardurl'], -10) == '/index.php')
926
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
927
-		elseif (substr($_POST['boardurl'], -1) == '/')
928
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
929
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
930
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
978
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
979
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
980
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
981
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
982
+		}
983
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
984
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
985
+		}
931 986
 
932 987
 		// Save these variables.
933 988
 		$vars = array(
@@ -964,10 +1019,10 @@  discard block
 block discarded – undo
964 1019
 			{
965 1020
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
966 1021
 				return false;
967
-			}
968
-			else
969
-				// Set the character set here.
1022
+			} else {
1023
+							// Set the character set here.
970 1024
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1025
+			}
971 1026
 		}
972 1027
 
973 1028
 		// Good, skip on.
@@ -987,8 +1042,9 @@  discard block
 block discarded – undo
987 1042
 	$incontext['continue'] = 1;
988 1043
 
989 1044
 	// Already done?
990
-	if (isset($_POST['pop_done']))
991
-		return true;
1045
+	if (isset($_POST['pop_done'])) {
1046
+			return true;
1047
+	}
992 1048
 
993 1049
 	// Reload settings.
994 1050
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1006,8 +1062,9 @@  discard block
 block discarded – undo
1006 1062
 	$modSettings = array();
1007 1063
 	if ($result !== false)
1008 1064
 	{
1009
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1010
-			$modSettings[$row['variable']] = $row['value'];
1065
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1066
+					$modSettings[$row['variable']] = $row['value'];
1067
+		}
1011 1068
 		$smcFunc['db_free_result']($result);
1012 1069
 
1013 1070
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1020,20 +1077,22 @@  discard block
 block discarded – undo
1020 1077
 	$modSettings['disableQueryCheck'] = true;
1021 1078
 
1022 1079
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1023
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1024
-		$smcFunc['db_query']('', '
1080
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1081
+			$smcFunc['db_query']('', '
1025 1082
 			SET NAMES {string:utf8}',
1026 1083
 			array(
1027 1084
 				'db_error_skip' => true,
1028 1085
 				'utf8' => 'utf8',
1029 1086
 			)
1030 1087
 		);
1088
+	}
1031 1089
 
1032 1090
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1033
-	if (substr(__DIR__, -1) == '\\')
1034
-		$attachdir = __DIR__ . 'attachments';
1035
-	else
1036
-		$attachdir = __DIR__ . '/attachments';
1091
+	if (substr(__DIR__, -1) == '\\') {
1092
+			$attachdir = __DIR__ . 'attachments';
1093
+	} else {
1094
+			$attachdir = __DIR__ . '/attachments';
1095
+	}
1037 1096
 
1038 1097
 	$replaces = array(
1039 1098
 		'{$db_prefix}' => $db_prefix,
@@ -1050,8 +1109,9 @@  discard block
 block discarded – undo
1050 1109
 
1051 1110
 	foreach ($txt as $key => $value)
1052 1111
 	{
1053
-		if (substr($key, 0, 8) == 'default_')
1054
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1112
+		if (substr($key, 0, 8) == 'default_') {
1113
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1114
+		}
1055 1115
 	}
1056 1116
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1057 1117
 
@@ -1066,8 +1126,9 @@  discard block
 block discarded – undo
1066 1126
 
1067 1127
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1068 1128
 		{
1069
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1070
-				$engines[] = $row['Engine'];
1129
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1130
+							$engines[] = $row['Engine'];
1131
+			}
1071 1132
 		}
1072 1133
 
1073 1134
 		// Done with this now
@@ -1091,8 +1152,7 @@  discard block
 block discarded – undo
1091 1152
 			$replaces['START TRANSACTION;'] = '';
1092 1153
 			$replaces['COMMIT;'] = '';
1093 1154
 		}
1094
-	}
1095
-	else
1155
+	} else
1096 1156
 	{
1097 1157
 		$has_innodb = false;
1098 1158
 	}
@@ -1114,21 +1174,24 @@  discard block
 block discarded – undo
1114 1174
 	foreach ($sql_lines as $count => $line)
1115 1175
 	{
1116 1176
 		// No comments allowed!
1117
-		if (substr(trim($line), 0, 1) != '#')
1118
-			$current_statement .= "\n" . rtrim($line);
1177
+		if (substr(trim($line), 0, 1) != '#') {
1178
+					$current_statement .= "\n" . rtrim($line);
1179
+		}
1119 1180
 
1120 1181
 		// Is this the end of the query string?
1121
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1122
-			continue;
1182
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1183
+					continue;
1184
+		}
1123 1185
 
1124 1186
 		// Does this table already exist?  If so, don't insert more data into it!
1125 1187
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1126 1188
 		{
1127 1189
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1128
-			if (!empty($matches[0]))
1129
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1130
-			else
1131
-				$incontext['sql_results']['insert_dups']++;
1190
+			if (!empty($matches[0])) {
1191
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1192
+			} else {
1193
+							$incontext['sql_results']['insert_dups']++;
1194
+			}
1132 1195
 
1133 1196
 			$current_statement = '';
1134 1197
 			continue;
@@ -1137,8 +1200,9 @@  discard block
 block discarded – undo
1137 1200
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1138 1201
 		{
1139 1202
 			// Use the appropriate function based on the DB type
1140
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1141
-				$db_errorno = $db_type . '_errno';
1203
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1204
+							$db_errorno = $db_type . '_errno';
1205
+			}
1142 1206
 
1143 1207
 			// Error 1050: Table already exists!
1144 1208
 			// @todo Needs to be made better!
@@ -1153,18 +1217,18 @@  discard block
 block discarded – undo
1153 1217
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1154 1218
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1155 1219
 			}
1156
-		}
1157
-		else
1220
+		} else
1158 1221
 		{
1159
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1160
-				$incontext['sql_results']['tables']++;
1161
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1222
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1223
+							$incontext['sql_results']['tables']++;
1224
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1162 1225
 			{
1163 1226
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1164
-				if (!empty($matches[0]))
1165
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1166
-				else
1167
-					$incontext['sql_results']['inserts']++;
1227
+				if (!empty($matches[0])) {
1228
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1229
+				} else {
1230
+									$incontext['sql_results']['inserts']++;
1231
+				}
1168 1232
 			}
1169 1233
 		}
1170 1234
 
@@ -1177,15 +1241,17 @@  discard block
 block discarded – undo
1177 1241
 	// Sort out the context for the SQL.
1178 1242
 	foreach ($incontext['sql_results'] as $key => $number)
1179 1243
 	{
1180
-		if ($number == 0)
1181
-			unset($incontext['sql_results'][$key]);
1182
-		else
1183
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1244
+		if ($number == 0) {
1245
+					unset($incontext['sql_results'][$key]);
1246
+		} else {
1247
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1248
+		}
1184 1249
 	}
1185 1250
 
1186 1251
 	// Make sure UTF will be used globally.
1187
-	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'])))
1188
-		$newSettings[] = array('global_character_set', 'UTF-8');
1252
+	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']))) {
1253
+			$newSettings[] = array('global_character_set', 'UTF-8');
1254
+	}
1189 1255
 
1190 1256
 	// Maybe we can auto-detect better cookie settings?
1191 1257
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1196,16 +1262,20 @@  discard block
 block discarded – undo
1196 1262
 		$globalCookies = false;
1197 1263
 
1198 1264
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1199
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1200
-			$globalCookies = true;
1265
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1266
+					$globalCookies = true;
1267
+		}
1201 1268
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1202
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1203
-			$localCookies = true;
1269
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1270
+					$localCookies = true;
1271
+		}
1204 1272
 
1205
-		if ($globalCookies)
1206
-			$newSettings[] = array('globalCookies', '1');
1207
-		if ($localCookies)
1208
-			$newSettings[] = array('localCookies', '1');
1273
+		if ($globalCookies) {
1274
+					$newSettings[] = array('globalCookies', '1');
1275
+		}
1276
+		if ($localCookies) {
1277
+					$newSettings[] = array('localCookies', '1');
1278
+		}
1209 1279
 	}
1210 1280
 
1211 1281
 	// Are we allowing stat collection?
@@ -1221,32 +1291,36 @@  discard block
 block discarded – undo
1221 1291
 			fwrite($fp, $out);
1222 1292
 
1223 1293
 			$return_data = '';
1224
-			while (!feof($fp))
1225
-				$return_data .= fgets($fp, 128);
1294
+			while (!feof($fp)) {
1295
+							$return_data .= fgets($fp, 128);
1296
+			}
1226 1297
 
1227 1298
 			fclose($fp);
1228 1299
 
1229 1300
 			// Get the unique site ID.
1230 1301
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1231 1302
 
1232
-			if (!empty($ID[1]))
1233
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1303
+			if (!empty($ID[1])) {
1304
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1305
+			}
1234 1306
 		}
1235 1307
 	}
1236 1308
 
1237 1309
 	// Are we enabling SSL?
1238
-	if (!empty($_POST['force_ssl']))
1239
-		$newSettings[] = array('force_ssl', 2);
1310
+	if (!empty($_POST['force_ssl'])) {
1311
+			$newSettings[] = array('force_ssl', 2);
1312
+	}
1240 1313
 
1241 1314
 	// Setting a timezone is required.
1242 1315
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1243 1316
 	{
1244 1317
 		// Get PHP's default timezone, if set
1245 1318
 		$ini_tz = ini_get('date.timezone');
1246
-		if (!empty($ini_tz))
1247
-			$timezone_id = $ini_tz;
1248
-		else
1249
-			$timezone_id = '';
1319
+		if (!empty($ini_tz)) {
1320
+					$timezone_id = $ini_tz;
1321
+		} else {
1322
+					$timezone_id = '';
1323
+		}
1250 1324
 
1251 1325
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1252 1326
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1255,8 +1329,9 @@  discard block
 block discarded – undo
1255 1329
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1256 1330
 		}
1257 1331
 
1258
-		if (date_default_timezone_set($timezone_id))
1259
-			$newSettings[] = array('default_timezone', $timezone_id);
1332
+		if (date_default_timezone_set($timezone_id)) {
1333
+					$newSettings[] = array('default_timezone', $timezone_id);
1334
+		}
1260 1335
 	}
1261 1336
 
1262 1337
 	if (!empty($newSettings))
@@ -1287,16 +1362,18 @@  discard block
 block discarded – undo
1287 1362
 	}
1288 1363
 
1289 1364
 	// MySQL specific stuff
1290
-	if (substr($db_type, 0, 5) != 'mysql')
1291
-		return false;
1365
+	if (substr($db_type, 0, 5) != 'mysql') {
1366
+			return false;
1367
+	}
1292 1368
 
1293 1369
 	// Find database user privileges.
1294 1370
 	$privs = array();
1295 1371
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1296 1372
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1297 1373
 	{
1298
-		if ($row['Privilege'] == 'Alter')
1299
-			$privs[] = $row['Privilege'];
1374
+		if ($row['Privilege'] == 'Alter') {
1375
+					$privs[] = $row['Privilege'];
1376
+		}
1300 1377
 	}
1301 1378
 	$smcFunc['db_free_result']($get_privs);
1302 1379
 
@@ -1326,8 +1403,9 @@  discard block
 block discarded – undo
1326 1403
 	$incontext['continue'] = 1;
1327 1404
 
1328 1405
 	// Skipping?
1329
-	if (!empty($_POST['skip']))
1330
-		return true;
1406
+	if (!empty($_POST['skip'])) {
1407
+			return true;
1408
+	}
1331 1409
 
1332 1410
 	// Need this to check whether we need the database password.
1333 1411
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1340,18 +1418,22 @@  discard block
 block discarded – undo
1340 1418
 	// We need this to properly hash the password for Admin
1341 1419
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1342 1420
 			global $sourcedir;
1343
-			if (function_exists('mb_strtolower'))
1344
-				return mb_strtolower($string, 'UTF-8');
1421
+			if (function_exists('mb_strtolower')) {
1422
+							return mb_strtolower($string, 'UTF-8');
1423
+			}
1345 1424
 			require_once($sourcedir . '/Subs-Charset.php');
1346 1425
 			return utf8_strtolower($string);
1347 1426
 		};
1348 1427
 
1349
-	if (!isset($_POST['username']))
1350
-		$_POST['username'] = '';
1351
-	if (!isset($_POST['email']))
1352
-		$_POST['email'] = '';
1353
-	if (!isset($_POST['server_email']))
1354
-		$_POST['server_email'] = '';
1428
+	if (!isset($_POST['username'])) {
1429
+			$_POST['username'] = '';
1430
+	}
1431
+	if (!isset($_POST['email'])) {
1432
+			$_POST['email'] = '';
1433
+	}
1434
+	if (!isset($_POST['server_email'])) {
1435
+			$_POST['server_email'] = '';
1436
+	}
1355 1437
 
1356 1438
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1357 1439
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1370,8 +1452,9 @@  discard block
 block discarded – undo
1370 1452
 			'admin_group' => 1,
1371 1453
 		)
1372 1454
 	);
1373
-	if ($smcFunc['db_num_rows']($request) != 0)
1374
-		$incontext['skip'] = 1;
1455
+	if ($smcFunc['db_num_rows']($request) != 0) {
1456
+			$incontext['skip'] = 1;
1457
+	}
1375 1458
 	$smcFunc['db_free_result']($request);
1376 1459
 
1377 1460
 	// Trying to create an account?
@@ -1402,8 +1485,9 @@  discard block
 block discarded – undo
1402 1485
 		}
1403 1486
 
1404 1487
 		// Update the webmaster's email?
1405
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1406
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1488
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1489
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1490
+		}
1407 1491
 
1408 1492
 		// Work out whether we're going to have dodgy characters and remove them.
1409 1493
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1426,32 +1510,27 @@  discard block
 block discarded – undo
1426 1510
 			$smcFunc['db_free_result']($result);
1427 1511
 
1428 1512
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1429
-		}
1430
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1513
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1431 1514
 		{
1432 1515
 			// Try the previous step again.
1433 1516
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1434 1517
 			return false;
1435
-		}
1436
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1518
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1437 1519
 		{
1438 1520
 			// Try the previous step again.
1439 1521
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1440 1522
 			return false;
1441
-		}
1442
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1523
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1443 1524
 		{
1444 1525
 			// One step back, this time fill out a proper admin email address.
1445 1526
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1446 1527
 			return false;
1447
-		}
1448
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1528
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1449 1529
 		{
1450 1530
 			// One step back, this time fill out a proper admin email address.
1451 1531
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1452 1532
 			return false;
1453
-		}
1454
-		elseif ($_POST['username'] != '')
1533
+		} elseif ($_POST['username'] != '')
1455 1534
 		{
1456 1535
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1457 1536
 
@@ -1516,17 +1595,19 @@  discard block
 block discarded – undo
1516 1595
 	require_once($sourcedir . '/Subs-Auth.php');
1517 1596
 
1518 1597
 	// Bring a warning over.
1519
-	if (!empty($incontext['account_existed']))
1520
-		$incontext['warning'] = $incontext['account_existed'];
1598
+	if (!empty($incontext['account_existed'])) {
1599
+			$incontext['warning'] = $incontext['account_existed'];
1600
+	}
1521 1601
 
1522
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1523
-		$smcFunc['db_query']('', '
1602
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1603
+			$smcFunc['db_query']('', '
1524 1604
 			SET NAMES {string:db_character_set}',
1525 1605
 			array(
1526 1606
 				'db_character_set' => $db_character_set,
1527 1607
 				'db_error_skip' => true,
1528 1608
 			)
1529 1609
 		);
1610
+	}
1530 1611
 
1531 1612
 	// As track stats is by default enabled let's add some activity.
1532 1613
 	$smcFunc['db_insert']('ignore',
@@ -1547,14 +1628,16 @@  discard block
 block discarded – undo
1547 1628
 	// Only proceed if we can load the data.
1548 1629
 	if ($request)
1549 1630
 	{
1550
-		while ($row = $smcFunc['db_fetch_row']($request))
1551
-			$modSettings[$row[0]] = $row[1];
1631
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1632
+					$modSettings[$row[0]] = $row[1];
1633
+		}
1552 1634
 		$smcFunc['db_free_result']($request);
1553 1635
 	}
1554 1636
 
1555 1637
 	// Automatically log them in ;)
1556
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1557
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1638
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1639
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1640
+	}
1558 1641
 
1559 1642
 	$result = $smcFunc['db_query']('', '
1560 1643
 		SELECT value
@@ -1565,13 +1648,14 @@  discard block
 block discarded – undo
1565 1648
 			'db_error_skip' => true,
1566 1649
 		)
1567 1650
 	);
1568
-	if ($smcFunc['db_num_rows']($result) != 0)
1569
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1651
+	if ($smcFunc['db_num_rows']($result) != 0) {
1652
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1653
+	}
1570 1654
 	$smcFunc['db_free_result']($result);
1571 1655
 
1572
-	if (empty($db_sessions))
1573
-		$_SESSION['admin_time'] = time();
1574
-	else
1656
+	if (empty($db_sessions)) {
1657
+			$_SESSION['admin_time'] = time();
1658
+	} else
1575 1659
 	{
1576 1660
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1577 1661
 
@@ -1595,8 +1679,9 @@  discard block
 block discarded – undo
1595 1679
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1596 1680
 		function($string){
1597 1681
 			global $sourcedir;
1598
-			if (function_exists('mb_strtolower'))
1599
-				return mb_strtolower($string, 'UTF-8');
1682
+			if (function_exists('mb_strtolower')) {
1683
+							return mb_strtolower($string, 'UTF-8');
1684
+			}
1600 1685
 			require_once($sourcedir . '/Subs-Charset.php');
1601 1686
 			return utf8_strtolower($string);
1602 1687
 		};
@@ -1612,8 +1697,9 @@  discard block
 block discarded – undo
1612 1697
 		)
1613 1698
 	);
1614 1699
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1615
-	if ($smcFunc['db_num_rows']($request) > 0)
1616
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1700
+	if ($smcFunc['db_num_rows']($request) > 0) {
1701
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1702
+	}
1617 1703
 	$smcFunc['db_free_result']($request);
1618 1704
 
1619 1705
 	// Now is the perfect time to fetch the SM files.
@@ -1632,8 +1718,9 @@  discard block
 block discarded – undo
1632 1718
 
1633 1719
 	// Check if we need some stupid MySQL fix.
1634 1720
 	$server_version = $smcFunc['db_server_info']();
1635
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1636
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1721
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1722
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1723
+	}
1637 1724
 
1638 1725
 	// Some final context for the template.
1639 1726
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1653,8 +1740,9 @@  discard block
 block discarded – undo
1653 1740
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1654 1741
 
1655 1742
 	// @todo Do we just want to read the file in clean, and split it this way always?
1656
-	if (count($settingsArray) == 1)
1657
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1743
+	if (count($settingsArray) == 1) {
1744
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1745
+	}
1658 1746
 
1659 1747
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1660 1748
 	{
@@ -1669,19 +1757,22 @@  discard block
 block discarded – undo
1669 1757
 			continue;
1670 1758
 		}
1671 1759
 
1672
-		if (trim($settingsArray[$i]) == '?' . '>')
1673
-			$settingsArray[$i] = '';
1760
+		if (trim($settingsArray[$i]) == '?' . '>') {
1761
+					$settingsArray[$i] = '';
1762
+		}
1674 1763
 
1675 1764
 		// Don't trim or bother with it if it's not a variable.
1676
-		if (substr($settingsArray[$i], 0, 1) != '$')
1677
-			continue;
1765
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1766
+					continue;
1767
+		}
1678 1768
 
1679 1769
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1680 1770
 
1681
-		foreach ($vars as $var => $val)
1682
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1771
+		foreach ($vars as $var => $val) {
1772
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1683 1773
 			{
1684 1774
 				$comment = strstr($settingsArray[$i], '#');
1775
+		}
1685 1776
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1686 1777
 				unset($vars[$var]);
1687 1778
 			}
@@ -1691,36 +1782,41 @@  discard block
 block discarded – undo
1691 1782
 	if (!empty($vars))
1692 1783
 	{
1693 1784
 		$settingsArray[$i++] = '';
1694
-		foreach ($vars as $var => $val)
1695
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1785
+		foreach ($vars as $var => $val) {
1786
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1787
+		}
1696 1788
 	}
1697 1789
 
1698 1790
 	// Blank out the file - done to fix a oddity with some servers.
1699 1791
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1700
-	if (!$fp)
1701
-		return false;
1792
+	if (!$fp) {
1793
+			return false;
1794
+	}
1702 1795
 	fclose($fp);
1703 1796
 
1704 1797
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1705 1798
 
1706 1799
 	// Gotta have one of these ;)
1707
-	if (trim($settingsArray[0]) != '<?php')
1708
-		fwrite($fp, "<?php\n");
1800
+	if (trim($settingsArray[0]) != '<?php') {
1801
+			fwrite($fp, "<?php\n");
1802
+	}
1709 1803
 
1710 1804
 	$lines = count($settingsArray);
1711 1805
 	for ($i = 0; $i < $lines - 1; $i++)
1712 1806
 	{
1713 1807
 		// Don't just write a bunch of blank lines.
1714
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1715
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1808
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1809
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1810
+		}
1716 1811
 	}
1717 1812
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1718 1813
 	fclose($fp);
1719 1814
 
1720 1815
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1721 1816
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1722
-	if (function_exists('opcache_invalidate'))
1723
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1817
+	if (function_exists('opcache_invalidate')) {
1818
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1819
+	}
1724 1820
 
1725 1821
 	return true;
1726 1822
 }
@@ -1745,9 +1841,9 @@  discard block
 block discarded – undo
1745 1841
 	SecFilterScanPOST Off
1746 1842
 </IfModule>';
1747 1843
 
1748
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1749
-		return true;
1750
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1844
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1845
+			return true;
1846
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1751 1847
 	{
1752 1848
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1753 1849
 
@@ -1759,29 +1855,28 @@  discard block
 block discarded – undo
1759 1855
 				fwrite($ht_handle, $htaccess_addition);
1760 1856
 				fclose($ht_handle);
1761 1857
 				return true;
1858
+			} else {
1859
+							return false;
1762 1860
 			}
1763
-			else
1764
-				return false;
1861
+		} else {
1862
+					return true;
1765 1863
 		}
1766
-		else
1767
-			return true;
1768
-	}
1769
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1770
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1771
-	elseif (is_writable(dirname(__FILE__)))
1864
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1865
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1866
+	} elseif (is_writable(dirname(__FILE__)))
1772 1867
 	{
1773 1868
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1774 1869
 		{
1775 1870
 			fwrite($ht_handle, $htaccess_addition);
1776 1871
 			fclose($ht_handle);
1777 1872
 			return true;
1873
+		} else {
1874
+					return false;
1778 1875
 		}
1779
-		else
1876
+	} else {
1780 1877
 			return false;
1781 1878
 	}
1782
-	else
1783
-		return false;
1784
-}
1879
+	}
1785 1880
 
1786 1881
 function template_install_above()
1787 1882
 {
@@ -1819,9 +1914,10 @@  discard block
 block discarded – undo
1819 1914
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1820 1915
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1821 1916
 
1822
-		foreach ($incontext['detected_languages'] as $lang => $name)
1823
-			echo '
1917
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1918
+					echo '
1824 1919
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1920
+		}
1825 1921
 
1826 1922
 		echo '
1827 1923
 								</select>
@@ -1841,9 +1937,10 @@  discard block
 block discarded – undo
1841 1937
 						<h2>', $txt['upgrade_progress'], '</h2>
1842 1938
 						<ul>';
1843 1939
 
1844
-	foreach ($incontext['steps'] as $num => $step)
1845
-		echo '
1940
+	foreach ($incontext['steps'] as $num => $step) {
1941
+			echo '
1846 1942
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1943
+	}
1847 1944
 
1848 1945
 	echo '
1849 1946
 						</ul>
@@ -1868,20 +1965,23 @@  discard block
 block discarded – undo
1868 1965
 		echo '
1869 1966
 								<div>';
1870 1967
 
1871
-		if (!empty($incontext['continue']))
1872
-			echo '
1968
+		if (!empty($incontext['continue'])) {
1969
+					echo '
1873 1970
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1874
-		if (!empty($incontext['skip']))
1875
-			echo '
1971
+		}
1972
+		if (!empty($incontext['skip'])) {
1973
+					echo '
1876 1974
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1975
+		}
1877 1976
 		echo '
1878 1977
 								</div>';
1879 1978
 	}
1880 1979
 
1881 1980
 	// Show the closing form tag and other data only if not in the last step
1882
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1883
-		echo '
1981
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
1982
+			echo '
1884 1983
 							</form>';
1984
+	}
1885 1985
 
1886 1986
 	echo '
1887 1987
 						</div>
@@ -1916,13 +2016,15 @@  discard block
 block discarded – undo
1916 2016
 		</div>';
1917 2017
 
1918 2018
 	// Show the warnings, or not.
1919
-	if (template_warning_divs())
1920
-		echo '
2019
+	if (template_warning_divs()) {
2020
+			echo '
1921 2021
 		<h3>', $txt['install_all_lovely'], '</h3>';
2022
+	}
1922 2023
 
1923 2024
 	// Say we want the continue button!
1924
-	if (empty($incontext['error']))
1925
-		$incontext['continue'] = 1;
2025
+	if (empty($incontext['error'])) {
2026
+			$incontext['continue'] = 1;
2027
+	}
1926 2028
 
1927 2029
 	// For the latest version stuff.
1928 2030
 	echo '
@@ -1956,8 +2058,8 @@  discard block
 block discarded – undo
1956 2058
 	global $txt, $incontext;
1957 2059
 
1958 2060
 	// Errors are very serious..
1959
-	if (!empty($incontext['error']))
1960
-		echo '
2061
+	if (!empty($incontext['error'])) {
2062
+			echo '
1961 2063
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1962 2064
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1963 2065
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1965,9 +2067,10 @@  discard block
 block discarded – undo
1965 2067
 				', $incontext['error'], '
1966 2068
 			</div>
1967 2069
 		</div>';
2070
+	}
1968 2071
 	// A warning message?
1969
-	elseif (!empty($incontext['warning']))
1970
-		echo '
2072
+	elseif (!empty($incontext['warning'])) {
2073
+			echo '
1971 2074
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1972 2075
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1973 2076
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -1975,6 +2078,7 @@  discard block
 block discarded – undo
1975 2078
 				', $incontext['warning'], '
1976 2079
 			</div>
1977 2080
 		</div>';
2081
+	}
1978 2082
 
1979 2083
 	return empty($incontext['error']) && empty($incontext['warning']);
1980 2084
 }
@@ -1990,27 +2094,30 @@  discard block
 block discarded – undo
1990 2094
 			<li>', $incontext['failed_files']), '</li>
1991 2095
 		</ul>';
1992 2096
 
1993
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
1994
-		echo '
2097
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2098
+			echo '
1995 2099
 		<hr>
1996 2100
 		<p>', $txt['chmod_linux_info'], '</p>
1997 2101
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2102
+	}
1998 2103
 
1999 2104
 	// This is serious!
2000
-	if (!template_warning_divs())
2001
-		return;
2105
+	if (!template_warning_divs()) {
2106
+			return;
2107
+	}
2002 2108
 
2003 2109
 	echo '
2004 2110
 		<hr>
2005 2111
 		<p>', $txt['ftp_setup_info'], '</p>';
2006 2112
 
2007
-	if (!empty($incontext['ftp_errors']))
2008
-		echo '
2113
+	if (!empty($incontext['ftp_errors'])) {
2114
+			echo '
2009 2115
 		<div class="error_message">
2010 2116
 			', $txt['error_ftp_no_connect'], '<br><br>
2011 2117
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2012 2118
 		</div>
2013 2119
 		<br>';
2120
+	}
2014 2121
 
2015 2122
 	echo '
2016 2123
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2070,17 +2177,17 @@  discard block
 block discarded – undo
2070 2177
 				<td>
2071 2178
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2072 2179
 
2073
-	foreach ($incontext['supported_databases'] as $key => $db)
2074
-			echo '
2180
+	foreach ($incontext['supported_databases'] as $key => $db) {
2181
+				echo '
2075 2182
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2183
+	}
2076 2184
 
2077 2185
 	echo '
2078 2186
 					</select>
2079 2187
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2080 2188
 				</td>
2081 2189
 			</tr>';
2082
-	}
2083
-	else
2190
+	} else
2084 2191
 	{
2085 2192
 		echo '
2086 2193
 			<tr style="display: none;">
@@ -2272,9 +2379,10 @@  discard block
 block discarded – undo
2272 2379
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2273 2380
 				<ul>';
2274 2381
 
2275
-		foreach ($incontext['failures'] as $line => $fail)
2276
-			echo '
2382
+		foreach ($incontext['failures'] as $line => $fail) {
2383
+					echo '
2277 2384
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2385
+		}
2278 2386
 
2279 2387
 		echo '
2280 2388
 				</ul>';
@@ -2335,15 +2443,16 @@  discard block
 block discarded – undo
2335 2443
 			</tr>
2336 2444
 		</table>';
2337 2445
 
2338
-	if ($incontext['require_db_confirm'])
2339
-		echo '
2446
+	if ($incontext['require_db_confirm']) {
2447
+			echo '
2340 2448
 		<h2>', $txt['user_settings_database'], '</h2>
2341 2449
 		<p>', $txt['user_settings_database_info'], '</p>
2342 2450
 
2343 2451
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2344 2452
 			<input type="password" name="password3" size="30" class="input_password" />
2345 2453
 		</div>';
2346
-}
2454
+	}
2455
+	}
2347 2456
 
2348 2457
 // Tell them it's done, and to delete.
2349 2458
 function template_delete_install()
@@ -2356,14 +2465,15 @@  discard block
 block discarded – undo
2356 2465
 	template_warning_divs();
2357 2466
 
2358 2467
 	// Install directory still writable?
2359
-	if ($incontext['dir_still_writable'])
2360
-		echo '
2468
+	if ($incontext['dir_still_writable']) {
2469
+			echo '
2361 2470
 		<em>', $txt['still_writable'], '</em><br>
2362 2471
 		<br>';
2472
+	}
2363 2473
 
2364 2474
 	// Don't show the box if it's like 99% sure it won't work :P.
2365
-	if ($incontext['probably_delete_install'])
2366
-		echo '
2475
+	if ($incontext['probably_delete_install']) {
2476
+			echo '
2367 2477
 		<div style="margin: 1ex; font-weight: bold;">
2368 2478
 			<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>
2369 2479
 		</div>
@@ -2379,6 +2489,7 @@  discard block
 block discarded – undo
2379 2489
 			}
2380 2490
 		</script>
2381 2491
 		<br>';
2492
+	}
2382 2493
 
2383 2494
 	echo '
2384 2495
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.