Completed
Push — release-2.1 ( 0c47ec...0c190a )
by Jeremy
19:40 queued 12:01
created
Themes/default/Packages.template.php 1 patch
Braces   +175 added lines, -128 removed lines patch added patch discarded remove patch
@@ -31,25 +31,27 @@  discard block
 block discarded – undo
31 31
 		</div>
32 32
 		<div class="information">';
33 33
 
34
-	if ($context['is_installed'])
35
-		echo '
34
+	if ($context['is_installed']) {
35
+			echo '
36 36
 			<strong>', $txt['package_installed_warning1'], '</strong><br>
37 37
 			<br>
38 38
 			', $txt['package_installed_warning2'], '<br>
39 39
 			<br>';
40
+	}
40 41
 
41 42
 	echo $txt['package_installed_warning3'], '
42 43
 		</div>
43 44
 		<br>';
44 45
 
45 46
 	// Do errors exist in the install? If so light them up like a christmas tree.
46
-	if ($context['has_failure'])
47
-		echo '
47
+	if ($context['has_failure']) {
48
+			echo '
48 49
 		<div class="errorbox">
49 50
 			', sprintf($txt['package_will_fail_title'], $txt['package_' . ($context['uninstalling'] ? 'uninstall' : 'install')]), '<br>
50 51
 			', sprintf($txt['package_will_fail_warning'], $txt['package_' . ($context['uninstalling'] ? 'uninstall' : 'install')]),
51 52
 			!empty($context['failure_details']) ? '<br><br><strong>' . $context['failure_details'] . '</strong>' : '', '
52 53
 		</div>';
54
+	}
53 55
 
54 56
 	// Display the package readme if one exists
55 57
 	if (isset($context['package_readme']))
@@ -63,9 +65,10 @@  discard block
 block discarded – undo
63 65
 			<span class="floatright">', $txt['package_available_readme_language'], '
64 66
 				<select name="readme_language" id="readme_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = smf_prepareScriptUrl(smf_scripturl + \'', '?action=admin;area=packages;sa=', $context['uninstalling'] ? 'uninstall' : 'install', ';package=', $context['filename'], ';readme=\' + this.options[this.selectedIndex].value + \';license=\' + get_selected(\'license_language\'));">';
65 67
 
66
-		foreach ($context['readmes'] as $a => $b)
67
-			echo '
68
+		foreach ($context['readmes'] as $a => $b) {
69
+					echo '
68 70
 					<option value="', $b, '"', $a === 'selected' ? ' selected' : '', '>', $b == 'default' ? $txt['package_readme_default'] : ucfirst($b), '</option>';
71
+		}
69 72
 
70 73
 		echo '
71 74
 				</select>
@@ -86,9 +89,10 @@  discard block
 block discarded – undo
86 89
 			<span class="floatright">', $txt['package_available_license_language'], '
87 90
 				<select name="license_language" id="license_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = smf_prepareScriptUrl(smf_scripturl + \'', '?action=admin;area=packages;sa=install', ';package=', $context['filename'], ';license=\' + this.options[this.selectedIndex].value + \';readme=\' + get_selected(\'readme_language\'));">';
88 91
 
89
-		foreach ($context['licenses'] as $a => $b)
90
-			echo '
92
+		foreach ($context['licenses'] as $a => $b) {
93
+					echo '
91 94
 					<option value="', $b, '"', $a === 'selected' ? ' selected' : '', '>', $b == 'default' ? $txt['package_license_default'] : ucfirst($b), '</option>';
95
+		}
92 96
 		echo '
93 97
 				</select>
94 98
 			</span>
@@ -115,9 +119,10 @@  discard block
 block discarded – undo
115 119
 					', $txt['package_db_uninstall_actions'], ':
116 120
 					<ul>';
117 121
 
118
-		foreach ($context['database_changes'] as $change)
119
-			echo '
122
+		foreach ($context['database_changes'] as $change) {
123
+					echo '
120 124
 						<li>', $change, '</li>';
125
+		}
121 126
 
122 127
 		echo '
123 128
 					</ul>
@@ -128,14 +133,14 @@  discard block
 block discarded – undo
128 133
 	echo '
129 134
 			<div class="information">';
130 135
 
131
-	if (empty($context['actions']) && empty($context['database_changes']))
132
-		echo '
136
+	if (empty($context['actions']) && empty($context['database_changes'])) {
137
+			echo '
133 138
 				<br>
134 139
 				<div class="errorbox">
135 140
 					', $txt['corrupt_compatible'], '
136 141
 				</div>
137 142
 			</div><!-- .information -->';
138
-	else
143
+	} else
139 144
 	{
140 145
 		echo '
141 146
 				', $txt['perform_actions'], '
@@ -239,9 +244,10 @@  discard block
 block discarded – undo
239 244
 						<td></td>
240 245
 						<td>';
241 246
 
242
-				if (!empty($context['themes_locked']))
243
-					echo '
247
+				if (!empty($context['themes_locked'])) {
248
+									echo '
244 249
 							<input type="hidden" name="custom_theme[]" value="', $id, '">';
250
+				}
245 251
 				echo '
246 252
 							<input type="checkbox" name="custom_theme[]" id="custom_theme_', $id, '" value="', $id, '" onclick="', (!empty($theme['has_failure']) ? 'if (this.form.custom_theme_' . $id . '.checked && !confirm(\'' . $txt['package_theme_failure_warning'] . '\')) return false;' : ''), 'invertAll(this, this.form, \'dummy_theme_', $id, '\', true);"', !empty($context['themes_locked']) ? ' disabled checked' : '', '>
247 253
 						</td>
@@ -307,21 +313,23 @@  discard block
 block discarded – undo
307 313
 	}
308 314
 
309 315
 	// Are we effectively ready to install?
310
-	if (!$context['ftp_needed'] && (!empty($context['actions']) || !empty($context['database_changes'])))
311
-		echo '
316
+	if (!$context['ftp_needed'] && (!empty($context['actions']) || !empty($context['database_changes']))) {
317
+			echo '
312 318
 			<div class="righttext padding">
313 319
 				<input type="submit" value="', $context['uninstalling'] ? $txt['package_uninstall_now'] : $txt['package_install_now'], '" onclick="return ', !empty($context['has_failure']) ? '(submitThisOnce(this) &amp;&amp; confirm(\'' . ($context['uninstalling'] ? $txt['package_will_fail_popup_uninstall'] : $txt['package_will_fail_popup']) . '\'))' : 'submitThisOnce(this)', ';" class="button">
314 320
 			</div>';
321
+	}
315 322
 
316 323
 	// If we need ftp information then demand it!
317
-	elseif ($context['ftp_needed'])
318
-		echo '
324
+	elseif ($context['ftp_needed']) {
325
+			echo '
319 326
 			<div class="cat_bar">
320 327
 				<h3 class="catbg">', $txt['package_ftp_necessary'], '</h3>
321 328
 			</div>
322 329
 			<div>
323 330
 				', template_control_chmod(), '
324 331
 			</div>';
332
+	}
325 333
 
326 334
 	echo '
327 335
 
@@ -338,8 +346,8 @@  discard block
 block discarded – undo
338 346
 	// Operations.
339 347
 	if (!empty($js_operations))
340 348
 	{
341
-		foreach ($js_operations as $key => $operation)
342
-			echo '
349
+		foreach ($js_operations as $key => $operation) {
350
+					echo '
343 351
 		aOperationElements[', $key, '] = new smc_Toggle({
344 352
 			bToggleEnabled: true,
345 353
 			bNoAnimate: true,
@@ -357,6 +365,7 @@  discard block
 block discarded – undo
357 365
 				}
358 366
 			]
359 367
 		});';
368
+		}
360 369
 	}
361 370
 
362 371
 	echo '
@@ -378,14 +387,15 @@  discard block
 block discarded – undo
378 387
 	</script>';
379 388
 
380 389
 	// And a bit more for database changes.
381
-	if (!empty($context['database_changes']))
382
-		echo '
390
+	if (!empty($context['database_changes'])) {
391
+			echo '
383 392
 	<script>
384 393
 		var database_changes_area = document.getElementById(\'db_changes_div\');
385 394
 		var db_vis = false;
386 395
 		database_changes_area.style.display = "none";
387 396
 	</script>';
388
-}
397
+	}
398
+	}
389 399
 
390 400
 /**
391 401
  * Extract package contents
@@ -394,8 +404,8 @@  discard block
 block discarded – undo
394 404
 {
395 405
 	global $context, $txt, $scripturl;
396 406
 
397
-	if (!empty($context['redirect_url']))
398
-		echo '
407
+	if (!empty($context['redirect_url'])) {
408
+			echo '
399 409
 	<script>
400 410
 		setTimeout("doRedirect();", ', empty($context['redirect_timeout']) ? '5000' : $context['redirect_timeout'], ');
401 411
 
@@ -404,52 +414,51 @@  discard block
 block discarded – undo
404 414
 			window.location = "', $context['redirect_url'], '";
405 415
 		}
406 416
 	</script>';
417
+	}
407 418
 
408 419
 	echo '
409 420
 	<div id="admincenter">';
410 421
 
411
-	if (empty($context['redirect_url']))
412
-		echo '
422
+	if (empty($context['redirect_url'])) {
423
+			echo '
413 424
 		<div class="cat_bar">
414 425
 			<h3 class="catbg">', $context['uninstalling'] ? $txt['uninstall'] : $txt['extracting'], '</h3>
415 426
 		</div>
416 427
 		<div class="information">', $txt['package_installed_extract'], '</div>';
417
-	else
418
-		echo '
428
+	} else {
429
+			echo '
419 430
 		<div class="cat_bar">
420 431
 			<h3 class="catbg">', $txt['package_installed_redirecting'], '</h3>
421 432
 		</div>';
433
+	}
422 434
 
423 435
 	echo '
424 436
 		<div class="windowbg">';
425 437
 
426 438
 	// If we are going to redirect we have a slightly different agenda.
427
-	if (!empty($context['redirect_url']))
428
-		echo '
439
+	if (!empty($context['redirect_url'])) {
440
+			echo '
429 441
 			', $context['redirect_text'], '<br><br>
430 442
 			<a href="', $context['redirect_url'], '">', $txt['package_installed_redirect_go_now'], '</a> | <a href="', $scripturl, '?action=admin;area=packages;sa=browse">', $txt['package_installed_redirect_cancel'], '</a>';
431
-
432
-	elseif ($context['uninstalling'])
433
-		echo '
443
+	} elseif ($context['uninstalling']) {
444
+			echo '
434 445
 			', $txt['package_uninstall_done'];
435
-
436
-	elseif ($context['install_finished'])
446
+	} elseif ($context['install_finished'])
437 447
 	{
438
-		if ($context['extract_type'] == 'avatar')
439
-			echo '
448
+		if ($context['extract_type'] == 'avatar') {
449
+					echo '
440 450
 			', $txt['avatars_extracted'];
441
-
442
-		elseif ($context['extract_type'] == 'language')
443
-			echo '
451
+		} elseif ($context['extract_type'] == 'language') {
452
+					echo '
444 453
 			', $txt['language_extracted'];
445
-
446
-		else
447
-			echo '
454
+		} else {
455
+					echo '
448 456
 			', $txt['package_installed_done'];
449
-	}
450
-	else
451
-		echo '
457
+		}
458
+	} else {
459
+			echo '
452 460
 			', $txt['corrupt_compatible'];
461
+	}
453 462
 
454 463
 	echo '
455 464
 		</div><!-- .windowbg -->';
@@ -483,9 +492,10 @@  discard block
 block discarded – undo
483 492
 		<div class="windowbg">
484 493
 			<ol>';
485 494
 
486
-	foreach ($context['files'] as $fileinfo)
487
-		echo '
495
+	foreach ($context['files'] as $fileinfo) {
496
+			echo '
488 497
 				<li><a href="', $scripturl, '?action=admin;area=packages;sa=examine;package=', $context['filename'], ';file=', $fileinfo['filename'], '" title="', $txt['view'], '">', $fileinfo['filename'], '</a> (', $fileinfo['size'], ' ', $txt['package_bytes'], ')</li>';
498
+	}
489 499
 
490 500
 	echo '
491 501
 			</ol>
@@ -549,9 +559,10 @@  discard block
 block discarded – undo
549 559
 			</script>
550 560
 			<div id="yourVersion" style="display:none">', $context['forum_version'], '</div>';
551 561
 
552
-	if (empty($modSettings['disable_smf_js']))
553
-		echo '
562
+	if (empty($modSettings['disable_smf_js'])) {
563
+			echo '
554 564
 			<script src="', $scripturl, '?action=viewsmfile;filename=latest-news.js"></script>';
565
+	}
555 566
 
556 567
 	// This sets the announcements and current versions themselves ;).
557 568
 	echo '
@@ -589,12 +600,13 @@  discard block
 block discarded – undo
589 600
 		}
590 601
 	}
591 602
 
592
-	if (!$mods_available)
593
-		echo '
603
+	if (!$mods_available) {
604
+			echo '
594 605
 		<div class="noticebox">', $txt['no_packages'], '</div>';
595
-	else
596
-		echo '
606
+	} else {
607
+			echo '
597 608
 		<br>';
609
+	}
598 610
 
599 611
 	// The advanced (emulation) box, collapsed by default
600 612
 	echo '
@@ -621,9 +633,10 @@  discard block
 block discarded – undo
621 633
 							<a id="revert" name="revert"></a>
622 634
 							<select name="version_emulate" id="ve">';
623 635
 
624
-	foreach ($context['emulation_versions'] as $version)
625
-		echo '
636
+	foreach ($context['emulation_versions'] as $version) {
637
+			echo '
626 638
 								<option value="', $version, '"', ($version == $context['selected_version'] ? ' selected="selected"' : ''), '>', $version, '</option>';
639
+	}
627 640
 
628 641
 	echo '
629 642
 							</select>
@@ -679,11 +692,12 @@  discard block
 block discarded – undo
679 692
 {
680 693
 	global $context, $txt, $scripturl;
681 694
 
682
-	if (!empty($context['package_ftp']['error']))
683
-		echo '
695
+	if (!empty($context['package_ftp']['error'])) {
696
+			echo '
684 697
 	<div class="errorbox">
685 698
 		<pre>', $context['package_ftp']['error'], '</pre>
686 699
 	</div>';
700
+	}
687 701
 
688 702
 	echo '
689 703
 	<div id="admin_form_wrapper">
@@ -766,13 +780,14 @@  discard block
 block discarded – undo
766 780
 					<legend>' . $txt['package_servers'] . '</legend>
767 781
 					<ul class="package_servers">';
768 782
 
769
-	foreach ($context['servers'] as $server)
770
-		echo '
783
+	foreach ($context['servers'] as $server) {
784
+			echo '
771 785
 						<li class="flow_auto">
772 786
 							<span class="floatleft">' . $server['name'] . '</span>
773 787
 							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=remove;server=' . $server['id'] . ';', $context['session_var'], '=', $context['session_id'], '">[ ' . $txt['delete'] . ' ]</a></span>
774 788
 							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $server['id'] . '">[ ' . $txt['package_browse'] . ' ]</a></span>
775 789
 						</li>';
790
+	}
776 791
 	echo '
777 792
 					</ul>
778 793
 				</fieldset>
@@ -859,11 +874,12 @@  discard block
 block discarded – undo
859 874
 		<div class="windowbg">';
860 875
 
861 876
 	// No packages, as yet.
862
-	if (empty($context['package_list']))
863
-		echo '
877
+	if (empty($context['package_list'])) {
878
+			echo '
864 879
 			<ul>
865 880
 				<li>', $txt['no_packages'], '</li>
866 881
 			</ul>';
882
+	}
867 883
 
868 884
 	// List out the packages...
869 885
 	else
@@ -877,11 +893,12 @@  discard block
 block discarded – undo
877 893
 				<li>
878 894
 					<strong><span id="ps_img_', $i, '" class="toggle_up" alt="*" style="display: none;"></span> ', $packageSection['title'], '</strong>';
879 895
 
880
-			if (!empty($packageSection['text']))
881
-				echo '
896
+			if (!empty($packageSection['text'])) {
897
+							echo '
882 898
 					<div class="sub_bar">
883 899
 						<h3 class="subbg">', $packageSection['text'], '</h3>
884 900
 					</div>';
901
+			}
885 902
 
886 903
 			echo '
887 904
 					<', $context['list_type'], ' id="package_section_', $i, '" class="packages">';
@@ -892,24 +909,28 @@  discard block
 block discarded – undo
892 909
 						<li>';
893 910
 
894 911
 				// Textual message. Could be empty just for a blank line...
895
-				if ($package['is_text'])
896
-					echo '
912
+				if ($package['is_text']) {
913
+									echo '
897 914
 							', empty($package['name']) ? '&nbsp;' : $package['name'];
915
+				}
898 916
 
899 917
 				// This is supposed to be a rule..
900
-				elseif ($package['is_line'])
901
-					echo '
918
+				elseif ($package['is_line']) {
919
+									echo '
902 920
 							<hr>';
921
+				}
903 922
 
904 923
 				// A remote link.
905
-				elseif ($package['is_remote'])
906
-					echo '
924
+				elseif ($package['is_remote']) {
925
+									echo '
907 926
 							<strong>', $package['link'], '</strong>';
927
+				}
908 928
 
909 929
 				// A title?
910
-				elseif ($package['is_heading'] || $package['is_title'])
911
-					echo '
930
+				elseif ($package['is_heading'] || $package['is_title']) {
931
+									echo '
912 932
 							<strong>', $package['name'], '</strong>';
933
+				}
913 934
 
914 935
 				// Otherwise, it's a package.
915 936
 				else
@@ -920,32 +941,36 @@  discard block
 block discarded – undo
920 941
 						<ul id="package_section_', $i, '_pkg_', $id, '" class="package_section">';
921 942
 
922 943
 					// Show the mod type?
923
-					if ($package['type'] != '')
924
-						echo '
944
+					if ($package['type'] != '') {
945
+											echo '
925 946
 							<li class="package_section">
926 947
 								', $txt['package_type'], ':&nbsp; ', $smcFunc['ucwords']($smcFunc['strtolower']($package['type'])), '
927 948
 							</li>';
949
+					}
928 950
 
929 951
 					// Show the version number?
930
-					if ($package['version'] != '')
931
-						echo '
952
+					if ($package['version'] != '') {
953
+											echo '
932 954
 							<li class="package_section">
933 955
 								', $txt['mod_version'], ':&nbsp; ', $package['version'], '
934 956
 							</li>';
957
+					}
935 958
 
936 959
 					// How 'bout the author?
937
-					if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link']))
938
-						echo '
960
+					if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link'])) {
961
+											echo '
939 962
 							<li class="package_section">
940 963
 								', $txt['mod_author'], ':&nbsp; ', $package['author']['link'], '
941 964
 							</li>';
965
+					}
942 966
 
943 967
 					// The homepage...
944
-					if ($package['author']['website']['link'] != '')
945
-						echo '
968
+					if ($package['author']['website']['link'] != '') {
969
+											echo '
946 970
 							<li class="package_section">
947 971
 								', $txt['author_website'], ':&nbsp; ', $package['author']['website']['link'], '
948 972
 							</li>';
973
+					}
949 974
 
950 975
 					// Description: bleh bleh!
951 976
 					// Location of file: http://someplace/.
@@ -1004,8 +1029,8 @@  discard block
 block discarded – undo
1004 1029
 
1005 1030
 			foreach ($ps['items'] as $id => $package)
1006 1031
 			{
1007
-				if (!$package['is_text'] && !$package['is_line'] && !$package['is_remote'])
1008
-					echo '
1032
+				if (!$package['is_text'] && !$package['is_line'] && !$package['is_remote']) {
1033
+									echo '
1009 1034
 		var oPackageToggle_', $section, '_pkg_', $id, ' = new smc_Toggle({
1010 1035
 			bToggleEnabled: true,
1011 1036
 			bCurrentlyCollapsed: true,
@@ -1020,6 +1045,7 @@  discard block
 block discarded – undo
1020 1045
 				}
1021 1046
 			]
1022 1047
 		});';
1048
+				}
1023 1049
 			}
1024 1050
 		}
1025 1051
 
@@ -1064,9 +1090,10 @@  discard block
 block discarded – undo
1064 1090
 {
1065 1091
 	global $context, $txt, $scripturl;
1066 1092
 
1067
-	if (!empty($context['saved_successful']))
1068
-		echo '
1093
+	if (!empty($context['saved_successful'])) {
1094
+			echo '
1069 1095
 	<div class="infobox">', $txt['settings_saved'], '</div>';
1096
+	}
1070 1097
 
1071 1098
 	echo '
1072 1099
 	<div id="admincenter">
@@ -1128,8 +1155,9 @@  discard block
 block discarded – undo
1128 1155
 	global $context, $txt;
1129 1156
 
1130 1157
 	// Nothing to do? Brilliant!
1131
-	if (empty($context['package_ftp']))
1132
-		return false;
1158
+	if (empty($context['package_ftp'])) {
1159
+			return false;
1160
+	}
1133 1161
 
1134 1162
 	if (empty($context['package_ftp']['form_elements_only']))
1135 1163
 	{
@@ -1139,19 +1167,21 @@  discard block
 block discarded – undo
1139 1167
 					', $txt['package_ftp_why_file_list'], '
1140 1168
 					<ul style="display: inline;">';
1141 1169
 
1142
-		if (!empty($context['notwritable_files']))
1143
-			foreach ($context['notwritable_files'] as $file)
1170
+		if (!empty($context['notwritable_files'])) {
1171
+					foreach ($context['notwritable_files'] as $file)
1144 1172
 				echo '
1145 1173
 						<li>', $file, '</li>';
1174
+		}
1146 1175
 
1147 1176
 		echo '
1148 1177
 					</ul>';
1149 1178
 
1150
-		if (!$context['server']['is_windows'])
1151
-			echo '
1179
+		if (!$context['server']['is_windows']) {
1180
+					echo '
1152 1181
 					<hr>
1153 1182
 					', $txt['package_chmod_linux'], '<br>
1154 1183
 					<samp># chmod a+w ', implode(' ', $context['notwritable_files']), '</samp>';
1184
+		}
1155 1185
 
1156 1186
 		echo '
1157 1187
 				</div><!-- #need_writable_list -->';
@@ -1164,9 +1194,10 @@  discard block
 block discarded – undo
1164 1194
 					</div>
1165 1195
 				</div>';
1166 1196
 
1167
-	if (!empty($context['package_ftp']['destination']))
1168
-		echo '
1197
+	if (!empty($context['package_ftp']['destination'])) {
1198
+			echo '
1169 1199
 				<form action="', $context['package_ftp']['destination'], '" method="post" accept-charset="', $context['character_set'], '">';
1200
+	}
1170 1201
 
1171 1202
 	echo '
1172 1203
 					<fieldset>
@@ -1200,24 +1231,27 @@  discard block
 block discarded – undo
1200 1231
 					</dl>
1201 1232
 					</fieldset>';
1202 1233
 
1203
-	if (empty($context['package_ftp']['form_elements_only']))
1204
-		echo '
1234
+	if (empty($context['package_ftp']['form_elements_only'])) {
1235
+			echo '
1205 1236
 					<div class="righttext" style="margin: 1ex;">
1206 1237
 						<span id="test_ftp_placeholder_full"></span>
1207 1238
 						<input type="submit" value="', $txt['package_proceed'], '" class="button">
1208 1239
 					</div>';
1240
+	}
1209 1241
 
1210
-	if (!empty($context['package_ftp']['destination']))
1211
-		echo '
1242
+	if (!empty($context['package_ftp']['destination'])) {
1243
+			echo '
1212 1244
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1213 1245
 				</form>';
1246
+	}
1214 1247
 
1215 1248
 	// Hide the details of the list.
1216
-	if (empty($context['package_ftp']['form_elements_only']))
1217
-		echo '
1249
+	if (empty($context['package_ftp']['form_elements_only'])) {
1250
+			echo '
1218 1251
 				<script>
1219 1252
 					document.getElementById(\'need_writable_list\').style.display = \'none\';
1220 1253
 				</script>';
1254
+	}
1221 1255
 
1222 1256
 	// Quick generate the test button.
1223 1257
 	echo '
@@ -1574,9 +1608,10 @@  discard block
 block discarded – undo
1574 1608
 					<td width="30%">
1575 1609
 						<strong>';
1576 1610
 
1577
-		if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
1578
-			echo '
1611
+		if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive')) {
1612
+					echo '
1579 1613
 							<span class="generic_icons folder"></span>';
1614
+		}
1580 1615
 
1581 1616
 		echo '
1582 1617
 							', $name, '
@@ -1603,8 +1638,9 @@  discard block
 block discarded – undo
1603 1638
 					</td>
1604 1639
 				</tr>';
1605 1640
 
1606
-		if (!empty($dir['contents']))
1607
-			template_permission_show_contents($name, $dir['contents'], 1);
1641
+		if (!empty($dir['contents'])) {
1642
+					template_permission_show_contents($name, $dir['contents'], 1);
1643
+		}
1608 1644
 	}
1609 1645
 
1610 1646
 	echo '
@@ -1640,13 +1676,14 @@  discard block
 block discarded – undo
1640 1676
 			</fieldset>';
1641 1677
 
1642 1678
 	// Likely to need FTP?
1643
-	if (empty($context['ftp_connected']))
1644
-		echo '
1679
+	if (empty($context['ftp_connected'])) {
1680
+			echo '
1645 1681
 			<p>
1646 1682
 				', $txt['package_file_perms_ftp_details'], ':
1647 1683
 			</p>
1648 1684
 			', template_control_chmod(), '
1649 1685
 			<div class="noticebox">', $txt['package_file_perms_ftp_retain'], '</div>';
1686
+	}
1650 1687
 
1651 1688
 	echo '
1652 1689
 			<span id="test_ftp_placeholder_full"></span>
@@ -1655,9 +1692,10 @@  discard block
 block discarded – undo
1655 1692
 		</div><!-- .windowbg -->';
1656 1693
 
1657 1694
 	// Any looks fors we've already done?
1658
-	foreach ($context['look_for'] as $path)
1659
-		echo '
1695
+	foreach ($context['look_for'] as $path) {
1696
+			echo '
1660 1697
 		<input type="hidden" name="back_look[]" value="', $path, '">';
1698
+	}
1661 1699
 
1662 1700
 	echo '
1663 1701
 	</form>
@@ -1699,9 +1737,10 @@  discard block
 block discarded – undo
1699 1737
 					<td class="smalltext" width="30%">' . str_repeat('&nbsp;', $level * 5), '
1700 1738
 					', (!empty($dir['type']) && $dir['type'] == 'dir_recursive') || !empty($dir['list_contents']) ? '<a id="link_' . $cur_ident . '" href="' . $scripturl . '?action=admin;area=packages;sa=perms;find=' . base64_encode($ident . '/' . $name) . ';back_look=' . $context['back_look_data'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '#fol_' . $cur_ident . '" onclick="return expandFolder(\'' . $cur_ident . '\', \'' . addcslashes($ident . '/' . $name, "'\\") . '\');">' : '';
1701 1739
 
1702
-			if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
1703
-				echo '
1740
+			if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive')) {
1741
+							echo '
1704 1742
 						<span class="generic_icons folder"></span>';
1743
+			}
1705 1744
 
1706 1745
 			echo '
1707 1746
 						', $name, '
@@ -1719,34 +1758,38 @@  discard block
 block discarded – undo
1719 1758
 				</tr>
1720 1759
 				<tr id="insert_div_loc_' . $cur_ident . '" style="display: none;"><td></td></tr>';
1721 1760
 
1722
-			if (!empty($dir['contents']))
1723
-				template_permission_show_contents($ident . '/' . $name, $dir['contents'], $level + 1, !empty($dir['more_files']));
1761
+			if (!empty($dir['contents'])) {
1762
+							template_permission_show_contents($ident . '/' . $name, $dir['contents'], $level + 1, !empty($dir['more_files']));
1763
+			}
1724 1764
 		}
1725 1765
 	}
1726 1766
 
1727 1767
 	// We have more files to show?
1728
-	if ($has_more)
1729
-		echo '
1768
+	if ($has_more) {
1769
+			echo '
1730 1770
 				<tr class="windowbg" id="content_', $js_ident, '_more">
1731 1771
 					<td class="smalltext" width="40%">' . str_repeat('&nbsp;', $level * 5), '
1732 1772
 						&#171; <a href="' . $scripturl . '?action=admin;area=packages;sa=perms;find=' . base64_encode($ident) . ';fileoffset=', ($context['file_offset'] + $context['file_limit']), ';' . $context['session_var'] . '=' . $context['session_id'] . '#fol_' . preg_replace('~[^A-Za-z0-9_\-=:]~', ':-:', $ident) . '">', $txt['package_file_perms_more_files'], '</a> &#187;
1733 1773
 					</td>
1734 1774
 					<td colspan="6"></td>
1735 1775
 				</tr>';
1776
+	}
1736 1777
 
1737 1778
 	if ($drawn_div)
1738 1779
 	{
1739 1780
 		// Hide anything too far down the tree.
1740 1781
 		$isFound = false;
1741
-		foreach ($context['look_for'] as $tree)
1742
-			if (substr($tree, 0, strlen($ident)) == $ident)
1782
+		foreach ($context['look_for'] as $tree) {
1783
+					if (substr($tree, 0, strlen($ident)) == $ident)
1743 1784
 				$isFound = true;
1785
+		}
1744 1786
 
1745
-		if ($level > 1 && !$isFound)
1746
-			echo '
1787
+		if ($level > 1 && !$isFound) {
1788
+					echo '
1747 1789
 		<script>
1748 1790
 			expandFolder(\'', $js_ident, '\', \'\');
1749 1791
 		</script>';
1792
+		}
1750 1793
 	}
1751 1794
 }
1752 1795
 
@@ -1766,11 +1809,12 @@  discard block
 block discarded – undo
1766 1809
 				<h3 class="catbg">', $txt['package_file_perms_applying'], '</h3>
1767 1810
 			</div>';
1768 1811
 
1769
-	if (!empty($context['skip_ftp']))
1770
-		echo '
1812
+	if (!empty($context['skip_ftp'])) {
1813
+			echo '
1771 1814
 			<div class="errorbox">
1772 1815
 				', $txt['package_file_perms_skipping_ftp'], '
1773 1816
 			</div>';
1817
+	}
1774 1818
 
1775 1819
 	// How many have we done?
1776 1820
 	$remaining_items = count($context['method'] == 'individual' ? $context['to_process'] : $context['directory_list']);
@@ -1808,28 +1852,31 @@  discard block
 block discarded – undo
1808 1852
 				<br>';
1809 1853
 
1810 1854
 	// Put out the right hidden data.
1811
-	if ($context['method'] == 'individual')
1812
-		echo '
1855
+	if ($context['method'] == 'individual') {
1856
+			echo '
1813 1857
 				<input type="hidden" name="custom_value" value="', $context['custom_value'], '">
1814 1858
 				<input type="hidden" name="totalItems" value="', $context['total_items'], '">
1815 1859
 				<input type="hidden" name="toProcess" value="', $context['to_process_encode'], '">';
1816
-	else
1817
-		echo '
1860
+	} else {
1861
+			echo '
1818 1862
 				<input type="hidden" name="predefined" value="', $context['predefined_type'], '">
1819 1863
 				<input type="hidden" name="fileOffset" value="', $context['file_offset'], '">
1820 1864
 				<input type="hidden" name="totalItems" value="', $context['total_items'], '">
1821 1865
 				<input type="hidden" name="dirList" value="', $context['directory_list_encode'], '">
1822 1866
 				<input type="hidden" name="specialFiles" value="', $context['special_files_encode'], '">';
1867
+	}
1823 1868
 
1824 1869
 	// Are we not using FTP for whatever reason.
1825
-	if (!empty($context['skip_ftp']))
1826
-		echo '
1870
+	if (!empty($context['skip_ftp'])) {
1871
+			echo '
1827 1872
 				<input type="hidden" name="skip_ftp" value="1">';
1873
+	}
1828 1874
 
1829 1875
 	// Retain state.
1830
-	foreach ($context['back_look_data'] as $path)
1831
-		echo '
1876
+	foreach ($context['back_look_data'] as $path) {
1877
+			echo '
1832 1878
 				<input type="hidden" name="back_look[]" value="', $path, '">';
1879
+	}
1833 1880
 
1834 1881
 	echo '
1835 1882
 				<input type="hidden" name="method" value="', $context['method'], '">
Please login to merge, or discard this patch.
Sources/BoardIndex.php 1 patch
Braces   +20 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * This function shows the board index.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	$context['canonical_url'] = $scripturl;
35 36
 
36 37
 	// Do not let search engines index anything if there is a random thing in $_GET.
37
-	if (!empty($_GET))
38
-		$context['robot_no_index'] = true;
38
+	if (!empty($_GET)) {
39
+			$context['robot_no_index'] = true;
40
+	}
39 41
 
40 42
 	// Retrieve the categories and boards.
41 43
 	require_once($sourcedir . '/Subs-BoardIndex.php');
@@ -62,11 +64,12 @@  discard block
 block discarded – undo
62 64
 			$context['latest_posts'] = cache_quick_get('boardindex-latest_posts:' . md5($user_info['query_wanna_see_board'] . $user_info['language']), 'Subs-Recent.php', 'cache_getLastPosts', array($latestPostOptions));
63 65
 		}
64 66
 
65
-		if (!empty($context['latest_posts']) || !empty($context['latest_post']))
66
-			$context['info_center'][] = array(
67
+		if (!empty($context['latest_posts']) || !empty($context['latest_post'])) {
68
+					$context['info_center'][] = array(
67 69
 				'tpl' => 'recent',
68 70
 				'txt' => 'recent_posts',
69 71
 			);
72
+		}
70 73
 	}
71 74
 
72 75
 	// Load the calendar?
@@ -87,20 +90,22 @@  discard block
 block discarded – undo
87 90
 		// This is used to show the "how-do-I-edit" help.
88 91
 		$context['calendar_can_edit'] = allowedTo('calendar_edit_any');
89 92
 
90
-		if (!empty($context['show_calendar']))
91
-			$context['info_center'][] = array(
93
+		if (!empty($context['show_calendar'])) {
94
+					$context['info_center'][] = array(
92 95
 				'tpl' => 'calendar',
93 96
 				'txt' => $context['calendar_only_today'] ? 'calendar_today' : 'calendar_upcoming',
94 97
 			);
98
+		}
95 99
 	}
96 100
 
97 101
 	// And stats.
98 102
 	$context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);
99
-	if ($settings['show_stats_index'])
100
-		$context['info_center'][] = array(
103
+	if ($settings['show_stats_index']) {
104
+			$context['info_center'][] = array(
101 105
 				'tpl' => 'stats',
102 106
 				'txt' => 'forum_stats',
103 107
 			);
108
+	}
104 109
 
105 110
 	// Now the online stuff
106 111
 	require_once($sourcedir . '/Subs-MembersOnline.php');
@@ -118,12 +123,14 @@  discard block
 block discarded – undo
118 123
 			);
119 124
 
120 125
 	// Track most online statistics? (Subs-MembersOnline.php)
121
-	if (!empty($modSettings['trackStats']))
122
-		trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
126
+	if (!empty($modSettings['trackStats'])) {
127
+			trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
128
+	}
123 129
 
124 130
 	// Are we showing all membergroups on the board index?
125
-	if (!empty($settings['show_group_key']))
126
-		$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
131
+	if (!empty($settings['show_group_key'])) {
132
+			$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
133
+	}
127 134
 
128 135
 	// And back to normality.
129 136
 	$context['page_title'] = sprintf($txt['forum_index'], $context['forum_name']);
Please login to merge, or discard this patch.
Sources/Security.php 1 patch
Braces   +255 added lines, -197 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * 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) && !httpsOn())
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
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, COALESCE(bg.expire_time, 0) AS expire_time
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -298,14 +315,15 @@  discard block
 block discarded – undo
298 315
 	if (isset($_SESSION['ban']['cannot_access']))
299 316
 	{
300 317
 		// We don't wanna see you!
301
-		if (!$user_info['is_guest'])
302
-			$smcFunc['db_query']('', '
318
+		if (!$user_info['is_guest']) {
319
+					$smcFunc['db_query']('', '
303 320
 				DELETE FROM {db_prefix}log_online
304 321
 				WHERE id_member = {int:current_member}',
305 322
 				array(
306 323
 					'current_member' => $user_info['id'],
307 324
 				)
308 325
 			);
326
+		}
309 327
 
310 328
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
311 329
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -391,9 +409,10 @@  discard block
 block discarded – undo
391 409
 	}
392 410
 
393 411
 	// Fix up the banning permissions.
394
-	if (isset($user_info['permissions']))
395
-		banPermissions();
396
-}
412
+	if (isset($user_info['permissions'])) {
413
+			banPermissions();
414
+	}
415
+	}
397 416
 
398 417
 /**
399 418
  * Fix permissions according to ban status.
@@ -404,8 +423,9 @@  discard block
 block discarded – undo
404 423
 	global $user_info, $sourcedir, $modSettings, $context;
405 424
 
406 425
 	// Somehow they got here, at least take away all permissions...
407
-	if (isset($_SESSION['ban']['cannot_access']))
408
-		$user_info['permissions'] = array();
426
+	if (isset($_SESSION['ban']['cannot_access'])) {
427
+			$user_info['permissions'] = array();
428
+	}
409 429
 	// Okay, well, you can watch, but don't touch a thing.
410 430
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
411 431
 	{
@@ -447,19 +467,20 @@  discard block
 block discarded – undo
447 467
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
448 468
 		foreach ($permission_change as $old => $new)
449 469
 		{
450
-			if (!in_array($old, $user_info['permissions']))
451
-				unset($permission_change[$old]);
452
-			else
453
-				$user_info['permissions'][] = $new;
470
+			if (!in_array($old, $user_info['permissions'])) {
471
+							unset($permission_change[$old]);
472
+			} else {
473
+							$user_info['permissions'][] = $new;
474
+			}
454 475
 		}
455 476
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
456 477
 	}
457 478
 
458 479
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
459 480
 	// Finally, some bits we cache in the session because it saves queries.
460
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
461
-		$user_info['mod_cache'] = $_SESSION['mc'];
462
-	else
481
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
482
+			$user_info['mod_cache'] = $_SESSION['mc'];
483
+	} else
463 484
 	{
464 485
 		require_once($sourcedir . '/Subs-Auth.php');
465 486
 		rebuildModCache();
@@ -470,14 +491,12 @@  discard block
 block discarded – undo
470 491
 	{
471 492
 		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
472 493
 		$context['open_member_reports'] = $_SESSION['rc']['member_reports'];
473
-	}
474
-	elseif ($_SESSION['mc']['bq'] != '0=1')
494
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
475 495
 	{
476 496
 		require_once($sourcedir . '/Subs-ReportedContent.php');
477 497
 		$context['open_mod_reports'] = recountOpenReports('posts');
478 498
 		$context['open_member_reports'] = recountOpenReports('members');
479
-	}
480
-	else
499
+	} else
481 500
 	{
482 501
 		$context['open_mod_reports'] = 0;
483 502
 		$context['open_member_reports'] = 0;
@@ -497,8 +516,9 @@  discard block
 block discarded – undo
497 516
 	global $user_info, $smcFunc;
498 517
 
499 518
 	// Don't log web accelerators, it's very confusing...
500
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
501
-		return;
519
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
520
+			return;
521
+	}
502 522
 
503 523
 	$smcFunc['db_insert']('',
504 524
 		'{db_prefix}log_banned',
@@ -508,8 +528,8 @@  discard block
 block discarded – undo
508 528
 	);
509 529
 
510 530
 	// One extra point for these bans.
511
-	if (!empty($ban_ids))
512
-		$smcFunc['db_query']('', '
531
+	if (!empty($ban_ids)) {
532
+			$smcFunc['db_query']('', '
513 533
 			UPDATE {db_prefix}ban_items
514 534
 			SET hits = hits + 1
515 535
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -517,7 +537,8 @@  discard block
 block discarded – undo
517 537
 				'ban_ids' => $ban_ids,
518 538
 			)
519 539
 		);
520
-}
540
+	}
541
+	}
521 542
 
522 543
 /**
523 544
  * Checks if a given email address might be banned.
@@ -533,8 +554,9 @@  discard block
 block discarded – undo
533 554
 	global $txt, $smcFunc;
534 555
 
535 556
 	// Can't ban an empty email
536
-	if (empty($email) || trim($email) == '')
537
-		return;
557
+	if (empty($email) || trim($email) == '') {
558
+			return;
559
+	}
538 560
 
539 561
 	// Let's start with the bans based on your IP/hostname/memberID...
540 562
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -607,16 +629,18 @@  discard block
 block discarded – undo
607 629
 	if ($type == 'post')
608 630
 	{
609 631
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
610
-		if ($check !== $sc)
611
-			$error = 'session_timeout';
632
+		if ($check !== $sc) {
633
+					$error = 'session_timeout';
634
+		}
612 635
 	}
613 636
 
614 637
 	// How about $_GET['sesc']?
615 638
 	elseif ($type == 'get')
616 639
 	{
617 640
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
618
-		if ($check !== $sc)
619
-			$error = 'session_verify_fail';
641
+		if ($check !== $sc) {
642
+					$error = 'session_verify_fail';
643
+		}
620 644
 	}
621 645
 
622 646
 	// Or can it be in either?
@@ -624,13 +648,15 @@  discard block
 block discarded – undo
624 648
 	{
625 649
 		$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)));
626 650
 
627
-		if ($check !== $sc)
628
-			$error = 'session_verify_fail';
651
+		if ($check !== $sc) {
652
+					$error = 'session_verify_fail';
653
+		}
629 654
 	}
630 655
 
631 656
 	// Verify that they aren't changing user agents on us - that could be bad.
632
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
633
-		$error = 'session_verify_fail';
657
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
658
+			$error = 'session_verify_fail';
659
+	}
634 660
 
635 661
 	// Make sure a page with session check requirement is not being prefetched.
636 662
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -641,30 +667,35 @@  discard block
 block discarded – undo
641 667
 	}
642 668
 
643 669
 	// Check the referring site - it should be the same server at least!
644
-	if (isset($_SESSION['request_referer']))
645
-		$referrer = $_SESSION['request_referer'];
646
-	else
647
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
670
+	if (isset($_SESSION['request_referer'])) {
671
+			$referrer = $_SESSION['request_referer'];
672
+	} else {
673
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
674
+	}
648 675
 	if (!empty($referrer['host']))
649 676
 	{
650
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
651
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
652
-		else
653
-			$real_host = $_SERVER['HTTP_HOST'];
677
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
678
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
679
+		} else {
680
+					$real_host = $_SERVER['HTTP_HOST'];
681
+		}
654 682
 
655 683
 		$parsed_url = parse_url($boardurl);
656 684
 
657 685
 		// Are global cookies on?  If so, let's check them ;).
658 686
 		if (!empty($modSettings['globalCookies']))
659 687
 		{
660
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
661
-				$parsed_url['host'] = $parts[1];
688
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
689
+							$parsed_url['host'] = $parts[1];
690
+			}
662 691
 
663
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
664
-				$referrer['host'] = $parts[1];
692
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
693
+							$referrer['host'] = $parts[1];
694
+			}
665 695
 
666
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
667
-				$real_host = $parts[1];
696
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
697
+							$real_host = $parts[1];
698
+			}
668 699
 		}
669 700
 
670 701
 		// Okay: referrer must either match parsed_url or real_host.
@@ -682,12 +713,14 @@  discard block
 block discarded – undo
682 713
 		$log_error = true;
683 714
 	}
684 715
 
685
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
686
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
716
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
717
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
718
+	}
687 719
 
688 720
 	// Everything is ok, return an empty string.
689
-	if (!isset($error))
690
-		return '';
721
+	if (!isset($error)) {
722
+			return '';
723
+	}
691 724
 	// A session error occurred, show the error.
692 725
 	elseif ($is_fatal)
693 726
 	{
@@ -696,13 +729,14 @@  discard block
 block discarded – undo
696 729
 			ob_end_clean();
697 730
 			header('HTTP/1.1 403 Forbidden - Session timeout');
698 731
 			die;
732
+		} else {
733
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
699 734
 		}
700
-		else
701
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
702 735
 	}
703 736
 	// A session error occurred, return the error to the calling function.
704
-	else
705
-		return $error;
737
+	else {
738
+			return $error;
739
+	}
706 740
 
707 741
 	// We really should never fall through here, for very important reasons.  Let's make sure.
708 742
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -718,10 +752,9 @@  discard block
 block discarded – undo
718 752
 {
719 753
 	global $modSettings;
720 754
 
721
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
722
-		return true;
723
-
724
-	else
755
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
756
+			return true;
757
+	} else
725 758
 	{
726 759
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
727 760
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -772,9 +805,9 @@  discard block
 block discarded – undo
772 805
 			$return = $_SESSION['token'][$type . '-' . $action][3];
773 806
 			unset($_SESSION['token'][$type . '-' . $action]);
774 807
 			return $return;
808
+		} else {
809
+					return '';
775 810
 		}
776
-		else
777
-			return '';
778 811
 	}
779 812
 
780 813
 	// This nasty piece of code validates a token.
@@ -805,12 +838,14 @@  discard block
 block discarded – undo
805 838
 		fatal_lang_error('token_verify_fail', false);
806 839
 	}
807 840
 	// Remove this token as its useless
808
-	else
809
-		unset($_SESSION['token'][$type . '-' . $action]);
841
+	else {
842
+			unset($_SESSION['token'][$type . '-' . $action]);
843
+	}
810 844
 
811 845
 	// Randomly check if we should remove some older tokens.
812
-	if (mt_rand(0, 138) == 23)
813
-		cleanTokens();
846
+	if (mt_rand(0, 138) == 23) {
847
+			cleanTokens();
848
+	}
814 849
 
815 850
 	return false;
816 851
 }
@@ -825,14 +860,16 @@  discard block
 block discarded – undo
825 860
 function cleanTokens($complete = false)
826 861
 {
827 862
 	// We appreciate cleaning up after yourselves.
828
-	if (!isset($_SESSION['token']))
829
-		return;
863
+	if (!isset($_SESSION['token'])) {
864
+			return;
865
+	}
830 866
 
831 867
 	// Clean up tokens, trying to give enough time still.
832
-	foreach ($_SESSION['token'] as $key => $data)
833
-		if ($data[2] + 10800 < time() || $complete)
868
+	foreach ($_SESSION['token'] as $key => $data) {
869
+			if ($data[2] + 10800 < time() || $complete)
834 870
 			unset($_SESSION['token'][$key]);
835
-}
871
+	}
872
+	}
836 873
 
837 874
 /**
838 875
  * Check whether a form has been submitted twice.
@@ -850,37 +887,40 @@  discard block
 block discarded – undo
850 887
 {
851 888
 	global $context;
852 889
 
853
-	if (!isset($_SESSION['forms']))
854
-		$_SESSION['forms'] = array();
890
+	if (!isset($_SESSION['forms'])) {
891
+			$_SESSION['forms'] = array();
892
+	}
855 893
 
856 894
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
857 895
 	if ($action == 'register')
858 896
 	{
859 897
 		$context['form_sequence_number'] = 0;
860
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
861
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
898
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
899
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
900
+		}
862 901
 	}
863 902
 	// Check whether the submitted number can be found in the session.
864 903
 	elseif ($action == 'check')
865 904
 	{
866
-		if (!isset($_REQUEST['seqnum']))
867
-			return true;
868
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
905
+		if (!isset($_REQUEST['seqnum'])) {
906
+					return true;
907
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
869 908
 		{
870 909
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
871 910
 			return true;
911
+		} elseif ($is_fatal) {
912
+					fatal_lang_error('error_form_already_submitted', false);
913
+		} else {
914
+					return false;
872 915
 		}
873
-		elseif ($is_fatal)
874
-			fatal_lang_error('error_form_already_submitted', false);
875
-		else
876
-			return false;
877 916
 	}
878 917
 	// Don't check, just free the stack number.
879
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
880
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
881
-	elseif ($action != 'free')
882
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
883
-}
918
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
919
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
920
+	} elseif ($action != 'free') {
921
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
922
+	}
923
+	}
884 924
 
885 925
 /**
886 926
  * Check the user's permissions.
@@ -899,16 +939,19 @@  discard block
 block discarded – undo
899 939
 	global $user_info, $smcFunc;
900 940
 
901 941
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
902
-	if (empty($permission))
903
-		return true;
942
+	if (empty($permission)) {
943
+			return true;
944
+	}
904 945
 
905 946
 	// You're never allowed to do something if your data hasn't been loaded yet!
906
-	if (empty($user_info))
907
-		return false;
947
+	if (empty($user_info)) {
948
+			return false;
949
+	}
908 950
 
909 951
 	// Administrators are supermen :P.
910
-	if ($user_info['is_admin'])
911
-		return true;
952
+	if ($user_info['is_admin']) {
953
+			return true;
954
+	}
912 955
 
913 956
 	// Let's ensure this is an array.
914 957
 	$permission = (array) $permission;
@@ -916,14 +959,16 @@  discard block
 block discarded – undo
916 959
 	// Are we checking the _current_ board, or some other boards?
917 960
 	if ($boards === null)
918 961
 	{
919
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
920
-			return true;
962
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
963
+					return true;
964
+		}
921 965
 		// You aren't allowed, by default.
922
-		else
923
-			return false;
966
+		else {
967
+					return false;
968
+		}
969
+	} elseif (!is_array($boards)) {
970
+			$boards = array($boards);
924 971
 	}
925
-	elseif (!is_array($boards))
926
-		$boards = array($boards);
927 972
 
928 973
 	$request = $smcFunc['db_query']('', '
929 974
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -951,20 +996,23 @@  discard block
 block discarded – undo
951 996
 		while ($row = $smcFunc['db_fetch_assoc']($request))
952 997
 		{
953 998
 			$result = !empty($row['add_deny']);
954
-			if ($result == true)
955
-				break;
999
+			if ($result == true) {
1000
+							break;
1001
+			}
956 1002
 		}
957 1003
 		$smcFunc['db_free_result']($request);
958 1004
 		return $result;
959 1005
 	}
960 1006
 
961 1007
 	// Make sure they can do it on all of the boards.
962
-	if ($smcFunc['db_num_rows']($request) != count($boards))
963
-		return false;
1008
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
1009
+			return false;
1010
+	}
964 1011
 
965 1012
 	$result = true;
966
-	while ($row = $smcFunc['db_fetch_assoc']($request))
967
-		$result &= !empty($row['add_deny']);
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$result &= !empty($row['add_deny']);
1015
+	}
968 1016
 	$smcFunc['db_free_result']($request);
969 1017
 
970 1018
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1031,9 +1079,10 @@  discard block
 block discarded – undo
1031 1079
 
1032 1080
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1033 1081
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1034
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1035
-		validateSession();
1036
-}
1082
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1083
+			validateSession();
1084
+	}
1085
+	}
1037 1086
 
1038 1087
 /**
1039 1088
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1064,13 +1113,14 @@  discard block
 block discarded – undo
1064 1113
 	// Administrators are all powerful, sorry.
1065 1114
 	if ($user_info['is_admin'])
1066 1115
 	{
1067
-		if ($simple)
1068
-			return array(0);
1069
-		else
1116
+		if ($simple) {
1117
+					return array(0);
1118
+		} else
1070 1119
 		{
1071 1120
 			$boards = array();
1072
-			foreach ($permissions as $permission)
1073
-				$boards[$permission] = array(0);
1121
+			foreach ($permissions as $permission) {
1122
+							$boards[$permission] = array(0);
1123
+			}
1074 1124
 
1075 1125
 			return $boards;
1076 1126
 		}
@@ -1102,31 +1152,32 @@  discard block
 block discarded – undo
1102 1152
 	{
1103 1153
 		if ($simple)
1104 1154
 		{
1105
-			if (empty($row['add_deny']))
1106
-				$deny_boards[] = $row['id_board'];
1107
-			else
1108
-				$boards[] = $row['id_board'];
1109
-		}
1110
-		else
1155
+			if (empty($row['add_deny'])) {
1156
+							$deny_boards[] = $row['id_board'];
1157
+			} else {
1158
+							$boards[] = $row['id_board'];
1159
+			}
1160
+		} else
1111 1161
 		{
1112
-			if (empty($row['add_deny']))
1113
-				$deny_boards[$row['permission']][] = $row['id_board'];
1114
-			else
1115
-				$boards[$row['permission']][] = $row['id_board'];
1162
+			if (empty($row['add_deny'])) {
1163
+							$deny_boards[$row['permission']][] = $row['id_board'];
1164
+			} else {
1165
+							$boards[$row['permission']][] = $row['id_board'];
1166
+			}
1116 1167
 		}
1117 1168
 	}
1118 1169
 	$smcFunc['db_free_result']($request);
1119 1170
 
1120
-	if ($simple)
1121
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1122
-	else
1171
+	if ($simple) {
1172
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1173
+	} else
1123 1174
 	{
1124 1175
 		foreach ($permissions as $permission)
1125 1176
 		{
1126 1177
 			// never had it to start with
1127
-			if (empty($boards[$permission]))
1128
-				$boards[$permission] = array();
1129
-			else
1178
+			if (empty($boards[$permission])) {
1179
+							$boards[$permission] = array();
1180
+			} else
1130 1181
 			{
1131 1182
 				// Or it may have been removed
1132 1183
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1162,10 +1213,11 @@  discard block
 block discarded – undo
1162 1213
 
1163 1214
 
1164 1215
 	// Moderators are free...
1165
-	if (!allowedTo('moderate_board'))
1166
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1167
-	else
1168
-		$timeLimit = 2;
1216
+	if (!allowedTo('moderate_board')) {
1217
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1218
+	} else {
1219
+			$timeLimit = 2;
1220
+	}
1169 1221
 
1170 1222
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1171 1223
 
@@ -1192,8 +1244,9 @@  discard block
 block discarded – undo
1192 1244
 	if ($smcFunc['db_affected_rows']() != 1)
1193 1245
 	{
1194 1246
 		// Spammer!  You only have to wait a *few* seconds!
1195
-		if (!$only_return_result)
1196
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1247
+		if (!$only_return_result) {
1248
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1249
+		}
1197 1250
 
1198 1251
 		return true;
1199 1252
 	}
@@ -1211,11 +1264,13 @@  discard block
 block discarded – undo
1211 1264
  */
