Completed
Branch release-2.1 (e49a83)
by Michael
08:59
created
Sources/ManageSettings.php 1 patch
Braces   +273 added lines, -199 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 makes sure the requested subaction does exists, if it doesn't, it sets a default action or.
@@ -205,16 +206,18 @@  discard block
 block discarded – undo
205 206
 	{
206 207
 		$all_zones = timezone_identifiers_list();
207 208
 		// Make sure we set the value to the same as the printed value.
208
-		foreach ($all_zones as $zone)
209
-			$config_vars['default_timezone'][2][$zone] = $zone;
209
+		foreach ($all_zones as $zone) {
210
+					$config_vars['default_timezone'][2][$zone] = $zone;
211
+		}
212
+	} else {
213
+			unset($config_vars['default_timezone']);
210 214
 	}
211
-	else
212
-		unset($config_vars['default_timezone']);
213 215
 
214 216
 	call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
215 217
 
216
-	if ($return_config)
217
-		return $config_vars;
218
+	if ($return_config) {
219
+			return $config_vars;
220
+	}
218 221
 
219 222
 	// Saving?
220 223
 	if (isset($_GET['save']))
@@ -222,8 +225,9 @@  discard block
 block discarded – undo
222 225
 		checkSession();
223 226
 
224 227
 		// Prevent absurd boundaries here - make it a day tops.
225
-		if (isset($_POST['lastActive']))
226
-			$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
228
+		if (isset($_POST['lastActive'])) {
229
+					$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
230
+		}
227 231
 
228 232
 		call_integration_hook('integrate_save_basic_settings');
229 233
 
@@ -268,8 +272,9 @@  discard block
 block discarded – undo
268 272
 
269 273
 	call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars));
270 274
 
271
-	if ($return_config)
272
-		return $config_vars;
275
+	if ($return_config) {
276
+			return $config_vars;
277
+	}
273 278
 
274 279
 	// Setup the template.
275 280
 	require_once($sourcedir . '/ManageServer.php');
@@ -286,13 +291,15 @@  discard block
 block discarded – undo
286 291
 
287 292
 		// Clean up the tags.
288 293
 		$bbcTags = array();
289
-		foreach (parse_bbc(false) as $tag)
290
-			$bbcTags[] = $tag['tag'];
294
+		foreach (parse_bbc(false) as $tag) {
295
+					$bbcTags[] = $tag['tag'];
296
+		}
291 297
 
292
-		if (!isset($_POST['disabledBBC_enabledTags']))
293
-			$_POST['disabledBBC_enabledTags'] = array();
294
-		elseif (!is_array($_POST['disabledBBC_enabledTags']))
295
-			$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
298
+		if (!isset($_POST['disabledBBC_enabledTags'])) {
299
+					$_POST['disabledBBC_enabledTags'] = array();
300
+		} elseif (!is_array($_POST['disabledBBC_enabledTags'])) {
301
+					$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
302
+		}
296 303
 		// Work out what is actually disabled!
297 304
 		$_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
298 305
 
@@ -336,8 +343,9 @@  discard block
 block discarded – undo
336 343
 
337 344
 	call_integration_hook('integrate_layout_settings', array(&$config_vars));
338 345
 
339
-	if ($return_config)
340
-		return $config_vars;
346
+	if ($return_config) {
347
+			return $config_vars;
348
+	}
341 349
 
342 350
 	// Saving?
343 351
 	if (isset($_GET['save']))
@@ -378,8 +386,9 @@  discard block
 block discarded – undo
378 386
 
379 387
 	call_integration_hook('integrate_likes_settings', array(&$config_vars));
380 388
 
381
-	if ($return_config)
382
-		return $config_vars;
389
+	if ($return_config) {
390
+			return $config_vars;
391
+	}
383 392
 
384 393
 	// Saving?
385 394
 	if (isset($_GET['save']))
@@ -417,8 +426,9 @@  discard block
 block discarded – undo
417 426
 
418 427
 	call_integration_hook('integrate_mentions_settings', array(&$config_vars));
419 428
 
420
-	if ($return_config)
421
-		return $config_vars;
429
+	if ($return_config) {
430
+			return $config_vars;
431
+	}
422 432
 
423 433
 	// Saving?
424 434
 	if (isset($_GET['save']))
@@ -462,8 +472,8 @@  discard block
 block discarded – undo
462 472
 			'enable' => array('check', 'warning_enable'),
463 473
 	);
464 474
 
465
-	if (!empty($modSettings['warning_settings']) && $currently_enabled)
466
-		$config_vars += array(
475
+	if (!empty($modSettings['warning_settings']) && $currently_enabled) {
476
+			$config_vars += array(
467 477
 			'',
468 478
 				array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']),
469 479
 				'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']),
@@ -472,15 +482,18 @@  discard block
 block discarded – undo
472 482
 				'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']),
473 483
 				array('permissions', 'view_warning'),
474 484
 		);
485
+	}
475 486
 
476 487
 	call_integration_hook('integrate_warning_settings', array(&$config_vars));
477 488
 
478
-	if ($return_config)
479
-		return $config_vars;
489
+	if ($return_config) {
490
+			return $config_vars;
491
+	}
480 492
 
481 493
 	// Cannot use moderation if post moderation is not enabled.
482
-	if (!$modSettings['postmod_active'])
483
-		unset($config_vars['moderate']);
494
+	if (!$modSettings['postmod_active']) {
495
+			unset($config_vars['moderate']);
496
+	}
484 497
 
485 498
 	// Will need the utility functions from here.
486 499
 	require_once($sourcedir . '/ManageServer.php');
@@ -505,16 +518,16 @@  discard block
 block discarded – undo
505 518
 				'warning_watch' => 10,
506 519
 				'warning_mute' => 60,
507 520
 			);
508
-			if ($modSettings['postmod_active'])
509
-				$vars['warning_moderate'] = 35;
521
+			if ($modSettings['postmod_active']) {
522
+							$vars['warning_moderate'] = 35;
523
+			}
510 524
 
511 525
 			foreach ($vars as $var => $value)
512 526
 			{
513 527
 				$config_vars[] = array('int', $var);
514 528
 				$_POST[$var] = $value;
515 529
 			}
516
-		}
517
-		else
530
+		} else
518 531
 		{
519 532
 			$_POST['warning_watch'] = min($_POST['warning_watch'], 100);
520 533
 			$_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
@@ -595,8 +608,9 @@  discard block
 block discarded – undo
595 608
 
596 609
 	call_integration_hook('integrate_spam_settings', array(&$config_vars));
597 610
 
598
-	if ($return_config)
599
-		return $config_vars;
611
+	if ($return_config) {
612
+			return $config_vars;
613
+	}
600 614
 
601 615
 	// You need to be an admin to edit settings!
602 616
 	isAllowedTo('admin_forum');
@@ -630,8 +644,9 @@  discard block
 block discarded – undo
630 644
 
631 645
 	if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers']))
632 646
 	{
633
-		if (empty($context['settings_insert_above']))
634
-			$context['settings_insert_above'] = '';
647
+		if (empty($context['settings_insert_above'])) {
648
+					$context['settings_insert_above'] = '';
649
+		}
635 650
 
636 651
 		$context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>';
637 652
 	}
@@ -674,8 +689,9 @@  discard block
 block discarded – undo
674 689
 		$_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
675 690
 
676 691
 		// Hack in guest requiring verification!
677
-		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
678
-			$_POST['posts_require_captcha'] = -1;
692
+		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) {
693
+					$_POST['posts_require_captcha'] = -1;
694
+		}
679 695
 
680 696
 		$save_vars = $config_vars;
681 697
 		unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
@@ -692,14 +708,16 @@  discard block
 block discarded – undo
692 708
 		foreach ($context['qa_languages'] as $lang_id => $dummy)
693 709
 		{
694 710
 			// If we had some questions for this language before, but don't now, delete everything from that language.
695
-			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
696
-				$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
711
+			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) {
712
+							$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
713
+			}
697 714
 
698 715
 			// Now step through and see if any existing questions no longer exist.
699
-			if (!empty($context['qa_by_lang'][$lang_id]))
700
-				foreach ($context['qa_by_lang'][$lang_id] as $q_id)
716
+			if (!empty($context['qa_by_lang'][$lang_id])) {
717
+							foreach ($context['qa_by_lang'][$lang_id] as $q_id)
701 718
 					if (empty($_POST['question'][$lang_id][$q_id]))
702 719
 						$changes['delete'][] = $q_id;
720
+			}
703 721
 
704 722
 			// Now let's see if there are new questions or ones that need updating.
705 723
 			if (isset($_POST['question'][$lang_id]))
@@ -708,14 +726,16 @@  discard block
 block discarded – undo
708 726
 				{
709 727
 					// Ignore junky ids.
710 728
 					$q_id = (int) $q_id;
711
-					if ($q_id <= 0)
712
-						continue;
729
+					if ($q_id <= 0) {
730
+											continue;
731
+					}
713 732
 
714 733
 					// Check the question isn't empty (because they want to delete it?)
715 734
 					if (empty($question) || trim($question) == '')
716 735
 					{
717
-						if (isset($context['question_answers'][$q_id]))
718
-							$changes['delete'][] = $q_id;
736
+						if (isset($context['question_answers'][$q_id])) {
737
+													$changes['delete'][] = $q_id;
738
+						}
719 739
 						continue;
720 740
 					}
721 741
 					$question = $smcFunc['htmlspecialchars'](trim($question));
@@ -723,19 +743,22 @@  discard block
 block discarded – undo
723 743
 					// Get the answers. Firstly check there actually might be some.
724 744
 					if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
725 745
 					{
726
-						if (isset($context['question_answers'][$q_id]))
727
-							$changes['delete'][] = $q_id;
746
+						if (isset($context['question_answers'][$q_id])) {
747
+													$changes['delete'][] = $q_id;
748
+						}
728 749
 						continue;
729 750
 					}
730 751
 					// Now get them and check that they might be viable.
731 752
 					$answers = array();
732
-					foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
733
-						if (!empty($answer) && trim($answer) !== '')
753
+					foreach ($_POST['answer'][$lang_id][$q_id] as $answer) {
754
+											if (!empty($answer) && trim($answer) !== '')
734 755
 							$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
756
+					}
735 757
 					if (empty($answers))
736 758
 					{
737
-						if (isset($context['question_answers'][$q_id]))
738
-							$changes['delete'][] = $q_id;
759
+						if (isset($context['question_answers'][$q_id])) {
760
+													$changes['delete'][] = $q_id;
761
+						}
739 762
 						continue;
740 763
 					}
741 764
 					$answers = json_encode($answers);
@@ -745,16 +768,17 @@  discard block
 block discarded – undo
745 768
 					{
746 769
 						// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
747 770
 						$changes['insert'][] = array($lang_id, $question, $answers);
748
-					}
749
-					else
771
+					} else
750 772
 					{
751 773
 						// It's an existing question. Let's see what's changed, if anything.
752
-						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
753
-							$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
774
+						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) {
775
+													$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
776
+						}
754 777
 					}
755 778
 
756
-					if (!isset($qs_per_lang[$lang_id]))
757
-						$qs_per_lang[$lang_id] = 0;
779
+					if (!isset($qs_per_lang[$lang_id])) {
780
+											$qs_per_lang[$lang_id] = 0;
781
+					}
758 782
 					$qs_per_lang[$lang_id]++;
759 783
 				}
760 784
 			}
@@ -804,8 +828,9 @@  discard block
 block discarded – undo
804 828
 
805 829
 		// Lastly, the count of messages needs to be no more than the lowest number of questions for any one language.
806 830
 		$count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
807
-		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
808
-			$_POST['qa_verification_number'] = $count_questions;
831
+		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) {
832
+					$_POST['qa_verification_number'] = $count_questions;
833
+		}
809 834
 
810 835
 		call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
811 836
 
@@ -820,24 +845,27 @@  discard block
 block discarded – undo
820 845
 
821 846
 	$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
822 847
 	$_SESSION['visual_verification_code'] = '';
823
-	for ($i = 0; $i < 6; $i++)
824
-		$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
848
+	for ($i = 0; $i < 6; $i++) {
849
+			$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
850
+	}
825 851
 
826 852
 	// Some javascript for CAPTCHA.
827 853
 	$context['settings_post_javascript'] = '';
828
-	if ($context['use_graphic_library'])
829
-		$context['settings_post_javascript'] .= '
854
+	if ($context['use_graphic_library']) {
855
+			$context['settings_post_javascript'] .= '
830 856
 		function refreshImages()
831 857
 		{
832 858
 			var imageType = document.getElementById(\'visual_verification_type\').value;
833 859
 			document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
834 860
 		}';
861
+	}
835 862
 
836 863
 	// Show the image itself, or text saying we can't.
837
-	if ($context['use_graphic_library'])
838
-		$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
839
-	else
840
-		$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
864
+	if ($context['use_graphic_library']) {
865
+			$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
866
+	} else {
867
+			$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
868
+	}
841 869
 
842 870
 	// Hack for PM spam settings.
843 871
 	list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
@@ -847,9 +875,10 @@  discard block
 block discarded – undo
847 875
 	$modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
848 876
 
849 877
 	// Some minor javascript for the guest post setting.
850
-	if ($modSettings['posts_require_captcha'])
851
-		$context['settings_post_javascript'] .= '
878
+	if ($modSettings['posts_require_captcha']) {
879
+			$context['settings_post_javascript'] .= '
852 880
 		document.getElementById(\'guests_require_captcha\').disabled = true;';
881
+	}
853 882
 
854 883
 	// And everything else.
855 884
 	$context['post_url'] = $scripturl . '?action=admin;area=antispam;save';
@@ -896,8 +925,9 @@  discard block
 block discarded – undo
896 925
 
897 926
 	call_integration_hook('integrate_signature_settings', array(&$config_vars));
898 927
 
899
-	if ($return_config)
900
-		return $config_vars;
928
+	if ($return_config) {
929
+			return $config_vars;
930
+	}
901 931
 
902 932
 	// Setup the template.
903 933
 	$context['page_title'] = $txt['signature_settings'];
@@ -952,8 +982,9 @@  discard block
 block discarded – undo
952 982
 				$sig = strtr($row['signature'], array('<br>' => "\n"));
953 983
 
954 984
 				// Max characters...
955
-				if (!empty($sig_limits[1]))
956
-					$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
985
+				if (!empty($sig_limits[1])) {
986
+									$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
987
+				}
957 988
 				// Max lines...
958 989
 				if (!empty($sig_limits[2]))
959 990
 				{
@@ -963,8 +994,9 @@  discard block
 block discarded – undo
963 994
 						if ($sig[$i] == "\n")
964 995
 						{
965 996
 							$count++;
966
-							if ($count >= $sig_limits[2])
967
-								$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
997
+							if ($count >= $sig_limits[2]) {
998
+															$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
999
+							}
968 1000
 						}
969 1001
 					}
970 1002
 				}
@@ -975,17 +1007,19 @@  discard block
 block discarded – undo
975 1007
 					{
976 1008
 						$limit_broke = 0;
977 1009
 						// Attempt to allow all sizes of abuse, so to speak.
978
-						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
979
-							$limit_broke = $sig_limits[7] . 'px';
980
-						elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
981
-							$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
982
-						elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
983
-							$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
984
-						elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
985
-							$limit_broke = 'large';
986
-
987
-						if ($limit_broke)
988
-							$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1010
+						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
1011
+													$limit_broke = $sig_limits[7] . 'px';
1012
+						} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
1013
+													$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
1014
+						} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
1015
+													$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
1016
+						} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
1017
+													$limit_broke = 'large';
1018
+						}
1019
+
1020
+						if ($limit_broke) {
1021
+													$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1022
+						}
989 1023
 					}
990 1024
 				}
991 1025
 
@@ -1041,32 +1075,34 @@  discard block
 block discarded – undo
1041 1075
 											$img_offset = false;
1042 1076
 										}
1043 1077
 									}
1078
+								} else {
1079
+																	$replaces[$image] = '';
1044 1080
 								}
1045
-								else
1046
-									$replaces[$image] = '';
1047 1081
 
1048 1082
 								continue;
1049 1083
 							}
1050 1084
 
1051 1085
 							// Does it have predefined restraints? Width first.
1052
-							if ($matches[6][$key])
1053
-								$matches[2][$key] = $matches[6][$key];
1086
+							if ($matches[6][$key]) {
1087
+															$matches[2][$key] = $matches[6][$key];
1088
+							}
1054 1089
 							if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
1055 1090
 							{
1056 1091
 								$width = $sig_limits[5];
1057 1092
 								$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
1093
+							} elseif ($matches[2][$key]) {
1094
+															$width = $matches[2][$key];
1058 1095
 							}
1059
-							elseif ($matches[2][$key])
1060
-								$width = $matches[2][$key];
1061 1096
 							// ... and height.
1062 1097
 							if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
1063 1098
 							{
1064 1099
 								$height = $sig_limits[6];
1065
-								if ($width != -1)
1066
-									$width = $width * ($height / $matches[4][$key]);
1100
+								if ($width != -1) {
1101
+																	$width = $width * ($height / $matches[4][$key]);
1102
+								}
1103
+							} elseif ($matches[4][$key]) {
1104
+															$height = $matches[4][$key];
1067 1105
 							}
1068
-							elseif ($matches[4][$key])
1069
-								$height = $matches[4][$key];
1070 1106
 
1071 1107
 							// If the dimensions are still not fixed - we need to check the actual image.
1072 1108
 							if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -1084,12 +1120,13 @@  discard block
 block discarded – undo
1084 1120
 									if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
1085 1121
 									{
1086 1122
 										$height = $sig_limits[6];
1087
-										if ($width == -1)
1088
-											$width = $sizes[0];
1123
+										if ($width == -1) {
1124
+																					$width = $sizes[0];
1125
+										}
1089 1126
 										$width = $width * ($height / $sizes[1]);
1127
+									} elseif ($width != -1) {
1128
+																			$height = $sizes[1];
1090 1129
 									}
1091
-									elseif ($width != -1)
1092
-										$height = $sizes[1];
1093 1130
 								}
1094 1131
 							}
1095 1132
 
@@ -1102,8 +1139,9 @@  discard block
 block discarded – undo
1102 1139
 							// Record that we got one.
1103 1140
 							$image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
1104 1141
 						}
1105
-						if (!empty($replaces))
1106
-							$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1142
+						if (!empty($replaces)) {
1143
+													$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1144
+						}
1107 1145
 					}
1108 1146
 				}
1109 1147
 				// Try to fix disabled tags.
@@ -1115,18 +1153,20 @@  discard block
 block discarded – undo
1115 1153
 
1116 1154
 				$sig = strtr($sig, array("\n" => '<br>'));
1117 1155
 				call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
1118
-				if ($sig != $row['signature'])
1119
-					$changes[$row['id_member']] = $sig;
1156
+				if ($sig != $row['signature']) {
1157
+									$changes[$row['id_member']] = $sig;
1158
+				}
1159
+			}
1160
+			if ($smcFunc['db_num_rows']($request) == 0) {
1161
+							$done = true;
1120 1162
 			}
1121
-			if ($smcFunc['db_num_rows']($request) == 0)
1122
-				$done = true;
1123 1163
 			$smcFunc['db_free_result']($request);
1124 1164
 
1125 1165
 			// Do we need to delete what we have?
1126 1166
 			if (!empty($changes))
1127 1167
 			{
1128
-				foreach ($changes as $id => $sig)
1129
-					$smcFunc['db_query']('', '
1168
+				foreach ($changes as $id => $sig) {
1169
+									$smcFunc['db_query']('', '
1130 1170
 						UPDATE {db_prefix}members
1131 1171
 						SET signature = {string:signature}
1132 1172
 						WHERE id_member = {int:id_member}',
@@ -1135,11 +1175,13 @@  discard block
 block discarded – undo
1135 1175
 							'signature' => $sig,
1136 1176
 						)
1137 1177
 					);
1178
+				}
1138 1179
 			}
1139 1180
 
1140 1181
 			$_GET['step'] += 50;
1141
-			if (!$done)
1142
-				pauseSignatureApplySettings();
1182
+			if (!$done) {
1183
+							pauseSignatureApplySettings();
1184
+			}
1143 1185
 		}
1144 1186
 		$settings_applied = true;
1145 1187
 	}
@@ -1157,8 +1199,9 @@  discard block
 block discarded – undo
1157 1199
 	);
1158 1200
 
1159 1201
 	// Temporarily make each setting a modSetting!
1160
-	foreach ($context['signature_settings'] as $key => $value)
1161
-		$modSettings['signature_' . $key] = $value;
1202
+	foreach ($context['signature_settings'] as $key => $value) {
1203
+			$modSettings['signature_' . $key] = $value;
1204
+	}
1162 1205
 
1163 1206
 	// Make sure we check the right tags!
1164 1207
 	$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
@@ -1170,23 +1213,26 @@  discard block
 block discarded – undo
1170 1213
 
1171 1214
 		// Clean up the tag stuff!
1172 1215
 		$bbcTags = array();
1173
-		foreach (parse_bbc(false) as $tag)
1174
-			$bbcTags[] = $tag['tag'];
1216
+		foreach (parse_bbc(false) as $tag) {
1217
+					$bbcTags[] = $tag['tag'];
1218
+		}
1175 1219
 
1176
-		if (!isset($_POST['signature_bbc_enabledTags']))
1177
-			$_POST['signature_bbc_enabledTags'] = array();
1178
-		elseif (!is_array($_POST['signature_bbc_enabledTags']))
1179
-			$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1220
+		if (!isset($_POST['signature_bbc_enabledTags'])) {
1221
+					$_POST['signature_bbc_enabledTags'] = array();
1222
+		} elseif (!is_array($_POST['signature_bbc_enabledTags'])) {
1223
+					$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1224
+		}
1180 1225
 
1181 1226
 		$sig_limits = array();
1182 1227
 		foreach ($context['signature_settings'] as $key => $value)
1183 1228
 		{
1184
-			if ($key == 'allow_smileys')
1185
-				continue;
1186
-			elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
1187
-				$sig_limits[] = -1;
1188
-			else
1189
-				$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1229
+			if ($key == 'allow_smileys') {
1230
+							continue;
1231
+			} elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) {
1232
+							$sig_limits[] = -1;
1233
+			} else {
1234
+							$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1235
+			}
1190 1236
 		}
1191 1237
 
1192 1238
 		call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
@@ -1219,12 +1265,14 @@  discard block
 block discarded – undo
1219 1265
 
1220 1266
 	// Try get more time...
1221 1267
 	@set_time_limit(600);
1222
-	if (function_exists('apache_reset_timeout'))
1223
-		@apache_reset_timeout();
1268
+	if (function_exists('apache_reset_timeout')) {
1269
+			@apache_reset_timeout();
1270
+	}
1224 1271
 
1225 1272
 	// Have we exhausted all the time we allowed?
1226
-	if (time() - array_sum(explode(' ', $sig_start)) < 3)
1227
-		return;
1273
+	if (time() - array_sum(explode(' ', $sig_start)) < 3) {
1274
+			return;
1275
+	}
1228 1276
 
1229 1277
 	$context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1230 1278
 	$context['page_title'] = $txt['not_done_title'];
@@ -1270,9 +1318,10 @@  discard block
 block discarded – undo
1270 1318
 		$disable_fields = array_flip($standard_fields);
1271 1319
 		if (!empty($_POST['active']))
1272 1320
 		{
1273
-			foreach ($_POST['active'] as $value)
1274
-				if (isset($disable_fields[$value]))
1321
+			foreach ($_POST['active'] as $value) {
1322
+							if (isset($disable_fields[$value]))
1275 1323
 					unset($disable_fields[$value]);
1324
+			}
1276 1325
 		}
1277 1326
 		// What we have left!
1278 1327
 		$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
@@ -1281,16 +1330,18 @@  discard block
 block discarded – undo
1281 1330
 		$reg_fields = array();
1282 1331
 		if (!empty($_POST['reg']))
1283 1332
 		{
1284
-			foreach ($_POST['reg'] as $value)
1285
-				if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1333
+			foreach ($_POST['reg'] as $value) {
1334
+							if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1286 1335
 					$reg_fields[] = $value;
1336
+			}
1287 1337
 		}
1288 1338
 		// What we have left!
1289 1339
 		$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
1290 1340
 
1291 1341
 		$_SESSION['adm-save'] = true;
1292
-		if (!empty($changes))
1293
-			updateSettings($changes);
1342
+		if (!empty($changes)) {
1343
+					updateSettings($changes);
1344
+		}
1294 1345
 	}
1295 1346
 
1296 1347
 	createToken('admin-scp');
@@ -1393,11 +1444,13 @@  discard block
 block discarded – undo
1393 1444
 					{
1394 1445
 						$return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br />';
1395 1446
 
1396
-						if ($rowData['field_order'] > 1)
1397
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1447
+						if ($rowData['field_order'] > 1) {
1448
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1449
+						}
1398 1450
 
1399
-						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1400
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1451
+						if ($rowData['field_order'] < $context['custFieldsMaxOrder']) {
1452
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1453
+						}
1401 1454
 
1402 1455
 						$return .= '</p>';
1403 1456
 
@@ -1535,16 +1588,16 @@  discard block
 block discarded – undo
1535 1588
 		$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
1536 1589
 		$registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
1537 1590
 
1538
-		foreach ($standard_fields as $field)
1539
-			$list[] = array(
1591
+		foreach ($standard_fields as $field) {
1592
+					$list[] = array(
1540 1593
 				'id' => $field,
1541 1594
 				'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
1542 1595
 				'disabled' => in_array($field, $disabled_fields),
1543 1596
 				'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
1544 1597
 				'can_show_register' => !in_array($field, $fields_no_registration),
1545 1598
 			);
1546
-	}
1547
-	else
1599
+		}
1600
+	} else
1548 1601
 	{
1549 1602
 		// Load all the fields.
1550 1603
 		$request = $smcFunc['db_query']('', '
@@ -1558,8 +1611,9 @@  discard block
 block discarded – undo
1558 1611
 				'items_per_page' => $items_per_page,
1559 1612
 			)
1560 1613
 		);
1561
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1562
-			$list[] = $row;
1614
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1615
+					$list[] = $row;
1616
+		}
1563 1617
 		$smcFunc['db_free_result']($request);
1564 1618
 	}
1565 1619
 
@@ -1625,9 +1679,9 @@  discard block
 block discarded – undo
1625 1679
 		$context['field'] = array();
1626 1680
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1627 1681
 		{
1628
-			if ($row['field_type'] == 'textarea')
1629
-				@list ($rows, $cols) = @explode(',', $row['default_value']);
1630
-			else
1682
+			if ($row['field_type'] == 'textarea') {
1683
+							@list ($rows, $cols) = @explode(',', $row['default_value']);
1684
+			} else
1631 1685
 			{
1632 1686
 				$rows = 3;
1633 1687
 				$cols = 30;
@@ -1663,8 +1717,8 @@  discard block
 block discarded – undo
1663 1717
 	}
1664 1718
 
1665 1719
 	// Setup the default values as needed.
1666
-	if (empty($context['field']))
1667
-		$context['field'] = array(
1720
+	if (empty($context['field'])) {
1721
+			$context['field'] = array(
1668 1722
 			'name' => '',
1669 1723
 			'col_name' => '???',
1670 1724
 			'desc' => '',
@@ -1689,6 +1743,7 @@  discard block
 block discarded – undo
1689 1743
 			'enclose' => '',
1690 1744
 			'placement' => 0,
1691 1745
 		);
1746
+	}
1692 1747
 
1693 1748
 	// Are we moving it?
1694 1749
 	if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to))
@@ -1697,8 +1752,10 @@  discard block
 block discarded – undo
1697 1752
 		$new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1));
1698 1753
 
1699 1754
 		// Is this a valid position?
1700
-		if ($new_order <= 0 || $new_order > $order_count)
1701
-			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1755
+		if ($new_order <= 0 || $new_order > $order_count) {
1756
+					redirectexit('action=admin;area=featuresettings;sa=profile');
1757
+		}
1758
+		// @todo implement an error handler
1702 1759
 
1703 1760
 		// All good, proceed.
1704 1761
 		$smcFunc['db_query']('','
@@ -1729,12 +1786,14 @@  discard block
 block discarded – undo
1729 1786
 		validateToken('admin-ecp');
1730 1787
 
1731 1788
 		// Everyone needs a name - even the (bracket) unknown...
1732
-		if (trim($_POST['field_name']) == '')
1733
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1789
+		if (trim($_POST['field_name']) == '') {
1790
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1791
+		}
1734 1792
 
1735 1793
 		// Regex you say?  Do a very basic test to see if the pattern is valid
1736
-		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
1737
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1794
+		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) {
1795
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1796
+		}
1738 1797
 
1739 1798
 		$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
1740 1799
 		$_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
@@ -1751,8 +1810,9 @@  discard block
 block discarded – undo
1751 1810
 
1752 1811
 		// Some masking stuff...
1753 1812
 		$mask = isset($_POST['mask']) ? $_POST['mask'] : '';
1754
-		if ($mask == 'regex' && isset($_POST['regex']))
1755
-			$mask .= $_POST['regex'];
1813
+		if ($mask == 'regex' && isset($_POST['regex'])) {
1814
+					$mask .= $_POST['regex'];
1815
+		}
1756 1816
 
1757 1817
 		$field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
1758 1818
 		$enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
@@ -1771,8 +1831,9 @@  discard block
 block discarded – undo
1771 1831
 				$v = strtr($v, array(',' => ''));
1772 1832
 
1773 1833
 				// Nada, zip, etc...
1774
-				if (trim($v) == '')
1775
-					continue;
1834
+				if (trim($v) == '') {
1835
+									continue;
1836
+				}
1776 1837
 
1777 1838
 				// Otherwise, save it boy.
1778 1839
 				$field_options .= $v . ',';
@@ -1780,15 +1841,17 @@  discard block
 block discarded – undo
1780 1841
 				$newOptions[$k] = $v;
1781 1842
 
1782 1843
 				// Is it default?
1783
-				if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
1784
-					$default = $v;
1844
+				if (isset($_POST['default_select']) && $_POST['default_select'] == $k) {
1845
+									$default = $v;
1846
+				}
1785 1847
 			}
1786 1848
 			$field_options = substr($field_options, 0, -1);
1787 1849
 		}
1788 1850
 
1789 1851
 		// Text area has default has dimensions
1790
-		if ($_POST['field_type'] == 'textarea')
1791
-			$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1852
+		if ($_POST['field_type'] == 'textarea') {
1853
+					$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1854
+		}
1792 1855
 
1793 1856
 		// Come up with the unique name?
1794 1857
 		if (empty($context['fid']))
@@ -1797,32 +1860,36 @@  discard block
 block discarded – undo
1797 1860
 			preg_match('~([\w\d_-]+)~', $col_name, $matches);
1798 1861
 
1799 1862
 			// If there is nothing to the name, then let's start out own - for foreign languages etc.
1800
-			if (isset($matches[1]))
1801
-				$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1802
-			else
1803
-				$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1863
+			if (isset($matches[1])) {
1864
+							$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1865
+			} else {
1866
+							$col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999);
1867
+			}
1804 1868
 
1805 1869
 			// Make sure this is unique.
1806 1870
 			$current_fields = array();
1807 1871
 			$request = $smcFunc['db_query']('', '
1808 1872
 				SELECT id_field, col_name
1809 1873
 				FROM {db_prefix}custom_fields');
1810
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1811
-				$current_fields[$row['id_field']] = $row['col_name'];
1874
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1875
+							$current_fields[$row['id_field']] = $row['col_name'];
1876
+			}
1812 1877
 			$smcFunc['db_free_result']($request);
1813 1878
 
1814 1879
 			$unique = false;
1815 1880
 			for ($i = 0; !$unique && $i < 9; $i ++)
1816 1881
 			{
1817
-				if (!in_array($col_name, $current_fields))
1818
-					$unique = true;
1819
-				else
1820
-					$col_name = $initial_col_name . $i;
1882
+				if (!in_array($col_name, $current_fields)) {
1883
+									$unique = true;
1884
+				} else {
1885
+									$col_name = $initial_col_name . $i;
1886
+				}
1821 1887
 			}
1822 1888
 
1823 1889
 			// Still not a unique column name? Leave it up to the user, then.
1824
-			if (!$unique)
1825
-				fatal_lang_error('custom_option_not_unique');
1890
+			if (!$unique) {
1891
+							fatal_lang_error('custom_option_not_unique');
1892
+			}
1826 1893
 		}
1827 1894
 		// Work out what to do with the user data otherwise...
1828 1895
 		else
@@ -1850,8 +1917,9 @@  discard block
 block discarded – undo
1850 1917
 				// Work out what's changed!
1851 1918
 				foreach ($context['field']['options'] as $k => $option)
1852 1919
 				{
1853
-					if (trim($option) == '')
1854
-						continue;
1920
+					if (trim($option) == '') {
1921
+											continue;
1922
+					}
1855 1923
 
1856 1924
 					// Still exists?
1857 1925
 					if (in_array($option, $newOptions))
@@ -1865,8 +1933,8 @@  discard block
 block discarded – undo
1865 1933
 				foreach ($optionChanges as $k => $option)
1866 1934
 				{
1867 1935
 					// Just been renamed?
1868
-					if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1869
-						$smcFunc['db_query']('', '
1936
+					if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) {
1937
+											$smcFunc['db_query']('', '
1870 1938
 							UPDATE {db_prefix}themes
1871 1939
 							SET value = {string:new_value}
1872 1940
 							WHERE variable = {string:current_column}
@@ -1879,6 +1947,7 @@  discard block
 block discarded – undo
1879 1947
 								'old_value' => $option,
1880 1948
 							)
1881 1949
 						);
1950
+					}
1882 1951
 				}
1883 1952
 			}
1884 1953
 			// @todo Maybe we should adjust based on new text length limits?
@@ -1921,8 +1990,8 @@  discard block
 block discarded – undo
1921 1990
 			);
1922 1991
 
1923 1992
 			// Just clean up any old selects - these are a pain!
1924
-			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
1925
-				$smcFunc['db_query']('', '
1993
+			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) {
1994
+							$smcFunc['db_query']('', '
1926 1995
 					DELETE FROM {db_prefix}themes
1927 1996
 					WHERE variable = {string:current_column}
1928 1997
 						AND value NOT IN ({array_string:new_option_values})
@@ -1933,8 +2002,8 @@  discard block
 block discarded – undo
1933 2002
 						'current_column' => $context['field']['col_name'],
1934 2003
 					)
1935 2004
 				);
1936
-		}
1937
-		else
2005
+			}
2006
+		} else
1938 2007
 		{
1939 2008
 			// Gotta figure it out the order.
1940 2009
 			$new_order = $order_count > 1 ? ($order_count + 1) : 1;
@@ -2108,11 +2177,13 @@  discard block
 block discarded – undo
2108 2177
 	call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false));
2109 2178
 
2110 2179
 	$prune_toggle_dt = array();
2111
-	foreach ($prune_toggle as $item)
2112
-		$prune_toggle_dt[] = 'setting_' . $item;
2180
+	foreach ($prune_toggle as $item) {
2181
+			$prune_toggle_dt[] = 'setting_' . $item;
2182
+	}
2113 2183
 
2114
-	if ($return_config)
2115
-		return $config_vars;
2184
+	if ($return_config) {
2185
+			return $config_vars;
2186
+	}
2116 2187
 
2117 2188
 	addInlineJavaScript('
2118 2189
 	function togglePruned()
@@ -2150,15 +2221,16 @@  discard block
 block discarded – undo
2150 2221
 			$vals = array();
2151 2222
 			foreach ($config_vars as $index => $dummy)
2152 2223
 			{
2153
-				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle))
2154
-					continue;
2224
+				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) {
2225
+									continue;
2226
+				}
2155 2227
 
2156 2228
 				$vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
2157 2229
 			}
2158 2230
 			$_POST['pruningOptions'] = implode(',', $vals);
2231
+		} else {
2232
+					$_POST['pruningOptions'] = '';
2159 2233
 		}
2160
-		else
2161
-			$_POST['pruningOptions'] = '';
2162 2234
 
2163 2235
 		saveDBSettings($savevar);
2164 2236
 		$_SESSION['adm-save'] = true;
@@ -2170,10 +2242,11 @@  discard block
 block discarded – undo
2170 2242
 	$context['sub_template'] = 'show_settings';
2171 2243
 
2172 2244
 	// Get the actual values
2173
-	if (!empty($modSettings['pruningOptions']))
2174
-		@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2175
-	else
2176
-		$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2245
+	if (!empty($modSettings['pruningOptions'])) {
2246
+			@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2247
+	} else {
2248
+			$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2249
+	}
2177 2250
 
2178 2251
 	prepareDBSettingContext($config_vars);
2179 2252
 }
@@ -2195,8 +2268,9 @@  discard block
 block discarded – undo
2195 2268
 	// Make it even easier to add new settings.
2196 2269
 	call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
2197 2270
 
2198
-	if ($return_config)
2199
-		return $config_vars;
2271
+	if ($return_config) {
2272
+			return $config_vars;
2273
+	}
2200 2274
 
2201 2275
 	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
2202 2276
 	$context['settings_title'] = $txt['mods_cat_modifications_misc'];
Please login to merge, or discard this patch.
Sources/Security.php 1 patch
Braces   +263 added lines, -203 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
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type. '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:'.$ip_number.'} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -297,14 +314,15 @@  discard block
 block discarded – undo
297 314
 	if (isset($_SESSION['ban']['cannot_access']))
298 315
 	{
299 316
 		// We don't wanna see you!
300
-		if (!$user_info['is_guest'])
301
-			$smcFunc['db_query']('', '
317
+		if (!$user_info['is_guest']) {
318
+					$smcFunc['db_query']('', '
302 319
 				DELETE FROM {db_prefix}log_online
303 320
 				WHERE id_member = {int:current_member}',
304 321
 				array(
305 322
 					'current_member' => $user_info['id'],
306 323
 				)
307 324
 			);
325
+		}
308 326
 
309 327
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
310 328
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -390,9 +408,10 @@  discard block
 block discarded – undo
390 408
 	}
391 409
 
392 410
 	// Fix up the banning permissions.
393
-	if (isset($user_info['permissions']))
394
-		banPermissions();
395
-}
411
+	if (isset($user_info['permissions'])) {
412
+			banPermissions();
413
+	}
414
+	}
396 415
 
397 416
 /**
398 417
  * Fix permissions according to ban status.
@@ -403,8 +422,9 @@  discard block
 block discarded – undo
403 422
 	global $user_info, $sourcedir, $modSettings, $context;
404 423
 
405 424
 	// Somehow they got here, at least take away all permissions...
406
-	if (isset($_SESSION['ban']['cannot_access']))
407
-		$user_info['permissions'] = array();
425
+	if (isset($_SESSION['ban']['cannot_access'])) {
426
+			$user_info['permissions'] = array();
427
+	}
408 428
 	// Okay, well, you can watch, but don't touch a thing.
409 429
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
410 430
 	{
@@ -446,44 +466,45 @@  discard block
 block discarded – undo
446 466
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
447 467
 		foreach ($permission_change as $old => $new)
448 468
 		{
449
-			if (!in_array($old, $user_info['permissions']))
450
-				unset($permission_change[$old]);
451
-			else
452
-				$user_info['permissions'][] = $new;
469
+			if (!in_array($old, $user_info['permissions'])) {
470
+							unset($permission_change[$old]);
471
+			} else {
472
+							$user_info['permissions'][] = $new;
473
+			}
453 474
 		}
454 475
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
455 476
 	}
456 477
 
457 478
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
458 479
 	// Finally, some bits we cache in the session because it saves queries.
459
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
460
-		$user_info['mod_cache'] = $_SESSION['mc'];
461
-	else
480
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
481
+			$user_info['mod_cache'] = $_SESSION['mc'];
482
+	} else
462 483
 	{
463 484
 		require_once($sourcedir . '/Subs-Auth.php');
464 485
 		rebuildModCache();
465 486
 	}
466 487
 
467 488
 	// Now that we have the mod cache taken care of lets setup a cache for the number of mod reports still open
468
-	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id'])
469
-		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
470
-	elseif ($_SESSION['mc']['bq'] != '0=1')
489
+	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id']) {
490
+			$context['open_mod_reports'] = $_SESSION['rc']['reports'];
491
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
471 492
 	{
472 493
 		require_once($sourcedir . '/Subs-ReportedContent.php');
473 494
 		recountOpenReports('posts');
495
+	} else {
496
+			$context['open_mod_reports'] = 0;
474 497
 	}
475
-	else
476
-		$context['open_mod_reports'] = 0;
477 498
 
478
-	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id'])
479
-		$context['open_member_reports'] = !empty($_SESSION['rc']['member_reports']) ? $_SESSION['rc']['member_reports'] : 0;
480
-	elseif (allowedTo('moderate_forum'))
499
+	if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id']) {
500
+			$context['open_member_reports'] = !empty($_SESSION['rc']['member_reports']) ? $_SESSION['rc']['member_reports'] : 0;
501
+	} elseif (allowedTo('moderate_forum'))
481 502
 	{
482 503
 		require_once($sourcedir . '/Subs-ReportedContent.php');
483 504
 		recountOpenReports('members');
505
+	} else {
506
+			$context['open_member_reports'] = 0;
484 507
 	}
485
-	else
486
-		$context['open_member_reports'] = 0;
487 508
 
488 509
 }
489 510
 
@@ -500,8 +521,9 @@  discard block
 block discarded – undo
500 521
 	global $user_info, $smcFunc;
501 522
 
502 523
 	// Don't log web accelerators, it's very confusing...
503
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
504
-		return;
524
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
525
+			return;
526
+	}
505 527
 
506 528
 	$smcFunc['db_insert']('',
507 529
 		'{db_prefix}log_banned',
@@ -511,8 +533,8 @@  discard block
 block discarded – undo
511 533
 	);
512 534
 
513 535
 	// One extra point for these bans.
514
-	if (!empty($ban_ids))
515
-		$smcFunc['db_query']('', '
536
+	if (!empty($ban_ids)) {
537
+			$smcFunc['db_query']('', '
516 538
 			UPDATE {db_prefix}ban_items
517 539
 			SET hits = hits + 1
518 540
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -520,7 +542,8 @@  discard block
 block discarded – undo
520 542
 				'ban_ids' => $ban_ids,
521 543
 			)
522 544
 		);
523
-}
545
+	}
546
+	}
524 547
 
525 548
 /**
526 549
  * Checks if a given email address might be banned.
@@ -536,8 +559,9 @@  discard block
 block discarded – undo
536 559
 	global $txt, $smcFunc;
537 560
 
538 561
 	// Can't ban an empty email
539
-	if (empty($email) || trim($email) == '')
540
-		return;
562
+	if (empty($email) || trim($email) == '') {
563
+			return;
564
+	}
541 565
 
542 566
 	// Let's start with the bans based on your IP/hostname/memberID...
543 567
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -610,16 +634,18 @@  discard block
 block discarded – undo
610 634
 	if ($type == 'post')
611 635
 	{
612 636
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
613
-		if ($check !== $sc)
614
-			$error = 'session_timeout';
637
+		if ($check !== $sc) {
638
+					$error = 'session_timeout';
639
+		}
615 640
 	}
616 641
 
617 642
 	// How about $_GET['sesc']?
618 643
 	elseif ($type == 'get')
619 644
 	{
620 645
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
621
-		if ($check !== $sc)
622
-			$error = 'session_verify_fail';
646
+		if ($check !== $sc) {
647
+					$error = 'session_verify_fail';
648
+		}
623 649
 	}
624 650
 
625 651
 	// Or can it be in either?
@@ -627,13 +653,15 @@  discard block
 block discarded – undo
627 653
 	{
628 654
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
629 655
 
630
-		if ($check !== $sc)
631
-			$error = 'session_verify_fail';
656
+		if ($check !== $sc) {
657
+					$error = 'session_verify_fail';
658
+		}
632 659
 	}
633 660
 
634 661
 	// Verify that they aren't changing user agents on us - that could be bad.
635
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
636
-		$error = 'session_verify_fail';
662
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
663
+			$error = 'session_verify_fail';
664
+	}
637 665
 
638 666
 	// Make sure a page with session check requirement is not being prefetched.
639 667
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -644,30 +672,35 @@  discard block
 block discarded – undo
644 672
 	}
645 673
 
646 674
 	// Check the referring site - it should be the same server at least!
647
-	if (isset($_SESSION['request_referer']))
648
-		$referrer = $_SESSION['request_referer'];
649
-	else
650
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
675
+	if (isset($_SESSION['request_referer'])) {
676
+			$referrer = $_SESSION['request_referer'];
677
+	} else {
678
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
679
+	}
651 680
 	if (!empty($referrer['host']))
652 681
 	{
653
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
654
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
655
-		else
656
-			$real_host = $_SERVER['HTTP_HOST'];
682
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
683
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
684
+		} else {
685
+					$real_host = $_SERVER['HTTP_HOST'];
686
+		}
657 687
 
658 688
 		$parsed_url = parse_url($boardurl);
659 689
 
660 690
 		// Are global cookies on?  If so, let's check them ;).
661 691
 		if (!empty($modSettings['globalCookies']))
662 692
 		{
663
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
664
-				$parsed_url['host'] = $parts[1];
693
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
694
+							$parsed_url['host'] = $parts[1];
695
+			}
665 696
 
666
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
667
-				$referrer['host'] = $parts[1];
697
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
698
+							$referrer['host'] = $parts[1];
699
+			}
668 700
 
669
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
670
-				$real_host = $parts[1];
701
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
702
+							$real_host = $parts[1];
703
+			}
671 704
 		}
672 705
 
673 706
 		// Okay: referrer must either match parsed_url or real_host.
@@ -685,12 +718,14 @@  discard block
 block discarded – undo
685 718
 		$log_error = true;
686 719
 	}
687 720
 
688
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
689
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
721
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
722
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
723
+	}
690 724
 
691 725
 	// Everything is ok, return an empty string.
692
-	if (!isset($error))
693
-		return '';
726
+	if (!isset($error)) {
727
+			return '';
728
+	}
694 729
 	// A session error occurred, show the error.
695 730
 	elseif ($is_fatal)
696 731
 	{
@@ -699,13 +734,14 @@  discard block
 block discarded – undo
699 734
 			ob_end_clean();
700 735
 			header('HTTP/1.1 403 Forbidden - Session timeout');
701 736
 			die;
737
+		} else {
738
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
702 739
 		}
703
-		else
704
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
705 740
 	}
706 741
 	// A session error occurred, return the error to the calling function.
707
-	else
708
-		return $error;
742
+	else {
743
+			return $error;
744
+	}
709 745
 
710 746
 	// We really should never fall through here, for very important reasons.  Let's make sure.
711 747
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -721,10 +757,9 @@  discard block
 block discarded – undo
721 757
 {
722 758
 	global $modSettings;
723 759
 
724
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
725
-		return true;
726
-
727
-	else
760
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
761
+			return true;
762
+	} else
728 763
 	{
729 764
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
730 765
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -775,9 +810,9 @@  discard block
 block discarded – undo
775 810
 			$return = $_SESSION['token'][$type . '-' . $action][3];
776 811
 			unset($_SESSION['token'][$type . '-' . $action]);
777 812
 			return $return;
813
+		} else {
814
+					return '';
778 815
 		}
779
-		else
780
-			return '';
781 816
 	}
782 817
 
783 818
 	// This nasty piece of code validates a token.
@@ -808,12 +843,14 @@  discard block
 block discarded – undo
808 843
 		fatal_lang_error('token_verify_fail', false);
809 844
 	}
810 845
 	// Remove this token as its useless
811
-	else
812
-		unset($_SESSION['token'][$type . '-' . $action]);
846
+	else {
847
+			unset($_SESSION['token'][$type . '-' . $action]);
848
+	}
813 849
 
814 850
 	// Randomly check if we should remove some older tokens.
815
-	if (mt_rand(0, 138) == 23)
816
-		cleanTokens();
851
+	if (mt_rand(0, 138) == 23) {
852
+			cleanTokens();
853
+	}
817 854
 
818 855
 	return false;
819 856
 }
@@ -828,14 +865,16 @@  discard block
 block discarded – undo
828 865
 function cleanTokens($complete = false)
829 866
 {
830 867
 	// We appreciate cleaning up after yourselves.
831
-	if (!isset($_SESSION['token']))
832
-		return;
868
+	if (!isset($_SESSION['token'])) {
869
+			return;
870
+	}
833 871
 
834 872
 	// Clean up tokens, trying to give enough time still.
835
-	foreach ($_SESSION['token'] as $key => $data)
836
-		if ($data[2] + 10800 < time() || $complete)
873
+	foreach ($_SESSION['token'] as $key => $data) {
874
+			if ($data[2] + 10800 < time() || $complete)
837 875
 			unset($_SESSION['token'][$key]);
838
-}
876
+	}
877
+	}
839 878
 
840 879
 /**
841 880
  * Check whether a form has been submitted twice.
@@ -853,37 +892,40 @@  discard block
 block discarded – undo
853 892
 {
854 893
 	global $context;
855 894
 
856
-	if (!isset($_SESSION['forms']))
857
-		$_SESSION['forms'] = array();
895
+	if (!isset($_SESSION['forms'])) {
896
+			$_SESSION['forms'] = array();
897
+	}
858 898
 
859 899
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
860 900
 	if ($action == 'register')
861 901
 	{
862 902
 		$context['form_sequence_number'] = 0;
863
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
864
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
903
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
904
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
905
+		}
865 906
 	}
866 907
 	// Check whether the submitted number can be found in the session.
867 908
 	elseif ($action == 'check')
868 909
 	{
869
-		if (!isset($_REQUEST['seqnum']))
870
-			return true;
871
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
910
+		if (!isset($_REQUEST['seqnum'])) {
911
+					return true;
912
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
872 913
 		{
873 914
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
874 915
 			return true;
916
+		} elseif ($is_fatal) {
917
+					fatal_lang_error('error_form_already_submitted', false);
918
+		} else {
919
+					return false;
875 920
 		}
876
-		elseif ($is_fatal)
877
-			fatal_lang_error('error_form_already_submitted', false);
878
-		else
879
-			return false;
880 921
 	}
881 922
 	// Don't check, just free the stack number.
882
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
883
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
884
-	elseif ($action != 'free')
885
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
886
-}
923
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
924
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
925
+	} elseif ($action != 'free') {
926
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
927
+	}
928
+	}
887 929
 
888 930
 /**
889 931
  * Check the user's permissions.
@@ -900,16 +942,19 @@  discard block
 block discarded – undo
900 942
 	global $user_info, $smcFunc;
901 943
 
902 944
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
903
-	if (empty($permission))
904
-		return true;
945
+	if (empty($permission)) {
946
+			return true;
947
+	}
905 948
 
906 949
 	// You're never allowed to do something if your data hasn't been loaded yet!
907
-	if (empty($user_info))
908
-		return false;
950
+	if (empty($user_info)) {
951
+			return false;
952
+	}
909 953
 
910 954
 	// Administrators are supermen :P.
911
-	if ($user_info['is_admin'])
912
-		return true;
955
+	if ($user_info['is_admin']) {
956
+			return true;
957
+	}
913 958
 
914 959
 	// Let's ensure this is an array.
915 960
 	$permission = (array)$permission;
@@ -917,14 +962,16 @@  discard block
 block discarded – undo
917 962
 	// Are we checking the _current_ board, or some other boards?
918 963
 	if ($boards === null)
919 964
 	{
920
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
921
-			return true;
965
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
966
+					return true;
967
+		}
922 968
 		// You aren't allowed, by default.
923
-		else
924
-			return false;
969
+		else {
970
+					return false;
971
+		}
972
+	} elseif (!is_array($boards)) {
973
+			$boards = array($boards);
925 974
 	}
926
-	elseif (!is_array($boards))
927
-		$boards = array($boards);
928 975
 
929 976
 	$request = $smcFunc['db_query']('', '
930 977
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -947,12 +994,14 @@  discard block
 block discarded – undo
947 994
 	);
948 995
 
949 996
 	// Make sure they can do it on all of the boards.
950
-	if ($smcFunc['db_num_rows']($request) != count($boards))
951
-		return false;
997
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
998
+			return false;
999
+	}
952 1000
 
953 1001
 	$result = true;
954
-	while ($row = $smcFunc['db_fetch_assoc']($request))
955
-		$result &= !empty($row['add_deny']);
1002
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1003
+			$result &= !empty($row['add_deny']);
1004
+	}
956 1005
 	$smcFunc['db_free_result']($request);
957 1006
 
958 1007
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1017,9 +1066,10 @@  discard block
 block discarded – undo
1017 1066
 
1018 1067
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1019 1068
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1020
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1021
-		validateSession();
1022
-}
1069
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1070
+			validateSession();
1071
+	}
1072
+	}
1023 1073
 
1024 1074
 /**
1025 1075
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1038,8 +1088,9 @@  discard block
 block discarded – undo
1038 1088
 	global $user_info, $smcFunc;
1039 1089
 
1040 1090
 	// Arrays are nice, most of the time.
1041
-	if (!is_array($permissions))
1042
-		$permissions = array($permissions);
1091
+	if (!is_array($permissions)) {
1092
+			$permissions = array($permissions);
1093
+	}
1043 1094
 
1044 1095
 	/*
1045 1096
 	 * Set $simple to true to use this function as it were in SMF 2.0.x.
@@ -1051,13 +1102,14 @@  discard block
 block discarded – undo
1051 1102
 	// Administrators are all powerful, sorry.
1052 1103
 	if ($user_info['is_admin'])
1053 1104
 	{
1054
-		if ($simple)
1055
-			return array(0);
1056
-		else
1105
+		if ($simple) {
1106
+					return array(0);
1107
+		} else
1057 1108
 		{
1058 1109
 			$boards = array();
1059
-			foreach ($permissions as $permission)
1060
-				$boards[$permission] = array(0);
1110
+			foreach ($permissions as $permission) {
1111
+							$boards[$permission] = array(0);
1112
+			}
1061 1113
 
1062 1114
 			return $boards;
1063 1115
 		}
@@ -1089,31 +1141,32 @@  discard block
 block discarded – undo
1089 1141
 	{
1090 1142
 		if ($simple)
1091 1143
 		{
1092
-			if (empty($row['add_deny']))
1093
-				$deny_boards[] = $row['id_board'];
1094
-			else
1095
-				$boards[] = $row['id_board'];
1096
-		}
1097
-		else
1144
+			if (empty($row['add_deny'])) {
1145
+							$deny_boards[] = $row['id_board'];
1146
+			} else {
1147
+							$boards[] = $row['id_board'];
1148
+			}
1149
+		} else
1098 1150
 		{
1099
-			if (empty($row['add_deny']))
1100
-				$deny_boards[$row['permission']][] = $row['id_board'];
1101
-			else
1102
-				$boards[$row['permission']][] = $row['id_board'];
1151
+			if (empty($row['add_deny'])) {
1152
+							$deny_boards[$row['permission']][] = $row['id_board'];
1153
+			} else {
1154
+							$boards[$row['permission']][] = $row['id_board'];
1155
+			}
1103 1156
 		}
1104 1157
 	}
1105 1158
 	$smcFunc['db_free_result']($request);
1106 1159
 
1107
-	if ($simple)
1108
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1109
-	else
1160
+	if ($simple) {
1161
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1162
+	} else
1110 1163
 	{
1111 1164
 		foreach ($permissions as $permission)
1112 1165
 		{
1113 1166
 			// never had it to start with
1114
-			if (empty($boards[$permission]))
1115
-				$boards[$permission] = array();
1116
-			else
1167
+			if (empty($boards[$permission])) {
1168
+							$boards[$permission] = array();
1169
+			} else
1117 1170
 			{
1118 1171
 				// Or it may have been removed
1119 1172
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1149,10 +1202,11 @@  discard block
 block discarded – undo
1149 1202
 
1150 1203
 
1151 1204
 	// Moderators are free...
1152
-	if (!allowedTo('moderate_board'))
1153
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1154
-	else
1155
-		$timeLimit = 2;
1205
+	if (!allowedTo('moderate_board')) {
1206
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1207
+	} else {
1208
+			$timeLimit = 2;
1209
+	}
1156 1210
 
1157 1211
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1158 1212
 
@@ -1179,8 +1233,9 @@  discard block
 block discarded – undo
1179 1233
 	if ($smcFunc['db_affected_rows']() != 1)
1180 1234
 	{
1181 1235
 		// Spammer!  You only have to wait a *few* seconds!
1182
-		if (!$only_return_result)
1183
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1236
+		if (!$only_return_result) {
1237
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1238
+		}
1184 1239
 
1185 1240
 		return true;
1186 1241
 	}
@@ -1198,11 +1253,13 @@  discard block
 block discarded – undo
1198 1253
  */
1199 1254
 function secureDirectory($path, $attachments = false)