1212 1265
 function secureDirectory($path, $attachments = false)
1213 1266
 {
1214
-	if (empty($path))
1215
-		return 'empty_path';
1267
+	if (empty($path)) {
1268
+			return 'empty_path';
1269
+	}
1216 1270
 
1217
-	if (!is_writable($path))
1218
-		return 'path_not_writable';
1271
+	if (!is_writable($path)) {
1272
+			return 'path_not_writable';
1273
+	}
1219 1274
 
1220 1275
 	$directoryname = basename($path);
1221 1276
 
@@ -1227,9 +1282,9 @@  discard block
 block discarded – undo
1227 1282
 
1228 1283
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1229 1284
 
1230
-	if (file_exists($path . '/.htaccess'))
1231
-		$errors[] = 'htaccess_exists';
1232
-	else
1285
+	if (file_exists($path . '/.htaccess')) {
1286
+			$errors[] = 'htaccess_exists';
1287
+	} else
1233 1288
 	{
1234 1289
 		$fh = @fopen($path . '/.htaccess', 'w');
1235 1290
 		if ($fh)
@@ -1242,9 +1297,9 @@  discard block
 block discarded – undo
1242 1297
 		$errors[] = 'htaccess_cannot_create_file';
1243 1298
 	}
1244 1299
 
1245
-	if (file_exists($path . '/index.php'))
1246
-		$errors[] = 'index-php_exists';
1247
-	else
1300
+	if (file_exists($path . '/index.php')) {
1301
+			$errors[] = 'index-php_exists';
1302
+	} else
1248 1303
 	{
1249 1304
 		$fh = @fopen($path . '/index.php', 'w');
1250 1305
 		if ($fh)
@@ -1272,11 +1327,12 @@  discard block
 block discarded – undo
1272 1327
 		$errors[] = 'index-php_cannot_create_file';
1273 1328
 	}
1274 1329
 
1275
-	if (!empty($errors))
1276
-		return $errors;
1277
-	else
1278
-		return true;
1279
-}
1330
+	if (!empty($errors)) {
1331
+			return $errors;
1332
+	} else {
1333
+			return true;
1334
+	}
1335
+	}
1280 1336
 