1200 1255
 {
1201
-	if (empty($path))
1202
-		return 'empty_path';
1256
+	if (empty($path)) {
1257
+			return 'empty_path';
1258
+	}
1203 1259
 
1204
-	if (!is_writable($path))
1205
-		return 'path_not_writable';
1260
+	if (!is_writable($path)) {
1261
+			return 'path_not_writable';
1262
+	}
1206 1263
 
1207 1264
 	$directoryname = basename($path);
1208 1265
 
@@ -1214,9 +1271,9 @@  discard block
 block discarded – undo
1214 1271
 
1215 1272
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1216 1273
 
1217
-	if (file_exists($path . '/.htaccess'))
1218
-		$errors[] = 'htaccess_exists';
1219
-	else
1274
+	if (file_exists($path . '/.htaccess')) {
1275
+			$errors[] = 'htaccess_exists';
1276
+	} else
1220 1277
 	{
1221 1278
 		$fh = @fopen($path . '/.htaccess', 'w');
1222 1279
 		if ($fh) {
@@ -1228,9 +1285,9 @@  discard block
 block discarded – undo
1228 1285
 		$errors[] = 'htaccess_cannot_create_file';
1229 1286
 	}
1230 1287
 
1231
-	if (file_exists($path . '/index.php'))
1232
-		$errors[] = 'index-php_exists';
1233
-	else
1288
+	if (file_exists($path . '/index.php')) {
1289
+			$errors[] = 'index-php_exists';
1290
+	} else
1234 1291
 	{
1235 1292
 		$fh = @fopen($path . '/index.php', 'w');
1236 1293
 		if ($fh) {
@@ -1257,11 +1314,12 @@  discard block
 block discarded – undo
1257 1314
 		$errors[] = 'index-php_cannot_create_file';
1258 1315
 	}
1259 1316
 
1260
-	if (!empty($errors))
1261
-		return $errors;
1262
-	else
1263
-		return true;
1264
-}
1317
+	if (!empty($errors)) {
1318
+			return $errors;
1319
+	} else {
1320
+			return true;
1321
+	}
1322
+	}
1265 1323
 
1266 1324
 /**
1267 1325
 * This sets the X-Frame-Options header.
@@ -1274,14 +1332,16 @@  discard block
 block discarded – undo
1274 1332
 	global $modSettings;
1275 1333
 
1276 1334
 	$option = 'SAMEORIGIN';
1277
-	if (is_null($override) && !empty($modSettings['frame_security']))
1278
-		$option = $modSettings['frame_security'];
1279
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1280
-		$option = $override;
1335
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1336
+			$option = $modSettings['frame_security'];
1337
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1338
+			$option = $override;
1339
+	}
1281 1340
 
1282 1341
 	// Don't bother setting the header if we have disabled it.
1283
-	if ($option == 'DISABLE')
1284
-		return;
1342
+	if ($option == 'DISABLE') {
1343
+			return;
1344
+	}
1285 1345
 
1286 1346
 	// Finally set it.
1287 1347
 	header('X-Frame-Options: ' . $option);
Please login to merge, or discard this patch.
Sources/Class-CacheAPI.php 1 patch
Braces   +13 added lines, -9 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
  * Interface cache_api_interface
@@ -186,8 +187,9 @@  discard block
 block discarded – undo
186 187
 	{
187 188
 		global $cache_enable;
188 189
 
189
-		if ($test)
190
-			return true;
190
+		if ($test) {
191
+					return true;
192
+		}
191 193
 		return !empty($cache_enable);
192 194
 	}
193 195
 
@@ -206,10 +208,11 @@  discard block
 block discarded – undo
206 208
 		global $boardurl, $cachedir;
207 209
 
208 210
 		// Set the default if no prefix was specified.
209
-		if (empty($prefix))
210
-			$this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-';
211
-		else
212
-			$this->prefix = $prefix;
211
+		if (empty($prefix)) {
212
+					$this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-';
213
+		} else {
214
+					$this->prefix = $prefix;
215
+		}
213 216
 
214 217
 		return true;
215 218
 	}
@@ -272,8 +275,9 @@  discard block
 block discarded – undo
272 275
 
273 276
 		// Invalidate cache, to be sure!
274 277
 		// ... as long as index.php can be modified, anyway.
275
-		if (is_writable($cachedir . '/' . 'index.php'))
276
-			@touch($cachedir . '/' . 'index.php');
278
+		if (is_writable($cachedir . '/' . 'index.php')) {
279
+					@touch($cachedir . '/' . 'index.php');
280
+		}
277 281
 
278 282
 		return true;
279 283
 	}
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +225 added lines, -164 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query' => 'smf_db_query',
39 40
 			'db_quote' => 'smf_db_quote',
40 41
 			'db_fetch_assoc' => 'mysql_fetch_assoc',
@@ -58,36 +59,42 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource' => 'is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['port']))
63
-		$db_server .= ':' . $db_options['port'];
64
+	if (!empty($db_options['port'])) {
65
+			$db_server .= ':' . $db_options['port'];
66
+	}
64 67
 	
65 68
 	$flags = 2; //#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
66 69
 
67
-	if (!empty($db_options['persist']))
68
-		$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
69
-	else
70
-		$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
70
+	if (!empty($db_options['persist'])) {
71
+			$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
72
+	} else {
73
+			$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
74
+	}
71 75
 
72 76
 	// Something's wrong, show an error if its fatal (which we assume it is)
73 77
 	if (!$connection)
74 78
 	{
75
-		if (!empty($db_options['non_fatal']))
76
-			return null;
77
-		else
78
-			display_db_error();
79
+		if (!empty($db_options['non_fatal'])) {
80
+					return null;
81
+		} else {
82
+					display_db_error();
83
+		}
79 84
 	}
80 85
 
81 86
 	// Select the database, unless told not to
82
-	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal']))
83
-		display_db_error();
87
+	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) {
88
+			display_db_error();
89
+	}
84 90
 
85 91
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
86
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
87
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
92
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
93
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
88 94
 		array(),
89 95
 		false
90 96
 	);
97
+	}
91 98
 
92 99
 	return $connection;
93 100
 }
@@ -134,37 +141,46 @@  discard block
 block discarded – undo
134 141
 	list ($values, $connection) = $db_callback;
135 142
 
136 143
 	// Connection gone???  This should *never* happen at this point, yet it does :'(
137
-	if (!is_resource($connection))
138
-		display_db_error();
144
+	if (!is_resource($connection)) {
145
+			display_db_error();
146
+	}
139 147
 
140
-	if ($matches[1] === 'db_prefix')
141
-		return $db_prefix;
148
+	if ($matches[1] === 'db_prefix') {
149
+			return $db_prefix;
150
+	}
142 151
 
143
-	if ($matches[1] === 'query_see_board')
144
-		return $user_info['query_see_board'];
152
+	if ($matches[1] === 'query_see_board') {
153
+			return $user_info['query_see_board'];
154
+	}
145 155
 
146
-	if ($matches[1] === 'query_wanna_see_board')
147
-		return $user_info['query_wanna_see_board'];
156
+	if ($matches[1] === 'query_wanna_see_board') {
157
+			return $user_info['query_wanna_see_board'];
158
+	}
148 159
 
149
-	if ($matches[1] === 'empty')
150
-		return '\'\'';
160
+	if ($matches[1] === 'empty') {
161
+			return '\'\'';
162
+	}
151 163
 
152
-	if (!isset($matches[2]))
153
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
164
+	if (!isset($matches[2])) {
165
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
166
+	}
154 167
 
155
-	if ($matches[1] === 'literal')
156
-		return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
168
+	if ($matches[1] === 'literal') {
169
+			return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
170
+	}
157 171
 
158
-	if (!isset($values[$matches[2]]))
159
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
172
+	if (!isset($values[$matches[2]])) {
173
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
174
+	}
160 175
 
161 176
 	$replacement = $values[$matches[2]];
162 177
 
163 178
 	switch ($matches[1])
164 179
 	{
165 180
 		case 'int':
166
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
167
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
182
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+			}
168 184
 			return (string) (int) $replacement;
169 185
 		break;
170 186
 
@@ -176,49 +192,55 @@  discard block
 block discarded – undo
176 192
 		case 'array_int':
177 193
 			if (is_array($replacement))
178 194
 			{
179
-				if (empty($replacement))
180
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195
+				if (empty($replacement)) {
196
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
197
+				}
181 198
 
182 199
 				foreach ($replacement as $key => $value)
183 200
 				{
184
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
185
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
201
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
202
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
203
+					}
186 204
 
187 205
 					$replacement[$key] = (string) (int) $value;
188 206
 				}
189 207
 
190 208
 				return implode(', ', $replacement);
209
+			} else {
210
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
191 211
 			}
192
-			else
193
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
194 212
 
195 213
 		break;
196 214
 
197 215
 		case 'array_string':
198 216
 			if (is_array($replacement))
199 217
 			{
200
-				if (empty($replacement))
201
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+				if (empty($replacement)) {
219
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				}
202 221
 
203
-				foreach ($replacement as $key => $value)
204
-					$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
222
+				foreach ($replacement as $key => $value) {
223
+									$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
224
+				}
205 225
 
206 226
 				return implode(', ', $replacement);
227
+			} else {
228
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
207 229
 			}
208
-			else
209
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210 230
 		break;
211 231
 
212 232
 		case 'date':
213
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
214
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
-			else
216
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
234
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			}
217 238
 		break;
218 239
 
219 240
 		case 'float':
220
-			if (!is_numeric($replacement))
221
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			if (!is_numeric($replacement)) {
242
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243
+			}
222 244
 			return (string) (float) $replacement;
223 245
 		break;
224 246
 
@@ -232,32 +254,37 @@  discard block
 block discarded – undo
232 254
 		break;
233 255
 
234 256
 		case 'inet':
235
-			if ($replacement == 'null' || $replacement == '')
236
-				return 'null';
237
-			if (!isValidIP($replacement))
238
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+			if ($replacement == 'null' || $replacement == '') {
258
+							return 'null';
259
+			}
260
+			if (!isValidIP($replacement)) {
261
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262
+			}
239 263
 			//we don't use the native support of mysql > 5.6.2
240 264
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
241 265
 
242 266
 		case 'array_inet':
243 267
 			if (is_array($replacement))
244 268
 			{
245
-				if (empty($replacement))
246
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+				if (empty($replacement)) {
270
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+				}
247 272
 
248 273
 				foreach ($replacement as $key => $value)
249 274
 				{
250
-					if ($replacement == 'null' || $replacement == '')
251
-						$replacement[$key] = 'null';
252
-					if (!isValidIP($value))
253
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
275
+					if ($replacement == 'null' || $replacement == '') {
276
+											$replacement[$key] = 'null';
277
+					}
278
+					if (!isValidIP($value)) {
279
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
280
+					}
254 281
 					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
255 282
 				}
256 283
 
257 284
 				return implode(', ', $replacement);
285
+			} else {
286
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
258 287
 			}
259
-			else
260
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
261 288
 		break;
262 289
 
263 290
 		default:
@@ -328,18 +355,20 @@  discard block
 block discarded – undo
328 355
 	// One more query....
329 356
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
330 357
 
331
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
332
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
358
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
359
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
360
+	}
333 361
 
334 362
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
335 363
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
336 364
 	{
337 365
 		// Add before LIMIT
338
-		if ($pos = strpos($db_string, 'LIMIT '))
339
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
340
-		else
341
-			// Append it.
366
+		if ($pos = strpos($db_string, 'LIMIT ')) {
367
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
368
+		} else {
369
+					// Append it.
342 370
 			$db_string .= "\n\t\t\tORDER BY null";
371
+		}
343 372
 	}
344 373
 
345 374
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -361,8 +390,9 @@  discard block
 block discarded – undo
361 390
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
362 391
 
363 392
 		// Initialize $db_cache if not already initialized.
364
-		if (!isset($db_cache))
365
-			$db_cache = array();
393
+		if (!isset($db_cache)) {
394
+					$db_cache = array();
395
+		}
366 396
 
367 397
 		if (!empty($_SESSION['debug_redirect']))
368 398
 		{
@@ -388,17 +418,18 @@  discard block
 block discarded – undo
388 418
 		while (true)
389 419
 		{
390 420
 			$pos = strpos($db_string, '\'', $pos + 1);
391
-			if ($pos === false)
392
-				break;
421
+			if ($pos === false) {
422
+							break;
423
+			}
393 424
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
394 425
 
395 426
 			while (true)
396 427
 			{
397 428
 				$pos1 = strpos($db_string, '\'', $pos + 1);
398 429
 				$pos2 = strpos($db_string, '\\', $pos + 1);
399
-				if ($pos1 === false)
400
-					break;
401
-				elseif ($pos2 === false || $pos2 > $pos1)
430
+				if ($pos1 === false) {
431
+									break;
432
+				} elseif ($pos2 === false || $pos2 > $pos1)
402 433
 				{
403 434
 					$pos = $pos1;
404 435
 					break;
@@ -414,29 +445,35 @@  discard block
 block discarded – undo
414 445
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
415 446
 
416 447
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
417
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
418
-			$fail = true;
448
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
449
+					$fail = true;
450
+		}
419 451
 		// Trying to change passwords, slow us down, or something?
420
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
421
-			$fail = true;
422
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
423
-			$fail = true;
452
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
453
+					$fail = true;
454
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
455
+					$fail = true;
456
+		}
424 457
 
425
-		if (!empty($fail) && function_exists('log_error'))
426
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
458
+		if (!empty($fail) && function_exists('log_error')) {
459
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
460
+		}
427 461
 	}
428 462
 
429
-	if (empty($db_unbuffered))
430
-		$ret = @mysql_query($db_string, $connection);
431
-	else
432
-		$ret = @mysql_unbuffered_query($db_string, $connection);
463
+	if (empty($db_unbuffered)) {
464
+			$ret = @mysql_query($db_string, $connection);
465
+	} else {
466
+			$ret = @mysql_unbuffered_query($db_string, $connection);
467
+	}
433 468
 
434
-	if ($ret === false && empty($db_values['db_error_skip']))
435
-		$ret = smf_db_error($db_string, $connection);
469
+	if ($ret === false && empty($db_values['db_error_skip'])) {
470
+			$ret = smf_db_error($db_string, $connection);
471
+	}
436 472
 
437 473
 	// Debugging.
438
-	if (isset($db_show_debug) && $db_show_debug === true)
439
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
474
+	if (isset($db_show_debug) && $db_show_debug === true) {
475
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
476
+	}
440 477
 
441 478
 	return $ret;
442 479
 }
@@ -485,12 +522,13 @@  discard block
 block discarded – undo
485 522
 	// Decide which connection to use
486 523
 	$connection = $connection === null ? $db_connection : $connection;
487 524
 
488
-	if ($type == 'begin')
489
-		return @mysql_query('BEGIN', $connection);
490
-	elseif ($type == 'rollback')
491
-		return @mysql_query('ROLLBACK', $connection);
492
-	elseif ($type == 'commit')
493
-		return @mysql_query('COMMIT', $connection);
525
+	if ($type == 'begin') {
526
+			return @mysql_query('BEGIN', $connection);
527
+	} elseif ($type == 'rollback') {
528
+			return @mysql_query('ROLLBACK', $connection);
529
+	} elseif ($type == 'commit') {
530
+			return @mysql_query('COMMIT', $connection);
531
+	}
494 532
 
495 533
 	return false;
496 534
 }
@@ -530,8 +568,9 @@  discard block
 block discarded – undo
530 568
 	//    2013: Lost connection to server during query.
531 569
 
532 570
 	// Log the error.
533
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
534
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
571
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
572
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
573
+	}
535 574
 
536 575
 	// Database error auto fixing ;).
537 576
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -540,8 +579,9 @@  discard block
 block discarded – undo
540 579
 		$old_cache = @$modSettings['cache_enable'];
541 580
 		$modSettings['cache_enable'] = '1';
542 581
 
543
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
544
-			$db_last_error = max(@$db_last_error, $temp);
582
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
583
+					$db_last_error = max(@$db_last_error, $temp);
584
+		}
545 585
 
546 586
 		if (@$db_last_error < time() - 3600 * 24 * 3)
547 587
 		{
@@ -557,8 +597,9 @@  discard block
 block discarded – undo
557 597
 					foreach ($tables as $table)
558 598
 					{
559 599
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
560
-						if (trim($table) != '')
561
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
600
+						if (trim($table) != '') {
601
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
602
+						}
562 603
 					}
563 604
 				}
564 605
 
@@ -567,8 +608,9 @@  discard block
 block discarded – undo
567 608
 			// Table crashed.  Let's try to fix it.
568 609
 			elseif ($query_errno == 1016)
569 610
 			{
570
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
571
-					$fix_tables = array('`' . $match[1] . '`');
611
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
612
+									$fix_tables = array('`' . $match[1] . '`');
613
+				}
572 614
 			}
573 615
 			// Indexes crashed.  Should be easy to fix!
574 616
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -587,13 +629,15 @@  discard block
 block discarded – undo
587 629
 
588 630
 			// Make a note of the REPAIR...
589 631
 			cache_put_data('db_last_error', time(), 600);
590
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
591
-				updateSettingsFile(array('db_last_error' => time()));
632
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
633
+							updateSettingsFile(array('db_last_error' => time()));
634
+			}
592 635
 
593 636
 			// Attempt to find and repair the broken table.
594
-			foreach ($fix_tables as $table)
595
-				$smcFunc['db_query']('', "
637
+			foreach ($fix_tables as $table) {
638
+							$smcFunc['db_query']('', "
596 639
 					REPAIR TABLE $table", false, false);
640
+			}
597 641
 
598 642
 			// And send off an email!
599 643
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -602,11 +646,12 @@  discard block
 block discarded – undo
602 646
 
603 647
 			// Try the query again...?
604 648
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
605
-			if ($ret !== false)
606
-				return $ret;
649
+			if ($ret !== false) {
650
+							return $ret;
651
+			}
652
+		} else {
653
+					$modSettings['cache_enable'] = $old_cache;
607 654
 		}
608
-		else
609
-			$modSettings['cache_enable'] = $old_cache;
610 655
 
611 656
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
612 657
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -616,22 +661,25 @@  discard block
 block discarded – undo
616 661
 				// Are we in SSI mode?  If so try that username and password first
617 662
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
618 663
 				{
619
-					if (empty($db_persist))
620
-						$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
621
-					else
622
-						$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
664
+					if (empty($db_persist)) {
665
+											$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
666
+					} else {
667
+											$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
668
+					}
623 669
 				}
624 670
 				// Fall back to the regular username and password if need be
625 671
 				if (!$db_connection)
626 672
 				{
627
-					if (empty($db_persist))
628
-						$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
629
-					else
630
-						$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
673
+					if (empty($db_persist)) {
674
+											$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
675
+					} else {
676
+											$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
677
+					}
631 678
 				}
632 679
 
633
-				if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
634
-					$db_connection = false;
680
+				if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) {
681
+									$db_connection = false;
682
+				}
635 683
 			}
636 684
 
637 685
 			if ($db_connection)
@@ -642,24 +690,27 @@  discard block
 block discarded – undo
642 690
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
643 691
 
644 692
 					$new_errno = mysql_errno($db_connection);
645
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
646
-						break;
693
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
694
+											break;
695
+					}
647 696
 				}
648 697
 
649 698
 				// If it failed again, shucks to be you... we're not trying it over and over.
650
-				if ($ret !== false)
651
-					return $ret;
699
+				if ($ret !== false) {
700
+									return $ret;
701
+				}
652 702
 			}
653 703
 		}
654 704
 		// Are they out of space, perhaps?
655 705
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
656 706
 		{
657
-			if (!isset($txt))
658
-				$query_error .= ' - check database storage space.';
659
-			else
707
+			if (!isset($txt)) {
708
+							$query_error .= ' - check database storage space.';
709
+			} else
660 710
 			{
661
-				if (!isset($txt['mysql_error_space']))
662
-					loadLanguage('Errors');
711
+				if (!isset($txt['mysql_error_space'])) {
712
+									loadLanguage('Errors');
713
+				}
663 714
 
664 715
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
665 716
 			}
@@ -667,15 +718,17 @@  discard block
 block discarded – undo
667 718
 	}
668 719
 
669 720
 	// Nothing's defined yet... just die with it.
670
-	if (empty($context) || empty($txt))
671
-		die($query_error);
721
+	if (empty($context) || empty($txt)) {
722
+			die($query_error);
723
+	}
672 724
 
673 725
 	// Show an error message, if possible.
674 726
 	$context['error_title'] = $txt['database_error'];
675
-	if (allowedTo('admin_forum'))
676
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
677
-	else
678
-		$context['error_message'] = $txt['try_again'];
727
+	if (allowedTo('admin_forum')) {
728
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
729
+	} else {
730
+			$context['error_message'] = $txt['try_again'];
731
+	}
679 732
 
680 733
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
681 734
 	{
@@ -704,25 +757,28 @@  discard block
 block discarded – undo
704 757
 	$connection = $connection === null ? $db_connection : $connection;
705 758
 
706 759
 	// With nothing to insert, simply return.
707
-	if (empty($data))
708
-		return;
760
+	if (empty($data)) {
761
+			return;
762
+	}
709 763
 
710 764
 	// Replace the prefix holder with the actual prefix.
711 765
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
712 766
 
713 767
 	// Inserting data as a single row can be done as a single array.
714
-	if (!is_array($data[array_rand($data)]))
715
-		$data = array($data);
768
+	if (!is_array($data[array_rand($data)])) {
769
+			$data = array($data);
770
+	}
716 771
 
717 772
 	// Create the mold for a single row insert.
718 773
 	$insertData = '(';
719 774
 	foreach ($columns as $columnName => $type)
720 775
 	{
721 776
 		// Are we restricting the length?
722
-		if (strpos($type, 'string-') !== false)
723
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
724
-		else
725
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
777
+		if (strpos($type, 'string-') !== false) {
778
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
779
+		} else {
780
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
781
+		}
726 782
 	}
727 783
 	$insertData = substr($insertData, 0, -2) . ')';
728 784
 
@@ -731,8 +787,9 @@  discard block
 block discarded – undo
731 787
 
732 788
 	// Here's where the variables are injected to the query.
733 789
 	$insertRows = array();
734
-	foreach ($data as $dataRow)
735
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
790
+	foreach ($data as $dataRow) {
791
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
792
+	}
736 793
 
737 794
 	// Determine the method of insertion.
738 795
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -763,8 +820,9 @@  discard block
 block discarded – undo
763 820
  */
764 821
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
765 822
 {
766
-	if (empty($log_message))
767
-		$log_message = $error_message;
823
+	if (empty($log_message)) {
824
+			$log_message = $error_message;
825
+	}
768 826
 
769 827
 	foreach (debug_backtrace() as $step)
770 828
 	{
@@ -783,12 +841,14 @@  discard block
 block discarded – undo
783 841
 	}
784 842
 
785 843
 	// A special case - we want the file and line numbers for debugging.
786
-	if ($error_type == 'return')
787
-		return array($file, $line);
844
+	if ($error_type == 'return') {
845
+			return array($file, $line);
846
+	}
788 847
 
789 848
 	// Is always a critical error.
790
-	if (function_exists('log_error'))
791
-		log_error($log_message, 'critical', $file, $line);
849
+	if (function_exists('log_error')) {
850
+			log_error($log_message, 'critical', $file, $line);
851
+	}
792 852
 
793 853
 	if (function_exists('fatal_error'))
794 854
 	{
@@ -796,12 +856,12 @@  discard block
 block discarded – undo
796 856
 
797 857
 		// Cannot continue...
798 858
 		exit;
859
+	} elseif ($error_type) {
860
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
861
+	} else {
862
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
863
+	}
799 864
 	}
800
-	elseif ($error_type)
801
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
802
-	else
803
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
804
-}
805 865
 