1281 1337
 /**
1282 1338
 * This sets the X-Frame-Options header.
@@ -1289,14 +1345,16 @@  discard block
 block discarded – undo
1289 1345
 	global $modSettings;
1290 1346
 
1291 1347
 	$option = 'SAMEORIGIN';
1292
-	if (is_null($override) && !empty($modSettings['frame_security']))
1293
-		$option = $modSettings['frame_security'];
1294
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1295
-		$option = $override;
1348
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1349
+			$option = $modSettings['frame_security'];
1350
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1351
+			$option = $override;
1352
+	}
1296 1353
 
1297 1354
 	// Don't bother setting the header if we have disabled it.
1298
-	if ($option == 'DISABLE')
1299
-		return;
1355
+	if ($option == 'DISABLE') {
1356
+			return;
1357
+	}
1300 1358
 
1301 1359
 	// Finally set it.
1302 1360
 	header('x-frame-options: ' . $option);
Please login to merge, or discard this patch.
Sources/Post.php 1 patch
Braces   +677 added lines, -523 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -60,12 +63,14 @@  discard block
 block discarded – undo
60 63
 	{
61 64
 		// Get ids of all the boards they can post in.
62 65
 		$post_permissions = array('post_new');
63
-		if ($modSettings['postmod_active'])
64
-			$post_permissions[] = 'post_unapproved_topics';
66
+		if ($modSettings['postmod_active']) {
67
+					$post_permissions[] = 'post_unapproved_topics';
68
+		}
65 69
 
66 70
 		$boards = boardsAllowedTo($post_permissions);
67
-		if (empty($boards))
68
-			fatal_lang_error('cannot_post_new', false);
71
+		if (empty($boards)) {
72
+					fatal_lang_error('cannot_post_new', false);
73
+		}
69 74
 
70 75
 		// Get a list of boards for the select menu
71 76
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -78,8 +83,9 @@  discard block
 block discarded – undo
78 83
 		$board_list = getBoardList($boardListOptions);
79 84
 	}
80 85
 	// Let's keep things simple for ourselves below
81
-	else
82
-		$boards = array($board);
86
+	else {
87
+			$boards = array($board);
88
+	}
83 89
 
84 90
 	require_once($sourcedir . '/Subs-Post.php');
85 91
 
@@ -102,10 +108,11 @@  discard block
 block discarded – undo
102 108
 			array(
103 109
 				'msg' => (int) $_REQUEST['msg'],
104 110
 		));
105
-		if ($smcFunc['db_num_rows']($request) != 1)
106
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
107
-		else
108
-			list ($topic) = $smcFunc['db_fetch_row']($request);
111
+		if ($smcFunc['db_num_rows']($request) != 1) {
112
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
113
+		} else {
114
+					list ($topic) = $smcFunc['db_fetch_row']($request);
115
+		}
109 116
 		$smcFunc['db_free_result']($request);
110 117
 	}
111 118
 
@@ -132,33 +139,36 @@  discard block
 block discarded – undo
132 139
 		$smcFunc['db_free_result']($request);
133 140
 
134 141
 		// If this topic already has a poll, they sure can't add another.
135
-		if (isset($_REQUEST['poll']) && $pollID > 0)
136
-			unset($_REQUEST['poll']);
142
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
143
+					unset($_REQUEST['poll']);
144
+		}
137 145
 
138 146
 		if (empty($_REQUEST['msg']))
139 147
 		{
140
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
141
-				is_not_guest();
148
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
149
+							is_not_guest();
150
+			}
142 151
 
143 152
 			// By default the reply will be approved...
144 153
 			$context['becomes_approved'] = true;
145 154
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
146 155
 			{
147
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
148
-					$context['becomes_approved'] = false;
149
-				else
150
-					isAllowedTo('post_reply_any');
151
-			}
152
-			elseif (!allowedTo('post_reply_any'))
156
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
157
+									$context['becomes_approved'] = false;
158
+				} else {
159
+									isAllowedTo('post_reply_any');
160
+				}
161
+			} elseif (!allowedTo('post_reply_any'))
153 162
 			{
154
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
155
-					$context['becomes_approved'] = false;
156
-				else
157
-					isAllowedTo('post_reply_own');
163
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
164
+									$context['becomes_approved'] = false;
165
+				} else {
166
+									isAllowedTo('post_reply_own');
167
+				}
158 168
 			}
169
+		} else {
170
+					$context['becomes_approved'] = true;
159 171
 		}
160
-		else
161
-			$context['becomes_approved'] = true;
162 172
 
163 173
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
164 174
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -173,17 +183,18 @@  discard block
 block discarded – undo
173 183
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
174 184
 
175 185
 		// Check whether this is a really old post being bumped...
176
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
177
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
178
-	}
179
-	else
186
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
187
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
188
+		}
189
+	} else
180 190
 	{
181 191
 		// @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu
182 192
 		$context['becomes_approved'] = true;
183
-		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true))
184
-			$context['becomes_approved'] = false;
185
-		else
186
-			isAllowedTo('post_new', $boards, true);
193
+		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) {
194
+					$context['becomes_approved'] = false;
195
+		} else {
196
+					isAllowedTo('post_new', $boards, true);
197
+		}
187 198
 
188 199
 		$locked = 0;
189 200
 		$context['already_locked'] = 0;
@@ -213,27 +224,32 @@  discard block
 block discarded – undo
213 224
 	if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached']))
214 225
 	{
215 226
 		require_once($sourcedir . '/ManageAttachments.php');
216
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
217
-			removeAttachments(array('id_attach' => $attachID));
227
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
228
+					removeAttachments(array('id_attach' => $attachID));
229
+		}
218 230
 
219 231
 		unset($_SESSION['already_attached']);
220 232
 	}
221 233
 
222 234
 	// Don't allow a post if it's locked and you aren't all powerful.
223
-	if ($locked && !allowedTo('moderate_board'))
224
-		fatal_lang_error('topic_locked', false);
235
+	if ($locked && !allowedTo('moderate_board')) {
236
+			fatal_lang_error('topic_locked', false);
237
+	}
225 238
 	// Check the users permissions - is the user allowed to add or post a poll?
226 239
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
227 240
 	{
228 241
 		// New topic, new poll.
229
-		if (empty($topic))
230
-			isAllowedTo('poll_post');
242
+		if (empty($topic)) {
243
+					isAllowedTo('poll_post');
244
+		}
231 245
 		// This is an old topic - but it is yours!  Can you add to it?
232
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
233
-			isAllowedTo('poll_add_own');
246
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
247
+					isAllowedTo('poll_add_own');
248
+		}
234 249
 		// If you're not the owner, can you add to any poll?
235
-		else
236
-			isAllowedTo('poll_add_any');
250
+		else {
251
+					isAllowedTo('poll_add_any');
252
+		}
237 253
 
238 254
 		if (!empty($board))
239 255
 		{
@@ -242,8 +258,9 @@  discard block
 block discarded – undo
242 258
 			$guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']);
243 259
 		}
244 260
 		// No board, so we'll have to check this again in Post2
245
-		else
246
-			$guest_vote_enabled = true;
261
+		else {
262
+					$guest_vote_enabled = true;
263
+		}
247 264
 
248 265
 		// Set up the poll options.
249 266
 		$context['poll_options'] = array(
@@ -269,8 +286,9 @@  discard block
 block discarded – undo
269 286
 	if ($context['make_event'])
270 287
 	{
271 288
 		// They might want to pick a board.
272
-		if (!isset($context['current_board']))
273
-			$context['current_board'] = 0;
289
+		if (!isset($context['current_board'])) {
290
+					$context['current_board'] = 0;
291
+		}
274 292
 
275 293
 		// Start loading up the event info.
276 294
 		$context['event'] = array();
@@ -284,10 +302,11 @@  discard block
 block discarded – undo
284 302
 		isAllowedTo('calendar_post');
285 303
 
286 304
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
287
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
288
-			$time_string = '%k:%M';
289
-		else
290
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
305
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
306
+					$time_string = '%k:%M';
307
+		} else {
308
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
309
+		}
291 310
 
292 311
 		$js_time_string = str_replace(
293 312
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -309,8 +328,7 @@  discard block
 block discarded – undo
309 328
 			require_once($sourcedir . '/Subs-Calendar.php');
310 329
 			$eventProperties = getEventProperties($context['event']['id']);
311 330
 			$context['event'] = array_merge($context['event'], $eventProperties);
312
-		}
313
-		else
331
+		} else
314 332
 		{
315 333
 			// Get the current event information.
316 334
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -318,10 +336,12 @@  discard block
 block discarded – undo
318 336
 			$context['event'] = array_merge($context['event'], $eventProperties);
319 337
 
320 338
 			// Make sure the year and month are in the valid range.
321
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
322
-				fatal_lang_error('invalid_month', false);
323
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
324
-				fatal_lang_error('invalid_year', false);
339
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
340
+							fatal_lang_error('invalid_month', false);
341
+			}
342
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
343
+							fatal_lang_error('invalid_year', false);
344
+			}
325 345
 
326 346
 			$context['event']['categories'] = $board_list;
327 347
 		}
@@ -432,10 +452,11 @@  discard block
 block discarded – undo
432 452
 
433 453
 			if (!empty($context['new_replies']))
434 454
 			{
435
-				if ($context['new_replies'] == 1)
436
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
437
-				else
438
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
455
+				if ($context['new_replies'] == 1) {
456
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
457
+				} else {
458
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
459
+				}
439 460
 
440 461
 				$post_errors[] = 'new_replies';
441 462
 
@@ -447,9 +468,9 @@  discard block
 block discarded – undo
447 468
 	// Get a response prefix (like 'Re:') in the default forum language.
448 469
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
449 470
 	{
450
-		if ($language === $user_info['language'])
451
-			$context['response_prefix'] = $txt['response_prefix'];
452
-		else
471
+		if ($language === $user_info['language']) {
472
+					$context['response_prefix'] = $txt['response_prefix'];
473
+		} else
453 474
 		{
454 475
 			loadLanguage('index', $language, false);
455 476
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -462,23 +483,26 @@  discard block
 block discarded – undo
462 483
 	// Do we have a body, but an error happened.
463 484
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
464 485
 	{
465
-		if (isset($_REQUEST['quickReply']))
466
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
486
+		if (isset($_REQUEST['quickReply'])) {
487
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
488
+		}
467 489
 
468 490
 		// Validate inputs.
469 491
 		if (empty($context['post_error']))
470 492
 		{
471 493
 			// This means they didn't click Post and get an error.
472 494
 			$really_previewing = true;
473
-		}
474
-		else
495
+		} else
475 496
 		{
476
-			if (!isset($_REQUEST['subject']))
477
-				$_REQUEST['subject'] = '';
478
-			if (!isset($_REQUEST['message']))
479
-				$_REQUEST['message'] = '';
480
-			if (!isset($_REQUEST['icon']))
481
-				$_REQUEST['icon'] = 'xx';
497
+			if (!isset($_REQUEST['subject'])) {
498
+							$_REQUEST['subject'] = '';
499
+			}
500
+			if (!isset($_REQUEST['message'])) {
501
+							$_REQUEST['message'] = '';
502
+			}
503
+			if (!isset($_REQUEST['icon'])) {
504
+							$_REQUEST['icon'] = 'xx';
505
+			}
482 506
 
483 507
 			// They are previewing if they asked to preview (i.e. came from quick reply).
484 508
 			$really_previewing = !empty($_POST['preview']);
@@ -494,8 +518,9 @@  discard block
 block discarded – undo
494 518
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
495 519
 
496 520
 		// Make sure the subject isn't too long - taking into account special characters.
497
-		if ($smcFunc['strlen']($form_subject) > 100)
498
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
521
+		if ($smcFunc['strlen']($form_subject) > 100) {
522
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
523
+		}
499 524
 
500 525
 		if (isset($_REQUEST['poll']))
501 526
 		{
@@ -507,8 +532,9 @@  discard block
 block discarded – undo
507 532
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
508 533
 			foreach ($_POST['options'] as $option)
509 534
 			{
510
-				if (trim($option) == '')
511
-					continue;
535
+				if (trim($option) == '') {
536
+									continue;
537
+				}
512 538
 
513 539
 				$context['choices'][] = array(
514 540
 					'id' => $choice_id++,
@@ -570,13 +596,14 @@  discard block
 block discarded – undo
570 596
 				$context['preview_subject'] = $form_subject;
571 597
 
572 598
 				censorText($context['preview_subject']);
599
+			} else {
600
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
573 601
 			}
574
-			else
575
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
576 602
 
577 603
 			// Protect any CDATA blocks.
578
-			if (isset($_REQUEST['xml']))
579
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
604
+			if (isset($_REQUEST['xml'])) {
605
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
606
+			}
580 607
 		}
581 608
 
582 609
 		// Set up the checkboxes.
@@ -615,29 +642,32 @@  discard block
 block discarded – undo
615 642
 			);
616 643
 			// The message they were trying to edit was most likely deleted.
617 644
 			// @todo Change this error message?
618
-			if ($smcFunc['db_num_rows']($request) == 0)
619
-				fatal_lang_error('no_board', false);
645
+			if ($smcFunc['db_num_rows']($request) == 0) {
646
+							fatal_lang_error('no_board', false);
647
+			}
620 648
 			$row = $smcFunc['db_fetch_assoc']($request);
621 649
 
622 650
 			$attachment_stuff = array($row);
623
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
624
-				$attachment_stuff[] = $row2;
651
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
652
+							$attachment_stuff[] = $row2;
653
+			}
625 654
 			$smcFunc['db_free_result']($request);
626 655
 
627 656
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
628 657
 			{
629 658
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
630
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
631
-					fatal_lang_error('modify_post_time_passed', false);
632
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
633
-					isAllowedTo('modify_replies');
634
-				else
635
-					isAllowedTo('modify_own');
659
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
660
+									fatal_lang_error('modify_post_time_passed', false);
661
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
662
+									isAllowedTo('modify_replies');
663
+				} else {
664
+									isAllowedTo('modify_own');
665
+				}
666
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
667
+							isAllowedTo('modify_replies');
668
+			} else {
669
+							isAllowedTo('modify_any');
636 670
 			}
637
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
638
-				isAllowedTo('modify_replies');
639
-			else
640
-				isAllowedTo('modify_any');
641 671
 
642 672
 			if ($context['can_announce'] && !empty($row['id_action']))
643 673
 			{
@@ -661,8 +691,9 @@  discard block
 block discarded – undo
661 691
 
662 692
 				while ($row = $smcFunc['db_fetch_assoc']($request))
663 693
 				{
664
-					if ($row['filesize'] <= 0)
665
-						continue;
694
+					if ($row['filesize'] <= 0) {
695
+											continue;
696
+					}
666 697
 					$context['current_attachments'][$row['id_attach']] = array(
667 698
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
668 699
 						'size' => $row['filesize'],
@@ -732,29 +763,32 @@  discard block
 block discarded – undo
732 763
 			)
733 764
 		);
734 765
 		// The message they were trying to edit was most likely deleted.
735
-		if ($smcFunc['db_num_rows']($request) == 0)
736
-			fatal_lang_error('no_message', false);
766
+		if ($smcFunc['db_num_rows']($request) == 0) {
767
+					fatal_lang_error('no_message', false);
768
+		}
737 769
 		$row = $smcFunc['db_fetch_assoc']($request);
738 770
 
739 771
 		$attachment_stuff = array($row);
740
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
741
-			$attachment_stuff[] = $row2;
772
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
773
+					$attachment_stuff[] = $row2;
774
+		}
742 775
 		$smcFunc['db_free_result']($request);
743 776
 
744 777
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
745 778
 		{
746 779
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
747
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
748
-				fatal_lang_error('modify_post_time_passed', false);
749
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
750
-				isAllowedTo('modify_replies');
751
-			else
752
-				isAllowedTo('modify_own');
780
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
781
+							fatal_lang_error('modify_post_time_passed', false);
782
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
783
+							isAllowedTo('modify_replies');
784
+			} else {
785
+							isAllowedTo('modify_own');
786
+			}
787
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
788
+					isAllowedTo('modify_replies');
789
+		} else {
790
+					isAllowedTo('modify_any');
753 791
 		}
754
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
755
-			isAllowedTo('modify_replies');
756
-		else
757
-			isAllowedTo('modify_any');
758 792
 
759 793
 		if ($context['can_announce'] && !empty($row['id_action']))
760 794
 		{
@@ -781,15 +815,17 @@  discard block
 block discarded – undo
781 815
 		$context['icon'] = $row['icon'];
782 816
 
783 817
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
784
-		if (!$row['approved'] && !$context['show_approval'])
785
-			$context['show_approval'] = allowedTo('approve_posts');
818
+		if (!$row['approved'] && !$context['show_approval']) {
819
+					$context['show_approval'] = allowedTo('approve_posts');
820
+		}
786 821
 
787 822
 		// Sort the attachments so they are in the order saved
788 823
 		$temp = array();
789 824
 		foreach ($attachment_stuff as $attachment)
790 825
 		{
791
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
792
-				$temp[$attachment['id_attach']] = $attachment;
826
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
827
+							$temp[$attachment['id_attach']] = $attachment;
828
+			}
793 829
 		}
794 830
 		ksort($temp);
795 831
 
@@ -850,14 +886,16 @@  discard block
 block discarded – undo
850 886
 					'is_approved' => 1,
851 887
 				)
852 888
 			);
853
-			if ($smcFunc['db_num_rows']($request) == 0)
854
-				fatal_lang_error('quoted_post_deleted', false);
889
+			if ($smcFunc['db_num_rows']($request) == 0) {
890
+							fatal_lang_error('quoted_post_deleted', false);
891
+			}
855 892
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
856 893
 			$smcFunc['db_free_result']($request);
857 894
 
858 895
 			// Add 'Re: ' to the front of the quoted subject.
859
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
860
-				$form_subject = $context['response_prefix'] . $form_subject;
896
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
897
+							$form_subject = $context['response_prefix'] . $form_subject;
898
+			}
861 899
 
862 900
 			// Censor the message and subject.
863 901
 			censorText($form_message);
@@ -870,10 +908,11 @@  discard block
 block discarded – undo
870 908
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
871 909
 				{
872 910
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
873
-					if ($i % 4 == 0)
874
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
911
+					if ($i % 4 == 0) {
912
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
875 913
 						{
876 914
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
915
+					}
877 916
 						}, $parts[$i]);
878 917
 				}
879 918
 				$form_message = implode('', $parts);
@@ -882,8 +921,9 @@  discard block
 block discarded – undo
882 921
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
883 922
 
884 923
 			// Remove any nested quotes, if necessary.
885
-			if (!empty($modSettings['removeNestedQuotes']))
886
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
924
+			if (!empty($modSettings['removeNestedQuotes'])) {
925
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
926
+			}
887 927
 
888 928
 			// Add a quote string on the front and end.
889 929
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -895,15 +935,15 @@  discard block
 block discarded – undo
895 935
 			$form_subject = $first_subject;
896 936
 
897 937
 			// Add 'Re: ' to the front of the subject.
898
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
899
-				$form_subject = $context['response_prefix'] . $form_subject;
938
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
939
+							$form_subject = $context['response_prefix'] . $form_subject;
940
+			}
900 941
 
901 942
 			// Censor the subject.
902 943
 			censorText($form_subject);
903 944
 
904 945
 			$form_message = '';
905
-		}
906
-		else
946
+		} else
907 947
 		{
908 948
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
909 949
 			$form_message = '';
@@ -922,13 +962,15 @@  discard block
 block discarded – undo
922 962
 		if (isset($_REQUEST['msg']))
923 963
 		{
924 964
 			$context['attachments']['quantity'] = count($context['current_attachments']);
925
-			foreach ($context['current_attachments'] as $attachment)
926
-				$context['attachments']['total_size'] += $attachment['size'];
965
+			foreach ($context['current_attachments'] as $attachment) {
966
+							$context['attachments']['total_size'] += $attachment['size'];
967
+			}
927 968
 		}
928 969
 
929 970
 		// A bit of house keeping first.
930
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
931
-			unset($_SESSION['temp_attachments']);
971
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
972
+					unset($_SESSION['temp_attachments']);
973
+		}
932 974
 
933 975
 		if (!empty($_SESSION['temp_attachments']))
934 976
 		{
@@ -937,9 +979,10 @@  discard block
 block discarded – undo
937 979
 			{
938 980
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
939 981
 				{
940
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
941
-						if (file_exists($attachment['tmp_name']))
982
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
983
+											if (file_exists($attachment['tmp_name']))
942 984
 							unlink($attachment['tmp_name']);
985
+					}
943 986
 				}
944 987
 				$post_errors[] = 'temp_attachments_gone';
945 988
 				$_SESSION['temp_attachments'] = array();
@@ -953,8 +996,9 @@  discard block
 block discarded – undo
953 996
 					// See if any files still exist before showing the warning message and the files attached.
954 997
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
955 998
 					{
956
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
957
-							continue;
999
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1000
+													continue;
1001
+						}
958 1002
 
959 1003
 						if (file_exists($attachment['tmp_name']))
960 1004
 						{
@@ -964,20 +1008,21 @@  discard block
 block discarded – undo
964 1008
 							break;
965 1009
 						}
966 1010
 					}
967
-				}
968
-				else
1011
+				} else
969 1012
 				{
970 1013
 					// Since, they don't belong here. Let's inform the user that they exist..
971
-					if (!empty($topic))
972
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
973
-					else
974
-						$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1014
+					if (!empty($topic)) {
1015
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
1016
+					} else {
1017
+											$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1018
+					}
975 1019
 
976 1020
 					// Compile a list of the files to show the user.
977 1021
 					$file_list = array();
978
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
979
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1022
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1023
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
980 1024
 							$file_list[] = $attachment['name'];
1025
+					}
981 1026
 
982 1027
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
983 1028
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -989,8 +1034,7 @@  discard block
 block discarded – undo
989 1034
 
990 1035
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
991 1036
 						$context['ignore_temp_attachments'] = true;
992
-					}
993
-					else
1037
+					} else
994 1038
 					{
995 1039
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
996 1040
 						$context['ignore_temp_attachments'] = true;
@@ -998,16 +1042,19 @@  discard block
 block discarded – undo
998 1042
 				}
999 1043
 			}
1000 1044
 
1001
-			if (!empty($context['we_are_history']))
1002
-				$post_errors[] = $context['we_are_history'];
1045
+			if (!empty($context['we_are_history'])) {
1046
+							$post_errors[] = $context['we_are_history'];
1047
+			}
1003 1048
 
1004 1049
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1005 1050
 			{
1006
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
1007
-					break;
1051
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1052
+									break;
1053
+				}
1008 1054
 
1009
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1010
-					continue;
1055
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1056
+									continue;
1057
+				}
1011 1058
 
1012 1059
 				if ($attachID == 'initial_error')
1013 1060
 				{
@@ -1022,15 +1069,17 @@  discard block
 block discarded – undo
1022 1069
 				{
1023 1070
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1024 1071
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1025
-					foreach ($attachment['errors'] as $error)
1026
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1072
+					foreach ($attachment['errors'] as $error) {
1073
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1074
+					}
1027 1075
 					$txt['error_attach_errors'] .= '</div>';
1028 1076
 					$post_errors[] = 'attach_errors';
1029 1077
 
1030 1078
 					// Take out the trash.
1031 1079
 					unset($_SESSION['temp_attachments'][$attachID]);
1032
-					if (file_exists($attachment['tmp_name']))
1033
-						unlink($attachment['tmp_name']);
1080
+					if (file_exists($attachment['tmp_name'])) {
1081
+											unlink($attachment['tmp_name']);
1082
+					}
1034 1083
 					continue;
1035 1084
 				}
1036 1085
 
@@ -1043,8 +1092,9 @@  discard block
 block discarded – undo
1043 1092
 
1044 1093
 				$context['attachments']['quantity']++;
1045 1094
 				$context['attachments']['total_size'] += $attachment['size'];
1046
-				if (!isset($context['files_in_session_warning']))
1047
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1095
+				if (!isset($context['files_in_session_warning'])) {
1096
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1097
+				}
1048 1098
 
1049 1099
 				$context['current_attachments'][$attachID] = array(
1050 1100
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1072,8 +1122,9 @@  discard block
 block discarded – undo
1072 1122
 	}
1073 1123
 
1074 1124
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1075
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1076
-		$post_errors[] = 'need_qr_verification';
1125
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1126
+			$post_errors[] = 'need_qr_verification';
1127
+	}
1077 1128
 
1078 1129
 	/*
1079 1130
 	 * There are two error types: serious and minor. Serious errors
@@ -1090,52 +1141,56 @@  discard block
 block discarded – undo
1090 1141
 	{
1091 1142
 		loadLanguage('Errors');
1092 1143
 		$context['error_type'] = 'minor';
1093
-		foreach ($post_errors as $post_error)
1094
-			if (is_array($post_error))
1144
+		foreach ($post_errors as $post_error) {
1145
+					if (is_array($post_error))
1095 1146
 			{
1096 1147
 				$post_error_id = $post_error[0];
1148
+		}
1097 1149
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1098 1150
 
1099 1151
 				// If it's not a minor error flag it as such.
1100
-				if (!in_array($post_error_id, $minor_errors))
1101
-					$context['error_type'] = 'serious';
1102
-			}
1103
-			else
1152
+				if (!in_array($post_error_id, $minor_errors)) {
1153
+									$context['error_type'] = 'serious';
1154
+				}
1155
+			} else
1104 1156
 			{
1105 1157
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1106 1158
 
1107 1159
 				// If it's not a minor error flag it as such.
1108
-				if (!in_array($post_error, $minor_errors))
1109
-					$context['error_type'] = 'serious';
1160
+				if (!in_array($post_error, $minor_errors)) {
1161
+									$context['error_type'] = 'serious';
1162
+				}
1110 1163
 			}
1111 1164
 	}
1112 1165
 
1113 1166
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1114
-	if (isset($_REQUEST['poll']))
1115
-		$context['page_title'] = $txt['new_poll'];
1116
-	elseif ($context['make_event'])
1117
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1118
-	elseif (isset($_REQUEST['msg']))
1119
-		$context['page_title'] = $txt['modify_msg'];
1120
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1121
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1122
-	elseif (empty($topic))
1123
-		$context['page_title'] = $txt['start_new_topic'];
1124
-	else
1125
-		$context['page_title'] = $txt['post_reply'];
1167
+	if (isset($_REQUEST['poll'])) {
1168
+			$context['page_title'] = $txt['new_poll'];
1169
+	} elseif ($context['make_event']) {
1170
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1171
+	} elseif (isset($_REQUEST['msg'])) {
1172
+			$context['page_title'] = $txt['modify_msg'];
1173
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1174
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1175
+	} elseif (empty($topic)) {
1176
+			$context['page_title'] = $txt['start_new_topic'];
1177
+	} else {
1178
+			$context['page_title'] = $txt['post_reply'];
1179
+	}
1126 1180
 
1127 1181
 	// Build the link tree.
1128
-	if (empty($topic))
1129
-		$context['linktree'][] = array(
1182
+	if (empty($topic)) {
1183
+			$context['linktree'][] = array(
1130 1184
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1131 1185
 		);
1132
-	else
1133
-		$context['linktree'][] = array(
1186
+	} else {
1187
+			$context['linktree'][] = array(
1134 1188
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1135 1189
 			'name' => $form_subject,
1136 1190
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1137 1191
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1138 1192
 		);
1193
+	}
1139 1194
 
1140 1195
 	$context['subject'] = addcslashes($form_subject, '"');
1141 1196
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1179,8 +1234,9 @@  discard block
 block discarded – undo
1179 1234
 	// Message icons - customized icons are off?
1180 1235
 	$context['icons'] = getMessageIcons(!empty($board) ? $board : 0);
1181 1236
 
1182
-	if (!empty($context['icons']))
1183
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1237
+	if (!empty($context['icons'])) {
1238
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1239
+	}
1184 1240
 
1185 1241
 	// Are we starting a poll? if set the poll icon as selected if its available
1186 1242
 	if (isset($_REQUEST['poll']))
@@ -1200,8 +1256,9 @@  discard block
 block discarded – undo
1200 1256
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1201 1257
 	{
1202 1258
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1203
-		if ($context['icons'][$i]['selected'])
1204
-			$context['icon_url'] = $context['icons'][$i]['url'];
1259
+		if ($context['icons'][$i]['selected']) {
1260
+					$context['icon_url'] = $context['icons'][$i]['url'];
1261
+		}
1205 1262
 	}
1206 1263
 	if (empty($context['icon_url']))
1207 1264
 	{
@@ -1215,8 +1272,9 @@  discard block
 block discarded – undo
1215 1272
 		));
1216 1273
 	}
1217 1274
 
1218
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1219
-		getTopic();
1275
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1276
+			getTopic();
1277
+	}
1220 1278
 
1221 1279
 	// If the user can post attachments prepare the warning labels.
1222 1280
 	if ($context['can_post_attachment'])
@@ -1227,12 +1285,13 @@  discard block
 block discarded – undo
1227 1285
 		$context['attachment_restrictions'] = array();
1228 1286
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1229 1287
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1230
-		foreach ($attachmentRestrictionTypes as $type)
1231
-			if (!empty($modSettings[$type]))
1288
+		foreach ($attachmentRestrictionTypes as $type) {
1289
+					if (!empty($modSettings[$type]))
1232 1290
 			{
1233 1291
 				// Show the max number of attachments if not 0.
1234 1292
 				if ($type == 'attachmentNumPerPostLimit')
1235 1293
 					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1294
+		}
1236 1295
 			}
1237 1296
 	}
1238 1297
 
@@ -1266,8 +1325,8 @@  discard block
 block discarded – undo
1266 1325
 
1267 1326
 	if (!empty($context['current_attachments']))
1268 1327
 	{
1269
-		foreach ($context['current_attachments'] as $key => $mock)
1270
-			addInlineJavaScript('
1328
+		foreach ($context['current_attachments'] as $key => $mock) {
1329
+					addInlineJavaScript('
1271 1330
 	current_attachments.push({
1272 1331
 		name: '. JavaScriptEscape($mock['name']) . ',
1273 1332
 		size: '. $mock['size'] . ',
@@ -1276,6 +1335,7 @@  discard block
 block discarded – undo
1276 1335
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1277 1336
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1278 1337
 	});');
1338
+		}
1279 1339
 	}
1280 1340
 
1281 1341
 	// File Upload.
@@ -1350,9 +1410,10 @@  discard block
 block discarded – undo
1350 1410
 			$context['posting_fields']['board']['dd'] .= '
1351 1411
 							<optgroup label="' . $category['name'] . '">';
1352 1412
 
1353
-			foreach ($category['boards'] as $brd)
1354
-				$context['posting_fields']['board']['dd'] .= '
1413
+			foreach ($category['boards'] as $brd) {
1414
+							$context['posting_fields']['board']['dd'] .= '
1355 1415
 								<option value="' . $brd['id'] . '"' . ($brd['selected'] ? ' selected' : '') . '>' . ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=&gt;' : '') . ' ' . $brd['name'] . '</option>';
1416
+			}
1356 1417
 
1357 1418
 			$context['posting_fields']['board']['dd'] .= '
1358 1419
 							</optgroup>';
@@ -1383,8 +1444,9 @@  discard block
 block discarded – undo
1383 1444
 
1384 1445
 
1385 1446
 	// Finally, load the template.
1386
-	if (!isset($_REQUEST['xml']))
1387
-		loadTemplate('Post');
1447
+	if (!isset($_REQUEST['xml'])) {
1448
+			loadTemplate('Post');
1449
+	}
1388 1450
 
1389 1451
 	call_integration_hook('integrate_post_end');
1390 1452
 }
@@ -1405,13 +1467,14 @@  discard block
 block discarded – undo
1405 1467
 	// Sneaking off, are we?
1406 1468
 	if (empty($_POST) && empty($topic))
1407 1469
 	{
1408
-		if (empty($_SERVER['CONTENT_LENGTH']))
1409
-			redirectexit('action=post;board=' . $board . '.0');
1410
-		else
1411
-			fatal_lang_error('post_upload_error', false);
1470
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1471
+					redirectexit('action=post;board=' . $board . '.0');
1472
+		} else {
1473
+					fatal_lang_error('post_upload_error', false);
1474
+		}
1475
+	} elseif (empty($_POST) && !empty($topic)) {
1476
+			redirectexit('action=post;topic=' . $topic . '.0');
1412 1477
 	}
1413
-	elseif (empty($_POST) && !empty($topic))
1414
-		redirectexit('action=post;topic=' . $topic . '.0');
1415 1478
 
1416 1479
 	// No need!
1417 1480
 	$context['robot_no_index'] = true;
@@ -1423,8 +1486,9 @@  discard block
 block discarded – undo
1423 1486
 	$post_errors = array();
1424 1487
 
1425 1488
 	// If the session has timed out, let the user re-submit their form.
1426
-	if (checkSession('post', '', false) != '')
1427
-		$post_errors[] = 'session_timeout';
1489
+	if (checkSession('post', '', false) != '') {
1490
+			$post_errors[] = 'session_timeout';
1491
+	}
1428 1492
 
1429 1493
 	// Wrong verification code?
1430 1494
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1434,8 +1498,9 @@  discard block
 block discarded – undo
1434 1498
 			'id' => 'post',
1435 1499
 		);
1436 1500
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1437
-		if (is_array($context['require_verification']))
1438
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1501
+		if (is_array($context['require_verification'])) {
1502
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1503
+		}
1439 1504
 	}
1440 1505
 
1441 1506
 	require_once($sourcedir . '/Subs-Post.php');
@@ -1444,25 +1509,29 @@  discard block
 block discarded – undo
1444 1509
 	call_integration_hook('integrate_post2_start');
1445 1510
 
1446 1511
 	// Drafts enabled and needed?
1447
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1448
-		require_once($sourcedir . '/Drafts.php');
1512
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1513
+			require_once($sourcedir . '/Drafts.php');
1514
+	}
1449 1515
 
1450 1516
 	// First check to see if they are trying to delete any current attachments.
1451 1517
 	if (isset($_POST['attach_del']))
1452 1518
 	{
1453 1519
 		$keep_temp = array();
1454 1520
 		$keep_ids = array();
1455
-		foreach ($_POST['attach_del'] as $dummy)
1456
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1521
+		foreach ($_POST['attach_del'] as $dummy) {
1522
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1457 1523
 				$keep_temp[] = $dummy;
1458
-			else
1459
-				$keep_ids[] = (int) $dummy;
1524
+		}
1525
+			else {
1526
+							$keep_ids[] = (int) $dummy;
1527
+			}
1460 1528
 
1461
-		if (isset($_SESSION['temp_attachments']))
1462
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1529
+		if (isset($_SESSION['temp_attachments'])) {
1530
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1463 1531
 			{
1464 1532
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1465 1533
 					continue;
1534
+		}
1466 1535
 
1467 1536
 				unset($_SESSION['temp_attachments'][$attachID]);
1468 1537
 				unlink($attachment['tmp_name']);
@@ -1494,8 +1563,9 @@  discard block
 block discarded – undo
1494 1563
 	{
1495 1564
 		require_once($sourcedir . '/ManageAttachments.php');
1496 1565
 
1497
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
1498
-			removeAttachments(array('id_attach' => $attachID));
1566
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
1567
+					removeAttachments(array('id_attach' => $attachID));
1568
+		}
1499 1569
 
1500 1570
 		unset($_SESSION['already_attached']);
1501 1571
 
@@ -1518,12 +1588,14 @@  discard block
 block discarded – undo
1518 1588
 		$smcFunc['db_free_result']($request);
1519 1589
 
1520 1590
 		// Though the topic should be there, it might have vanished.
1521
-		if (!is_array($topic_info))
1522
-			fatal_lang_error('topic_doesnt_exist', 404);
1591
+		if (!is_array($topic_info)) {
1592
+					fatal_lang_error('topic_doesnt_exist', 404);
1593
+		}
1523 1594
 
1524 1595
 		// Did this topic suddenly move? Just checking...
1525
-		if ($topic_info['id_board'] != $board)
1526
-			fatal_lang_error('not_a_topic');
1596
+		if ($topic_info['id_board'] != $board) {
1597
+					fatal_lang_error('not_a_topic');
1598
+		}
1527 1599
 
1528 1600
 		// Do the permissions and approval stuff...
1529 1601
 		$becomesApproved = true;
@@ -1546,49 +1618,50 @@  discard block
 block discarded – undo
1546 1618
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1547 1619
 	{
1548 1620
 		// Don't allow a post if it's locked.
1549
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1550
-			fatal_lang_error('topic_locked', false);
1621
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1622
+					fatal_lang_error('topic_locked', false);
1623
+		}
1551 1624
 
1552 1625
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1553
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1554
-			unset($_REQUEST['poll']);
1555
-
1556
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1557
-		{
1558
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1559
-				$becomesApproved = false;
1560
-
1561
-			else
1562
-				isAllowedTo('post_reply_any');
1563
-		}
1564
-		elseif (!allowedTo('post_reply_any'))
1626
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1627
+					unset($_REQUEST['poll']);
1628
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1629
+		{
1630
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1631
+							$becomesApproved = false;
1632
+			} else {
1633
+							isAllowedTo('post_reply_any');
1634
+			}
1635
+		} elseif (!allowedTo('post_reply_any'))
1565 1636
 		{
1566
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1567
-				$becomesApproved = false;
1568
-
1569
-			else
1570
-				isAllowedTo('post_reply_own');
1637
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1638
+							$becomesApproved = false;
1639
+			} else {
1640
+							isAllowedTo('post_reply_own');
1641
+			}
1571 1642
 		}
1572 1643
 
1573 1644
 		if (isset($_POST['lock']))
1574 1645
 		{
1575 1646
 			// Nothing is changed to the lock.
1576
-			if (empty($topic_info['locked']) == empty($_POST['lock']))
1577
-				unset($_POST['lock']);
1647
+			if (empty($topic_info['locked']) == empty($_POST['lock'])) {
1648
+							unset($_POST['lock']);
1649
+			}
1578 1650
 
1579 1651
 			// You're have no permission to lock this topic.
1580
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1581
-				unset($_POST['lock']);
1652
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1653
+							unset($_POST['lock']);
1654
+			}
1582 1655
 
1583 1656
 			// You are allowed to (un)lock your own topic only.
1584 1657
 			elseif (!allowedTo('lock_any'))
1585 1658
 			{
1586 1659
 				// You cannot override a moderator lock.
1587
-				if ($topic_info['locked'] == 1)
1588
-					unset($_POST['lock']);
1589
-
1590
-				else
1591
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1660
+				if ($topic_info['locked'] == 1) {
1661
+									unset($_POST['lock']);
1662
+				} else {
1663
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1664
+				}
1592 1665
 			}
1593 1666
 			// Hail mighty moderator, (un)lock this topic immediately.
1594 1667
 			else
@@ -1596,19 +1669,21 @@  discard block
 block discarded – undo
1596 1669
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1597 1670
 
1598 1671
 				// Did someone (un)lock this while you were posting?
1599
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1600
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1672
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1673
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1674
+				}
1601 1675
 			}
1602 1676
 		}
1603 1677
 
1604 1678
 		// So you wanna (un)sticky this...let's see.
1605
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1606
-			unset($_POST['sticky']);
1607
-		elseif (isset($_POST['sticky']))
1679
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1680
+					unset($_POST['sticky']);
1681
+		} elseif (isset($_POST['sticky']))
1608 1682
 		{
1609 1683
 			// Did someone (un)sticky this while you were posting?
1610
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1611
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1684
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1685
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1686
+			}
1612 1687
 		}
1613 1688
 
1614 1689
 		// If drafts are enabled, then pass this off
@@ -1635,26 +1710,31 @@  discard block
 block discarded – undo
1635 1710
 
1636 1711
 		// Do like, the permissions, for safety and stuff...
1637 1712
 		$becomesApproved = true;
1638
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1639
-			$becomesApproved = false;
1640
-		else
1641
-			isAllowedTo('post_new');
1713
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1714
+					$becomesApproved = false;
1715
+		} else {
1716
+					isAllowedTo('post_new');
1717
+		}
1642 1718
 
1643 1719
 		if (isset($_POST['lock']))
1644 1720
 		{
1645 1721
 			// New topics are by default not locked.
1646
-			if (empty($_POST['lock']))
1647
-				unset($_POST['lock']);
1722
+			if (empty($_POST['lock'])) {
1723
+							unset($_POST['lock']);
1724
+			}
1648 1725
 			// Besides, you need permission.
1649
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1650
-				unset($_POST['lock']);
1726
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1727
+							unset($_POST['lock']);
1728
+			}
1651 1729
 			// A moderator-lock (1) can override a user-lock (2).
1652
-			else
1653
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1730
+			else {
1731
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1732
+			}
1654 1733
 		}
1655 1734
 
1656
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1657
-			unset($_POST['sticky']);
1735
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1736
+					unset($_POST['sticky']);
1737
+		}
1658 1738
 
1659 1739
 		// Saving your new topic as a draft first?
1660 1740
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1679,31 +1759,37 @@  discard block
 block discarded – undo
1679 1759
 				'id_msg' => $_REQUEST['msg'],
1680 1760
 			)
1681 1761
 		);
1682
-		if ($smcFunc['db_num_rows']($request) == 0)
1683
-			fatal_lang_error('cant_find_messages', false);
1762
+		if ($smcFunc['db_num_rows']($request) == 0) {
1763
+					fatal_lang_error('cant_find_messages', false);
1764
+		}
1684 1765
 		$row = $smcFunc['db_fetch_assoc']($request);
1685 1766
 		$smcFunc['db_free_result']($request);
1686 1767
 
1687
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1688
-			fatal_lang_error('topic_locked', false);
1768
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1769
+					fatal_lang_error('topic_locked', false);
1770
+		}
1689 1771
 
1690 1772
 		if (isset($_POST['lock']))
1691 1773
 		{
1692 1774
 			// Nothing changes to the lock status.
1693
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1694
-				unset($_POST['lock']);
1775
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1776
+							unset($_POST['lock']);
1777
+			}
1695 1778
 			// You're simply not allowed to (un)lock this.
1696
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1697
-				unset($_POST['lock']);
1779
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1780
+							unset($_POST['lock']);
1781
+			}
1698 1782
 			// You're only allowed to lock your own topics.
1699 1783
 			elseif (!allowedTo('lock_any'))
1700 1784
 			{
1701 1785
 				// You're not allowed to break a moderator's lock.
1702
-				if ($topic_info['locked'] == 1)
1703
-					unset($_POST['lock']);
1786
+				if ($topic_info['locked'] == 1) {
1787
+									unset($_POST['lock']);
1788
+				}
1704 1789
 				// Lock it with a soft lock or unlock it.
1705
-				else
1706
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1790
+				else {
1791
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1792
+				}
1707 1793
 			}
1708 1794
 			// You must be the moderator.
1709 1795
 			else
@@ -1711,44 +1797,46 @@  discard block
 block discarded – undo
1711 1797
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1712 1798
 
1713 1799
 				// Did someone (un)lock this while you were posting?
1714
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1715
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1800
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1801
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1802
+				}
1716 1803
 			}
1717 1804
 		}
1718 1805
 
1719 1806
 		// Change the sticky status of this topic?
1720
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1721
-			unset($_POST['sticky']);
1722
-		elseif (isset($_POST['sticky']))
1807
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1808
+					unset($_POST['sticky']);
1809
+		} elseif (isset($_POST['sticky']))
1723 1810
 		{
1724 1811
 			// Did someone (un)sticky this while you were posting?
1725
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1726
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1812
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1813
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1814
+			}
1727 1815
 		}
1728 1816
 
1729 1817
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1730 1818
 		{
1731
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1732
-				fatal_lang_error('modify_post_time_passed', false);
1733
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1734
-				isAllowedTo('modify_replies');
1735
-			else
1736
-				isAllowedTo('modify_own');
1737
-		}
1738
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1819
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1820
+							fatal_lang_error('modify_post_time_passed', false);
1821
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1822
+							isAllowedTo('modify_replies');
1823
+			} else {
1824
+							isAllowedTo('modify_own');
1825
+			}
1826
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1739 1827
 		{
1740 1828
 			isAllowedTo('modify_replies');
1741 1829
 
1742 1830
 			// If you're modifying a reply, I say it better be logged...
1743 1831
 			$moderationAction = true;
1744
-		}
1745
-		else
1832
+		} else
1746 1833
 		{
1747 1834
 			isAllowedTo('modify_any');
1748 1835
 
1749 1836
 			// Log it, assuming you're not modifying your own post.
1750
-			if ($row['id_member'] != $user_info['id'])
1751
-				$moderationAction = true;
1837
+			if ($row['id_member'] != $user_info['id']) {
1838
+							$moderationAction = true;
1839
+			}
1752 1840
 		}
1753 1841
 
1754 1842
 		// If drafts are enabled, then lets send this off to save
@@ -1775,8 +1863,9 @@  discard block
 block discarded – undo
1775 1863
 		// Update search api
1776 1864
 		require_once($sourcedir . '/Search.php');
1777 1865
 		$searchAPI = findSearchAPI();
1778
-		if ($searchAPI->supportsMethod('postRemoved'))
1779
-			$searchAPI->postRemoved($_REQUEST['msg']);
1866
+		if ($searchAPI->supportsMethod('postRemoved')) {
1867
+					$searchAPI->postRemoved($_REQUEST['msg']);
1868
+		}
1780 1869
 
1781 1870
 	}
1782 1871
 
@@ -1794,20 +1883,24 @@  discard block
 block discarded – undo
1794 1883
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1795 1884
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1796 1885
 
1797
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1798
-			$post_errors[] = 'no_name';
1799
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1800
-			$post_errors[] = 'long_name';
1886
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1887
+					$post_errors[] = 'no_name';
1888
+		}
1889
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1890
+					$post_errors[] = 'long_name';
1891
+		}
1801 1892
 
1802 1893
 		if (empty($modSettings['guest_post_no_email']))
1803 1894
 		{
1804 1895
 			// Only check if they changed it!
1805 1896
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1806 1897
 			{
1807
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1808
-					$post_errors[] = 'no_email';
1809
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1810
-					$post_errors[] = 'bad_email';
1898
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1899
+									$post_errors[] = 'no_email';
1900
+				}
1901
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1902
+									$post_errors[] = 'bad_email';
1903
+				}
1811 1904
 			}
1812 1905
 
1813 1906
 			// Now make sure this email address is not banned from posting.
@@ -1823,76 +1916,90 @@  discard block
 block discarded – undo
1823 1916
 	}
1824 1917
 
1825 1918
 	// Coming from the quickReply?
1826
-	if (isset($_POST['quickReply']))
1827
-		$_POST['message'] = $_POST['quickReply'];
1919
+	if (isset($_POST['quickReply'])) {
1920
+			$_POST['message'] = $_POST['quickReply'];
1921
+	}
1828 1922
 
1829 1923
 	// Check the subject and message.
1830
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1831
-		$post_errors[] = 'no_subject';
1832
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1833
-		$post_errors[] = 'no_message';
1834
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1835
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1836
-	else
1924
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1925
+			$post_errors[] = 'no_subject';
1926
+	}
1927
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1928
+			$post_errors[] = 'no_message';
1929
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1930
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1931
+	} else
1837 1932
 	{
1838 1933
 		// Prepare the message a bit for some additional testing.
1839 1934
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1840 1935
 
1841 1936
 		// Preparse code. (Zef)
1842
-		if ($user_info['is_guest'])
1843
-			$user_info['name'] = $_POST['guestname'];
1937
+		if ($user_info['is_guest']) {
1938
+					$user_info['name'] = $_POST['guestname'];
1939
+		}
1844 1940
 		preparsecode($_POST['message']);
1845 1941
 
1846 1942
 		// Let's see if there's still some content left without the tags.
1847
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1848
-			$post_errors[] = 'no_message';
1943
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1944
+					$post_errors[] = 'no_message';
1945
+		}
1849 1946
 
1850 1947
 	}
1851
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1852
-		$post_errors[] = 'no_event';
1948
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1949
+			$post_errors[] = 'no_event';
1950
+	}
1853 1951
 	// You are not!
1854
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1855
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1952
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1953
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1954
+	}
1856 1955
 
1857 1956
 	// Validate the poll...
1858 1957
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1859 1958
 	{
1860
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1861
-			fatal_lang_error('no_access', false);
1959
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1960
+					fatal_lang_error('no_access', false);
1961
+		}
1862 1962
 
1863 1963
 		// This is a new topic... so it's a new poll.
1864
-		if (empty($topic))
1865
-			isAllowedTo('poll_post');
1964
+		if (empty($topic)) {
1965
+					isAllowedTo('poll_post');
1966
+		}
1866 1967
 		// Can you add to your own topics?
1867
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1868
-			isAllowedTo('poll_add_own');
1968
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1969
+					isAllowedTo('poll_add_own');
1970
+		}
1869 1971
 		// Can you add polls to any topic, then?
1870
-		else
1871
-			isAllowedTo('poll_add_any');
1972
+		else {
1973
+					isAllowedTo('poll_add_any');
1974
+		}
1872 1975
 
1873
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1874
-			$post_errors[] = 'no_question';
1976
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1977
+					$post_errors[] = 'no_question';
1978
+		}
1875 1979
 
1876 1980
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1877 1981
 
1878 1982
 		// Get rid of empty ones.
1879
-		foreach ($_POST['options'] as $k => $option)
1880
-			if ($option == '')
1983
+		foreach ($_POST['options'] as $k => $option) {
1984
+					if ($option == '')
1881 1985
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1986
+		}
1882 1987
 
1883 1988
 		// What are you going to vote between with one choice?!?
1884
-		if (count($_POST['options']) < 2)
1885
-			$post_errors[] = 'poll_few';
1886
-		elseif (count($_POST['options']) > 256)
1887
-			$post_errors[] = 'poll_many';
1989
+		if (count($_POST['options']) < 2) {
1990
+					$post_errors[] = 'poll_few';
1991
+		} elseif (count($_POST['options']) > 256) {
1992
+					$post_errors[] = 'poll_many';
1993
+		}
1888 1994
 	}
1889 1995
 
1890 1996
 	if ($posterIsGuest)
1891 1997
 	{
1892 1998
 		// If user is a guest, make sure the chosen name isn't taken.
1893 1999
 		require_once($sourcedir . '/Subs-Members.php');
1894
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1895
-			$post_errors[] = 'bad_name';
2000
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
2001
+					$post_errors[] = 'bad_name';
2002
+		}
1896 2003
 	}
1897 2004
 	// If the user isn't a guest, get his or her name and email.
1898 2005
 	elseif (!isset($_REQUEST['msg']))
@@ -1923,8 +2030,9 @@  discard block
 block discarded – undo
1923 2030
 	}
1924 2031
 
1925 2032
 	// Make sure the user isn't spamming the board.
1926
-	if (!isset($_REQUEST['msg']))
1927
-		spamProtection('post');
2033
+	if (!isset($_REQUEST['msg'])) {
2034
+			spamProtection('post');
2035
+	}
1928 2036
 
1929 2037
 	// At about this point, we're posting and that's that.
1930 2038
 	ignore_user_abort(true);
@@ -1937,32 +2045,36 @@  discard block
 block discarded – undo
1937 2045
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1938 2046
 
1939 2047
 	// At this point, we want to make sure the subject isn't too long.
1940
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1941
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2048
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
2049
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2050
+	}
1942 2051
 
1943 2052
 	// Same with the "why did you edit this" text.
1944
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1945
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2053
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2054
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2055
+	}
1946 2056
 
1947 2057
 	// Make the poll...
1948 2058
 	if (isset($_REQUEST['poll']))
1949 2059
 	{
1950 2060
 		// Make sure that the user has not entered a ridiculous number of options..
1951
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1952
-			$_POST['poll_max_votes'] = 1;
1953
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1954
-			$_POST['poll_max_votes'] = count($_POST['options']);
1955
-		else
1956
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2061
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
2062
+					$_POST['poll_max_votes'] = 1;
2063
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
2064
+					$_POST['poll_max_votes'] = count($_POST['options']);
2065
+		} else {
2066
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2067
+		}
1957 2068
 
1958 2069
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1959 2070
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1960 2071
 
1961 2072
 		// Just set it to zero if it's not there..
1962
-		if (!isset($_POST['poll_hide']))
1963
-			$_POST['poll_hide'] = 0;
1964
-		else
1965
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2073
+		if (!isset($_POST['poll_hide'])) {
2074
+					$_POST['poll_hide'] = 0;
2075
+		} else {
2076
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2077
+		}
1966 2078
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1967 2079
 
1968 2080
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1971,16 +2083,19 @@  discard block
 block discarded – undo
1971 2083
 		{
1972 2084
 			require_once($sourcedir . '/Subs-Members.php');
1973 2085
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1974
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1975
-				$_POST['poll_guest_vote'] = 0;
2086
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2087
+							$_POST['poll_guest_vote'] = 0;
2088
+			}
1976 2089
 		}
1977 2090
 
1978 2091
 		// If the user tries to set the poll too far in advance, don't let them.
1979
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1980
-			fatal_lang_error('poll_range_error', false);
2092
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2093
+					fatal_lang_error('poll_range_error', false);
2094
+		}
1981 2095
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1982
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1983
-			$_POST['poll_hide'] = 1;
2096
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2097
+					$_POST['poll_hide'] = 1;
2098
+		}
1984 2099
 
1985 2100
 		// Clean up the question and answers.
1986 2101
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1994,13 +2109,15 @@  discard block
 block discarded – undo
1994 2109
 	{
1995 2110
 		$attachIDs = array();
1996 2111
 		$attach_errors = array();
1997
-		if (!empty($context['we_are_history']))
1998
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2112
+		if (!empty($context['we_are_history'])) {
2113
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2114
+		}
1999 2115
 
2000 2116
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
2001 2117
 		{
2002
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
2003
-				continue;
2118
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2119
+							continue;
2120
+			}
2004 2121
 
2005 2122
 			// If there was an initial error just show that message.
2006 2123
 			if ($attachID == 'initial_error')
@@ -2029,12 +2146,13 @@  discard block
 block discarded – undo
2029 2146
 				if (createAttachment($attachmentOptions))
2030 2147
 				{
2031 2148
 					$attachIDs[] = $attachmentOptions['id'];
2032
-					if (!empty($attachmentOptions['thumb']))
2033
-						$attachIDs[] = $attachmentOptions['thumb'];
2149
+					if (!empty($attachmentOptions['thumb'])) {
2150
+											$attachIDs[] = $attachmentOptions['thumb'];
2151
+					}
2034 2152
 				}
2153
+			} else {
2154
+							$attach_errors[] = '<dt>&nbsp;</dt>';
2035 2155
 			}
2036
-			else
2037
-				$attach_errors[] = '<dt>&nbsp;</dt>';
2038 2156
 
2039 2157
 			if (!empty($attachmentOptions['errors']))
2040 2158
 			{
@@ -2046,14 +2164,16 @@  discard block
 block discarded – undo
2046 2164
 					if (!is_array($error))
2047 2165
 					{
2048 2166
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
2049
-						if (in_array($error, $log_these))
2050
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2167
+						if (in_array($error, $log_these)) {
2168
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2169
+						}
2170
+					} else {
2171
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2051 2172
 					}
2052
-					else
2053
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2054 2173
 				}
2055
-				if (file_exists($attachment['tmp_name']))
2056
-					unlink($attachment['tmp_name']);
2174
+				if (file_exists($attachment['tmp_name'])) {
2175
+									unlink($attachment['tmp_name']);
2176
+				}
2057 2177
 			}
2058 2178
 		}
2059 2179
 		unset($_SESSION['temp_attachments']);
@@ -2094,24 +2214,24 @@  discard block
 block discarded – undo
2094 2214
 		);
2095 2215
 
2096 2216
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2217
+	} else {
2218
+			$id_poll = 0;
2097 2219
 	}
2098
-	else
2099
-		$id_poll = 0;
2100 2220
 
2101 2221
 	// Creating a new topic?
2102 2222
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2103 2223
 
2104 2224
 	// Check the icon.
2105
-	if (!isset($_POST['icon']))
2106
-		$_POST['icon'] = 'xx';
2107
-
2108
-	else
2225
+	if (!isset($_POST['icon'])) {
2226
+			$_POST['icon'] = 'xx';
2227
+	} else
2109 2228
 	{
2110 2229
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2111 2230
 
2112 2231
 		// Need to figure it out if this is a valid icon name.
2113
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2114
-			$_POST['icon'] = 'xx';
2232
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2233
+					$_POST['icon'] = 'xx';
2234
+		}
2115 2235
 	}
2116 2236
 
2117 2237
 	// Collect all parameters for the creation or modification of a post.
@@ -2152,8 +2272,9 @@  discard block
 block discarded – undo
2152 2272
 		}
2153 2273
 
2154 2274
 		// This will save some time...
2155
-		if (empty($approve_has_changed))
2156
-			unset($msgOptions['approved']);
2275
+		if (empty($approve_has_changed)) {
2276
+					unset($msgOptions['approved']);
2277
+		}
2157 2278
 
2158 2279
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2159 2280
 	}
@@ -2162,8 +2283,9 @@  discard block
 block discarded – undo
2162 2283
 	{
2163 2284
 		createPost($msgOptions, $topicOptions, $posterOptions);
2164 2285
 
2165
-		if (isset($topicOptions['id']))
2166
-			$topic = $topicOptions['id'];
2286
+		if (isset($topicOptions['id'])) {
2287
+					$topic = $topicOptions['id'];
2288
+		}
2167 2289
 	}
2168 2290
 
2169 2291
 	// Are there attachments already uploaded and waiting to be assigned?
@@ -2175,8 +2297,9 @@  discard block
 block discarded – undo
2175 2297
 	}
2176 2298
 
2177 2299
 	// If we had a draft for this, its time to remove it since it was just posted
2178
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2179
-		DeleteDraft($_POST['id_draft']);
2300
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2301
+			DeleteDraft($_POST['id_draft']);
2302
+	}
2180 2303
 
2181 2304
 	// Editing or posting an event?
2182 2305
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2195,8 +2318,7 @@  discard block
 block discarded – undo
2195 2318
 			'member' => $user_info['id'],
2196 2319
 		);
2197 2320
 		insertEvent($eventOptions);
2198
-	}
2199
-	elseif (isset($_POST['calendar']))
2321
+	} elseif (isset($_POST['calendar']))
2200 2322
 	{
2201 2323
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2202 2324
 
@@ -2224,14 +2346,15 @@  discard block
 block discarded – undo
2224 2346
 		}
2225 2347
 
2226 2348
 		// Delete it?
2227
-		if (isset($_REQUEST['deleteevent']))
2228
-			$smcFunc['db_query']('', '
2349
+		if (isset($_REQUEST['deleteevent'])) {
2350
+					$smcFunc['db_query']('', '
2229 2351
 				DELETE FROM {db_prefix}calendar
2230 2352
 				WHERE id_event = {int:id_event}',
2231 2353
 				array(
2232 2354
 					'id_event' => $_REQUEST['eventid'],
2233 2355
 				)
2234 2356
 			);
2357
+		}
2235 2358
 		// ... or just update it?
2236 2359
 		else
2237 2360
 		{
@@ -2273,9 +2396,8 @@  discard block
 block discarded – undo
2273 2396
 			array($user_info['id'], $topic, 0),
2274 2397
 			array('id_member', 'id_topic', 'id_board')
2275 2398
 		);
2276
-	}
2277
-	elseif (!$newTopic)
2278
-		$smcFunc['db_query']('', '
2399
+	} elseif (!$newTopic) {
2400
+			$smcFunc['db_query']('', '
2279 2401
 			DELETE FROM {db_prefix}log_notify
2280 2402
 			WHERE id_member = {int:current_member}
2281 2403
 				AND id_topic = {int:current_topic}',
@@ -2284,16 +2406,20 @@  discard block
 block discarded – undo
2284 2406
 				'current_topic' => $topic,
2285 2407
 			)
2286 2408
 		);
2409
+	}
2287 2410
 
2288 2411
 	// Log an act of moderation - modifying.
2289
-	if (!empty($moderationAction))
2290
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2412
+	if (!empty($moderationAction)) {
2413
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2414
+	}
2291 2415
 
2292
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2293
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2416
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2417
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2418
+	}
2294 2419
 
2295
-	if (isset($_POST['sticky']))
2296
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2420
+	if (isset($_POST['sticky'])) {
2421
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2422
+	}
2297 2423
 
2298 2424
 	// Returning to the topic?
2299 2425
 	if (!empty($_REQUEST['goback']))
@@ -2312,26 +2438,31 @@  discard block
 block discarded – undo
2312 2438
 		);
2313 2439
 	}
2314 2440
 
2315
-	if ($board_info['num_topics'] == 0)
2316
-		cache_put_data('board-' . $board, null, 120);
2441
+	if ($board_info['num_topics'] == 0) {
2442
+			cache_put_data('board-' . $board, null, 120);
2443
+	}
2317 2444
 
2318 2445
 	call_integration_hook('integrate_post2_end');
2319 2446
 
2320
-	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic'))
2321
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2447
+	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) {
2448
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2449
+	}
2322 2450
 
2323
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2324
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2451
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2452
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2453
+	}
2325 2454
 
2326 2455
 	// Return to post if the mod is on.
2327
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2328
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2329
-	elseif (!empty($_REQUEST['goback']))
2330
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2456
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2457
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2458
+	} elseif (!empty($_REQUEST['goback'])) {
2459
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2460
+	}
2331 2461
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2332
-	else
2333
-		redirectexit('board=' . $board . '.0');
2334
-}
2462
+	else {
2463
+			redirectexit('board=' . $board . '.0');
2464
+	}
2465
+	}
2335 2466
 
2336 2467
 /**
2337 2468
  * Handle the announce topic function (action=announce).
@@ -2349,8 +2480,9 @@  discard block
 block discarded – undo
2349 2480
 
2350 2481
 	validateSession();
2351 2482
 
2352
-	if (empty($topic))
2353
-		fatal_lang_error('topic_gone', false);
2483
+	if (empty($topic)) {
2484
+			fatal_lang_error('topic_gone', false);
2485
+	}
2354 2486
 
2355 2487
 	loadLanguage('Post');
2356 2488
 	loadTemplate('Post');
@@ -2377,8 +2509,9 @@  discard block
 block discarded – undo
2377 2509
 	global $txt, $context, $topic, $board_info, $smcFunc;
2378 2510
 
2379 2511
 	$groups = array_merge($board_info['groups'], array(1));
2380
-	foreach ($groups as $id => $group)
2381
-		$groups[$id] = (int) $group;
2512
+	foreach ($groups as $id => $group) {
2513
+			$groups[$id] = (int) $group;
2514
+	}
2382 2515
 
2383 2516
 	$context['groups'] = array();
2384 2517
 	if (in_array(0, $groups))
@@ -2421,8 +2554,9 @@  discard block
 block discarded – undo
2421 2554
 			'group_list' => $groups,
2422 2555
 		)
2423 2556
 	);
2424
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2425
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2557
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2558
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2559
+	}
2426 2560
 	$smcFunc['db_free_result']($request);
2427 2561
 
2428 2562
 	// Get the subject of the topic we're about to announce.
@@ -2464,16 +2598,19 @@  discard block
 block discarded – undo
2464 2598
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2465 2599
 	$groups = array_merge($board_info['groups'], array(1));
2466 2600
 
2467
-	if (isset($_POST['membergroups']))
2468
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2601
+	if (isset($_POST['membergroups'])) {
2602
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2603
+	}
2469 2604
 
2470 2605
 	// Check whether at least one membergroup was selected.
2471
-	if (empty($_POST['who']))
2472
-		fatal_lang_error('no_membergroup_selected');
2606
+	if (empty($_POST['who'])) {
2607
+			fatal_lang_error('no_membergroup_selected');
2608
+	}
2473 2609
 
2474 2610
 	// Make sure all membergroups are integers and can access the board of the announcement.
2475
-	foreach ($_POST['who'] as $id => $mg)
2476
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2611
+	foreach ($_POST['who'] as $id => $mg) {
2612
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2613
+	}
2477 2614
 
2478 2615
 	// Get the topic subject and censor it.
2479 2616
 	$request = $smcFunc['db_query']('', '
@@ -2519,12 +2656,13 @@  discard block
 block discarded – undo
2519 2656
 	if ($smcFunc['db_num_rows']($request) == 0)
2520 2657
 	{
2521 2658
 		logAction('announce_topic', array('topic' => $topic), 'user');
2522
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2523
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2524
-		elseif (!empty($_REQUEST['goback']))
2525
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2526
-		else
2527
-			redirectexit('board=' . $board . '.0');
2659
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2660
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2661
+		} elseif (!empty($_REQUEST['goback'])) {
2662
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2663
+		} else {
2664
+					redirectexit('board=' . $board . '.0');
2665
+		}
2528 2666
 	}
2529 2667
 
2530 2668
 	$announcements = array();
@@ -2543,8 +2681,9 @@  discard block
 block discarded – undo
2543 2681
 	foreach ($rows as $row)
2544 2682
 	{
2545 2683
 		// Force them to have it?
2546
-		if (empty($prefs[$row['id_member']]['announcements']))
2547
-			continue;
2684
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2685
+					continue;
2686
+		}
2548 2687
 
2549 2688
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2550 2689
 
@@ -2572,8 +2711,9 @@  discard block
 block discarded – undo
2572 2711
 	}
2573 2712
 
2574 2713
 	// For each language send a different mail - low priority...
2575
-	foreach ($announcements as $lang => $mail)
2576
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2714
+	foreach ($announcements as $lang => $mail) {
2715
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2716
+	}
2577 2717
 
2578 2718
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2579 2719
 
@@ -2583,9 +2723,10 @@  discard block
 block discarded – undo
2583 2723
 	$context['sub_template'] = 'announcement_send';
2584 2724
 
2585 2725
 	// Go back to the correct language for the user ;).
2586
-	if (!empty($modSettings['userLanguage']))
2587
-		loadLanguage('Post');
2588
-}
2726
+	if (!empty($modSettings['userLanguage'])) {
2727
+			loadLanguage('Post');
2728
+	}
2729
+	}
2589 2730
 
2590 2731
 /**
2591 2732
  * Get the topic for display purposes.
@@ -2598,12 +2739,13 @@  discard block
 block discarded – undo
2598 2739
 {
2599 2740
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2600 2741
 
2601
-	if (isset($_REQUEST['xml']))
2602
-		$limit = '
2742
+	if (isset($_REQUEST['xml'])) {
2743
+			$limit = '
2603 2744
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2604
-	else
2605
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2745
+	} else {
2746
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2606 2747
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2748
+	}
2607 2749
 
2608 2750
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2609 2751
 	$request = $smcFunc['db_query']('', '
@@ -2641,8 +2783,9 @@  discard block
 block discarded – undo
2641 2783
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2642 2784
 		);
2643 2785
 
2644
-		if (!empty($context['new_replies']))
2645
-			$context['new_replies']--;
2786
+		if (!empty($context['new_replies'])) {
2787
+					$context['new_replies']--;
2788
+		}
2646 2789
 	}
2647 2790
 	$smcFunc['db_free_result']($request);
2648 2791
 }
@@ -2659,8 +2802,9 @@  discard block
 block discarded – undo
2659 2802
 	global $sourcedir, $smcFunc;
2660 2803
 
2661 2804
 	loadLanguage('Post');
2662
-	if (!isset($_REQUEST['xml']))
2663
-		loadTemplate('Post');
2805
+	if (!isset($_REQUEST['xml'])) {
2806
+			loadTemplate('Post');
2807
+	}
2664 2808
 
2665 2809
 	include_once($sourcedir . '/Subs-Post.php');
2666 2810
 
@@ -2691,8 +2835,9 @@  discard block
 block discarded – undo
2691 2835
 	$smcFunc['db_free_result']($request);
2692 2836
 
2693 2837
 	$context['sub_template'] = 'quotefast';
2694
-	if (!empty($row))
2695
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2838
+	if (!empty($row)) {
2839
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2840
+	}
2696 2841
 
2697 2842
 	if (!empty($can_view_post))
2698 2843
 	{
@@ -2725,8 +2870,9 @@  discard block
 block discarded – undo
2725 2870
 		}
2726 2871
 
2727 2872
 		// Remove any nested quotes.
2728
-		if (!empty($modSettings['removeNestedQuotes']))
2729
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2873
+		if (!empty($modSettings['removeNestedQuotes'])) {
2874
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2875
+		}
2730 2876
 
2731 2877
 		$lb = "\n";
2732 2878
 
@@ -2752,14 +2898,14 @@  discard block
 block discarded – undo
2752 2898
 				'time' => '',
2753 2899
 			),
2754 2900
 		);
2755
-	}
2756
-	else
2757
-		$context['quote'] = array(
2901
+	} else {
2902
+			$context['quote'] = array(
2758 2903
 			'xml' => '',
2759 2904
 			'mozilla' => '',
2760 2905
 			'text' => '',
2761 2906
 		);
2762
-}
2907
+	}
2908
+	}
2763 2909
 
2764 2910
 /**
2765 2911
  * Used to edit the body or subject of a message inline
@@ -2771,8 +2917,9 @@  discard block
 block discarded – undo
2771 2917
 	global $user_info, $context, $smcFunc, $language, $board_info;
2772 2918
 
2773 2919
 	// We have to have a topic!
2774
-	if (empty($topic))
2775
-		obExit(false);
2920
+	if (empty($topic)) {
2921
+			obExit(false);
2922
+	}
2776 2923
 
2777 2924
 	checkSession('get');
2778 2925
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2798,31 +2945,35 @@  discard block
 block discarded – undo
2798 2945
 			'guest_id' => 0,
2799 2946
 		)
2800 2947
 	);
2801
-	if ($smcFunc['db_num_rows']($request) == 0)
2802
-		fatal_lang_error('no_board', false);
2948
+	if ($smcFunc['db_num_rows']($request) == 0) {
2949
+			fatal_lang_error('no_board', false);
2950
+	}
2803 2951
 	$row = $smcFunc['db_fetch_assoc']($request);
2804 2952
 	$smcFunc['db_free_result']($request);
2805 2953
 
2806 2954
 	// Change either body or subject requires permissions to modify messages.
2807 2955
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2808 2956
 	{
2809
-		if (!empty($row['locked']))
2810
-			isAllowedTo('moderate_board');
2957
+		if (!empty($row['locked'])) {
2958
+					isAllowedTo('moderate_board');
2959
+		}
2811 2960
 
2812 2961
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2813 2962
 		{
2814
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2815
-				fatal_lang_error('modify_post_time_passed', false);
2816
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2817
-				isAllowedTo('modify_replies');
2818
-			else
2819
-				isAllowedTo('modify_own');
2963
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2964
+							fatal_lang_error('modify_post_time_passed', false);
2965
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2966
+							isAllowedTo('modify_replies');
2967
+			} else {
2968
+							isAllowedTo('modify_own');
2969
+			}
2820 2970
 		}
2821 2971
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2822
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2823
-			isAllowedTo('modify_replies');
2824
-		else
2825
-			isAllowedTo('modify_any');
2972
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2973
+					isAllowedTo('modify_replies');
2974
+		} else {
2975
+					isAllowedTo('modify_any');
2976
+		}
2826 2977
 
2827 2978
 		// Only log this action if it wasn't your message.
2828 2979
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2834,10 +2985,10 @@  discard block
 block discarded – undo
2834 2985
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2835 2986
 
2836 2987
 		// Maximum number of characters.
2837
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2838
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2839
-	}
2840
-	elseif (isset($_POST['subject']))
2988
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2989
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2990
+		}
2991
+	} elseif (isset($_POST['subject']))
2841 2992
 	{
2842 2993
 		$post_errors[] = 'no_subject';
2843 2994
 		unset($_POST['subject']);
@@ -2849,13 +3000,11 @@  discard block
 block discarded – undo
2849 3000
 		{
2850 3001
 			$post_errors[] = 'no_message';
2851 3002
 			unset($_POST['message']);
2852
-		}
2853
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
3003
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2854 3004
 		{
2855 3005
 			$post_errors[] = 'long_message';
2856 3006
 			unset($_POST['message']);
2857
-		}
2858
-		else
3007
+		} else
2859 3008
 		{
2860 3009
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2861 3010
 
@@ -2871,31 +3020,34 @@  discard block
 block discarded – undo
2871 3020
 
2872 3021
 	if (isset($_POST['lock']))
2873 3022
 	{
2874
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2875
-			unset($_POST['lock']);
2876
-		elseif (!allowedTo('lock_any'))
3023
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
3024
+					unset($_POST['lock']);
3025
+		} elseif (!allowedTo('lock_any'))
2877 3026
 		{
2878
-			if ($row['locked'] == 1)
2879
-				unset($_POST['lock']);
2880
-			else
2881
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3027
+			if ($row['locked'] == 1) {
3028
+							unset($_POST['lock']);
3029
+			} else {
3030
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3031
+			}
3032
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
3033
+					unset($_POST['lock']);
3034
+		} else {
3035
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2882 3036
 		}
2883
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2884
-			unset($_POST['lock']);
2885
-		else
2886
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2887 3037
 	}
2888 3038
 
2889
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2890
-		unset($_POST['sticky']);
3039
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
3040
+			unset($_POST['sticky']);
3041
+	}
2891 3042
 
2892 3043
 	if (isset($_POST['modify_reason']))
2893 3044
 	{
2894 3045
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2895 3046
 
2896 3047
 		// Maximum number of characters.
2897
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2898
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3048
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
3049
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3050
+		}
2899 3051
 	}
2900 3052
 
2901 3053
 	if (empty($post_errors))
@@ -2932,8 +3084,9 @@  discard block
 block discarded – undo
2932 3084
 			}
2933 3085
 		}
2934 3086
 		// If nothing was changed there's no need to add an entry to the moderation log.
2935
-		else
2936
-			$moderationAction = false;
3087
+		else {
3088
+					$moderationAction = false;
3089
+		}
2937 3090
 
2938 3091
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2939 3092
 
@@ -2951,9 +3104,9 @@  discard block
 block discarded – undo
2951 3104
 			// Get the proper (default language) response prefix first.
2952 3105
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2953 3106
 			{
2954
-				if ($language === $user_info['language'])
2955
-					$context['response_prefix'] = $txt['response_prefix'];
2956
-				else
3107
+				if ($language === $user_info['language']) {
3108
+									$context['response_prefix'] = $txt['response_prefix'];
3109
+				} else
2957 3110
 				{
2958 3111
 					loadLanguage('index', $language, false);
2959 3112
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2975,8 +3128,9 @@  discard block
 block discarded – undo
2975 3128
 			);
2976 3129
 		}
2977 3130
 
2978
-		if (!empty($moderationAction))
2979
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3131
+		if (!empty($moderationAction)) {
3132
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3133
+		}
2980 3134
 	}
2981 3135
 
2982 3136
 	if (isset($_REQUEST['xml']))
@@ -3017,8 +3171,7 @@  discard block
 block discarded – undo
3017 3171
 			);
3018 3172
 
3019 3173
 			censorText($context['message']['subject']);
3020
-		}
3021
-		else
3174
+		} else
3022 3175
 		{
3023 3176
 			$context['message'] = array(
3024 3177
 				'id' => $row['id_msg'],
@@ -3030,15 +3183,16 @@  discard block
 block discarded – undo
3030 3183
 			loadLanguage('Errors');
3031 3184
 			foreach ($post_errors as $post_error)
3032 3185
 			{
3033
-				if ($post_error == 'long_message')
3034
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3035
-				else
3036
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3186
+				if ($post_error == 'long_message') {
3187
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3188
+				} else {
3189
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3190
+				}
3037 3191
 			}
3038 3192
 		}
3193
+	} else {
3194
+			obExit(false);
3195
+	}
3039 3196
 	}
3040
-	else
3041
-		obExit(false);
3042
-}
3043 3197
 
3044 3198
 ?>
3045 3199
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 1 patch
Braces   +48 added lines, -33 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 	<strong>
29 29
 		', $context['error_title'], '
30 30
 	</strong><br>
31 31
 	<div ', $context['error_code'], 'class="padding">
32 32
 		', $context['error_message'], '
33 33
 	</div>';
34
-	else
34
+	} else
35 35
 	{
36 36
 		echo '
37 37
 	<div id="fatal_error">
@@ -85,21 +85,23 @@  discard block
 block discarded – undo
85 85
 
86 86
 	$error_types = array();
87 87
 
88
-	foreach ($context['error_types'] as $type => $details)
89
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
88
+	foreach ($context['error_types'] as $type => $details) {
89
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
90
+	}
90 91
 
91 92
 	echo '
92 93
 						', implode(' | ', $error_types), '
93 94
 					</td>
94 95
 				</tr>';
95 96
 
96
-	if ($context['has_filter'])
97
-		echo '
97
+	if ($context['has_filter']) {
98
+			echo '
98 99
 				<tr>
99 100
 					<td colspan="3" class="windowbg">
100 101
 						<strong>', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], ' [<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
101 102
 					</td>
102 103
 				</tr>';
104
+	}
103 105
 
104 106
 	echo '
105 107
 				<tr>
@@ -110,11 +112,12 @@  discard block
 block discarded – undo
110 112
 				</tr>';
111 113
 
112 114
 	// No errors, then show a message
113
-	if (count($context['errors']) == 0)
114
-		echo '
115
+	if (count($context['errors']) == 0) {
116
+			echo '
115 117
 				<tr class="windowbg">
116 118
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
117 119
 				</tr>';
120
+	}
118 121
 
119 122
 	// We have some errors, must be some mods installed :P
120 123
 	foreach ($context['errors'] as $error)
@@ -128,16 +131,18 @@  discard block
 block discarded – undo
128 131
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
129 132
 							', $error['time'], '<br>';
130 133
 
131
-		if (!empty($error['member']['ip']))
132
-			echo '
134
+		if (!empty($error['member']['ip'])) {
135
+					echo '
133 136
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a>
134 137
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>';
138
+		}
135 139
 
136
-		if ($error['member']['session'] != '')
137
-			echo '
140
+		if ($error['member']['session'] != '') {
141
+					echo '
138 142
 							<br>
139 143
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 						</div>
@@ -152,12 +157,13 @@  discard block
 block discarded – undo
152 157
 							<a href="', $error['url']['html'], '">', $error['url']['html'], '</a>
153 158
 ';
154 159
 
155
-		if (!empty($error['file']))
156
-			echo '
160
+		if (!empty($error['file'])) {
161
+					echo '
157 162
 							<div>
158 163
 								<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '">'
159 164
 				. '					<span class="generic_icons filter"></span></a> ', $error['file']['link'], ' (', $txt['line'], ' ', $error['file']['line'], ')
160 165
 							</div>';
166
+		}
161 167
 
162 168
 		echo '
163 169
 						</div>
@@ -186,9 +192,10 @@  discard block
 block discarded – undo
186 192
 				</div>
187 193
 			</div>';
188 194
 
189
-	if ($context['sort_direction'] == 'down')
190
-		echo '
195
+	if ($context['sort_direction'] == 'down') {
196
+			echo '
191 197
 			<input type="hidden" name="desc" value="1">';
198
+	}
192 199
 
193 200
 	echo '
194 201
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -249,9 +256,10 @@  discard block
 block discarded – undo
249 256
 					$context['error_message'], '
250 257
 				</div>';
251 258
 	
252
-	if (!empty($context['back_link'])) 
253
-		echo '
259
+	if (!empty($context['back_link'])) {
260
+			echo '
254 261
 				<a class="button" href="', $scripturl, $context['back_link'], '">', $txt['back'], '</a>';
262
+	}
255 263
 
256 264
 	echo '
257 265
 				<span style="float: right; margin:.5em;"></span>
@@ -288,25 +296,30 @@  discard block
 block discarded – undo
288 296
 			<div class="windowbg">
289 297
 				<ul class="padding">';
290 298
 
291
-		if (!empty($context['error_info']['error_type']))
292
-			echo '
299
+		if (!empty($context['error_info']['error_type'])) {
300
+					echo '
293 301
 					<li>', $txt['error_type'], ': ', ucfirst($context['error_info']['error_type']), '</li>';
302
+		}
294 303
 
295
-		if (!empty($context['error_info']['message']))
296
-			echo '
304
+		if (!empty($context['error_info']['message'])) {
305
+					echo '
297 306
 					<li>', $txt['error_message'], ': ', $context['error_info']['message'], '</li>';
307
+		}
298 308
 
299
-		if (!empty($context['error_info']['file']))
300
-			echo '
309
+		if (!empty($context['error_info']['file'])) {
310
+					echo '
301 311
 					<li>', $txt['error_file'], ': ', $context['error_info']['file'], '</li>';
312
+		}
302 313
 
303
-		if (!empty($context['error_info']['line']))
304
-			echo '
314
+		if (!empty($context['error_info']['line'])) {
315
+					echo '
305 316
 					<li>', $txt['error_line'], ': ', $context['error_info']['line'], '</li>';
317
+		}
306 318
 
307
-		if (!empty($context['error_info']['url']))
308
-			echo '
319
+		if (!empty($context['error_info']['url'])) {
320
+					echo '
309 321
 					<li>', $txt['error_url'], ': ', $context['error_info']['url'], '</li>';
322
+		}
310 323
 
311 324
 
312 325
 		echo '
@@ -328,10 +341,12 @@  discard block
 block discarded – undo
328 341
 		foreach ($context['error_info']['backtrace'] as $key => $value)
329 342
 		{
330 343
 			//Check for existing
331
-			if (!property_exists($value,'file') || empty($value->file))
332
-				$value->file = $txt['unknown'];
333
-			if (!property_exists($value, 'line') || empty($value->line))
334
-				$value->line = -1;
344
+			if (!property_exists($value,'file') || empty($value->file)) {
345
+							$value->file = $txt['unknown'];
346
+			}
347
+			if (!property_exists($value, 'line') || empty($value->line)) {
348
+							$value->line = -1;
349
+			}
335 350
 
336 351
 				echo '
337 352
 					<li class="backtrace">', sprintf($txt['backtrace_info'], $key, $value->function, $value->file, $value->line, base64_encode($value->file)), '</li>';
Please login to merge, or discard this patch.
Themes/default/Recent.template.php 1 patch
Braces   +77 added lines, -54 removed lines patch added patch discarded remove patch
@@ -26,9 +26,10 @@  discard block
 block discarded – undo
26 26
 		</div>
27 27
 		<div class="pagesection">', $context['page_index'], '</div>';
28 28
 
29
-	if (empty($context['posts']))
30
-		echo '
29
+	if (empty($context['posts'])) {
30
+			echo '
31 31
 		<div class="windowbg">', $txt['no_messages'], '</div>';
32
+	}
32 33
 
33 34
 	foreach ($context['posts'] as $post)
34 35
 	{
@@ -41,28 +42,33 @@  discard block
 block discarded – undo
41 42
 			</div>
42 43
 			<div class="list_posts">', $post['message'], '</div>';
43 44
 
44
-		if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
45
-			echo '
45
+		if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
46
+					echo '
46 47
 			<ul class="quickbuttons">';
48
+		}
47 49
 
48 50
 		// If they *can* reply?
49
-		if ($post['can_reply'])
50
-			echo '
51
+		if ($post['can_reply']) {
52
+					echo '
51 53
 				<li><a href="', $scripturl, '?action=post;topic=', $post['topic'], '.', $post['start'], '"><span class="generic_icons reply_button"></span>', $txt['reply'], '</a></li>';
54
+		}
52 55
 
53 56
 		// If they *can* quote?
54
-		if ($post['can_quote'])
55
-			echo '
57
+		if ($post['can_quote']) {
58
+					echo '
56 59
 				<li><a href="', $scripturl, '?action=post;topic=', $post['topic'], '.', $post['start'], ';quote=', $post['id'], '"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>';
60
+		}
57 61
 
58 62
 		// How about... even... remove it entirely?!
59
-		if ($post['can_delete'])
60
-			echo '
63
+		if ($post['can_delete']) {
64
+					echo '
61 65
 				<li><a href="', $scripturl, '?action=deletemsg;msg=', $post['id'], ';topic=', $post['topic'], ';recent;', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
66
+		}
62 67
 
63
-		if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
64
-			echo '
68
+		if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
69
+					echo '
65 70
 			</ul>';
71
+		}
66 72
 
67 73
 		echo '
68 74
 		</div><!-- $post[css_class] -->';
@@ -83,12 +89,13 @@  discard block
 block discarded – undo
83 89
 	echo '
84 90
 	<div id="recent" class="main_content">';
85 91
 
86
-	if ($context['showCheckboxes'])
87
-		echo '
92
+	if ($context['showCheckboxes']) {
93
+			echo '
88 94
 		<form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="quickModForm" id="quickModForm">
89 95
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
90 96
 			<input type="hidden" name="qaction" value="markread">
91 97
 			<input type="hidden" name="redirect_url" value="action=unread', (!empty($context['showing_all_topics']) ? ';all' : ''), $context['querystring_board_limits'], '">';
98
+	}
92 99
 
93 100
 	if (!empty($context['topics']))
94 101
 	{
@@ -117,11 +124,12 @@  discard block
 block discarded – undo
117 124
 					</div>';
118 125
 
119 126
 		// Show a "select all" box for quick moderation?
120
-		if ($context['showCheckboxes'])
121
-			echo '
127
+		if ($context['showCheckboxes']) {
128
+					echo '
122 129
 					<div class="moderation">
123 130
 						<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');">
124 131
 					</div>';
132
+		}
125 133
 
126 134
 		echo '
127 135
 				</div><!-- #topic_header -->
@@ -141,17 +149,20 @@  discard block
 block discarded – undo
141 149
 			echo '
142 150
 							<div class="icons floatright">';
143 151
 
144
-			if ($topic['is_locked'])
145
-				echo '
152
+			if ($topic['is_locked']) {
153
+							echo '
146 154
 								<span class="generic_icons lock"></span>';
155
+			}
147 156
 
148
-			if ($topic['is_sticky'])
149
-				echo '
157
+			if ($topic['is_sticky']) {
158
+							echo '
150 159
 								<span class="generic_icons sticky"></span>';
160
+			}
151 161
 
152
-			if ($topic['is_poll'])
153
-				echo '
162
+			if ($topic['is_poll']) {
163
+							echo '
154 164
 								<span class="generic_icons poll"></span>';
165
+			}
155 166
 
156 167
 			echo '
157 168
 							</div>';
@@ -177,19 +188,21 @@  discard block
 block discarded – undo
177 188
 							', sprintf($txt['last_post_topic'], '<a href="' . $topic['last_post']['href'] . '">' . $topic['last_post']['time'] . '</a>', $topic['last_post']['member']['link']), '
178 189
 						</div>';
179 190
 
180
-			if ($context['showCheckboxes'])
181
-				echo '
191
+			if ($context['showCheckboxes']) {
192
+							echo '
182 193
 						<div class="moderation">
183 194
 							<input type="checkbox" name="topics[]" value="', $topic['id'], '">
184 195
 						</div>';
196
+			}
185 197
 
186 198
 			echo '
187 199
 					</div><!-- $topic[css_class] -->';
188 200
 		}
189 201
 
190
-		if (empty($context['topics']))
191
-			echo '
202
+		if (empty($context['topics'])) {
203
+					echo '
192 204
 					<div style="display: none;"></div>';
205
+		}
193 206
 
194 207
 		echo '
195 208
 				</div><!-- #topic_container -->
@@ -204,25 +217,27 @@  discard block
 block discarded – undo
204 217
 					', $context['page_index'], '
205 218
 				</div>
206 219
 			</div>';
207
-	}
208
-	else
209
-		echo '
220
+	} else {
221
+			echo '
210 222
 			<div class="cat_bar">
211 223
 				<h3 class="catbg centertext">
212 224
 					', $context['showing_all_topics'] ? $txt['topic_alert_none'] : $txt['unread_topics_visit_none'], '
213 225
 				</h3>
214 226
 			</div>';
227
+	}
215 228
 
216
-	if ($context['showCheckboxes'])
217
-		echo '
229
+	if ($context['showCheckboxes']) {
230
+			echo '
218 231
 		</form>';
232
+	}
219 233
 
220 234
 	echo '
221 235
 	</div><!-- #recent -->';
222 236
 
223
-	if (empty($context['no_topic_listing']))
224
-		template_topic_legend();
225
-}
237
+	if (empty($context['no_topic_listing'])) {
238
+			template_topic_legend();
239
+	}
240
+	}
226 241
 
227 242
 /**
228 243
  * Template for showing unread replies (eg new replies to topics you've posted in)
@@ -234,12 +249,13 @@  discard block
 block discarded – undo
234 249
 	echo '
235 250
 	<div id="recent">';
236 251
 
237
-	if ($context['showCheckboxes'])
238
-		echo '
252
+	if ($context['showCheckboxes']) {
253
+			echo '
239 254
 		<form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="quickModForm" id="quickModForm">
240 255
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
241 256
 			<input type="hidden" name="qaction" value="markread">
242 257
 			<input type="hidden" name="redirect_url" value="action=unreadreplies', (!empty($context['showing_all_topics']) ? ';all' : ''), $context['querystring_board_limits'], '">';
258
+	}
243 259
 
244 260
 	if (!empty($context['topics']))
245 261
 	{
@@ -268,11 +284,12 @@  discard block
 block discarded – undo
268 284
 					</div>';
269 285
 
270 286
 		// Show a "select all" box for quick moderation?
271
-		if ($context['showCheckboxes'])
272
-			echo '
287
+		if ($context['showCheckboxes']) {
288
+					echo '
273 289
 					<div class="moderation">
274 290
 						<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');">
275 291
 					</div>';
292
+		}
276 293
 
277 294
 		echo '
278 295
 				</div><!-- #topic_header -->
@@ -292,17 +309,20 @@  discard block
 block discarded – undo
292 309
 			echo '
293 310
 							<div class="icons floatright">';
294 311
 
295
-			if ($topic['is_locked'])
296
-				echo '
312
+			if ($topic['is_locked']) {
313
+							echo '
297 314
 								<span class="generic_icons lock"></span>';
315
+			}
298 316
 
299
-			if ($topic['is_sticky'])
300
-				echo '
317
+			if ($topic['is_sticky']) {
318
+							echo '
301 319
 								<span class="generic_icons sticky"></span>';
320
+			}
302 321
 
303
-			if ($topic['is_poll'])
304
-				echo '
322
+			if ($topic['is_poll']) {
323
+							echo '
305 324
 								<span class="generic_icons poll"></span>';
325
+			}
306 326
 
307 327
 			echo '
308 328
 							</div>';
@@ -328,11 +348,12 @@  discard block
 block discarded – undo
328 348
 							', sprintf($txt['last_post_topic'], '<a href="' . $topic['last_post']['href'] . '">' . $topic['last_post']['time'] . '</a>', $topic['last_post']['member']['link']), '
329 349
 						</div>';
330 350
 
331
-			if ($context['showCheckboxes'])
332
-				echo '
351
+			if ($context['showCheckboxes']) {
352
+							echo '
333 353
 						<div class="moderation">
334 354
 							<input type="checkbox" name="topics[]" value="', $topic['id'], '">
335 355
 						</div>';
356
+			}
336 357
 
337 358
 			echo '
338 359
 					</div><!-- $topic[css_class] -->';
@@ -349,24 +370,26 @@  discard block
 block discarded – undo
349 370
 					', $context['page_index'], '
350 371
 				</div>
351 372
 			</div>';
352
-	}
353
-	else
354
-		echo '
373
+	} else {
374
+			echo '
355 375
 			<div class="cat_bar">
356 376
 				<h3 class="catbg centertext">
357 377
 					', $context['showing_all_topics'] ? $txt['topic_alert_none'] : $txt['updated_topics_visit_none'], '
358 378
 				</h3>
359 379
 			</div>';
380
+	}
360 381
 
361
-	if ($context['showCheckboxes'])
362
-		echo '
382
+	if ($context['showCheckboxes']) {
383
+			echo '
363 384
 		</form>';
385
+	}
364 386
 
365 387
 	echo '
366 388
 	</div><!-- #recent -->';
367 389
 
368
-	if (empty($context['no_topic_listing']))
369
-		template_topic_legend();
370
-}
390
+	if (empty($context['no_topic_listing'])) {
391
+			template_topic_legend();
392
+	}
393
+	}
371 394
 
372 395
 ?>
373 396
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +297 added lines, -224 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $smcFunc, $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');
@@ -54,21 +57,25 @@  discard block
 block discarded – undo
54 57
 
55 58
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
56 59
 	{
57
-			if (!is_array($modSettings['attachment_basedirectories']))
58
-				$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
60
+			if (!is_array($modSettings['attachment_basedirectories'])) {
61
+							$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
62
+			}
59 63
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
64
+	} else {
65
+			$base_dir = 0;
60 66
 	}
61
-	else
62
-		$base_dir = 0;
63 67
 
64 68
 	if ($modSettings['automanage_attachments'] == 1)
65 69
 	{
66
-		if (!isset($modSettings['last_attachments_directory']))
67
-			$modSettings['last_attachments_directory'] = array();
68
-		if (!is_array($modSettings['last_attachments_directory']))
69
-			$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
70
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
71
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
70
+		if (!isset($modSettings['last_attachments_directory'])) {
71
+					$modSettings['last_attachments_directory'] = array();
72
+		}
73
+		if (!is_array($modSettings['last_attachments_directory'])) {
74
+					$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
75
+		}
76
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
77
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
78
+		}
72 79
 	}
73 80
 
74 81
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -97,12 +104,14 @@  discard block
 block discarded – undo
97 104
 			$updir = '';
98 105
 	}
99 106
 
100
-	if (!is_array($modSettings['attachmentUploadDir']))
101
-		$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
102
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
103
-		$outputCreation = automanage_attachments_create_directory($updir);
104
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
105
-		$outputCreation = true;
107
+	if (!is_array($modSettings['attachmentUploadDir'])) {
108
+			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
109
+	}
110
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
111
+			$outputCreation = automanage_attachments_create_directory($updir);
112
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
113
+			$outputCreation = true;
114
+	}
106 115
 
107 116
 	if ($outputCreation)
108 117
 	{
@@ -139,8 +148,9 @@  discard block
 block discarded – undo
139 148
 		$count = count($tree);
140 149
 
141 150
 		$directory = attachments_init_dir($tree, $count);
142
-		if ($directory === false)
143
-			return false;
151
+		if ($directory === false) {
152
+					return false;
153
+		}
144 154
 	}
145 155
 
146 156
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -168,8 +178,9 @@  discard block
 block discarded – undo
168 178
 	}
169 179
 
170 180
 	// Everything seems fine...let's create the .htaccess
171
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
172
-		secureDirectory($updir, true);
181
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
182
+			secureDirectory($updir, true);
183
+	}
173 184
 
174 185
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
175 186
 	$updir = rtrim($updir, $sep);
@@ -201,8 +212,9 @@  discard block
 block discarded – undo
201 212
 {
202 213
 	global $smcFunc, $modSettings, $boarddir;
203 214
 
204
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
205
-		return;
215
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
216
+			return;
217
+	}
206 218
 
207 219
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
208 220
 	// Just to be sure: I don't want directory separators at the end
@@ -214,13 +226,14 @@  discard block
 block discarded – undo
214 226
 	{
215 227
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
216 228
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
229
+	} else {
230
+			$base_dir = 0;
217 231
 	}
218
-	else
219
-		$base_dir = 0;
220 232
 
221 233
 	// Get the last attachment directory for that base directory
222
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
223
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
234
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
235
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
236
+	}
224 237
 	// And increment it.
225 238
 	$modSettings['last_attachments_directory'][$base_dir]++;
226 239
 
@@ -235,10 +248,10 @@  discard block
 block discarded – undo
235 248
 		$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
236 249
 
237 250
 		return true;
251
+	} else {
252
+			return false;
253
+	}
238 254
 	}
239
-	else
240
-		return false;
241
-}
242 255
 
243 256
 /**
244 257
  * Split a path into a list of all directories and subdirectories
@@ -256,12 +269,13 @@  discard block
 block discarded – undo
256 269
 			* in Windows we need to explode for both \ and /
257 270
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
258 271
 	*/