806 866
 /**
807 867
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -818,10 +878,11 @@  discard block
 block discarded – undo
818 878
 		'\\' => '\\\\',
819 879
 	);
820 880
 
821
-	if ($translate_human_wildcards)
822
-		$replacements += array(
881
+	if ($translate_human_wildcards) {
882
+			$replacements += array(
823 883
 			'*' => '%',
824 884
 		);
885
+	}
825 886
 
826 887
 	return strtr($string, $replacements);
827 888
 }
Please login to merge, or discard this patch.
Sources/Register.php 1 patch
Braces   +168 added lines, -122 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
  * Begin the registration process.
@@ -29,19 +30,23 @@  discard block
 block discarded – undo
29 30
 	global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile;
30 31
 
31 32
 	// Is this an incoming AJAX check?
32
-	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck')
33
-		return RegisterCheckUsername();
33
+	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') {
34
+			return RegisterCheckUsername();
35
+	}
34 36
 
35 37
 	// Check if the administrator has it disabled.
36
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3')
37
-		fatal_lang_error('registration_disabled', false);
38
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') {
39
+			fatal_lang_error('registration_disabled', false);
40
+	}
38 41
 
39 42
 	// If this user is an admin - redirect them to the admin registration page.
40
-	if (allowedTo('moderate_forum') && !$user_info['is_guest'])
41
-		redirectexit('action=admin;area=regcenter;sa=register');
43
+	if (allowedTo('moderate_forum') && !$user_info['is_guest']) {
44
+			redirectexit('action=admin;area=regcenter;sa=register');
45
+	}
42 46
 	// You are not a guest, so you are a member - and members don't get to register twice!
43
-	elseif (empty($user_info['is_guest']))
44
-		redirectexit();
47
+	elseif (empty($user_info['is_guest'])) {
48
+			redirectexit();
49
+	}
45 50
 
46 51
 	loadLanguage('Login');
47 52
 	loadTemplate('Register');
@@ -82,16 +87,18 @@  discard block
 block discarded – undo
82 87
 		}
83 88
 	}
84 89
 	// Make sure they don't squeeze through without agreeing.
85
-	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement'])
86
-		$current_step = 1;
90
+	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) {
91
+			$current_step = 1;
92
+	}
87 93
 
88 94
 	// Show the user the right form.
89 95
 	$context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form';
90 96
 	$context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form'];
91 97
 
92 98
 	// Kinda need this.
93
-	if ($context['sub_template'] == 'registration_form')
94
-		loadJavaScriptFile('register.js', array('defer' => false), 'smf_register');
99
+	if ($context['sub_template'] == 'registration_form') {
100
+			loadJavaScriptFile('register.js', array('defer' => false), 'smf_register');
101
+	}
95 102
 
96 103
 	// Add the register chain to the link tree.
97 104
 	$context['linktree'][] = array(
@@ -100,24 +107,26 @@  discard block
 block discarded – undo
100 107
 	);
101 108
 
102 109
 	// Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one.
103
-	if (!isset($_SESSION['register']))
104
-		$_SESSION['register'] = array(
110
+	if (!isset($_SESSION['register'])) {
111
+			$_SESSION['register'] = array(
105 112
 			'timenow' => time(),
106 113
 			'limit' => 10, // minimum number of seconds required on this page for registration
107 114
 		);
108
-	else
109
-		$_SESSION['register']['timenow'] = time();
115
+	} else {
116
+			$_SESSION['register']['timenow'] = time();
117
+	}
110 118
 
111 119
 	// If you have to agree to the agreement, it needs to be fetched from the file.
112 120
 	if ($context['require_agreement'])
113 121
 	{
114 122
 		// Have we got a localized one?
115
-		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt'))
116
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
117
-		elseif (file_exists($boarddir . '/agreement.txt'))
118
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
119
-		else
120
-			$context['agreement'] = '';
123
+		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) {
124
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
125
+		} elseif (file_exists($boarddir . '/agreement.txt')) {
126
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
127
+		} else {
128
+					$context['agreement'] = '';
129
+		}
121 130
 
122 131
 		// Nothing to show, lets disable registration and inform the admin of this error
123 132
 		if (empty($context['agreement']))
@@ -133,8 +142,9 @@  discard block
 block discarded – undo
133 142
 		$selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language'];
134 143
 
135 144
 		// Do we have any languages?
136
-		if (empty($context['languages']))
137
-			getLanguages();
145
+		if (empty($context['languages'])) {
146
+					getLanguages();
147
+		}
138 148
 
139 149
 		// Try to find our selected language.
140 150
 		foreach ($context['languages'] as $key => $lang)
@@ -142,8 +152,9 @@  discard block
 block discarded – undo
142 152
 			$context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => ''));
143 153
 
144 154
 			// Found it!
145
-			if ($selectedLanguage == $lang['filename'])
146
-				$context['languages'][$key]['selected'] = true;
155
+			if ($selectedLanguage == $lang['filename']) {
156
+							$context['languages'][$key]['selected'] = true;
157
+			}
147 158
 		}
148 159
 	}
149 160
 
@@ -167,9 +178,10 @@  discard block
 block discarded – undo
167 178
 		$reg_fields = explode(',', $modSettings['registration_fields']);
168 179
 
169 180
 		// We might have had some submissions on this front - go check.
170
-		foreach ($reg_fields as $field)
171
-			if (isset($_POST[$field]))
181
+		foreach ($reg_fields as $field) {
182
+					if (isset($_POST[$field]))
172 183
 				$cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]);
184
+		}
173 185
 
174 186
 		// Load all the fields in question.
175 187
 		setupProfileContext($reg_fields);
@@ -186,8 +198,9 @@  discard block
 block discarded – undo
186 198
 		$context['visual_verification_id'] = $verificationOptions['id'];
187 199
 	}
188 200
 	// Otherwise we have nothing to show.
189
-	else
190
-		$context['visual_verification'] = false;
201
+	else {
202
+			$context['visual_verification'] = false;
203
+	}
191 204
 
192 205
 
193 206
 	$context += array(
@@ -198,8 +211,9 @@  discard block
 block discarded – undo
198 211
 
199 212
 	// Were there any errors?
200 213
 	$context['registration_errors'] = array();
201
-	if (!empty($reg_errors))
202
-		$context['registration_errors'] = $reg_errors;
214
+	if (!empty($reg_errors)) {
215
+			$context['registration_errors'] = $reg_errors;
216
+	}
203 217
 
204 218
 	createToken('register');
205 219
 }
@@ -216,27 +230,32 @@  discard block
 block discarded – undo
216 230
 	validateToken('register');
217 231
 
218 232
 	// Check to ensure we're forcing SSL for authentication
219
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
220
-		fatal_lang_error('register_ssl_required');
233
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
234
+			fatal_lang_error('register_ssl_required');
235
+	}
221 236
 
222 237
 	// Start collecting together any errors.
223 238
 	$reg_errors = array();
224 239
 
225 240
 	// You can't register if it's disabled.
226
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3)
227
-		fatal_lang_error('registration_disabled', false);
241
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) {
242
+			fatal_lang_error('registration_disabled', false);
243
+	}
228 244
 
229 245
 	// Well, if you don't agree, you can't register.
230
-	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed']))
231
-		redirectexit();
246
+	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) {
247
+			redirectexit();
248
+	}
232 249
 
233 250
 	// Make sure they came from *somewhere*, have a session.
234
-	if (!isset($_SESSION['old_url']))
235
-		redirectexit('action=signup');
251
+	if (!isset($_SESSION['old_url'])) {
252
+			redirectexit('action=signup');
253
+	}
236 254
 
237 255
 	// If we don't require an agreement, we need a extra check for coppa.
238
-	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge']))
239
-		$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
256
+	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) {
257
+			$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
258
+	}
240 259
 	// Are they under age, and under age users are banned?
241 260
 	if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa']))
242 261
 	{
@@ -245,8 +264,9 @@  discard block
 block discarded – undo
245 264
 	}
246 265
 
247 266
 	// Check the time gate for miscreants. First make sure they came from somewhere that actually set it up.
248
-	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit']))
249
-		redirectexit('action=signup');
267
+	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) {
268
+			redirectexit('action=signup');
269
+	}
250 270
 	// Failing that, check the time on it.
251 271
 	if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit'])
252 272
 	{
@@ -266,15 +286,17 @@  discard block
 block discarded – undo
266 286
 		if (is_array($context['visual_verification']))
267 287
 		{
268 288
 			loadLanguage('Errors');
269
-			foreach ($context['visual_verification'] as $error)
270
-				$reg_errors[] = $txt['error_' . $error];
289
+			foreach ($context['visual_verification'] as $error) {
290
+							$reg_errors[] = $txt['error_' . $error];
291
+			}
271 292
 		}
272 293
 	}
273 294
 
274 295
 	foreach ($_POST as $key => $value)
275 296
 	{
276
-		if (!is_array($_POST[$key]))
277
-			$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
297
+		if (!is_array($_POST[$key])) {
298
+					$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
299
+		}
278 300
 	}
279 301
 
280 302
 	// Collect all extra registration fields someone might have filled in.
@@ -304,12 +326,14 @@  discard block
 block discarded – undo
304 326
 		$reg_fields = explode(',', $modSettings['registration_fields']);
305 327
 
306 328
 		// Website is a little different
307
-		if (in_array('website', $reg_fields))
308
-			$possible_strings += array('website_url', 'website_title');
329
+		if (in_array('website', $reg_fields)) {
330
+					$possible_strings += array('website_url', 'website_title');
331
+		}
309 332
 	}
310 333
 
311
-	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '')
312
-		$_POST['secret_answer'] = md5($_POST['secret_answer']);
334
+	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') {
335
+			$_POST['secret_answer'] = md5($_POST['secret_answer']);
336
+	}
313 337
 
314 338
 	// Needed for isReservedName() and registerMember().
315 339
 	require_once($sourcedir . '/Subs-Members.php');
@@ -318,32 +342,37 @@  discard block
 block discarded – undo
318 342
 	if (isset($_POST['real_name']) && (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')))
319 343
 	{
320 344
 		$_POST['real_name'] = 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' : ''), ' ', $_POST['real_name']));
321
-		if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60)
322
-			$possible_strings[] = 'real_name';
345
+		if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) {
346
+					$possible_strings[] = 'real_name';
347
+		}
323 348
 	}
324 349
 
325 350
 	// Handle a string as a birthdate...
326
-	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '')
327
-		$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
351
+	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') {
352
+			$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
353
+	}
328 354
 	// Or birthdate parts...
329
-	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2']))
330
-		$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
355
+	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) {
356
+			$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
357
+	}
331 358
 
332 359
 	// Validate the passed language file.
333 360
 	if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage']))
334 361
 	{
335 362
 		// Do we have any languages?
336
-		if (empty($context['languages']))
337
-			getLanguages();
363
+		if (empty($context['languages'])) {
364
+					getLanguages();
365
+		}
338 366
 
339 367
 		// Did we find it?
340
-		if (isset($context['languages'][$_POST['lngfile']]))
341
-			$_SESSION['language'] = $_POST['lngfile'];
342
-		else
368
+		if (isset($context['languages'][$_POST['lngfile']])) {
369
+					$_SESSION['language'] = $_POST['lngfile'];
370
+		} else {
371
+					unset($_POST['lngfile']);
372
+		}
373
+	} else {
343 374
 			unset($_POST['lngfile']);
344 375
 	}
345
-	else
346
-		unset($_POST['lngfile']);
347 376
 
348 377
 	// Set the options needed for registration.
349 378
 	$regOptions = array(
@@ -363,22 +392,27 @@  discard block
 block discarded – undo
363 392
 	);
364 393
 
365 394
 	// Include the additional options that might have been filled in.
366
-	foreach ($possible_strings as $var)
367
-		if (isset($_POST[$var]))
395
+	foreach ($possible_strings as $var) {
396
+			if (isset($_POST[$var]))
368 397
 			$regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES);
369
-	foreach ($possible_ints as $var)
370
-		if (isset($_POST[$var]))
398
+	}
399
+	foreach ($possible_ints as $var) {
400
+			if (isset($_POST[$var]))
371 401
 			$regOptions['extra_register_vars'][$var] = (int) $_POST[$var];
372
-	foreach ($possible_floats as $var)
373
-		if (isset($_POST[$var]))
402
+	}
403
+	foreach ($possible_floats as $var) {
404
+			if (isset($_POST[$var]))
374 405
 			$regOptions['extra_register_vars'][$var] = (float) $_POST[$var];
375
-	foreach ($possible_bools as $var)
376
-		if (isset($_POST[$var]))
406
+	}
407
+	foreach ($possible_bools as $var) {
408
+			if (isset($_POST[$var]))
377 409
 			$regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1;
410
+	}
378 411
 
379 412
 	// Registration options are always default options...
380
-	if (isset($_POST['default_options']))
381
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
413
+	if (isset($_POST['default_options'])) {
414
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
415
+	}
382 416
 	$regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array();
383 417
 
384 418
 	// Make sure they are clean, dammit!
@@ -398,12 +432,14 @@  discard block
 block discarded – undo
398 432
 	while ($row = $smcFunc['db_fetch_assoc']($request))
399 433
 	{
400 434
 		// Don't allow overriding of the theme variables.
401
-		if (isset($regOptions['theme_vars'][$row['col_name']]))
402
-			unset($regOptions['theme_vars'][$row['col_name']]);
435
+		if (isset($regOptions['theme_vars'][$row['col_name']])) {
436
+					unset($regOptions['theme_vars'][$row['col_name']]);
437
+		}
403 438
 
404 439
 		// Not actually showing it then?
405
-		if (!$row['show_reg'])
406
-			continue;
440
+		if (!$row['show_reg']) {
441
+					continue;
442
+		}
407 443
 
408 444
 		// Prepare the value!
409 445
 		$value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : '';
@@ -412,24 +448,27 @@  discard block
 block discarded – undo
412 448
 		if (!in_array($row['field_type'], array('check', 'select', 'radio')))
413 449
 		{
414 450
 			// Is it too long?
415
-			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value))
416
-				$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
451
+			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) {
452
+							$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
453
+			}
417 454
 
418 455
 			// Any masks to apply?
419 456
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
420 457
 			{
421
-				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
422
-					$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
423
-				elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value))
424
-					$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
425
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
426
-					$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
458
+				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) {
459
+									$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
460
+				} elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) {
461
+									$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
462
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) {
463
+									$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
464
+				}
427 465
 			}
428 466
 		}
429 467
 
430 468
 		// Is this required but not there?
431
-		if (trim($value) == '' && $row['show_reg'] > 1)
432
-			$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
469
+		if (trim($value) == '' && $row['show_reg'] > 1) {
470
+					$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
471
+		}
433 472
 	}
434 473
 	$smcFunc['db_free_result']($request);
435 474
 
@@ -437,8 +476,9 @@  discard block
 block discarded – undo
437 476
 	if (!empty($custom_field_errors))
438 477
 	{
439 478
 		loadLanguage('Errors');
440
-		foreach ($custom_field_errors as $error)
441
-			$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
479
+		foreach ($custom_field_errors as $error) {
480
+					$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
481
+		}
442 482
 	}
443 483
 
444 484
 	// Lets check for other errors before trying to register the member.
@@ -483,8 +523,9 @@  discard block
 block discarded – undo
483 523
 	}
484 524
 
485 525
 	// If COPPA has been selected then things get complicated, setup the template.
486
-	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa']))
487
-		redirectexit('action=coppa;member=' . $memberID);
526
+	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) {
527
+			redirectexit('action=coppa;member=' . $memberID);
528
+	}
488 529
 	// Basic template variable setup.
489 530
 	elseif (!empty($modSettings['registration_method']))
490 531
 	{
@@ -496,8 +537,7 @@  discard block
 block discarded – undo
496 537
 			'sub_template' => 'after',
497 538
 			'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration']
498 539
 		);
499
-	}
500
-	else
540
+	} else
501 541
 	{
502 542
 		call_integration_hook('integrate_activate', array($regOptions['username']));
503 543
 
@@ -517,16 +557,18 @@  discard block
 block discarded – undo
517 557
 	global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info;
518 558
 
519 559
 	// Logged in users should not bother to activate their accounts
520
-	if (!empty($user_info['id']))
521
-		redirectexit();
560
+	if (!empty($user_info['id'])) {
561
+			redirectexit();
562
+	}
522 563
 
523 564
 	loadLanguage('Login');
524 565
 	loadTemplate('Login');
525 566
 
526 567
 	if (empty($_REQUEST['u']) && empty($_POST['user']))
527 568
 	{
528
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3')
529
-			fatal_lang_error('no_access', false);
569
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') {
570
+					fatal_lang_error('no_access', false);
571
+		}
530 572
 
531 573
 		$context['member_id'] = 0;
532 574
 		$context['sub_template'] = 'resend';
@@ -566,11 +608,13 @@  discard block
 block discarded – undo
566 608
 	// Change their email address? (they probably tried a fake one first :P.)
567 609
 	if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2))
568 610
 	{
569
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3)
570
-			fatal_lang_error('no_access', false);
611
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) {
612
+					fatal_lang_error('no_access', false);
613
+		}
571 614
 
572
-		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL))
573
-			fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
615
+		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) {
616
+					fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
617
+		}
574 618
 
575 619
 		// Make sure their email isn't banned.
576 620
 		isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']);
@@ -586,8 +630,9 @@  discard block
 block discarded – undo
586 630
 			)
587 631
 		);
588 632
 
589
-		if ($smcFunc['db_num_rows']($request) != 0)
590
-			fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
633
+		if ($smcFunc['db_num_rows']($request) != 0) {
634
+					fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
635
+		}
591 636
 		$smcFunc['db_free_result']($request);
592 637
 
593 638
 		updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
@@ -625,9 +670,9 @@  discard block
 block discarded – undo
625 670
 	// Quit if this code is not right.
626 671
 	if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code'])
627 672
 	{
628
-		if (!empty($row['is_activated']))
629
-			fatal_lang_error('already_activated', false);
630
-		elseif ($row['validation_code'] == '')
673
+		if (!empty($row['is_activated'])) {
674
+					fatal_lang_error('already_activated', false);
675
+		} elseif ($row['validation_code'] == '')
631 676
 		{
632 677
 			loadLanguage('Profile');
633 678
 			fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false);
@@ -677,8 +722,9 @@  discard block
 block discarded – undo
677 722
 	loadTemplate('Register');
678 723
 
679 724
 	// No User ID??
680
-	if (!isset($_GET['member']))
681
-		fatal_lang_error('no_access', false);
725
+	if (!isset($_GET['member'])) {
726
+			fatal_lang_error('no_access', false);
727
+	}
682 728
 
683 729
 	// Get the user details...
684 730
 	$request = $smcFunc['db_query']('', '
@@ -691,8 +737,9 @@  discard block
 block discarded – undo
691 737
 			'is_coppa' => 5,
692 738
 		)
693 739
 	);
694
-	if ($smcFunc['db_num_rows']($request) == 0)
695
-		fatal_lang_error('no_access', false);
740
+	if ($smcFunc['db_num_rows']($request) == 0) {
741
+			fatal_lang_error('no_access', false);
742
+	}
696 743
 	list ($username) = $smcFunc['db_fetch_row']($request);
697 744
 	$smcFunc['db_free_result']($request);
698 745
 
@@ -730,8 +777,7 @@  discard block
 block discarded – undo
730 777
 			echo $data;
731 778
 			obExit(false);
732 779
 		}
733
-	}
734
-	else
780
+	} else
735 781
 	{
736 782
 		$context += array(
737 783
 			'page_title' => $txt['coppa_title'],
@@ -784,8 +830,9 @@  discard block
 block discarded – undo
784 830
 	{
785 831
 		require_once($sourcedir . '/Subs-Graphics.php');
786 832
 
787
-		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code))
788
-			header('HTTP/1.1 400 Bad Request');
833
+		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) {
834
+					header('HTTP/1.1 400 Bad Request');
835
+		}
789 836
 
790 837
 		// Otherwise just show a pre-defined letter.
791 838
 		elseif (isset($_REQUEST['letter']))
@@ -803,14 +850,13 @@  discard block
 block discarded – undo
803 850
 			header('Content-Type: image/gif');
804 851
 			die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
805 852
 		}
806
-	}
807
-
808
-	elseif ($_REQUEST['format'] === '.wav')
853
+	} elseif ($_REQUEST['format'] === '.wav')
809 854
 	{
810 855
 		require_once($sourcedir . '/Subs-Sound.php');
811 856
 
812
-		if (!createWaveFile($code))
813
-			header('HTTP/1.1 400 Bad Request');
857
+		if (!createWaveFile($code)) {
858
+					header('HTTP/1.1 400 Bad Request');
859
+		}
814 860
 	}
815 861
 
816 862
 	// We all die one day...
Please login to merge, or discard this patch.
Sources/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('Location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManagePermissions.php 1 patch
Braces   +312 added lines, -223 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
  * Dispatches to the right function based on the given subaction.
@@ -176,8 +177,9 @@  discard block
 block discarded – undo
176 177
 		// If it's inherited, just add it as a child.
177 178
 		if ($row['id_parent'] != -2)
178 179
 		{
179
-			if (isset($context['groups'][$row['id_parent']]))
180
-				$context['groups'][$row['id_parent']]['children'][$row['id_group']] = $row['group_name'];
180
+			if (isset($context['groups'][$row['id_parent']])) {
181
+							$context['groups'][$row['id_parent']]['children'][$row['id_group']] = $row['group_name'];
182
+			}
181 183
 			continue;
182 184
 		}
183 185
 
@@ -202,10 +204,11 @@  discard block
 block discarded – undo
202 204
 			'access' => false,
203 205
 		);
204 206
 
205
-		if ($row['min_posts'] == -1)
206
-			$normalGroups[$row['id_group']] = $row['id_group'];
207
-		else
208
-			$postGroups[$row['id_group']] = $row['id_group'];
207
+		if ($row['min_posts'] == -1) {
208
+					$normalGroups[$row['id_group']] = $row['id_group'];
209
+		} else {
210
+					$postGroups[$row['id_group']] = $row['id_group'];
211
+		}
209 212
 	}
210 213
 	$smcFunc['db_free_result']($query);
211 214
 
@@ -221,8 +224,9 @@  discard block
 block discarded – undo
221 224
 				'post_group_list' => $postGroups,
222 225
 			)
223 226
 		);
224
-		while ($row = $smcFunc['db_fetch_assoc']($query))
225
-			$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
227
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
228
+					$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
229
+		}
226 230
 		$smcFunc['db_free_result']($query);
227 231
 	}
228 232
 
@@ -238,8 +242,9 @@  discard block
 block discarded – undo
238 242
 				'normal_group_list' => $normalGroups,
239 243
 			)
240 244
 		);
241
-		while ($row = $smcFunc['db_fetch_assoc']($query))
242
-			$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
245
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
246
+					$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
247
+		}
243 248
 		$smcFunc['db_free_result']($query);
244 249
 
245 250
 		// This one is slower, but it's okay... careful not to count twice!
@@ -256,15 +261,17 @@  discard block
 block discarded – undo
256 261
 				'blank_string' => '',
257 262
 			)
258 263
 		);
259
-		while ($row = $smcFunc['db_fetch_assoc']($query))
260
-			$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
264
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
265
+					$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
266
+		}
261 267
 		$smcFunc['db_free_result']($query);
262 268
 	}
263 269
 
264 270
 	foreach ($context['groups'] as $id => $data)
265 271
 	{
266
-		if ($data['href'] != '')
267
-			$context['groups'][$id]['link'] = '<a href="' . $data['href'] . '">' . $data['num_members'] . '</a>';
272
+		if ($data['href'] != '') {
273
+					$context['groups'][$id]['link'] = '<a href="' . $data['href'] . '">' . $data['num_members'] . '</a>';
274
+		}
268 275
 	}
269 276
 
270 277
 	if (empty($_REQUEST['pid']))
@@ -278,9 +285,10 @@  discard block
 block discarded – undo
278 285
 				'hidden_permissions' => !empty($context['hidden_permissions']) ? $context['hidden_permissions'] : array(),
279 286
 			)
280 287
 		);
281
-		while ($row = $smcFunc['db_fetch_assoc']($request))
282
-			if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1))
288
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
289
+					if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1))
283 290
 				$context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] = $row['num_permissions'];
291
+		}
284 292
 		$smcFunc['db_free_result']($request);
285 293
 
286 294
 		// Get the "default" profile permissions too.
@@ -297,17 +305,18 @@  discard block
 block discarded – undo
297 305
 		);
298 306
 		while ($row = $smcFunc['db_fetch_assoc']($request))
299 307
 		{
300
-			if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1))
301
-				$context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions'];
308
+			if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) {
309
+							$context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions'];
310
+			}
302 311
 		}
303 312
 		$smcFunc['db_free_result']($request);
304
-	}
305
-	else
313
+	} else
306 314
 	{
307 315
 		$_REQUEST['pid'] = (int) $_REQUEST['pid'];
308 316
 
309
-		if (!isset($context['profiles'][$_REQUEST['pid']]))
310
-			fatal_lang_error('no_access', false);
317
+		if (!isset($context['profiles'][$_REQUEST['pid']])) {
318
+					fatal_lang_error('no_access', false);
319
+		}
311 320
 
312 321
 		// Change the selected tab to better reflect that this really is a board profile.
313 322
 		$context[$context['admin_menu_name']]['current_subsection'] = 'profiles';
@@ -323,8 +332,9 @@  discard block
 block discarded – undo
323 332
 		);
324 333
 		while ($row = $smcFunc['db_fetch_assoc']($request))
325 334
 		{
326
-			if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1))
327
-				$context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions'];
335
+			if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) {
336
+							$context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions'];
337
+			}
328 338
 		}
329 339
 		$smcFunc['db_free_result']($request);
330 340
 
@@ -366,8 +376,8 @@  discard block
 block discarded – undo
366 376
 
367 377
 		if (!empty($changes))
368 378
 		{
369
-			foreach ($changes as $profile => $boards)
370
-				$smcFunc['db_query']('', '
379
+			foreach ($changes as $profile => $boards) {
380
+							$smcFunc['db_query']('', '
371 381
 					UPDATE {db_prefix}boards
372 382
 					SET id_profile = {int:current_profile}
373 383
 					WHERE id_board IN ({array_int:board_list})',
@@ -376,6 +386,7 @@  discard block
 block discarded – undo
376 386
 						'current_profile' => $profile,
377 387
 					)
378 388
 				);
389
+			}
379 390
 		}
380 391
 
381 392
 		$context['edit_all'] = false;
@@ -400,8 +411,9 @@  discard block
 block discarded – undo
400 411
 		);
401 412
 		foreach ($boardList[$catid] as $boardid)
402 413
 		{
403
-			if (!isset($context['profiles'][$boards[$boardid]['profile']]))
404
-				$boards[$boardid]['profile'] = 1;
414
+			if (!isset($context['profiles'][$boards[$boardid]['profile']])) {
415
+							$boards[$boardid]['profile'] = 1;
416
+			}
405 417
 
406 418
 			$context['categories'][$catid]['boards'][$boardid] = array(
407 419
 				'id' => &$boards[$boardid]['id'],
@@ -433,64 +445,74 @@  discard block
 block discarded – undo
433 445
 	loadIllegalGuestPermissions();
434 446
 
435 447
 	// Make sure only one of the quick options was selected.
436
-	if ((!empty($_POST['predefined']) && ((isset($_POST['copy_from']) && $_POST['copy_from'] != 'empty') || !empty($_POST['permissions']))) || (!empty($_POST['copy_from']) && $_POST['copy_from'] != 'empty' && !empty($_POST['permissions'])))
437
-		fatal_lang_error('permissions_only_one_option', false);
448
+	if ((!empty($_POST['predefined']) && ((isset($_POST['copy_from']) && $_POST['copy_from'] != 'empty') || !empty($_POST['permissions']))) || (!empty($_POST['copy_from']) && $_POST['copy_from'] != 'empty' && !empty($_POST['permissions']))) {
449
+			fatal_lang_error('permissions_only_one_option', false);
450
+	}
438 451
 
439
-	if (empty($_POST['group']) || !is_array($_POST['group']))
440
-		$_POST['group'] = array();
452
+	if (empty($_POST['group']) || !is_array($_POST['group'])) {
453
+			$_POST['group'] = array();
454
+	}
441 455
 
442 456
 	// Only accept numeric values for selected membergroups.
443
-	foreach ($_POST['group'] as $id => $group_id)
444
-		$_POST['group'][$id] = (int) $group_id;
457
+	foreach ($_POST['group'] as $id => $group_id) {
458
+			$_POST['group'][$id] = (int) $group_id;
459
+	}
445 460
 	$_POST['group'] = array_unique($_POST['group']);
446 461
 
447
-	if (empty($_REQUEST['pid']))
448
-		$_REQUEST['pid'] = 0;
449
-	else
450
-		$_REQUEST['pid'] = (int) $_REQUEST['pid'];
462
+	if (empty($_REQUEST['pid'])) {
463
+			$_REQUEST['pid'] = 0;
464
+	} else {
465
+			$_REQUEST['pid'] = (int) $_REQUEST['pid'];
466
+	}
451 467
 
452 468
 	// Fix up the old global to the new default!
453 469
 	$bid = max(1, $_REQUEST['pid']);
454 470
 
455 471
 	// No modifying the predefined profiles.
456
-	if ($_REQUEST['pid'] > 1 && $_REQUEST['pid'] < 5)
457
-		fatal_lang_error('no_access', false);
472
+	if ($_REQUEST['pid'] > 1 && $_REQUEST['pid'] < 5) {
473
+			fatal_lang_error('no_access', false);
474
+	}
458 475
 
459 476
 	// Clear out any cached authority.
460 477
 	updateSettings(array('settings_updated' => time()));
461 478
 
462 479
 	// No groups where selected.
463
-	if (empty($_POST['group']))
464
-		redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
480
+	if (empty($_POST['group'])) {
481
+			redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
482
+	}
465 483
 
466 484
 	// Set a predefined permission profile.
467 485
 	if (!empty($_POST['predefined']))
468 486
 	{
469 487
 		// Make sure it's a predefined permission set we expect.
470
-		if (!in_array($_POST['predefined'], array('restrict', 'standard', 'moderator', 'maintenance')))
471
-			redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
488
+		if (!in_array($_POST['predefined'], array('restrict', 'standard', 'moderator', 'maintenance'))) {
489
+					redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
490
+		}
472 491
 
473 492
 		foreach ($_POST['group'] as $group_id)
474 493
 		{
475
-			if (!empty($_REQUEST['pid']))
476
-				setPermissionLevel($_POST['predefined'], $group_id, $_REQUEST['pid']);
477
-			else
478
-				setPermissionLevel($_POST['predefined'], $group_id);
494
+			if (!empty($_REQUEST['pid'])) {
495
+							setPermissionLevel($_POST['predefined'], $group_id, $_REQUEST['pid']);
496
+			} else {
497
+							setPermissionLevel($_POST['predefined'], $group_id);
498
+			}
479 499
 		}
480 500
 	}
481 501
 	// Set a permission profile based on the permissions of a selected group.
482 502
 	elseif ($_POST['copy_from'] != 'empty')
483 503
 	{
484 504
 		// Just checking the input.
485
-		if (!is_numeric($_POST['copy_from']))
486
-			redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
505
+		if (!is_numeric($_POST['copy_from'])) {
506
+					redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
507
+		}
487 508
 
488 509
 		// Make sure the group we're copying to is never included.
489 510
 		$_POST['group'] = array_diff($_POST['group'], array($_POST['copy_from']));
490 511
 
491 512
 		// No groups left? Too bad.
492
-		if (empty($_POST['group']))
493
-			redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
513
+		if (empty($_POST['group'])) {
514
+					redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
515
+		}
494 516
 
495 517
 		if (empty($_REQUEST['pid']))
496 518
 		{
@@ -504,22 +526,26 @@  discard block
 block discarded – undo
504 526
 				)
505 527
 			);
506 528
 			$target_perm = array();
507
-			while ($row = $smcFunc['db_fetch_assoc']($request))
508
-				$target_perm[$row['permission']] = $row['add_deny'];
529
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
530
+							$target_perm[$row['permission']] = $row['add_deny'];
531
+			}
509 532
 			$smcFunc['db_free_result']($request);
510 533
 
511 534
 			$inserts = array();
512
-			foreach ($_POST['group'] as $group_id)
513
-				foreach ($target_perm as $perm => $add_deny)
535
+			foreach ($_POST['group'] as $group_id) {
536
+							foreach ($target_perm as $perm => $add_deny)
514 537
 				{
515 538
 					// No dodgy permissions please!
516 539
 					if (!empty($context['illegal_permissions']) && in_array($perm, $context['illegal_permissions']))
517 540
 						continue;
518
-					if ($group_id == -1 && in_array($perm, $context['non_guest_permissions']))
519
-						continue;
541
+			}
542
+					if ($group_id == -1 && in_array($perm, $context['non_guest_permissions'])) {
543
+											continue;
544
+					}
520 545
 
521
-					if ($group_id != 1 && $group_id != 3)
522
-						$inserts[] = array($perm, $group_id, $add_deny);
546
+					if ($group_id != 1 && $group_id != 3) {
547
+											$inserts[] = array($perm, $group_id, $add_deny);
548
+					}
523 549
 				}
524 550
 
525 551
 			// Delete the previous permissions...
@@ -559,17 +585,19 @@  discard block
 block discarded – undo
559 585
 			)
560 586
 		);
561 587
 		$target_perm = array();
562
-		while ($row = $smcFunc['db_fetch_assoc']($request))
563
-			$target_perm[$row['permission']] = $row['add_deny'];
588
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
589
+					$target_perm[$row['permission']] = $row['add_deny'];
590
+		}
564 591
 		$smcFunc['db_free_result']($request);
565 592
 
566 593
 		$inserts = array();
567
-		foreach ($_POST['group'] as $group_id)
568
-			foreach ($target_perm as $perm => $add_deny)
594
+		foreach ($_POST['group'] as $group_id) {
595
+					foreach ($target_perm as $perm => $add_deny)
569 596
 			{
570 597
 				// Are these for guests?
571 598
 				if ($group_id == -1 && in_array($perm, $context['non_guest_permissions']))
572 599
 					continue;
600
+		}
573 601
 
574 602
 				$inserts[] = array($perm, $group_id, $bid, $add_deny);
575 603
 			}
@@ -607,13 +635,14 @@  discard block
 block discarded – undo
607 635
 		list ($permissionType, $permission) = explode('/', $_POST['permissions']);
608 636
 
609 637
 		// Check whether our input is within expected range.
610
-		if (!in_array($_POST['add_remove'], array('add', 'clear', 'deny')) || !in_array($permissionType, array('membergroup', 'board')))
611
-			redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
638
+		if (!in_array($_POST['add_remove'], array('add', 'clear', 'deny')) || !in_array($permissionType, array('membergroup', 'board'))) {
639
+					redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
640
+		}
612 641
 
613 642
 		if ($_POST['add_remove'] == 'clear')
614 643
 		{
615
-			if ($permissionType == 'membergroup')
616
-				$smcFunc['db_query']('', '
644
+			if ($permissionType == 'membergroup') {
645
+							$smcFunc['db_query']('', '
617 646
 					DELETE FROM {db_prefix}permissions
618 647
 					WHERE id_group IN ({array_int:current_group_list})
619 648
 						AND permission = {string:current_permission}
@@ -624,8 +653,8 @@  discard block
 block discarded – undo
624 653
 						'illegal_permissions' => !empty($context['illegal_permissions']) ? $context['illegal_permissions'] : array(),
625 654
 					)
626 655
 				);
627
-			else
628
-				$smcFunc['db_query']('', '
656
+			} else {
657
+							$smcFunc['db_query']('', '
629 658
 					DELETE FROM {db_prefix}board_permissions
630 659
 					WHERE id_group IN ({array_int:current_group_list})
631 660
 						AND id_profile = {int:current_profile}
@@ -636,6 +665,7 @@  discard block
 block discarded – undo
636 665
 						'current_permission' => $permission,
637 666
 					)
638 667
 				);
668
+			}
639 669
 		}
640 670
 		// Add a permission (either 'set' or 'deny').
641 671
 		else
@@ -644,32 +674,36 @@  discard block
 block discarded – undo
644 674
 			$permChange = array();
645 675
 			foreach ($_POST['group'] as $groupID)
646 676
 			{
647
-				if ($groupID == -1 && in_array($permission, $context['non_guest_permissions']))
648
-					continue;
677
+				if ($groupID == -1 && in_array($permission, $context['non_guest_permissions'])) {
678
+									continue;
679
+				}
649 680
 
650
-				if ($permissionType == 'membergroup' && $groupID != 1 && $groupID != 3 && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions'])))
651
-					$permChange[] = array($permission, $groupID, $add_deny);
652
-				elseif ($permissionType != 'membergroup')
653
-					$permChange[] = array($permission, $groupID, $bid, $add_deny);
681
+				if ($permissionType == 'membergroup' && $groupID != 1 && $groupID != 3 && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions']))) {
682
+									$permChange[] = array($permission, $groupID, $add_deny);
683
+				} elseif ($permissionType != 'membergroup') {
684
+									$permChange[] = array($permission, $groupID, $bid, $add_deny);
685
+				}
654 686
 			}
655 687
 
656 688
 			if (!empty($permChange))
657 689
 			{
658
-				if ($permissionType == 'membergroup')
659
-					$smcFunc['db_insert']('replace',
690
+				if ($permissionType == 'membergroup') {
691
+									$smcFunc['db_insert']('replace',
660 692
 						'{db_prefix}permissions',
661 693
 						array('permission' => 'string', 'id_group' => 'int', 'add_deny' => 'int'),
662 694
 						$permChange,
663 695
 						array('permission', 'id_group')
664 696
 					);
697
+				}
665 698
 				// Board permissions go into the other table.
666
-				else
667
-					$smcFunc['db_insert']('replace',
699
+				else {
700
+									$smcFunc['db_insert']('replace',
668 701
 						'{db_prefix}board_permissions',
669 702
 						array('permission' => 'string', 'id_group' => 'int', 'id_profile' => 'int', 'add_deny' => 'int'),
670 703
 						$permChange,
671 704
 						array('permission', 'id_group', 'id_profile')
672 705
 					);
706
+				}
673 707
 			}
674 708
 		}
675 709
 
@@ -687,14 +721,16 @@  discard block
 block discarded – undo
687 721
 {
688 722
 	global $context, $txt, $smcFunc, $modSettings;
689 723
 
690
-	if (!isset($_GET['group']))
691
-		fatal_lang_error('no_access', false);
724
+	if (!isset($_GET['group'])) {
725
+			fatal_lang_error('no_access', false);
726
+	}
692 727
 
693 728
 	$context['group']['id'] = (int) $_GET['group'];
694 729
 
695 730
 	// It's not likely you'd end up here with this setting disabled.
696
-	if ($_GET['group'] == 1)
697
-		redirectexit('action=admin;area=permissions');
731
+	if ($_GET['group'] == 1) {
732
+			redirectexit('action=admin;area=permissions');
733
+	}
698 734
 
699 735
 	loadAllPermissions();
700 736
 	loadPermissionProfiles();
@@ -715,13 +751,14 @@  discard block
 block discarded – undo
715 751
 		$smcFunc['db_free_result']($result);
716 752
 
717 753
 		// Cannot edit an inherited group!
718
-		if ($parent != -2)
719
-			fatal_lang_error('cannot_edit_permissions_inherited');
754
+		if ($parent != -2) {
755
+					fatal_lang_error('cannot_edit_permissions_inherited');
756
+		}
757
+	} elseif ($context['group']['id'] == -1) {
758
+			$context['group']['name'] = $txt['membergroups_guests'];
759
+	} else {
760
+			$context['group']['name'] = $txt['membergroups_members'];
720 761
 	}
721
-	elseif ($context['group']['id'] == -1)
722
-		$context['group']['name'] = $txt['membergroups_guests'];
723
-	else
724
-		$context['group']['name'] = $txt['membergroups_members'];
725 762
 
726 763
 	$context['profile']['id'] = empty($_GET['pid']) ? 0 : (int) $_GET['pid'];
727 764
 
@@ -767,8 +804,9 @@  discard block
 block discarded – undo
767 804
 				'current_group' => $_GET['group'],
768 805
 			)
769 806
 		);
770
-		while ($row = $smcFunc['db_fetch_assoc']($result))
771
-			$permissions['membergroup'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission'];
807
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
808
+					$permissions['membergroup'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission'];
809
+		}
772 810
 		$smcFunc['db_free_result']($result);
773 811
 	}
774 812
 
@@ -783,8 +821,9 @@  discard block
 block discarded – undo
783 821
 			'current_profile' => $context['permission_type'] == 'membergroup' ? 1 : $context['profile']['id'],
784 822
 		)
785 823
 	);
786
-	while ($row = $smcFunc['db_fetch_assoc']($result))
787
-		$permissions['board'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission'];
824
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
825
+			$permissions['board'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission'];
826
+	}
788 827
 	$smcFunc['db_free_result']($result);
789 828
 
790 829
 	// Loop through each permission and set whether it's checked.
@@ -803,9 +842,9 @@  discard block
 block discarded – undo
803 842
 					{
804 843
 						$curPerm['any']['select'] = in_array($perm['id'] . '_any', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_any', $permissions[$permissionType]['denied']) ? 'deny' : 'off');
805 844
 						$curPerm['own']['select'] = in_array($perm['id'] . '_own', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_own', $permissions[$permissionType]['denied']) ? 'deny' : 'off');
845
+					} else {
846
+											$curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'deny' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off');
806 847
 					}
807
-					else
808
-						$curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'deny' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off');
809 848
 
810 849
 						// Keep the last value if it's hidden.
811 850
 						if ($perm['hidden'] || $permissionArray['hidden'])
@@ -822,13 +861,13 @@  discard block
 block discarded – undo
822 861
 									$perm['any']['id'],
823 862
 									$curPerm['any']['select'] == 'deny' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $curPerm['any']['select'],
824 863
 								);
825
-							}
826
-							else
827
-								$context['hidden_perms'][] = array(
864
+							} else {
865
+															$context['hidden_perms'][] = array(
828 866
 									$permissionType,
829 867
 									$perm['id'],
830 868
 									$curPerm['select'] == 'deny' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $curPerm['select'],
831 869
 								);
870
+							}
832 871
 						}
833 872
 				}
834 873
 			}
@@ -856,13 +895,14 @@  discard block
 block discarded – undo
856 895
 	$_GET['pid'] = (int) $_GET['pid'];
857 896
 
858 897
 	// Cannot modify predefined profiles.
859
-	if ($_GET['pid'] > 1 && $_GET['pid'] < 5)
860
-		fatal_lang_error('no_access', false);
898
+	if ($_GET['pid'] > 1 && $_GET['pid'] < 5) {
899
+			fatal_lang_error('no_access', false);
900
+	}
861 901
 
862 902
 	// Verify this isn't inherited.
863
-	if ($_GET['group'] == -1 || $_GET['group'] == 0)
864
-		$parent = -2;
865
-	else
903
+	if ($_GET['group'] == -1 || $_GET['group'] == 0) {
904
+			$parent = -2;
905
+	} else
866 906
 	{
867 907
 		$result = $smcFunc['db_query']('', '
868 908
 			SELECT id_parent
@@ -877,8 +917,9 @@  discard block
 block discarded – undo
877 917
 		$smcFunc['db_free_result']($result);
878 918
 	}
879 919
 
880
-	if ($parent != -2)
881
-		fatal_lang_error('cannot_edit_permissions_inherited');
920
+	if ($parent != -2) {
921
+			fatal_lang_error('cannot_edit_permissions_inherited');
922
+	}
882 923
 
883 924
 	$givePerms = array('membergroup' => array(), 'board' => array());
884 925
 
@@ -896,12 +937,13 @@  discard block
 block discarded – undo
896 937
 		{
897 938
 			if (is_array($perm_array))
898 939
 			{
899
-				foreach ($perm_array as $permission => $value)
900
-					if ($value == 'on' || $value == 'deny')
940
+				foreach ($perm_array as $permission => $value) {
941
+									if ($value == 'on' || $value == 'deny')
901 942
 					{
902 943
 						// Don't allow people to escalate themselves!
903 944
 						if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions']))
904 945
 							continue;
946
+				}
905 947
 
906 948
 						$givePerms[$perm_type][] = array($_GET['group'], $permission, $value == 'deny' ? 0 : 1);
907 949
 					}
@@ -946,8 +988,9 @@  discard block
 block discarded – undo
946 988
 	);
947 989
 	if (!empty($givePerms['board']))
948 990
 	{
949
-		foreach ($givePerms['board'] as $k => $v)
950
-			$givePerms['board'][$k][] = $profileid;
991
+		foreach ($givePerms['board'] as $k => $v) {
992
+					$givePerms['board'][$k][] = $profileid;
993
+		}
951 994
 		$smcFunc['db_insert']('replace',
952 995
 			'{db_prefix}board_permissions',
953 996
 			array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int', 'id_profile' => 'int'),
@@ -988,8 +1031,9 @@  discard block
 block discarded – undo
988 1031
 
989 1032
 	call_integration_hook('integrate_modify_permission_settings', array(&$config_vars));
990 1033
 
991
-	if ($return_config)
992
-		return $config_vars;
1034
+	if ($return_config) {
1035
+			return $config_vars;
1036
+	}
993 1037
 
994 1038
 	$context['page_title'] = $txt['permission_settings_title'];
995 1039
 	$context['sub_template'] = 'show_settings';
@@ -1040,8 +1084,9 @@  discard block
 block discarded – undo
1040 1084
 					'min_posts' => -1,
1041 1085
 				)
1042 1086
 			);
1043
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1044
-				$post_groups[] = $row['id_group'];
1087
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1088
+							$post_groups[] = $row['id_group'];
1089
+			}
1045 1090
 			$smcFunc['db_free_result']($request);
1046 1091
 
1047 1092
 			// Remove'em.
@@ -1250,16 +1295,19 @@  discard block
 block discarded – undo
1250 1295
 	// Make sure we're not granting someone too many permissions!
1251 1296
 	foreach ($groupLevels['global'][$level] as $k => $permission)
1252 1297
 	{
1253
-		if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions']))
1254
-			unset($groupLevels['global'][$level][$k]);
1298
+		if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions'])) {
1299
+					unset($groupLevels['global'][$level][$k]);
1300
+		}
1255 1301
 
1256
-		if ($group == -1 && in_array($permission, $context['non_guest_permissions']))
1257
-			unset($groupLevels['global'][$level][$k]);
1302
+		if ($group == -1 && in_array($permission, $context['non_guest_permissions'])) {
1303
+					unset($groupLevels['global'][$level][$k]);
1304
+		}
1258 1305
 	}
1259
-	if ($group == -1)
1260
-		foreach ($groupLevels['board'][$level] as $k => $permission)
1306
+	if ($group == -1) {
1307
+			foreach ($groupLevels['board'][$level] as $k => $permission)
1261 1308
 			if (in_array($permission, $context['non_guest_permissions']))
1262 1309
 				unset($groupLevels['board'][$level][$k]);
1310
+	}
1263 1311
 
1264 1312
 	// Reset all cached permissions.
1265 1313
 	updateSettings(array('settings_updated' => time()));
@@ -1269,8 +1317,9 @@  discard block
 block discarded – undo
1269 1317
 	{
1270 1318
 		$group = (int) $group;
1271 1319
 
1272
-		if (empty($groupLevels['global'][$level]))
1273
-			return;
1320
+		if (empty($groupLevels['global'][$level])) {
1321
+					return;
1322
+		}
1274 1323
 
1275 1324
 		$smcFunc['db_query']('', '
1276 1325
 			DELETE FROM {db_prefix}permissions
@@ -1292,8 +1341,9 @@  discard block
 block discarded – undo
1292 1341
 		);
1293 1342
 
1294 1343
 		$groupInserts = array();
1295
-		foreach ($groupLevels['global'][$level] as $permission)
1296
-			$groupInserts[] = array($group, $permission);
1344
+		foreach ($groupLevels['global'][$level] as $permission) {
1345
+					$groupInserts[] = array($group, $permission);
1346
+		}
1297 1347
 
1298 1348
 		$smcFunc['db_insert']('insert',
1299 1349
 			'{db_prefix}permissions',
@@ -1303,8 +1353,9 @@  discard block
 block discarded – undo
1303 1353
 		);
1304 1354
 
1305 1355
 		$boardInserts = array();
1306
-		foreach ($groupLevels['board'][$level] as $permission)
1307
-			$boardInserts[] = array(1, $group, $permission);
1356
+		foreach ($groupLevels['board'][$level] as $permission) {
1357
+					$boardInserts[] = array(1, $group, $permission);
1358
+		}
1308 1359
 
1309 1360
 		$smcFunc['db_insert']('insert',
1310 1361
 			'{db_prefix}board_permissions',
@@ -1335,8 +1386,9 @@  discard block
 block discarded – undo
1335 1386
 		if (!empty($groupLevels['board'][$level]))
1336 1387
 		{
1337 1388
 			$boardInserts = array();
1338
-			foreach ($groupLevels['board'][$level] as $permission)
1339
-				$boardInserts[] = array($profile, $group, $permission);
1389
+			foreach ($groupLevels['board'][$level] as $permission) {
1390
+							$boardInserts[] = array($profile, $group, $permission);
1391
+			}
1340 1392
 
1341 1393
 			$smcFunc['db_insert']('insert',
1342 1394
 				'{db_prefix}board_permissions',
@@ -1359,8 +1411,9 @@  discard block
 block discarded – undo
1359 1411
 			)
1360 1412
 		);
1361 1413
 
1362
-		if (empty($boardLevels[$level]))
1363
-			return;
1414
+		if (empty($boardLevels[$level])) {
1415
+					return;
1416
+		}
1364 1417
 
1365 1418
 		// Get all the groups...
1366 1419
 		$query = $smcFunc['db_query']('', '
@@ -1378,8 +1431,9 @@  discard block
 block discarded – undo
1378 1431
 			$group = $row[0];
1379 1432
 
1380 1433
 			$boardInserts = array();
1381
-			foreach ($boardLevels[$level] as $permission)
1382
-				$boardInserts[] = array($profile, $group, $permission);
1434
+			foreach ($boardLevels[$level] as $permission) {
1435
+							$boardInserts[] = array($profile, $group, $permission);
1436
+			}
1383 1437
 
1384 1438
 			$smcFunc['db_insert']('insert',
1385 1439
 				'{db_prefix}board_permissions',
@@ -1392,8 +1446,9 @@  discard block
 block discarded – undo
1392 1446
 
1393 1447
 		// Add permissions for ungrouped members.
1394 1448
 		$boardInserts = array();
1395
-		foreach ($boardLevels[$level] as $permission)
1396
-			$boardInserts[] = array($profile, 0, $permission);
1449
+		foreach ($boardLevels[$level] as $permission) {
1450
+					$boardInserts[] = array($profile, 0, $permission);
1451
+		}
1397 1452
 
1398 1453
 		$smcFunc['db_insert']('insert',
1399 1454
 				'{db_prefix}board_permissions',
@@ -1403,9 +1458,10 @@  discard block
 block discarded – undo
1403 1458
 			);
1404 1459
 	}
1405 1460
 	// $profile and $group are both null!
1406
-	else
1407
-		fatal_lang_error('no_access', false);
1408
-}
1461
+	else {
1462
+			fatal_lang_error('no_access', false);
1463
+	}
1464
+	}
1409 1465
 
1410 1466
 /**
1411 1467
  * Load permissions into $context['permissions'].
@@ -1607,15 +1663,17 @@  discard block
 block discarded – undo
1607 1663
 		foreach ($permissionList as $permission => $permissionArray)
1608 1664
 		{
1609 1665
 			// If this is a guest permission we don't do it if it's the guest group.
1610
-			if (isset($context['group']['id']) && $context['group']['id'] == -1 && in_array($permission, $context['non_guest_permissions']))
1611
-				continue;
1666
+			if (isset($context['group']['id']) && $context['group']['id'] == -1 && in_array($permission, $context['non_guest_permissions'])) {
1667
+							continue;
1668
+			}
1612 1669
 
1613 1670
 			// What groups will this permission be in?
1614 1671
 			$own_group = $permissionArray[1];
1615 1672
 
1616 1673
 			// First, Do these groups actually exist - if not add them.
1617
-			if (!isset($permissionGroups[$permissionType][$own_group]))
1618
-				$permissionGroups[$permissionType][$own_group] = true;
1674
+			if (!isset($permissionGroups[$permissionType][$own_group])) {
1675
+							$permissionGroups[$permissionType][$own_group] = true;
1676
+			}
1619 1677
 
1620 1678
 			// What column should this be located into?
1621 1679
 			$position = !in_array($own_group, $leftPermissionGroups) ? 1 : 0;
@@ -1623,8 +1681,8 @@  discard block
 block discarded – undo
1623 1681
 			// If the groups have not yet been created be sure to create them.
1624 1682
 			$bothGroups = array('own' => $own_group);
1625 1683
 
1626
-			foreach ($bothGroups as $group)
1627
-				if (!isset($context['permissions'][$permissionType]['columns'][$position][$group]))
1684
+			foreach ($bothGroups as $group) {
1685
+							if (!isset($context['permissions'][$permissionType]['columns'][$position][$group]))
1628 1686
 					$context['permissions'][$permissionType]['columns'][$position][$group] = array(
1629 1687
 						'type' => $permissionType,
1630 1688
 						'id' => $group,
@@ -1634,6 +1692,7 @@  discard block
 block discarded – undo
1634 1692
 						'hidden' => false,
1635 1693
 						'permissions' => array()
1636 1694
 					);
1695
+			}
1637 1696
 
1638 1697
 			$context['permissions'][$permissionType]['columns'][$position][$own_group]['permissions'][$permission] = array(
1639 1698
 				'id' => $permission,
@@ -1658,27 +1717,30 @@  discard block
 block discarded – undo
1658 1717
 				{
1659 1718
 					$context['hidden_permissions'][] = $permission . '_own';
1660 1719
 					$context['hidden_permissions'][] = $permission . '_any';
1720
+				} else {
1721
+									$context['hidden_permissions'][] = $permission;
1661 1722
 				}
1662
-				else
1663
-					$context['hidden_permissions'][] = $permission;
1664 1723
 			}
1665 1724
 		}
1666 1725
 		ksort($context['permissions'][$permissionType]['columns']);
1667 1726
 
1668 1727
 		// Check we don't leave any empty groups - and mark hidden ones as such.
1669
-		foreach ($context['permissions'][$permissionType]['columns'] as $column => $groups)
1670
-			foreach ($groups as $id => $group)
1728
+		foreach ($context['permissions'][$permissionType]['columns'] as $column => $groups) {
1729
+					foreach ($groups as $id => $group)
1671 1730
 			{
1672 1731
 				if (empty($group['permissions']))
1673 1732
 					unset($context['permissions'][$permissionType]['columns'][$column][$id]);
1733
+		}
1674 1734
 				else
1675 1735
 				{
1676 1736
 					$foundNonHidden = false;
1677
-					foreach ($group['permissions'] as $permission)
1678
-						if (empty($permission['hidden']))
1737
+					foreach ($group['permissions'] as $permission) {
1738
+											if (empty($permission['hidden']))
1679 1739
 							$foundNonHidden = true;
1680
-					if (!$foundNonHidden)
1681
-						$context['permissions'][$permissionType]['columns'][$column][$id]['hidden'] = true;
1740
+					}
1741
+					if (!$foundNonHidden) {
1742
+											$context['permissions'][$permissionType]['columns'][$column][$id]['hidden'] = true;
1743
+					}
1682 1744
 				}
1683 1745
 			}
1684 1746
 	}
@@ -1705,12 +1767,13 @@  discard block
 block discarded – undo
1705 1767
 	$context['can_change_permissions'] = allowedTo('manage_permissions');
1706 1768
 
1707 1769
 	// Nothing to initialize here.
1708
-	if (!$context['can_change_permissions'])
1709
-		return;
1770
+	if (!$context['can_change_permissions']) {
1771
+			return;
1772
+	}
1710 1773
 
1711 1774
 	// Load the permission settings for guests
1712
-	foreach ($permissions as $permission)
1713
-		$context[$permission] = array(
1775
+	foreach ($permissions as $permission) {
1776
+			$context[$permission] = array(
1714 1777
 			-1 => array(
1715 1778
 				'id' => -1,
1716 1779
 				'name' => $txt['membergroups_guests'],
@@ -1724,6 +1787,7 @@  discard block
 block discarded – undo
1724 1787
 				'status' => 'off',
1725 1788
 			),
1726 1789
 		);
1790
+	}
1727 1791
 
1728 1792
 	$request = $smcFunc['db_query']('', '
1729 1793
 		SELECT id_group, CASE WHEN add_deny = {int:denied} THEN {string:deny} ELSE {string:on} END AS status, permission
@@ -1737,8 +1801,9 @@  discard block
 block discarded – undo
1737 1801
 			'on' => 'on',
1738 1802
 		)
1739 1803
 	);
1740
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1741
-		$context[$row['permission']][$row['id_group']]['status'] = $row['status'];
1804
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1805
+			$context[$row['permission']][$row['id_group']]['status'] = $row['status'];
1806
+	}
1742 1807
 	$smcFunc['db_free_result']($request);
1743 1808
 
1744 1809
 	$request = $smcFunc['db_query']('', '
@@ -1759,14 +1824,15 @@  discard block
 block discarded – undo
1759 1824
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1760 1825
 	{
1761 1826
 		// Initialize each permission as being 'off' until proven otherwise.
1762
-		foreach ($permissions as $permission)
1763
-			if (!isset($context[$permission][$row['id_group']]))
1827
+		foreach ($permissions as $permission) {
1828
+					if (!isset($context[$permission][$row['id_group']]))
1764 1829
 				$context[$permission][$row['id_group']] = array(
1765 1830
 					'id' => $row['id_group'],
1766 1831
 					'name' => $row['group_name'],
1767 1832
 					'is_postgroup' => $row['min_posts'] != -1,
1768 1833
 					'status' => 'off',
1769 1834
 				);
1835
+		}
1770 1836
 
1771 1837
 		$context[$row['permission']][$row['id_group']]['status'] = empty($row['status']) ? 'deny' : ($row['status'] == 1 ? 'on' : 'off');
1772 1838
 	}
@@ -1780,8 +1846,9 @@  discard block
 block discarded – undo
1780 1846
 	{
1781 1847
 		foreach ($permissions as $permission)
1782 1848
 		{
1783
-			if (isset($context[$permission][$group]))
1784
-				unset($context[$permission][$group]);
1849
+			if (isset($context[$permission][$group])) {
1850
+							unset($context[$permission][$group]);
1851
+			}
1785 1852
 		}
1786 1853
 	}
1787 1854
 
@@ -1789,8 +1856,9 @@  discard block
 block discarded – undo
1789 1856
 	$non_guest_perms = array_intersect(str_replace(array('_any', '_own'), '', $permissions), $context['non_guest_permissions']);
1790 1857
 	foreach ($non_guest_perms as $permission)
1791 1858
 	{
1792
-		if (isset($context[$permission][-1]))
1793
-			unset($context[$permission][-1]);
1859
+		if (isset($context[$permission][-1])) {
1860
+					unset($context[$permission][-1]);
1861
+		}
1794 1862
 	}
1795 1863
 
1796 1864
 	// Create the token for the separate inline permission verification.
@@ -1825,8 +1893,9 @@  discard block
 block discarded – undo
1825 1893
 	global $context, $smcFunc;
1826 1894
 
1827 1895
 	// No permissions? Not a great deal to do here.
1828
-	if (!allowedTo('manage_permissions'))
1829
-		return;
1896
+	if (!allowedTo('manage_permissions')) {
1897
+			return;
1898
+	}
1830 1899
 
1831 1900
 	// Almighty session check, verify our ways.
1832 1901
 	checkSession();
@@ -1838,13 +1907,15 @@  discard block
 block discarded – undo
1838 1907
 	$insertRows = array();
1839 1908
 	foreach ($permissions as $permission)
1840 1909
 	{
1841
-		if (!isset($_POST[$permission]))
1842
-			continue;
1910
+		if (!isset($_POST[$permission])) {
1911
+					continue;
1912
+		}
1843 1913
 
1844 1914
 		foreach ($_POST[$permission] as $id_group => $value)
1845 1915
 		{
1846
-			if (in_array($value, array('on', 'deny')) && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions'])))
1847
-				$insertRows[] = array((int) $id_group, $permission, $value == 'on' ? 1 : 0);
1916
+			if (in_array($value, array('on', 'deny')) && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions']))) {
1917
+							$insertRows[] = array((int) $id_group, $permission, $value == 'on' ? 1 : 0);
1918
+			}
1848 1919
 		}
1849 1920
 	}
1850 1921
 
@@ -1860,13 +1931,14 @@  discard block
 block discarded – undo
1860 1931
 	);
1861 1932
 
1862 1933
 	// ...and replace them with new ones.
1863
-	if (!empty($insertRows))
1864
-		$smcFunc['db_insert']('insert',
1934
+	if (!empty($insertRows)) {
1935
+			$smcFunc['db_insert']('insert',
1865 1936
 			'{db_prefix}permissions',
1866 1937
 			array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
1867 1938
 			$insertRows,
1868 1939
 			array('id_group', 'permission')
1869 1940
 		);
1941
+	}
1870 1942
 
1871 1943
 	// Do a full child update.
1872 1944
 	updateChildPermissions(array(), -1);
@@ -1893,10 +1965,11 @@  discard block
 block discarded – undo
1893 1965
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1894 1966
 	{
1895 1967
 		// Format the label nicely.
1896
-		if (isset($txt['permissions_profile_' . $row['profile_name']]))
1897
-			$name = $txt['permissions_profile_' . $row['profile_name']];
1898
-		else
1899
-			$name = $row['profile_name'];
1968
+		if (isset($txt['permissions_profile_' . $row['profile_name']])) {
1969
+					$name = $txt['permissions_profile_' . $row['profile_name']];
1970
+		} else {
1971
+					$name = $row['profile_name'];
1972
+		}
1900 1973
 
1901 1974
 		$context['profiles'][$row['id_profile']] = array(
1902 1975
 			'id' => $row['id_profile'],
@@ -1951,17 +2024,19 @@  discard block
 block discarded – undo
1951 2024
 			)
1952 2025
 		);
1953 2026
 		$inserts = array();
1954
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1955
-			$inserts[] = array($profile_id, $row['id_group'], $row['permission'], $row['add_deny']);
2027
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2028
+					$inserts[] = array($profile_id, $row['id_group'], $row['permission'], $row['add_deny']);
2029
+		}
1956 2030
 		$smcFunc['db_free_result']($request);
1957 2031
 
1958
-		if (!empty($inserts))
1959
-			$smcFunc['db_insert']('insert',
2032
+		if (!empty($inserts)) {
2033
+					$smcFunc['db_insert']('insert',
1960 2034
 				'{db_prefix}board_permissions',
1961 2035
 				array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
1962 2036
 				$inserts,
1963 2037
 				array('id_profile', 'id_group', 'permission')
1964 2038
 			);
2039
+		}
1965 2040
 	}
1966 2041
 	// Renaming?
1967 2042
 	elseif (isset($_POST['rename']))
@@ -1970,16 +2045,16 @@  discard block
 block discarded – undo
1970 2045
 		validateToken('admin-mpp');
1971 2046
 
1972 2047
 		// Just showing the boxes?
1973
-		if (!isset($_POST['rename_profile']))
1974
-			$context['show_rename_boxes'] = true;
1975
-		else
2048
+		if (!isset($_POST['rename_profile'])) {
2049
+					$context['show_rename_boxes'] = true;
2050
+		} else
1976 2051
 		{
1977 2052
 			foreach ($_POST['rename_profile'] as $id => $value)
1978 2053
 			{
1979 2054
 				$value = $smcFunc['htmlspecialchars']($value);
1980 2055
 
1981
-				if (trim($value) != '' && $id > 4)
1982
-					$smcFunc['db_query']('', '
2056
+				if (trim($value) != '' && $id > 4) {
2057
+									$smcFunc['db_query']('', '
1983 2058
 						UPDATE {db_prefix}permission_profiles
1984 2059
 						SET profile_name = {string:profile_name}
1985 2060
 						WHERE id_profile = {int:current_profile}',
@@ -1988,6 +2063,7 @@  discard block
 block discarded – undo
1988 2063
 							'profile_name' => $value,
1989 2064
 						)
1990 2065
 					);
2066
+				}
1991 2067
 			}
1992 2068
 		}
1993 2069
 	}
@@ -1998,9 +2074,10 @@  discard block
 block discarded – undo
1998 2074
 		validateToken('admin-mpp');
1999 2075
 
2000 2076
 		$profiles = array();
2001
-		foreach ($_POST['delete_profile'] as $profile)
2002
-			if ($profile > 4)
2077
+		foreach ($_POST['delete_profile'] as $profile) {
2078
+					if ($profile > 4)
2003 2079
 				$profiles[] = (int) $profile;
2080
+		}
2004 2081
 
2005 2082
 		// Verify it's not in use...
2006 2083
 		$request = $smcFunc['db_query']('', '
@@ -2012,8 +2089,9 @@  discard block
 block discarded – undo
2012 2089
 				'profile_list' => $profiles,
2013 2090
 			)
2014 2091
 		);
2015
-		if ($smcFunc['db_num_rows']($request) != 0)
2016
-			fatal_lang_error('no_access', false);
2092
+		if ($smcFunc['db_num_rows']($request) != 0) {
2093
+					fatal_lang_error('no_access', false);
2094
+		}
2017 2095
 		$smcFunc['db_free_result']($request);
2018 2096
 
2019 2097
 		// Oh well, delete.
@@ -2037,10 +2115,11 @@  discard block
 block discarded – undo
2037 2115
 		array(
2038 2116
 		)
2039 2117
 	);
2040
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2041
-		if (isset($context['profiles'][$row['id_profile']]))
2118
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2119
+			if (isset($context['profiles'][$row['id_profile']]))
2042 2120
 		{
2043 2121
 			$context['profiles'][$row['id_profile']]['in_use'] = true;
2122
+	}
2044 2123
 			$context['profiles'][$row['id_profile']]['boards'] = $row['board_count'];
2045 2124
 			$context['profiles'][$row['id_profile']]['boards_text'] = $row['board_count'] > 1 ? sprintf($txt['permissions_profile_used_by_many'], $row['board_count']) : $txt['permissions_profile_used_by_' . ($row['board_count'] ? 'one' : 'none')];
2046 2125
 		}
@@ -2052,8 +2131,9 @@  discard block
 block discarded – undo
2052 2131
 	{
2053 2132
 		// Can't delete special ones.
2054 2133
 		$context['profiles'][$id]['can_edit'] = isset($txt['permissions_profile_' . $profile['unformatted_name']]) ? false : true;
2055
-		if ($context['profiles'][$id]['can_edit'])
2056
-			$context['can_edit_something'] = true;
2134
+		if ($context['profiles'][$id]['can_edit']) {
2135
+					$context['can_edit_something'] = true;
2136
+		}
2057 2137
 
2058 2138
 		// You can only delete it if you can edit it AND it's not in use.
2059 2139
 		$context['profiles'][$id]['can_delete'] = $context['profiles'][$id]['can_edit'] && empty($profile['in_use']) ? true : false;
@@ -2074,8 +2154,9 @@  discard block
 block discarded – undo
2074 2154
 	global $smcFunc;
2075 2155
 
2076 2156
 	// All the parent groups to sort out.
2077
-	if (!is_array($parents))
2078
-		$parents = array($parents);
2157
+	if (!is_array($parents)) {
2158
+			$parents = array($parents);
2159
+	}
2079 2160
 
2080 2161
 	// Find all the children of this group.
2081 2162
 	$request = $smcFunc['db_query']('', '
@@ -2102,8 +2183,9 @@  discard block
 block discarded – undo
2102 2183
 	$parents = array_unique($parents);
2103 2184
 
2104 2185
 	// Not a sausage, or a child?
2105
-	if (empty($children))
2106
-		return false;
2186
+	if (empty($children)) {
2187
+			return false;
2188
+	}
2107 2189
 
2108 2190
 	// First off, are we doing general permissions?
2109 2191
 	if ($profile < 1 || $profile === null)
@@ -2118,9 +2200,10 @@  discard block
 block discarded – undo
2118 2200
 			)
2119 2201
 		);
2120 2202
 		$permissions = array();
2121
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2122
-			foreach ($children[$row['id_group']] as $child)
2203
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2204
+					foreach ($children[$row['id_group']] as $child)
2123 2205
 				$permissions[] = array($child, $row['permission'], $row['add_deny']);
2206
+		}
2124 2207
 		$smcFunc['db_free_result']($request);
2125 2208
 
2126 2209
 		$smcFunc['db_query']('', '
@@ -2160,9 +2243,10 @@  discard block
 block discarded – undo
2160 2243
 			)
2161 2244
 		);
2162 2245
 		$permissions = array();
2163
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2164
-			foreach ($children[$row['id_group']] as $child)
2246
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2247
+					foreach ($children[$row['id_group']] as $child)
2165 2248
 				$permissions[] = array($child, $row['id_profile'], $row['permission'], $row['add_deny']);
2249
+		}
2166 2250
 		$smcFunc['db_free_result']($request);
2167 2251
 
2168 2252
 		$smcFunc['db_query']('', '
@@ -2196,12 +2280,15 @@  discard block
 block discarded – undo
2196 2280
 	global $context;
2197 2281
 
2198 2282
 	$context['illegal_permissions'] = array();
2199
-	if (!allowedTo('admin_forum'))
2200
-		$context['illegal_permissions'][] = 'admin_forum';
2201
-	if (!allowedTo('manage_membergroups'))
2202
-		$context['illegal_permissions'][] = 'manage_membergroups';
2203
-	if (!allowedTo('manage_permissions'))
2204
-		$context['illegal_permissions'][] = 'manage_permissions';
2283
+	if (!allowedTo('admin_forum')) {
2284
+			$context['illegal_permissions'][] = 'admin_forum';
2285
+	}
2286
+	if (!allowedTo('manage_membergroups')) {
2287
+			$context['illegal_permissions'][] = 'manage_membergroups';
2288
+	}
2289
+	if (!allowedTo('manage_permissions')) {
2290
+			$context['illegal_permissions'][] = 'manage_permissions';
2291
+	}
2205 2292
 
2206 2293
 	call_integration_hook('integrate_load_illegal_permissions');
2207 2294
 }
@@ -2350,16 +2437,17 @@  discard block
 block discarded – undo
2350 2437
 				'attachment' => 'disallow',
2351 2438
 				'children' => array(),
2352 2439
 			);
2440
+		} elseif (isset($context['profile_groups'][$row['id_parent']])) {
2441
+					$context['profile_groups'][$row['id_parent']]['children'][] = $row['group_name'];
2353 2442
 		}
2354
-		elseif (isset($context['profile_groups'][$row['id_parent']]))
2355
-			$context['profile_groups'][$row['id_parent']]['children'][] = $row['group_name'];
2356 2443
 	}
2357 2444
 	$smcFunc['db_free_result']($request);
2358 2445
 
2359 2446
 	// What are the permissions we are querying?
2360 2447
 	$all_permissions = array();
2361
-	foreach ($mappings as $perm_set)
2362
-		$all_permissions = array_merge($all_permissions, $perm_set);
2448
+	foreach ($mappings as $perm_set) {
2449
+			$all_permissions = array_merge($all_permissions, $perm_set);
2450
+	}
2363 2451
 
2364 2452
 	// If we're saving the changes then do just that - save them.
2365 2453
 	if (!empty($_POST['save_changes']) && ($context['current_profile'] == 1 || $context['current_profile'] > 4))
@@ -2374,8 +2462,7 @@  discard block
 block discarded – undo
2374 2462
 			{
2375 2463
 				// Turning it on. This seems easy enough.
2376 2464
 				updateSettings(array('postmod_active' => 1));
2377
-			}
2378
-			else
2465
+			} else
2379 2466
 			{
2380 2467
 				// Turning it off. Not so straightforward. We have to turn off warnings to moderation level, and make everything approved.
2381 2468
 				updateSettings(array(
@@ -2386,8 +2473,7 @@  discard block
 block discarded – undo
2386 2473
 				require_once($sourcedir . '/PostModeration.php');
2387 2474
 				approveAllData();
2388 2475
 			}
2389
-		}
2390
-		elseif ($modSettings['postmod_active'])
2476
+		} elseif ($modSettings['postmod_active'])
2391 2477
 		{
2392 2478
 			// We're not saving a new setting - and if it's still enabled we have more work to do.
2393 2479
 
@@ -2417,21 +2503,22 @@  discard block
 block discarded – undo
2417 2503
 							// Give them both sets for fun.
2418 2504
 							$new_permissions[] = array($context['current_profile'], $group['id'], $data[0], 1);
2419 2505
 							$new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1);
2506
+						} elseif ($_POST[$index][$group['id']] == 'moderate') {
2507
+													$new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1);
2420 2508
 						}
2421
-						elseif ($_POST[$index][$group['id']] == 'moderate')
2422
-							$new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1);
2423 2509
 					}
2424 2510
 				}
2425 2511
 			}
2426 2512
 
2427 2513
 			// Insert new permissions.
2428
-			if (!empty($new_permissions))
2429
-				$smcFunc['db_insert']('',
2514
+			if (!empty($new_permissions)) {
2515
+							$smcFunc['db_insert']('',
2430 2516
 					'{db_prefix}board_permissions',
2431 2517
 					array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
2432 2518
 					$new_permissions,
2433 2519
 					array('id_profile', 'id_group', 'permission')
2434 2520
 				);
2521
+			}
2435 2522
 		}
2436 2523
 	}
2437 2524
 
@@ -2460,11 +2547,13 @@  discard block
 block discarded – undo
2460 2547
 					if ($row['add_deny'])
2461 2548
 					{
2462 2549
 						// Full allowance?
2463
-						if ($index == 0)
2464
-							$context['profile_groups'][$row['id_group']][$key] = 'allow';
2550
+						if ($index == 0) {
2551
+													$context['profile_groups'][$row['id_group']][$key] = 'allow';
2552
+						}
2465 2553
 						// Otherwise only bother with moderate if not on allow.
2466
-						elseif ($context['profile_groups'][$row['id_group']][$key] != 'allow')
2467
-							$context['profile_groups'][$row['id_group']][$key] = 'moderate';
2554
+						elseif ($context['profile_groups'][$row['id_group']][$key] != 'allow') {
2555
+													$context['profile_groups'][$row['id_group']][$key] = 'moderate';
2556
+						}
2468 2557
 					}
2469 2558
 				}
2470 2559
 			}
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +793 added lines, -597 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,27 +48,35 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65
-		if (!is_array($modSettings['attachmentUploadDir']))
66
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
73
+		if (!is_array($modSettings['attachmentUploadDir'])) {
74
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
75
+		}
67 76
 
68
-		if (!empty($cache_enable))
69
-			cache_put_data('modSettings', $modSettings, 90);
77
+		if (!empty($cache_enable)) {
78
+					cache_put_data('modSettings', $modSettings, 90);
79
+		}
70 80
 	}
71 81
 
72 82
 	$modSettings['cache_enable'] = $cache_enable;
@@ -86,8 +96,9 @@  discard block
 block discarded – undo
86 96
 		};
87 97
 	$fix_utf8mb4 = function ($string) use ($utf8)
88 98
 	{
89
-		if (!$utf8)
90
-			return $string;
99
+		if (!$utf8) {
100
+					return $string;
101
+		}
91 102
 
92 103
 		$i = 0;
93 104
 		$len = strlen($string);
@@ -99,18 +110,15 @@  discard block
 block discarded – undo
99 110
 			{
100 111
 				$new_string .= $string[$i];
101 112
 				$i++;
102
-			}
103
-			elseif ($ord < 224)
113
+			} elseif ($ord < 224)
104 114
 			{
105 115
 				$new_string .= $string[$i] . $string[$i+1];
106 116
 				$i += 2;
107
-			}
108
-			elseif ($ord < 240)
117
+			} elseif ($ord < 240)
109 118
 			{
110 119
 				$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
111 120
 				$i += 3;
112
-			}
113
-			elseif ($ord < 248)
121
+			} elseif ($ord < 248)
114 122
 			{
115 123
 				// Magic happens.
116 124
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -154,8 +162,7 @@  discard block
 block discarded – undo
154 162
 			{
155 163
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
156 164
 				return is_int($result) ? $result + $offset : false;
157
-			}
158
-			else
165
+			} else
159 166
 			{
160 167
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
161 168
 				$needle_size = count($needle_arr);
@@ -164,8 +171,9 @@  discard block
 block discarded – undo
164 171
 				while ((int) $result === $result)
165 172
 				{
166 173
 					$offset += $result;
167
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
168
-						return $offset;
174
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
175
+											return $offset;
176
+					}
169 177
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
170 178
 				}
171 179
 				return false;
@@ -203,8 +211,9 @@  discard block
 block discarded – undo
203 211
 			$string = $ent_check($string);
204 212
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'.  ($utf8 ? 'u' : ''), $string, $matches);
205 213
 			$string = $matches[0];
206
-			while (strlen($string) > $length)
207
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
214
+			while (strlen($string) > $length) {
215
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
216
+			}
208 217
 			return $string;
209 218
 		},
210 219
 		'ucfirst' => $utf8 ? function ($string) use (&$smcFunc)
@@ -214,15 +223,17 @@  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']))
225
-		date_default_timezone_set($modSettings['default_timezone']);
234
+	if (isset($modSettings['default_timezone'])) {
235
+			date_default_timezone_set($modSettings['default_timezone']);
236
+	}
226 237
 
227 238
 	// Check the load averages?
228 239
 	if (!empty($modSettings['loadavg_enable']))
@@ -230,22 +241,26 @@  discard block
 block discarded – undo
230 241
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
231 242
 		{
232 243
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
233
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
234
-				$modSettings['load_average'] = (float) $matches[1];
235
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
236
-				$modSettings['load_average'] = (float) $matches[1];
237
-			else
238
-				unset($modSettings['load_average']);
244
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
245
+							$modSettings['load_average'] = (float) $matches[1];
246
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
247
+							$modSettings['load_average'] = (float) $matches[1];
248
+			} else {
249
+							unset($modSettings['load_average']);
250
+			}
239 251
 
240
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
241
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
252
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
253
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
254
+			}
242 255
 		}
243 256
 
244
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
245
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
257
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
258
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
259
+		}
246 260
 
247
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
248
-			display_loadavg_error();
261
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
262
+					display_loadavg_error();
263
+		}
249 264
 	}
250 265
 
251 266
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -266,8 +281,9 @@  discard block
 block discarded – undo
266 281
 	if (defined('SMF_INTEGRATION_SETTINGS'))
267 282
 	{
268 283
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
269
-		foreach ($integration_settings as $hook => $function)
270
-			add_integration_function($hook, $function, '', false);
284
+		foreach ($integration_settings as $hook => $function) {
285
+					add_integration_function($hook, $function, '', false);
286
+		}
271 287
 	}
272 288
 
273 289
 	// Any files to pre include?
@@ -277,8 +293,9 @@  discard block
 block discarded – undo
277 293
 		foreach ($pre_includes as $include)
278 294
 		{
279 295
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
280
-			if (file_exists($include))
281
-				require_once($include);
296
+			if (file_exists($include)) {
297
+							require_once($include);
298
+			}
282 299
 		}
283 300
 	}
284 301
 
@@ -382,27 +399,28 @@  discard block
 block discarded – undo
382 399
 				break;
383 400
 			}
384 401
 		}
402
+	} else {
403
+			$id_member = 0;
385 404
 	}
386
-	else
387
-		$id_member = 0;
388 405
 
389 406
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
390 407
 	{
391 408
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
392 409
 
393
-		if (empty($cookie_data))
394
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
410
+		if (empty($cookie_data)) {
411
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
412
+		}
395 413
 
396 414
 		list ($id_member, $password) = $cookie_data;
397 415
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
398
-	}
399
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
416
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
400 417
 	{
401 418
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
402 419
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
403 420
 
404
-		if (empty($cookie_data))
405
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
421
+		if (empty($cookie_data)) {
422
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
423
+		}
406 424
 
407 425
 		list ($id_member, $password, $login_span) = $cookie_data;
408 426
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -427,30 +445,34 @@  discard block
 block discarded – undo
427 445
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
428 446
 			$smcFunc['db_free_result']($request);
429 447
 
430
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
431
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
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);
450
+			}
432 451
 
433
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
434
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
452
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
453
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
454
+			}
435 455
 		}
436 456
 
437 457
 		// Did we find 'im?  If not, junk it.
438 458
 		if (!empty($user_settings))
439 459
 		{
440 460
 			// As much as the password should be right, we can assume the integration set things up.
441
-			if (!empty($already_verified) && $already_verified === true)
442
-				$check = true;
461
+			if (!empty($already_verified) && $already_verified === true) {
462
+							$check = true;
463
+			}
443 464
 			// SHA-512 hash should be 128 characters long.
444
-			elseif (strlen($password) == 128)
445
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
446
-			else
447
-				$check = false;
465
+			elseif (strlen($password) == 128) {
466
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
467
+			} else {
468
+							$check = false;
469
+			}
448 470
 
449 471
 			// Wrong password or not activated - either way, you're going nowhere.
450 472
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
473
+		} else {
474
+					$id_member = 0;
451 475
 		}
452
-		else
453
-			$id_member = 0;
454 476
 
455 477
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
456 478
 		if (!$id_member)
@@ -472,13 +494,15 @@  discard block
 block discarded – undo
472 494
 				{
473 495
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
474 496
 
475
-					if (is_null($tfa_data))
476
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
497
+					if (is_null($tfa_data)) {
498
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
499
+					}
477 500
 
478 501
 					list ($tfamember, $tfasecret) = $tfa_data;
479 502
 
480
-					if ((int) $tfamember != $id_member)
481
-						$tfasecret = null;
503
+					if ((int) $tfamember != $id_member) {
504
+											$tfasecret = null;
505
+					}
482 506
 				}
483 507
 
484 508
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -498,10 +522,12 @@  discard block
 block discarded – undo
498 522
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
499 523
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
500 524
 		{
501
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
525
+			if ($modSettings['tfa_mode'] == 2) {
526
+				//only do this if we are just forcing SOME membergroups
502 527
 			{
503 528
 				//Build an array of ALL user membergroups.
504 529
 				$full_groups = array($user_settings['id_group']);
530
+			}
505 531
 				if (!empty($user_settings['additional_groups']))
506 532
 				{
507 533
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -521,15 +547,17 @@  discard block
 block discarded – undo
521 547
 				);
522 548
 				$row = $smcFunc['db_fetch_assoc']($request);
523 549
 				$smcFunc['db_free_result']($request);
550
+			} else {
551
+							$row['total'] = 1;
524 552
 			}
525
-			else
526
-				$row['total'] = 1; //simplifies logics in the next "if"
553
+			//simplifies logics in the next "if"
527 554
 
528 555
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
529 556
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
530 557
 
531
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
532
-				redirectexit('action=profile;area=tfasetup;forced');
558
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
559
+							redirectexit('action=profile;area=tfasetup;forced');
560
+			}
533 561
 		}
534 562
 	}
535 563
 
@@ -566,33 +594,37 @@  discard block
 block discarded – undo
566 594
 				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']));
567 595
 				$user_settings['last_login'] = time();
568 596
 
569
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
570
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
597
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
598
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
599
+				}
571 600
 
572
-				if (!empty($modSettings['cache_enable']))
573
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
601
+				if (!empty($modSettings['cache_enable'])) {
602
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
603
+				}
574 604
 			}
605
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
606
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
575 607
 		}
576
-		elseif (empty($_SESSION['id_msg_last_visit']))
577
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
578 608
 
579 609
 		$username = $user_settings['member_name'];
580 610
 
581
-		if (empty($user_settings['additional_groups']))
582
-			$user_info = array(
611
+		if (empty($user_settings['additional_groups'])) {
612
+					$user_info = array(
583 613
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
584 614
 			);
585
-		else
586
-			$user_info = array(
615
+		} else {
616
+					$user_info = array(
587 617
 				'groups' => array_merge(
588 618
 					array($user_settings['id_group'], $user_settings['id_post_group']),
589 619
 					explode(',', $user_settings['additional_groups'])
590 620
 				)
591 621
 			);
622
+		}
592 623
 
593 624
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
594
-		foreach ($user_info['groups'] as $k => $v)
595
-			$user_info['groups'][$k] = (int) $v;
625
+		foreach ($user_info['groups'] as $k => $v) {
626
+					$user_info['groups'][$k] = (int) $v;
627
+		}
596 628
 
597 629
 		// This is a logged in user, so definitely not a spider.
598 630
 		$user_info['possibly_robot'] = false;
@@ -606,8 +638,7 @@  discard block
 block discarded – undo
606 638
 			$time_system = new DateTime('now', $tz_system);
607 639
 			$time_user = new DateTime('now', $tz_user);
608 640
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
609
-		}
610
-		else
641
+		} else
611 642
 		{
612 643
 			// !!! Compatibility.
613 644
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset'];
@@ -621,16 +652,18 @@  discard block
 block discarded – undo
621 652
 		$user_info = array('groups' => array(-1));
622 653
 		$user_settings = array();
623 654
 
624
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
625
-			$_COOKIE[$cookiename] = '';
655
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
656
+					$_COOKIE[$cookiename] = '';
657
+		}
626 658
 
627 659
 		// Expire the 2FA cookie
628 660
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
629 661
 		{
630 662
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
631 663
 
632
-			if (is_null($tfa_data))
633
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
664
+			if (is_null($tfa_data)) {
665
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
666
+			}
634 667
 
635 668
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
636 669
 
@@ -642,19 +675,20 @@  discard block
 block discarded – undo
642 675
 		}
643 676
 
644 677
 		// Create a login token if it doesn't exist yet.
645
-		if (!isset($_SESSION['token']['post-login']))
646
-			createToken('login');
647
-		else
648
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
678
+		if (!isset($_SESSION['token']['post-login'])) {
679
+					createToken('login');
680
+		} else {
681
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
682
+		}
649 683
 
650 684
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
651 685
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
652 686
 		{
653 687
 			require_once($sourcedir . '/ManageSearchEngines.php');
654 688
 			$user_info['possibly_robot'] = SpiderCheck();
689
+		} elseif (!empty($modSettings['spider_mode'])) {
690
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
655 691
 		}
656
-		elseif (!empty($modSettings['spider_mode']))
657
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
658 692
 		// If we haven't turned on proper spider hunts then have a guess!
659 693
 		else
660 694
 		{
@@ -702,8 +736,9 @@  discard block
 block discarded – undo
702 736
 	$user_info['groups'] = array_unique($user_info['groups']);
703 737
 
704 738
 	// 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.
705
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
706
-		unset($user_info['ignoreboards'][$tmp]);
739
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
740
+			unset($user_info['ignoreboards'][$tmp]);
741
+	}
707 742
 
708 743
 	// Allow the user to change their language.
709 744
 	if (!empty($modSettings['userLanguage']))
@@ -716,31 +751,36 @@  discard block
 block discarded – undo
716 751
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
717 752
 
718 753
 			// Make it permanent for members.
719
-			if (!empty($user_info['id']))
720
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
721
-			else
722
-				$_SESSION['language'] = $user_info['language'];
754
+			if (!empty($user_info['id'])) {
755
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
756
+			} else {
757
+							$_SESSION['language'] = $user_info['language'];
758
+			}
759
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
760
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
723 761
 		}
724
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
725
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
726 762
 	}
727 763
 
728 764
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
729
-	if ($user_info['is_admin'])
730
-		$user_info['query_see_board'] = '1=1';
765
+	if ($user_info['is_admin']) {
766
+			$user_info['query_see_board'] = '1=1';
767
+	}
731 768
 	// Otherwise just the groups in $user_info['groups'].
732
-	else
733
-		$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'] : '') . ')';
769
+	else {
770
+			$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'] : '') . ')';
771
+	}
734 772
 
735 773
 	// Build the list of boards they WANT to see.
736 774
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
737 775
 
738 776
 	// If they aren't ignoring any boards then they want to see all the boards they can see
739
-	if (empty($user_info['ignoreboards']))
740
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
777
+	if (empty($user_info['ignoreboards'])) {
778
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
779
+	}
741 780
 	// Ok I guess they don't want to see all the boards
742
-	else
743
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
781
+	else {
782
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
783
+	}
744 784
 
745 785
 	call_integration_hook('integrate_user_info');
746 786
 }
@@ -798,9 +838,9 @@  discard block
 block discarded – undo
798 838
 		}
799 839
 
800 840
 		// Remember redirection is the key to avoiding fallout from your bosses.
801
-		if (!empty($topic))
802
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
803
-		else
841
+		if (!empty($topic)) {
842
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
843
+		} else
804 844
 		{
805 845
 			loadPermissions();
806 846
 			loadTheme();
@@ -818,10 +858,11 @@  discard block
 block discarded – undo
818 858
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
819 859
 	{
820 860
 		// @todo SLOW?
821
-		if (!empty($topic))
822
-			$temp = cache_get_data('topic_board-' . $topic, 120);
823
-		else
824
-			$temp = cache_get_data('board-' . $board, 120);
861
+		if (!empty($topic)) {
862
+					$temp = cache_get_data('topic_board-' . $topic, 120);
863
+		} else {
864
+					$temp = cache_get_data('board-' . $board, 120);
865
+		}
825 866
 
826 867
 		if (!empty($temp))
827 868
 		{
@@ -859,8 +900,9 @@  discard block
 block discarded – undo
859 900
 			$row = $smcFunc['db_fetch_assoc']($request);
860 901
 
861 902
 			// Set the current board.
862
-			if (!empty($row['id_board']))
863
-				$board = $row['id_board'];
903
+			if (!empty($row['id_board'])) {
904
+							$board = $row['id_board'];
905
+			}
864 906
 
865 907
 			// Basic operating information. (globals... :/)
866 908
 			$board_info = array(
@@ -896,21 +938,23 @@  discard block
 block discarded – undo
896 938
 
897 939
 			do
898 940
 			{
899
-				if (!empty($row['id_moderator']))
900
-					$board_info['moderators'][$row['id_moderator']] = array(
941
+				if (!empty($row['id_moderator'])) {
942
+									$board_info['moderators'][$row['id_moderator']] = array(
901 943
 						'id' => $row['id_moderator'],
902 944
 						'name' => $row['real_name'],
903 945
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
904 946
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
905 947
 					);
948
+				}
906 949
 
907
-				if (!empty($row['id_moderator_group']))
908
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
950
+				if (!empty($row['id_moderator_group'])) {
951
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
909 952
 						'id' => $row['id_moderator_group'],
910 953
 						'name' => $row['group_name'],
911 954
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
912 955
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
913 956
 					);
957
+				}
914 958
 			}
915 959
 			while ($row = $smcFunc['db_fetch_assoc']($request));
916 960
 
@@ -942,12 +986,12 @@  discard block
 block discarded – undo
942 986
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
943 987
 			{
944 988
 				// @todo SLOW?
945
-				if (!empty($topic))
946
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
989
+				if (!empty($topic)) {
990
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
991
+				}
947 992
 				cache_put_data('board-' . $board, $board_info, 120);
948 993
 			}
949
-		}
950
-		else
994
+		} else
951 995
 		{
952 996
 			// Otherwise the topic is invalid, there are no moderators, etc.
953 997
 			$board_info = array(
@@ -961,8 +1005,9 @@  discard block
 block discarded – undo
961 1005
 		$smcFunc['db_free_result']($request);
962 1006
 	}
963 1007
 
964
-	if (!empty($topic))
965
-		$_GET['board'] = (int) $board;
1008
+	if (!empty($topic)) {
1009
+			$_GET['board'] = (int) $board;
1010
+	}
966 1011
 
967 1012
 	if (!empty($board))
968 1013
 	{
@@ -972,10 +1017,12 @@  discard block
 block discarded – undo
972 1017
 		// Now check if the user is a moderator.
973 1018
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
974 1019
 
975
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
976
-			$board_info['error'] = 'access';
977
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
978
-			$board_info['error'] = 'access';
1020
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1021
+					$board_info['error'] = 'access';
1022
+		}
1023
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1024
+					$board_info['error'] = 'access';
1025
+		}
979 1026
 
980 1027
 		// Build up the linktree.
981 1028
 		$context['linktree'] = array_merge(
@@ -998,8 +1045,9 @@  discard block
 block discarded – undo
998 1045
 	$context['current_board'] = $board;
999 1046
 
1000 1047
 	// No posting in redirection boards!
1001
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1002
-		$board_info['error'] == 'post_in_redirect';
1048
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1049
+			$board_info['error'] == 'post_in_redirect';
1050
+	}
1003 1051
 
1004 1052
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1005 1053
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1025,24 +1073,23 @@  discard block
 block discarded – undo
1025 1073
 			ob_end_clean();
1026 1074
 			header('HTTP/1.1 403 Forbidden');
1027 1075
 			die;
1028
-		}
1029
-		elseif ($board_info['error'] == 'post_in_redirect')
1076
+		} elseif ($board_info['error'] == 'post_in_redirect')
1030 1077
 		{
1031 1078
 			// Slightly different error message here...
1032 1079
 			fatal_lang_error('cannot_post_redirect', false);
1033
-		}
1034
-		elseif ($user_info['is_guest'])
1080
+		} elseif ($user_info['is_guest'])
1035 1081
 		{
1036 1082
 			loadLanguage('Errors');
1037 1083
 			is_not_guest($txt['topic_gone']);
1084
+		} else {
1085
+					fatal_lang_error('topic_gone', false);
1038 1086
 		}
1039
-		else
1040
-			fatal_lang_error('topic_gone', false);
1041 1087
 	}
1042 1088
 
1043
-	if ($user_info['is_mod'])
1044
-		$user_info['groups'][] = 3;
1045
-}
1089
+	if ($user_info['is_mod']) {
1090
+			$user_info['groups'][] = 3;
1091
+	}
1092
+	}
1046 1093
 
1047 1094
 /**
1048 1095
  * Load this user's permissions.
@@ -1063,8 +1110,9 @@  discard block
 block discarded – undo
1063 1110
 		asort($cache_groups);
1064 1111
 		$cache_groups = implode(',', $cache_groups);
1065 1112
 		// If it's a spider then cache it different.
1066
-		if ($user_info['possibly_robot'])
1067
-			$cache_groups .= '-spider';
1113
+		if ($user_info['possibly_robot']) {
1114
+					$cache_groups .= '-spider';
1115
+		}
1068 1116
 
1069 1117
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1070 1118
 		{
@@ -1072,9 +1120,9 @@  discard block
 block discarded – undo
1072 1120
 			banPermissions();
1073 1121
 
1074 1122
 			return;
1123
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1124
+					list ($user_info['permissions'], $removals) = $temp;
1075 1125
 		}
1076
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1077
-			list ($user_info['permissions'], $removals) = $temp;
1078 1126
 	}
1079 1127
 
1080 1128
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1096,23 +1144,26 @@  discard block
 block discarded – undo
1096 1144
 		$removals = array();
1097 1145
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1098 1146
 		{
1099
-			if (empty($row['add_deny']))
1100
-				$removals[] = $row['permission'];
1101
-			else
1102
-				$user_info['permissions'][] = $row['permission'];
1147
+			if (empty($row['add_deny'])) {
1148
+							$removals[] = $row['permission'];
1149
+			} else {
1150
+							$user_info['permissions'][] = $row['permission'];
1151
+			}
1103 1152
 		}
1104 1153
 		$smcFunc['db_free_result']($request);
1105 1154
 
1106
-		if (isset($cache_groups))
1107
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1155
+		if (isset($cache_groups)) {
1156
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1157
+		}
1108 1158
 	}
1109 1159
 
1110 1160
 	// Get the board permissions.
1111 1161
 	if (!empty($board))
1112 1162
 	{
1113 1163
 		// Make sure the board (if any) has been loaded by loadBoard().
1114
-		if (!isset($board_info['profile']))
1115
-			fatal_lang_error('no_board');
1164
+		if (!isset($board_info['profile'])) {
1165
+					fatal_lang_error('no_board');
1166
+		}
1116 1167
 
1117 1168
 		$request = $smcFunc['db_query']('', '
1118 1169
 			SELECT permission, add_deny
@@ -1128,20 +1179,23 @@  discard block
 block discarded – undo
1128 1179
 		);
1129 1180
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1130 1181
 		{
1131
-			if (empty($row['add_deny']))
1132
-				$removals[] = $row['permission'];
1133
-			else
1134
-				$user_info['permissions'][] = $row['permission'];
1182
+			if (empty($row['add_deny'])) {
1183
+							$removals[] = $row['permission'];
1184
+			} else {
1185
+							$user_info['permissions'][] = $row['permission'];
1186
+			}
1135 1187
 		}
1136 1188
 		$smcFunc['db_free_result']($request);
1137 1189
 	}
1138 1190
 
1139 1191
 	// Remove all the permissions they shouldn't have ;).
1140
-	if (!empty($modSettings['permission_enable_deny']))
1141
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1192
+	if (!empty($modSettings['permission_enable_deny'])) {
1193
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1194
+	}
1142 1195
 
1143
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1144
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1196
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1197
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1198
+	}
1145 1199
 
1146 1200
 	// Banned?  Watch, don't touch..
1147 1201
 	banPermissions();
@@ -1153,17 +1207,18 @@  discard block
 block discarded – undo
1153 1207
 		{
1154 1208
 			require_once($sourcedir . '/Subs-Auth.php');
1155 1209
 			rebuildModCache();
1210
+		} else {
1211
+					$user_info['mod_cache'] = $_SESSION['mc'];
1156 1212
 		}
1157
-		else
1158
-			$user_info['mod_cache'] = $_SESSION['mc'];
1159 1213
 
1160 1214
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1161 1215
 		// For example this drastically simplifies certain changes to the profile area.
1162 1216
 		$user_info['permissions'][] = 'is_not_guest';
1163 1217
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1164 1218
 		$user_info['permissions'][] = 'profile_view_own';
1165
-		if (in_array('profile_view', $user_info['permissions']))
1166
-			$user_info['permissions'][] = 'profile_view_any';
1219
+		if (in_array('profile_view', $user_info['permissions'])) {
1220
+					$user_info['permissions'][] = 'profile_view_any';
1221
+		}
1167 1222
 	}
1168 1223
 }
1169 1224
 
@@ -1181,8 +1236,9 @@  discard block
 block discarded – undo
1181 1236
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1182 1237
 
1183 1238
 	// Can't just look for no users :P.
1184
-	if (empty($users))
1185
-		return array();
1239
+	if (empty($users)) {
1240
+			return array();
1241
+	}
1186 1242
 
1187 1243
 	// Pass the set value
1188 1244
 	$context['loadMemberContext_set'] = $set;
@@ -1197,8 +1253,9 @@  discard block
 block discarded – undo
1197 1253
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1198 1254
 		{
1199 1255
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1200
-			if ($data == null)
1201
-				continue;
1256
+			if ($data == null) {
1257
+							continue;
1258
+			}
1202 1259
 
1203 1260
 			$loaded_ids[] = $data['id_member'];
1204 1261
 			$user_profile[$data['id_member']] = $data;
@@ -1262,13 +1319,16 @@  discard block
 block discarded – undo
1262 1319
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1263 1320
 		{
1264 1321
 			// Take care of proxying avatar if required, do this here for maximum reach
1265
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1266
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1322
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1323
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1324
+			}
1267 1325
 
1268
-			if ( isset($row['member_ip']) )
1269
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1270
-			if ( isset($row['member_ip2']) )
1271
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1326
+			if ( isset($row['member_ip']) ) {
1327
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1328
+			}
1329
+			if ( isset($row['member_ip2']) ) {
1330
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1331
+			}
1272 1332
 			$new_loaded_ids[] = $row['id_member'];
1273 1333
 			$loaded_ids[] = $row['id_member'];
1274 1334
 			$row['options'] = array();
@@ -1287,8 +1347,9 @@  discard block
 block discarded – undo
1287 1347
 				'loaded_ids' => $new_loaded_ids,
1288 1348
 			)
1289 1349
 		);
1290
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1291
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1350
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1351
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1352
+		}
1292 1353
 		$smcFunc['db_free_result']($request);
1293 1354
 	}
1294 1355
 
@@ -1299,10 +1360,11 @@  discard block
 block discarded – undo
1299 1360
 	{
1300 1361
 		foreach ($loaded_ids as $a_member)
1301 1362
 		{
1302
-			if (!empty($user_profile[$a_member]['additional_groups']))
1303
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1304
-			else
1305
-				$groups = array($user_profile[$a_member]['id_group']);
1363
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1364
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1365
+			} else {
1366
+							$groups = array($user_profile[$a_member]['id_group']);
1367
+			}
1306 1368
 
1307 1369
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1308 1370
 
@@ -1315,8 +1377,9 @@  discard block
 block discarded – undo
1315 1377
 
1316 1378
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1317 1379
 	{
1318
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1319
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1380
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1381
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1382
+		}
1320 1383
 	}
1321 1384
 
1322 1385
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1342,14 +1405,17 @@  discard block
 block discarded – undo
1342 1405
 		foreach ($temp_mods as $id)
1343 1406
 		{
1344 1407
 			// By popular demand, don't show admins or global moderators as moderators.
1345
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1346
-				$user_profile[$id]['member_group'] = $row['member_group'];
1408
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1409
+							$user_profile[$id]['member_group'] = $row['member_group'];
1410
+			}
1347 1411
 
1348 1412
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1349
-			if (!empty($row['icons']))
1350
-				$user_profile[$id]['icons'] = $row['icons'];
1351
-			if (!empty($row['member_group_color']))
1352
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1413
+			if (!empty($row['icons'])) {
1414
+							$user_profile[$id]['icons'] = $row['icons'];
1415
+			}
1416
+			if (!empty($row['member_group_color'])) {
1417
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1418
+			}
1353 1419
 		}
1354 1420
 	}
1355 1421
 
@@ -1371,12 +1437,14 @@  discard block
 block discarded – undo
1371 1437
 	static $loadedLanguages = array();
1372 1438
 
1373 1439
 	// If this person's data is already loaded, skip it.
1374
-	if (isset($dataLoaded[$user]))
1375
-		return true;
1440
+	if (isset($dataLoaded[$user])) {
1441
+			return true;
1442
+	}
1376 1443
 
1377 1444
 	// We can't load guests or members not loaded by loadMemberData()!
1378
-	if ($user == 0)
1379
-		return false;
1445
+	if ($user == 0) {
1446
+			return false;
1447
+	}
1380 1448
 	if (!isset($user_profile[$user]))
1381 1449
 	{
1382 1450
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1402,12 +1470,16 @@  discard block
 block discarded – undo
1402 1470
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1403 1471
 
1404 1472
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1405
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1473
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1474
+		//icon is set and exists
1406 1475
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1407
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1476
+	} elseif (isset($profile['icons'][1])) {
1477
+		//icon is set and doesn't exist, fallback to default
1408 1478
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1409
-	else //not set, bye bye
1479
+	} else {
1480
+		//not set, bye bye
1410 1481
 		$group_icon_url = '';
1482
+	}
1411 1483
 
1412 1484
 	// These minimal values are always loaded
1413 1485
 	$memberContext[$user] = array(
@@ -1426,8 +1498,9 @@  discard block
 block discarded – undo
1426 1498
 	if ($context['loadMemberContext_set'] != 'minimal')
1427 1499
 	{
1428 1500
 		// Go the extra mile and load the user's native language name.
1429
-		if (empty($loadedLanguages))
1430
-			$loadedLanguages = getLanguages();
1501
+		if (empty($loadedLanguages)) {
1502
+					$loadedLanguages = getLanguages();
1503
+		}
1431 1504
 
1432 1505
 		$memberContext[$user] += array(
1433 1506
 			'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>',
@@ -1481,31 +1554,33 @@  discard block
 block discarded – undo
1481 1554
 	{
1482 1555
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1483 1556
 		{
1484
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1485
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1486
-			else
1487
-				$image = get_gravatar_url($profile['email_address']);
1488
-		}
1489
-		else
1557
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1558
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1559
+			} else {
1560
+							$image = get_gravatar_url($profile['email_address']);
1561
+			}
1562
+		} else
1490 1563
 		{
1491 1564
 			// So it's stored in the member table?
1492 1565
 			if (!empty($profile['avatar']))
1493 1566
 			{
1494 1567
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1568
+			} elseif (!empty($profile['filename'])) {
1569
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1495 1570
 			}
1496
-			elseif (!empty($profile['filename']))
1497
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1498 1571
 			// Right... no avatar...use the default one
1499
-			else
1500
-				$image = $modSettings['avatar_url'] . '/default.png';
1572
+			else {
1573
+							$image = $modSettings['avatar_url'] . '/default.png';
1574
+			}
1501 1575
 		}
1502
-		if (!empty($image))
1503
-			$memberContext[$user]['avatar'] = array(
1576
+		if (!empty($image)) {
1577
+					$memberContext[$user]['avatar'] = array(
1504 1578
 				'name' => $profile['avatar'],
1505 1579
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">',
1506 1580
 				'href' => $image,
1507 1581
 				'url' => $image,
1508 1582
 			);
1583
+		}
1509 1584
 	}
1510 1585
 
1511 1586
 	// Are we also loading the members custom fields into context?
@@ -1513,35 +1588,41 @@  discard block
 block discarded – undo
1513 1588
 	{
1514 1589
 		$memberContext[$user]['custom_fields'] = array();
1515 1590
 
1516
-		if (!isset($context['display_fields']))
1517
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1591
+		if (!isset($context['display_fields'])) {
1592
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1593
+		}
1518 1594
 
1519 1595
 		foreach ($context['display_fields'] as $custom)
1520 1596
 		{
1521
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1522
-				continue;
1597
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1598
+							continue;
1599
+			}
1523 1600
 
1524 1601
 			$value = $profile['options'][$custom['col_name']];
1525 1602
 
1526 1603
 			// Don't show the "disabled" option for the "gender" field.
1527
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1528
-				continue;
1604
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1605
+							continue;
1606
+			}
1529 1607
 
1530 1608
 			// BBC?
1531
-			if ($custom['bbc'])
1532
-				$value = parse_bbc($value);
1609
+			if ($custom['bbc']) {
1610
+							$value = parse_bbc($value);
1611
+			}
1533 1612
 			// ... or checkbox?
1534
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1535
-				$value = $value ? $txt['yes'] : $txt['no'];
1613
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1614
+							$value = $value ? $txt['yes'] : $txt['no'];
1615
+			}
1536 1616
 
1537 1617
 			// Enclosing the user input within some other text?
1538
-			if (!empty($custom['enclose']))
1539
-				$value = strtr($custom['enclose'], array(
1618
+			if (!empty($custom['enclose'])) {
1619
+							$value = strtr($custom['enclose'], array(
1540 1620
 					'{SCRIPTURL}' => $scripturl,
1541 1621
 					'{IMAGES_URL}' => $settings['images_url'],
1542 1622
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1543 1623
 					'{INPUT}' => $value,
1544 1624
 				));
1625
+			}
1545 1626
 
1546 1627
 			$memberContext[$user]['custom_fields'][] = array(
1547 1628
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1568,8 +1649,9 @@  discard block
 block discarded – undo
1568 1649
 	global $smcFunc, $txt, $scripturl, $settings;
1569 1650
 
1570 1651
 	// Do not waste my time...
1571
-	if (empty($users) || empty($params))
1572
-		return false;
1652
+	if (empty($users) || empty($params)) {
1653
+			return false;
1654
+	}
1573 1655
 
1574 1656
 	// Make sure it's an array.
1575 1657
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1593,31 +1675,36 @@  discard block
 block discarded – undo
1593 1675
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1594 1676
 	{
1595 1677
 		// BBC?
1596
-		if (!empty($row['bbc']))
1597
-			$row['value'] = parse_bbc($row['value']);
1678
+		if (!empty($row['bbc'])) {
1679
+					$row['value'] = parse_bbc($row['value']);
1680
+		}
1598 1681
 
1599 1682
 		// ... or checkbox?
1600
-		elseif (isset($row['type']) && $row['type'] == 'check')
1601
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1683
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1684
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1685
+		}
1602 1686
 
1603 1687
 		// Enclosing the user input within some other text?
1604
-		if (!empty($row['enclose']))
1605
-			$row['value'] = strtr($row['enclose'], array(
1688
+		if (!empty($row['enclose'])) {
1689
+					$row['value'] = strtr($row['enclose'], array(
1606 1690
 				'{SCRIPTURL}' => $scripturl,
1607 1691
 				'{IMAGES_URL}' => $settings['images_url'],
1608 1692
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1609 1693
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1610 1694
 			));
1695
+		}
1611 1696
 
1612 1697
 		// Send a simple array if there is just 1 param
1613
-		if (count($params) == 1)
1614
-			$return[$row['id_member']] = $row;
1698
+		if (count($params) == 1) {
1699
+					$return[$row['id_member']] = $row;
1700
+		}
1615 1701
 
1616 1702
 		// More than 1? knock yourself out...
1617 1703
 		else
1618 1704
 		{
1619
-			if (!isset($return[$row['id_member']]))
1620
-				$return[$row['id_member']] = array();
1705
+			if (!isset($return[$row['id_member']])) {
1706
+							$return[$row['id_member']] = array();
1707
+			}
1621 1708
 
1622 1709
 			$return[$row['id_member']][$row['variable']] = $row;
1623 1710
 		}
@@ -1651,8 +1738,9 @@  discard block
 block discarded – undo
1651 1738
 	global $context;
1652 1739
 
1653 1740
 	// Don't know any browser!
1654
-	if (empty($context['browser']))
1655
-		detectBrowser();
1741
+	if (empty($context['browser'])) {
1742
+			detectBrowser();
1743
+	}
1656 1744
 
1657 1745
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1658 1746
 }
@@ -1670,8 +1758,9 @@  discard block
 block discarded – undo
1670 1758
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1671 1759
 
1672 1760
 	// The theme was specified by parameter.
1673
-	if (!empty($id_theme))
1674
-		$id_theme = (int) $id_theme;
1761
+	if (!empty($id_theme)) {
1762
+			$id_theme = (int) $id_theme;
1763
+	}
1675 1764
 	// The theme was specified by REQUEST.
1676 1765
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1677 1766
 	{
@@ -1679,51 +1768,58 @@  discard block
 block discarded – undo
1679 1768
 		$_SESSION['id_theme'] = $id_theme;
1680 1769
 	}
1681 1770
 	// The theme was specified by REQUEST... previously.
1682
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1683
-		$id_theme = (int) $_SESSION['id_theme'];
1771
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1772
+			$id_theme = (int) $_SESSION['id_theme'];
1773
+	}
1684 1774
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1685
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1686
-		$id_theme = $user_info['theme'];
1775
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1776
+			$id_theme = $user_info['theme'];
1777
+	}
1687 1778
 	// The theme was specified by the board.
1688
-	elseif (!empty($board_info['theme']))
1689
-		$id_theme = $board_info['theme'];
1779
+	elseif (!empty($board_info['theme'])) {
1780
+			$id_theme = $board_info['theme'];
1781
+	}
1690 1782
 	// The theme is the forum's default.
1691
-	else
1692
-		$id_theme = $modSettings['theme_guests'];
1783
+	else {
1784
+			$id_theme = $modSettings['theme_guests'];
1785
+	}
1693 1786
 
1694 1787
 	// Verify the id_theme... no foul play.
1695 1788
 	// Always allow the board specific theme, if they are overriding.
1696
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1697
-		$id_theme = $board_info['theme'];
1789
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1790
+			$id_theme = $board_info['theme'];
1791
+	}
1698 1792
 	// If they have specified a particular theme to use with SSI allow it to be used.
1699
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1700
-		$id_theme = (int) $id_theme;
1701
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1793
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1794
+			$id_theme = (int) $id_theme;
1795
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1702 1796
 	{
1703 1797
 		$themes = explode(',', $modSettings['enableThemes']);
1704
-		if (!in_array($id_theme, $themes))
1705
-			$id_theme = $modSettings['theme_guests'];
1706
-		else
1798
+		if (!in_array($id_theme, $themes)) {
1799
+					$id_theme = $modSettings['theme_guests'];
1800
+		} else {
1801
+					$id_theme = (int) $id_theme;
1802
+		}
1803
+	} else {
1707 1804
 			$id_theme = (int) $id_theme;
1708 1805
 	}
1709
-	else
1710
-		$id_theme = (int) $id_theme;
1711 1806
 
1712 1807
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1713 1808
 
1714 1809
 	// Disable image proxy if we don't have SSL enabled
1715
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1716
-		$image_proxy_enabled = false;
1810
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1811
+			$image_proxy_enabled = false;
1812
+	}
1717 1813
 
1718 1814
 	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'])
1719 1815
 	{
1720 1816
 		$themeData = $temp;
1721 1817
 		$flag = true;
1818
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1819
+			$themeData = $temp + array($member => array());
1820
+	} else {
1821
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1722 1822
 	}
1723
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1724
-		$themeData = $temp + array($member => array());
1725
-	else
1726
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1727 1823
 
1728 1824
 	if (empty($flag))
1729 1825
 	{
@@ -1742,31 +1838,37 @@  discard block
 block discarded – undo
1742 1838
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1743 1839
 		{
1744 1840
 			// There are just things we shouldn't be able to change as members.
1745
-			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')))
1746
-				continue;
1841
+			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'))) {
1842
+							continue;
1843
+			}
1747 1844
 
1748 1845
 			// If this is the theme_dir of the default theme, store it.
1749
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1750
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1846
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1847
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1848
+			}
1751 1849
 
1752 1850
 			// If this isn't set yet, is a theme option, or is not the default theme..
1753
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1754
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1851
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1852
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1853
+			}
1755 1854
 		}
1756 1855
 		$smcFunc['db_free_result']($result);
1757 1856
 
1758
-		if (!empty($themeData[-1]))
1759
-			foreach ($themeData[-1] as $k => $v)
1857
+		if (!empty($themeData[-1])) {
1858
+					foreach ($themeData[-1] as $k => $v)
1760 1859
 			{
1761 1860
 				if (!isset($themeData[$member][$k]))
1762 1861
 					$themeData[$member][$k] = $v;
1862
+		}
1763 1863
 			}
1764 1864
 
1765
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1766
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1865
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1866
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1867
+		}
1767 1868
 		// Only if we didn't already load that part of the cache...
1768
-		elseif (!isset($temp))
1769
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1869
+		elseif (!isset($temp)) {
1870
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1871
+		}
1770 1872
 	}
1771 1873
 
1772 1874
 	$settings = $themeData[0];
@@ -1783,20 +1885,24 @@  discard block
 block discarded – undo
1783 1885
 	$settings['template_dirs'][] = $settings['theme_dir'];
1784 1886
 
1785 1887
 	// Based on theme (if there is one).
1786
-	if (!empty($settings['base_theme_dir']))
1787
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1888
+	if (!empty($settings['base_theme_dir'])) {
1889
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1890
+	}
1788 1891
 
1789 1892
 	// Lastly the default theme.
1790
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1791
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1893
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1894
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1895
+	}
1792 1896
 
1793
-	if (!$initialize)
1794
-		return;
1897
+	if (!$initialize) {
1898
+			return;
1899
+	}
1795 1900
 
1796 1901
 	// Check to see if we're forcing SSL
1797 1902
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1798
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1799
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1903
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1904
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1905
+	}
1800 1906
 
1801 1907
 	// Check to see if they're accessing it from the wrong place.
1802 1908
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1804,8 +1910,9 @@  discard block
 block discarded – undo
1804 1910
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1805 1911
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1806 1912
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1807
-		if ($temp != '/')
1808
-			$detected_url .= $temp;
1913
+		if ($temp != '/') {
1914
+					$detected_url .= $temp;
1915
+		}
1809 1916
 	}
1810 1917
 	if (isset($detected_url) && $detected_url != $boardurl)
1811 1918
 	{
@@ -1817,8 +1924,9 @@  discard block
 block discarded – undo
1817 1924
 			foreach ($aliases as $alias)
1818 1925
 			{
1819 1926
 				// Rip off all the boring parts, spaces, etc.
1820
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1821
-					$do_fix = true;
1927
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1928
+									$do_fix = true;
1929
+				}
1822 1930
 			}
1823 1931
 		}
1824 1932
 
@@ -1826,20 +1934,22 @@  discard block
 block discarded – undo
1826 1934
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1827 1935
 		{
1828 1936
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1829
-			if (empty($_GET))
1830
-				redirectexit('wwwRedirect');
1831
-			else
1937
+			if (empty($_GET)) {
1938
+							redirectexit('wwwRedirect');
1939
+			} else
1832 1940
 			{
1833 1941
 				list ($k, $v) = each($_GET);
1834 1942
 
1835
-				if ($k != 'wwwRedirect')
1836
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1943
+				if ($k != 'wwwRedirect') {
1944
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1945
+				}
1837 1946
 			}
1838 1947
 		}
1839 1948
 
1840 1949
 		// #3 is just a check for SSL...
1841
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1842
-			$do_fix = true;
1950
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1951
+					$do_fix = true;
1952
+		}
1843 1953
 
1844 1954
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1845 1955
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1873,8 +1983,9 @@  discard block
 block discarded – undo
1873 1983
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1874 1984
 				}
1875 1985
 			}
1876
-			foreach ($context['linktree'] as $k => $dummy)
1877
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1986
+			foreach ($context['linktree'] as $k => $dummy) {
1987
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1988
+			}
1878 1989
 		}
1879 1990
 	}
1880 1991
 	// Set up the contextual user array.
@@ -1893,16 +2004,16 @@  discard block
 block discarded – undo
1893 2004
 			'email' => $user_info['email'],
1894 2005
 			'ignoreusers' => $user_info['ignoreusers'],
1895 2006
 		);
1896
-		if (!$context['user']['is_guest'])
1897
-			$context['user']['name'] = $user_info['name'];
1898
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1899
-			$context['user']['name'] = $txt['guest_title'];
2007
+		if (!$context['user']['is_guest']) {
2008
+					$context['user']['name'] = $user_info['name'];
2009
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2010
+					$context['user']['name'] = $txt['guest_title'];
2011
+		}
1900 2012
 
1901 2013
 		// Determine the current smiley set.
1902 2014
 		$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'];
1903 2015
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1904
-	}
1905
-	else
2016
+	} else
1906 2017
 	{
1907 2018
 		$context['user'] = array(
1908 2019
 			'id' => -1,
@@ -1918,18 +2029,24 @@  discard block
 block discarded – undo
1918 2029
 	}
1919 2030
 
1920 2031
 	// Some basic information...
1921
-	if (!isset($context['html_headers']))
1922
-		$context['html_headers'] = '';
1923
-	if (!isset($context['javascript_files']))
1924
-		$context['javascript_files'] = array();
1925
-	if (!isset($context['css_files']))
1926
-		$context['css_files'] = array();
1927
-	if (!isset($context['css_header']))
1928
-		$context['css_header'] = array();
1929
-	if (!isset($context['javascript_inline']))
1930
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1931
-	if (!isset($context['javascript_vars']))
1932
-		$context['javascript_vars'] = array();
2032
+	if (!isset($context['html_headers'])) {
2033
+			$context['html_headers'] = '';
2034
+	}
2035
+	if (!isset($context['javascript_files'])) {
2036
+			$context['javascript_files'] = array();
2037
+	}
2038
+	if (!isset($context['css_files'])) {
2039
+			$context['css_files'] = array();
2040
+	}
2041
+	if (!isset($context['css_header'])) {
2042
+			$context['css_header'] = array();
2043
+	}
2044
+	if (!isset($context['javascript_inline'])) {
2045
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2046
+	}
2047
+	if (!isset($context['javascript_vars'])) {
2048
+			$context['javascript_vars'] = array();
2049
+	}
1933 2050
 
1934 2051
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1935 2052
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1941,8 +2058,9 @@  discard block
 block discarded – undo
1941 2058
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1942 2059
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1943 2060
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1944
-	if (isset($modSettings['load_average']))
1945
-		$context['load_average'] = $modSettings['load_average'];
2061
+	if (isset($modSettings['load_average'])) {
2062
+			$context['load_average'] = $modSettings['load_average'];
2063
+	}
1946 2064
 
1947 2065
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1948 2066
 	detectBrowser();
@@ -1956,8 +2074,9 @@  discard block
 block discarded – undo
1956 2074
 	// This allows sticking some HTML on the page output - useful for controls.
1957 2075
 	$context['insert_after_template'] = '';
1958 2076
 
1959
-	if (!isset($txt))
1960
-		$txt = array();
2077
+	if (!isset($txt)) {
2078
+			$txt = array();
2079
+	}
1961 2080
 
1962 2081
 	$simpleActions = array(
1963 2082
 		'findmember',
@@ -2003,9 +2122,10 @@  discard block
 block discarded – undo
2003 2122
 
2004 2123
 	// See if theres any extra param to check.
2005 2124
 	$requiresXML = false;
2006
-	foreach ($extraParams as $key => $extra)
2007
-		if (isset($_REQUEST[$extra]))
2125
+	foreach ($extraParams as $key => $extra) {
2126
+			if (isset($_REQUEST[$extra]))
2008 2127
 			$requiresXML = true;
2128
+	}
2009 2129
 
2010 2130
 	// Output is fully XML, so no need for the index template.
2011 2131
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2020,37 +2140,39 @@  discard block
 block discarded – undo
2020 2140
 	{
2021 2141
 		loadLanguage('index+Modifications');
2022 2142
 		$context['template_layers'] = array();
2023
-	}
2024
-
2025
-	else
2143
+	} else
2026 2144
 	{
2027 2145
 		// Custom templates to load, or just default?
2028
-		if (isset($settings['theme_templates']))
2029
-			$templates = explode(',', $settings['theme_templates']);
2030
-		else
2031
-			$templates = array('index');
2146
+		if (isset($settings['theme_templates'])) {
2147
+					$templates = explode(',', $settings['theme_templates']);
2148
+		} else {
2149
+					$templates = array('index');
2150
+		}
2032 2151
 
2033 2152
 		// Load each template...
2034
-		foreach ($templates as $template)
2035
-			loadTemplate($template);
2153
+		foreach ($templates as $template) {
2154
+					loadTemplate($template);
2155
+		}
2036 2156
 
2037 2157
 		// ...and attempt to load their associated language files.
2038 2158
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2039 2159
 		loadLanguage($required_files, '', false);
2040 2160
 
2041 2161
 		// Custom template layers?
2042
-		if (isset($settings['theme_layers']))
2043
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2044
-		else
2045
-			$context['template_layers'] = array('html', 'body');
2162
+		if (isset($settings['theme_layers'])) {
2163
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2164
+		} else {
2165
+					$context['template_layers'] = array('html', 'body');
2166
+		}
2046 2167
 	}
2047 2168
 
2048 2169
 	// Initialize the theme.
2049 2170
 	loadSubTemplate('init', 'ignore');
2050 2171
 
2051 2172
 	// Allow overriding the board wide time/number formats.
2052
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2053
-		$user_info['time_format'] = $txt['time_format'];
2173
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2174
+			$user_info['time_format'] = $txt['time_format'];
2175
+	}
2054 2176
 
2055 2177
 	// Set the character set from the template.
2056 2178
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2058,12 +2180,14 @@  discard block
 block discarded – undo
2058 2180
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2059 2181
 
2060 2182
 	// Guests may still need a name.
2061
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2062
-		$context['user']['name'] = $txt['guest_title'];
2183
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2184
+			$context['user']['name'] = $txt['guest_title'];
2185
+	}
2063 2186
 
2064 2187
 	// Any theme-related strings that need to be loaded?
2065
-	if (!empty($settings['require_theme_strings']))
2066
-		loadLanguage('ThemeStrings', '', false);
2188
+	if (!empty($settings['require_theme_strings'])) {
2189
+			loadLanguage('ThemeStrings', '', false);
2190
+	}
2067 2191
 
2068 2192
 	// Make a special URL for the language.
2069 2193
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2074,8 +2198,9 @@  discard block
 block discarded – undo
2074 2198
 	// Here is my luvly Responsive CSS
2075 2199
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2076 2200
 
2077
-	if ($context['right_to_left'])
2078
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2201
+	if ($context['right_to_left']) {
2202
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2203
+	}
2079 2204
 
2080 2205
 	// We allow theme variants, because we're cool.
2081 2206
 	$context['theme_variant'] = '';
@@ -2083,14 +2208,17 @@  discard block
 block discarded – undo
2083 2208
 	if (!empty($settings['theme_variants']))
2084 2209
 	{
2085 2210
 		// Overriding - for previews and that ilk.
2086
-		if (!empty($_REQUEST['variant']))
2087
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2211
+		if (!empty($_REQUEST['variant'])) {
2212
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2213
+		}
2088 2214
 		// User selection?
2089
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2090
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2215
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2216
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2217
+		}
2091 2218
 		// If not a user variant, select the default.
2092
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2093
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2219
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2220
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2221
+		}
2094 2222
 
2095 2223
 		// Do this to keep things easier in the templates.
2096 2224
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2099,20 +2227,23 @@  discard block
 block discarded – undo
2099 2227
 		if (!empty($context['theme_variant']))
2100 2228
 		{
2101 2229
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2102
-			if ($context['right_to_left'])
2103
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2230
+			if ($context['right_to_left']) {
2231
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2232
+			}
2104 2233
 		}
2105 2234
 	}
2106 2235
 
2107 2236
 	// Let's be compatible with old themes!
2108
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2109
-		$context['template_layers'] = array('main');
2237
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2238
+			$context['template_layers'] = array('main');
2239
+	}
2110 2240
 
2111 2241
 	$context['tabindex'] = 1;
2112 2242
 
2113 2243
 	// Compatibility.
2114
-	if (!isset($settings['theme_version']))
2115
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2244
+	if (!isset($settings['theme_version'])) {
2245
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2246
+	}
2116 2247
 
2117 2248
 	// Default JS variables for use in every theme
2118 2249
 	$context['javascript_vars'] = array(
@@ -2131,18 +2262,18 @@  discard block
 block discarded – undo
2131 2262
 	);
2132 2263
 
2133 2264
 	// Add the JQuery library to the list of files to load.
2134
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2135
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2136
-
2137
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2138
-		loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2139
-
2140
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2141
-		loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2265
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2266
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2267
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2268
+			loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2269
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2270
+			loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2271
+	}
2142 2272
 
2143 2273
 	// Auto loading? template_javascript() will take care of the local half of this.
2144
-	else
2145
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2274
+	else {
2275
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2276
+	}
2146 2277
 
2147 2278
 	// Queue our JQuery plugins!
2148 2279
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2165,12 +2296,12 @@  discard block
 block discarded – undo
2165 2296
 			require_once($sourcedir . '/ScheduledTasks.php');
2166 2297
 
2167 2298
 			// What to do, what to do?!
2168
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2169
-				AutoTask();
2170
-			else
2171
-				ReduceMailQueue();
2172
-		}
2173
-		else
2299
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2300
+							AutoTask();
2301
+			} else {
2302
+							ReduceMailQueue();
2303
+			}
2304
+		} else
2174 2305
 		{
2175 2306
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2176 2307
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2221,8 +2352,9 @@  discard block
 block discarded – undo
2221 2352
 		foreach ($theme_includes as $include)
2222 2353
 		{
2223 2354
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2224
-			if (file_exists($include))
2225
-				require_once($include);
2355
+			if (file_exists($include)) {
2356
+							require_once($include);
2357
+			}
2226 2358
 		}
2227 2359
 	}
2228 2360
 
@@ -2252,16 +2384,19 @@  discard block
 block discarded – undo
2252 2384
 	// Do any style sheets first, cause we're easy with those.
2253 2385
 	if (!empty($style_sheets))
2254 2386
 	{
2255
-		if (!is_array($style_sheets))
2256
-			$style_sheets = array($style_sheets);
2387
+		if (!is_array($style_sheets)) {
2388
+					$style_sheets = array($style_sheets);
2389
+		}
2257 2390
 
2258
-		foreach ($style_sheets as $sheet)
2259
-			loadCSSFile($sheet . '.css', array(), $sheet);
2391
+		foreach ($style_sheets as $sheet) {
2392
+					loadCSSFile($sheet . '.css', array(), $sheet);
2393
+		}
2260 2394
 	}
2261 2395
 
2262 2396
 	// No template to load?
2263
-	if ($template_name === false)
2264
-		return true;
2397
+	if ($template_name === false) {
2398
+			return true;
2399
+	}
2265 2400
 
2266 2401
 	$loaded = false;
2267 2402
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2276,12 +2411,14 @@  discard block
 block discarded – undo
2276 2411
 
2277 2412
 	if ($loaded)
2278 2413
 	{
2279
-		if ($db_show_debug === true)
2280
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2414
+		if ($db_show_debug === true) {
2415
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2416
+		}
2281 2417
 
2282 2418
 		// If they have specified an initialization function for this template, go ahead and call it now.
2283
-		if (function_exists('template_' . $template_name . '_init'))
2284
-			call_user_func('template_' . $template_name . '_init');
2419
+		if (function_exists('template_' . $template_name . '_init')) {
2420
+					call_user_func('template_' . $template_name . '_init');
2421
+		}
2285 2422
 	}
2286 2423
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2287 2424
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2301,13 +2438,14 @@  discard block
 block discarded – undo
2301 2438
 		loadTemplate($template_name);
2302 2439
 	}
2303 2440
 	// Cause an error otherwise.
2304
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2305
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2306
-	elseif ($fatal)
2307
-		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'));
2308
-	else
2309
-		return false;
2310
-}
2441
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2442
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2443
+	} elseif ($fatal) {
2444
+			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'));
2445
+	} else {
2446
+			return false;
2447
+	}
2448
+	}
2311 2449
 
2312 2450
 /**
2313 2451
  * Load a sub-template.
@@ -2325,17 +2463,19 @@  discard block
 block discarded – undo
2325 2463
 {
2326 2464
 	global $context, $txt, $db_show_debug;
2327 2465
 
2328
-	if ($db_show_debug === true)
2329
-		$context['debug']['sub_templates'][] = $sub_template_name;
2466
+	if ($db_show_debug === true) {
2467
+			$context['debug']['sub_templates'][] = $sub_template_name;
2468
+	}
2330 2469
 
2331 2470
 	// Figure out what the template function is named.
2332 2471
 	$theme_function = 'template_' . $sub_template_name;
2333
-	if (function_exists($theme_function))
2334
-		$theme_function();
2335
-	elseif ($fatal === false)
2336
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2337
-	elseif ($fatal !== 'ignore')
2338
-		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'));
2472
+	if (function_exists($theme_function)) {
2473
+			$theme_function();
2474
+	} elseif ($fatal === false) {
2475
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2476
+	} elseif ($fatal !== 'ignore') {
2477
+			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'));
2478
+	}
2339 2479
 
2340 2480
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2341 2481
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2372,8 +2512,9 @@  discard block
 block discarded – undo
2372 2512
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2373 2513
 
2374 2514
 	// If this is an external file, automatically set this to false.
2375
-	if (!empty($params['external']))
2376
-		$params['minimize'] = false;
2515
+	if (!empty($params['external'])) {
2516
+			$params['minimize'] = false;
2517
+	}
2377 2518
 
2378 2519
 	// Account for shorthand like admin.css?alp21 filenames
2379 2520
 	$has_seed = strpos($fileName, '.css?');
@@ -2390,13 +2531,10 @@  discard block
 block discarded – undo
2390 2531
 			{
2391 2532
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2392 2533
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2534
+			} else {
2535
+							$fileUrl = false;
2393 2536
 			}
2394
-
2395
-			else
2396
-				$fileUrl = false;
2397
-		}
2398
-
2399
-		else
2537
+		} else
2400 2538
 		{
2401 2539
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2402 2540
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2411,12 +2549,14 @@  discard block
 block discarded – undo
2411 2549
 	}
2412 2550
 
2413 2551
 	// Add it to the array for use in the template
2414
-	if (!empty($fileName))
2415
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2552
+	if (!empty($fileName)) {
2553
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2554
+	}
2416 2555
 
2417
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2418
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2419
-}
2556
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2557
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2558
+	}
2559
+	}
2420 2560
 
2421 2561
 /**
2422 2562
  * Add a block of inline css code to be executed later
@@ -2433,8 +2573,9 @@  discard block
 block discarded – undo
2433 2573
 	global $context;
2434 2574
 
2435 2575
 	// Gotta add something...
2436
-	if (empty($css))
2437
-		return false;
2576
+	if (empty($css)) {
2577
+			return false;
2578
+	}
2438 2579
 
2439 2580
 	$context['css_header'][] = $css;
2440 2581
 }
@@ -2469,8 +2610,9 @@  discard block
 block discarded – undo
2469 2610
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2470 2611
 
2471 2612
 	// If this is an external file, automatically set this to false.
2472
-	if (!empty($params['external']))
2473
-		$params['minimize'] = false;
2613
+	if (!empty($params['external'])) {
2614
+			$params['minimize'] = false;
2615
+	}
2474 2616
 
2475 2617
 	// Account for shorthand like admin.js?alp21 filenames
2476 2618
 	$has_seed = strpos($fileName, '.js?');
@@ -2487,16 +2629,12 @@  discard block
 block discarded – undo
2487 2629
 			{
2488 2630
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2489 2631
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2490
-			}
2491
-
2492
-			else
2632
+			} else
2493 2633
 			{
2494 2634
 				$fileUrl = false;
2495 2635
 				$filePath = false;
2496 2636
 			}
2497
-		}
2498
-
2499
-		else
2637
+		} else
2500 2638
 		{
2501 2639
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2502 2640
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2511,9 +2649,10 @@  discard block
 block discarded – undo
2511 2649
 	}
2512 2650
 
2513 2651
 	// Add it to the array for use in the template
2514
-	if (!empty($fileName))
2515
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2516
-}
2652
+	if (!empty($fileName)) {
2653
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2654
+	}
2655
+	}
2517 2656
 
2518 2657
 /**
2519 2658
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2527,9 +2666,10 @@  discard block
 block discarded – undo
2527 2666
 {
2528 2667
 	global $context;
2529 2668
 
2530
-	if (!empty($key) && (!empty($value) || $value === '0'))
2531
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2532
-}
2669
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2670
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2671
+	}
2672
+	}
2533 2673
 
2534 2674
 /**
2535 2675
  * Add a block of inline Javascript code to be executed later
@@ -2546,8 +2686,9 @@  discard block
 block discarded – undo
2546 2686
 {
2547 2687
 	global $context;
2548 2688
 
2549
-	if (empty($javascript))
2550
-		return false;
2689
+	if (empty($javascript)) {
2690
+			return false;
2691
+	}
2551 2692
 
2552 2693
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2553 2694
 }
@@ -2568,15 +2709,18 @@  discard block
 block discarded – undo
2568 2709
 	static $already_loaded = array();
2569 2710
 
2570 2711
 	// Default to the user's language.
2571
-	if ($lang == '')
2572
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2712
+	if ($lang == '') {
2713
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2714
+	}
2573 2715
 
2574 2716
 	// Do we want the English version of language file as fallback?
2575
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2576
-		loadLanguage($template_name, 'english', false);
2717
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2718
+			loadLanguage($template_name, 'english', false);
2719
+	}
2577 2720
 
2578
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2579
-		return $lang;
2721
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2722
+			return $lang;
2723
+	}
2580 2724
 
2581 2725
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2582 2726
 	if (empty($settings['default_theme_dir']))
@@ -2587,8 +2731,9 @@  discard block
 block discarded – undo
2587 2731
 
2588 2732
 	// What theme are we in?
2589 2733
 	$theme_name = basename($settings['theme_url']);
2590
-	if (empty($theme_name))
2591
-		$theme_name = 'unknown';
2734
+	if (empty($theme_name)) {
2735
+			$theme_name = 'unknown';
2736
+	}
2592 2737
 
2593 2738
 	// For each file open it up and write it out!
2594 2739
 	foreach (explode('+', $template_name) as $template)
@@ -2667,8 +2812,9 @@  discard block
 block discarded – undo
2667 2812
 	}
2668 2813
 
2669 2814
 	// Keep track of what we're up to soldier.
2670
-	if ($db_show_debug === true)
2671
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2815
+	if ($db_show_debug === true) {
2816
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2817
+	}
2672 2818
 
2673 2819
 	// Remember what we have loaded, and in which language.
2674 2820
 	$already_loaded[$template_name] = $lang;
@@ -2714,8 +2860,9 @@  discard block
 block discarded – undo
2714 2860
 				)
2715 2861
 			);
2716 2862
 			// In the EXTREMELY unlikely event this happens, give an error message.
2717
-			if ($smcFunc['db_num_rows']($result) == 0)
2718
-				fatal_lang_error('parent_not_found', 'critical');
2863
+			if ($smcFunc['db_num_rows']($result) == 0) {
2864
+							fatal_lang_error('parent_not_found', 'critical');
2865
+			}
2719 2866
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2720 2867
 			{
2721 2868
 				if (!isset($boards[$row['id_board']]))
@@ -2732,8 +2879,8 @@  discard block
 block discarded – undo
2732 2879
 					);
2733 2880
 				}
2734 2881
 				// If a moderator exists for this board, add that moderator for all children too.
2735
-				if (!empty($row['id_moderator']))
2736
-					foreach ($boards as $id => $dummy)
2882
+				if (!empty($row['id_moderator'])) {
2883
+									foreach ($boards as $id => $dummy)
2737 2884
 					{
2738 2885
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2739 2886
 							'id' => $row['id_moderator'],
@@ -2741,11 +2888,12 @@  discard block
 block discarded – undo
2741 2888
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2742 2889
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2743 2890
 						);
2891
+				}
2744 2892
 					}
2745 2893
 
2746 2894
 				// If a moderator group exists for this board, add that moderator group for all children too
2747
-				if (!empty($row['id_moderator_group']))
2748
-					foreach ($boards as $id => $dummy)
2895
+				if (!empty($row['id_moderator_group'])) {
2896
+									foreach ($boards as $id => $dummy)
2749 2897
 					{
2750 2898
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2751 2899
 							'id' => $row['id_moderator_group'],
@@ -2753,6 +2901,7 @@  discard block
 block discarded – undo
2753 2901
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2754 2902
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2755 2903
 						);
2904
+				}
2756 2905
 					}
2757 2906
 			}
2758 2907
 			$smcFunc['db_free_result']($result);
@@ -2780,23 +2929,27 @@  discard block
 block discarded – undo
2780 2929
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2781 2930
 	{
2782 2931
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2783
-		if (empty($smcFunc['ucwords']))
2784
-			reloadSettings();
2932
+		if (empty($smcFunc['ucwords'])) {
2933
+					reloadSettings();
2934
+		}
2785 2935
 
2786 2936
 		// If we don't have our theme information yet, let's get it.
2787
-		if (empty($settings['default_theme_dir']))
2788
-			loadTheme(0, false);
2937
+		if (empty($settings['default_theme_dir'])) {
2938
+					loadTheme(0, false);
2939
+		}
2789 2940
 
2790 2941
 		// Default language directories to try.
2791 2942
 		$language_directories = array(
2792 2943
 			$settings['default_theme_dir'] . '/languages',
2793 2944
 		);
2794
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2795
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2945
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2946
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2947
+		}
2796 2948
 
2797 2949
 		// We possibly have a base theme directory.
2798
-		if (!empty($settings['base_theme_dir']))
2799
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2950
+		if (!empty($settings['base_theme_dir'])) {
2951
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2952
+		}
2800 2953
 
2801 2954
 		// Remove any duplicates.
2802 2955
 		$language_directories = array_unique($language_directories);
@@ -2810,20 +2963,21 @@  discard block
 block discarded – undo
2810 2963
 		foreach ($language_directories as $language_dir)
2811 2964
 		{
2812 2965
 			// Can't look in here... doesn't exist!
2813
-			if (!file_exists($language_dir))
2814
-				continue;
2966
+			if (!file_exists($language_dir)) {
2967
+							continue;
2968
+			}
2815 2969
 
2816 2970
 			$dir = dir($language_dir);
2817 2971
 			while ($entry = $dir->read())
2818 2972
 			{
2819 2973
 				// Look for the index language file....
2820
-				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches))
2821
-					continue;
2822
-
2823
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2824
-					$langName = $langList[$matches[1]];
2974
+				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) {
2975
+									continue;
2976
+				}
2825 2977
 
2826
-				else
2978
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
2979
+									$langName = $langList[$matches[1]];
2980
+				} else
2827 2981
 				{
2828 2982
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2829 2983
 
@@ -2866,20 +3020,23 @@  discard block
 block discarded – undo
2866 3020
 		}
2867 3021
 
2868 3022
 		// Do we need to store the lang list?
2869
-		if (empty($langList))
2870
-			updateSettings(array('langList' => json_encode($catchLang)));
3023
+		if (empty($langList)) {
3024
+					updateSettings(array('langList' => json_encode($catchLang)));
3025
+		}
2871 3026
 
2872 3027
 		// Favoring UTF8? Then prevent us from selecting non-UTF8 versions.
2873 3028
 		if ($favor_utf8)
2874 3029
 		{
2875
-			foreach ($context['languages'] as $lang)
2876
-				if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
3030
+			foreach ($context['languages'] as $lang) {
3031
+							if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2877 3032
 					unset($context['languages'][$lang['filename']]);
3033
+			}
2878 3034
 		}
2879 3035
 
2880 3036
 		// Let's cash in on this deal.
2881
-		if (!empty($modSettings['cache_enable']))
2882
-			cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3037
+		if (!empty($modSettings['cache_enable'])) {
3038
+					cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3039
+		}
2883 3040
 	}
2884 3041
 
2885 3042
 	return $context['languages'];
@@ -2902,8 +3059,9 @@  discard block
 block discarded – undo
2902 3059
 	global $modSettings, $options, $txt;
2903 3060
 	static $censor_vulgar = null, $censor_proper;
2904 3061
 
2905
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2906
-		return $text;
3062
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3063
+			return $text;
3064
+	}
2907 3065
 
2908 3066
 	// If they haven't yet been loaded, load them.
2909 3067
 	if ($censor_vulgar == null)
@@ -2931,9 +3089,9 @@  discard block
 block discarded – undo
2931 3089
 	{
2932 3090
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2933 3091
 		$text = $func($censor_vulgar, $censor_proper, $text);
3092
+	} else {
3093
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2934 3094
 	}
2935
-	else
2936
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2937 3095
 
2938 3096
 	return $text;
2939 3097
 }
@@ -2959,38 +3117,42 @@  discard block
 block discarded – undo
2959 3117
 	@ini_set('track_errors', '1');
2960 3118
 
2961 3119
 	// Don't include the file more than once, if $once is true.
2962
-	if ($once && in_array($filename, $templates))
2963
-		return;
3120
+	if ($once && in_array($filename, $templates)) {
3121
+			return;
3122
+	}
2964 3123
 	// Add this file to the include list, whether $once is true or not.
2965
-	else
2966
-		$templates[] = $filename;
3124
+	else {
3125
+			$templates[] = $filename;
3126
+	}
2967 3127
 
2968 3128
 	// Are we going to use eval?
2969 3129
 	if (empty($modSettings['disableTemplateEval']))
2970 3130
 	{
2971 3131
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2972 3132
 		$settings['current_include_filename'] = $filename;
2973
-	}
2974
-	else
3133
+	} else
2975 3134
 	{
2976 3135
 		$file_found = file_exists($filename);
2977 3136
 
2978
-		if ($once && $file_found)
2979
-			require_once($filename);
2980
-		elseif ($file_found)
2981
-			require($filename);
3137
+		if ($once && $file_found) {
3138
+					require_once($filename);
3139
+		} elseif ($file_found) {
3140
+					require($filename);
3141
+		}
2982 3142
 	}
2983 3143
 
2984 3144
 	if ($file_found !== true)
2985 3145
 	{
2986 3146
 		ob_end_clean();
2987
-		if (!empty($modSettings['enableCompressedOutput']))
2988
-			@ob_start('ob_gzhandler');
2989
-		else
2990
-			ob_start();
3147
+		if (!empty($modSettings['enableCompressedOutput'])) {
3148
+					@ob_start('ob_gzhandler');
3149
+		} else {
3150
+					ob_start();
3151
+		}
2991 3152
 
2992
-		if (isset($_GET['debug']))
2993
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3153
+		if (isset($_GET['debug'])) {
3154
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3155
+		}
2994 3156
 
2995 3157
 		// Don't cache error pages!!
2996 3158
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3009,12 +3171,13 @@  discard block
 block discarded – undo
3009 3171
 		echo '<!DOCTYPE html>
3010 3172
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3011 3173
 	<head>';
3012
-		if (isset($context['character_set']))
3013
-			echo '
3174
+		if (isset($context['character_set'])) {
3175
+					echo '
3014 3176
 		<meta charset="', $context['character_set'], '">';
3177
+		}
3015 3178
 
3016
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3017
-			echo '
3179
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3180
+					echo '
3018 3181
 		<title>', $mtitle, '</title>
3019 3182
 	</head>
3020 3183
 	<body>
@@ -3022,8 +3185,8 @@  discard block
 block discarded – undo
3022 3185
 		', $mmessage, '
3023 3186
 	</body>
3024 3187
 </html>';
3025
-		elseif (!allowedTo('admin_forum'))
3026
-			echo '
3188
+		} elseif (!allowedTo('admin_forum')) {
3189
+					echo '
3027 3190
 		<title>', $txt['template_parse_error'], '</title>
3028 3191
 	</head>
3029 3192
 	<body>
@@ -3031,15 +3194,17 @@  discard block
 block discarded – undo
3031 3194
 		', $txt['template_parse_error_message'], '
3032 3195
 	</body>
3033 3196
 </html>';
3034
-		else
3197
+		} else
3035 3198
 		{
3036 3199
 			require_once($sourcedir . '/Subs-Package.php');
3037 3200
 
3038 3201
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3039
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3040
-				$error = $php_errormsg;
3041
-			if (empty($error))
3042
-				$error = $txt['template_parse_errmsg'];
3202
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3203
+							$error = $php_errormsg;
3204
+			}
3205
+			if (empty($error)) {
3206
+							$error = $txt['template_parse_errmsg'];
3207
+			}
3043 3208
 
3044 3209
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3045 3210
 
@@ -3050,11 +3215,12 @@  discard block
 block discarded – undo
3050 3215
 		<h3>', $txt['template_parse_error'], '</h3>
3051 3216
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3052 3217
 
3053
-			if (!empty($error))
3054
-				echo '
3218
+			if (!empty($error)) {
3219
+							echo '
3055 3220
 		<hr>
3056 3221
 
3057 3222
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3223
+			}
3058 3224
 
3059 3225
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3060 3226
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3064,10 +3230,11 @@  discard block
 block discarded – undo
3064 3230
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3065 3231
 
3066 3232
 				// Fix the PHP code stuff...
3067
-				if (!isBrowser('gecko'))
3068
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3069
-				else
3070
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3233
+				if (!isBrowser('gecko')) {
3234
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3235
+				} else {
3236
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3237
+				}
3071 3238
 
3072 3239
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3073 3240
 				$j = -1;
@@ -3075,8 +3242,9 @@  discard block
 block discarded – undo
3075 3242
 				{
3076 3243
 					$j++;
3077 3244
 
3078
-					if (substr_count($line, '<br>') == 0)
3079
-						continue;
3245
+					if (substr_count($line, '<br>') == 0) {
3246
+											continue;
3247
+					}
3080 3248
 
3081 3249
 					$n = substr_count($line, '<br>');
3082 3250
 					for ($i = 0; $i < $n; $i++)
@@ -3095,38 +3263,42 @@  discard block
 block discarded – undo
3095 3263
 				// Figure out what the color coding was before...
3096 3264
 				$line = max($match[1] - 9, 1);
3097 3265
 				$last_line = '';
3098
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3099
-					if (strpos($data2[$line2], '<') !== false)
3266
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3267
+									if (strpos($data2[$line2], '<') !== false)
3100 3268
 					{
3101 3269
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3102 3270
 							$last_line = $color_match[1];
3271
+				}
3103 3272
 						break;
3104 3273
 					}
3105 3274
 
3106 3275
 				// Show the relevant lines...
3107 3276
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3108 3277
 				{
3109
-					if ($line == $match[1])
3110
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3278
+					if ($line == $match[1]) {
3279
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3280
+					}
3111 3281
 
3112 3282
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3113
-					if (isset($data2[$line]) && $data2[$line] != '')
3114
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3283
+					if (isset($data2[$line]) && $data2[$line] != '') {
3284
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3285
+					}
3115 3286
 
3116 3287
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3117 3288
 					{
3118 3289
 						$last_line = $color_match[1];
3119 3290
 						echo '</', substr($last_line, 1, 4), '>';
3291
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3292
+											$last_line = '';
3293
+					} elseif ($last_line != '' && $data2[$line] != '') {
3294
+											echo '</', substr($last_line, 1, 4), '>';
3120 3295
 					}
3121
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3122
-						$last_line = '';
3123
-					elseif ($last_line != '' && $data2[$line] != '')
3124
-						echo '</', substr($last_line, 1, 4), '>';
3125 3296
 
3126
-					if ($line == $match[1])
3127
-						echo '</pre></div><pre style="margin: 0;">';
3128
-					else
3129
-						echo "\n";
3297
+					if ($line == $match[1]) {
3298
+											echo '</pre></div><pre style="margin: 0;">';
3299
+					} else {
3300
+											echo "\n";
3301
+					}
3130 3302
 				}
3131 3303
 
3132 3304
 				echo '</pre></div>';
@@ -3150,8 +3322,9 @@  discard block
 block discarded – undo
3150 3322
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3151 3323
 
3152 3324
 	// Figure out what type of database we are using.
3153
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3154
-		$db_type = 'mysql';
3325
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3326
+			$db_type = 'mysql';
3327
+	}
3155 3328
 
3156 3329
 	// Load the file for the database.
3157 3330
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3159,8 +3332,9 @@  discard block
 block discarded – undo
3159 3332
 	$db_options = array();
3160 3333
 
3161 3334
 	// Add in the port if needed
3162
-	if (!empty($db_port))
3163
-		$db_options['port'] = $db_port;
3335
+	if (!empty($db_port)) {
3336
+			$db_options['port'] = $db_port;
3337
+	}
3164 3338
 
3165 3339
 	// 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.
3166 3340
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3179,13 +3353,15 @@  discard block
 block discarded – undo
3179 3353
 	}
3180 3354
 
3181 3355
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3182
-	if (!$db_connection)
3183
-		display_db_error();
3356
+	if (!$db_connection) {
3357
+			display_db_error();
3358
+	}
3184 3359
 
3185 3360
 	// If in SSI mode fix up the prefix.
3186
-	if (SMF == 'SSI')
3187
-		db_fix_prefix($db_prefix, $db_name);
3188
-}
3361
+	if (SMF == 'SSI') {
3362
+			db_fix_prefix($db_prefix, $db_name);
3363
+	}
3364
+	}
3189 3365
 
3190 3366
 /**
3191 3367
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3199,10 +3375,11 @@  discard block
 block discarded – undo
3199 3375
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3200 3376
 
3201 3377
 	// Not overriding this and we have a cacheAPI, send it back.
3202
-	if (empty($overrideCache) && is_object($cacheAPI))
3203
-		return $cacheAPI;
3204
-	elseif (is_null($cacheAPI))
3205
-		$cacheAPI = false;
3378
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3379
+			return $cacheAPI;
3380
+	} elseif (is_null($cacheAPI)) {
3381
+			$cacheAPI = false;
3382
+	}
3206 3383
 
3207 3384
 	// Make sure our class is in session.
3208 3385
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3223,8 +3400,9 @@  discard block
 block discarded – undo
3223 3400
 		if (!$testAPI->isSupported())
3224 3401
 		{
3225 3402
 			// Can we save ourselves?
3226
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3227
-				return loadCacheAccelerator(null, false);
3403
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3404
+							return loadCacheAccelerator(null, false);
3405
+			}
3228 3406
 			return false;
3229 3407
 		}
3230 3408
 
@@ -3236,9 +3414,9 @@  discard block
 block discarded – undo
3236 3414
 		{
3237 3415
 			$cacheAPI = $testAPI;
3238 3416
 			return $cacheAPI;
3417
+		} else {
3418
+					return $testAPI;
3239 3419
 		}
3240
-		else
3241
-			return $testAPI;
3242 3420
 	}
3243 3421
 }
3244 3422
 
@@ -3258,8 +3436,9 @@  discard block
 block discarded – undo
3258 3436
 
3259 3437
 	// @todo Why are we doing this if caching is disabled?
3260 3438
 
3261
-	if (function_exists('call_integration_hook'))
3262
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3439
+	if (function_exists('call_integration_hook')) {
3440
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3441
+	}
3263 3442
 
3264 3443
 	/* Refresh the cache if either:
3265 3444
 		1. Caching is disabled.
@@ -3273,16 +3452,19 @@  discard block
 block discarded – undo
3273 3452
 		require_once($sourcedir . '/' . $file);
3274 3453
 		$cache_block = call_user_func_array($function, $params);
3275 3454
 
3276
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3277
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3455
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3456
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3457
+		}
3278 3458
 	}
3279 3459
 
3280 3460
 	// Some cached data may need a freshening up after retrieval.
3281
-	if (!empty($cache_block['post_retri_eval']))
3282
-		eval($cache_block['post_retri_eval']);
3461
+	if (!empty($cache_block['post_retri_eval'])) {
3462
+			eval($cache_block['post_retri_eval']);
3463
+	}
3283 3464
 
3284
-	if (function_exists('call_integration_hook'))
3285
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3465
+	if (function_exists('call_integration_hook')) {
3466
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3467
+	}
3286 3468
 
3287 3469
 	return $cache_block['data'];
3288 3470
 }
@@ -3309,8 +3491,9 @@  discard block
 block discarded – undo
3309 3491
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3310 3492
 	global $cache_hits, $cache_count, $db_show_debug;
3311 3493
 
3312
-	if (empty($cache_enable) || empty($cacheAPI))
3313
-		return;
3494
+	if (empty($cache_enable) || empty($cacheAPI)) {
3495
+			return;
3496
+	}
3314 3497
 
3315 3498
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3316 3499
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3323,12 +3506,14 @@  discard block
 block discarded – undo
3323 3506
 	$value = $value === null ? null : json_encode($value);
3324 3507
 	$result = $cacheAPI->putData($key, $value, $ttl);
3325 3508
 
3326
-	if (function_exists('call_integration_hook'))
3327
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3509
+	if (function_exists('call_integration_hook')) {
3510
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3511
+	}
3328 3512
 
3329
-	if (isset($db_show_debug) && $db_show_debug === true)
3330
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3331
-}
3513
+	if (isset($db_show_debug) && $db_show_debug === true) {
3514
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3515
+	}
3516
+	}
3332 3517
 
3333 3518
 /**
3334 3519
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3344,8 +3529,9 @@  discard block
 block discarded – undo
3344 3529
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3345 3530
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3346 3531
 
3347
-	if (empty($cache_enable) || empty($cacheAPI))
3348
-		return;
3532
+	if (empty($cache_enable) || empty($cacheAPI)) {
3533
+			return;
3534
+	}
3349 3535
 
3350 3536
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3351 3537
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3365,16 +3551,18 @@  discard block
 block discarded – undo
3365 3551
 
3366 3552
 		if (empty($value))
3367 3553
 		{
3368
-			if (!is_array($cache_misses))
3369
-				$cache_misses = array();
3554
+			if (!is_array($cache_misses)) {
3555
+							$cache_misses = array();
3556
+			}
3370 3557
 
3371 3558
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3372 3559
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3373 3560
 		}
3374 3561
 	}
3375 3562
 
3376
-	if (function_exists('call_integration_hook') && isset($value))
3377
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3563
+	if (function_exists('call_integration_hook') && isset($value)) {
3564
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3565
+	}
3378 3566
 
3379 3567
 	return empty($value) ? null : smf_json_decode($value, true);
3380 3568
 }
@@ -3396,8 +3584,9 @@  discard block
 block discarded – undo
3396 3584
 	global $cachedir, $sourcedir, $modSettings;
3397 3585
 
3398 3586
 	// If we can't get to the API, can't do this.
3399
-	if (empty($cacheAPI))
3400
-		return false;
3587
+	if (empty($cacheAPI)) {
3588
+			return false;
3589
+	}
3401 3590
 
3402 3591
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3403 3592
 	$value = $cacheAPI->cleanCache($type);
@@ -3422,8 +3611,9 @@  discard block
 block discarded – undo
3422 3611
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3423 3612
 
3424 3613
 	// Come on!
3425
-	if (empty($data))
3426
-		return array();
3614
+	if (empty($data)) {
3615
+			return array();
3616
+	}
3427 3617
 
3428 3618
 	// Set a nice default var.
3429 3619
 	$image = '';
@@ -3431,11 +3621,11 @@  discard block
 block discarded – undo
3431 3621
 	// Gravatar has been set as mandatory!
3432 3622
 	if (!empty($modSettings['gravatarOverride']))
3433 3623
 	{
3434
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3435
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3436
-
3437
-		else if (!empty($data['email']))
3438
-			$image = get_gravatar_url($data['email']);
3624
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3625
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3626
+		} else if (!empty($data['email'])) {
3627
+					$image = get_gravatar_url($data['email']);
3628
+		}
3439 3629
 	}
3440 3630
 
3441 3631
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3447,54 +3637,60 @@  discard block
 block discarded – undo
3447 3637
 			// Gravatar.
3448 3638
 			if (stristr($data['avatar'], 'gravatar://'))
3449 3639
 			{
3450
-				if ($data['avatar'] == 'gravatar://')
3451
-					$image = get_gravatar_url($data['email']);
3452
-
3453
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3454
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3640
+				if ($data['avatar'] == 'gravatar://') {
3641
+									$image = get_gravatar_url($data['email']);
3642
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3643
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3644
+				}
3455 3645
 			}
3456 3646
 
3457 3647
 			// External url.
3458 3648
 			else
3459 3649
 			{
3460 3650
 				// Using ssl?
3461
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3462
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3651
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3652
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3653
+				}
3463 3654
 
3464 3655
 				// Just a plain external url.
3465
-				else
3466
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3656
+				else {
3657
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3658
+				}
3467 3659
 			}
3468 3660
 		}
3469 3661
 
3470 3662
 		// Perhaps this user has an attachment as avatar...
3471
-		else if (!empty($data['filename']))
3472
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3663
+		else if (!empty($data['filename'])) {
3664
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3665
+		}
3473 3666
 
3474 3667
 		// Right... no avatar... use our default image.
3475
-		else
3476
-			$image = $modSettings['avatar_url'] . '/default.png';
3668
+		else {
3669
+					$image = $modSettings['avatar_url'] . '/default.png';
3670
+		}
3477 3671
 	}
3478 3672
 
3479 3673
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3480 3674
 
3481 3675
 	// 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.
3482
-	if (!empty($image))
3483
-		return array(
3676
+	if (!empty($image)) {
3677
+			return array(
3484 3678
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3485 3679
 			'image' => '<img class="avatar" src="' . $image . '" />',
3486 3680
 			'href' => $image,
3487 3681
 			'url' => $image,
3488 3682
 		);
3683
+	}
3489 3684
 
3490 3685
 	// Fallback to make life easier for everyone...
3491
-	else
3492
-		return array(
3686
+	else {
3687
+			return array(
3493 3688
 			'name' => '',
3494 3689
 			'image' => '',
3495 3690
 			'href' => '',
3496 3691
 			'url' => '',
3497 3692
 		);
3498
-}
3693
+	}
3694
+	}
3499 3695
 
3500 3696
 ?>
3501 3697
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +294 added lines, -222 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
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -55,21 +58,25 @@  discard block
 block discarded – undo
55 58
 
56 59
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
57 60
 	{
58
-			if (!is_array($modSettings['attachment_basedirectories']))
59
-				$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
61
+			if (!is_array($modSettings['attachment_basedirectories'])) {
62
+							$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
63
+			}
60 64
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
65
+	} else {
66
+			$base_dir = 0;
61 67
 	}
62
-	else
63
-		$base_dir = 0;
64 68
 
65 69
 	if ($modSettings['automanage_attachments'] == 1)
66 70
 	{
67
-		if (!isset($modSettings['last_attachments_directory']))
68
-			$modSettings['last_attachments_directory'] = array();
69
-		if (!is_array($modSettings['last_attachments_directory']))
70
-			$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
71
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
72
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
71
+		if (!isset($modSettings['last_attachments_directory'])) {
72
+					$modSettings['last_attachments_directory'] = array();
73
+		}
74
+		if (!is_array($modSettings['last_attachments_directory'])) {
75
+					$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
76
+		}
77
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
78
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
79
+		}
73 80
 	}
74 81
 
75 82
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -98,12 +105,14 @@  discard block
 block discarded – undo
98 105
 			$updir = '';
99 106
 	}
100 107
 
101
-	if (!is_array($modSettings['attachmentUploadDir']))
102
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
103
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
104
-		$outputCreation = automanage_attachments_create_directory($updir);
105
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
106
-		$outputCreation = true;
108
+	if (!is_array($modSettings['attachmentUploadDir'])) {
109
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
110
+	}
111
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
112
+			$outputCreation = automanage_attachments_create_directory($updir);
113
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
114
+			$outputCreation = true;
115
+	}
107 116
 
108 117
 	if ($outputCreation)
109 118
 	{
@@ -140,8 +149,9 @@  discard block
 block discarded – undo
140 149
 		$count = count($tree);
141 150
 
142 151
 		$directory = attachments_init_dir($tree, $count);
143
-		if ($directory === false)
144
-			return false;
152
+		if ($directory === false) {
153
+					return false;
154
+		}
145 155
 	}
146 156
 
147 157
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -169,8 +179,9 @@  discard block
 block discarded – undo
169 179
 	}
170 180
 
171 181
 	// Everything seems fine...let's create the .htaccess
172
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
173
-		secureDirectory($updir, true);
182
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
183
+			secureDirectory($updir, true);
184
+	}
174 185
 
175 186
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
176 187
 	$updir = rtrim($updir, $sep);
@@ -202,8 +213,9 @@  discard block
 block discarded – undo
202 213
 {
203 214
 	global $modSettings, $boarddir;
204 215
 
205
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
206
-		return;
216
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
217
+			return;
218
+	}
207 219
 
208 220
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
209 221
 	// Just to be sure: I don't want directory separators at the end
@@ -215,13 +227,14 @@  discard block
 block discarded – undo
215 227
 	{
216 228
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
217 229
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
230
+	} else {
231
+			$base_dir = 0;
218 232
 	}
219
-	else
220
-		$base_dir = 0;
221 233
 
222 234
 	// Get the last attachment directory for that base directory
223
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
224
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
235
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
236
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
237
+	}
225 238
 	// And increment it.
226 239
 	$modSettings['last_attachments_directory'][$base_dir]++;
227 240
 
@@ -236,10 +249,10 @@  discard block
 block discarded – undo
236 249
 		$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
237 250
 
238 251
 		return true;
252
+	} else {
253
+			return false;
254
+	}
239 255
 	}
240
-	else
241
-		return false;
242
-}
243 256
 
244 257
 /**
245 258
  * Split a path into a list of all directories and subdirectories
@@ -257,12 +270,13 @@  discard block
 block discarded – undo
257 270
 			* in Windows we need to explode for both \ and /
258 271
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
259 272
 	*/
260
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
261
-		$tree = preg_split('#[\\\/]#', $directory);
262
-	else
273
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
274
+			$tree = preg_split('#[\\\/]#', $directory);
275
+	} else
263 276
 	{
264
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
265
-			return false;
277
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
278
+					return false;
279
+		}
266 280
 
267 281
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory,DIRECTORY_SEPARATOR));
268 282
 	}
@@ -286,10 +300,11 @@  discard block
 block discarded – undo
286 300
 		 //Better be sure that the first part of the path is actually a drive letter...
287 301
 		 //...even if, I should check this in the admin page...isn't it?
288 302
 		 //...NHAAA Let's leave space for users' complains! :P
289
-		if (preg_match('/^[a-z]:$/i',$tree[0]))
290
-			$directory = array_shift($tree);
291
-		else
292
-			return false;
303
+		if (preg_match('/^[a-z]:$/i',$tree[0])) {
304
+					$directory = array_shift($tree);
305
+		} else {
306
+					return false;
307
+		}
293 308
 
294 309
 		$count--;
295 310
 	}
@@ -304,18 +319,20 @@  discard block
 block discarded – undo
304 319
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
305 320
 
306 321
 	// Make sure we're uploading to the right place.
307
-	if (!empty($modSettings['automanage_attachments']))
308
-		automanage_attachments_check_directory();
322
+	if (!empty($modSettings['automanage_attachments'])) {
323
+			automanage_attachments_check_directory();
324
+	}
309 325
 