259
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
260
-		$tree = preg_split('#[\\\/]#', $directory);
261
-	else
272
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
273
+			$tree = preg_split('#[\\\/]#', $directory);
274
+	} else
262 275
 	{
263
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
264
-			return false;
276
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
277
+					return false;
278
+		}
265 279
 
266 280
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
267 281
 	}
@@ -285,10 +299,11 @@  discard block
 block discarded – undo
285 299
 		 //Better be sure that the first part of the path is actually a drive letter...
286 300
 		 //...even if, I should check this in the admin page...isn't it?
287 301
 		 //...NHAAA Let's leave space for users' complains! :P
288
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
289
-			$directory = array_shift($tree);
290
-		else
291
-			return false;
302
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
303
+					$directory = array_shift($tree);
304
+		} else {
305
+					return false;
306
+		}
292 307
 
293 308
 		$count--;
294 309
 	}
@@ -303,18 +318,20 @@  discard block
 block discarded – undo
303 318
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
304 319
 
305 320
 	// Make sure we're uploading to the right place.
306
-	if (!empty($modSettings['automanage_attachments']))
307
-		automanage_attachments_check_directory();
321
+	if (!empty($modSettings['automanage_attachments'])) {
322
+			automanage_attachments_check_directory();
323
+	}
308 324
 