310
-	if (!is_array($modSettings['attachmentUploadDir']))
311
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
326
+	if (!is_array($modSettings['attachmentUploadDir'])) {
327
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
328
+	}
312 329
 
313 330
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
314 331
 
315 332
 	// Is the attachments folder actualy there?
316
-	if (!empty($context['dir_creation_error']))
317
-		$initial_error = $context['dir_creation_error'];
318
-	elseif (!is_dir($context['attach_dir']))
333
+	if (!empty($context['dir_creation_error'])) {
334
+			$initial_error = $context['dir_creation_error'];
335
+	} elseif (!is_dir($context['attach_dir']))
319 336
 	{
320 337
 		$initial_error = 'attach_folder_warning';
321 338
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -338,12 +355,12 @@  discard block
 block discarded – undo
338 355
 			);
339 356
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
340 357
 			$smcFunc['db_free_result']($request);
341
-		}
342
-		else
343
-			$context['attachments'] = array(
358
+		} else {
359
+					$context['attachments'] = array(
344 360
 				'quantity' => 0,
345 361
 				'total_size' => 0,
346 362
 			);
363
+		}
347 364
 	}
348 365
 
349 366
 	// Hmm. There are still files in session.
@@ -353,39 +370,44 @@  discard block
 block discarded – undo
353 370
 		// Let's try to keep them. But...
354 371
 		$ignore_temp = true;
355 372
 		// If new files are being added. We can't ignore those
356
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
357
-			if (!empty($dummy))
373
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
374
+					if (!empty($dummy))
358 375
 			{
359 376
 				$ignore_temp = false;
377
+		}
360 378
 				break;
361 379
 			}
362 380
 
363 381
 		// Need to make space for the new files. So, bye bye.
364 382
 		if (!$ignore_temp)
365 383
 		{
366
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
367
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
384
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
385
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
368 386
 					unlink($attachment['tmp_name']);
387
+			}
369 388
 
370 389
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
371 390
 			$_SESSION['temp_attachments'] = array();
372 391
 		}
373 392
 	}
374 393
 
375
-	if (!isset($_FILES['attachment']['name']))
376
-		$_FILES['attachment']['tmp_name'] = array();
394
+	if (!isset($_FILES['attachment']['name'])) {
395
+			$_FILES['attachment']['tmp_name'] = array();
396
+	}
377 397
 
378
-	if (!isset($_SESSION['temp_attachments']))
379
-		$_SESSION['temp_attachments'] = array();
398
+	if (!isset($_SESSION['temp_attachments'])) {
399
+			$_SESSION['temp_attachments'] = array();
400
+	}
380 401
 