309
-	if (!is_array($modSettings['attachmentUploadDir']))
310
-		$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
325
+	if (!is_array($modSettings['attachmentUploadDir'])) {
326
+			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
327
+	}
311 328
 
312 329
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
313 330
 
314 331
 	// Is the attachments folder actualy there?
315
-	if (!empty($context['dir_creation_error']))
316
-		$initial_error = $context['dir_creation_error'];
317
-	elseif (!is_dir($context['attach_dir']))
332
+	if (!empty($context['dir_creation_error'])) {
333
+			$initial_error = $context['dir_creation_error'];
334
+	} elseif (!is_dir($context['attach_dir']))
318 335
 	{
319 336
 		$initial_error = 'attach_folder_warning';
320 337
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -337,12 +354,12 @@  discard block
 block discarded – undo
337 354
 			);
338 355
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
339 356
 			$smcFunc['db_free_result']($request);
340
-		}
341
-		else
342
-			$context['attachments'] = array(
357
+		} else {
358
+					$context['attachments'] = array(
343 359
 				'quantity' => 0,
344 360
 				'total_size' => 0,
345 361
 			);
362
+		}
346 363
 	}
347 364
 
348 365
 	// Hmm. There are still files in session.
@@ -352,39 +369,44 @@  discard block
 block discarded – undo
352 369
 		// Let's try to keep them. But...
353 370
 		$ignore_temp = true;
354 371
 		// If new files are being added. We can't ignore those
355
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
356
-			if (!empty($dummy))
372
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
373
+					if (!empty($dummy))
357 374
 			{
358 375
 				$ignore_temp = false;
376
+		}
359 377
 				break;
360 378
 			}
361 379
 
362 380
 		// Need to make space for the new files. So, bye bye.
363 381
 		if (!$ignore_temp)
364 382
 		{
365
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
366
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
383
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
384
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
367 385
 					unlink($attachment['tmp_name']);
386
+			}
368 387
 
369 388
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
370 389
 			$_SESSION['temp_attachments'] = array();
371 390
 		}
372 391
 	}
373 392
 
374
-	if (!isset($_FILES['attachment']['name']))
375
-		$_FILES['attachment']['tmp_name'] = array();
393
+	if (!isset($_FILES['attachment']['name'])) {
394
+			$_FILES['attachment']['tmp_name'] = array();
395
+	}
376 396
 
377
-	if (!isset($_SESSION['temp_attachments']))
378
-		$_SESSION['temp_attachments'] = array();
397
+	if (!isset($_SESSION['temp_attachments'])) {
398
+			$_SESSION['temp_attachments'] = array();
399
+	}
379 400
 
380 401
 	// Remember where we are at. If it's anywhere at all.
381
-	if (!$ignore_temp)
382
-		$_SESSION['temp_attachments']['post'] = array(
402
+	if (!$ignore_temp) {
403
+			$_SESSION['temp_attachments']['post'] = array(
383 404
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
384 405
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
385 406
 			'topic' => !empty($topic) ? $topic : 0,
386 407
 			'board' => !empty($board) ? $board : 0,
387 408
 		);
409
+	}
388 410
 
389 411
 	// If we have an initial error, lets just display it.
390 412
 	if (!empty($initial_error))
@@ -392,9 +414,10 @@  discard block
 block discarded – undo
392 414
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
393 415
 
394 416
 		// And delete the files 'cos they ain't going nowhere.
395
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
396
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
417
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
418
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
397 419
 				unlink($_FILES['attachment']['tmp_name'][$n]);
420
+		}
398 421
 
399 422
 		$_FILES['attachment']['tmp_name'] = array();
400 423
 	}
@@ -402,21 +425,24 @@  discard block
 block discarded – undo
402 425
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
403 426
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
404 427
 	{
405
-		if ($_FILES['attachment']['name'][$n] == '')
406
-			continue;
428
+		if ($_FILES['attachment']['name'][$n] == '') {
429
+					continue;
430
+		}
407 431
 
408 432
 		// First, let's first check for PHP upload errors.
409 433
 		$errors = array();
410 434
 		if (!empty($_FILES['attachment']['error'][$n]))
411 435
 		{
412
-			if ($_FILES['attachment']['error'][$n] == 2)
413
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
414
-			elseif ($_FILES['attachment']['error'][$n] == 6)
415
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
416
-			else
417
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
418
-			if (empty($errors))
419
-				$errors[] = 'attach_php_error';
436
+			if ($_FILES['attachment']['error'][$n] == 2) {
437
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
438
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
439
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
440
+			} else {
441
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
442
+			}
443
+			if (empty($errors)) {
444
+							$errors[] = 'attach_php_error';
445
+			}
420 446
 		}
421 447
 
422 448
 		// Try to move and rename the file before doing any more checks on it.
@@ -426,8 +452,9 @@  discard block
 block discarded – undo
426 452
 		{
427 453
 			// The reported MIME type of the attachment might not be reliable.
428 454
 			// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
429
-			if (function_exists('mime_content_type'))
430
-				$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
455
+			if (function_exists('mime_content_type')) {
456
+							$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
457
+			}
431 458
 
432 459
 			$_SESSION['temp_attachments'][$attachID] = array(
433 460
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -439,16 +466,16 @@  discard block
 block discarded – undo
439 466
 			);
440 467
 
441 468
 			// Move the file to the attachments folder with a temp name for now.
442
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
443
-				smf_chmod($destName, 0644);
444
-			else
469
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
470
+							smf_chmod($destName, 0644);
471
+			} else
445 472
 			{
446 473
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
447
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
448
-					unlink($_FILES['attachment']['tmp_name'][$n]);
474
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
475
+									unlink($_FILES['attachment']['tmp_name'][$n]);
476
+				}
449 477
 			}
450
-		}
451
-		else
478
+		} else
452 479
 		{
453 480
 			$_SESSION['temp_attachments'][$attachID] = array(
454 481
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -456,12 +483,14 @@  discard block
 block discarded – undo
456 483
 				'errors' => $errors,
457 484
 			);
458 485
 
459
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
460
-				unlink($_FILES['attachment']['tmp_name'][$n]);
486
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
487
+							unlink($_FILES['attachment']['tmp_name'][$n]);
488
+			}
461 489
 		}
462 490
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
463
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
464
-			attachmentChecks($attachID);
491
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
492
+					attachmentChecks($attachID);
493
+		}
465 494
 	}
466 495
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
467 496
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -488,21 +517,20 @@  discard block
 block discarded – undo
488 517
 	global $modSettings, $context, $sourcedir, $smcFunc;
489 518
 
490 519
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
491
-	if (empty($_SESSION['temp_attachments'][$attachID]))
492
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
493
-
494
-	elseif (empty($attachID))
495
-		$error = '$attachID';
496
-
497
-	elseif (empty($context['attachments']))
498
-		$error = '$context[\'attachments\']';
499
-
500
-	elseif (empty($context['attach_dir']))
501
-		$error = '$context[\'attach_dir\']';
520
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
521
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
522
+	} elseif (empty($attachID)) {
523
+			$error = '$attachID';
524
+	} elseif (empty($context['attachments'])) {
525
+			$error = '$context[\'attachments\']';
526
+	} elseif (empty($context['attach_dir'])) {
527
+			$error = '$context[\'attach_dir\']';
528
+	}
502 529
 
503 530
 	// Let's get their attention.
504
-	if (!empty($error))
505
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
531
+	if (!empty($error)) {
532
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
533
+	}
506 534
 
507 535
 	// Just in case this slipped by the first checks, we stop it here and now
508 536
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -531,8 +559,9 @@  discard block
 block discarded – undo
531 559
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
532 560
 			if (!(empty($size)) && ($size[2] != $old_format))
533 561
 			{
534
-				if (isset($context['valid_image_types'][$size[2]]))
535
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['valid_image_types'][$size[2]];
562
+				if (isset($context['valid_image_types'][$size[2]])) {
563
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['valid_image_types'][$size[2]];
564
+				}
536 565
 			}
537 566
 		}
538 567
 	}
@@ -586,42 +615,48 @@  discard block
 block discarded – undo
586 615
 				// Or, let the user know that it ain't gonna happen.
587 616
 				else
588 617
 				{
589
-					if (isset($context['dir_creation_error']))
590
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
591
-					else
592
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
618
+					if (isset($context['dir_creation_error'])) {
619
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
620
+					} else {
621
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
622
+					}
593 623
 				}
624
+			} else {
625
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
594 626
 			}
595
-			else
596
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
597 627
 		}
598 628
 	}
599 629
 
600 630
 	// Is the file too big?
601 631
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
602
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
632
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
634
+	}
604 635
 
605 636
 	// Check the total upload size for this post...
606
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
607
-		$_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)));
637
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
638
+			$_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)));
639
+	}
608 640
 
609 641
 	// Have we reached the maximum number of files we are allowed?
610 642
 	$context['attachments']['quantity']++;
611 643
 
612 644
 	// Set a max limit if none exists
613
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
614
-		$modSettings['attachmentNumPerPostLimit'] = 50;
645
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
646
+			$modSettings['attachmentNumPerPostLimit'] = 50;
647
+	}
615 648
 
616
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
617
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
649
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
650
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
651
+	}
618 652
 
619 653
 	// File extension check
620 654
 	if (!empty($modSettings['attachmentCheckExtensions']))
621 655
 	{
622 656
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
623
-		foreach ($allowed as $k => $dummy)
624
-			$allowed[$k] = trim($dummy);
657
+		foreach ($allowed as $k => $dummy) {
658
+					$allowed[$k] = trim($dummy);
659
+		}
625 660
 
626 661
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
627 662
 		{
@@ -633,10 +668,12 @@  discard block
 block discarded – undo
633 668
 	// Undo the math if there's an error
634 669
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
635 670
 	{
636
-		if (isset($context['dir_size']))
637
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
638
-		if (isset($context['dir_files']))
639
-			$context['dir_files']--;
671
+		if (isset($context['dir_size'])) {
672
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
673
+		}
674
+		if (isset($context['dir_files'])) {
675
+					$context['dir_files']--;
676
+		}
640 677
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
641 678
 		$context['attachments']['quantity']--;
642 679
 		return false;
@@ -668,12 +705,14 @@  discard block
 block discarded – undo
668 705
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
669 706
 	{
670 707
 		// Got a proper mime type?
671
-		if (!empty($size['mime']))
672
-			$attachmentOptions['mime_type'] = $size['mime'];
708
+		if (!empty($size['mime'])) {
709
+					$attachmentOptions['mime_type'] = $size['mime'];
710
+		}
673 711
 
674 712
 		// Otherwise a valid one?
675
-		elseif (isset($context['valid_image_types'][$size[2]]))
676
-			$attachmentOptions['mime_type'] = 'image/' . $context['valid_image_types'][$size[2]];
713
+		elseif (isset($context['valid_image_types'][$size[2]])) {
714
+					$attachmentOptions['mime_type'] = 'image/' . $context['valid_image_types'][$size[2]];
715
+		}
677 716
 	}
678 717
 
679 718
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -685,15 +724,17 @@  discard block
 block discarded – undo
685 724
 	}
686 725
 
687 726
 	// Get the hash if no hash has been given yet.
688
-	if (empty($attachmentOptions['file_hash']))
689
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
727
+	if (empty($attachmentOptions['file_hash'])) {
728
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
729
+	}
690 730
 
691 731
 	// Assuming no-one set the extension let's take a look at it.
692 732
 	if (empty($attachmentOptions['fileext']))
693 733
 	{
694 734
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
695
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
696
-			$attachmentOptions['fileext'] = '';
735
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
736
+					$attachmentOptions['fileext'] = '';
737
+		}
697 738
 	}
698 739
 
699 740
 	// Last chance to change stuff!
@@ -702,8 +743,9 @@  discard block
 block discarded – undo
702 743
 	// Make sure the folder is valid...
703 744
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
704 745
 	$folders = array_keys($tmp);
705
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
706
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
746
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
747
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
748
+	}
707 749
 
708 750
 	$attachmentOptions['id'] = $smcFunc['db_insert']('',
709 751
 		'{db_prefix}attachments',
@@ -734,8 +776,8 @@  discard block
 block discarded – undo
734 776
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
735 777
 
736 778
 	// If it's not approved then add to the approval queue.
737
-	if (!$attachmentOptions['approved'])
738
-		$smcFunc['db_insert']('',
779
+	if (!$attachmentOptions['approved']) {
780
+			$smcFunc['db_insert']('',
739 781
 			'{db_prefix}approval_queue',
740 782
 			array(
741 783
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -745,9 +787,11 @@  discard block
 block discarded – undo
745 787
 			),
746 788
 			array()
747 789
 		);
790
+	}
748 791
 
749
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
750
-		return true;
792
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
793
+			return true;
794
+	}
751 795
 
752 796
 	// Like thumbnails, do we?
753 797
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -758,13 +802,15 @@  discard block
 block discarded – undo
758 802
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
759 803
 			list ($thumb_width, $thumb_height) = $size;
760 804
 
761
-			if (!empty($size['mime']))
762
-				$thumb_mime = $size['mime'];
763
-			elseif (isset($context['valid_image_types'][$size[2]]))
764
-				$thumb_mime = 'image/' . $context['valid_image_types'][$size[2]];
805
+			if (!empty($size['mime'])) {
806
+							$thumb_mime = $size['mime'];
807
+			} elseif (isset($context['valid_image_types'][$size[2]])) {
808
+							$thumb_mime = 'image/' . $context['valid_image_types'][$size[2]];
809
+			}
765 810
 			// Lord only knows how this happened...
766
-			else
767
-				$thumb_mime = '';
811
+			else {
812
+							$thumb_mime = '';
813
+			}
768 814
 
769 815
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
770 816
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -844,15 +890,17 @@  discard block
 block discarded – undo
844 890
 	global $smcFunc;
845 891
 
846 892
 	// Oh, come on!
847
-	if (empty($attachIDs) || empty($msgID))
848
-		return false;
893
+	if (empty($attachIDs) || empty($msgID)) {
894
+			return false;
895
+	}
849 896
 
850 897
 	// "I see what is right and approve, but I do what is wrong."
851 898
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
852 899
 
853 900
 	// One last check
854
-	if (empty($attachIDs))
855
-		return false;
901
+	if (empty($attachIDs)) {
902
+			return false;
903
+	}
856 904
 
857 905
 	// Perform.
858 906
 	$smcFunc['db_query']('', '
@@ -880,8 +928,9 @@  discard block
 block discarded – undo
880 928
 	global $board, $modSettings, $context, $scripturl, $smcFunc;
881 929
 
882 930
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
931
+	if (empty($attachID)) {
932
+			return 'attachments_no_data_loaded';
933
+	}
885 934
 
886 935
 	// Make it easy.
887 936
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +939,23 @@  discard block
 block discarded – undo
890 939
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 940
 
892 941
 	// "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;
942
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
943
+			return $externalParse;
944
+	}
895 945
 
896 946
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
947
+	if (empty($modSettings['attachmentEnable'])) {
948
+			return 'attachments_not_enable';
949
+	}
899 950
 
900 951
 	// Previewing much? no msg ID has been set yet.
901 952
 	if (!empty($context['preview_message']))
902 953
 	{
903 954
 		$allAttachments = getAttachsByMsg(0);
904 955
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
956
+		if (empty($allAttachments[0][$attachID])) {
957
+					return 'attachments_no_data_loaded';
958
+		}
907 959
 
908 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
909 961
 
@@ -915,57 +967,66 @@  discard block
 block discarded – undo
915 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
916 968
 
917 969
 		// Fix the thumbnail too, if the image has one.
918
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
919
-			$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
+		}
920 973
 
921 974
 		return $attachContext;
922 975
 	}