381 402
 	// Remember where we are at. If it's anywhere at all.
382
-	if (!$ignore_temp)
383
-		$_SESSION['temp_attachments']['post'] = array(
403
+	if (!$ignore_temp) {
404
+			$_SESSION['temp_attachments']['post'] = array(
384 405
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
385 406
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
386 407
 			'topic' => !empty($topic) ? $topic : 0,
387 408
 			'board' => !empty($board) ? $board : 0,
388 409
 		);
410
+	}
389 411
 
390 412
 	// If we have an initial error, lets just display it.
391 413
 	if (!empty($initial_error))
@@ -393,9 +415,10 @@  discard block
 block discarded – undo
393 415
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
394 416
 
395 417
 		// And delete the files 'cos they ain't going nowhere.
396
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
397
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
418
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
419
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
398 420
 				unlink($_FILES['attachment']['tmp_name'][$n]);
421
+		}
399 422
 
400 423
 		$_FILES['attachment']['tmp_name'] = array();
401 424
 	}
@@ -403,21 +426,24 @@  discard block
 block discarded – undo
403 426
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
404 427
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
405 428
 	{
406
-		if ($_FILES['attachment']['name'][$n] == '')
407
-			continue;
429
+		if ($_FILES['attachment']['name'][$n] == '') {
430
+					continue;
431
+		}
408 432
 
409 433
 		// First, let's first check for PHP upload errors.
410 434
 		$errors = array();
411 435
 		if (!empty($_FILES['attachment']['error'][$n]))
412 436
 		{
413
-			if ($_FILES['attachment']['error'][$n] == 2)
414
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
415
-			elseif ($_FILES['attachment']['error'][$n] == 6)
416
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
417
-			else
418
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
419
-			if (empty($errors))
420
-				$errors[] = 'attach_php_error';
437
+			if ($_FILES['attachment']['error'][$n] == 2) {
438
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
439
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
440
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
441
+			} else {
442
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
443
+			}
444
+			if (empty($errors)) {
445
+							$errors[] = 'attach_php_error';
446
+			}
421 447
 		}
422 448
 
423 449
 		// Try to move and rename the file before doing any more checks on it.
@@ -435,16 +461,16 @@  discard block
 block discarded – undo
435 461
 			);
436 462
 
437 463
 			// Move the file to the attachments folder with a temp name for now.
438
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
439
-				smf_chmod($destName, 0644);
440
-			else
464
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
465
+							smf_chmod($destName, 0644);
466
+			} else
441 467
 			{
442 468
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
443
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
444
-					unlink($_FILES['attachment']['tmp_name'][$n]);
469
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
470
+									unlink($_FILES['attachment']['tmp_name'][$n]);
471
+				}
445 472
 			}
446
-		}
447
-		else
473
+		} else
448 474
 		{
449 475
 			$_SESSION['temp_attachments'][$attachID] = array(
450 476
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -452,12 +478,14 @@  discard block
 block discarded – undo
452 478
 				'errors' => $errors,
453 479
 			);
454 480
 
455
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
456
-				unlink($_FILES['attachment']['tmp_name'][$n]);
481
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
482
+							unlink($_FILES['attachment']['tmp_name'][$n]);
483
+			}
457 484
 		}
458 485
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
459
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
460
-			attachmentChecks($attachID);
486
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
487
+					attachmentChecks($attachID);
488
+		}
461 489
 	}
462 490
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
463 491
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -484,21 +512,20 @@  discard block
 block discarded – undo
484 512
 	global $modSettings, $context, $sourcedir, $smcFunc;
485 513
 
486 514
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
487
-	if ( empty($_SESSION['temp_attachments'][$attachID]))
488
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
489
-
490
-	elseif (empty($attachID))
491
-		$error = '$attachID';
492
-
493
-	elseif (empty($context['attachments']))
494
-		$error = '$context[\'attachments\']';
495
-
496
-	elseif (empty($context['attach_dir']))
497
-		$error = '$context[\'attach_dir\']';
515
+	if ( empty($_SESSION['temp_attachments'][$attachID])) {
516
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
517
+	} elseif (empty($attachID)) {
518
+			$error = '$attachID';
519
+	} elseif (empty($context['attachments'])) {
520
+			$error = '$context[\'attachments\']';
521
+	} elseif (empty($context['attach_dir'])) {
522
+			$error = '$context[\'attach_dir\']';
523
+	}
498 524
 
499 525
 	// Let's get their attention.
500
-	if (!empty($error))
501
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
526
+	if (!empty($error)) {
527
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
528
+	}
502 529
 
503 530
 	// Just in case this slipped by the first checks, we stop it here and now
504 531
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -527,8 +554,9 @@  discard block
 block discarded – undo
527 554
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
528 555
 			if (!(empty($size)) && ($size[2] != $old_format))
529 556
 			{
530
-				if (isset($context['validImageTypes'][$size[2]]))
531
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
557
+				if (isset($context['validImageTypes'][$size[2]])) {
558
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
559
+				}
532 560
 			}
533 561
 		}
534 562
 	}
@@ -582,42 +610,48 @@  discard block
 block discarded – undo
582 610
 				// Or, let the user know that it ain't gonna happen.
583 611
 				else
584 612
 				{
585
-					if (isset($context['dir_creation_error']))
586
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
587
-					else
588
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
613
+					if (isset($context['dir_creation_error'])) {
614
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
615
+					} else {
616
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
617
+					}
589 618
 				}
619
+			} else {
620
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
590 621
 			}
591
-			else
592
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
593 622
 		}
594 623
 	}
595 624
 
596 625
 	// Is the file too big?
597 626
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
598
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
599
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
627
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
628
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
629
+	}
600 630
 
601 631
 	// Check the total upload size for this post...
602
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
632
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
634
+	}
604 635
 
605 636
 	// Have we reached the maximum number of files we are allowed?
606 637
 	$context['attachments']['quantity']++;
607 638
 
608 639
 	// Set a max limit if none exists
609
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
610
-		$modSettings['attachmentNumPerPostLimit'] = 50;
640
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
641
+			$modSettings['attachmentNumPerPostLimit'] = 50;
642
+	}
611 643
 
612
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
613
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
644
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
645
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
646
+	}
614 647
 
615 648
 	// File extension check
616 649
 	if (!empty($modSettings['attachmentCheckExtensions']))
617 650
 	{
618 651
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
619
-		foreach ($allowed as $k => $dummy)
620
-			$allowed[$k] = trim($dummy);
652
+		foreach ($allowed as $k => $dummy) {
653
+					$allowed[$k] = trim($dummy);
654
+		}
621 655
 
622 656
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
623 657
 		{
@@ -629,10 +663,12 @@  discard block
 block discarded – undo
629 663
 	// Undo the math if there's an error
630 664
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
631 665
 	{
632
-		if (isset($context['dir_size']))
633
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
634
-		if (isset($context['dir_files']))
635
-			$context['dir_files']--;
666
+		if (isset($context['dir_size'])) {
667
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
668
+		}
669
+		if (isset($context['dir_files'])) {
670
+					$context['dir_files']--;
671
+		}
636 672
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
637 673
 		$context['attachments']['quantity']--;
638 674
 		return false;
@@ -664,12 +700,14 @@  discard block
 block discarded – undo
664 700
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
665 701
 	{
666 702
 		// Got a proper mime type?
667
-		if (!empty($size['mime']))
668
-			$attachmentOptions['mime_type'] = $size['mime'];
703
+		if (!empty($size['mime'])) {
704
+					$attachmentOptions['mime_type'] = $size['mime'];
705
+		}
669 706
 
670 707
 		// Otherwise a valid one?
671
-		elseif (isset($context['validImageTypes'][$size[2]]))
672
-			$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
708
+		elseif (isset($context['validImageTypes'][$size[2]])) {
709
+					$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
710
+		}
673 711
 	}
674 712
 
675 713
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -681,15 +719,17 @@  discard block
 block discarded – undo
681 719
 	}
682 720
 
683 721
 	// Get the hash if no hash has been given yet.
684
-	if (empty($attachmentOptions['file_hash']))
685
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
722
+	if (empty($attachmentOptions['file_hash'])) {
723
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
724
+	}
686 725
 
687 726
 	// Assuming no-one set the extension let's take a look at it.
688 727
 	if (empty($attachmentOptions['fileext']))
689 728
 	{
690 729
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
691
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
692
-			$attachmentOptions['fileext'] = '';
730
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
731
+					$attachmentOptions['fileext'] = '';
732
+		}
693 733
 	}
694 734
 
695 735
 	// Last chance to change stuff!
@@ -698,8 +738,9 @@  discard block
 block discarded – undo
698 738
 	// Make sure the folder is valid...
699 739
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true);
700 740
 	$folders = array_keys($tmp);
701
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
702
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
741
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
742
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
743
+	}
703 744
 
704 745
 	$smcFunc['db_insert']('',
705 746
 		'{db_prefix}attachments',
@@ -730,8 +771,8 @@  discard block
 block discarded – undo
730 771
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
731 772
 
732 773
 	// If it's not approved then add to the approval queue.
733
-	if (!$attachmentOptions['approved'])
734
-		$smcFunc['db_insert']('',
774
+	if (!$attachmentOptions['approved']) {
775
+			$smcFunc['db_insert']('',
735 776
 			'{db_prefix}approval_queue',
736 777
 			array(
737 778
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -741,9 +782,11 @@  discard block
 block discarded – undo
741 782
 			),
742 783
 			array()
743 784
 		);
785
+	}
744 786
 
745
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
746
-		return true;
787
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
788
+			return true;
789
+	}
747 790
 
748 791
 	// Like thumbnails, do we?
749 792
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -754,13 +797,15 @@  discard block
 block discarded – undo
754 797
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
755 798
 			list ($thumb_width, $thumb_height) = $size;
756 799
 
757
-			if (!empty($size['mime']))
758
-				$thumb_mime = $size['mime'];
759
-			elseif (isset($context['validImageTypes'][$size[2]]))
760
-				$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
800
+			if (!empty($size['mime'])) {
801
+							$thumb_mime = $size['mime'];
802
+			} elseif (isset($context['validImageTypes'][$size[2]])) {
803
+							$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
804
+			}
761 805
 			// Lord only knows how this happened...
762
-			else
763
-				$thumb_mime = '';
806
+			else {
807
+							$thumb_mime = '';
808
+			}
764 809
 
765 810
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
766 811
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -840,15 +885,17 @@  discard block
 block discarded – undo
840 885
 	global $smcFunc;
841 886
 
842 887
 	// Oh, come on!
843
-	if (empty($attachIDs) || empty($msgID))
844
-		return false;
888
+	if (empty($attachIDs) || empty($msgID)) {
889
+			return false;
890
+	}
845 891
 
846 892
 	// "I see what is right and approve, but I do what is wrong."
847 893
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
848 894
 
849 895
 	// One last check
850
-	if (empty($attachIDs))
851
-		return false;
896
+	if (empty($attachIDs)) {
897
+			return false;
898
+	}
852 899
 
853 900
 	// Perform.
854 901
 	$smcFunc['db_query']('', '
@@ -880,8 +927,9 @@  discard block
 block discarded – undo
880 927
 	$externalParse = false;
881 928
 
882 929
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
930
+	if (empty($attachID)) {
931
+			return 'attachments_no_data_loaded';
932
+	}
885 933
 
886 934
 	// Make it easy.
887 935
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +938,23 @@  discard block
 block discarded – undo
890 938
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 939
 
892 940
 	// "I am innocent of the blood of this just person: see ye to it."
893
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
894
-		return $externalParse;
941
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
942
+			return $externalParse;
943
+	}
895 944
 
896 945
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
946
+	if (empty($modSettings['attachmentEnable'])) {
947
+			return 'attachments_not_enable';
948
+	}
899 949
 
900 950
 	// Previewing much? no msg ID has been set yet.
901 951
 	if (!empty($context['preview_message']))
902 952
 	{
903 953
 		$allAttachments = getAttachsByMsg(0);
904 954
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
955
+		if (empty($allAttachments[0][$attachID])) {
956
+					return 'attachments_no_data_loaded';
957
+		}
907 958
 
908 959
 		$attachContext = $allAttachments[0][$attachID];
909 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
@@ -916,57 +967,66 @@  discard block
 block discarded – undo
916 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID .';type=preview'. (empty($attachContext['is_image']) ? ';file' : '') .'">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
917 968
 
918 969
 		// Fix the thumbnail too, if the image has one.
919
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
920
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
970
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
971
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		}
921 973
 
922 974
 		return $attachContext;
923 975
 	}
924 976
 
925 977
 	// There is always the chance someone else has already done our dirty work...
926 978
 	// If so, all pertinent checks were already done. Hopefully...
927
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
928
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
929 982
 
930 983
 	// If we are lucky enough to be in $board's scope then check it!
931
-	if (!empty($board) && !allowedTo('view_attachments', $board))
932
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
933 987
 
934 988
 	// Get the message info associated with this particular attach ID.
935 989
 	$attachInfo = getAttachMsgInfo($attachID);
936 990
 
937 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
938
-	if (empty($attachInfo) || empty($attachInfo['msg']))
939
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
940 995
 
941 996
 	// Hold it! got the info now check if you can see this attachment.
942
-	if (!allowedTo('view_attachments', $attachInfo['board']))
943
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
944 1000
 
945 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
946 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
947 1003
 
948 1004
 	// No point in keep going further.
949
-	if (!allowedTo('view_attachments', $attachContext['board']))
950
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
951 1008
 
952 1009
 	// Load this particular attach's context.
953
-	if (!empty($attachContext))
954
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
955 1013
 
956 1014
 	// One last check, you know, gotta be paranoid...
957
-	else
958
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
959 1018
 
960 1019
 	// This is the last "if" I promise!
961
-	if (empty($attachLoaded))
962
-		return 'attachments_no_data_loaded';
963
-
964
-	else
965
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
966 1025
 
967 1026
 	// You may or may not want to show this under the post.
968
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
969
-		$context['show_attach_under_post'][$attachID] = $attachID;
1027
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1028
+			$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	}
970 1030
 
971 1031
 	// Last minute changes?
972 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -986,8 +1046,9 @@  discard block
 block discarded – undo
986 1046
 {
987 1047
 	global $smcFunc, $modSettings;
988 1048
 
989
-	if (empty($attachIDs))
990
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
991 1052
 
992 1053
 	$return = array();
993 1054
 
@@ -1003,11 +1064,12 @@  discard block
 block discarded – undo
1003 1064
 		)
1004 1065
 	);
1005 1066
 
1006
-	if ($smcFunc['db_num_rows']($request) != 1)
1007
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1008 1070
 
1009
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1010
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1011 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1012 1074
 			'size' => $row['size'],
1013 1075
 			'attachID' => $row['id_attach'],
@@ -1016,6 +1078,7 @@  discard block
 block discarded – undo
1016 1078
 			'mime_type' => $row['mime_type'],
1017 1079
 			'thumb' => $row['id_thumb'],
1018 1080
 		);
1081
+	}
1019 1082
 	$smcFunc['db_free_result']($request);
1020 1083
 
1021 1084
 	return $return;
@@ -1032,8 +1095,9 @@  discard block
 block discarded – undo
1032 1095
 {
1033 1096
 	global $smcFunc;
1034 1097
 
1035
-	if (empty($attachID))
1036
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1037 1101
 
1038 1102
 	$request = $smcFunc['db_query']('', '
1039 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1046,8 +1110,9 @@  discard block
 block discarded – undo
1046 1110
 		)
1047 1111
 	);
1048 1112
 
1049
-	if ($smcFunc['db_num_rows']($request) != 1)
1050
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1051 1116
 
1052 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1053 1118
 	$smcFunc['db_free_result']($request);
@@ -1088,8 +1153,9 @@  discard block
 block discarded – undo
1088 1153
 		$temp = array();
1089 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1090 1155
 		{
1091
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1092
-				continue;
1156
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1157
+							continue;
1158
+			}
1093 1159
 
1094 1160
 			$temp[$row['id_attach']] = $row;
1095 1161
 		}
@@ -1118,8 +1184,9 @@  discard block
 block discarded – undo
1118 1184
 {
1119 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1120 1186
 
1121
-	if (empty($attachments) || empty($attachments[$id_msg]))
1122
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1123 1190
 
1124 1191
 	// Set up the attachment info - based on code by Meriadoc.
1125 1192
 	$attachmentData = array();
@@ -1143,11 +1210,13 @@  discard block
 block discarded – undo
1143 1210
 			);
1144 1211
 
1145 1212
 			// If something is unapproved we'll note it so we can sort them.
1146
-			if (!$attachment['approved'])
1147
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1148 1216
 
1149
-			if (!$attachmentData[$i]['is_image'])
1150
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1151 1220
 
1152 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1153 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1168,12 +1237,12 @@  discard block
 block discarded – undo
1168 1237
 						// So what folder are we putting this image in?
1169 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1170 1239
 						{
1171
-							if (!is_array($modSettings['attachmentUploadDir']))
1172
-								$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1242
+							}
1173 1243
 							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
1174 1244
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1175
-						}
1176
-						else
1245
+						} else
1177 1246
 						{
1178 1247
 							$path = $modSettings['attachmentUploadDir'];
1179 1248
 							$id_folder_thumb = 1;
@@ -1188,10 +1257,11 @@  discard block
 block discarded – undo
1188 1257
 						$thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : '';
1189 1258
 
1190 1259
 						// Figure out the mime type.
1191
-						if (!empty($size['mime']))
1192
-							$thumb_mime = $size['mime'];
1193
-						else
1194
-							$thumb_mime = 'image/' . $thumb_ext;
1260
+						if (!empty($size['mime'])) {
1261
+													$thumb_mime = $size['mime'];
1262
+						} else {
1263
+													$thumb_mime = 'image/' . $thumb_ext;
1264
+						}
1195 1265
 
1196 1266
 						$thumb_filename = $attachment['filename'] . '_thumb';
1197 1267
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1238,11 +1308,12 @@  discard block
 block discarded – undo
1238 1308
 				}
1239 1309
 			}
1240 1310
 
1241
-			if (!empty($attachment['id_thumb']))
1242
-				$attachmentData[$i]['thumbnail'] = array(
1311
+			if (!empty($attachment['id_thumb'])) {
1312
+							$attachmentData[$i]['thumbnail'] = array(
1243 1313
 					'id' => $attachment['id_thumb'],
1244 1314
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1245 1315
 				);
1316
+			}
1246 1317
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1247 1318
 
1248 1319
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1252,30 +1323,31 @@  discard block
 block discarded – undo
1252 1323
 				{
1253 1324
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1254 1325
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1255
-				}
1256
-				elseif (!empty($modSettings['max_image_width']))
1326
+				} elseif (!empty($modSettings['max_image_width']))
1257 1327
 				{
1258 1328
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1259 1329
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1260 1330
 				}
1261
-			}
1262
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1331
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1263 1332
 			{
1264 1333
 				// If the image is too large to show inline, make it a popup.
1265
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1266
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1267
-				else
1268
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1334
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1335
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1336
+				} else {
1337
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1338
+				}
1269 1339
 			}
1270 1340
 
1271
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1272
-				$attachmentData[$i]['downloads']++;
1341
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1342
+							$attachmentData[$i]['downloads']++;
1343
+			}
1273 1344
 		}
1274 1345
 	}
1275 1346
 
1276 1347
 	// Do we need to instigate a sort?
1277
-	if ($have_unapproved)
1278
-		usort($attachmentData, 'approved_attach_sort');
1348
+	if ($have_unapproved) {
1349
+			usort($attachmentData, 'approved_attach_sort');
1350
+	}
1279 1351
 
1280 1352
 	return $attachmentData;
1281 1353
 }
Please login to merge, or discard this patch.