923 976
 
924 977
 	// There is always the chance someone else has already done our dirty work...
925 978
 	// If so, all pertinent checks were already done. Hopefully...
926
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
927
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
928 982
 
929 983
 	// If we are lucky enough to be in $board's scope then check it!
930
-	if (!empty($board) && !allowedTo('view_attachments', $board))
931
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
932 987
 
933 988
 	// Get the message info associated with this particular attach ID.
934 989
 	$attachInfo = getAttachMsgInfo($attachID);
935 990
 
936 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
937
-	if (empty($attachInfo) || empty($attachInfo['msg']))
938
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
939 995
 
940 996
 	// Hold it! got the info now check if you can see this attachment.
941
-	if (!allowedTo('view_attachments', $attachInfo['board']))
942
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
943 1000
 
944 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
945 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
946 1003
 
947 1004
 	// No point in keep going further.
948
-	if (!allowedTo('view_attachments', $attachContext['board']))
949
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
950 1008
 
951 1009
 	// Load this particular attach's context.
952
-	if (!empty($attachContext))
953
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
954 1013
 
955 1014
 	// One last check, you know, gotta be paranoid...
956
-	else
957
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
958 1018
 
959 1019
 	// This is the last "if" I promise!
960
-	if (empty($attachLoaded))
961
-		return 'attachments_no_data_loaded';
962
-
963
-	else
964
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
965 1025
 
966 1026
 	// You may or may not want to show this under the post.
967
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
968
-		$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
+	}
969 1030
 
970 1031
 	// Last minute changes?
971 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -985,8 +1046,9 @@  discard block
 block discarded – undo
985 1046
 {
986 1047
 	global $smcFunc, $modSettings;
987 1048
 
988
-	if (empty($attachIDs))
989
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
990 1052
 
991 1053
 	$return = array();
992 1054
 
@@ -1002,11 +1064,12 @@  discard block
 block discarded – undo
1002 1064
 		)
1003 1065
 	);
1004 1066
 
1005
-	if ($smcFunc['db_num_rows']($request) != 1)
1006
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1007 1070
 
1008
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1009
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1010 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1011 1074
 			'size' => $row['size'],
1012 1075
 			'attachID' => $row['id_attach'],
@@ -1015,6 +1078,7 @@  discard block
 block discarded – undo
1015 1078
 			'mime_type' => $row['mime_type'],
1016 1079
 			'thumb' => $row['id_thumb'],
1017 1080
 		);
1081
+	}
1018 1082
 	$smcFunc['db_free_result']($request);
1019 1083
 
1020 1084
 	return $return;
@@ -1031,8 +1095,9 @@  discard block
 block discarded – undo
1031 1095
 {
1032 1096
 	global $smcFunc;
1033 1097
 
1034
-	if (empty($attachID))
1035
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1036 1101
 
1037 1102
 	$request = $smcFunc['db_query']('', '
1038 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1045,8 +1110,9 @@  discard block
 block discarded – undo
1045 1110
 		)
1046 1111
 	);
1047 1112
 
1048
-	if ($smcFunc['db_num_rows']($request) != 1)
1049
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1050 1116
 
1051 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1052 1118
 	$smcFunc['db_free_result']($request);
@@ -1087,8 +1153,9 @@  discard block
 block discarded – undo
1087 1153
 		$temp = array();
1088 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1089 1155
 		{
1090
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1091
-				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
+			}
1092 1159
 
1093 1160
 			$temp[$row['id_attach']] = $row;
1094 1161
 		}
@@ -1117,8 +1184,9 @@  discard block
 block discarded – undo
1117 1184
 {
1118 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1119 1186
 
1120
-	if (empty($attachments) || empty($attachments[$id_msg]))
1121
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1122 1190
 
1123 1191
 	// Set up the attachment info - based on code by Meriadoc.
1124 1192
 	$attachmentData = array();
@@ -1142,11 +1210,13 @@  discard block
 block discarded – undo
1142 1210
 			);
1143 1211
 
1144 1212
 			// If something is unapproved we'll note it so we can sort them.
1145
-			if (!$attachment['approved'])
1146
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1147 1216
 
1148
-			if (!$attachmentData[$i]['is_image'])
1149
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1150 1220
 
1151 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1152 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1167,11 +1237,11 @@  discard block
 block discarded – undo
1167 1237
 						// So what folder are we putting this image in?
1168 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1169 1239
 						{
1170
-							if (!is_array($modSettings['attachmentUploadDir']))
1171
-								$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1242
+							}
1172 1243
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1173
-						}
1174
-						else
1244
+						} else
1175 1245
 						{
1176 1246
 							$id_folder_thumb = 1;
1177 1247
 						}
@@ -1185,10 +1255,11 @@  discard block
 block discarded – undo
1185 1255
 						$thumb_ext = isset($context['valid_image_types'][$size[2]]) ? $context['valid_image_types'][$size[2]] : '';
1186 1256
 
1187 1257
 						// Figure out the mime type.
1188
-						if (!empty($size['mime']))
1189
-							$thumb_mime = $size['mime'];
1190
-						else
1191
-							$thumb_mime = 'image/' . $thumb_ext;
1258
+						if (!empty($size['mime'])) {
1259
+													$thumb_mime = $size['mime'];
1260
+						} else {
1261
+													$thumb_mime = 'image/' . $thumb_ext;
1262
+						}
1192 1263
 
1193 1264
 						$thumb_filename = $attachment['filename'] . '_thumb';
1194 1265
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1236,11 +1307,12 @@  discard block
 block discarded – undo
1236 1307
 				}
1237 1308
 			}
1238 1309
 
1239
-			if (!empty($attachment['id_thumb']))
1240
-				$attachmentData[$i]['thumbnail'] = array(
1310
+			if (!empty($attachment['id_thumb'])) {
1311
+							$attachmentData[$i]['thumbnail'] = array(
1241 1312
 					'id' => $attachment['id_thumb'],
1242 1313
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1243 1314
 				);
1315
+			}
1244 1316
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1245 1317
 
1246 1318
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1250,30 +1322,31 @@  discard block
 block discarded – undo
1250 1322
 				{
1251 1323
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1252 1324
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1253
-				}
1254
-				elseif (!empty($modSettings['max_image_width']))
1325
+				} elseif (!empty($modSettings['max_image_width']))
1255 1326
 				{
1256 1327
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1257 1328
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1258 1329
 				}
1259
-			}
1260
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1330
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1261 1331
 			{
1262 1332
 				// If the image is too large to show inline, make it a popup.
1263
-				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'])))
1264
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1265
-				else
1266
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1333
+				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']))) {
1334
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1335
+				} else {
1336
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1337
+				}
1267 1338
 			}
1268 1339
 
1269
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1270
-				$attachmentData[$i]['downloads']++;
1340
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1341
+							$attachmentData[$i]['downloads']++;
1342
+			}
1271 1343
 		}
1272 1344
 	}
1273 1345
 
1274 1346
 	// Do we need to instigate a sort?
1275
-	if ($have_unapproved)
1276
-		usort($attachmentData, 'approved_attach_sort');
1347
+	if ($have_unapproved) {
1348
+			usort($attachmentData, 'approved_attach_sort');
1349
+	}
1277 1350
 
1278 1351
 	return $attachmentData;
1279 1352
 }
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +792 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 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * 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,28 +48,36 @@  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 73
 		// We explicitly do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -405,9 +422,9 @@  discard block
 block discarded – undo
405 422
 				break;
406 423
 			}
407 424
 		}
425
+	} else {
426
+			$id_member = 0;
408 427
 	}
409
-	else
410
-		$id_member = 0;
411 428
 
412 429
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
413 430
 	{
@@ -415,8 +432,9 @@  discard block
 block discarded – undo
415 432
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
416 433
 
417 434
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
418
-		if (empty($cookie_data))
419
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
435
+		if (empty($cookie_data)) {
436
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
437
+		}
420 438
 
421 439
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
422 440
 
@@ -424,16 +442,17 @@  discard block
 block discarded – undo
424 442
 
425 443
 		// Make sure the cookie is set to the correct domain and path
426 444
 		require_once($sourcedir . '/Subs-Auth.php');
427
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
428
-			setLoginCookie((int) $login_span - time(), $id_member);
429
-	}
430
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
445
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
446
+					setLoginCookie((int) $login_span - time(), $id_member);
447
+		}
448
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
431 449
 	{
432 450
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
433 451
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
434 452
 
435
-		if (empty($cookie_data))
436
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
453
+		if (empty($cookie_data)) {
454
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
455
+		}
437 456
 
438 457
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
439 458
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -458,30 +477,34 @@  discard block
 block discarded – undo
458 477
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
459 478
 			$smcFunc['db_free_result']($request);
460 479
 
461
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
462
-				$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
480
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
481
+							$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
482
+			}
463 483
 
464
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
465
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
484
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
485
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
486
+			}
466 487
 		}
467 488
 
468 489
 		// Did we find 'im?  If not, junk it.
469 490
 		if (!empty($user_settings))
470 491
 		{
471 492
 			// As much as the password should be right, we can assume the integration set things up.
472
-			if (!empty($already_verified) && $already_verified === true)
473
-				$check = true;
493
+			if (!empty($already_verified) && $already_verified === true) {
494
+							$check = true;
495
+			}
474 496
 			// SHA-512 hash should be 128 characters long.
475
-			elseif (strlen($password) == 128)
476
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
477
-			else
478
-				$check = false;
497
+			elseif (strlen($password) == 128) {
498
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
499
+			} else {
500
+							$check = false;
501
+			}
479 502
 
480 503
 			// Wrong password or not activated - either way, you're going nowhere.
481 504
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
505
+		} else {
506
+					$id_member = 0;
482 507
 		}
483
-		else
484
-			$id_member = 0;
485 508
 
486 509
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
487 510
 		if (!$id_member)
@@ -510,8 +533,9 @@  discard block
 block discarded – undo
510 533
 
511 534
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
512 535
 
513
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
514
-						$tfasecret = null;
536
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
537
+											$tfasecret = null;
538
+					}
515 539
 				}
516 540
 
517 541
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -533,10 +557,12 @@  discard block
 block discarded – undo
533 557
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
534 558
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
535 559
 		{
536
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
560
+			if ($modSettings['tfa_mode'] == 2) {
561
+				//only do this if we are just forcing SOME membergroups
537 562
 			{
538 563
 				//Build an array of ALL user membergroups.
539 564
 				$full_groups = array($user_settings['id_group']);
565
+			}
540 566
 				if (!empty($user_settings['additional_groups']))
541 567
 				{
542 568
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -556,15 +582,17 @@  discard block
 block discarded – undo
556 582
 				);
557 583
 				$row = $smcFunc['db_fetch_assoc']($request);
558 584
 				$smcFunc['db_free_result']($request);
585
+			} else {
586
+							$row['total'] = 1;
559 587
 			}
560
-			else
561
-				$row['total'] = 1; //simplifies logics in the next "if"
588
+			//simplifies logics in the next "if"
562 589
 
563 590
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
564 591
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
565 592
 
566
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
567
-				redirectexit('action=profile;area=tfasetup;forced');
593
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
594
+							redirectexit('action=profile;area=tfasetup;forced');
595
+			}
568 596
 		}
569 597
 	}
570 598
 
@@ -601,29 +629,32 @@  discard block
 block discarded – undo
601 629
 				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']));
602 630
 				$user_settings['last_login'] = time();
603 631
 
604
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
605
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
632
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
633
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
634
+				}
606 635
 
607
-				if (!empty($modSettings['cache_enable']))
608
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
636
+				if (!empty($modSettings['cache_enable'])) {
637
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
638
+				}
609 639
 			}
640
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
641
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
610 642
 		}
611
-		elseif (empty($_SESSION['id_msg_last_visit']))
612
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
613 643
 
614 644
 		$username = $user_settings['member_name'];
615 645
 
616
-		if (empty($user_settings['additional_groups']))
617
-			$user_info = array(
646
+		if (empty($user_settings['additional_groups'])) {
647
+					$user_info = array(
618 648
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
619 649
 			);
620
-		else
621
-			$user_info = array(
650
+		} else {
651
+					$user_info = array(
622 652
 				'groups' => array_merge(
623 653
 					array($user_settings['id_group'], $user_settings['id_post_group']),
624 654
 					explode(',', $user_settings['additional_groups'])
625 655
 				)
626 656
 			);
657
+		}
627 658
 
628 659
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
629 660
 		$user_info['groups'] = array_map('intval', $user_info['groups']);
@@ -640,8 +671,7 @@  discard block
 block discarded – undo
640 671
 			$time_system = new DateTime('now', $tz_system);
641 672
 			$time_user = new DateTime('now', $tz_user);
642 673
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
643
-		}
644
-		else
674
+		} else
645 675
 		{
646 676
 			// !!! Compatibility.
647 677
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -655,8 +685,9 @@  discard block
 block discarded – undo
655 685
 		$user_info = array('groups' => array(-1));
656 686
 		$user_settings = array();
657 687
 
658
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
659
-			$_COOKIE[$cookiename] = '';
688
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
689
+					$_COOKIE[$cookiename] = '';
690
+		}
660 691
 
661 692
 		// Expire the 2FA cookie
662 693
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -673,19 +704,20 @@  discard block
 block discarded – undo
673 704
 		}
674 705
 
675 706
 		// Create a login token if it doesn't exist yet.
676
-		if (!isset($_SESSION['token']['post-login']))
677
-			createToken('login');
678
-		else
679
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
707
+		if (!isset($_SESSION['token']['post-login'])) {
708
+					createToken('login');
709
+		} else {
710
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
711
+		}
680 712
 
681 713
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
682 714
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
683 715
 		{
684 716
 			require_once($sourcedir . '/ManageSearchEngines.php');
685 717
 			$user_info['possibly_robot'] = SpiderCheck();
718
+		} elseif (!empty($modSettings['spider_mode'])) {
719
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
686 720
 		}
687
-		elseif (!empty($modSettings['spider_mode']))
688
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
689 721
 		// If we haven't turned on proper spider hunts then have a guess!
690 722
 		else
691 723
 		{
@@ -733,8 +765,9 @@  discard block
 block discarded – undo
733 765
 	$user_info['groups'] = array_unique($user_info['groups']);
734 766
 
735 767
 	// 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.
736
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
737
-		unset($user_info['ignoreboards'][$tmp]);
768
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
769
+			unset($user_info['ignoreboards'][$tmp]);
770
+	}
738 771
 
739 772
 	// Allow the user to change their language.
740 773
 	if (!empty($modSettings['userLanguage']))
@@ -747,13 +780,14 @@  discard block
 block discarded – undo
747 780
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
748 781
 
749 782
 			// Make it permanent for members.
750
-			if (!empty($user_info['id']))
751
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
752
-			else
753
-				$_SESSION['language'] = $user_info['language'];
783
+			if (!empty($user_info['id'])) {
784
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
785
+			} else {
786
+							$_SESSION['language'] = $user_info['language'];
787
+			}
788
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
789
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
754 790
 		}
755
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
756
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
757 791
 	}
758 792
 
759 793
 	$temp = build_query_board($user_info['id']);
@@ -816,9 +850,9 @@  discard block
 block discarded – undo
816 850
 		}
817 851
 
818 852
 		// Remember redirection is the key to avoiding fallout from your bosses.
819
-		if (!empty($topic))
820
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
821
-		else
853
+		if (!empty($topic)) {
854
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
855
+		} else
822 856
 		{
823 857
 			loadPermissions();
824 858
 			loadTheme();
@@ -836,10 +870,11 @@  discard block
 block discarded – undo
836 870
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
837 871
 	{
838 872
 		// @todo SLOW?
839
-		if (!empty($topic))
840
-			$temp = cache_get_data('topic_board-' . $topic, 120);
841
-		else
842
-			$temp = cache_get_data('board-' . $board, 120);
873
+		if (!empty($topic)) {
874
+					$temp = cache_get_data('topic_board-' . $topic, 120);
875
+		} else {
876
+					$temp = cache_get_data('board-' . $board, 120);
877
+		}
843 878
 
844 879
 		if (!empty($temp))
845 880
 		{
@@ -877,8 +912,9 @@  discard block
 block discarded – undo
877 912
 			$row = $smcFunc['db_fetch_assoc']($request);
878 913
 
879 914
 			// Set the current board.
880
-			if (!empty($row['id_board']))
881
-				$board = $row['id_board'];
915
+			if (!empty($row['id_board'])) {
916
+							$board = $row['id_board'];
917
+			}
882 918
 
883 919
 			// Basic operating information. (globals... :/)
884 920
 			$board_info = array(
@@ -914,21 +950,23 @@  discard block
 block discarded – undo
914 950
 
915 951
 			do
916 952
 			{
917
-				if (!empty($row['id_moderator']))
918
-					$board_info['moderators'][$row['id_moderator']] = array(
953
+				if (!empty($row['id_moderator'])) {
954
+									$board_info['moderators'][$row['id_moderator']] = array(
919 955
 						'id' => $row['id_moderator'],
920 956
 						'name' => $row['real_name'],
921 957
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
922 958
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
923 959
 					);
960
+				}
924 961
 
925
-				if (!empty($row['id_moderator_group']))
926
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
962
+				if (!empty($row['id_moderator_group'])) {
963
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
927 964
 						'id' => $row['id_moderator_group'],
928 965
 						'name' => $row['group_name'],
929 966
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
930 967
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
931 968
 					);
969
+				}
932 970
 			}
933 971
 			while ($row = $smcFunc['db_fetch_assoc']($request));
934 972
 
@@ -960,12 +998,12 @@  discard block
 block discarded – undo
960 998
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
961 999
 			{
962 1000
 				// @todo SLOW?
963
-				if (!empty($topic))
964
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1001
+				if (!empty($topic)) {
1002
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1003
+				}
965 1004
 				cache_put_data('board-' . $board, $board_info, 120);
966 1005
 			}
967
-		}
968
-		else
1006
+		} else
969 1007
 		{
970 1008
 			// Otherwise the topic is invalid, there are no moderators, etc.
971 1009
 			$board_info = array(
@@ -979,8 +1017,9 @@  discard block
 block discarded – undo
979 1017
 		$smcFunc['db_free_result']($request);
980 1018
 	}
981 1019
 
982
-	if (!empty($topic))
983
-		$_GET['board'] = (int) $board;
1020
+	if (!empty($topic)) {
1021
+			$_GET['board'] = (int) $board;
1022
+	}
984 1023
 
985 1024
 	if (!empty($board))
986 1025
 	{
@@ -990,10 +1029,12 @@  discard block
 block discarded – undo
990 1029
 		// Now check if the user is a moderator.
991 1030
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
992 1031
 
993
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
995
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
996
-			$board_info['error'] = 'access';
1032
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1033
+					$board_info['error'] = 'access';
1034
+		}
1035
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1036
+					$board_info['error'] = 'access';
1037
+		}
997 1038
 
998 1039
 		// Build up the linktree.
999 1040
 		$context['linktree'] = array_merge(
@@ -1016,8 +1057,9 @@  discard block
 block discarded – undo
1016 1057
 	$context['current_board'] = $board;
1017 1058
 
1018 1059
 	// No posting in redirection boards!
1019
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1020
-		$board_info['error'] == 'post_in_redirect';
1060
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1061
+			$board_info['error'] == 'post_in_redirect';
1062
+	}
1021 1063
 
1022 1064
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1023 1065
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1043,24 +1085,23 @@  discard block
 block discarded – undo
1043 1085
 			ob_end_clean();
1044 1086
 			header('HTTP/1.1 403 Forbidden');
1045 1087
 			die;
1046
-		}
1047
-		elseif ($board_info['error'] == 'post_in_redirect')
1088
+		} elseif ($board_info['error'] == 'post_in_redirect')
1048 1089
 		{
1049 1090
 			// Slightly different error message here...
1050 1091
 			fatal_lang_error('cannot_post_redirect', false);
1051
-		}
1052
-		elseif ($user_info['is_guest'])
1092
+		} elseif ($user_info['is_guest'])
1053 1093
 		{
1054 1094
 			loadLanguage('Errors');
1055 1095
 			is_not_guest($txt['topic_gone']);
1096
+		} else {
1097
+					fatal_lang_error('topic_gone', false);
1056 1098
 		}
1057
-		else
1058
-			fatal_lang_error('topic_gone', false);
1059 1099
 	}
1060 1100
 
1061
-	if ($user_info['is_mod'])
1062
-		$user_info['groups'][] = 3;
1063
-}
1101
+	if ($user_info['is_mod']) {
1102
+			$user_info['groups'][] = 3;
1103
+	}
1104
+	}
1064 1105
 
1065 1106
 /**
1066 1107
  * Load this user's permissions.
@@ -1081,8 +1122,9 @@  discard block
 block discarded – undo
1081 1122
 		asort($cache_groups);
1082 1123
 		$cache_groups = implode(',', $cache_groups);
1083 1124
 		// If it's a spider then cache it different.
1084
-		if ($user_info['possibly_robot'])
1085
-			$cache_groups .= '-spider';
1125
+		if ($user_info['possibly_robot']) {
1126
+					$cache_groups .= '-spider';
1127
+		}
1086 1128
 
1087 1129
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1088 1130
 		{
@@ -1090,9 +1132,9 @@  discard block
 block discarded – undo
1090 1132
 			banPermissions();
1091 1133
 
1092 1134
 			return;
1135
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1136
+					list ($user_info['permissions'], $removals) = $temp;
1093 1137
 		}
1094
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1095
-			list ($user_info['permissions'], $removals) = $temp;
1096 1138
 	}
1097 1139
 
1098 1140
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1114,23 +1156,26 @@  discard block
 block discarded – undo
1114 1156
 		$removals = array();
1115 1157
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1116 1158
 		{
1117
-			if (empty($row['add_deny']))
1118
-				$removals[] = $row['permission'];
1119
-			else
1120
-				$user_info['permissions'][] = $row['permission'];
1159
+			if (empty($row['add_deny'])) {
1160
+							$removals[] = $row['permission'];
1161
+			} else {
1162
+							$user_info['permissions'][] = $row['permission'];
1163
+			}
1121 1164
 		}
1122 1165
 		$smcFunc['db_free_result']($request);
1123 1166
 
1124
-		if (isset($cache_groups))
1125
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1167
+		if (isset($cache_groups)) {
1168
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1169
+		}
1126 1170
 	}
1127 1171
 
1128 1172
 	// Get the board permissions.
1129 1173
 	if (!empty($board))
1130 1174
 	{
1131 1175
 		// Make sure the board (if any) has been loaded by loadBoard().
1132
-		if (!isset($board_info['profile']))
1133
-			fatal_lang_error('no_board');
1176
+		if (!isset($board_info['profile'])) {
1177
+					fatal_lang_error('no_board');
1178
+		}
1134 1179
 
1135 1180
 		$request = $smcFunc['db_query']('', '
1136 1181
 			SELECT permission, add_deny
@@ -1146,20 +1191,23 @@  discard block
 block discarded – undo
1146 1191
 		);
1147 1192
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1148 1193
 		{
1149
-			if (empty($row['add_deny']))
1150
-				$removals[] = $row['permission'];
1151
-			else
1152
-				$user_info['permissions'][] = $row['permission'];
1194
+			if (empty($row['add_deny'])) {
1195
+							$removals[] = $row['permission'];
1196
+			} else {
1197
+							$user_info['permissions'][] = $row['permission'];
1198
+			}
1153 1199
 		}
1154 1200
 		$smcFunc['db_free_result']($request);
1155 1201
 	}
1156 1202
 
1157 1203
 	// Remove all the permissions they shouldn't have ;).
1158
-	if (!empty($modSettings['permission_enable_deny']))
1159
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1204
+	if (!empty($modSettings['permission_enable_deny'])) {
1205
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1206
+	}
1160 1207
 
1161
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1162
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1208
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1209
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1210
+	}
1163 1211
 
1164 1212
 	// Banned?  Watch, don't touch..
1165 1213
 	banPermissions();
@@ -1171,17 +1219,18 @@  discard block
 block discarded – undo
1171 1219
 		{
1172 1220
 			require_once($sourcedir . '/Subs-Auth.php');
1173 1221
 			rebuildModCache();
1222
+		} else {
1223
+					$user_info['mod_cache'] = $_SESSION['mc'];
1174 1224
 		}
1175
-		else
1176
-			$user_info['mod_cache'] = $_SESSION['mc'];
1177 1225
 
1178 1226
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1179 1227
 		// For example this drastically simplifies certain changes to the profile area.
1180 1228
 		$user_info['permissions'][] = 'is_not_guest';
1181 1229
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1182 1230
 		$user_info['permissions'][] = 'profile_view_own';
1183
-		if (in_array('profile_view', $user_info['permissions']))
1184
-			$user_info['permissions'][] = 'profile_view_any';
1231
+		if (in_array('profile_view', $user_info['permissions'])) {
1232
+					$user_info['permissions'][] = 'profile_view_any';
1233
+		}
1185 1234
 	}
1186 1235
 }
1187 1236
 
@@ -1199,8 +1248,9 @@  discard block
 block discarded – undo
1199 1248
 	global $image_proxy_enabled, $user_info;
1200 1249
 
1201 1250
 	// Can't just look for no users :P.
1202
-	if (empty($users))
1203
-		return array();
1251
+	if (empty($users)) {
1252
+			return array();
1253
+	}
1204 1254
 
1205 1255
 	// Pass the set value
1206 1256
 	$context['loadMemberContext_set'] = $set;
@@ -1215,8 +1265,9 @@  discard block
 block discarded – undo
1215 1265
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1216 1266
 		{
1217 1267
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1218
-			if ($data == null)
1219
-				continue;
1268
+			if ($data == null) {
1269
+							continue;
1270
+			}
1220 1271
 
1221 1272
 			$loaded_ids[] = $data['id_member'];
1222 1273
 			$user_profile[$data['id_member']] = $data;
@@ -1283,16 +1334,19 @@  discard block
 block discarded – undo
1283 1334
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1284 1335
 
1285 1336
 			// Take care of proxying avatar if required, do this here for maximum reach
1286
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1287
-				$row['avatar'] = get_proxied_url($row['avatar']);
1337
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1338
+							$row['avatar'] = get_proxied_url($row['avatar']);
1339
+			}
1288 1340
 
1289 1341
 			// Keep track of the member's normal member group
1290 1342
 			$row['primary_group'] = !empty($row['member_group']) ? $row['member_group'] : '';
1291 1343
 
1292
-			if (isset($row['member_ip']))
1293
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1294
-			if (isset($row['member_ip2']))
1295
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1344
+			if (isset($row['member_ip'])) {
1345
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1346
+			}
1347
+			if (isset($row['member_ip2'])) {
1348
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1349
+			}
1296 1350
 			$new_loaded_ids[] = $row['id_member'];
1297 1351
 			$loaded_ids[] = $row['id_member'];
1298 1352
 			$row['options'] = array();
@@ -1311,8 +1365,9 @@  discard block
 block discarded – undo
1311 1365
 				'loaded_ids' => $new_loaded_ids,
1312 1366
 			)
1313 1367
 		);
1314
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1315
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1368
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1369
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1370
+		}
1316 1371
 		$smcFunc['db_free_result']($request);
1317 1372
 	}
1318 1373
 
@@ -1323,10 +1378,11 @@  discard block
 block discarded – undo
1323 1378
 	{
1324 1379
 		foreach ($loaded_ids as $a_member)
1325 1380
 		{
1326
-			if (!empty($user_profile[$a_member]['additional_groups']))
1327
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1328
-			else
1329
-				$groups = array($user_profile[$a_member]['id_group']);
1381
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1382
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1383
+			} else {
1384
+							$groups = array($user_profile[$a_member]['id_group']);
1385
+			}
1330 1386
 
1331 1387
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1332 1388
 
@@ -1339,8 +1395,9 @@  discard block
 block discarded – undo
1339 1395
 
1340 1396
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1341 1397
 	{
1342
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1343
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1398
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1399
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1400
+		}
1344 1401
 	}
1345 1402
 
1346 1403
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1366,14 +1423,17 @@  discard block
 block discarded – undo
1366 1423
 		foreach ($temp_mods as $id)
1367 1424
 		{
1368 1425
 			// By popular demand, don't show admins or global moderators as moderators.
1369
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1370
-				$user_profile[$id]['member_group'] = $row['member_group'];
1426
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1427
+							$user_profile[$id]['member_group'] = $row['member_group'];
1428
+			}
1371 1429
 
1372 1430
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1373
-			if (!empty($row['icons']))
1374
-				$user_profile[$id]['icons'] = $row['icons'];
1375
-			if (!empty($row['member_group_color']))
1376
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1431
+			if (!empty($row['icons'])) {
1432
+							$user_profile[$id]['icons'] = $row['icons'];
1433
+			}
1434
+			if (!empty($row['member_group_color'])) {
1435
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1436
+			}
1377 1437
 		}
1378 1438
 	}
1379 1439
 
@@ -1395,12 +1455,14 @@  discard block
 block discarded – undo
1395 1455
 	static $loadedLanguages = array();
1396 1456
 
1397 1457
 	// If this person's data is already loaded, skip it.
1398
-	if (isset($dataLoaded[$user]))
1399
-		return true;
1458
+	if (isset($dataLoaded[$user])) {
1459
+			return true;
1460
+	}
1400 1461
 
1401 1462
 	// We can't load guests or members not loaded by loadMemberData()!
1402
-	if ($user == 0)
1403
-		return false;
1463
+	if ($user == 0) {
1464
+			return false;
1465
+	}
1404 1466
 	if (!isset($user_profile[$user]))
1405 1467
 	{
1406 1468
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1426,12 +1488,16 @@  discard block
 block discarded – undo
1426 1488
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1427 1489
 
1428 1490
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1429
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1491
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1492
+		//icon is set and exists
1430 1493
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1431
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1494
+	} elseif (isset($profile['icons'][1])) {
1495
+		//icon is set and doesn't exist, fallback to default
1432 1496
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1433
-	else //not set, bye bye
1497
+	} else {
1498
+		//not set, bye bye
1434 1499
 		$group_icon_url = '';
1500
+	}
1435 1501
 
1436 1502
 	// These minimal values are always loaded
1437 1503
 	$memberContext[$user] = array(
@@ -1450,8 +1516,9 @@  discard block
 block discarded – undo
1450 1516
 	if ($context['loadMemberContext_set'] != 'minimal')
1451 1517
 	{
1452 1518
 		// Go the extra mile and load the user's native language name.
1453
-		if (empty($loadedLanguages))
1454
-			$loadedLanguages = getLanguages();
1519
+		if (empty($loadedLanguages)) {
1520
+					$loadedLanguages = getLanguages();
1521
+		}
1455 1522
 
1456 1523
 		$memberContext[$user] += array(
1457 1524
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1506,31 +1573,33 @@  discard block
 block discarded – undo
1506 1573
 	{
1507 1574
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1508 1575
 		{
1509
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1510
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1511
-			else
1512
-				$image = get_gravatar_url($profile['email_address']);
1513
-		}
1514
-		else
1576
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1577
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1578
+			} else {
1579
+							$image = get_gravatar_url($profile['email_address']);
1580
+			}
1581
+		} else
1515 1582
 		{
1516 1583
 			// So it's stored in the member table?
1517 1584
 			if (!empty($profile['avatar']))
1518 1585
 			{
1519 1586
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1587
+			} elseif (!empty($profile['filename'])) {
1588
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1520 1589
 			}
1521
-			elseif (!empty($profile['filename']))
1522
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1523 1590
 			// Right... no avatar...use the default one
1524
-			else
1525
-				$image = $modSettings['avatar_url'] . '/default.png';
1591
+			else {
1592
+							$image = $modSettings['avatar_url'] . '/default.png';
1593
+			}
1526 1594
 		}
1527
-		if (!empty($image))
1528
-			$memberContext[$user]['avatar'] = array(
1595
+		if (!empty($image)) {
1596
+					$memberContext[$user]['avatar'] = array(
1529 1597
 				'name' => $profile['avatar'],
1530 1598
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1531 1599
 				'href' => $image,
1532 1600
 				'url' => $image,
1533 1601
 			);
1602
+		}
1534 1603
 	}
1535 1604
 
1536 1605
 	// Are we also loading the members custom fields into context?
@@ -1538,13 +1607,15 @@  discard block
 block discarded – undo
1538 1607
 	{
1539 1608
 		$memberContext[$user]['custom_fields'] = array();
1540 1609
 
1541
-		if (!isset($context['display_fields']))
1542
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1610
+		if (!isset($context['display_fields'])) {
1611
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1612
+		}
1543 1613
 
1544 1614
 		foreach ($context['display_fields'] as $custom)
1545 1615
 		{
1546
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1547
-				continue;
1616
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1617
+							continue;
1618
+			}
1548 1619
 
1549 1620
 			$value = $profile['options'][$custom['col_name']];
1550 1621
 
@@ -1552,31 +1623,36 @@  discard block
 block discarded – undo
1552 1623
 			$currentKey = 0;
1553 1624
 
1554 1625
 			// Create a key => value array for multiple options fields
1555
-			if (!empty($custom['options']))
1556
-				foreach ($custom['options'] as $k => $v)
1626
+			if (!empty($custom['options'])) {
1627
+							foreach ($custom['options'] as $k => $v)
1557 1628
 				{
1558 1629
 					$fieldOptions[] = $v;
1559
-					if (empty($currentKey))
1560
-						$currentKey = $v == $value ? $k : 0;
1630
+			}
1631
+					if (empty($currentKey)) {
1632
+											$currentKey = $v == $value ? $k : 0;
1633
+					}
1561 1634
 				}
1562 1635
 
1563 1636
 			// BBC?
1564
-			if ($custom['bbc'])
1565
-				$value = parse_bbc($value);
1637
+			if ($custom['bbc']) {
1638
+							$value = parse_bbc($value);
1639
+			}
1566 1640
 
1567 1641
 			// ... or checkbox?
1568
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1569
-				$value = $value ? $txt['yes'] : $txt['no'];
1642
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1643
+							$value = $value ? $txt['yes'] : $txt['no'];
1644
+			}
1570 1645
 
1571 1646
 			// Enclosing the user input within some other text?
1572
-			if (!empty($custom['enclose']))
1573
-				$value = strtr($custom['enclose'], array(
1647
+			if (!empty($custom['enclose'])) {
1648
+							$value = strtr($custom['enclose'], array(
1574 1649
 					'{SCRIPTURL}' => $scripturl,
1575 1650
 					'{IMAGES_URL}' => $settings['images_url'],
1576 1651
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1577 1652
 					'{INPUT}' => $value,
1578 1653
 					'{KEY}' => $currentKey,
1579 1654
 				));
1655
+			}
1580 1656
 
1581 1657
 			$memberContext[$user]['custom_fields'][] = array(
1582 1658
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1603,8 +1679,9 @@  discard block
 block discarded – undo
1603 1679
 	global $smcFunc, $txt, $scripturl, $settings;
1604 1680
 
1605 1681
 	// Do not waste my time...
1606
-	if (empty($users) || empty($params))
1607
-		return false;
1682
+	if (empty($users) || empty($params)) {
1683
+			return false;
1684
+	}
1608 1685
 
1609 1686
 	// Make sure it's an array.
1610 1687
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1631,41 +1708,48 @@  discard block
 block discarded – undo
1631 1708
 		$currentKey = 0;
1632 1709
 
1633 1710
 		// Create a key => value array for multiple options fields
1634
-		if (!empty($row['field_options']))
1635
-			foreach (explode(',', $row['field_options']) as $k => $v)
1711
+		if (!empty($row['field_options'])) {
1712
+					foreach (explode(',', $row['field_options']) as $k => $v)
1636 1713
 			{
1637 1714
 				$fieldOptions[] = $v;
1638
-				if (empty($currentKey))
1639
-					$currentKey = $v == $row['value'] ? $k : 0;
1715
+		}
1716
+				if (empty($currentKey)) {
1717
+									$currentKey = $v == $row['value'] ? $k : 0;
1718
+				}
1640 1719
 			}
1641 1720
 
1642 1721
 		// BBC?
1643
-		if (!empty($row['bbc']))
1644
-			$row['value'] = parse_bbc($row['value']);
1722
+		if (!empty($row['bbc'])) {
1723
+					$row['value'] = parse_bbc($row['value']);
1724
+		}
1645 1725
 
1646 1726
 		// ... or checkbox?
1647
-		elseif (isset($row['type']) && $row['type'] == 'check')
1648
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1727
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1728
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1729
+		}
1649 1730
 
1650 1731
 		// Enclosing the user input within some other text?
1651
-		if (!empty($row['enclose']))
1652
-			$row['value'] = strtr($row['enclose'], array(
1732
+		if (!empty($row['enclose'])) {
1733
+					$row['value'] = strtr($row['enclose'], array(
1653 1734
 				'{SCRIPTURL}' => $scripturl,
1654 1735
 				'{IMAGES_URL}' => $settings['images_url'],
1655 1736
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1656 1737
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1657 1738
 				'{KEY}' => $currentKey,
1658 1739
 			));
1740
+		}
1659 1741
 
1660 1742
 		// Send a simple array if there is just 1 param
1661
-		if (count($params) == 1)
1662
-			$return[$row['id_member']] = $row;
1743
+		if (count($params) == 1) {
1744
+					$return[$row['id_member']] = $row;
1745
+		}
1663 1746
 
1664 1747
 		// More than 1? knock yourself out...
1665 1748
 		else
1666 1749
 		{
1667
-			if (!isset($return[$row['id_member']]))
1668
-				$return[$row['id_member']] = array();
1750
+			if (!isset($return[$row['id_member']])) {
1751
+							$return[$row['id_member']] = array();
1752
+			}
1669 1753
 
1670 1754
 			$return[$row['id_member']][$row['variable']] = $row;
1671 1755
 		}
@@ -1699,8 +1783,9 @@  discard block
 block discarded – undo
1699 1783
 	global $context;
1700 1784
 
1701 1785
 	// Don't know any browser!
1702
-	if (empty($context['browser']))
1703
-		detectBrowser();
1786
+	if (empty($context['browser'])) {
1787
+			detectBrowser();
1788
+	}
1704 1789
 
1705 1790
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1706 1791
 }
@@ -1718,8 +1803,9 @@  discard block
 block discarded – undo
1718 1803
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1719 1804
 
1720 1805
 	// The theme was specified by parameter.
1721
-	if (!empty($id_theme))
1722
-		$id_theme = (int) $id_theme;
1806
+	if (!empty($id_theme)) {
1807
+			$id_theme = (int) $id_theme;
1808
+	}
1723 1809
 	// The theme was specified by REQUEST.
1724 1810
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1725 1811
 	{
@@ -1727,32 +1813,38 @@  discard block
 block discarded – undo
1727 1813
 		$_SESSION['id_theme'] = $id_theme;
1728 1814
 	}
1729 1815
 	// The theme was specified by REQUEST... previously.
1730
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1731
-		$id_theme = (int) $_SESSION['id_theme'];
1816
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1817
+			$id_theme = (int) $_SESSION['id_theme'];
1818
+	}
1732 1819
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1733
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1734
-		$id_theme = $user_info['theme'];
1820
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1821
+			$id_theme = $user_info['theme'];
1822
+	}
1735 1823
 	// The theme was specified by the board.
1736
-	elseif (!empty($board_info['theme']))
1737
-		$id_theme = $board_info['theme'];
1824
+	elseif (!empty($board_info['theme'])) {
1825
+			$id_theme = $board_info['theme'];
1826
+	}
1738 1827
 	// The theme is the forum's default.
1739
-	else
1740
-		$id_theme = $modSettings['theme_guests'];
1828
+	else {
1829
+			$id_theme = $modSettings['theme_guests'];
1830
+	}
1741 1831
 
1742 1832
 	// Verify the id_theme... no foul play.
1743 1833
 	// Always allow the board specific theme, if they are overriding.
1744
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1745
-		$id_theme = $board_info['theme'];
1834
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1835
+			$id_theme = $board_info['theme'];
1836
+	}
1746 1837
 	// If they have specified a particular theme to use with SSI allow it to be used.
1747
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1748
-		$id_theme = (int) $id_theme;
1749
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1838
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1839
+			$id_theme = (int) $id_theme;
1840
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1750 1841
 	{
1751 1842
 		$themes = explode(',', $modSettings['enableThemes']);
1752
-		if (!in_array($id_theme, $themes))
1753
-			$id_theme = $modSettings['theme_guests'];
1754
-		else
1755
-			$id_theme = (int) $id_theme;
1843
+		if (!in_array($id_theme, $themes)) {
1844
+					$id_theme = $modSettings['theme_guests'];
1845
+		} else {
1846
+					$id_theme = (int) $id_theme;
1847
+		}
1756 1848
 	}
1757 1849
 		
1758 1850
 	// We already load the basic stuff?
@@ -1761,18 +1853,19 @@  discard block
 block discarded – undo
1761 1853
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1762 1854
 
1763 1855
 		// Disable image proxy if we don't have SSL enabled
1764
-		if (empty($modSettings['force_ssl']))
1765
-			$image_proxy_enabled = false;
1856
+		if (empty($modSettings['force_ssl'])) {
1857
+					$image_proxy_enabled = false;
1858
+		}
1766 1859
 
1767 1860
 		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'])
1768 1861
 		{
1769 1862
 			$themeData = $temp;
1770 1863
 			$flag = true;
1864
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1865
+					$themeData = $temp + array($member => array());
1866
+		} else {
1867
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1771 1868
 		}
1772
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1773
-			$themeData = $temp + array($member => array());
1774
-		else
1775
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1776 1869
 
1777 1870
 		if (empty($flag))
1778 1871
 		{
@@ -1792,31 +1885,37 @@  discard block
 block discarded – undo
1792 1885
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1793 1886
 			{
1794 1887
 				// There are just things we shouldn't be able to change as members.
1795
-				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')))
1796
-					continue;
1888
+				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'))) {
1889
+									continue;
1890
+				}
1797 1891
 
1798 1892
 				// If this is the theme_dir of the default theme, store it.
1799
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1800
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1893
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1894
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1895
+				}
1801 1896
 
1802 1897
 				// If this isn't set yet, is a theme option, or is not the default theme..
1803
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1804
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1898
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1899
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1900
+				}
1805 1901
 			}
1806 1902
 			$smcFunc['db_free_result']($result);
1807 1903
 
1808
-			if (!empty($themeData[-1]))
1809
-				foreach ($themeData[-1] as $k => $v)
1904
+			if (!empty($themeData[-1])) {
1905
+							foreach ($themeData[-1] as $k => $v)
1810 1906
 				{
1811 1907
 					if (!isset($themeData[$member][$k]))
1812 1908
 						$themeData[$member][$k] = $v;
1909
+			}
1813 1910
 				}
1814 1911
 
1815
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1816
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1912
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1913
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1914
+			}
1817 1915
 			// Only if we didn't already load that part of the cache...
1818
-			elseif (!isset($temp))
1819
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1916
+			elseif (!isset($temp)) {
1917
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1918
+			}
1820 1919
 		}
1821 1920
 
1822 1921
 		$settings = $themeData[0];
@@ -1833,17 +1932,20 @@  discard block
 block discarded – undo
1833 1932
 		$settings['template_dirs'][] = $settings['theme_dir'];
1834 1933
 
1835 1934
 		// Based on theme (if there is one).
1836
-		if (!empty($settings['base_theme_dir']))
1837
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1935
+		if (!empty($settings['base_theme_dir'])) {
1936
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1937
+		}
1838 1938
 
1839 1939
 		// Lastly the default theme.
1840
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1841
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1940
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1941
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1942
+		}
1842 1943
 	}
1843 1944
 
1844 1945
 
1845
-	if (!$initialize)
1846
-		return;
1946
+	if (!$initialize) {
1947
+			return;
1948
+	}
1847 1949
 
1848 1950
 	// Check to see if we're forcing SSL
1849 1951
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1864,8 +1966,9 @@  discard block
 block discarded – undo
1864 1966
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1865 1967
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1866 1968
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1867
-		if ($temp != '/')
1868
-			$detected_url .= $temp;
1969
+		if ($temp != '/') {
1970
+					$detected_url .= $temp;
1971
+		}
1869 1972
 	}
1870 1973
 	if (isset($detected_url) && $detected_url != $boardurl)
1871 1974
 	{
@@ -1877,8 +1980,9 @@  discard block
 block discarded – undo
1877 1980
 			foreach ($aliases as $alias)
1878 1981
 			{
1879 1982
 				// Rip off all the boring parts, spaces, etc.
1880
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1881
-					$do_fix = true;
1983
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1984
+									$do_fix = true;
1985
+				}
1882 1986
 			}
1883 1987
 		}
1884 1988
 
@@ -1886,21 +1990,23 @@  discard block
 block discarded – undo
1886 1990
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1887 1991
 		{
1888 1992
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1889
-			if (empty($_GET))
1890
-				redirectexit('wwwRedirect');
1891
-			else
1993
+			if (empty($_GET)) {
1994
+							redirectexit('wwwRedirect');
1995
+			} else
1892 1996
 			{
1893 1997
 				$k = key($_GET);
1894 1998
 				$v = current($_GET);
1895 1999
 
1896
-				if ($k != 'wwwRedirect')
1897
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
2000
+				if ($k != 'wwwRedirect') {
2001
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
2002
+				}
1898 2003
 			}
1899 2004
 		}
1900 2005
 
1901 2006
 		// #3 is just a check for SSL...
1902
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1903
-			$do_fix = true;
2007
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
2008
+					$do_fix = true;
2009
+		}
1904 2010
 
1905 2011
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1906 2012
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1935,8 +2041,9 @@  discard block
 block discarded – undo
1935 2041
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1936 2042
 				}
1937 2043
 			}
1938
-			foreach ($context['linktree'] as $k => $dummy)
1939
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2044
+			foreach ($context['linktree'] as $k => $dummy) {
2045
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2046
+			}
1940 2047
 		}
1941 2048
 	}
1942 2049
 	// Set up the contextual user array.
@@ -1955,16 +2062,16 @@  discard block
 block discarded – undo
1955 2062
 			'email' => $user_info['email'],
1956 2063
 			'ignoreusers' => $user_info['ignoreusers'],
1957 2064
 		);
1958
-		if (!$context['user']['is_guest'])
1959
-			$context['user']['name'] = $user_info['name'];
1960
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1961
-			$context['user']['name'] = $txt['guest_title'];
2065
+		if (!$context['user']['is_guest']) {
2066
+					$context['user']['name'] = $user_info['name'];
2067
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2068
+					$context['user']['name'] = $txt['guest_title'];
2069
+		}
1962 2070
 
1963 2071
 		// Determine the current smiley set.
1964 2072
 		$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'];
1965 2073
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1966
-	}
1967
-	else
2074
+	} else
1968 2075
 	{
1969 2076
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1970 2077
 		$context['user'] = array(
@@ -1998,18 +2105,24 @@  discard block
 block discarded – undo
1998 2105
 	}
1999 2106
 
2000 2107
 	// Some basic information...
2001
-	if (!isset($context['html_headers']))
2002
-		$context['html_headers'] = '';
2003
-	if (!isset($context['javascript_files']))
2004
-		$context['javascript_files'] = array();
2005
-	if (!isset($context['css_files']))
2006
-		$context['css_files'] = array();
2007
-	if (!isset($context['css_header']))
2008
-		$context['css_header'] = array();
2009
-	if (!isset($context['javascript_inline']))
2010
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2011
-	if (!isset($context['javascript_vars']))
2012
-		$context['javascript_vars'] = array();
2108
+	if (!isset($context['html_headers'])) {
2109
+			$context['html_headers'] = '';
2110
+	}
2111
+	if (!isset($context['javascript_files'])) {
2112
+			$context['javascript_files'] = array();
2113
+	}
2114
+	if (!isset($context['css_files'])) {
2115
+			$context['css_files'] = array();
2116
+	}
2117
+	if (!isset($context['css_header'])) {
2118
+			$context['css_header'] = array();
2119
+	}
2120
+	if (!isset($context['javascript_inline'])) {
2121
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2122
+	}
2123
+	if (!isset($context['javascript_vars'])) {
2124
+			$context['javascript_vars'] = array();
2125
+	}
2013 2126
 
2014 2127
 	$context['login_url'] =  $scripturl . '?action=login2';
2015 2128
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2021,16 +2134,18 @@  discard block
 block discarded – undo
2021 2134
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2022 2135
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2023 2136
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2024
-	if (isset($modSettings['load_average']))
2025
-		$context['load_average'] = $modSettings['load_average'];
2137
+	if (isset($modSettings['load_average'])) {
2138
+			$context['load_average'] = $modSettings['load_average'];
2139
+	}
2026 2140
 
2027 2141
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2028 2142
 	detectBrowser();
2029 2143
 
2030 2144
 	// Set the top level linktree up.
2031 2145
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2032
-	if (empty($context['linktree']))
2033
-		$context['linktree'] = array();
2146
+	if (empty($context['linktree'])) {
2147
+			$context['linktree'] = array();
2148
+	}
2034 2149
 	array_unshift($context['linktree'], array(
2035 2150
 		'url' => $scripturl,
2036 2151
 		'name' => $context['forum_name_html_safe']
@@ -2039,8 +2154,9 @@  discard block
 block discarded – undo
2039 2154
 	// This allows sticking some HTML on the page output - useful for controls.
2040 2155
 	$context['insert_after_template'] = '';
2041 2156
 
2042
-	if (!isset($txt))
2043
-		$txt = array();
2157
+	if (!isset($txt)) {
2158
+			$txt = array();
2159
+	}
2044 2160
 
2045 2161
 	$simpleActions = array(
2046 2162
 		'findmember',
@@ -2086,9 +2202,10 @@  discard block
 block discarded – undo
2086 2202
 
2087 2203
 	// See if theres any extra param to check.
2088 2204
 	$requiresXML = false;
2089
-	foreach ($extraParams as $key => $extra)
2090
-		if (isset($_REQUEST[$extra]))
2205
+	foreach ($extraParams as $key => $extra) {
2206
+			if (isset($_REQUEST[$extra]))
2091 2207
 			$requiresXML = true;
2208
+	}
2092 2209
 
2093 2210
 	// Output is fully XML, so no need for the index template.
2094 2211
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2103,37 +2220,39 @@  discard block
 block discarded – undo
2103 2220
 	{
2104 2221
 		loadLanguage('index+Modifications');
2105 2222
 		$context['template_layers'] = array();
2106
-	}
2107
-
2108
-	else
2223
+	} else
2109 2224
 	{
2110 2225
 		// Custom templates to load, or just default?
2111
-		if (isset($settings['theme_templates']))
2112
-			$templates = explode(',', $settings['theme_templates']);
2113
-		else
2114
-			$templates = array('index');
2226
+		if (isset($settings['theme_templates'])) {
2227
+					$templates = explode(',', $settings['theme_templates']);
2228
+		} else {
2229
+					$templates = array('index');
2230
+		}
2115 2231
 
2116 2232
 		// Load each template...
2117
-		foreach ($templates as $template)
2118
-			loadTemplate($template);
2233
+		foreach ($templates as $template) {
2234
+					loadTemplate($template);
2235
+		}
2119 2236
 
2120 2237
 		// ...and attempt to load their associated language files.
2121 2238
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2122 2239
 		loadLanguage($required_files, '', false);
2123 2240
 
2124 2241
 		// Custom template layers?
2125
-		if (isset($settings['theme_layers']))
2126
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2127
-		else
2128
-			$context['template_layers'] = array('html', 'body');
2242
+		if (isset($settings['theme_layers'])) {
2243
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2244
+		} else {
2245
+					$context['template_layers'] = array('html', 'body');
2246
+		}
2129 2247
 	}
2130 2248
 
2131 2249
 	// Initialize the theme.
2132 2250
 	loadSubTemplate('init', 'ignore');
2133 2251
 
2134 2252
 	// Allow overriding the board wide time/number formats.
2135
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2136
-		$user_info['time_format'] = $txt['time_format'];
2253
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2254
+			$user_info['time_format'] = $txt['time_format'];
2255
+	}
2137 2256
 
2138 2257
 	// Set the character set from the template.
2139 2258
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2141,12 +2260,14 @@  discard block
 block discarded – undo
2141 2260
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2142 2261
 
2143 2262
 	// Guests may still need a name.
2144
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2145
-		$context['user']['name'] = $txt['guest_title'];
2263
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2264
+			$context['user']['name'] = $txt['guest_title'];
2265
+	}
2146 2266
 
2147 2267
 	// Any theme-related strings that need to be loaded?
2148
-	if (!empty($settings['require_theme_strings']))
2149
-		loadLanguage('ThemeStrings', '', false);
2268
+	if (!empty($settings['require_theme_strings'])) {
2269
+			loadLanguage('ThemeStrings', '', false);
2270
+	}
2150 2271
 
2151 2272
 	// Make a special URL for the language.
2152 2273
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2157,8 +2278,9 @@  discard block
 block discarded – undo
2157 2278
 	// Here is my luvly Responsive CSS
2158 2279
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2159 2280
 
2160
-	if ($context['right_to_left'])
2161
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2281
+	if ($context['right_to_left']) {
2282
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2283
+	}
2162 2284
 
2163 2285
 	// We allow theme variants, because we're cool.
2164 2286
 	$context['theme_variant'] = '';
@@ -2166,14 +2288,17 @@  discard block
 block discarded – undo
2166 2288
 	if (!empty($settings['theme_variants']))
2167 2289
 	{
2168 2290
 		// Overriding - for previews and that ilk.
2169
-		if (!empty($_REQUEST['variant']))
2170
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2291
+		if (!empty($_REQUEST['variant'])) {
2292
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2293
+		}
2171 2294
 		// User selection?
2172
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2173
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2295
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2296
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2297
+		}
2174 2298
 		// If not a user variant, select the default.
2175
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2176
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2299
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2300
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2301
+		}
2177 2302
 
2178 2303
 		// Do this to keep things easier in the templates.
2179 2304
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2182,20 +2307,23 @@  discard block
 block discarded – undo
2182 2307
 		if (!empty($context['theme_variant']))
2183 2308
 		{
2184 2309
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2185
-			if ($context['right_to_left'])
2186
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2310
+			if ($context['right_to_left']) {
2311
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2312
+			}
2187 2313
 		}
2188 2314
 	}
2189 2315
 
2190 2316
 	// Let's be compatible with old themes!
2191
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2192
-		$context['template_layers'] = array('main');
2317
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2318
+			$context['template_layers'] = array('main');
2319
+	}
2193 2320
 
2194 2321
 	$context['tabindex'] = 1;
2195 2322
 
2196 2323
 	// Compatibility.
2197
-	if (!isset($settings['theme_version']))
2198
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2324
+	if (!isset($settings['theme_version'])) {
2325
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2326
+	}
2199 2327
 
2200 2328
 	// Default JS variables for use in every theme
2201 2329
 	$context['javascript_vars'] = array(
@@ -2215,18 +2343,18 @@  discard block
 block discarded – undo
2215 2343
 	);
2216 2344
 
2217 2345
 	// Add the JQuery library to the list of files to load.
2218
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2219
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2220
-
2221
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2222
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2223
-
2224
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2225
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2346
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2347
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2348
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2349
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2350
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2351
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2352
+	}
2226 2353
 
2227 2354
 	// Auto loading? template_javascript() will take care of the local half of this.
2228
-	else
2229
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2355
+	else {
2356
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2357
+	}
2230 2358
 
2231 2359
 	// Queue our JQuery plugins!
2232 2360
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2249,12 +2377,12 @@  discard block
 block discarded – undo
2249 2377
 			require_once($sourcedir . '/ScheduledTasks.php');
2250 2378
 
2251 2379
 			// What to do, what to do?!
2252
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2253
-				AutoTask();
2254
-			else
2255
-				ReduceMailQueue();
2256
-		}
2257
-		else
2380
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2381
+							AutoTask();
2382
+			} else {
2383
+							ReduceMailQueue();
2384
+			}
2385
+		} else
2258 2386
 		{
2259 2387
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2260 2388
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2305,8 +2433,9 @@  discard block
 block discarded – undo
2305 2433
 		foreach ($theme_includes as $include)
2306 2434
 		{
2307 2435
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2308
-			if (file_exists($include))
2309
-				require_once($include);
2436
+			if (file_exists($include)) {
2437
+							require_once($include);
2438
+			}
2310 2439
 		}
2311 2440
 	}
2312 2441
 
@@ -2336,16 +2465,19 @@  discard block
 block discarded – undo
2336 2465
 	// Do any style sheets first, cause we're easy with those.
2337 2466
 	if (!empty($style_sheets))
2338 2467
 	{
2339
-		if (!is_array($style_sheets))
2340
-			$style_sheets = array($style_sheets);
2468
+		if (!is_array($style_sheets)) {
2469
+					$style_sheets = array($style_sheets);
2470
+		}
2341 2471
 
2342
-		foreach ($style_sheets as $sheet)
2343
-			loadCSSFile($sheet . '.css', array(), $sheet);
2472
+		foreach ($style_sheets as $sheet) {
2473
+					loadCSSFile($sheet . '.css', array(), $sheet);
2474
+		}
2344 2475
 	}
2345 2476
 
2346 2477
 	// No template to load?
2347
-	if ($template_name === false)
2348
-		return true;
2478
+	if ($template_name === false) {
2479
+			return true;
2480
+	}
2349 2481
 
2350 2482
 	$loaded = false;
2351 2483
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2360,12 +2492,14 @@  discard block
 block discarded – undo
2360 2492
 
2361 2493
 	if ($loaded)
2362 2494
 	{
2363
-		if ($db_show_debug === true)
2364
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2495
+		if ($db_show_debug === true) {
2496
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2497
+		}
2365 2498
 
2366 2499
 		// If they have specified an initialization function for this template, go ahead and call it now.
2367
-		if (function_exists('template_' . $template_name . '_init'))
2368
-			call_user_func('template_' . $template_name . '_init');
2500
+		if (function_exists('template_' . $template_name . '_init')) {
2501
+					call_user_func('template_' . $template_name . '_init');
2502
+		}
2369 2503
 	}
2370 2504
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2371 2505
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2385,13 +2519,14 @@  discard block
 block discarded – undo
2385 2519
 		loadTemplate($template_name);
2386 2520
 	}
2387 2521
 	// Cause an error otherwise.
2388
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2389
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2390
-	elseif ($fatal)
2391
-		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'));
2392
-	else
2393
-		return false;
2394
-}
2522
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2523
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2524
+	} elseif ($fatal) {
2525
+			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'));
2526
+	} else {
2527
+			return false;
2528
+	}
2529
+	}
2395 2530
 
2396 2531
 /**
2397 2532
  * Load a sub-template.
@@ -2409,17 +2544,19 @@  discard block
 block discarded – undo
2409 2544
 {
2410 2545
 	global $context, $txt, $db_show_debug;
2411 2546
 
2412
-	if ($db_show_debug === true)
2413
-		$context['debug']['sub_templates'][] = $sub_template_name;
2547
+	if ($db_show_debug === true) {
2548
+			$context['debug']['sub_templates'][] = $sub_template_name;
2549
+	}
2414 2550
 
2415 2551
 	// Figure out what the template function is named.
2416 2552
 	$theme_function = 'template_' . $sub_template_name;
2417
-	if (function_exists($theme_function))
2418
-		$theme_function();
2419
-	elseif ($fatal === false)
2420
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2421
-	elseif ($fatal !== 'ignore')
2422
-		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'));
2553
+	if (function_exists($theme_function)) {
2554
+			$theme_function();
2555
+	} elseif ($fatal === false) {
2556
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2557
+	} elseif ($fatal !== 'ignore') {
2558
+			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'));
2559
+	}
2423 2560
 
2424 2561
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2425 2562
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2449,8 +2586,9 @@  discard block
 block discarded – undo
2449 2586
 {
2450 2587
 	global $settings, $context, $modSettings;
2451 2588
 
2452
-	if (empty($context['css_files_order']))
2453
-		$context['css_files_order'] = array();
2589
+	if (empty($context['css_files_order'])) {
2590
+			$context['css_files_order'] = array();
2591
+	}
2454 2592
 
2455 2593
 	$params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
2456 2594
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2461,8 +2599,9 @@  discard block
 block discarded – undo
2461 2599
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2462 2600
 
2463 2601
 	// If this is an external file, automatically set this to false.
2464
-	if (!empty($params['external']))
2465
-		$params['minimize'] = false;
2602
+	if (!empty($params['external'])) {
2603
+			$params['minimize'] = false;
2604
+	}
2466 2605
 
2467 2606
 	// Account for shorthand like admin.css?alp21 filenames
2468 2607
 	$has_seed = strpos($fileName, '.css?');
@@ -2479,16 +2618,12 @@  discard block
 block discarded – undo
2479 2618
 			{
2480 2619
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2481 2620
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2482
-			}
2483
-
2484
-			else
2621
+			} else
2485 2622
 			{
2486 2623
 				$fileUrl = false;
2487 2624
 				$filePath = false;
2488 2625
 			}
2489
-		}
2490
-
2491
-		else
2626
+		} else
2492 2627
 		{
2493 2628
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2494 2629
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2506,16 +2641,18 @@  discard block
 block discarded – undo
2506 2641
 	if (!empty($fileName))
2507 2642
 	{
2508 2643
 		// find a free number/position
2509
-		while (isset($context['css_files_order'][$params['order_pos']]))
2510
-			$params['order_pos']++;
2644
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2645
+					$params['order_pos']++;
2646
+		}
2511 2647
 		$context['css_files_order'][$params['order_pos']] = $id;
2512 2648
 
2513 2649
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2514 2650
 	}
2515 2651
 
2516
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2517
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2518
-}
2652
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2653
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2654
+	}
2655
+	}
2519 2656
 
2520 2657
 /**
2521 2658
  * Add a block of inline css code to be executed later
@@ -2532,8 +2669,9 @@  discard block
 block discarded – undo
2532 2669
 	global $context;
2533 2670
 
2534 2671
 	// Gotta add something...
2535
-	if (empty($css))
2536
-		return false;
2672
+	if (empty($css)) {
2673
+			return false;
2674
+	}
2537 2675
 
2538 2676
 	$context['css_header'][] = $css;
2539 2677
 }
@@ -2569,8 +2707,9 @@  discard block
 block discarded – undo
2569 2707
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2570 2708
 
2571 2709
 	// If this is an external file, automatically set this to false.
2572
-	if (!empty($params['external']))
2573
-		$params['minimize'] = false;
2710
+	if (!empty($params['external'])) {
2711
+			$params['minimize'] = false;
2712
+	}
2574 2713
 
2575 2714
 	// Account for shorthand like admin.js?alp21 filenames
2576 2715
 	$has_seed = strpos($fileName, '.js?');
@@ -2587,16 +2726,12 @@  discard block
 block discarded – undo
2587 2726
 			{
2588 2727
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2589 2728
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2590
-			}
2591
-
2592
-			else
2729
+			} else
2593 2730
 			{
2594 2731
 				$fileUrl = false;
2595 2732
 				$filePath = false;
2596 2733
 			}
2597
-		}
2598
-
2599
-		else
2734
+		} else
2600 2735
 		{
2601 2736
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2602 2737
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2611,9 +2746,10 @@  discard block
 block discarded – undo
2611 2746
 	}
2612 2747
 
2613 2748
 	// Add it to the array for use in the template
2614
-	if (!empty($fileName))
2615
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2616
-}
2749
+	if (!empty($fileName)) {
2750
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2751
+	}
2752
+	}
2617 2753
 
2618 2754
 /**
2619 2755
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2627,9 +2763,10 @@  discard block
 block discarded – undo
2627 2763
 {
2628 2764
 	global $context;
2629 2765
 
2630
-	if (!empty($key) && (!empty($value) || $value === '0'))
2631
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2632
-}
2766
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2767
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2768
+	}
2769
+	}
2633 2770
 
2634 2771
 /**
2635 2772
  * Add a block of inline Javascript code to be executed later
@@ -2646,8 +2783,9 @@  discard block
 block discarded – undo
2646 2783
 {
2647 2784
 	global $context;
2648 2785
 
2649
-	if (empty($javascript))
2650
-		return false;
2786
+	if (empty($javascript)) {
2787
+			return false;
2788
+	}
2651 2789
 
2652 2790
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2653 2791
 }
@@ -2668,15 +2806,18 @@  discard block
 block discarded – undo
2668 2806
 	static $already_loaded = array();
2669 2807
 
2670 2808
 	// Default to the user's language.
2671
-	if ($lang == '')
2672
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2809
+	if ($lang == '') {
2810
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2811
+	}
2673 2812
 
2674 2813
 	// Do we want the English version of language file as fallback?
2675
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2676
-		loadLanguage($template_name, 'english', false);
2814
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2815
+			loadLanguage($template_name, 'english', false);
2816
+	}
2677 2817
 
2678
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2679
-		return $lang;
2818
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2819
+			return $lang;
2820
+	}
2680 2821
 
2681 2822
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2682 2823
 	if (empty($settings['default_theme_dir']))
@@ -2687,8 +2828,9 @@  discard block
 block discarded – undo
2687 2828
 
2688 2829
 	// What theme are we in?
2689 2830
 	$theme_name = basename($settings['theme_url']);
2690
-	if (empty($theme_name))
2691
-		$theme_name = 'unknown';
2831
+	if (empty($theme_name)) {
2832
+			$theme_name = 'unknown';
2833
+	}
2692 2834
 
2693 2835
 	// For each file open it up and write it out!
2694 2836
 	foreach (explode('+', $template_name) as $template)
@@ -2730,8 +2872,9 @@  discard block
 block discarded – undo
2730 2872
 				$found = true;
2731 2873
 
2732 2874
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2733
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2734
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2875
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2876
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2877
+				}
2735 2878
 
2736 2879
 				break;
2737 2880
 			}
@@ -2771,8 +2914,9 @@  discard block
 block discarded – undo
2771 2914
 	}
2772 2915
 
2773 2916
 	// Keep track of what we're up to soldier.
2774
-	if ($db_show_debug === true)
2775
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2917
+	if ($db_show_debug === true) {
2918
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2919
+	}
2776 2920
 
2777 2921
 	// Remember what we have loaded, and in which language.
2778 2922
 	$already_loaded[$template_name] = $lang;
@@ -2818,8 +2962,9 @@  discard block
 block discarded – undo
2818 2962
 				)
2819 2963
 			);
2820 2964
 			// In the EXTREMELY unlikely event this happens, give an error message.
2821
-			if ($smcFunc['db_num_rows']($result) == 0)
2822
-				fatal_lang_error('parent_not_found', 'critical');
2965
+			if ($smcFunc['db_num_rows']($result) == 0) {
2966
+							fatal_lang_error('parent_not_found', 'critical');
2967
+			}
2823 2968
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2824 2969
 			{
2825 2970
 				if (!isset($boards[$row['id_board']]))
@@ -2836,8 +2981,8 @@  discard block
 block discarded – undo
2836 2981
 					);
2837 2982
 				}
2838 2983
 				// If a moderator exists for this board, add that moderator for all children too.
2839
-				if (!empty($row['id_moderator']))
2840
-					foreach ($boards as $id => $dummy)
2984
+				if (!empty($row['id_moderator'])) {
2985
+									foreach ($boards as $id => $dummy)
2841 2986
 					{
2842 2987
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2843 2988
 							'id' => $row['id_moderator'],
@@ -2845,11 +2990,12 @@  discard block
 block discarded – undo
2845 2990
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2846 2991
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2847 2992
 						);
2993
+				}
2848 2994
 					}
2849 2995
 
2850 2996
 				// If a moderator group exists for this board, add that moderator group for all children too
2851
-				if (!empty($row['id_moderator_group']))
2852
-					foreach ($boards as $id => $dummy)
2997
+				if (!empty($row['id_moderator_group'])) {
2998
+									foreach ($boards as $id => $dummy)
2853 2999
 					{
2854 3000
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2855 3001
 							'id' => $row['id_moderator_group'],
@@ -2857,6 +3003,7 @@  discard block
 block discarded – undo
2857 3003
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2858 3004
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2859 3005
 						);
3006
+				}
2860 3007
 					}
2861 3008
 			}
2862 3009
 			$smcFunc['db_free_result']($result);
@@ -2883,23 +3030,27 @@  discard block
 block discarded – undo
2883 3030
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2884 3031
 	{
2885 3032
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2886
-		if (empty($smcFunc['ucwords']))
2887
-			reloadSettings();
3033
+		if (empty($smcFunc['ucwords'])) {
3034
+					reloadSettings();
3035
+		}
2888 3036
 
2889 3037
 		// If we don't have our theme information yet, let's get it.
2890
-		if (empty($settings['default_theme_dir']))
2891
-			loadTheme(0, false);
3038
+		if (empty($settings['default_theme_dir'])) {
3039
+					loadTheme(0, false);
3040
+		}
2892 3041
 
2893 3042
 		// Default language directories to try.
2894 3043
 		$language_directories = array(
2895 3044
 			$settings['default_theme_dir'] . '/languages',
2896 3045
 		);
2897
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2898
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3046
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3047
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3048
+		}
2899 3049
 
2900 3050
 		// We possibly have a base theme directory.
2901
-		if (!empty($settings['base_theme_dir']))
2902
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3051
+		if (!empty($settings['base_theme_dir'])) {
3052
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3053
+		}
2903 3054
 
2904 3055
 		// Remove any duplicates.
2905 3056
 		$language_directories = array_unique($language_directories);
@@ -2913,20 +3064,21 @@  discard block
 block discarded – undo
2913 3064
 		foreach ($language_directories as $language_dir)
2914 3065
 		{
2915 3066
 			// Can't look in here... doesn't exist!
2916
-			if (!file_exists($language_dir))
2917
-				continue;
3067
+			if (!file_exists($language_dir)) {
3068
+							continue;
3069
+			}
2918 3070
 
2919 3071
 			$dir = dir($language_dir);
2920 3072
 			while ($entry = $dir->read())
2921 3073
 			{
2922 3074
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2923
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2924
-					continue;
2925
-
2926
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2927
-					$langName = $langList[$matches[1]];
3075
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3076
+									continue;
3077
+				}
2928 3078
 
2929
-				else
3079
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3080
+									$langName = $langList[$matches[1]];
3081
+				} else
2930 3082
 				{
2931 3083
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2932 3084
 
@@ -2967,12 +3119,14 @@  discard block
 block discarded – undo
2967 3119
 		}
2968 3120
 
2969 3121
 		// Do we need to store the lang list?
2970
-		if (empty($langList))
2971
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3122
+		if (empty($langList)) {
3123
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3124
+		}
2972 3125
 
2973 3126
 		// Let's cash in on this deal.
2974
-		if (!empty($modSettings['cache_enable']))
2975
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3127
+		if (!empty($modSettings['cache_enable'])) {
3128
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3129
+		}
2976 3130
 	}
2977 3131
 
2978 3132
 	return $context['languages'];
@@ -2995,8 +3149,9 @@  discard block
 block discarded – undo
2995 3149
 	global $modSettings, $options, $txt;
2996 3150
 	static $censor_vulgar = null, $censor_proper;
2997 3151
 
2998
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2999
-		return $text;
3152
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3153
+			return $text;
3154
+	}
3000 3155
 
3001 3156
 	// If they haven't yet been loaded, load them.
3002 3157
 	if ($censor_vulgar == null)
@@ -3027,9 +3182,9 @@  discard block
 block discarded – undo
3027 3182
 	{
3028 3183
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3029 3184
 		$text = $func($censor_vulgar, $censor_proper, $text);
3185
+	} else {
3186
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3030 3187
 	}
3031
-	else
3032
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3033 3188
 
3034 3189
 	return $text;
3035 3190
 }
@@ -3055,30 +3210,35 @@  discard block
 block discarded – undo
3055 3210
 	@ini_set('track_errors', '1');
3056 3211
 
3057 3212
 	// Don't include the file more than once, if $once is true.
3058
-	if ($once && in_array($filename, $templates))
3059
-		return;
3213
+	if ($once && in_array($filename, $templates)) {
3214
+			return;
3215
+	}
3060 3216
 	// Add this file to the include list, whether $once is true or not.
3061
-	else
3062
-		$templates[] = $filename;
3217
+	else {
3218
+			$templates[] = $filename;
3219
+	}
3063 3220
 
3064 3221
 
3065 3222
 	$file_found = file_exists($filename);
3066 3223
 
3067
-	if ($once && $file_found)
3068
-		require_once($filename);
3069
-	elseif ($file_found)
3070
-		require($filename);
3224
+	if ($once && $file_found) {
3225
+			require_once($filename);
3226
+	} elseif ($file_found) {
3227
+			require($filename);
3228
+	}
3071 3229
 
3072 3230
 	if ($file_found !== true)
3073 3231
 	{
3074 3232
 		ob_end_clean();
3075
-		if (!empty($modSettings['enableCompressedOutput']))
3076
-			@ob_start('ob_gzhandler');
3077
-		else
3078
-			ob_start();
3233
+		if (!empty($modSettings['enableCompressedOutput'])) {
3234
+					@ob_start('ob_gzhandler');
3235
+		} else {
3236
+					ob_start();
3237
+		}
3079 3238
 
3080
-		if (isset($_GET['debug']))
3081
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3239
+		if (isset($_GET['debug'])) {
3240
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3241
+		}
3082 3242
 
3083 3243
 		// Don't cache error pages!!
3084 3244
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3097,12 +3257,13 @@  discard block
 block discarded – undo
3097 3257
 		echo '<!DOCTYPE html>
3098 3258
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3099 3259
 	<head>';
3100
-		if (isset($context['character_set']))
3101
-			echo '
3260
+		if (isset($context['character_set'])) {
3261
+					echo '
3102 3262
 		<meta charset="', $context['character_set'], '">';
3263
+		}
3103 3264
 
3104
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3105
-			echo '
3265
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3266
+					echo '
3106 3267
 		<title>', $mtitle, '</title>
3107 3268
 	</head>
3108 3269
 	<body>
@@ -3110,8 +3271,8 @@  discard block
 block discarded – undo
3110 3271
 		', $mmessage, '
3111 3272
 	</body>
3112 3273
 </html>';
3113
-		elseif (!allowedTo('admin_forum'))
3114
-			echo '
3274
+		} elseif (!allowedTo('admin_forum')) {
3275
+					echo '
3115 3276
 		<title>', $txt['template_parse_error'], '</title>
3116 3277
 	</head>
3117 3278
 	<body>
@@ -3119,14 +3280,16 @@  discard block
 block discarded – undo
3119 3280
 		', $txt['template_parse_error_message'], '
3120 3281
 	</body>
3121 3282
 </html>';
3122
-		else
3283
+		} else
3123 3284
 		{
3124 3285
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3125 3286
 			$error_array = error_get_last();
3126
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3127
-				$error = $error_array['message'];
3128
-			if (empty($error))
3129
-				$error = $txt['template_parse_errmsg'];
3287
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3288
+							$error = $error_array['message'];
3289
+			}
3290
+			if (empty($error)) {
3291
+							$error = $txt['template_parse_errmsg'];
3292
+			}
3130 3293
 
3131 3294
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3132 3295
 
@@ -3137,11 +3300,12 @@  discard block
 block discarded – undo
3137 3300
 		<h3>', $txt['template_parse_error'], '</h3>
3138 3301
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3139 3302
 
3140
-			if (!empty($error))
3141
-				echo '
3303
+			if (!empty($error)) {
3304
+							echo '
3142 3305
 		<hr>
3143 3306
 
3144 3307
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3308
+			}
3145 3309
 
3146 3310
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3147 3311
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3151,10 +3315,11 @@  discard block
 block discarded – undo
3151 3315
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3152 3316
 
3153 3317
 				// Fix the PHP code stuff...
3154
-				if (!isBrowser('gecko'))
3155
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3156
-				else
3157
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3318
+				if (!isBrowser('gecko')) {
3319
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3320
+				} else {
3321
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3322
+				}
3158 3323
 
3159 3324
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3160 3325
 				$j = -1;
@@ -3162,8 +3327,9 @@  discard block
 block discarded – undo
3162 3327
 				{
3163 3328
 					$j++;
3164 3329
 
3165
-					if (substr_count($line, '<br>') == 0)
3166
-						continue;
3330
+					if (substr_count($line, '<br>') == 0) {
3331
+											continue;
3332
+					}
3167 3333
 
3168 3334
 					$n = substr_count($line, '<br>');
3169 3335
 					for ($i = 0; $i < $n; $i++)
@@ -3182,38 +3348,42 @@  discard block
 block discarded – undo
3182 3348
 				// Figure out what the color coding was before...
3183 3349
 				$line = max($match[1] - 9, 1);
3184 3350
 				$last_line = '';
3185
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3186
-					if (strpos($data2[$line2], '<') !== false)
3351
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3352
+									if (strpos($data2[$line2], '<') !== false)
3187 3353
 					{
3188 3354
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3189 3355
 							$last_line = $color_match[1];
3356
+				}
3190 3357
 						break;
3191 3358
 					}
3192 3359
 
3193 3360
 				// Show the relevant lines...
3194 3361
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3195 3362
 				{
3196
-					if ($line == $match[1])
3197
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3363
+					if ($line == $match[1]) {
3364
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3365
+					}
3198 3366
 
3199 3367
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3200
-					if (isset($data2[$line]) && $data2[$line] != '')
3201
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3368
+					if (isset($data2[$line]) && $data2[$line] != '') {
3369
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3370
+					}
3202 3371
 
3203 3372
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3204 3373
 					{
3205 3374
 						$last_line = $color_match[1];
3206 3375
 						echo '</', substr($last_line, 1, 4), '>';
3376
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3377
+											$last_line = '';
3378
+					} elseif ($last_line != '' && $data2[$line] != '') {
3379
+											echo '</', substr($last_line, 1, 4), '>';
3207 3380
 					}
3208
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3209
-						$last_line = '';
3210
-					elseif ($last_line != '' && $data2[$line] != '')
3211
-						echo '</', substr($last_line, 1, 4), '>';
3212 3381
 
3213
-					if ($line == $match[1])
3214
-						echo '</pre></div><pre style="margin: 0;">';
3215
-					else
3216
-						echo "\n";
3382
+					if ($line == $match[1]) {
3383
+											echo '</pre></div><pre style="margin: 0;">';
3384
+					} else {
3385
+											echo "\n";
3386
+					}
3217 3387
 				}
3218 3388
 
3219 3389
 				echo '</pre></div>';
@@ -3237,8 +3407,9 @@  discard block
 block discarded – undo
3237 3407
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4;
3238 3408
 
3239 3409
 	// Figure out what type of database we are using.
3240
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3241
-		$db_type = 'mysql';
3410
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3411
+			$db_type = 'mysql';
3412
+	}
3242 3413
 
3243 3414
 	// Load the file for the database.
3244 3415
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3246,11 +3417,13 @@  discard block
 block discarded – undo
3246 3417
 	$db_options = array();
3247 3418
 
3248 3419
 	// Add in the port if needed
3249
-	if (!empty($db_port))
3250
-		$db_options['port'] = $db_port;
3420
+	if (!empty($db_port)) {
3421
+			$db_options['port'] = $db_port;
3422
+	}
3251 3423
 
3252
-	if (!empty($db_mb4))
3253
-		$db_options['db_mb4'] = $db_mb4;
3424
+	if (!empty($db_mb4)) {
3425
+			$db_options['db_mb4'] = $db_mb4;
3426
+	}
3254 3427
 
3255 3428
 	// 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.
3256 3429
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3269,13 +3442,15 @@  discard block
 block discarded – undo
3269 3442
 	}
3270 3443
 
3271 3444
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3272
-	if (!$db_connection)
3273
-		display_db_error();
3445
+	if (!$db_connection) {
3446
+			display_db_error();
3447
+	}
3274 3448
 
3275 3449
 	// If in SSI mode fix up the prefix.
3276
-	if (SMF == 'SSI')
3277
-		db_fix_prefix($db_prefix, $db_name);
3278
-}
3450
+	if (SMF == 'SSI') {
3451
+			db_fix_prefix($db_prefix, $db_name);
3452
+	}
3453
+	}
3279 3454
 
3280 3455
 /**
3281 3456
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3289,10 +3464,11 @@  discard block
 block discarded – undo
3289 3464
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3290 3465
 
3291 3466
 	// Not overriding this and we have a cacheAPI, send it back.
3292
-	if (empty($overrideCache) && is_object($cacheAPI))
3293
-		return $cacheAPI;
3294
-	elseif (is_null($cacheAPI))
3295
-		$cacheAPI = false;
3467
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3468
+			return $cacheAPI;
3469
+	} elseif (is_null($cacheAPI)) {
3470
+			$cacheAPI = false;
3471
+	}
3296 3472
 
3297 3473
 	// Make sure our class is in session.
3298 3474
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3313,8 +3489,9 @@  discard block
 block discarded – undo
3313 3489
 		if (!$testAPI->isSupported())
3314 3490
 		{
3315 3491
 			// Can we save ourselves?
3316
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3317
-				return loadCacheAccelerator(null, false);
3492
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3493
+							return loadCacheAccelerator(null, false);
3494
+			}
3318 3495
 			return false;
3319 3496
 		}
3320 3497
 
@@ -3326,9 +3503,9 @@  discard block
 block discarded – undo
3326 3503
 		{
3327 3504
 			$cacheAPI = $testAPI;
3328 3505
 			return $cacheAPI;
3506
+		} else {
3507
+					return $testAPI;
3329 3508
 		}
3330
-		else
3331
-			return $testAPI;
3332 3509
 	}
3333 3510
 }
3334 3511
 
@@ -3348,8 +3525,9 @@  discard block
 block discarded – undo
3348 3525
 
3349 3526
 	// @todo Why are we doing this if caching is disabled?
3350 3527
 
3351
-	if (function_exists('call_integration_hook'))
3352
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3528
+	if (function_exists('call_integration_hook')) {
3529
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3530
+	}
3353 3531
 
3354 3532
 	/* Refresh the cache if either:
3355 3533
 		1. Caching is disabled.
@@ -3363,16 +3541,19 @@  discard block
 block discarded – undo
3363 3541
 		require_once($sourcedir . '/' . $file);
3364 3542
 		$cache_block = call_user_func_array($function, $params);
3365 3543
 
3366
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3367
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3544
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3545
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3546
+		}
3368 3547
 	}
3369 3548
 
3370 3549
 	// Some cached data may need a freshening up after retrieval.
3371
-	if (!empty($cache_block['post_retri_eval']))
3372
-		eval($cache_block['post_retri_eval']);
3550
+	if (!empty($cache_block['post_retri_eval'])) {
3551
+			eval($cache_block['post_retri_eval']);
3552
+	}
3373 3553
 
3374
-	if (function_exists('call_integration_hook'))
3375
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3554
+	if (function_exists('call_integration_hook')) {
3555
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3556
+	}
3376 3557
 
3377 3558
 	return $cache_block['data'];
3378 3559
 }
@@ -3399,8 +3580,9 @@  discard block
 block discarded – undo
3399 3580
 	global $smcFunc, $cache_enable, $cacheAPI;
3400 3581
 	global $cache_hits, $cache_count, $db_show_debug;
3401 3582
 
3402
-	if (empty($cache_enable) || empty($cacheAPI))
3403
-		return;
3583
+	if (empty($cache_enable) || empty($cacheAPI)) {
3584
+			return;
3585
+	}
3404 3586
 
3405 3587
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3406 3588
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3413,12 +3595,14 @@  discard block
 block discarded – undo
3413 3595
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3414 3596
 	$cacheAPI->putData($key, $value, $ttl);
3415 3597
 
3416
-	if (function_exists('call_integration_hook'))
3417
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3598
+	if (function_exists('call_integration_hook')) {
3599
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3600
+	}
3418 3601
 
3419
-	if (isset($db_show_debug) && $db_show_debug === true)
3420
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3421
-}
3602
+	if (isset($db_show_debug) && $db_show_debug === true) {
3603
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3604
+	}
3605
+	}
3422 3606
 
3423 3607
 /**
3424 3608
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3434,8 +3618,9 @@  discard block
 block discarded – undo
3434 3618
 	global $smcFunc, $cache_enable, $cacheAPI;
3435 3619
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3436 3620
 
3437
-	if (empty($cache_enable) || empty($cacheAPI))
3438
-		return;
3621
+	if (empty($cache_enable) || empty($cacheAPI)) {
3622
+			return;
3623
+	}
3439 3624
 
3440 3625
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3441 3626
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3455,16 +3640,18 @@  discard block
 block discarded – undo
3455 3640
 
3456 3641
 		if (empty($value))
3457 3642
 		{
3458
-			if (!is_array($cache_misses))
3459
-				$cache_misses = array();
3643
+			if (!is_array($cache_misses)) {
3644
+							$cache_misses = array();
3645
+			}
3460 3646
 
3461 3647
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3462 3648
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3463 3649
 		}
3464 3650
 	}
3465 3651
 
3466
-	if (function_exists('call_integration_hook') && isset($value))
3467
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3652
+	if (function_exists('call_integration_hook') && isset($value)) {
3653
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3654
+	}
3468 3655
 
3469 3656
 	return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3470 3657
 }
@@ -3486,8 +3673,9 @@  discard block
 block discarded – undo
3486 3673
 	global $cacheAPI;
3487 3674
 
3488 3675
 	// If we can't get to the API, can't do this.
3489
-	if (empty($cacheAPI))
3490
-		return;
3676
+	if (empty($cacheAPI)) {
3677
+			return;
3678
+	}
3491 3679
 
3492 3680
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3493 3681
 	$cacheAPI->cleanCache($type);
@@ -3512,8 +3700,9 @@  discard block
 block discarded – undo
3512 3700
 	global $modSettings, $smcFunc, $image_proxy_enabled, $user_info;
3513 3701
 
3514 3702
 	// Come on!
3515
-	if (empty($data))
3516
-		return array();
3703
+	if (empty($data)) {
3704
+			return array();
3705
+	}
3517 3706
 
3518 3707
 	// Set a nice default var.
3519 3708
 	$image = '';
@@ -3521,11 +3710,11 @@  discard block
 block discarded – undo
3521 3710
 	// Gravatar has been set as mandatory!
3522 3711
 	if (!empty($modSettings['gravatarOverride']))
3523 3712
 	{
3524
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3525
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3526
-
3527
-		else if (!empty($data['email']))
3528
-			$image = get_gravatar_url($data['email']);
3713
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3714
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3715
+		} else if (!empty($data['email'])) {
3716
+					$image = get_gravatar_url($data['email']);
3717
+		}
3529 3718
 	}
3530 3719
 
3531 3720
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3537,54 +3726,60 @@  discard block
 block discarded – undo
3537 3726
 			// Gravatar.
3538 3727
 			if (stristr($data['avatar'], 'gravatar://'))
3539 3728
 			{
3540
-				if ($data['avatar'] == 'gravatar://')
3541
-					$image = get_gravatar_url($data['email']);
3542
-
3543
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3544
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3729
+				if ($data['avatar'] == 'gravatar://') {
3730
+									$image = get_gravatar_url($data['email']);
3731
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3732
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3733
+				}
3545 3734
 			}
3546 3735
 
3547 3736
 			// External url.
3548 3737
 			else
3549 3738
 			{
3550 3739
 				// Using ssl?
3551
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3552
-					$image = get_proxied_url($data['avatar']);
3740
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3741
+									$image = get_proxied_url($data['avatar']);
3742
+				}
3553 3743
 
3554 3744
 				// Just a plain external url.
3555
-				else
3556
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3745
+				else {
3746
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3747
+				}
3557 3748
 			}
3558 3749
 		}
3559 3750
 
3560 3751
 		// Perhaps this user has an attachment as avatar...
3561
-		else if (!empty($data['filename']))
3562
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3752
+		else if (!empty($data['filename'])) {
3753
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3754
+		}
3563 3755
 
3564 3756
 		// Right... no avatar... use our default image.
3565
-		else
3566
-			$image = $modSettings['avatar_url'] . '/default.png';
3757
+		else {
3758
+					$image = $modSettings['avatar_url'] . '/default.png';
3759
+		}
3567 3760
 	}
3568 3761
 
3569 3762
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3570 3763
 
3571 3764
 	// 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.
3572
-	if (!empty($image))
3573
-		return array(
3765
+	if (!empty($image)) {
3766
+			return array(
3574 3767
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3575 3768
 			'image' => '<img class="avatar" src="' . $image . '" />',
3576 3769
 			'href' => $image,
3577 3770
 			'url' => $image,
3578 3771
 		);
3772
+	}
3579 3773
 
3580 3774
 	// Fallback to make life easier for everyone...
3581
-	else
3582
-		return array(
3775
+	else {
3776
+			return array(
3583 3777
 			'name' => '',
3584 3778
 			'image' => '',
3585 3779
 			'href' => '',
3586 3780
 			'url' => '',
3587 3781
 		);
3588
-}
3782
+	}
3783
+	}
3589 3784
 
3590 3785
 ?>
3591 3786
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/GenericList.template.php 1 patch
Braces   +65 added lines, -46 removed lines patch added patch discarded remove patch
@@ -22,27 +22,31 @@  discard block
 block discarded – undo
22 22
 	// Get a shortcut to the current list.
23 23
 	$list_id = $list_id === null ? (!empty($context['default_list']) ? $context['default_list'] : '') : $list_id;
24 24
 
25
-	if (empty($list_id) || empty($context[$list_id]))
26
-		return;
25
+	if (empty($list_id) || empty($context[$list_id])) {
26
+			return;
27
+	}
27 28
 
28 29
 	$cur_list = &$context[$list_id];
29 30
 
30 31
 	// These are the main tabs that is used all around the template.
31
-	if (isset($cur_list['list_menu'], $cur_list['list_menu']['show_on']) && ($cur_list['list_menu']['show_on'] == 'both' || $cur_list['list_menu']['show_on'] == 'top'))
32
-		template_create_list_menu($cur_list['list_menu'], 'top');
32
+	if (isset($cur_list['list_menu'], $cur_list['list_menu']['show_on']) && ($cur_list['list_menu']['show_on'] == 'both' || $cur_list['list_menu']['show_on'] == 'top')) {
33
+			template_create_list_menu($cur_list['list_menu'], 'top');
34
+	}
33 35
 
34
-	if (isset($cur_list['form']))
35
-		echo '
36
+	if (isset($cur_list['form'])) {
37
+			echo '
36 38
 	<form action="', $cur_list['form']['href'], '" method="post"', empty($cur_list['form']['name']) ? '' : ' name="' . $cur_list['form']['name'] . '" id="' . $cur_list['form']['name'] . '"', ' accept-charset="', $context['character_set'], '">';
39
+	}
37 40
 
38 41
 	// Show the title of the table (if any).
39
-	if (!empty($cur_list['title']))
40
-		echo '
42
+	if (!empty($cur_list['title'])) {
43
+			echo '
41 44
 		<div class="cat_bar">
42 45
 			<h3 class="catbg">
43 46
 				', $cur_list['title'], '
44 47
 			</h3>
45 48
 		</div>';
49
+	}
46 50
 
47 51
 	if (isset($cur_list['additional_rows']['after_title']))
48 52
 	{
@@ -55,20 +59,23 @@  discard block
 block discarded – undo
55 59
 		</div>';
56 60
 	}
57 61
 
58
-	if (isset($cur_list['additional_rows']['top_of_list']))
59
-		template_additional_rows('top_of_list', $cur_list);
62
+	if (isset($cur_list['additional_rows']['top_of_list'])) {
63
+			template_additional_rows('top_of_list', $cur_list);
64
+	}
60 65
 
61 66
 	if ((!empty($cur_list['items_per_page']) && !empty($cur_list['page_index'])) || isset($cur_list['additional_rows']['above_column_headers']))
62 67
 	{
63 68
 		// Show the page index (if this list doesn't intend to show all items).
64
-		if (!empty($cur_list['items_per_page']) && !empty($cur_list['page_index']))
65
-			echo '
69
+		if (!empty($cur_list['items_per_page']) && !empty($cur_list['page_index'])) {
70
+					echo '
66 71
 		<div class="floatleft">
67 72
 			<div class="pagesection">', $cur_list['page_index'], '</div>
68 73
 		</div>';
74
+		}
69 75
 
70
-		if (isset($cur_list['additional_rows']['above_column_headers']))
71
-			template_additional_rows('above_column_headers', $cur_list);
76
+		if (isset($cur_list['additional_rows']['above_column_headers'])) {
77
+					template_additional_rows('above_column_headers', $cur_list);
78
+		}
72 79
 	}
73 80
 
74 81
 	echo '
@@ -83,11 +90,12 @@  discard block
 block discarded – undo
83 90
 				<tr class="title_bar">';
84 91
 
85 92
 		// Loop through each column and add a table header.
86
-		foreach ($cur_list['headers'] as $col_header)
87
-			echo '
93
+		foreach ($cur_list['headers'] as $col_header) {
94
+					echo '
88 95
 					<th scope="col" id="header_', $list_id, '_', $col_header['id'], '" class="' , $col_header['id'], empty($col_header['class']) ? '' : ' '.$col_header['class'] , '"', empty($col_header['style']) ? '' : ' style="' . $col_header['style'] . '"', empty($col_header['colspan']) ? '' : ' colspan="' . $col_header['colspan'] . '"', '>
89 96
 						', empty($col_header['href']) ? '' : '<a href="' . $col_header['href'] . '" rel="nofollow">', empty($col_header['label']) ? '' : $col_header['label'], empty($col_header['href']) ? '' : (empty($col_header['sort_image']) ? '</a>' : ' <span class="generic_icons sort_' . $col_header['sort_image'] . '"></span></a>'), '
90 97
 					</th>';
98
+		}
91 99
 
92 100
 		echo '
93 101
 				</tr>
@@ -98,13 +106,14 @@  discard block
 block discarded – undo
98 106
 			<tbody>';
99 107
 
100 108
 	// Show a nice message informing there are no items in this list.
101
-	if (empty($cur_list['rows']) && !empty($cur_list['no_items_label']))
102
-		echo '
109
+	if (empty($cur_list['rows']) && !empty($cur_list['no_items_label'])) {
110
+			echo '
103 111
 				<tr class="windowbg">
104 112
 					<td colspan="', $cur_list['num_columns'], '" class="', !empty($cur_list['no_items_align']) ? $cur_list['no_items_align'] : 'centertext', '">
105 113
 						', $cur_list['no_items_label'], '
106 114
 					</td>
107 115
 				</tr>';
116
+	}
108 117
 
109 118
 	// Show the list rows.
110 119
 	elseif (!empty($cur_list['rows']))
@@ -114,12 +123,13 @@  discard block
 block discarded – undo
114 123
 			echo '
115 124
 				<tr class="windowbg', empty($row['class']) ? '' : ' ' . $row['class'], '"', empty($row['style']) ? '' : ' style="' . $row['style'] . '"', ' id="list_', $list_id, '_', $id, '">';
116 125
 
117
-			if (!empty($row['data']))
118
-				foreach ($row['data'] as $row_id => $row_data)
126
+			if (!empty($row['data'])) {
127
+							foreach ($row['data'] as $row_id => $row_data)
119 128
 					echo '
120 129
 					<td class="', $row_id, empty($row_data['class']) ? '' : ' ' . $row_data['class'] .'', '"', empty($row_data['style']) ? '' : ' style="' . $row_data['style'] . '"', '>
121 130
 						', $row_data['value'], '
122 131
 					</td>';
132
+			}
123 133
 
124 134
 			echo '
125 135
 				</tr>';
@@ -136,46 +146,53 @@  discard block
 block discarded – undo
136 146
 		<div class="flow_auto">';
137 147
 
138 148
 		// Show the page index (if this list doesn't intend to show all items).
139
-		if (!empty($cur_list['items_per_page']) && !empty($cur_list['page_index']))
140
-			echo '
149
+		if (!empty($cur_list['items_per_page']) && !empty($cur_list['page_index'])) {
150
+					echo '
141 151
 			<div class="floatleft">
142 152
 				<div class="pagesection">', $cur_list['page_index'], '</div>
143 153
 			</div>';
154
+		}
144 155
 
145
-		if (isset($cur_list['additional_rows']['below_table_data']))
146
-			template_additional_rows('below_table_data', $cur_list);
156
+		if (isset($cur_list['additional_rows']['below_table_data'])) {
157
+					template_additional_rows('below_table_data', $cur_list);
158
+		}
147 159
 
148 160
 		echo '
149 161
 		</div>';
150 162
 	}
151 163
 
152
-	if (isset($cur_list['additional_rows']['bottom_of_list']))
153
-		template_additional_rows('bottom_of_list', $cur_list);
164
+	if (isset($cur_list['additional_rows']['bottom_of_list'])) {
165
+			template_additional_rows('bottom_of_list', $cur_list);
166
+	}
154 167
 
155 168
 	if (isset($cur_list['form']))
156 169
 	{
157
-		foreach ($cur_list['form']['hidden_fields'] as $name => $value)
158
-			echo '
170
+		foreach ($cur_list['form']['hidden_fields'] as $name => $value) {
171
+					echo '
159 172
 		<input type="hidden" name="', $name, '" value="', $value, '">';
173
+		}
160 174
 
161
-		if (isset($cur_list['form']['token']))
162
-			echo '
175
+		if (isset($cur_list['form']['token'])) {
176
+					echo '
163 177
 		<input type="hidden" name="', $context[$cur_list['form']['token'] . '_token_var'], '" value="', $context[$cur_list['form']['token'] . '_token'], '">';
178
+		}
164 179
 
165 180
 		echo '
166 181
 	</form>';
167 182
 	}
168 183
 
169 184
 	// Tabs at the bottom.  Usually bottom aligned.
170
-	if (isset($cur_list['list_menu'], $cur_list['list_menu']['show_on']) && ($cur_list['list_menu']['show_on'] == 'both' || $cur_list['list_menu']['show_on'] == 'bottom'))
171
-		template_create_list_menu($cur_list['list_menu'], 'bottom');
185
+	if (isset($cur_list['list_menu'], $cur_list['list_menu']['show_on']) && ($cur_list['list_menu']['show_on'] == 'both' || $cur_list['list_menu']['show_on'] == 'bottom')) {
186
+			template_create_list_menu($cur_list['list_menu'], 'bottom');
187
+	}
172 188
 
173
-	if (isset($cur_list['javascript']))
174
-		echo '
189
+	if (isset($cur_list['javascript'])) {
190
+			echo '
175 191
 	<script>
176 192
 		', $cur_list['javascript'], '
177 193
 	</script>';
178
-}
194
+	}
195
+	}
179 196
 
180 197
 /**
181 198
  * This template displays additional rows above or below the list.
@@ -185,12 +202,13 @@  discard block
 block discarded – undo
185 202
  */
186 203
 function template_additional_rows($row_position, $cur_list)
187 204
 {
188
-	foreach ($cur_list['additional_rows'][$row_position] as $row)
189
-		echo '
205
+	foreach ($cur_list['additional_rows'][$row_position] as $row) {
206
+			echo '
190 207
 			<div class="additional_row', empty($row['class']) ? '' : ' ' . $row['class'], '"', empty($row['style']) ? '' : ' style="' . $row['style'] . '"', '>
191 208
 				', $row['value'], '
192 209
 			</div>';
193
-}
210
+	}
211
+	}
194 212
 
195 213
 /**
196 214
  * This function creates a menu
@@ -249,18 +267,19 @@  discard block
 block discarded – undo
249 267
 
250 268
 		foreach ($list_menu['links'] as $link)
251 269
 		{
252
-			if ($link['is_selected'])
253
-				echo '
270
+			if ($link['is_selected']) {
271
+							echo '
254 272
 							<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_active_', $first, '"></td>
255 273
 							<td class="', $direction == 'top' ? 'mirrortab' : 'maintab', '_active_back">
256 274
 								<a href="', $link['href'], '">', $link['label'], '</a>
257 275
 							</td>
258 276
 							<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_active_', $last, '"></td>';
259
-			else
260
-				echo '
277
+			} else {
278
+							echo '
261 279
 							<td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_back">
262 280
 								<a href="', $link['href'], '">', $link['label'], '</a>
263 281
 							</td>';
282
+			}
264 283
 		}
265 284
 
266 285
 		echo '
@@ -271,12 +290,12 @@  discard block
 block discarded – undo
271 290
 				<td></td>' : '', '
272 291
 			</tr>
273 292
 		</table>';
274
-	}
275
-	elseif (isset($list_menu['style']) && $list_menu['style'] == 'buttons')
293
+	} elseif (isset($list_menu['style']) && $list_menu['style'] == 'buttons')
276 294
 	{
277 295
 		$links = array();
278
-		foreach ($list_menu['links'] as $link)
279
-			$links[] = '<a href="' . $link['href'] . '">' . $link['label'] . '</a>';
296
+		foreach ($list_menu['links'] as $link) {
297
+					$links[] = '<a href="' . $link['href'] . '">' . $link['label'] . '</a>';
298
+		}
280 299
 
281 300
 		echo '
282 301
 		<table style="margin-', $list_menu['position'], ': 10px; width: 100%;">
Please login to merge, or discard this patch.