Completed
Push — release-2.1 ( 65d689...40be7d )
by Jeremy
14s
created
Themes/default/Packages.template.php 1 patch
Braces   +175 added lines, -128 removed lines patch added patch discarded remove patch
@@ -30,25 +30,27 @@  discard block
 block discarded – undo
30 30
 		</div>
31 31
 		<div class="information">';
32 32
 
33
-	if ($context['is_installed'])
34
-		echo '
33
+	if ($context['is_installed']) {
34
+			echo '
35 35
 			<strong>', $txt['package_installed_warning1'], '</strong><br>
36 36
 			<br>
37 37
 			', $txt['package_installed_warning2'], '<br>
38 38
 			<br>';
39
+	}
39 40
 
40 41
 	echo $txt['package_installed_warning3'], '
41 42
 		</div>
42 43
 		<br>';
43 44
 
44 45
 	// Do errors exist in the install? If so light them up like a christmas tree.
45
-	if ($context['has_failure'])
46
-		echo '
46
+	if ($context['has_failure']) {
47
+			echo '
47 48
 		<div class="errorbox">
48 49
 			', sprintf($txt['package_will_fail_title'], $txt['package_' . ($context['uninstalling'] ? 'uninstall' : 'install')]), '<br>
49 50
 			', sprintf($txt['package_will_fail_warning'], $txt['package_' . ($context['uninstalling'] ? 'uninstall' : 'install')]),
50 51
 			!empty($context['failure_details']) ? '<br><br><strong>' . $context['failure_details'] . '</strong>' : '', '
51 52
 		</div>';
53
+	}
52 54
 
53 55
 	// Display the package readme if one exists
54 56
 	if (isset($context['package_readme']))
@@ -62,9 +64,10 @@  discard block
 block discarded – undo
62 64
 			<span class="floatright">', $txt['package_available_readme_language'], '
63 65
 				<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\'));">';
64 66
 
65
-		foreach ($context['readmes'] as $a => $b)
66
-			echo '
67
+		foreach ($context['readmes'] as $a => $b) {
68
+					echo '
67 69
 					<option value="', $b, '"', $a === 'selected' ? ' selected' : '', '>', $b == 'default' ? $txt['package_readme_default'] : ucfirst($b), '</option>';
70
+		}
68 71
 
69 72
 		echo '
70 73
 				</select>
@@ -85,9 +88,10 @@  discard block
 block discarded – undo
85 88
 			<span class="floatright">', $txt['package_available_license_language'], '
86 89
 				<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\'));">';
87 90
 
88
-		foreach ($context['licenses'] as $a => $b)
89
-			echo '
91
+		foreach ($context['licenses'] as $a => $b) {
92
+					echo '
90 93
 					<option value="', $b, '"', $a === 'selected' ? ' selected' : '', '>', $b == 'default' ? $txt['package_license_default'] : ucfirst($b), '</option>';
94
+		}
91 95
 		echo '
92 96
 				</select>
93 97
 			</span>
@@ -114,9 +118,10 @@  discard block
 block discarded – undo
114 118
 					', $txt['package_db_uninstall_actions'], ':
115 119
 					<ul>';
116 120
 
117
-		foreach ($context['database_changes'] as $change)
118
-			echo '
121
+		foreach ($context['database_changes'] as $change) {
122
+					echo '
119 123
 						<li>', $change, '</li>';
124
+		}
120 125
 
121 126
 		echo '
122 127
 					</ul>
@@ -127,14 +132,14 @@  discard block
 block discarded – undo
127 132
 	echo '
128 133
 			<div class="information">';
129 134
 
130
-	if (empty($context['actions']) && empty($context['database_changes']))
131
-		echo '
135
+	if (empty($context['actions']) && empty($context['database_changes'])) {
136
+			echo '
132 137
 				<br>
133 138
 				<div class="errorbox">
134 139
 					', $txt['corrupt_compatible'], '
135 140
 				</div>
136 141
 			</div><!-- .information -->';
137
-	else
142
+	} else
138 143
 	{
139 144
 		echo '
140 145
 				', $txt['perform_actions'], '
@@ -238,9 +243,10 @@  discard block
 block discarded – undo
238 243
 						<td></td>
239 244
 						<td>';
240 245
 
241
-				if (!empty($context['themes_locked']))
242
-					echo '
246
+				if (!empty($context['themes_locked'])) {
247
+									echo '
243 248
 							<input type="hidden" name="custom_theme[]" value="', $id, '">';
249
+				}
244 250
 				echo '
245 251
 							<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' : '', '>
246 252
 						</td>
@@ -306,21 +312,23 @@  discard block
 block discarded – undo
306 312
 	}
307 313
 
308 314
 	// Are we effectively ready to install?
309
-	if (!$context['ftp_needed'] && (!empty($context['actions']) || !empty($context['database_changes'])))
310
-		echo '
315
+	if (!$context['ftp_needed'] && (!empty($context['actions']) || !empty($context['database_changes']))) {
316
+			echo '
311 317
 			<div class="righttext padding">
312 318
 				<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">
313 319
 			</div>';
320
+	}
314 321
 
315 322
 	// If we need ftp information then demand it!
316
-	elseif ($context['ftp_needed'])
317
-		echo '
323
+	elseif ($context['ftp_needed']) {
324
+			echo '
318 325
 			<div class="cat_bar">
319 326
 				<h3 class="catbg">', $txt['package_ftp_necessary'], '</h3>
320 327
 			</div>
321 328
 			<div>
322 329
 				', template_control_chmod(), '
323 330
 			</div>';
331
+	}
324 332
 
325 333
 	echo '
326 334
 
@@ -336,8 +344,8 @@  discard block
 block discarded – undo
336 344
 	// Operations.
337 345
 	if (!empty($js_operations))
338 346
 	{
339
-		foreach ($js_operations as $key => $operation)
340
-			echo '
347
+		foreach ($js_operations as $key => $operation) {
348
+					echo '
341 349
 		aOperationElements[', $key, '] = new smc_Toggle({
342 350
 			bToggleEnabled: true,
343 351
 			bNoAnimate: true,
@@ -355,6 +363,7 @@  discard block
 block discarded – undo
355 363
 				}
356 364
 			]
357 365
 		});';
366
+		}
358 367
 	}
359 368
 
360 369
 	echo '
@@ -376,14 +385,15 @@  discard block
 block discarded – undo
376 385
 	</script>';
377 386
 
378 387
 	// And a bit more for database changes.
379
-	if (!empty($context['database_changes']))
380
-		echo '
388
+	if (!empty($context['database_changes'])) {
389
+			echo '
381 390
 	<script>
382 391
 		var database_changes_area = document.getElementById(\'db_changes_div\');
383 392
 		var db_vis = false;
384 393
 		database_changes_area.classList.add(\'hidden\');
385 394
 	</script>';
386
-}
395
+	}
396
+	}
387 397
 
388 398
 /**
389 399
  * Extract package contents
@@ -392,8 +402,8 @@  discard block
 block discarded – undo
392 402
 {
393 403
 	global $context, $txt, $scripturl;
394 404
 
395
-	if (!empty($context['redirect_url']))
396
-		echo '
405
+	if (!empty($context['redirect_url'])) {
406
+			echo '
397 407
 	<script>
398 408
 		setTimeout("doRedirect();", ', empty($context['redirect_timeout']) ? '5000' : $context['redirect_timeout'], ');
399 409
 
@@ -402,49 +412,48 @@  discard block
 block discarded – undo
402 412
 			window.location = "', $context['redirect_url'], '";
403 413
 		}
404 414
 	</script>';
415
+	}
405 416
 
406
-	if (empty($context['redirect_url']))
407
-		echo '
417
+	if (empty($context['redirect_url'])) {
418
+			echo '
408 419
 		<div class="cat_bar">
409 420
 			<h3 class="catbg">', $context['uninstalling'] ? $txt['uninstall'] : $txt['extracting'], '</h3>
410 421
 		</div>
411 422
 		<div class="information">', $txt['package_installed_extract'], '</div>';
412
-	else
413
-		echo '
423
+	} else {
424
+			echo '
414 425
 		<div class="cat_bar">
415 426
 			<h3 class="catbg">', $txt['package_installed_redirecting'], '</h3>
416 427
 		</div>';
428
+	}
417 429
 
418 430
 	echo '
419 431
 		<div class="windowbg">';
420 432
 
421 433
 	// If we are going to redirect we have a slightly different agenda.
422
-	if (!empty($context['redirect_url']))
423
-		echo '
434
+	if (!empty($context['redirect_url'])) {
435
+			echo '
424 436
 			', $context['redirect_text'], '<br><br>
425 437
 			<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>';
426
-
427
-	elseif ($context['uninstalling'])
428
-		echo '
438
+	} elseif ($context['uninstalling']) {
439
+			echo '
429 440
 			', $txt['package_uninstall_done'];
430
-
431
-	elseif ($context['install_finished'])
441
+	} elseif ($context['install_finished'])
432 442
 	{
433
-		if ($context['extract_type'] == 'avatar')
434
-			echo '
443
+		if ($context['extract_type'] == 'avatar') {
444
+					echo '
435 445
 			', $txt['avatars_extracted'];
436
-
437
-		elseif ($context['extract_type'] == 'language')
438
-			echo '
446
+		} elseif ($context['extract_type'] == 'language') {
447
+					echo '
439 448
 			', $txt['language_extracted'];
440
-
441
-		else
442
-			echo '
449
+		} else {
450
+					echo '
443 451
 			', $txt['package_installed_done'];
444
-	}
445
-	else
446
-		echo '
452
+		}
453
+	} else {
454
+			echo '
447 455
 			', $txt['corrupt_compatible'];
456
+	}
448 457
 
449 458
 	echo '
450 459
 		</div><!-- .windowbg -->';
@@ -474,9 +483,10 @@  discard block
 block discarded – undo
474 483
 		<div class="windowbg">
475 484
 			<ol>';
476 485
 
477
-	foreach ($context['files'] as $fileinfo)
478
-		echo '
486
+	foreach ($context['files'] as $fileinfo) {
487
+			echo '
479 488
 				<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>';
489
+	}
480 490
 
481 491
 	echo '
482 492
 			</ol>
@@ -536,9 +546,10 @@  discard block
 block discarded – undo
536 546
 			</script>
537 547
 			<div id="yourVersion" style="display:none">', $context['forum_version'], '</div>';
538 548
 
539
-	if (empty($modSettings['disable_smf_js']))
540
-		echo '
549
+	if (empty($modSettings['disable_smf_js'])) {
550
+			echo '
541 551
 			<script src="', $scripturl, '?action=viewsmfile;filename=latest-news.js"></script>';
552
+	}
542 553
 
543 554
 	// This sets the announcements and current versions themselves ;).
544 555
 	echo '
@@ -576,12 +587,13 @@  discard block
 block discarded – undo
576 587
 		}
577 588
 	}
578 589
 
579
-	if (!$mods_available)
580
-		echo '
590
+	if (!$mods_available) {
591
+			echo '
581 592
 		<div class="noticebox">', $txt['no_packages'], '</div>';
582
-	else
583
-		echo '
593
+	} else {
594
+			echo '
584 595
 		<br>';
596
+	}
585 597
 
586 598
 	// The advanced (emulation) box, collapsed by default
587 599
 	echo '
@@ -608,9 +620,10 @@  discard block
 block discarded – undo
608 620
 							<a id="revert" name="revert"></a>
609 621
 							<select name="version_emulate" id="ve">';
610 622
 
611
-	foreach ($context['emulation_versions'] as $version)
612
-		echo '
623
+	foreach ($context['emulation_versions'] as $version) {
624
+			echo '
613 625
 								<option value="', $version, '"', ($version == $context['selected_version'] ? ' selected="selected"' : ''), '>', $version, '</option>';
626
+	}
614 627
 
615 628
 	echo '
616 629
 							</select>
@@ -665,11 +678,12 @@  discard block
 block discarded – undo
665 678
 {
666 679
 	global $context, $txt, $scripturl;
667 680
 
668
-	if (!empty($context['package_ftp']['error']))
669
-		echo '
681
+	if (!empty($context['package_ftp']['error'])) {
682
+			echo '
670 683
 	<div class="errorbox">
671 684
 		<pre>', $context['package_ftp']['error'], '</pre>
672 685
 	</div>';
686
+	}
673 687
 
674 688
 	echo '
675 689
 	<div id="admin_form_wrapper">
@@ -752,13 +766,14 @@  discard block
 block discarded – undo
752 766
 					<legend>' . $txt['package_servers'] . '</legend>
753 767
 					<ul class="package_servers">';
754 768
 
755
-	foreach ($context['servers'] as $server)
756
-		echo '
769
+	foreach ($context['servers'] as $server) {
770
+			echo '
757 771
 						<li class="flow_auto">
758 772
 							<span class="floatleft">' . $server['name'] . '</span>
759 773
 							<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>
760 774
 							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $server['id'] . '">[ ' . $txt['package_browse'] . ' ]</a></span>
761 775
 						</li>';
776
+	}
762 777
 	echo '
763 778
 					</ul>
764 779
 				</fieldset>
@@ -842,11 +857,12 @@  discard block
 block discarded – undo
842 857
 		<div class="windowbg">';
843 858
 
844 859
 	// No packages, as yet.
845
-	if (empty($context['package_list']))
846
-		echo '
860
+	if (empty($context['package_list'])) {
861
+			echo '
847 862
 			<ul>
848 863
 				<li>', $txt['no_packages'], '</li>
849 864
 			</ul>';
865
+	}
850 866
 
851 867
 	// List out the packages...
852 868
 	else
@@ -860,11 +876,12 @@  discard block
 block discarded – undo
860 876
 				<li>
861 877
 					<strong><span id="ps_img_', $i, '" class="toggle_up" alt="*" style="display: none;"></span> ', $packageSection['title'], '</strong>';
862 878
 
863
-			if (!empty($packageSection['text']))
864
-				echo '
879
+			if (!empty($packageSection['text'])) {
880
+							echo '
865 881
 					<div class="sub_bar">
866 882
 						<h3 class="subbg">', $packageSection['text'], '</h3>
867 883
 					</div>';
884
+			}
868 885
 
869 886
 			echo '
870 887
 					<', $context['list_type'], ' id="package_section_', $i, '" class="packages">';
@@ -875,24 +892,28 @@  discard block
 block discarded – undo
875 892
 						<li>';
876 893
 
877 894
 				// Textual message. Could be empty just for a blank line...
878
-				if ($package['is_text'])
879
-					echo '
895
+				if ($package['is_text']) {
896
+									echo '
880 897
 							', empty($package['name']) ? '&nbsp;' : $package['name'];
898
+				}
881 899
 
882 900
 				// This is supposed to be a rule..
883
-				elseif ($package['is_line'])
884
-					echo '
901
+				elseif ($package['is_line']) {
902
+									echo '
885 903
 							<hr>';
904
+				}
886 905
 
887 906
 				// A remote link.
888
-				elseif ($package['is_remote'])
889
-					echo '
907
+				elseif ($package['is_remote']) {
908
+									echo '
890 909
 							<strong>', $package['link'], '</strong>';
910
+				}
891 911
 
892 912
 				// A title?
893
-				elseif ($package['is_heading'] || $package['is_title'])
894
-					echo '
913
+				elseif ($package['is_heading'] || $package['is_title']) {
914
+									echo '
895 915
 							<strong>', $package['name'], '</strong>';
916
+				}
896 917
 
897 918
 				// Otherwise, it's a package.
898 919
 				else
@@ -903,32 +924,36 @@  discard block
 block discarded – undo
903 924
 						<ul id="package_section_', $i, '_pkg_', $id, '" class="package_section">';
904 925
 
905 926
 					// Show the mod type?
906
-					if ($package['type'] != '')
907
-						echo '
927
+					if ($package['type'] != '') {
928
+											echo '
908 929
 							<li class="package_section">
909 930
 								', $txt['package_type'], ':&nbsp; ', $smcFunc['ucwords']($smcFunc['strtolower']($package['type'])), '
910 931
 							</li>';
932
+					}
911 933
 
912 934
 					// Show the version number?
913
-					if ($package['version'] != '')
914
-						echo '
935
+					if ($package['version'] != '') {
936
+											echo '
915 937
 							<li class="package_section">
916 938
 								', $txt['mod_version'], ':&nbsp; ', $package['version'], '
917 939
 							</li>';
940
+					}
918 941
 
919 942
 					// How 'bout the author?
920
-					if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link']))
921
-						echo '
943
+					if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link'])) {
944
+											echo '
922 945
 							<li class="package_section">
923 946
 								', $txt['mod_author'], ':&nbsp; ', $package['author']['link'], '
924 947
 							</li>';
948
+					}
925 949
 
926 950
 					// The homepage...
927
-					if ($package['author']['website']['link'] != '')
928
-						echo '
951
+					if ($package['author']['website']['link'] != '') {
952
+											echo '
929 953
 							<li class="package_section">
930 954
 								', $txt['author_website'], ':&nbsp; ', $package['author']['website']['link'], '
931 955
 							</li>';
956
+					}
932 957
 
933 958
 					// Description: bleh bleh!
934 959
 					// Location of file: http://someplace/.
@@ -986,8 +1011,8 @@  discard block
 block discarded – undo
986 1011
 
987 1012
 			foreach ($ps['items'] as $id => $package)
988 1013
 			{
989
-				if (!$package['is_text'] && !$package['is_line'] && !$package['is_remote'])
990
-					echo '
1014
+				if (!$package['is_text'] && !$package['is_line'] && !$package['is_remote']) {
1015
+									echo '
991 1016
 		var oPackageToggle_', $section, '_pkg_', $id, ' = new smc_Toggle({
992 1017
 			bToggleEnabled: true,
993 1018
 			bCurrentlyCollapsed: true,
@@ -1002,6 +1027,7 @@  discard block
 block discarded – undo
1002 1027
 				}
1003 1028
 			]
1004 1029
 		});';
1030
+				}
1005 1031
 			}
1006 1032
 		}
1007 1033
 
@@ -1044,9 +1070,10 @@  discard block
 block discarded – undo
1044 1070
 {
1045 1071
 	global $context, $txt, $scripturl;
1046 1072
 
1047
-	if (!empty($context['saved_successful']))
1048
-		echo '
1073
+	if (!empty($context['saved_successful'])) {
1074
+			echo '
1049 1075
 	<div class="infobox">', $txt['settings_saved'], '</div>';
1076
+	}
1050 1077
 
1051 1078
 	echo '
1052 1079
 		<div class="cat_bar">
@@ -1106,8 +1133,9 @@  discard block
 block discarded – undo
1106 1133
 	global $context, $txt;
1107 1134
 
1108 1135
 	// Nothing to do? Brilliant!
1109
-	if (empty($context['package_ftp']))
1110
-		return false;
1136
+	if (empty($context['package_ftp'])) {
1137
+			return false;
1138
+	}
1111 1139
 
1112 1140
 	if (empty($context['package_ftp']['form_elements_only']))
1113 1141
 	{
@@ -1117,19 +1145,21 @@  discard block
 block discarded – undo
1117 1145
 					', $txt['package_ftp_why_file_list'], '
1118 1146
 					<ul style="display: inline;">';
1119 1147
 
1120
-		if (!empty($context['notwritable_files']))
1121
-			foreach ($context['notwritable_files'] as $file)
1148
+		if (!empty($context['notwritable_files'])) {
1149
+					foreach ($context['notwritable_files'] as $file)
1122 1150
 				echo '
1123 1151
 						<li>', $file, '</li>';
1152
+		}
1124 1153
 
1125 1154
 		echo '
1126 1155
 					</ul>';
1127 1156
 
1128
-		if (!$context['server']['is_windows'])
1129
-			echo '
1157
+		if (!$context['server']['is_windows']) {
1158
+					echo '
1130 1159
 					<hr>
1131 1160
 					', $txt['package_chmod_linux'], '<br>
1132 1161
 					<samp># chmod a+w ', implode(' ', $context['notwritable_files']), '</samp>';
1162
+		}
1133 1163
 
1134 1164
 		echo '
1135 1165
 				</div><!-- #need_writable_list -->';
@@ -1142,9 +1172,10 @@  discard block
 block discarded – undo
1142 1172
 					</div>
1143 1173
 				</div>';
1144 1174
 
1145
-	if (!empty($context['package_ftp']['destination']))
1146
-		echo '
1175
+	if (!empty($context['package_ftp']['destination'])) {
1176
+			echo '
1147 1177
 				<form action="', $context['package_ftp']['destination'], '" method="post" accept-charset="', $context['character_set'], '">';
1178
+	}
1148 1179
 
1149 1180
 	echo '
1150 1181
 					<fieldset>
@@ -1178,24 +1209,27 @@  discard block
 block discarded – undo
1178 1209
 					</dl>
1179 1210
 					</fieldset>';
1180 1211
 
1181
-	if (empty($context['package_ftp']['form_elements_only']))
1182
-		echo '
1212
+	if (empty($context['package_ftp']['form_elements_only'])) {
1213
+			echo '
1183 1214
 					<div class="righttext" style="margin: 1ex;">
1184 1215
 						<span id="test_ftp_placeholder_full"></span>
1185 1216
 						<input type="submit" value="', $txt['package_proceed'], '" class="button">
1186 1217
 					</div>';
1218
+	}
1187 1219
 
1188
-	if (!empty($context['package_ftp']['destination']))
1189
-		echo '
1220
+	if (!empty($context['package_ftp']['destination'])) {
1221
+			echo '
1190 1222
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1191 1223
 				</form>';
1224
+	}
1192 1225
 
1193 1226
 	// Hide the details of the list.
1194
-	if (empty($context['package_ftp']['form_elements_only']))
1195
-		echo '
1227
+	if (empty($context['package_ftp']['form_elements_only'])) {
1228
+			echo '
1196 1229
 				<script>
1197 1230
 					document.getElementById(\'need_writable_list\').style.display = \'none\';
1198 1231
 				</script>';
1232
+	}
1199 1233
 
1200 1234
 	// Quick generate the test button.
1201 1235
 	echo '
@@ -1552,9 +1586,10 @@  discard block
 block discarded – undo
1552 1586
 					<td width="30%">
1553 1587
 						<strong>';
1554 1588
 
1555
-		if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
1556
-			echo '
1589
+		if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive')) {
1590
+					echo '
1557 1591
 							<span class="generic_icons folder"></span>';
1592
+		}
1558 1593
 
1559 1594
 		echo '
1560 1595
 							', $name, '
@@ -1581,8 +1616,9 @@  discard block
 block discarded – undo
1581 1616
 					</td>
1582 1617
 				</tr>';
1583 1618
 
1584
-		if (!empty($dir['contents']))
1585
-			template_permission_show_contents($name, $dir['contents'], 1);
1619
+		if (!empty($dir['contents'])) {
1620
+					template_permission_show_contents($name, $dir['contents'], 1);
1621
+		}
1586 1622
 	}
1587 1623
 
1588 1624
 	echo '
@@ -1618,13 +1654,14 @@  discard block
 block discarded – undo
1618 1654
 			</fieldset>';
1619 1655
 
1620 1656
 	// Likely to need FTP?
1621
-	if (empty($context['ftp_connected']))
1622
-		echo '
1657
+	if (empty($context['ftp_connected'])) {
1658
+			echo '
1623 1659
 			<p>
1624 1660
 				', $txt['package_file_perms_ftp_details'], ':
1625 1661
 			</p>
1626 1662
 			', template_control_chmod(), '
1627 1663
 			<div class="noticebox">', $txt['package_file_perms_ftp_retain'], '</div>';
1664
+	}
1628 1665
 
1629 1666
 	echo '
1630 1667
 			<span id="test_ftp_placeholder_full"></span>
@@ -1633,9 +1670,10 @@  discard block
 block discarded – undo
1633 1670
 		</div><!-- .windowbg -->';
1634 1671
 
1635 1672
 	// Any looks fors we've already done?
1636
-	foreach ($context['look_for'] as $path)
1637
-		echo '
1673
+	foreach ($context['look_for'] as $path) {
1674
+			echo '
1638 1675
 		<input type="hidden" name="back_look[]" value="', $path, '">';
1676
+	}
1639 1677
 
1640 1678
 	echo '
1641 1679
 	</form>
@@ -1677,9 +1715,10 @@  discard block
 block discarded – undo
1677 1715
 					<td class="smalltext" width="30%">' . str_repeat('&nbsp;', $level * 5), '
1678 1716
 					', (!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, "'\\") . '\');">' : '';
1679 1717
 
1680
-			if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
1681
-				echo '
1718
+			if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive')) {
1719
+							echo '
1682 1720
 						<span class="generic_icons folder"></span>';
1721
+			}
1683 1722
 
1684 1723
 			echo '
1685 1724
 						', $name, '
@@ -1697,34 +1736,38 @@  discard block
 block discarded – undo
1697 1736
 				</tr>
1698 1737
 				<tr id="insert_div_loc_' . $cur_ident . '" style="display: none;"><td></td></tr>';
1699 1738
 
1700
-			if (!empty($dir['contents']))
1701
-				template_permission_show_contents($ident . '/' . $name, $dir['contents'], $level + 1, !empty($dir['more_files']));
1739
+			if (!empty($dir['contents'])) {
1740
+							template_permission_show_contents($ident . '/' . $name, $dir['contents'], $level + 1, !empty($dir['more_files']));
1741
+			}
1702 1742
 		}
1703 1743
 	}
1704 1744
 
1705 1745
 	// We have more files to show?
1706
-	if ($has_more)
1707
-		echo '
1746
+	if ($has_more) {
1747
+			echo '
1708 1748
 				<tr class="windowbg" id="content_', $js_ident, '_more">
1709 1749
 					<td class="smalltext" width="40%">' . str_repeat('&nbsp;', $level * 5), '
1710 1750
 						&#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;
1711 1751
 					</td>
1712 1752
 					<td colspan="6"></td>
1713 1753
 				</tr>';
1754
+	}
1714 1755
 
1715 1756
 	if ($drawn_div)
1716 1757
 	{
1717 1758
 		// Hide anything too far down the tree.
1718 1759
 		$isFound = false;
1719
-		foreach ($context['look_for'] as $tree)
1720
-			if (substr($tree, 0, strlen($ident)) == $ident)
1760
+		foreach ($context['look_for'] as $tree) {
1761
+					if (substr($tree, 0, strlen($ident)) == $ident)
1721 1762
 				$isFound = true;
1763
+		}
1722 1764
 
1723
-		if ($level > 1 && !$isFound)
1724
-			echo '
1765
+		if ($level > 1 && !$isFound) {
1766
+					echo '
1725 1767
 		<script>
1726 1768
 			expandFolder(\'', $js_ident, '\', \'\');
1727 1769
 		</script>';
1770
+		}
1728 1771
 	}
1729 1772
 }
1730 1773
 
@@ -1743,11 +1786,12 @@  discard block
 block discarded – undo
1743 1786
 				<h3 class="catbg">', $txt['package_file_perms_applying'], '</h3>
1744 1787
 			</div>';
1745 1788
 
1746
-	if (!empty($context['skip_ftp']))
1747
-		echo '
1789
+	if (!empty($context['skip_ftp'])) {
1790
+			echo '
1748 1791
 			<div class="errorbox">
1749 1792
 				', $txt['package_file_perms_skipping_ftp'], '
1750 1793
 			</div>';
1794
+	}
1751 1795
 
1752 1796
 	// How many have we done?
1753 1797
 	$remaining_items = count($context['method'] == 'individual' ? $context['to_process'] : $context['directory_list']);
@@ -1785,28 +1829,31 @@  discard block
 block discarded – undo
1785 1829
 				<br>';
1786 1830
 
1787 1831
 	// Put out the right hidden data.
1788
-	if ($context['method'] == 'individual')
1789
-		echo '
1832
+	if ($context['method'] == 'individual') {
1833
+			echo '
1790 1834
 				<input type="hidden" name="custom_value" value="', $context['custom_value'], '">
1791 1835
 				<input type="hidden" name="totalItems" value="', $context['total_items'], '">
1792 1836
 				<input type="hidden" name="toProcess" value="', $context['to_process_encode'], '">';
1793
-	else
1794
-		echo '
1837
+	} else {
1838
+			echo '
1795 1839
 				<input type="hidden" name="predefined" value="', $context['predefined_type'], '">
1796 1840
 				<input type="hidden" name="fileOffset" value="', $context['file_offset'], '">
1797 1841
 				<input type="hidden" name="totalItems" value="', $context['total_items'], '">
1798 1842
 				<input type="hidden" name="dirList" value="', $context['directory_list_encode'], '">
1799 1843
 				<input type="hidden" name="specialFiles" value="', $context['special_files_encode'], '">';
1844
+	}
1800 1845
 
1801 1846
 	// Are we not using FTP for whatever reason.
1802
-	if (!empty($context['skip_ftp']))
1803
-		echo '
1847
+	if (!empty($context['skip_ftp'])) {
1848
+			echo '
1804 1849
 				<input type="hidden" name="skip_ftp" value="1">';
1850
+	}
1805 1851
 
1806 1852
 	// Retain state.
1807
-	foreach ($context['back_look_data'] as $path)
1808
-		echo '
1853
+	foreach ($context['back_look_data'] as $path) {
1854
+			echo '
1809 1855
 				<input type="hidden" name="back_look[]" value="', $path, '">';
1856
+	}
1810 1857
 
1811 1858
 	echo '
1812 1859
 				<input type="hidden" name="method" value="', $context['method'], '">
Please login to merge, or discard this patch.
Themes/default/ManageMembergroups.template.php 1 patch
Braces   +104 added lines, -74 removed lines patch added patch discarded remove patch
@@ -54,9 +54,10 @@  discard block
 block discarded – undo
54 54
 							<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
55 55
 							<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0" checked onclick="swapPostGroup(0);">', $txt['membergroups_group_type_private'], '</label><br>';
56 56
 
57
-		if ($context['allow_protected'])
58
-			echo '
57
+		if ($context['allow_protected']) {
58
+					echo '
59 59
 							<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1" onclick="swapPostGroup(0);">', $txt['membergroups_group_type_protected'], '</label><br>';
60
+		}
60 61
 
61 62
 		echo '
62 63
 							<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2" onclick="swapPostGroup(0);">', $txt['membergroups_group_type_request'], '</label><br>
@@ -66,14 +67,15 @@  discard block
 block discarded – undo
66 67
 					</dd>';
67 68
 	}
68 69
 
69
-	if ($context['post_group'] || $context['undefined_group'])
70
-		echo '
70
+	if ($context['post_group'] || $context['undefined_group']) {
71
+			echo '
71 72
 					<dt id="min_posts_text">
72 73
 						<strong>', $txt['membergroups_min_posts'], ':</strong>
73 74
 					</dt>
74 75
 					<dd>
75 76
 						<input type="number" name="min_posts" id="min_posts_input" size="5">
76 77
 					</dd>';
78
+	}
77 79
 
78 80
 	if (!$context['post_group'] || !empty($modSettings['permission_enable_postgroups']))
79 81
 	{
@@ -91,9 +93,10 @@  discard block
 block discarded – undo
91 93
 								<option value="-1">', $txt['membergroups_guests'], '</option>
92 94
 								<option value="0" selected>', $txt['membergroups_members'], '</option>';
93 95
 
94
-		foreach ($context['groups'] as $group)
95
-			echo '
96
+		foreach ($context['groups'] as $group) {
97
+					echo '
96 98
 								<option value="', $group['id'], '">', $group['name'], '</option>';
99
+		}
97 100
 
98 101
 		echo '
99 102
 							</select>
@@ -104,9 +107,10 @@  discard block
 block discarded – undo
104 107
 								<option value="-1">', $txt['membergroups_guests'], '</option>
105 108
 								<option value="0" selected>', $txt['membergroups_members'], '</option>';
106 109
 
107
-		foreach ($context['groups'] as $group)
108
-			echo '
110
+		foreach ($context['groups'] as $group) {
111
+					echo '
109 112
 								<option value="', $group['id'], '">', $group['name'], '</option>';
113
+		}
110 114
 
111 115
 		echo '
112 116
 							</select>
@@ -138,8 +142,8 @@  discard block
 block discarded – undo
138 142
 				<input type="submit" value="', $txt['membergroups_add_group'], '" class="button">
139 143
 			</div><!-- .windowbg -->';
140 144
 
141
-	if ($context['undefined_group'])
142
-		echo '
145
+	if ($context['undefined_group']) {
146
+			echo '
143 147
 			<script>
144 148
 				function swapPostGroup(isChecked)
145 149
 				{
@@ -149,6 +153,7 @@  discard block
 block discarded – undo
149 153
 				}
150 154
 				swapPostGroup(', $context['post_group'] ? 'true' : 'false', ');
151 155
 			</script>';
156
+	}
152 157
 
153 158
 	echo '
154 159
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -178,14 +183,15 @@  discard block
 block discarded – undo
178 183
 						<input type="text" name="group_name" id="group_name_input" value="', $context['group']['editable_name'], '" size="30">
179 184
 					</dd>';
180 185
 
181
-	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
182
-		echo '
186
+	if ($context['group']['id'] != 3 && $context['group']['id'] != 4) {
187
+			echo '
183 188
 					<dt id="group_desc_text">
184 189
 						<label for="group_desc_input"><strong>', $txt['membergroups_edit_desc'], ':</strong></label>
185 190
 					</dt>
186 191
 					<dd>
187 192
 						<textarea name="group_desc" id="group_desc_input" rows="4" cols="40">', $context['group']['description'], '</textarea>
188 193
 					</dd>';
194
+	}
189 195
 
190 196
 	// Group type...
191 197
 	if ($context['group']['allow_post_group'])
@@ -199,9 +205,10 @@  discard block
 block discarded – undo
199 205
 							<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
200 206
 							<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0"', !$context['group']['is_post_group'] && $context['group']['type'] == 0 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_private'], '</label><br>';
201 207
 
202
-		if ($context['group']['allow_protected'])
203
-			echo '
208
+		if ($context['group']['allow_protected']) {
209
+					echo '
204 210
 							<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1"', $context['group']['type'] == 1 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_protected'], '</label><br>';
211
+		}
205 212
 
206 213
 		echo '
207 214
 							<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2"', $context['group']['type'] == 2 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_request'], '</label><br>
@@ -211,8 +218,8 @@  discard block
 block discarded – undo
211 218
 					</dd>';
212 219
 	}
213 220
 
214
-	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
215
-		echo '
221
+	if ($context['group']['id'] != 3 && $context['group']['id'] != 4) {
222
+			echo '
216 223
 					<dt id="group_moderators_text">
217 224
 						<label for="group_moderators"><strong>', $txt['moderators'], ':</strong></label>
218 225
 					</dt>
@@ -230,6 +237,7 @@  discard block
 block discarded – undo
230 237
 							<option value="2"', $context['group']['hidden'] == 2 ? ' selected' : '', '>', $txt['membergroups_edit_hidden_all'], '</option>
231 238
 						</select>
232 239
 					</dd>';
240
+	}
233 241
 
234 242
 	// Can they inherit permissions?
235 243
 	if ($context['group']['id'] > 1 && $context['group']['id'] != 3)
@@ -246,9 +254,10 @@  discard block
 block discarded – undo
246 254
 							<option value="0"', $context['group']['inherited_from'] == 0 ? ' selected' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_members'], '</option>';
247 255
 
248 256
 		// For all the inheritable groups show an option.
249
-		foreach ($context['inheritable_groups'] as $id => $group)
250
-			echo '
257
+		foreach ($context['inheritable_groups'] as $id => $group) {
258
+					echo '
251 259
 							<option value="', $id, '"', $context['group']['inherited_from'] == $id ? ' selected' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $group, '</option>';
260
+		}
252 261
 
253 262
 		echo '
254 263
 						</select>
@@ -256,8 +265,8 @@  discard block
 block discarded – undo
256 265
 					</dd>';
257 266
 	}
258 267
 
259
-	if ($context['group']['allow_post_group'])
260
-		echo '
268
+	if ($context['group']['allow_post_group']) {
269
+			echo '
261 270
 
262 271
 					<dt id="min_posts_text">
263 272
 						<label for="min_posts_input"><strong>', $txt['membergroups_min_posts'], ':</strong></label>
@@ -265,6 +274,7 @@  discard block
 block discarded – undo
265 274
 					<dd>
266 275
 						<input type="number" name="min_posts" id="min_posts_input"', $context['group']['is_post_group'] ? ' value="' . $context['group']['min_posts'] . '"' : '', ' size="6">
267 276
 					</dd>';
277
+	}
268 278
 
269 279
 	echo '
270 280
 					<dt>
@@ -294,9 +304,10 @@  discard block
 block discarded – undo
294 304
 						<select name="icon_image" id="icon_image_input">';
295 305
 
296 306
 		// For every possible icon, create an option.
297
-		foreach ($context['possible_icons'] as $icon)
298
-			echo '
307
+		foreach ($context['possible_icons'] as $icon) {
308
+					echo '
299 309
 							<option value="', $icon, '"', $context['group']['icon_image'] == $icon ? ' selected' : '', '>', $icon, '</option>';
310
+		}
300 311
 
301 312
 		echo '
302 313
 						</select>
@@ -305,9 +316,10 @@  discard block
 block discarded – undo
305 316
 	}
306 317
 
307 318
 	// No? Hide the entire control.
308
-	else
309
-		echo '
319
+	else {
320
+			echo '
310 321
 					<input type="hidden" name="icon_image" value="">';
322
+	}
311 323
 
312 324
 	echo '
313 325
 					<dt>
@@ -319,8 +331,8 @@  discard block
 block discarded – undo
319 331
 					</dd>';
320 332
 
321 333
 	// Force 2FA for this membergroup?
322
-	if (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] == 2)
323
-		echo '
334
+	if (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] == 2) {
335
+			echo '
324 336
 					<dt>
325 337
 						<label for="group_tfa_force_input"><strong>', $txt['membergroups_tfa_force'], ':</strong></label><br>
326 338
 						<span class="smalltext">', $txt['membergroups_tfa_force_note'], '</span>
@@ -328,6 +340,7 @@  discard block
 block discarded – undo
328 340
 					<dd>
329 341
 						<input type="checkbox" name="group_tfa_force"', $context['group']['tfa_required'] ? ' checked' : '', '>
330 342
 					</dd>';
343
+	}
331 344
 
332 345
 	if (!empty($context['categories']))
333 346
 	{
@@ -338,11 +351,11 @@  discard block
 block discarded – undo
338 351
 					</dt>
339 352
 					<dd>';
340 353
 
341
-		if (!empty($context['can_manage_boards']))
342
-			echo $txt['membergroups_can_manage_access'];
343
-
344
-		else
345
-			template_add_edit_group_boards_list();
354
+		if (!empty($context['can_manage_boards'])) {
355
+					echo $txt['membergroups_can_manage_access'];
356
+		} else {
357
+					template_add_edit_group_boards_list();
358
+		}
346 359
 
347 360
 		echo '
348 361
 					</dd>';
@@ -371,20 +384,21 @@  discard block
 block discarded – undo
371 384
 			sItemListContainerId: \'moderator_container\',
372 385
 			aListItems: [';
373 386
 
374
-	foreach ($context['group']['moderators'] as $id_member => $member_name)
375
-		echo '
387
+	foreach ($context['group']['moderators'] as $id_member => $member_name) {
388
+			echo '
376 389
 				{
377 390
 					sItemId: ', JavaScriptEscape($id_member), ',
378 391
 					sItemName: ', JavaScriptEscape($member_name), '
379 392
 				}', $id_member == $context['group']['last_moderator_id'] ? '' : ',';
393
+	}
380 394
 
381 395
 	echo '
382 396
 			]
383 397
 		});
384 398
 	</script>';
385 399
 
386
-	if ($context['group']['allow_post_group'])
387
-		echo '
400
+	if ($context['group']['allow_post_group']) {
401
+			echo '
388 402
 	<script>
389 403
 		function swapPostGroup(isChecked)
390 404
 		{
@@ -432,7 +446,8 @@  discard block
 block discarded – undo
432 446
 
433 447
 		swapPostGroup(', $context['group']['is_post_group'] ? 'true' : 'false', ');
434 448
 	</script>';
435
-}
449
+	}
450
+	}
436 451
 
437 452
 /**
438 453
  * The template for determining which boards a group has access to.
@@ -450,13 +465,13 @@  discard block
 block discarded – undo
450 465
 
451 466
 	foreach ($context['categories'] as $category)
452 467
 	{
453
-		if (empty($modSettings['deny_boards_access']))
454
-			echo '
468
+		if (empty($modSettings['deny_boards_access'])) {
469
+					echo '
455 470
 									<li class="category">
456 471
 										<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \'new_group\'); return false;"><strong>', $category['name'], '</strong></a>
457 472
 										<ul>';
458
-		else
459
-			echo '
473
+		} else {
474
+					echo '
460 475
 									<li class="category">
461 476
 										<strong>', $category['name'], '</strong>
462 477
 										<span class="select_all_box">
@@ -469,16 +484,17 @@  discard block
 block discarded – undo
469 484
 											</select>
470 485
 										</span>
471 486
 										<ul id="boards_list_', $category['id'], '">';
487
+		}
472 488
 
473 489
 		foreach ($category['boards'] as $board)
474 490
 		{
475
-			if (empty($modSettings['deny_boards_access']))
476
-				echo '
491
+			if (empty($modSettings['deny_boards_access'])) {
492
+							echo '
477 493
 											<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
478 494
 												<input type="checkbox" name="boardaccess[', $board['id'], ']" id="brd', $board['id'], '" value="allow"', $board['allow'] ? ' checked' : '', '> <label for="brd', $board['id'], '">', $board['name'], '</label>
479 495
 											</li>';
480
-			else
481
-				echo '
496
+			} else {
497
+							echo '
482 498
 											<li class="board" style="width:100%">
483 499
 												<span style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">', $board['name'], ': </span>
484 500
 												<span style="width:50%;float:right">
@@ -487,6 +503,7 @@  discard block
 block discarded – undo
487 503
 													<input type="radio" name="boardaccess[', $board['id'], ']" id="deny_brd', $board['id'], '" value="deny"', $board['deny'] ? ' checked' : '', '> <label for="deny_brd', $board['id'], '">', $txt['permissions_option_deny'], '</label>
488 504
 												</span>
489 505
 											</li>';
506
+			}
490 507
 		}
491 508
 
492 509
 		echo '
@@ -497,14 +514,14 @@  discard block
 block discarded – undo
497 514
 	echo '
498 515
 								</ul>';
499 516
 
500
-	if (empty($modSettings['deny_boards_access']))
501
-		echo '
517
+	if (empty($modSettings['deny_boards_access'])) {
518
+			echo '
502 519
 								<br class="clear"><br>
503 520
 								<input type="checkbox" id="checkall_check" onclick="invertAll(this, this.form, \'boardaccess\');">
504 521
 								<label for="checkall_check"><em>', $txt['check_all'], '</em></label>
505 522
 							</fieldset>';
506
-	else
507
-		echo '
523
+	} else {
524
+			echo '
508 525
 								<br class="clear">
509 526
 								<span class="select_all_box">
510 527
 									<em>', $txt['all'], ': </em>
@@ -520,15 +537,17 @@  discard block
 block discarded – undo
520 537
 									});
521 538
 								});
522 539
 							</script>';
540
+	}
523 541
 
524
-	if ($collapse)
525
-		echo '
542
+	if ($collapse) {
543
+			echo '
526 544
 							<a href="javascript:void(0);" onclick="document.getElementById(\'visible_boards\').classList.remove(\'hidden\'); document.getElementById(\'visible_boards_link\').classList.add(\'hidden\'); return false;" id="visible_boards_link" class="hidden">[ ', $txt['membergroups_select_visible_boards'], ' ]</a>
527 545
 							<script>
528 546
 								document.getElementById("visible_boards_link").classList.remove(\'hidden\');
529 547
 								document.getElementById("visible_boards").classList.add(\'hidden\');
530 548
 							</script>';
531
-}
549
+	}
550
+	}
532 551
 
533 552
 /**
534 553
  * Templatine for viewing the members of a group.
@@ -552,14 +571,15 @@  discard block
 block discarded – undo
552 571
 					</dd>';
553 572
 
554 573
 	// Any description to show?
555
-	if (!empty($context['group']['description']))
556
-		echo '
574
+	if (!empty($context['group']['description'])) {
575
+			echo '
557 576
 					<dt>
558 577
 						<strong>' . $txt['membergroups_members_description'] . ':</strong>
559 578
 					</dt>
560 579
 					<dd>
561 580
 						', $context['group']['description'], '
562 581
 					</dd>';
582
+	}
563 583
 
564 584
 	echo '
565 585
 					<dt>
@@ -573,8 +593,9 @@  discard block
 block discarded – undo
573 593
 	if (!empty($context['group']['moderators']))
574 594
 	{
575 595
 		$moderators = array();
576
-		foreach ($context['group']['moderators'] as $moderator)
577
-			$moderators[] = '<a href="' . $scripturl . '?action=profile;u=' . $moderator['id'] . '">' . $moderator['name'] . '</a>';
596
+		foreach ($context['group']['moderators'] as $moderator) {
597
+					$moderators[] = '<a href="' . $scripturl . '?action=profile;u=' . $moderator['id'] . '">' . $moderator['name'] . '</a>';
598
+		}
578 599
 
579 600
 		echo '
580 601
 					<dt>
@@ -599,9 +620,10 @@  discard block
 block discarded – undo
599 620
 					<tr class="title_bar">
600 621
 						<th><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=name', $context['sort_by'] == 'name' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['name'], $context['sort_by'] == 'name' ? ' <span class="generic_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a></th>';
601 622
 
602
-	if ($context['can_send_email'])
603
-		echo '
623
+	if ($context['can_send_email']) {
624
+			echo '
604 625
 						<th><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=email', $context['sort_by'] == 'email' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['email'], $context['sort_by'] == 'email' ? ' <span class="generic_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a></th>';
626
+	}
605 627
 
606 628
 	echo '
607 629
 						<th><a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=active', $context['sort_by'] == 'active' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['membergroups_members_last_active'], $context['sort_by'] == 'active' ? '<span class="generic_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a></th>
@@ -610,20 +632,22 @@  discard block
 block discarded – undo
610 632
 							<a href="', $scripturl, '?action=', $context['current_action'], (isset($context['admin_area']) ? ';area=' . $context['admin_area'] : ''), ';sa=members;start=', $context['start'], ';sort=posts', $context['sort_by'] == 'posts' && $context['sort_direction'] == 'up' ? ';desc' : '', ';group=', $context['group']['id'], '">', $txt['posts'], $context['sort_by'] == 'posts' ? ' <span class="generic_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
611 633
 						</th>';
612 634
 
613
-	if (!empty($context['group']['assignable']))
614
-		echo '
635
+	if (!empty($context['group']['assignable'])) {
636
+			echo '
615 637
 						<th style="width: 4%"><input type="checkbox" onclick="invertAll(this, this.form);"></th>';
638
+	}
616 639
 
617 640
 	echo '
618 641
 					</tr>
619 642
 				</thead>
620 643
 				<tbody>';
621 644
 
622
-	if (empty($context['members']))
623
-		echo '
645
+	if (empty($context['members'])) {
646
+			echo '
624 647
 					<tr class="windowbg">
625 648
 						<td colspan="6">', $txt['membergroups_members_no_members'], '</td>
626 649
 					</tr>';
650
+	}
627 651
 
628 652
 	foreach ($context['members'] as $member)
629 653
 	{
@@ -631,20 +655,22 @@  discard block
 block discarded – undo
631 655
 					<tr class="windowbg">
632 656
 						<td>', $member['name'], '</td>';
633 657
 
634
-		if ($context['can_send_email'])
635
-			echo '
658
+		if ($context['can_send_email']) {
659
+					echo '
636 660
 						<td>
637 661
 								<a href="mailto:', $member['email'], '">', $member['email'], '</a>
638 662
 						</td>';
663
+		}
639 664
 
640 665
 		echo '
641 666
 						<td>', $member['last_online'], '</td>
642 667
 						<td>', $member['registered'], '</td>
643 668
 						<td', empty($context['group']['assignable']) ? ' colspan="2"' : '', '>', $member['posts'], '</td>';
644 669
 
645
-		if (!empty($context['group']['assignable']))
646
-			echo '
670
+		if (!empty($context['group']['assignable'])) {
671
+					echo '
647 672
 						<td style="width: 4%"><input type="checkbox" name="rem[]" value="', $member['id'], '" ', ($context['user']['id'] == $member['id'] && $context['group']['id'] == 1 ? 'onclick="if (this.checked) return confirm(\'' . $txt['membergroups_members_deadmin_confirm'] . '\')" ' : ''), '/></td>';
673
+		}
648 674
 
649 675
 		echo '
650 676
 					</tr>';
@@ -654,11 +680,12 @@  discard block
 block discarded – undo
654 680
 				</tbody>
655 681
 			</table>';
656 682
 
657
-	if (!empty($context['group']['assignable']))
658
-		echo '
683
+	if (!empty($context['group']['assignable'])) {
684
+			echo '
659 685
 			<div class="floatright">
660 686
 				<input type="submit" name="remove" value="', $txt['membergroups_members_remove'], '" class="button ">
661 687
 			</div>';
688
+	}
662 689
 
663 690
 	echo '
664 691
 			<div class="pagesection flow_hidden">
@@ -666,8 +693,8 @@  discard block
 block discarded – undo
666 693
 			</div>
667 694
 			<br>';
668 695
 
669
-	if (!empty($context['group']['assignable']))
670
-		echo '
696
+	if (!empty($context['group']['assignable'])) {
697
+			echo '
671 698
 			<div class="cat_bar">
672 699
 				<h3 class="catbg">', $txt['membergroups_members_add_title'], '</h3>
673 700
 			</div>
@@ -683,14 +710,15 @@  discard block
 block discarded – undo
683 710
 				</dl>
684 711
 				<input type="submit" name="add" value="', $txt['membergroups_members_add'], '" class="button">
685 712
 			</div>';
713
+	}
686 714
 
687 715
 	echo '
688 716
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
689 717
 			<input type="hidden" name="', $context['mod-mgm_token_var'], '" value="', $context['mod-mgm_token'], '">
690 718
 		</form>';
691 719
 
692
-	if (!empty($context['group']['assignable']))
693
-		echo '
720
+	if (!empty($context['group']['assignable'])) {
721
+			echo '
694 722
 	<script>
695 723
 		var oAddMemberSuggest = new smc_AutoSuggest({
696 724
 			sSelf: \'oAddMemberSuggest\',
@@ -706,7 +734,8 @@  discard block
 block discarded – undo
706 734
 			sItemListContainerId: \'toAddItemContainer\'
707 735
 		});
708 736
 	</script>';
709
-}
737
+	}
738
+	}
710 739
 
711 740
 /**
712 741
  * Allow the moderator to enter a reason to each user being rejected.
@@ -726,8 +755,8 @@  discard block
 block discarded – undo
726 755
 				<dl class="settings">';
727 756
 
728 757
 	// Loop through and print out a reason box for each...
729
-	foreach ($context['group_requests'] as $request)
730
-		echo '
758
+	foreach ($context['group_requests'] as $request) {
759
+			echo '
731 760
 					<dt>
732 761
 						<strong>', sprintf($txt['mc_groupr_reason_desc'], $request['member_link'], $request['group_link']), ':</strong>
733 762
 					</dt>
@@ -735,6 +764,7 @@  discard block
 block discarded – undo
735 764
 						<input type="hidden" name="groupr[]" value="', $request['id'], '">
736 765
 						<textarea name="groupreason[', $request['id'], ']" rows="3" cols="40"></textarea>
737 766
 					</dd>';
767
+	}
738 768
 
739 769
 	echo '
740 770
 				</dl>
Please login to merge, or discard this patch.
Themes/default/Calendar.template.php 1 patch
Braces   +222 added lines, -162 removed lines patch added patch discarded remove patch
@@ -22,30 +22,32 @@  discard block
 block discarded – undo
22 22
 		<div id="calendar">';
23 23
 
24 24
 	// Show the mini-blocks if they're enabled.
25
-	if (empty($context['blocks_disabled']))
26
-		echo '
25
+	if (empty($context['blocks_disabled'])) {
26
+			echo '
27 27
 			<div id="month_grid">
28 28
 				', template_show_month_grid('prev', true), '
29 29
 				', template_show_month_grid('current', true), '
30 30
 				', template_show_month_grid('next', true), '
31 31
 			</div>';
32
+	}
32 33
 
33 34
 	// What view are we showing?
34
-	if ($context['calendar_view'] == 'viewlist')
35
-		echo '
35
+	if ($context['calendar_view'] == 'viewlist') {
36
+			echo '
36 37
 			<div id="main_grid">
37 38
 				', template_show_upcoming_list('main'), '
38 39
 			</div>';
39
-	elseif ($context['calendar_view'] == 'viewweek')
40
-		echo '
40
+	} elseif ($context['calendar_view'] == 'viewweek') {
41
+			echo '
41 42
 			<div id="main_grid">
42 43
 				', template_show_week_grid('main'), '
43 44
 			</div>';
44
-	else
45
-		echo '
45
+	} else {
46
+			echo '
46 47
 			<div id="main_grid">
47 48
 				', template_show_month_grid('main'), '
48 49
 			</div>';
50
+	}
49 51
 
50 52
 	// Close our wrapper.
51 53
 	echo '
@@ -64,20 +66,22 @@  discard block
 block discarded – undo
64 66
 	global $context, $scripturl, $txt;
65 67
 
66 68
 	// Bail out if we have nothing to work with
67
-	if (!isset($context['calendar_grid_' . $grid_name]))
68
-		return false;
69
+	if (!isset($context['calendar_grid_' . $grid_name])) {
70
+			return false;
71
+	}
69 72
 
70 73
 	// Protect programmer sanity
71 74
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
72 75
 
73 76
 	// Do we want a title?
74
-	if (empty($calendar_data['disable_title']))
75
-		echo '
77
+	if (empty($calendar_data['disable_title'])) {
78
+			echo '
76 79
 			<div class="cat_bar">
77 80
 				<h3 class="catbg centertext largetext">
78 81
 					<a href="', $scripturl, '?action=calendar;viewlist;year=', $calendar_data['start_year'], ';month=', $calendar_data['start_month'], ';day=', $calendar_data['start_day'], '">', $txt['calendar_upcoming'], '</a>
79 82
 				</h3>
80 83
 			</div>';
84
+	}
81 85
 
82 86
 	// Give the user some controls to work with
83 87
 	template_calendar_top($calendar_data);
@@ -100,11 +104,13 @@  discard block
 block discarded – undo
100 104
 					<li class="windowbg">
101 105
 						<strong class="event_title">', $event['link'], '</strong>';
102 106
 
103
-				if ($event['can_edit'])
104
-					echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
107
+				if ($event['can_edit']) {
108
+									echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
109
+				}
105 110
 
106
-				if ($event['can_export'])
107
-					echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
111
+				if ($event['can_export']) {
112
+									echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
113
+				}
108 114
 
109 115
 				echo '
110 116
 						<br>';
@@ -112,14 +118,14 @@  discard block
 block discarded – undo
112 118
 				if (!empty($event['allday']))
113 119
 				{
114 120
 					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
115
-				}
116
-				else
121
+				} else
117 122
 				{
118 123
 					// Display event info relative to user's local timezone
119 124
 					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
120 125
 
121
-					if ($event['start_date_local'] != $event['end_date_local'])
122
-						echo trim($event['end_date_local']) . ', ';
126
+					if ($event['start_date_local'] != $event['end_date_local']) {
127
+											echo trim($event['end_date_local']) . ', ';
128
+					}
123 129
 
124 130
 					echo trim($event['end_time_local']);
125 131
 
@@ -128,23 +134,27 @@  discard block
 block discarded – undo
128 134
 					{
129 135
 						echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
130 136
 
131
-						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
132
-							echo trim($event['start_date_orig']), ', ';
137
+						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) {
138
+													echo trim($event['start_date_orig']), ', ';
139
+						}
133 140
 
134 141
 						echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
135 142
 
136
-						if ($event['start_date_orig'] != $event['end_date_orig'])
137
-							echo trim($event['end_date_orig']) . ', ';
143
+						if ($event['start_date_orig'] != $event['end_date_orig']) {
144
+													echo trim($event['end_date_orig']) . ', ';
145
+						}
138 146
 
139 147
 						echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
140 148
 					}
141 149
 					// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
142
-					else
143
-						echo ' ', $event['tz_abbrev'], '</time>';
150
+					else {
151
+											echo ' ', $event['tz_abbrev'], '</time>';
152
+					}
144 153
 				}
145 154
 
146
-				if (!empty($event['location']))
147
-					echo '<br>', $event['location'];
155
+				if (!empty($event['location'])) {
156
+									echo '<br>', $event['location'];
157
+				}
148 158
 
149 159
 				echo '
150 160
 					</li>';
@@ -176,8 +186,9 @@  discard block
 block discarded – undo
176 186
 
177 187
 			$birthdays = array();
178 188
 
179
-			foreach ($date as $member)
180
-				$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
189
+			foreach ($date as $member) {
190
+							$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
191
+			}
181 192
 
182 193
 			echo implode(', ', $birthdays);
183 194
 
@@ -208,8 +219,9 @@  discard block
 block discarded – undo
208 219
 			$date_local = $date['date_local'];
209 220
 			unset($date['date_local']);
210 221
 
211
-			foreach ($date as $holiday)
212
-				$holidays[] = $holiday . ' (' . $date_local . ')';
222
+			foreach ($date as $holiday) {
223
+							$holidays[] = $holiday . ' (' . $date_local . ')';
224
+			}
213 225
 		}
214 226
 
215 227
 		echo implode(', ', $holidays);
@@ -233,17 +245,19 @@  discard block
 block discarded – undo
233 245
 	global $context, $txt, $scripturl, $modSettings;
234 246
 
235 247
 	// If the grid doesn't exist, no point in proceeding.
236
-	if (!isset($context['calendar_grid_' . $grid_name]))
237
-		return false;
248
+	if (!isset($context['calendar_grid_' . $grid_name])) {
249
+			return false;
250
+	}
238 251
 
239 252
 	// A handy little pointer variable.
240 253
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
241 254
 
242 255
 	// Some conditions for whether or not we should show the week links *here*.
243
-	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false)))
244
-		$show_week_links = true;
245
-	else
246
-		$show_week_links = false;
256
+	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) {
257
+			$show_week_links = true;
258
+	} else {
259
+			$show_week_links = false;
260
+	}
247 261
 
248 262
 	// Assuming that we've not disabled it, show the title block!
249 263
 	if (empty($calendar_data['disable_title']))
@@ -253,18 +267,20 @@  discard block
 block discarded – undo
253 267
 				<h3 class="catbg centertext largetext">';
254 268
 
255 269
 		// Previous Link: If we're showing prev / next and it's not a mini-calendar.
256
-		if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
257
-			echo '
270
+		if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false) {
271
+					echo '
258 272
 					<span class="floatleft">
259 273
 						<a href="', $calendar_data['previous_calendar']['href'], '">&#171;</a>
260 274
 					</span>';
275
+		}
261 276
 
262 277
 		// Next Link: if we're showing prev / next and it's not a mini-calendar.
263
-		if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
264
-			echo '
278
+		if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false) {
279
+					echo '
265 280
 					<span class="floatright">
266 281
 						<a href="', $calendar_data['next_calendar']['href'], '">&#187;</a>
267 282
 					</span>';
283
+		}
268 284
 
269 285
 		// Arguably the most exciting part, the title!
270 286
 		echo '
@@ -274,8 +290,9 @@  discard block
 block discarded – undo
274 290
 	}
275 291
 
276 292
 	// Show the controls on main grids
277
-	if ($is_mini === false)
278
-		template_calendar_top($calendar_data);
293
+	if ($is_mini === false) {
294
+			template_calendar_top($calendar_data);
295
+	}
279 296
 
280 297
 	// Finally, the main calendar table.
281 298
 	echo '
@@ -288,14 +305,16 @@  discard block
 block discarded – undo
288 305
 				<tr>';
289 306
 
290 307
 		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
291
-		if ($show_week_links === true)
292
-			echo '
308
+		if ($show_week_links === true) {
309
+					echo '
293 310
 					<th></th>';
311
+		}
294 312
 
295 313
 		// Now, loop through each actual day of the week.
296
-		foreach ($calendar_data['week_days'] as $day)
297
-			echo '
314
+		foreach ($calendar_data['week_days'] as $day) {
315
+					echo '
298 316
 					<th class="days" scope="col">', !empty($calendar_data['short_day_titles']) || $is_mini === true ? $txt['days_short'][$day] : $txt['days'][$day], '</th>';
317
+		}
299 318
 
300 319
 		echo '
301 320
 				</tr>';
@@ -313,11 +332,12 @@  discard block
 block discarded – undo
313 332
 				<tr class="days_wrapper">';
314 333
 
315 334
 		// This is where we add the actual week link, if enabled on this location.
316
-		if ($show_week_links === true)
317
-			echo '
335
+		if ($show_week_links === true) {
336
+					echo '
318 337
 					<td class="windowbg weeks">
319 338
 						<a href="', $scripturl, '?action=calendar;viewweek;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $week['days'][0]['day'], '" title="', $txt['calendar_view_week'], '">&#187;</a>
320 339
 					</td>';
340
+		}
321 341
 
322 342
 		// Now loop through each day in the week we're on.
323 343
 		foreach ($week['days'] as $day)
@@ -333,27 +353,29 @@  discard block
 block discarded – undo
333 353
 				// Additional classes are given for events, holidays, and birthdays.
334 354
 				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
335 355
 				{
336
-					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3)))
337
-						$classes[] = 'events';
338
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3)))
339
-						$classes[] = 'events';
356
+					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) {
357
+											$classes[] = 'events';
358
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) {
359
+											$classes[] = 'events';
360
+					}
340 361
 				}
341 362
 				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
342 363
 				{
343
-					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3)))
344
-						$classes[] = 'holidays';
345
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3)))
346
-						$classes[] = 'holidays';
364
+					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) {
365
+											$classes[] = 'holidays';
366
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) {
367
+											$classes[] = 'holidays';
368
+					}
347 369
 				}
348 370
 				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
349 371
 				{
350
-					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3)))
351
-						$classes[] = 'birthdays';
352
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3)))
353
-						$classes[] = 'birthdays';
372
+					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) {
373
+											$classes[] = 'birthdays';
374
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) {
375
+											$classes[] = 'birthdays';
376
+					}
354 377
 				}
355
-			}
356
-			else
378
+			} else
357 379
 			{
358 380
 				// Default Classes (either compact or comfortable and disabled).
359 381
 				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
@@ -371,25 +393,27 @@  discard block
 block discarded – undo
371 393
 				$title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : '';
372 394
 
373 395
 				// The actual day number - be it a link, or just plain old text!
374
-				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
375
-					echo '
396
+				if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
397
+									echo '
376 398
 						<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
377
-				elseif ($is_mini)
378
-					echo '
399
+				} elseif ($is_mini) {
400
+									echo '
379 401
 						<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
380
-				else
381
-					echo '
402
+				} else {
403
+									echo '
382 404
 						<span class="day_text">', $title_prefix, $day['day'], '</span>';
405
+				}
383 406
 
384 407
 				// A lot of stuff, we're not showing on mini-calendars to conserve space.
385 408
 				if ($is_mini === false)
386 409
 				{
387 410
 					// Holidays are always fun, let's show them!
388
-					if (!empty($day['holidays']))
389
-						echo '
411
+					if (!empty($day['holidays'])) {
412
+											echo '
390 413
 						<div class="smalltext holiday">
391 414
 							<span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '
392 415
 						</div>';
416
+					}
393 417
 
394 418
 					// Happy Birthday Dear Member!
395 419
 					if (!empty($day['birthdays']))
@@ -407,15 +431,17 @@  discard block
 block discarded – undo
407 431
 							echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', ';
408 432
 
409 433
 							// 9...10! Let's stop there.
410
-							if ($birthday_count == 10 && $use_js_hide)
411
-								// !!TODO - Inline CSS and JavaScript should be moved.
434
+							if ($birthday_count == 10 && $use_js_hide) {
435
+															// !!TODO - Inline CSS and JavaScript should be moved.
412 436
 								echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').classList.remove(\'hidden\'); document.getElementById(\'bdhidelink_', $day['day'], '\').classList.add(\'hidden\'); return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" class="hidden">, ';
437
+							}
413 438
 
414 439
 							++$birthday_count;
415 440
 						}
416
-						if ($use_js_hide)
417
-							echo '
441
+						if ($use_js_hide) {
442
+													echo '
418 443
 							</span>';
444
+						}
419 445
 
420 446
 						echo '
421 447
 						</div><!-- .smalltext -->';
@@ -426,8 +452,9 @@  discard block
 block discarded – undo
426 452
 					{
427 453
 						// Sort events by start time (all day events will be listed first)
428 454
 						uasort($day['events'], function($a, $b) {
429
-							if ($a['start_timestamp'] == $b['start_timestamp'])
430
-								return 0;
455
+							if ($a['start_timestamp'] == $b['start_timestamp']) {
456
+															return 0;
457
+							}
431 458
 
432 459
 							return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
433 460
 						});
@@ -447,20 +474,22 @@  discard block
 block discarded – undo
447 474
 								', $event['link'], '<br>
448 475
 								<span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
449 476
 
450
-							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
451
-								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
452
-							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
453
-								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
454
-							elseif (!empty($event['allday']))
455
-								echo $txt['calendar_allday'];
477
+							if (!empty($event['start_time_local']) && $event['starts_today'] == true) {
478
+															echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
479
+							} elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) {
480
+															echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
481
+							} elseif (!empty($event['allday'])) {
482
+															echo $txt['calendar_allday'];
483
+							}
456 484
 
457 485
 							echo '
458 486
 								</span>';
459 487
 
460
-							if (!empty($event['location']))
461
-								echo '
488
+							if (!empty($event['location'])) {
489
+															echo '
462 490
 								<br>
463 491
 								<span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
492
+							}
464 493
 
465 494
 							if ($event['can_edit'] || $event['can_export'])
466 495
 							{
@@ -468,18 +497,20 @@  discard block
 block discarded – undo
468 497
 								<span class="modify_event_links">';
469 498
 
470 499
 								// If they can edit the event, show an icon they can click on....
471
-								if ($event['can_edit'])
472
-									echo '
500
+								if ($event['can_edit']) {
501
+																	echo '
473 502
 									<a class="modify_event" href="', $event['modify_href'], '">
474 503
 										<span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
475 504
 									</a>';
505
+								}
476 506
 
477 507
 								// Exporting!
478
-								if ($event['can_export'])
479
-									echo '
508
+								if ($event['can_export']) {
509
+																	echo '
480 510
 									<a class="modify_event" href="', $event['export_href'], '">
481 511
 										<span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span>
482 512
 									</a>';
513
+								}
483 514
 
484 515
 								echo '
485 516
 								</span><br class="clear">';
@@ -498,10 +529,11 @@  discard block
 block discarded – undo
498 529
 			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
499 530
 			elseif ($is_mini === false)
500 531
 			{
501
-				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
502
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
503
-				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
504
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
532
+				if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) {
533
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
534
+				} elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) {
535
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
536
+				}
505 537
 			}
506 538
 
507 539
 			// Close this day and increase var count.
@@ -531,8 +563,9 @@  discard block
 block discarded – undo
531 563
 	global $context, $txt, $scripturl, $modSettings;
532 564
 
533 565
 	// We might have no reason to proceed, if the variable isn't there.
534
-	if (!isset($context['calendar_grid_' . $grid_name]))
535
-		return false;
566
+	if (!isset($context['calendar_grid_' . $grid_name])) {
567
+			return false;
568
+	}
536 569
 
537 570
 	// Handy pointer.
538 571
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -549,22 +582,25 @@  discard block
 block discarded – undo
549 582
 					<h3 class="catbg centertext largetext">';
550 583
 
551 584
 			// Previous Week Link...
552
-			if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
553
-				echo '
585
+			if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev'])) {
586
+							echo '
554 587
 						<span class="floatleft">
555 588
 							<a href="', $calendar_data['previous_week']['href'], '">&#171;</a>
556 589
 						</span>';
590
+			}
557 591
 
558 592
 			// Next Week Link...
559
-			if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
560
-				echo '
593
+			if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev'])) {
594
+							echo '
561 595
 						<span class="floatright">
562 596
 							<a href="', $calendar_data['next_week']['href'], '">&#187;</a>
563 597
 						</span>';
598
+			}
564 599
 
565 600
 			// The Month Title + Week Number...
566
-			if (!empty($calendar_data['week_title']))
567
-				echo $calendar_data['week_title'];
601
+			if (!empty($calendar_data['week_title'])) {
602
+							echo $calendar_data['week_title'];
603
+			}
568 604
 
569 605
 			echo '
570 606
 					</h3>
@@ -605,11 +641,12 @@  discard block
 block discarded – undo
605 641
 						<td class="', implode(' ', $classes), ' act_day">';
606 642
 
607 643
 			// Should the day number be a link?
608
-			if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
609
-				echo '
644
+			if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
645
+							echo '
610 646
 							<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
611
-			else
612
-				echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
647
+			} else {
648
+							echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
649
+			}
613 650
 
614 651
 			echo '
615 652
 						</td>
@@ -620,8 +657,9 @@  discard block
 block discarded – undo
620 657
 			{
621 658
 				// Sort events by start time (all day events will be listed first)
622 659
 				uasort($day['events'], function($a, $b) {
623
-					if ($a['start_timestamp'] == $b['start_timestamp'])
624
-						return 0;
660
+					if ($a['start_timestamp'] == $b['start_timestamp']) {
661
+											return 0;
662
+					}
625 663
 					return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
626 664
 				});
627 665
 
@@ -635,35 +673,39 @@  discard block
 block discarded – undo
635 673
 					echo $event['link'], '<br>
636 674
 								<span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
637 675
 
638
-					if (!empty($event['start_time_local']))
639
-						echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
640
-					else
641
-						echo $txt['calendar_allday'];
676
+					if (!empty($event['start_time_local'])) {
677
+											echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
678
+					} else {
679
+											echo $txt['calendar_allday'];
680
+					}
642 681
 
643 682
 					echo '
644 683
 								</span>';
645 684
 
646
-					if (!empty($event['location']))
647
-						echo '<br>
685
+					if (!empty($event['location'])) {
686
+											echo '<br>
648 687
 								<span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
688
+					}
649 689
 
650 690
 					if (!empty($event_icons_needed))
651 691
 					{
652 692
 						echo ' <span class="modify_event_links">';
653 693
 
654 694
 						// If they can edit the event, show a star they can click on....
655
-						if (!empty($event['can_edit']))
656
-							echo '
695
+						if (!empty($event['can_edit'])) {
696
+													echo '
657 697
 									<a class="modify_event" href="', $event['modify_href'], '">
658 698
 										<span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
659 699
 									</a>';
700
+						}
660 701
 
661 702
 						// Can we export? Sweet.
662
-						if (!empty($event['can_export']))
663
-							echo '
703
+						if (!empty($event['can_export'])) {
704
+													echo '
664 705
 									<a class="modify_event" href="', $event['export_href'], '">
665 706
 										<span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span>
666 707
 									</a>';
708
+						}
667 709
 
668 710
 						echo '
669 711
 								</span><br class="clear">';
@@ -681,22 +723,23 @@  discard block
 block discarded – undo
681 723
 							</div>
682 724
 							<br class="clear">';
683 725
 				}
684
-			}
685
-			else
726
+			} else
686 727
 			{
687
-				if (!empty($context['can_post']))
688
-					echo '
728
+				if (!empty($context['can_post'])) {
729
+									echo '
689 730
 							<div class="week_add_event">
690 731
 								<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['calendar_post_event'], '</a>
691 732
 							</div>';
733
+				}
692 734
 			}
693 735
 			echo '
694 736
 						</td>
695 737
 						<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
696 738
 
697 739
 			// Show any holidays!
698
-			if (!empty($day['holidays']))
699
-				echo implode('<br>', $day['holidays']);
740
+			if (!empty($day['holidays'])) {
741
+							echo implode('<br>', $day['holidays']);
742
+			}
700 743
 
701 744
 			echo '
702 745
 						</td>
@@ -705,11 +748,12 @@  discard block
 block discarded – undo
705 748
 			// Show any birthdays...
706 749
 			if (!empty($day['birthdays']))
707 750
 			{
708
-				foreach ($day['birthdays'] as $member)
709
-					echo '
751
+				foreach ($day['birthdays'] as $member) {
752
+									echo '
710 753
 							<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], '</a>
711 754
 							', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '
712 755
 							', $member['is_last'] ? '' : '<br>';
756
+				}
713 757
 			}
714 758
 			echo '
715 759
 						</td>
@@ -755,26 +799,27 @@  discard block
 block discarded – undo
755 799
 				<input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="date_input end" data-type="date">
756 800
 				<input type="submit" class="button" style="float:none" id="view_button" value="', $txt['view'], '">
757 801
 			</form>';
758
-	}
759
-	else
802
+	} else
760 803
 	{
761 804
 		echo'
762 805
 			<form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
763 806
 				<select name="month" id="input_month">';
764 807
 
765 808
 		// Show a select box with all the months.
766
-		foreach ($txt['months_short'] as $number => $month)
767
-			echo '
809
+		foreach ($txt['months_short'] as $number => $month) {
810
+					echo '
768 811
 					<option value="', $number, '"', $number == $context['current_month'] ? ' selected' : '', '>', $month, '</option>';
812
+		}
769 813
 
770 814
 		echo '
771 815
 				</select>
772 816
 				<select name="year">';
773 817
 
774 818
 		// Show a link for every year...
775
-		for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++)
776
-			echo '
819
+		for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++) {
820
+					echo '
777 821
 					<option value="', $year, '"', $year == $context['current_year'] ? ' selected' : '', '>', $year, '</option>';
822
+		}
778 823
 
779 824
 		echo '
780 825
 				</select>
@@ -796,9 +841,10 @@  discard block
 block discarded – undo
796 841
 	echo '
797 842
 		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);">';
798 843
 
799
-	if (!empty($context['event']['new']))
800
-		echo '
844
+	if (!empty($context['event']['new'])) {
845
+			echo '
801 846
 			<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
847
+	}
802 848
 
803 849
 	// Start the main table.
804 850
 	echo '
@@ -809,8 +855,8 @@  discard block
 block discarded – undo
809 855
 					</h3>
810 856
 				</div>';
811 857
 
812
-	if (!empty($context['post_error']['messages']))
813
-		echo '
858
+	if (!empty($context['post_error']['messages'])) {
859
+			echo '
814 860
 				<div class="errorbox">
815 861
 					<dl class="event_error">
816 862
 						<dt>
@@ -821,6 +867,7 @@  discard block
 block discarded – undo
821 867
 						</dt>
822 868
 					</dl>
823 869
 				</div>';
870
+	}
824 871
 
825 872
 	echo '
826 873
 				<div class="roundframe noup">
@@ -848,9 +895,10 @@  discard block
 block discarded – undo
848 895
 			echo '
849 896
 									<optgroup label="', $category['name'], '">';
850 897
 
851
-			foreach ($category['boards'] as $board)
852
-				echo '
898
+			foreach ($category['boards'] as $board) {
899
+							echo '
853 900
 										<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
901
+			}
854 902
 			echo '
855 903
 									</optgroup>';
856 904
 		}
@@ -886,9 +934,10 @@  discard block
 block discarded – undo
886 934
 								<span class="label">', $txt['calendar_timezone'], '</span>
887 935
 								<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
888 936
 
889
-	foreach ($context['all_timezones'] as $tz => $tzname)
890
-		echo '
937
+	foreach ($context['all_timezones'] as $tz => $tzname) {
938
+			echo '
891 939
 									<option', is_numeric($tz) ? ' value="" disabled' : ' value="' . $tz . '"', $tz === $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
940
+	}
892 941
 
893 942
 	echo '
894 943
 								</select>
@@ -904,9 +953,10 @@  discard block
 block discarded – undo
904 953
 					<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button">';
905 954
 
906 955
 	// Delete button?
907
-	if (empty($context['event']['new']))
908
-		echo '
956
+	if (empty($context['event']['new'])) {
957
+			echo '
909 958
 					<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button you_sure">';
959
+	}
910 960
 
911 961
 	echo '
912 962
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -934,9 +984,10 @@  discard block
 block discarded – undo
934 984
 		echo '
935 985
 				<td style="padding-', $alt ? 'right' : 'left', ': 1.5em;">';
936 986
 
937
-		foreach ($v as $i)
938
-			echo '
987
+		foreach ($v as $i) {
988
+					echo '
939 989
 					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '"><br>';
990
+		}
940 991
 
941 992
 		echo '
942 993
 				</td>';
@@ -957,9 +1008,10 @@  discard block
 block discarded – undo
957 1008
 
958 1009
 	foreach ($context['clockicons'] as $t => $v)
959 1010
 	{
960
-		foreach ($v as $i)
961
-			echo '
1011
+		foreach ($v as $i) {
1012
+					echo '
962 1013
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1014
+		}
963 1015
 	}
964 1016
 
965 1017
 	echo '
@@ -984,13 +1036,14 @@  discard block
 block discarded – undo
984 1036
 
985 1037
 	foreach ($context['clockicons'] as $t => $v)
986 1038
 	{
987
-		foreach ($v as $i)
988
-			echo '
1039
+		foreach ($v as $i) {
1040
+					echo '
989 1041
 				if (', $t, ' >= ', $i, ')
990 1042
 				{
991 1043
 					turnon.push("', $t, '_', $i, '");
992 1044
 					', $t, ' -= ', $i, ';
993 1045
 				}';
1046
+		}
994 1047
 	}
995 1048
 
996 1049
 	echo '
@@ -1034,9 +1087,10 @@  discard block
 block discarded – undo
1034 1087
 			<tr class="windowbg">
1035 1088
 				<td>';
1036 1089
 
1037
-		foreach ($v as $i)
1038
-			echo '
1090
+		foreach ($v as $i) {
1091
+					echo '
1039 1092
 					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1093
+		}
1040 1094
 
1041 1095
 		echo '
1042 1096
 				</td>
@@ -1058,9 +1112,10 @@  discard block
 block discarded – undo
1058 1112
 
1059 1113
 	foreach ($context['clockicons'] as $t => $v)
1060 1114
 	{
1061
-		foreach ($v as $i)
1062
-			echo '
1115
+		foreach ($v as $i) {
1116
+					echo '
1063 1117
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1118
+		}
1064 1119
 	}
1065 1120
 
1066 1121
 	echo '
@@ -1077,13 +1132,14 @@  discard block
 block discarded – undo
1077 1132
 
1078 1133
 	foreach ($context['clockicons'] as $t => $v)
1079 1134
 	{
1080
-		foreach ($v as $i)
1081
-			echo '
1135
+		foreach ($v as $i) {
1136
+					echo '
1082 1137
 				if (', $t, ' >= ', $i, ')
1083 1138
 				{
1084 1139
 					turnon.push("', $t, '_', $i, '");
1085 1140
 					', $t, ' -= ', $i, ';
1086 1141
 				}';
1142
+		}
1087 1143
 	}
1088 1144
 
1089 1145
 	echo '
@@ -1127,9 +1183,10 @@  discard block
 block discarded – undo
1127 1183
 			<tr class="windowbg">
1128 1184
 				<td>';
1129 1185
 
1130
-		foreach ($v as $i)
1131
-			echo '
1186
+		foreach ($v as $i) {
1187
+					echo '
1132 1188
 					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1189
+		}
1133 1190
 
1134 1191
 		echo '
1135 1192
 				</td>
@@ -1145,9 +1202,10 @@  discard block
 block discarded – undo
1145 1202
 
1146 1203
 	foreach ($context['clockicons'] as $t => $v)
1147 1204
 	{
1148
-		foreach ($v as $i)
1149
-			echo '
1205
+		foreach ($v as $i) {
1206
+					echo '
1150 1207
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1208
+		}
1151 1209
 	}
1152 1210
 
1153 1211
 	echo '
@@ -1168,13 +1226,14 @@  discard block
 block discarded – undo
1168 1226
 
1169 1227
 	foreach ($context['clockicons'] as $t => $v)
1170 1228
 	{
1171
-		foreach ($v as $i)
1172
-		echo '
1229
+		foreach ($v as $i) {
1230
+				echo '
1173 1231
 				if (', $t, ' >= ', $i, ')
1174 1232
 				{
1175 1233
 					turnon.push("', $t, '_', $i, '");
1176 1234
 					', $t, ' -= ', $i, ';
1177 1235
 				}';
1236
+		}
1178 1237
 	}
1179 1238
 
1180 1239
 	echo '
@@ -1218,9 +1277,10 @@  discard block
 block discarded – undo
1218 1277
 			<tr class="windowbg">
1219 1278
 				<td>';
1220 1279
 
1221
-		foreach ($v as $i)
1222
-			echo '
1280
+		foreach ($v as $i) {
1281
+					echo '
1223 1282
 					<img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="" style="padding: 2px;">';
1283
+		}
1224 1284
 
1225 1285
 		echo '
1226 1286
 				</td>
Please login to merge, or discard this patch.
Themes/default/ManageBoards.template.php 1 patch
Braces   +99 added lines, -68 removed lines patch added patch discarded remove patch
@@ -25,18 +25,20 @@  discard block
 block discarded – undo
25 25
 		</div>
26 26
 		<div class="windowbg">';
27 27
 
28
-	if (!empty($context['move_board']))
29
-		echo '
28
+	if (!empty($context['move_board'])) {
29
+			echo '
30 30
 			<div class="noticebox">
31 31
 				', $context['move_title'], ' [<a href="', $scripturl, '?action=admin;area=manageboards">', $txt['mboards_cancel_moving'], '</a>]', '
32 32
 			</div>';
33
+	}
33 34
 
34 35
 	// No categories so show a label.
35
-	if (empty($context['categories']))
36
-		echo '
36
+	if (empty($context['categories'])) {
37
+			echo '
37 38
 			<div class="windowbg centertext">
38 39
 				', $txt['mboards_no_cats'], '
39 40
 			</div>';
41
+	}
40 42
 
41 43
 	// Loop through every category, listing the boards in each as we go.
42 44
 	foreach ($context['categories'] as $category)
@@ -54,9 +56,10 @@  discard block
 block discarded – undo
54 56
 			<form action="', $scripturl, '?action=admin;area=manageboards;sa=newboard;cat=', $category['id'], '" method="post" accept-charset="', $context['character_set'], '">
55 57
 				<ul id="category_', $category['id'], '" class="nolist">';
56 58
 
57
-		if (!empty($category['move_link']))
58
-			echo '
59
+		if (!empty($category['move_link'])) {
60
+					echo '
59 61
 					<li><a href="', $category['move_link']['href'], '" title="', $category['move_link']['label'], '"><span class="generic_icons select_above"></span></a></li>';
62
+		}
60 63
 
61 64
 		$recycle_board = '<a href="' . $scripturl . '?action=admin;area=manageboards;sa=settings"> <img src="' . $settings['images_url'] . '/post/recycled.png" alt="' . $txt['recycle_board'] . '" title="' . $txt['recycle_board'] . '"></a>';
62 65
 		$redirect_board = '<img src="' . $settings['images_url'] . '/new_redirect.png" alt="' . $txt['redirect_board_desc'] . '" title="' . $txt['redirect_board_desc'] . '">';
@@ -79,9 +82,10 @@  discard block
 block discarded – undo
79 82
 				echo '
80 83
 					<li class="windowbg" style="padding-', $context['right_to_left'] ? 'right' : 'left', ': ', 5 + 30 * $board['move_links'][0]['child_level'], 'px;">';
81 84
 
82
-				foreach ($board['move_links'] as $link)
83
-					echo '
85
+				foreach ($board['move_links'] as $link) {
86
+									echo '
84 87
 						<a href="', $link['href'], '" class="move_links" title="', $link['label'], '"><span class="generic_icons select_', $link['class'], '" title="', $link['label'], '"></span></a>';
88
+				}
85 89
 
86 90
 				echo '
87 91
 					</li>';
@@ -130,9 +134,10 @@  discard block
 block discarded – undo
130 134
 						<select name="cat_order">';
131 135
 
132 136
 		// Print every existing category into a select box.
133
-		foreach ($context['category_order'] as $order)
134
-			echo '
137
+		foreach ($context['category_order'] as $order) {
138
+					echo '
135 139
 							<option', $order['selected'] ? ' selected' : '', ' value="', $order['id'], '">', $order['name'], '</option>';
140
+		}
136 141
 		echo '
137 142
 						</select>
138 143
 					</dd>';
@@ -167,14 +172,15 @@  discard block
 block discarded – undo
167 172
 	{
168 173
 		foreach ($context['custom_category_settings'] as $catset_id => $catset)
169 174
 		{
170
-			if (!empty($catset['dt']) && !empty($catset['dd']))
171
-				echo '
175
+			if (!empty($catset['dt']) && !empty($catset['dd'])) {
176
+							echo '
172 177
 					<dt class="clear', !is_numeric($catset_id) ? ' catset_' . $catset_id : '', '">
173 178
 						', $catset['dt'], '
174 179
 					</dt>
175 180
 					<dd', !is_numeric($catset_id) ? ' class="catset_' . $catset_id . '"' : '', '>
176 181
 						', $catset['dd'], '
177 182
 					</dd>';
183
+			}
178 184
 		}
179 185
 	}
180 186
 
@@ -182,21 +188,23 @@  discard block
 block discarded – undo
182 188
 	echo '
183 189
 				</dl>';
184 190
 
185
-	if (isset($context['category']['is_new']))
186
-		echo '
191
+	if (isset($context['category']['is_new'])) {
192
+			echo '
187 193
 				<input type="submit" name="add" value="', $txt['mboards_add_cat_button'], '" onclick="return !isEmptyText(this.form.cat_name);" tabindex="', $context['tabindex']++, '" class="button">';
188
-	else
189
-		echo '
194
+	} else {
195
+			echo '
190 196
 				<input type="submit" name="edit" value="', $txt['modify'], '" onclick="return !isEmptyText(this.form.cat_name);" tabindex="', $context['tabindex']++, '" class="button">
191 197
 				<input type="submit" name="delete" value="', $txt['mboards_delete_cat'], '" data-confirm="', $txt['catConfirm'], '" class="button you_sure">';
198
+	}
192 199
 	echo '
193 200
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
194 201
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
195 202
 
196 203
 	// If this category is empty we don't bother with the next confirmation screen.
197
-	if ($context['category']['is_empty'])
198
-		echo '
204
+	if ($context['category']['is_empty']) {
205
+			echo '
199 206
 				<input type="hidden" name="empty" value="1">';
207
+	}
200 208
 
201 209
 	echo '
202 210
 			</div><!-- .windowbg -->
@@ -223,9 +231,10 @@  discard block
 block discarded – undo
223 231
 				<p>', $txt['mboards_delete_cat_contains'], ':</p>
224 232
 				<ul>';
225 233
 
226
-	foreach ($context['category']['children'] as $child)
227
-		echo '
234
+	foreach ($context['category']['children'] as $child) {
235
+			echo '
228 236
 					<li>', $child, '</li>';
237
+	}
229 238
 
230 239
 	echo '
231 240
 				</ul>
@@ -239,10 +248,11 @@  discard block
 block discarded – undo
239 248
 					<label for="delete_action1"><input type="radio" id="delete_action1" name="delete_action" value="1"', count($context['category_order']) == 1 ? ' disabled' : '', '>', $txt['mboards_delete_option2'], '</label>:
240 249
 					<select name="cat_to"', count($context['category_order']) == 1 ? ' disabled' : '', '>';
241 250
 
242
-	foreach ($context['category_order'] as $cat)
243
-		if ($cat['id'] != 0)
251
+	foreach ($context['category_order'] as $cat) {
252
+			if ($cat['id'] != 0)
244 253
 			echo '
245 254
 						<option value="', $cat['id'], '">', $cat['true_name'], '</option>';
255
+	}
246 256
 
247 257
 	echo '
248 258
 					</select>
@@ -285,9 +295,10 @@  discard block
 block discarded – undo
285 295
 					<dd>
286 296
 						<select name="new_cat" onchange="if (this.form.order) {this.form.order.disabled = this.options[this.selectedIndex].value != 0; this.form.board_order.disabled = this.options[this.selectedIndex].value != 0 || this.form.order.options[this.form.order.selectedIndex].value == \'\';}">';
287 297
 
288
-	foreach ($context['categories'] as $category)
289
-		echo '
298
+	foreach ($context['categories'] as $category) {
299
+			echo '
290 300
 							<option', $category['selected'] ? ' selected' : '', ' value="', $category['id'], '">', $category['name'], '</option>';
301
+	}
291 302
 	echo '
292 303
 						</select>
293 304
 					</dd>';
@@ -315,9 +326,10 @@  discard block
 block discarded – undo
315 326
 						<select id="board_order" name="board_order"', !isset($context['board']['is_new']) ? ' disabled' : '', '>
316 327
 							', !isset($context['board']['is_new']) ? '<option value="">(' . $txt['mboards_unchanged'] . ')</option>' : '';
317 328
 
318
-		foreach ($context['board_order'] as $order)
319
-			echo '
329
+		foreach ($context['board_order'] as $order) {
330
+					echo '
320 331
 							<option', $order['selected'] ? ' selected' : '', ' value="', $order['id'], '">', $order['name'], '</option>';
332
+		}
321 333
 		echo '
322 334
 						</select>
323 335
 					</dd>';
@@ -346,13 +358,15 @@  discard block
 block discarded – undo
346 358
 					<dd>
347 359
 						<select name="profile">';
348 360
 
349
-	if (isset($context['board']['is_new']))
350
-		echo '
361
+	if (isset($context['board']['is_new'])) {
362
+			echo '
351 363
 							<option value="-1">[', $txt['permission_profile_inherit'], ']</option>';
364
+	}
352 365
 
353
-	foreach ($context['profiles'] as $id => $profile)
354
-		echo '
366
+	foreach ($context['profiles'] as $id => $profile) {
367
+			echo '
355 368
 							<option value="', $id, '"', $id == $context['board']['profile'] ? ' selected' : '', '>', $profile['name'], '</option>';
369
+	}
356 370
 
357 371
 	echo '
358 372
 						</select>
@@ -365,8 +379,8 @@  discard block
 block discarded – undo
365 379
 					</dt>
366 380
 					<dd>';
367 381
 
368
-	if (!empty($modSettings['deny_boards_access']))
369
-		echo '
382
+	if (!empty($modSettings['deny_boards_access'])) {
383
+			echo '
370 384
 						<table>
371 385
 							<tr>
372 386
 								<td></td>
@@ -374,10 +388,11 @@  discard block
 block discarded – undo
374 388
 								<th>', $txt['permissions_option_off'], '</th>
375 389
 								<th>', $txt['permissions_option_deny'], '</th>
376 390
 							</tr>';
391
+	}
377 392
 
378 393
 	// List all the membergroups so the user can choose who may access this board.
379
-	foreach ($context['groups'] as $group)
380
-		if (empty($modSettings['deny_boards_access']))
394
+	foreach ($context['groups'] as $group) {
395
+			if (empty($modSettings['deny_boards_access']))
381 396
 			echo '
382 397
 						<label for="groups_', $group['id'], '">
383 398
 							<input type="checkbox" name="groups[', $group['id'], ']" value="allow" id="groups_', $group['id'], '"', in_array($group['id'], $context['board_managers']) ? ' checked disabled' : ($group['allow'] ? ' checked' : ''), '>
@@ -385,8 +400,9 @@  discard block
 block discarded – undo
385 400
 								', $group['name'], '
386 401
 							</span>
387 402
 						</label><br>';
388
-		else
389
-			echo '
403
+	}
404
+		else {
405
+					echo '
390 406
 							<tr>
391 407
 								<td>
392 408
 									<label for="groups_', $group['id'], '_a">
@@ -406,16 +422,17 @@  discard block
 block discarded – undo
406 422
 								</td>
407 423
 								<td></td>
408 424
 							</tr>';
425
+		}
409 426
 
410
-	if (empty($modSettings['deny_boards_access']))
411
-		echo '
427
+	if (empty($modSettings['deny_boards_access'])) {
428
+			echo '
412 429
 						<span class="select_all_box">
413 430
 							<em>', $txt['check_all'], '</em> <input type="checkbox" onclick="invertAll(this, this.form, \'groups[\');">
414 431
 						</span>
415 432
 						<br><br>
416 433
 					</dd>';
417
-	else
418
-		echo '
434
+	} else {
435
+			echo '
419 436
 							<tr class="select_all_box">
420 437
 								<td>
421 438
 								</td>
@@ -434,6 +451,7 @@  discard block
 block discarded – undo
434 451
 							</tr>
435 452
 						</table>
436 453
 					</dd>';
454
+	}
437 455
 
438 456
 	// Options to choose moderators, specify as announcement board and choose whether to count posts here.
439 457
 	echo '
@@ -488,8 +506,8 @@  discard block
 block discarded – undo
488 506
 					</dl>
489 507
 				</div>';
490 508
 
491
-		if ($context['board']['redirect'])
492
-			echo '
509
+		if ($context['board']['redirect']) {
510
+					echo '
493 511
 				<div id="reset_redirect_div">
494 512
 					<dl class="settings">
495 513
 						<dt>
@@ -502,6 +520,7 @@  discard block
 block discarded – undo
502 520
 						</dd>
503 521
 					</dl>
504 522
 				</div>';
523
+		}
505 524
 	}
506 525
 
507 526
 	echo '
@@ -529,9 +548,10 @@  discard block
 block discarded – undo
529 548
 							<select name="boardtheme" id="boardtheme" onchange="refreshOptions();">
530 549
 								<option value="0"', $context['board']['theme'] == 0 ? ' selected' : '', '>', $txt['mboards_theme_default'], '</option>';
531 550
 
532
-	foreach ($context['themes'] as $theme)
533
-		echo '
551
+	foreach ($context['themes'] as $theme) {
552
+			echo '
534 553
 									<option value="', $theme['id'], '"', $context['board']['theme'] == $theme['id'] ? ' selected' : '', '>', $theme['name'], '</option>';
554
+	}
535 555
 
536 556
 	echo '
537 557
 							</select>
@@ -560,14 +580,15 @@  discard block
 block discarded – undo
560 580
 
561 581
 		foreach ($context['custom_board_settings'] as $cbs_id => $cbs)
562 582
 		{
563
-			if (!empty($cbs['dt']) && !empty($cbs['dd']))
564
-				echo '
583
+			if (!empty($cbs['dt']) && !empty($cbs['dd'])) {
584
+							echo '
565 585
 						<dt class="clear', !is_numeric($cbs_id) ? ' cbs_' . $cbs_id : '', '">
566 586
 							', $cbs['dt'], '
567 587
 						</dt>
568 588
 						<dd', !is_numeric($cbs_id) ? ' class="cbs_' . $cbs_id . '"' : '', '>
569 589
 							', $cbs['dd'], '
570 590
 						</dd>';
591
+			}
571 592
 		}
572 593
 
573 594
 		echo '
@@ -575,9 +596,10 @@  discard block
 block discarded – undo
575 596
 				</div>';
576 597
 	}
577 598
 
578
-	if (!empty($context['board']['is_recycle']))
579
-		echo '
599
+	if (!empty($context['board']['is_recycle'])) {
600
+			echo '
580 601
 				<div class="noticebox">', $txt['mboards_recycle_disabled_delete'], '</div>';
602
+	}
581 603
 
582 604
 	echo '
583 605
 				<input type="hidden" name="rid" value="', $context['redirect_location'], '">
@@ -585,21 +607,24 @@  discard block
 block discarded – undo
585 607
 				<input type="hidden" name="', $context['admin-be-' . $context['board']['id'] . '_token_var'], '" value="', $context['admin-be-' . $context['board']['id'] . '_token'], '">';
586 608
 
587 609
 	// If this board has no children don't bother with the next confirmation screen.
588
-	if ($context['board']['no_children'])
589
-		echo '
610
+	if ($context['board']['no_children']) {
611
+			echo '
590 612
 				<input type="hidden" name="no_children" value="1">';
613
+	}
591 614
 
592
-	if (isset($context['board']['is_new']))
593
-		echo '
615
+	if (isset($context['board']['is_new'])) {
616
+			echo '
594 617
 				<input type="hidden" name="cur_cat" value="', $context['board']['category'], '">
595 618
 				<input type="submit" name="add" value="', $txt['mboards_new_board'], '" onclick="return !isEmptyText(this.form.board_name);" class="button">';
596
-	else
597
-		echo '
619
+	} else {
620
+			echo '
598 621
 				<input type="submit" name="edit" value="', $txt['modify'], '" onclick="return !isEmptyText(this.form.board_name);" class="button">';
622
+	}
599 623
 
600
-	if (!isset($context['board']['is_new']) && empty($context['board']['is_recycle']))
601
-		echo '
624
+	if (!isset($context['board']['is_new']) && empty($context['board']['is_recycle'])) {
625
+			echo '
602 626
 				<input type="submit" name="delete" value="', $txt['mboards_delete_board'], '" data-confirm="', $txt['boardConfirm'], '" class="button you_sure">';
627
+	}
603 628
 	echo '
604 629
 			</div><!-- .windowbg -->
605 630
 		</form>
@@ -620,12 +645,13 @@  discard block
 block discarded – undo
620 645
 			sItemListContainerId: \'moderator_container\',
621 646
 			aListItems: [';
622 647
 
623
-	foreach ($context['board']['moderators'] as $id_member => $member_name)
624
-		echo '
648
+	foreach ($context['board']['moderators'] as $id_member => $member_name) {
649
+			echo '
625 650
 				{
626 651
 					sItemId: ', JavaScriptEscape($id_member), ',
627 652
 					sItemName: ', JavaScriptEscape($member_name), '
628 653
 				}', $id_member == $context['board']['last_moderator_id'] ? '' : ',';
654
+	}
629 655
 
630 656
 	echo '
631 657
 			]
@@ -645,12 +671,13 @@  discard block
 block discarded – undo
645 671
 			sItemListContainerId: \'moderator_group_container\',
646 672
 			aListItems: [';
647 673
 
648
-	foreach ($context['board']['moderator_groups'] as $id_group => $group_name)
649
-		echo '
674
+	foreach ($context['board']['moderator_groups'] as $id_group => $group_name) {
675
+			echo '
650 676
 				{
651 677
 					sItemId: ', JavaScriptEscape($id_group), ',
652 678
 					sItemName: ', JavaScriptEscape($group_name), '
653 679
 				}', $id_group == $context['board']['last_moderator_group_id'] ? '' : ',';
680
+	}
654 681
 
655 682
 		echo '
656 683
 			]
@@ -689,20 +716,22 @@  discard block
 block discarded – undo
689 716
 			else 
690 717
 				document.getElementById("redirect_address_div").classList.add(\'hidden\');';
691 718
 
692
-		if ($context['board']['redirect'])
693
-			echo '
719
+		if ($context['board']['redirect']) {
720
+					echo '
694 721
 			if(redirectEnabled)
695 722
 				document.getElementById("reset_redirect_div").classList.remove(\'hidden\');
696 723
 			else 
697 724
 				document.getElementById("reset_redirect_div").classList.add(\'hidden\');';
725
+		}
698 726
 	}
699 727
 
700 728
 	// Include any JavaScript added by mods using the 'integrate_edit_board' hook.
701 729
 	if (!empty($context['custom_refreshOptions']) && is_array($context['custom_refreshOptions']))
702 730
 	{
703
-		foreach ($context['custom_refreshOptions'] as $refreshOption)
704
-			echo '
731
+		foreach ($context['custom_refreshOptions'] as $refreshOption) {
732
+					echo '
705 733
 			', $refreshOption;
734
+		}
706 735
 	}
707 736
 
708 737
 	echo '
@@ -731,9 +760,10 @@  discard block
 block discarded – undo
731 760
 				<p>', $txt['mboards_delete_board_contains'], '</p>
732 761
 				<ul>';
733 762
 
734
-	foreach ($context['children'] as $child)
735
-		echo '
763
+	foreach ($context['children'] as $child) {
764
+			echo '
736 765
 					<li>', $child['node']['name'], '</li>';
766
+	}
737 767
 
738 768
 	echo '
739 769
 				</ul>
@@ -747,10 +777,11 @@  discard block
 block discarded – undo
747 777
 					<label for="delete_action1"><input type="radio" id="delete_action1" name="delete_action" value="1"', empty($context['can_move_children']) ? ' disabled' : '', '>', $txt['mboards_delete_board_option2'], '</label>:
748 778
 					<select name="board_to"', empty($context['can_move_children']) ? ' disabled' : '', '>';
749 779
 
750
-	foreach ($context['board_order'] as $board)
751
-		if ($board['id'] != $context['board']['id'] && empty($board['is_child']))
780
+	foreach ($context['board_order'] as $board) {
781
+			if ($board['id'] != $context['board']['id'] && empty($board['is_child']))
752 782
 			echo '
753 783
 						<option value="', $board['id'], '">', $board['name'], '</option>';
784
+	}
754 785
 
755 786
 	echo '
756 787
 					</select>
Please login to merge, or discard this patch.
Themes/default/ManageLanguages.template.php 1 patch
Braces   +29 added lines, -20 removed lines patch added patch discarded remove patch
@@ -34,11 +34,12 @@  discard block
 block discarded – undo
34 34
 	}
35 35
 
36 36
 	// An error?
37
-	if (!empty($context['error_message']))
38
-		echo '
37
+	if (!empty($context['error_message'])) {
38
+			echo '
39 39
 	<div class="errorbox">
40 40
 		', $context['error_message'], '
41 41
 	</div>';
42
+	}
42 43
 
43 44
 	// Provide something of an introduction...
44 45
 	echo '
@@ -64,11 +65,12 @@  discard block
 block discarded – undo
64 65
 	// If the files are not writable, we might!
65 66
 	if (!empty($context['still_not_writable']))
66 67
 	{
67
-		if (!empty($context['package_ftp']['error']))
68
-			echo '
68
+		if (!empty($context['package_ftp']['error'])) {
69
+					echo '
69 70
 			<div class="errorbox">
70 71
 				', $context['package_ftp']['error'], '
71 72
 			</div>';
73
+		}
72 74
 
73 75
 		echo '
74 76
 			<div class="cat_bar">
@@ -145,11 +147,12 @@  discard block
 block discarded – undo
145 147
 			</div>';
146 148
 
147 149
 	// Not writable? Oops, show an error for ya.
148
-	if (!empty($context['lang_file_not_writable_message']))
149
-		echo '
150
+	if (!empty($context['lang_file_not_writable_message'])) {
151
+			echo '
150 152
 			<div class="errorbox">
151 153
 				', $context['lang_file_not_writable_message'], '
152 154
 			</div>';
155
+	}
153 156
 
154 157
 	// Show the language entries
155 158
 	echo '
@@ -160,8 +163,8 @@  discard block
 block discarded – undo
160 163
 
161 164
 	foreach ($context['primary_settings'] as $setting => $setting_info)
162 165
 	{
163
-		if ($setting != 'name')
164
-			echo '
166
+		if ($setting != 'name') {
167
+					echo '
165 168
 						<dt>
166 169
 							<a id="settings_', $setting, '_help" href="', $scripturl, '?action=helpadmin;help=languages_', $setting_info['label'], '" onclick="return reqOverlayDiv(this.href);"><span class="generic_icons help" title="', $txt['help'], '"></span></a>
167 170
 							<label for="', $setting, '">', $txt['languages_' . $setting_info['label']], ':</label>
@@ -169,6 +172,7 @@  discard block
 block discarded – undo
169 172
 						<dd>
170 173
 							<input type="', (is_bool($setting_info['value']) ? 'checkbox' : 'text'), '" name="', $setting, '" id="', $setting_info['label'], '" size="20"', (is_bool($setting_info['value']) ? (!empty($setting_info['value']) ? ' checked' : '') : ' value="' . $setting_info['value'] . '"'), (!empty($context['lang_file_not_writable_message']) ? ' disabled' : ''), ' data-orig="' . (is_bool($setting_info['value']) ? (!empty($setting_info['value']) ? 'true' : 'false') : $setting_info['value']) . '">
171 174
 						</dd>';
175
+		}
172 176
 	}
173 177
 
174 178
 	echo '
@@ -180,9 +184,10 @@  discard block
 block discarded – undo
180 184
 				<input type="reset" id="reset_main" value="', $txt['reset'], '" class="button">';
181 185
 
182 186
 	// Allow deleting entries. English can't be deleted though.
183
-	if ($context['lang_id'] != 'english')
184
-		echo '
187
+	if ($context['lang_id'] != 'english') {
188
+			echo '
185 189
 				<input type="submit" name="delete_main" value="', $txt['delete'], '"', !empty($context['lang_file_not_writable_message']) ? ' disabled' : '', ' onclick="confirm(\'', $txt['languages_delete_confirm'], '\');" class="button">';
190
+	}
186 191
 
187 192
 	echo '
188 193
 			</div><!-- .windowbg -->
@@ -209,9 +214,10 @@  discard block
 block discarded – undo
209 214
 		echo '
210 215
 						<optgroup label="', $theme['name'], '">';
211 216
 
212
-		foreach ($theme['files'] as $file)
213
-			echo '
217
+		foreach ($theme['files'] as $file) {
218
+					echo '
214 219
 							<option value="', $id_theme, '+', $file['id'], '"', $file['selected'] ? ' selected' : '', '>', $file['name'], '</option>';
220
+		}
215 221
 
216 222
 		echo '
217 223
 						</optgroup>';
@@ -226,11 +232,12 @@  discard block
 block discarded – undo
226 232
 			</div><!-- .information -->';
227 233
 
228 234
 	// Is it not writable? Show an error.
229
-	if (!empty($context['entries_not_writable_message']))
230
-		echo '
235
+	if (!empty($context['entries_not_writable_message'])) {
236
+			echo '
231 237
 			<div class="errorbox">
232 238
 				', $context['entries_not_writable_message'], '
233 239
 			</div>';
240
+	}
234 241
 
235 242
 	// Already have some file entries?
236 243
 	if (!empty($context['file_entries']))
@@ -259,8 +266,8 @@  discard block
 block discarded – undo
259 266
 						</dt>
260 267
 						<dd id="entry_', $entry_num, '">';
261 268
 
262
-				if ($entry['can_remove'])
263
-					echo '
269
+				if ($entry['can_remove']) {
270
+									echo '
264 271
 							<span style="margin-right: 1ch; white-space: nowrap">
265 272
 								<input id="entry_', $entry_num, '_none" class="entry_toggle" type="radio" name="edit[', $entry['key'], ']', isset($entry['subkey']) ? '[' . $entry['subkey'] . ']' : '', '" value="" data-target="#entry_', $entry_num, '" checked>
266 273
 								<label for="entry_', $entry_num, '_none">', $txt['no_change'], '</label>
@@ -273,10 +280,11 @@  discard block
 block discarded – undo
273 280
 								<input id="entry_', $entry_num, '_remove" class="entry_toggle" type="radio" name="edit[', $entry['key'], ']', isset($entry['subkey']) ? '[' . $entry['subkey'] . ']' : '', '" value="remove" data-target="#entry_', $entry_num, '">
274 281
 								<label for="entry_', $entry_num, '_remove">', $txt['remove'], '</label>
275 282
 							</span>';
276
-				else
277
-					echo '
283
+				} else {
284
+									echo '
278 285
 							<input id="entry_', $entry_num, '_edit" class="entry_toggle" type="checkbox" name="edit[', $entry['key'], ']', isset($entry['subkey']) ? '[' . $entry['subkey'] . ']' : '', '" value="edit" data-target="#entry_', $entry_num, '">
279 286
 							<label for="entry_', $entry_num, '_edit">', $txt['edit'], '</label>';
287
+				}
280 288
 
281 289
 				echo '
282 290
 							</span>
@@ -334,12 +342,13 @@  discard block
 block discarded – undo
334 342
 					<input type="text" name="smf_add" size="40" value="', !empty($context['smf_search_term']) ? $context['smf_search_term'] : '', '">';
335 343
 
336 344
 	// Do we have some errors? Too bad. Display a little error box.
337
-	if (!empty($context['smf_error']))
338
-		echo '
345
+	if (!empty($context['smf_error'])) {
346
+			echo '
339 347
 					<div>
340 348
 						<br>
341 349
 						<p class="errorbox">', $txt['add_language_error_' . $context['smf_error']], '</p>
342 350
 					</div>';
351
+	}
343 352
 
344 353
 	echo '
345 354
 				</fieldset>
Please login to merge, or discard this patch.
Sources/ManageLanguages.php 1 patch
Braces   +241 added lines, -181 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
  * This is the main function for the languages area.
@@ -150,11 +151,11 @@  discard block
 block discarded – undo
150 151
 	$language_list = new xmlArray(fetch_web_data($url), true);
151 152
 
152 153
 	// Check that the site responded and that the language exists.
153
-	if (!$language_list->exists('languages'))
154
-		$context['smf_error'] = 'no_response';
155
-	elseif (!$language_list->exists('languages/language'))
156
-		$context['smf_error'] = 'no_files';
157
-	else
154
+	if (!$language_list->exists('languages')) {
155
+			$context['smf_error'] = 'no_response';
156
+	} elseif (!$language_list->exists('languages/language')) {
157
+			$context['smf_error'] = 'no_files';
158
+	} else
158 159
 	{
159 160
 		$language_list = $language_list->path('languages[0]');
160 161
 		$lang_files = $language_list->set('language');
@@ -162,8 +163,9 @@  discard block
 block discarded – undo
162 163
 		foreach ($lang_files as $file)
163 164
 		{
164 165
 			// Were we searching?
165
-			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false)
166
-				continue;
166
+			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) {
167
+							continue;
168
+			}
167 169
 
168 170
 			$smf_languages[] = array(
169 171
 				'id' => $file->fetch('id'),
@@ -174,10 +176,11 @@  discard block
 block discarded – undo
174 176
 				'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_smf_install'] . '</a>',
175 177
 			);
176 178
 		}
177
-		if (empty($smf_languages))
178
-			$context['smf_error'] = 'no_files';
179
-		else
180
-			return $smf_languages;
179
+		if (empty($smf_languages)) {
180
+					$context['smf_error'] = 'no_files';
181
+		} else {
182
+					return $smf_languages;
183
+		}
181 184
 	}
182 185
 }
183 186
 
@@ -199,8 +202,9 @@  discard block
 block discarded – undo
199 202
 	require_once($sourcedir . '/Subs-Package.php');
200 203
 
201 204
 	// Clearly we need to know what to request.
202
-	if (!isset($_GET['did']))
203
-		fatal_lang_error('no_access', false);
205
+	if (!isset($_GET['did'])) {
206
+			fatal_lang_error('no_access', false);
207
+	}
204 208
 
205 209
 	// Some lovely context.
206 210
 	$context['download_id'] = $_GET['did'];
@@ -220,8 +224,9 @@  discard block
 block discarded – undo
220 224
 		foreach ($_POST['copy_file'] as $file)
221 225
 		{
222 226
 			// Check it's not very bad.
223
-			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file)))
224
-				fatal_error($txt['languages_download_illegal_paths']);
227
+			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) {
228
+							fatal_error($txt['languages_download_illegal_paths']);
229
+			}
225 230
 
226 231
 			$chmod_files[] = $boarddir . '/' . $file;
227 232
 			$install_files[] = $file;
@@ -232,8 +237,9 @@  discard block
 block discarded – undo
232 237
 		$files_left = $file_status['files']['notwritable'];
233 238
 
234 239
 		// Something not writable?
235
-		if (!empty($files_left))
236
-			$context['error_message'] = $txt['languages_download_not_chmod'];
240
+		if (!empty($files_left)) {
241
+					$context['error_message'] = $txt['languages_download_not_chmod'];
242
+		}
237 243
 		// Otherwise, go go go!
238 244
 		elseif (!empty($install_files))
239 245
 		{
@@ -248,11 +254,13 @@  discard block
 block discarded – undo
248 254
 	}
249 255
 
250 256
 	// Open up the old china.
251
-	if (!isset($archive_content))
252
-		$archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
257
+	if (!isset($archive_content)) {
258
+			$archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
259
+	}
253 260
 
254
-	if (empty($archive_content))
255
-		fatal_error($txt['add_language_error_no_response']);
261
+	if (empty($archive_content)) {
262
+			fatal_error($txt['add_language_error_no_response']);
263
+	}
256 264
 
257 265
 	// Now for each of the files, let's do some *stuff*
258 266
 	$context['files'] = array(
@@ -267,8 +275,9 @@  discard block
 block discarded – undo
267 275
 		$extension = substr($filename, strrpos($filename, '.') + 1);
268 276
 
269 277
 		// Don't do anything with files we don't understand.
270
-		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt')))
271
-			continue;
278
+		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) {
279
+					continue;
280
+		}
272 281
 
273 282
 		// Basic data.
274 283
 		$context_data = array(
@@ -287,8 +296,9 @@  discard block
 block discarded – undo
287 296
 		// Does the file exist, is it different and can we overwrite?
288 297
 		if (file_exists($boarddir . '/' . $file['filename']))
289 298
 		{
290
-			if (is_writable($boarddir . '/' . $file['filename']))
291
-				$context_data['writable'] = true;
299
+			if (is_writable($boarddir . '/' . $file['filename'])) {
300
+							$context_data['writable'] = true;
301
+			}
292 302
 
293 303
 			// Finally, do we actually think the content has changed?
294 304
 			if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename']))
@@ -301,16 +311,17 @@  discard block
 block discarded – undo
301 311
 			{
302 312
 				$context_data['exists'] = 'same';
303 313
 				$context_data['default_copy'] = false;
314
+			} else {
315
+							$context_data['exists'] = 'different';
304 316
 			}
305
-			else
306
-				$context_data['exists'] = 'different';
307 317
 		}
308 318
 		// No overwrite?
309 319
 		else
310 320
 		{
311 321
 			// Can we at least stick it in the directory...
312
-			if (is_writable($boarddir . '/' . $dirname))
313
-				$context_data['writable'] = true;
322
+			if (is_writable($boarddir . '/' . $dirname)) {
323
+							$context_data['writable'] = true;
324
+			}
314 325
 		}
315 326
 
316 327
 		// I love PHP files, that's why I'm a developer and not an artistic type spending my time drinking absinth and living a life of sin...
@@ -325,8 +336,9 @@  discard block
 block discarded – undo
325 336
 			list ($name, $language) = explode('.', $filename);
326 337
 
327 338
 			// Let's get the new version, I like versions, they tell me that I'm up to date.
328
-			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1)
329
-				$context_data['version'] = $match[1];
339
+			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) {
340
+							$context_data['version'] = $match[1];
341
+			}
330 342
 
331 343
 			// Now does the old file exist - if so what is it's version?
332 344
 			if (file_exists($boarddir . '/' . $file['filename']))
@@ -342,34 +354,35 @@  discard block
 block discarded – undo
342 354
 					$context_data['cur_version'] = $match[1];
343 355
 
344 356
 					// How does this compare?
345
-					if ($context_data['cur_version'] == $context_data['version'])
346
-						$context_data['version_compare'] = 'same';
347
-					elseif ($context_data['cur_version'] > $context_data['version'])
348
-						$context_data['version_compare'] = 'older';
357
+					if ($context_data['cur_version'] == $context_data['version']) {
358
+											$context_data['version_compare'] = 'same';
359
+					} elseif ($context_data['cur_version'] > $context_data['version']) {
360
+											$context_data['version_compare'] = 'older';
361
+					}
349 362
 
350 363
 					// Don't recommend copying if the version is the same.
351
-					if ($context_data['version_compare'] != 'newer')
352
-						$context_data['default_copy'] = false;
364
+					if ($context_data['version_compare'] != 'newer') {
365
+											$context_data['default_copy'] = false;
366
+					}
353 367
 				}
354 368
 			}
355 369
 
356 370
 			// Add the context data to the main set.
357 371
 			$context['files']['lang'][] = $context_data;
358
-		}
359
-		elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
372
+		} elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
360 373
 		{
361 374
 			// Registration agreement is a primary file
362 375
 			$context['files']['lang'][] = $context_data;
363
-		}
364
-		else
376
+		} else
365 377
 		{
366 378
 			// There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future
367 379
 			$context['files']['other'][] = $context_data;
368 380
 		}
369 381
 
370 382
 		// Collect together all non-writable areas.
371
-		if (!$context_data['writable'])
372
-			$context['make_writable'][] = $context_data['destination'];
383
+		if (!$context_data['writable']) {
384
+					$context['make_writable'][] = $context_data['destination'];
385
+		}
373 386
 	}
374 387
 
375 388
 	// Before we go to far can we make anything writable, eh, eh?
@@ -384,22 +397,24 @@  discard block
 block discarded – undo
384 397
 		{
385 398
 			if ($type == 'lang')
386 399
 			{
387
-				foreach ($data as $k => $file)
388
-					if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
400
+				foreach ($data as $k => $file) {
401
+									if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
389 402
 						$context['files'][$type][$k]['writable'] = true;
390
-			}
391
-			else
403
+				}
404
+			} else
392 405
 			{
393
-				foreach ($data as $theme => $files)
394
-					foreach ($files as $k => $file)
406
+				foreach ($data as $theme => $files) {
407
+									foreach ($files as $k => $file)
395 408
 						if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
396 409
 							$context['files'][$type][$theme][$k]['writable'] = true;
410
+				}
397 411
 			}
398 412
 		}
399 413
 
400 414
 		// Are we going to need more language stuff?
401
-		if (!empty($context['still_not_writable']))
402
-			loadLanguage('Packages');
415
+		if (!empty($context['still_not_writable'])) {
416
+					loadLanguage('Packages');
417
+		}
403 418
 	}
404 419
 
405 420
 	// This is the list for the main files.
@@ -612,12 +627,13 @@  discard block
 block discarded – undo
612 627
 	highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true);
613 628
 
614 629
 	// Display a warning if we cannot edit the default setting.
615
-	if (!is_writable($boarddir . '/Settings.php'))
616
-		$listOptions['additional_rows'][] = array(
630
+	if (!is_writable($boarddir . '/Settings.php')) {
631
+			$listOptions['additional_rows'][] = array(
617 632
 				'position' => 'after_title',
618 633
 				'value' => $txt['language_settings_writable'],
619 634
 				'class' => 'smalltext alert',
620 635
 			);
636
+	}
621 637
 
622 638
 	require_once($sourcedir . '/Subs-List.php');
623 639
 	createList($listOptions);
@@ -659,10 +675,11 @@  discard block
 block discarded – undo
659 675
 
660 676
 	// Put them back.
661 677
 	$settings['actual_theme_dir'] = $backup_actual_theme_dir;
662
-	if (!empty($backup_base_theme_dir))
663
-		$settings['base_theme_dir'] = $backup_base_theme_dir;
664
-	else
665
-		unset($settings['base_theme_dir']);
678
+	if (!empty($backup_base_theme_dir)) {
679
+			$settings['base_theme_dir'] = $backup_base_theme_dir;
680
+	} else {
681
+			unset($settings['base_theme_dir']);
682
+	}
666 683
 
667 684
 	// Get the language files and data...
668 685
 	foreach ($context['languages'] as $lang)
@@ -691,13 +708,15 @@  discard block
 block discarded – undo
691 708
 	while ($row = $smcFunc['db_fetch_assoc']($request))
692 709
 	{
693 710
 		// Default?
694
-		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']]))
695
-			$row['lngfile'] = $language;
711
+		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) {
712
+					$row['lngfile'] = $language;
713
+		}
696 714
 
697
-		if (!isset($languages[$row['lngfile']]) && isset($languages['english']))
698
-			$languages['english']['count'] += $row['num_users'];
699
-		elseif (isset($languages[$row['lngfile']]))
700
-			$languages[$row['lngfile']]['count'] += $row['num_users'];
715
+		if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) {
716
+					$languages['english']['count'] += $row['num_users'];
717
+		} elseif (isset($languages[$row['lngfile']])) {
718
+					$languages[$row['lngfile']]['count'] += $row['num_users'];
719
+		}
701 720
 	}
702 721
 	$smcFunc['db_free_result']($request);
703 722
 
@@ -737,13 +756,15 @@  discard block
 block discarded – undo
737 756
 
738 757
 	call_integration_hook('integrate_language_settings', array(&$config_vars));
739 758
 
740
-	if ($return_config)
741
-		return $config_vars;
759
+	if ($return_config) {
760
+			return $config_vars;
761
+	}
742 762
 
743 763
 	// Get our languages. No cache
744 764
 	getLanguages(false);
745
-	foreach ($context['languages'] as $lang)
746
-		$config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']);
765
+	foreach ($context['languages'] as $lang) {
766
+			$config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']);
767
+	}
747 768
 
748 769
 	// Saving settings?
749 770
 	if (isset($_REQUEST['save']))
@@ -753,8 +774,9 @@  discard block
 block discarded – undo
753 774
 		call_integration_hook('integrate_save_language_settings', array(&$config_vars));
754 775
 
755 776
 		saveSettings($config_vars);
756
-		if (!$settings_not_writable && !$settings_backup_fail)
757
-			$_SESSION['adm-save'] = true;
777
+		if (!$settings_not_writable && !$settings_backup_fail) {
778
+					$_SESSION['adm-save'] = true;
779
+		}
758 780
 		redirectexit('action=admin;area=languages;sa=settings');
759 781
 	}
760 782
 
@@ -763,10 +785,11 @@  discard block
 block discarded – undo
763 785
 	$context['settings_title'] = $txt['language_settings'];
764 786
 	$context['save_disabled'] = $settings_not_writable;
765 787
 
766
-	if ($settings_not_writable)
767
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
768
-	elseif ($settings_backup_fail)
769
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
788
+	if ($settings_not_writable) {
789
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
790
+	} elseif ($settings_backup_fail) {
791
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
792
+	}
770 793
 
771 794
 	// Fill the config array.
772 795
 	prepareServerSettingsContext($config_vars);
@@ -813,8 +836,9 @@  discard block
 block discarded – undo
813 836
 			'theme_dir' => $settings['default_theme_dir'],
814 837
 		),
815 838
 	);
816
-	while ($row = $smcFunc['db_fetch_assoc']($request))
817
-		$themes[$row['id_theme']][$row['variable']] = $row['value'];
839
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
840
+			$themes[$row['id_theme']][$row['variable']] = $row['value'];
841
+	}
818 842
 	$smcFunc['db_free_result']($request);
819 843
 
820 844
 	// This will be where we look
@@ -847,14 +871,16 @@  discard block
 block discarded – undo
847 871
 	// Check we have themes with a path and a name - just in case - and add the path.
848 872
 	foreach ($themes as $id => $data)
849 873
 	{
850
-		if (count($data) != 2)
851
-			unset($themes[$id]);
852
-		elseif (is_dir($data['theme_dir'] . '/languages'))
853
-			$lang_dirs[$id] = $data['theme_dir'] . '/languages';
874
+		if (count($data) != 2) {
875
+					unset($themes[$id]);
876
+		} elseif (is_dir($data['theme_dir'] . '/languages')) {
877
+					$lang_dirs[$id] = $data['theme_dir'] . '/languages';
878
+		}
854 879
 
855 880
 		// How about image directories?
856
-		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id']))
857
-			$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
881
+		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) {
882
+					$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
883
+		}
858 884
 	}
859 885
 
860 886
 	$current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : '';
@@ -868,15 +894,17 @@  discard block
 block discarded – undo
868 894
 		while ($entry = $dir->read())
869 895
 		{
870 896
 			// We're only after the files for this language.
871
-			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0)
872
-				continue;
897
+			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) {
898
+							continue;
899
+			}
873 900
 
874
-			if (!isset($context['possible_files'][$theme]))
875
-				$context['possible_files'][$theme] = array(
901
+			if (!isset($context['possible_files'][$theme])) {
902
+							$context['possible_files'][$theme] = array(
876 903
 					'id' => $theme,
877 904
 					'name' => $themes[$theme]['name'],
878 905
 					'files' => array(),
879 906
 				);
907
+			}
880 908
 
881 909
 			$context['possible_files'][$theme]['files'][] = array(
882 910
 				'id' => $matches[1],
@@ -905,31 +933,36 @@  discard block
 block discarded – undo
905 933
 		{
906 934
 			$_SESSION['last_backup_for'] = $context['lang_id'] . '$$$';
907 935
 			$result = package_create_backup('backup_lang_' . $context['lang_id']);
908
-			if (!$result)
909
-				fatal_lang_error('could_not_language_backup', false);
936
+			if (!$result) {
937
+							fatal_lang_error('could_not_language_backup', false);
938
+			}
910 939
 		}
911 940
 
912 941
 		// Second, loop through the array to remove the files.
913 942
 		foreach ($lang_dirs as $curPath)
914 943
 		{
915
-			foreach ($context['possible_files'][1]['files'] as $lang)
916
-				if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
944
+			foreach ($context['possible_files'][1]['files'] as $lang) {
945
+							if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
917 946
 					unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php');
947
+			}
918 948
 
919 949
 			// Check for the email template.
920
-			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'))
921
-				unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
950
+			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) {
951
+							unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
952
+			}
922 953
 		}
923 954
 
924 955
 		// Third, the agreement file.
925
-		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt'))
926
-			unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
956
+		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) {
957
+					unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
958
+		}
927 959
 
928 960
 		// Fourth, a related images folder, if it exists...
929
-		if (!empty($images_dirs))
930
-			foreach ($images_dirs as $curPath)
961
+		if (!empty($images_dirs)) {
962
+					foreach ($images_dirs as $curPath)
931 963
 				if (is_dir($curPath))
932 964
 					deltree($curPath);
965
+		}
933 966
 
934 967
 		// Members can no longer use this language.
935 968
 		$smcFunc['db_query']('', '
@@ -973,8 +1006,9 @@  discard block
 block discarded – undo
973 1006
 
974 1007
 		// Build the replacements. old => new
975 1008
 		$replace_array = array();
976
-		foreach ($primary_settings as $setting => $type)
977
-			$replace_array['~\$txt\[\'' . $setting . '\'\]\s*=\s*[^\r\n]+~'] = '$txt[\'' . $setting . '\'] = ' . ($type === 'bool' ? (!empty($_POST[$setting]) ? 'true' : 'false') : '\'' . ($setting = 'native_name' ? htmlentities(un_htmlspecialchars($_POST[$setting]), ENT_QUOTES, $context['character_set']) : preg_replace('~[^\w-]~i', '', $_POST[$setting])) . '\'') . ';';
1009
+		foreach ($primary_settings as $setting => $type) {
1010
+					$replace_array['~\$txt\[\'' . $setting . '\'\]\s*=\s*[^\r\n]+~'] = '$txt[\'' . $setting . '\'] = ' . ($type === 'bool' ? (!empty($_POST[$setting]) ? 'true' : 'false') : '\'' . ($setting = 'native_name' ? htmlentities(un_htmlspecialchars($_POST[$setting]), ENT_QUOTES, $context['character_set']) : preg_replace('~[^\w-]~i', '', $_POST[$setting])) . '\'') . ';';
1011
+		}
978 1012
 
979 1013
 		$current_data = preg_replace(array_keys($replace_array), array_values($replace_array), $current_data);
980 1014
 		$fp = fopen($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php', 'w+');
@@ -1017,30 +1051,29 @@  discard block
 block discarded – undo
1017 1051
 				if (is_string($v))
1018 1052
 				{
1019 1053
 					// Only try to save if 'edit' was specified and if the string has changed
1020
-					if ($v == 'edit' && isset($_POST['entry'][$k]) && isset($_POST['comp'][$k]) && $_POST['entry'][$k] != $_POST['comp'][$k])
1021
-						$save_strings[$k] = cleanLangString($_POST['entry'][$k], false);
1054
+					if ($v == 'edit' && isset($_POST['entry'][$k]) && isset($_POST['comp'][$k]) && $_POST['entry'][$k] != $_POST['comp'][$k]) {
1055
+											$save_strings[$k] = cleanLangString($_POST['entry'][$k], false);
1056
+					}
1022 1057
 
1023 1058
 					// Record any add or remove requests. We'll decide on them later.
1024
-					elseif ($v == 'remove')
1025
-						$remove_strings[] = $k;
1026
-					elseif ($v == 'add' && isset($_POST['entry'][$k]))
1059
+					elseif ($v == 'remove') {
1060
+											$remove_strings[] = $k;
1061
+					} elseif ($v == 'add' && isset($_POST['entry'][$k]))
1027 1062
 					{
1028 1063
 						$add_strings[$k] = array(
1029 1064
 							'group' => isset($_POST['grp'][$k]) ? $_POST['grp'][$k] : 'txt',
1030 1065
 							'string' => cleanLangString($_POST['entry'][$k], false),
1031 1066
 						);
1032 1067
 					}
1033
-				}
1034
-				elseif (is_array($v))
1068
+				} elseif (is_array($v))
1035 1069
 				{
1036 1070
 					foreach ($v as $subk => $subv)
1037 1071
 					{
1038
-						if ($subv == 'edit' && isset($_POST['entry'][$k][$subk]) && isset($_POST['comp'][$k][$subk]) && $_POST['entry'][$k][$subk] != $_POST['comp'][$k][$subk])
1039
-							$save_strings[$k][$subk] = cleanLangString($_POST['entry'][$k][$subk], false);
1040
-
1041
-						elseif ($subv == 'remove')
1042
-							$remove_strings[$k][] = $subk;
1043
-						elseif ($subv == 'add' && isset($_POST['entry'][$k][$subk]))
1072
+						if ($subv == 'edit' && isset($_POST['entry'][$k][$subk]) && isset($_POST['comp'][$k][$subk]) && $_POST['entry'][$k][$subk] != $_POST['comp'][$k][$subk]) {
1073
+													$save_strings[$k][$subk] = cleanLangString($_POST['entry'][$k][$subk], false);
1074
+						} elseif ($subv == 'remove') {
1075
+													$remove_strings[$k][] = $subk;
1076
+						} elseif ($subv == 'add' && isset($_POST['entry'][$k][$subk]))
1044 1077
 						{
1045 1078
 							$add_strings[$k][$subk] = array(
1046 1079
 								'group' => isset($_POST['grp'][$k]) ? $_POST['grp'][$k] : 'txt',
@@ -1076,8 +1109,9 @@  discard block
 block discarded – undo
1076 1109
 			foreach ($allows_add_remove[$file_id]['add'] as $var_group)
1077 1110
 			{
1078 1111
 				$group = !empty($special_groups[$file_id][$var_group]) ? $special_groups[$file_id][$var_group] : $var_group;
1079
-				if (in_array($var_group, $allows_add_remove[$file_id]['add']))
1080
-					$context['can_add_lang_entry'][$group] = true;
1112
+				if (in_array($var_group, $allows_add_remove[$file_id]['add'])) {
1113
+									$context['can_add_lang_entry'][$group] = true;
1114
+				}
1081 1115
 			}
1082 1116
 		}
1083 1117
 
@@ -1115,15 +1149,17 @@  discard block
 block discarded – undo
1115 1149
 		foreach ($entries as $entryKey => $entryValue)
1116 1150
 		{
1117 1151
 			// Ignore some things we set separately.
1118
-			if (in_array($entryKey, array_keys($primary_settings)))
1119
-				continue;
1152
+			if (in_array($entryKey, array_keys($primary_settings))) {
1153
+							continue;
1154
+			}
1120 1155
 
1121 1156
 			// These are arrays that need breaking out.
1122 1157
 			if (strpos($entryValue['entry'], 'array(') === 0 && strpos($entryValue['entry'], ')', -1) === strlen($entryValue['entry']) - 1)
1123 1158
 			{
1124 1159
 				// No, you may not use multidimensional arrays of $txt strings. Madness stalks that path.
1125
-				if (isset($entryValue['subkey']))
1126
-					continue;
1160
+				if (isset($entryValue['subkey'])) {
1161
+									continue;
1162
+				}
1127 1163
 
1128 1164
 				// Trim off the array construct bits.
1129 1165
 				$entryValue['entry'] = substr($entryValue['entry'], strpos($entryValue['entry'], 'array(') + 6, -1);
@@ -1166,8 +1202,9 @@  discard block
 block discarded – undo
1166 1202
 
1167 1203
 					/x' . ($context['utf8'] ? 'u' : ''), $entryValue['entry'], $matches);
1168 1204
 
1169
-				if (empty($m))
1170
-					continue;
1205
+				if (empty($m)) {
1206
+									continue;
1207
+				}
1171 1208
 
1172 1209
 				$entryValue['entry'] = $matches[0];
1173 1210
 
@@ -1184,19 +1221,21 @@  discard block
 block discarded – undo
1184 1221
 					{
1185 1222
 						$subKey = trim($matches[1], '\'"');
1186 1223
 
1187
-						if (ctype_digit($subKey))
1188
-							$cur_index = $subKey;
1224
+						if (ctype_digit($subKey)) {
1225
+													$cur_index = $subKey;
1226
+						}
1189 1227
 
1190 1228
 						$subValue = trim(substr($subValue, strpos($subValue, '=>') + 2));
1229
+					} else {
1230
+											$subKey = $cur_index++;
1191 1231
 					}
1192
-					else
1193
-						$subKey = $cur_index++;
1194 1232
 
1195 1233
 					// Clean up some bits.
1196
-					if (strpos($subValue, '\'') === 0)
1197
-						$subValue = trim($subValue, '\'');
1198
-					elseif (strpos($subValue, '"') === 0)
1199
-						$subValue = trim($subValue, '"');
1234
+					if (strpos($subValue, '\'') === 0) {
1235
+											$subValue = trim($subValue, '\'');
1236
+					} elseif (strpos($subValue, '"') === 0) {
1237
+											$subValue = trim($subValue, '"');
1238
+					}
1200 1239
 
1201 1240
 					// Can we save?
1202 1241
 					if (isset($save_strings[$entryKey][$subKey]))
@@ -1205,11 +1244,13 @@  discard block
 block discarded – undo
1205 1244
 						$save_cache['enabled'] = true;
1206 1245
 					}
1207 1246
 					// Should we remove this one?
1208
-					elseif (isset($remove_strings[$entryKey]) && in_array($subKey, $remove_strings[$entryKey]) && $entryValue['can_remove'])
1209
-						$save_cache['enabled'] = true;
1247
+					elseif (isset($remove_strings[$entryKey]) && in_array($subKey, $remove_strings[$entryKey]) && $entryValue['can_remove']) {
1248
+											$save_cache['enabled'] = true;
1249
+					}
1210 1250
 					// Just keep this one as it is
1211
-					else
1212
-						$save_cache['entries'][$subKey] = $subValue;
1251
+					else {
1252
+											$save_cache['entries'][$subKey] = $subValue;
1253
+					}
1213 1254
 
1214 1255
 					$context['file_entries'][$entryValue['group']][] = array(
1215 1256
 						'key' => $entryKey,
@@ -1223,15 +1264,17 @@  discard block
 block discarded – undo
1223 1264
 				// Should we add a new string to this array?
1224 1265
 				if (!empty($context['can_add_lang_entry'][$entryValue['type']]) && isset($add_strings[$entryKey]))
1225 1266
 				{
1226
-					foreach ($add_strings[$entryKey] as $string_key => $string_val)
1227
-						$save_cache['entries'][$string_key] = strtr($string_val['string'], array('\'' => ''));
1267
+					foreach ($add_strings[$entryKey] as $string_key => $string_val) {
1268
+											$save_cache['entries'][$string_key] = strtr($string_val['string'], array('\'' => ''));
1269
+					}
1228 1270
 
1229 1271
 					$save_cache['enabled'] = true;
1230 1272
 
1231 1273
 					// Make sure we don't add this again as an independent line
1232 1274
 					unset($add_strings[$entryKey][$string_key]);
1233
-					if (empty($add_strings[$entryKey]))
1234
-						unset($add_strings[$entryKey]);
1275
+					if (empty($add_strings[$entryKey])) {
1276
+											unset($add_strings[$entryKey]);
1277
+					}
1235 1278
 				}
1236 1279
 
1237 1280
 
@@ -1248,9 +1291,9 @@  discard block
 block discarded – undo
1248 1291
 						{
1249 1292
 							$items[] = $k2 . ' => \'' . $v2 . '\'';
1250 1293
 							$cur_index = $k2;
1294
+						} else {
1295
+													$items[] = '\'' . $v2 . '\'';
1251 1296
 						}
1252
-						else
1253
-							$items[] = '\'' . $v2 . '\'';
1254 1297
 
1255 1298
 						$cur_index++;
1256 1299
 					}
@@ -1267,8 +1310,9 @@  discard block
 block discarded – undo
1267 1310
 				// Saving?
1268 1311
 				if (isset($save_strings[$entryValue['key']][$entryValue['subkey']]) && $save_strings[$entryValue['key']][$entryValue['subkey']] != $entryValue['entry'])
1269 1312
 				{
1270
-					if ($save_strings[$entryValue['key']][$entryValue['subkey']] == '')
1271
-						$save_strings[$entryValue['key']][$entryValue['subkey']] = '\'\'';
1313
+					if ($save_strings[$entryValue['key']][$entryValue['subkey']] == '') {
1314
+											$save_strings[$entryValue['key']][$entryValue['subkey']] = '\'\'';
1315
+					}
1272 1316
 
1273 1317
 					// Preserve subkey as either digit or string
1274 1318
 					$subKey = ctype_digit($entryValue['subkey']) ? $entryValue['subkey'] : '\'' . $entryValue['subkey'] . '\'';
@@ -1309,8 +1353,9 @@  discard block
 block discarded – undo
1309 1353
 				if (isset($save_strings[$entryValue['key']]) && $save_strings[$entryValue['key']] != $entryValue['entry'])
1310 1354
 				{
1311 1355
 					// @todo Fix this properly.
1312
-					if ($save_strings[$entryValue['key']] == '')
1313
-						$save_strings[$entryValue['key']] = '\'\'';
1356
+					if ($save_strings[$entryValue['key']] == '') {
1357
+											$save_strings[$entryValue['key']] = '\'\'';
1358
+					}
1314 1359
 
1315 1360
 					// Set the new value.
1316 1361
 					$entryValue['entry'] = $save_strings[$entryValue['key']];
@@ -1353,8 +1398,9 @@  discard block
 block discarded – undo
1353 1398
 				{
1354 1399
 					$type = isset($special_types[$string_val['group']]) ? $special_types[$string_val['group']] : $string_val['group'];
1355 1400
 
1356
-					if (empty($context['can_add_lang_entry'][$type]))
1357
-						continue;
1401
+					if (empty($context['can_add_lang_entry'][$type])) {
1402
+											continue;
1403
+					}
1358 1404
 
1359 1405
 					$final_saves[$string_key] = array(
1360 1406
 						'find' => "\s*\?".'>$',
@@ -1369,8 +1415,9 @@  discard block
 block discarded – undo
1369 1415
 					{
1370 1416
 						$type = isset($special_types[$substring_val['group']]) ? $special_types[$substring_val['group']] : $substring_val['group'];
1371 1417
 
1372
-						if (empty($context['can_add_lang_entry'][$type]))
1373
-							continue;
1418
+						if (empty($context['can_add_lang_entry'][$type])) {
1419
+													continue;
1420
+						}
1374 1421
 
1375 1422
 						$subKey = ctype_digit(trim($substring_key, '\'')) ? trim($substring_key, '\'') : '\'' . $substring_key . '\'';
1376 1423
 
@@ -1393,10 +1440,11 @@  discard block
 block discarded – undo
1393 1440
 
1394 1441
 			foreach ($final_saves as $save)
1395 1442
 			{
1396
-				if (!empty($save['is_regex']))
1397
-					$file_contents = preg_replace('~' . $save['find'] . '~' . ($context['utf8'] ? 'u' : ''), $save['replace'], $file_contents);
1398
-				else
1399
-					$file_contents = str_replace($save['find'], $save['replace'], $file_contents);
1443
+				if (!empty($save['is_regex'])) {
1444
+									$file_contents = preg_replace('~' . $save['find'] . '~' . ($context['utf8'] ? 'u' : ''), $save['replace'], $file_contents);
1445
+				} else {
1446
+									$file_contents = str_replace($save['find'], $save['replace'], $file_contents);
1447
+				}
1400 1448
 			}
1401 1449
 
1402 1450
 			// Save the actual changes.
@@ -1414,8 +1462,9 @@  discard block
 block discarded – undo
1414 1462
 			// Make sure the Add button has a place to show up.
1415 1463
 			foreach ($context['can_add_lang_entry'] as $group => $value)
1416 1464
 			{
1417
-				if (!isset($context['file_entries'][$group]))
1418
-					$context['file_entries'][$group] = array();
1465
+				if (!isset($context['file_entries'][$group])) {
1466
+									$context['file_entries'][$group] = array();
1467
+				}
1419 1468
 			}
1420 1469
 
1421 1470
 			addInlineJavaScript('
@@ -1507,8 +1556,9 @@  discard block
 block discarded – undo
1507 1556
 	}
1508 1557
 
1509 1558
 	// If we saved, redirect.
1510
-	if ($madeSave)
1511
-		redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id'] . (!empty($file_id) ? ';entries;tfid=' . $theme_id . rawurlencode('+') . $file_id : ''));
1559
+	if ($madeSave) {
1560
+			redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id'] . (!empty($file_id) ? ';entries;tfid=' . $theme_id . rawurlencode('+') . $file_id : ''));
1561
+	}
1512 1562
 
1513 1563
 	createToken('admin-mlang');
1514 1564
 }
@@ -1540,8 +1590,9 @@  discard block
 block discarded – undo
1540 1590
 				// Toggle the escape.
1541 1591
 				$is_escape = !$is_escape;
1542 1592
 				// If we're now escaped don't add this string.
1543
-				if ($is_escape)
1544
-					continue;
1593
+				if ($is_escape) {
1594
+									continue;
1595
+				}
1545 1596
 			}
1546 1597
 			// Special case - parsed string with line break etc?
1547 1598
 			elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape)
@@ -1558,11 +1609,13 @@  discard block
 block discarded – undo
1558 1609
 				if ($in_string != 2 && ($in_string != 1 || !$is_escape))
1559 1610
 				{
1560 1611
 					// Is it the end of a single quote string?
1561
-					if ($in_string == 1)
1562
-						$in_string = 0;
1612
+					if ($in_string == 1) {
1613
+											$in_string = 0;
1614
+					}
1563 1615
 					// Otherwise it's the start!
1564
-					else
1565
-						$in_string = 1;
1616
+					else {
1617
+											$in_string = 1;
1618
+					}
1566 1619
 
1567 1620
 					// Don't actually include this character!
1568 1621
 					continue;
@@ -1575,19 +1628,22 @@  discard block
 block discarded – undo
1575 1628
 				if ($in_string != 1 && ($in_string != 2 || !$is_escape))
1576 1629
 				{
1577 1630
 					// Is it the end of a double quote string?
1578
-					if ($in_string == 2)
1579
-						$in_string = 0;
1631
+					if ($in_string == 2) {
1632
+											$in_string = 0;
1633
+					}
1580 1634
 					// Otherwise it's the start!
1581
-					else
1582
-						$in_string = 2;
1635
+					else {
1636
+											$in_string = 2;
1637
+					}
1583 1638
 
1584 1639
 					// Don't actually include this character!
1585 1640
 					continue;
1586 1641
 				}
1587 1642
 			}
1588 1643
 			// A join/space outside of a string is simply removed.
1589
-			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.'))
1590
-				continue;
1644
+			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) {
1645
+							continue;
1646
+			}
1591 1647
 			// Start of a variable?
1592 1648
 			elseif ($in_string == 0 && $string{$i} == '$')
1593 1649
 			{
@@ -1621,8 +1677,7 @@  discard block
 block discarded – undo
1621 1677
 
1622 1678
 		// Unhtml then rehtml the whole thing!
1623 1679
 		$new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string));
1624
-	}
1625
-	else
1680
+	} else
1626 1681
 	{
1627 1682
 		// Keep track of what we're doing...
1628 1683
 		$in_string = 0;
@@ -1651,10 +1706,11 @@  discard block
 block discarded – undo
1651 1706
 				preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches);
1652 1707
 				if (!empty($matches[1]))
1653 1708
 				{
1654
-					if ($in_string == 1)
1655
-						$new_string .= '\' . ';
1656
-					elseif ($new_string)
1657
-						$new_string .= ' . ';
1709
+					if ($in_string == 1) {
1710
+											$new_string .= '\' . ';
1711
+					} elseif ($new_string) {
1712
+											$new_string .= ' . ';
1713
+					}
1658 1714
 
1659 1715
 					$new_string .= $matches[1];
1660 1716
 					$i += strlen($matches[1]) + 3;
@@ -1667,8 +1723,9 @@  discard block
 block discarded – undo
1667 1723
 			elseif ($string{$i} == '<')
1668 1724
 			{
1669 1725
 				// Probably HTML?
1670
-				if ($string{$i + 1} != ' ')
1671
-					$in_html = true;
1726
+				if ($string{$i + 1} != ' ') {
1727
+									$in_html = true;
1728
+				}
1672 1729
 				// Assume we need an entity...
1673 1730
 				else
1674 1731
 				{
@@ -1680,8 +1737,9 @@  discard block
 block discarded – undo
1680 1737
 			elseif ($string{$i} == '>')
1681 1738
 			{
1682 1739
 				// Will it be HTML?
1683
-				if ($in_html)
1684
-					$in_html = false;
1740
+				if ($in_html) {
1741
+									$in_html = false;
1742
+				}
1685 1743
 				// Otherwise we need an entity...
1686 1744
 				else
1687 1745
 				{
@@ -1690,8 +1748,9 @@  discard block
 block discarded – undo
1690 1748
 				}
1691 1749
 			}
1692 1750
 			// Is it a slash? If so escape it...
1693
-			if ($string{$i} == '\\')
1694
-				$new_string .= '\\';
1751
+			if ($string{$i} == '\\') {
1752
+							$new_string .= '\\';
1753
+			}
1695 1754
 			// The infamous double quote?
1696 1755
 			elseif ($string{$i} == '"')
1697 1756
 			{
@@ -1714,10 +1773,11 @@  discard block
 block discarded – undo
1714 1773
 		}
1715 1774
 
1716 1775
 		// If we ended as a string then close it off.
1717
-		if ($in_string == 1)
1718
-			$new_string .= '\'';
1719
-		elseif ($in_string == 2)
1720
-			$new_string .= '"';
1776
+		if ($in_string == 1) {
1777
+					$new_string .= '\'';
1778
+		} elseif ($in_string == 2) {
1779
+					$new_string .= '"';
1780
+		}
1721 1781
 	}
1722 1782
 
1723 1783
 	return $new_string;
Please login to merge, or discard this patch.
Sources/Subs-Editor.php 1 patch
Braces   +408 added lines, -307 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
  * As of SMF 2.1, this is unused. But it is available if any mod wants to use it.
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 {
31 32
 	global $modSettings;
32 33
 
33
-	if (!$compat_mode)
34
-		return $text;
34
+	if (!$compat_mode) {
35
+			return $text;
36
+	}
35 37
 
36 38
 	// Turn line breaks back into br's.
37 39
 	$text = strtr($text, array("\r" => '', "\n" => '<br>'));
@@ -48,8 +50,9 @@  discard block
 block discarded – undo
48 50
 			for ($i = 0, $n = count($parts); $i < $n; $i++)
49 51
 			{
50 52
 				// Value of 2 means we're inside the tag.
51
-				if ($i % 4 == 2)
52
-					$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
53
+				if ($i % 4 == 2) {
54
+									$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
55
+				}
53 56
 			}
54 57
 			// Put our humpty dumpty message back together again.
55 58
 			$text = implode('', $parts);
@@ -104,8 +107,9 @@  discard block
 block discarded – undo
104 107
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
105 108
 
106 109
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
107
-	if (isBrowser('webkit'))
108
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
110
+	if (isBrowser('webkit')) {
111
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
112
+	}
109 113
 
110 114
 	// If there's a trailing break get rid of it - Firefox tends to add one.
111 115
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -120,8 +124,9 @@  discard block
 block discarded – undo
120 124
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
121 125
 		{
122 126
 			// Value of 2 means we're inside the tag.
123
-			if ($i % 4 == 2)
124
-				$parts[$i] = strip_tags($parts[$i]);
127
+			if ($i % 4 == 2) {
128
+							$parts[$i] = strip_tags($parts[$i]);
129
+			}
125 130
 		}
126 131
 
127 132
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -147,18 +152,19 @@  discard block
 block discarded – undo
147 152
 			{
148 153
 				$found = array_search($file, $smileysto);
149 154
 				// Note the weirdness here is to stop double spaces between smileys.
150
-				if ($found)
151
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
152
-				else
153
-					$matches[1][$k] = '';
155
+				if ($found) {
156
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
157
+				} else {
158
+									$matches[1][$k] = '';
159
+				}
154 160
 			}
155
-		}
156
-		else
161
+		} else
157 162
 		{
158 163
 			// Load all the smileys.
159 164
 			$names = array();
160
-			foreach ($matches[1] as $file)
161
-				$names[] = $file;
165
+			foreach ($matches[1] as $file) {
166
+							$names[] = $file;
167
+			}
162 168
 			$names = array_unique($names);
163 169
 
164 170
 			if (!empty($names))
@@ -172,13 +178,15 @@  discard block
 block discarded – undo
172 178
 					)
173 179
 				);
174 180
 				$mappings = array();
175
-				while ($row = $smcFunc['db_fetch_assoc']($request))
176
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
181
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
182
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
183
+				}
177 184
 				$smcFunc['db_free_result']($request);
178 185
 
179
-				foreach ($matches[1] as $k => $file)
180
-					if (isset($mappings[$file]))
186
+				foreach ($matches[1] as $k => $file) {
187
+									if (isset($mappings[$file]))
181 188
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
189
+				}
182 190
 			}
183 191
 		}
184 192
 
@@ -190,8 +198,9 @@  discard block
 block discarded – undo
190 198
 	}
191 199
 
192 200
 	// Only try to buy more time if the client didn't quit.
193
-	if (connection_aborted() && $context['server']['is_apache'])
194
-		@apache_reset_timeout();
201
+	if (connection_aborted() && $context['server']['is_apache']) {
202
+			@apache_reset_timeout();
203
+	}
195 204
 
196 205
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
197 206
 	$replacement = '';
@@ -202,9 +211,9 @@  discard block
 block discarded – undo
202 211
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
203 212
 		{
204 213
 			// If it's being closed instantly, we can't deal with it...yet.
205
-			if ($matches[5] === '/')
206
-				continue;
207
-			else
214
+			if ($matches[5] === '/') {
215
+							continue;
216
+			} else
208 217
 			{
209 218
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
210 219
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -220,8 +229,9 @@  discard block
 block discarded – undo
220 229
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
221 230
 
222 231
 					// Something like 'font-weight: bold' is expected here.
223
-					if (strpos($clean_type_value_pair, ':') === false)
224
-						continue;
232
+					if (strpos($clean_type_value_pair, ':') === false) {
233
+											continue;
234
+					}
225 235
 
226 236
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
227 237
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -243,8 +253,7 @@  discard block
 block discarded – undo
243 253
 							{
244 254
 								$curCloseTags .= '[/u]';
245 255
 								$replacement .= '[u]';
246
-							}
247
-							elseif ($style_value == 'line-through')
256
+							} elseif ($style_value == 'line-through')
248 257
 							{
249 258
 								$curCloseTags .= '[/s]';
250 259
 								$replacement .= '[s]';
@@ -256,13 +265,11 @@  discard block
 block discarded – undo
256 265
 							{
257 266
 								$curCloseTags .= '[/left]';
258 267
 								$replacement .= '[left]';
259
-							}
260
-							elseif ($style_value == 'center')
268
+							} elseif ($style_value == 'center')
261 269
 							{
262 270
 								$curCloseTags .= '[/center]';
263 271
 								$replacement .= '[center]';
264
-							}
265
-							elseif ($style_value == 'right')
272
+							} elseif ($style_value == 'right')
266 273
 							{
267 274
 								$curCloseTags .= '[/right]';
268 275
 								$replacement .= '[right]';
@@ -284,8 +291,9 @@  discard block
 block discarded – undo
284 291
 
285 292
 						case 'font-size':
286 293
 							// Sometimes people put decimals where decimals should not be.
287
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
288
-								$style_value = $dec_matches[1] . $dec_matches[2];
294
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
295
+															$style_value = $dec_matches[1] . $dec_matches[2];
296
+							}
289 297
 
290 298
 							$curCloseTags .= '[/size]';
291 299
 							$replacement .= '[size=' . $style_value . ']';
@@ -293,8 +301,9 @@  discard block
 block discarded – undo
293 301
 
294 302
 						case 'font-family':
295 303
 							// Only get the first freaking font if there's a list!
296
-							if (strpos($style_value, ',') !== false)
297
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
304
+							if (strpos($style_value, ',') !== false) {
305
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
306
+							}
298 307
 
299 308
 							$curCloseTags .= '[/font]';
300 309
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -303,13 +312,15 @@  discard block
 block discarded – undo
303 312
 						// This is a hack for images with dimensions embedded.
304 313
 						case 'width':
305 314
 						case 'height':
306
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
307
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
315
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
316
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
317
+							}
308 318
 						break;
309 319
 
310 320
 						case 'list-style-type':
311
-							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1)
312
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
321
+							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) {
322
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
323
+							}
313 324
 						break;
314 325
 					}
315 326
 				}
@@ -322,18 +333,17 @@  discard block
 block discarded – undo
322 333
 				}
323 334
 
324 335
 				// If there's something that still needs closing, push it to the stack.
325
-				if (!empty($curCloseTags))
326
-					array_push($stack, array(
336
+				if (!empty($curCloseTags)) {
337
+									array_push($stack, array(
327 338
 							'element' => strtolower($curElement),
328 339
 							'closeTags' => $curCloseTags
329 340
 						)
330 341
 					);
331
-				elseif (!empty($extra_attr))
332
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
342
+				} elseif (!empty($extra_attr)) {
343
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
344
+				}
333 345
 			}
334
-		}
335
-
336
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
346
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
337 347
 		{
338 348
 			// Is this the element that we've been waiting for to be closed?
339 349
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -343,28 +353,32 @@  discard block
 block discarded – undo
343 353
 			}
344 354
 
345 355
 			// Must've been something else.
346
-			else
347
-				$replacement .= $part;
356
+			else {
357
+							$replacement .= $part;
358
+			}
348 359
 		}
349 360
 		// In all other cases, just add the part to the replacement.
350
-		else
351
-			$replacement .= $part;
361
+		else {
362
+					$replacement .= $part;
363
+		}
352 364
 	}
353 365
 
354 366
 	// Now put back the replacement in the text.
355 367
 	$text = $replacement;
356 368
 
357 369
 	// We are not finished yet, request more time.
358
-	if (connection_aborted() && $context['server']['is_apache'])
359
-		@apache_reset_timeout();
370
+	if (connection_aborted() && $context['server']['is_apache']) {
371
+			@apache_reset_timeout();
372
+	}
360 373
 
361 374
 	// Let's pull out any legacy alignments.
362 375
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
363 376
 	{
364 377
 		// Find the position in the text of this tag over again.
365 378
 		$start_pos = strpos($text, $matches[0]);
366
-		if ($start_pos === false)
367
-			break;
379
+		if ($start_pos === false) {
380
+					break;
381
+		}
368 382
 
369 383
 		// End tag?
370 384
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -378,8 +392,7 @@  discard block
 block discarded – undo
378 392
 
379 393
 			// Put the tags back into the body.
380 394
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
381
-		}
382
-		else
395
+		} else
383 396
 		{
384 397
 			// Just get rid of this evil tag.
385 398
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -392,8 +405,9 @@  discard block
 block discarded – undo
392 405
 		// Find the position of this again.
393 406
 		$start_pos = strpos($text, $matches[0]);
394 407
 		$end_pos = false;
395
-		if ($start_pos === false)
396
-			break;
408
+		if ($start_pos === false) {
409
+					break;
410
+		}
397 411
 
398 412
 		// This must have an end tag - and we must find the right one.
399 413
 		$lower_text = strtolower($text);
@@ -426,8 +440,9 @@  discard block
 block discarded – undo
426 440
 				break;
427 441
 			}
428 442
 		}
429
-		if ($end_pos === false)
430
-			break;
443
+		if ($end_pos === false) {
444
+					break;
445
+		}
431 446
 
432 447
 		// Now work out what the attributes are.
433 448
 		$attribs = fetchTagAttributes($matches[1]);
@@ -441,11 +456,11 @@  discard block
 block discarded – undo
441 456
 				$v = (int) trim($v);
442 457
 				$v = empty($v) ? 1 : $v;
443 458
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
459
+			} elseif ($s == 'face') {
460
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
461
+			} elseif ($s == 'color') {
462
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
444 463
 			}
445
-			elseif ($s == 'face')
446
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
447
-			elseif ($s == 'color')
448
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
449 464
 		}
450 465
 
451 466
 		// As before add in our tags.
@@ -453,8 +468,9 @@  discard block
 block discarded – undo
453 468
 		foreach ($tags as $tag)
454 469
 		{
455 470
 			$before .= $tag[0];
456
-			if (isset($tag[1]))
457
-				$after = $tag[1] . $after;
471
+			if (isset($tag[1])) {
472
+							$after = $tag[1] . $after;
473
+			}
458 474
 		}
459 475
 
460 476
 		// Remove the tag so it's never checked again.
@@ -465,8 +481,9 @@  discard block
 block discarded – undo
465 481
 	}
466 482
 
467 483
 	// Almost there, just a little more time.
468
-	if (connection_aborted() && $context['server']['is_apache'])
469
-		@apache_reset_timeout();
484
+	if (connection_aborted() && $context['server']['is_apache']) {
485
+			@apache_reset_timeout();
486
+	}
470 487
 
471 488
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
472 489
 	{
@@ -522,12 +539,13 @@  discard block
 block discarded – undo
522 539
 						{
523 540
 							$inList = true;
524 541
 
525
-							if ($tag === 'ol')
526
-								$listType = 'decimal';
527
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
528
-								$listType = $listTypeMapping[$match[1]];
529
-							else
530
-								$listType = null;
542
+							if ($tag === 'ol') {
543
+															$listType = 'decimal';
544
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
545
+															$listType = $listTypeMapping[$match[1]];
546
+							} else {
547
+															$listType = null;
548
+							}
531 549
 
532 550
 							$listDepth++;
533 551
 
@@ -591,9 +609,7 @@  discard block
 block discarded – undo
591 609
 							$parts[$i + 1] = '';
592 610
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
593 611
 							$parts[$i + 3] = '';
594
-						}
595
-
596
-						else
612
+						} else
597 613
 						{
598 614
 							// We're in a list item.
599 615
 							if ($listDepth > 0)
@@ -630,9 +646,7 @@  discard block
 block discarded – undo
630 646
 							$parts[$i + 1] = '';
631 647
 							$parts[$i + 2] = '';
632 648
 							$parts[$i + 3] = '';
633
-						}
634
-
635
-						else
649
+						} else
636 650
 						{
637 651
 							// Remove the trailing breaks from the list item.
638 652
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -670,8 +684,9 @@  discard block
 block discarded – undo
670 684
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
671 685
 		}
672 686
 
673
-		for ($i = $listDepth; $i > 0; $i--)
674
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
687
+		for ($i = $listDepth; $i > 0; $i--) {
688
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
689
+		}
675 690
 	}
676 691
 
677 692
 	// I love my own image...
@@ -679,8 +694,9 @@  discard block
 block discarded – undo
679 694
 	{
680 695
 		// Find the position of the image.
681 696
 		$start_pos = strpos($text, $matches[0]);
682
-		if ($start_pos === false)
683
-			break;
697
+		if ($start_pos === false) {
698
+					break;
699
+		}
684 700
 		$end_pos = $start_pos + strlen($matches[0]);
685 701
 
686 702
 		$params = '';
@@ -689,12 +705,13 @@  discard block
 block discarded – undo
689 705
 		$attrs = fetchTagAttributes($matches[1]);
690 706
 		foreach ($attrs as $attrib => $value)
691 707
 		{
692
-			if (in_array($attrib, array('width', 'height')))
693
-				$params .= ' ' . $attrib . '=' . (int) $value;
694
-			elseif ($attrib == 'alt' && trim($value) != '')
695
-				$params .= ' alt=' . trim($value);
696
-			elseif ($attrib == 'src')
697
-				$src = trim($value);
708
+			if (in_array($attrib, array('width', 'height'))) {
709
+							$params .= ' ' . $attrib . '=' . (int) $value;
710
+			} elseif ($attrib == 'alt' && trim($value) != '') {
711
+							$params .= ' alt=' . trim($value);
712
+			} elseif ($attrib == 'src') {
713
+							$src = trim($value);
714
+			}
698 715
 		}
699 716
 
700 717
 		$tag = '';
@@ -705,10 +722,11 @@  discard block
 block discarded – undo
705 722
 			{
706 723
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
707 724
 
708
-				if (substr($src, 0, 1) === '/')
709
-					$src = $baseURL . $src;
710
-				else
711
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
725
+				if (substr($src, 0, 1) === '/') {
726
+									$src = $baseURL . $src;
727
+				} else {
728
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
729
+				}
712 730
 			}
713 731
 
714 732
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -886,20 +904,23 @@  discard block
 block discarded – undo
886 904
 		},
887 905
 	);
888 906
 
889
-	foreach ($tags as $tag => $replace)
890
-		$text = preg_replace_callback($tag, $replace, $text);
907
+	foreach ($tags as $tag => $replace) {
908
+			$text = preg_replace_callback($tag, $replace, $text);
909
+	}
891 910
 
892 911
 	// Please give us just a little more time.
893
-	if (connection_aborted() && $context['server']['is_apache'])
894
-		@apache_reset_timeout();
912
+	if (connection_aborted() && $context['server']['is_apache']) {
913
+			@apache_reset_timeout();
914
+	}
895 915
 
896 916
 	// What about URL's - the pain in the ass of the tag world.
897 917
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
898 918
 	{
899 919
 		// Find the position of the URL.
900 920
 		$start_pos = strpos($text, $matches[0]);
901
-		if ($start_pos === false)
902
-			break;
921
+		if ($start_pos === false) {
922
+					break;
923
+		}
903 924
 		$end_pos = $start_pos + strlen($matches[0]);
904 925
 
905 926
 		$tag_type = 'url';
@@ -913,8 +934,9 @@  discard block
 block discarded – undo
913 934
 				$href = trim($value);
914 935
 
915 936
 				// Are we dealing with an FTP link?
916
-				if (preg_match('~^ftps?://~', $href) === 1)
917
-					$tag_type = 'ftp';
937
+				if (preg_match('~^ftps?://~', $href) === 1) {
938
+									$tag_type = 'ftp';
939
+				}
918 940
 
919 941
 				// Or is this a link to an email address?
920 942
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -928,28 +950,31 @@  discard block
 block discarded – undo
928 950
 				{
929 951
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
930 952
 
931
-					if (substr($href, 0, 1) === '/')
932
-						$href = $baseURL . $href;
933
-					else
934
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
953
+					if (substr($href, 0, 1) === '/') {
954
+											$href = $baseURL . $href;
955
+					} else {
956
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
957
+					}
935 958
 				}
936 959
 			}
937 960
 
938 961
 			// External URL?
939 962
 			if ($attrib == 'target' && $tag_type == 'url')
940 963
 			{
941
-				if (trim($value) == '_blank')
942
-					$tag_type == 'iurl';
964
+				if (trim($value) == '_blank') {
965
+									$tag_type == 'iurl';
966
+				}
943 967
 			}
944 968
 		}
945 969
 
946 970
 		$tag = '';
947 971
 		if ($href != '')
948 972
 		{
949
-			if ($matches[2] == $href)
950
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
951
-			else
952
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
973
+			if ($matches[2] == $href) {
974
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
975
+			} else {
976
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
977
+			}
953 978
 		}
954 979
 
955 980
 		// Replace the tag
@@ -985,17 +1010,18 @@  discard block
 block discarded – undo
985 1010
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
986 1011
 		if ($text[$i] == '=')
987 1012
 		{
988
-			if ($tag_state == 0)
989
-				$tag_state = 1;
990
-			elseif ($tag_state == 2)
991
-				$value .= '=';
1013
+			if ($tag_state == 0) {
1014
+							$tag_state = 1;
1015
+			} elseif ($tag_state == 2) {
1016
+							$value .= '=';
1017
+			}
992 1018
 		}
993 1019
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
994 1020
 		elseif ($text[$i] == ' ')
995 1021
 		{
996
-			if ($tag_state == 2)
997
-				$value .= ' ';
998
-			elseif ($tag_state == 1)
1022
+			if ($tag_state == 2) {
1023
+							$value .= ' ';
1024
+			} elseif ($tag_state == 1)
999 1025
 			{
1000 1026
 				$attribs[$key] = $value;
1001 1027
 				$key = $value = '';
@@ -1006,24 +1032,27 @@  discard block
 block discarded – undo
1006 1032
 		elseif ($text[$i] == '"')
1007 1033
 		{
1008 1034
 			// Must be either going into or out of a string.
1009
-			if ($tag_state == 1)
1010
-				$tag_state = 2;
1011
-			else
1012
-				$tag_state = 1;
1035
+			if ($tag_state == 1) {
1036
+							$tag_state = 2;
1037
+			} else {
1038
+							$tag_state = 1;
1039
+			}
1013 1040
 		}
1014 1041
 		// Otherwise it's fine.
1015 1042
 		else
1016 1043
 		{
1017
-			if ($tag_state == 0)
1018
-				$key .= $text[$i];
1019
-			else
1020
-				$value .= $text[$i];
1044
+			if ($tag_state == 0) {
1045
+							$key .= $text[$i];
1046
+			} else {
1047
+							$value .= $text[$i];
1048
+			}
1021 1049
 		}
1022 1050
 	}
1023 1051
 
1024 1052
 	// Anything left?
1025
-	if ($key != '' && $value != '')
1026
-		$attribs[$key] = $value;
1053
+	if ($key != '' && $value != '') {
1054
+			$attribs[$key] = $value;
1055
+	}
1027 1056
 
1028 1057
 	return $attribs;
1029 1058
 }
@@ -1039,8 +1068,9 @@  discard block
 block discarded – undo
1039 1068
 	global $modSettings;
1040 1069
 
1041 1070
 	// Don't care about the texts that are too short.
1042
-	if (strlen($text) < 3)
1043
-		return $text;
1071
+	if (strlen($text) < 3) {
1072
+			return $text;
1073
+	}
1044 1074
 
1045 1075
 	// A list of tags that's disabled by the admin.
1046 1076
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
@@ -1051,10 +1081,12 @@  discard block
 block discarded – undo
1051 1081
 	$self_closing_tags = array();
1052 1082
 	foreach ($all_tags as $tag)
1053 1083
 	{
1054
-		if (!isset($disabled[$tag['tag']]))
1055
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1056
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1057
-			$self_closing_tags[] = $tag['tag'];
1084
+		if (!isset($disabled[$tag['tag']])) {
1085
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1086
+		}
1087
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1088
+					$self_closing_tags[] = $tag['tag'];
1089
+		}
1058 1090
 	}
1059 1091
 
1060 1092
 	// Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid!
@@ -1081,16 +1113,19 @@  discard block
 block discarded – undo
1081 1113
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1082 1114
 
1083 1115
 				// We're closing the exact same tag that we opened.
1084
-				if ($isClosingTag && $insideTag === $tagName)
1085
-					$insideTag = null;
1116
+				if ($isClosingTag && $insideTag === $tagName) {
1117
+									$insideTag = null;
1118
+				}
1086 1119
 
1087 1120
 				// We're opening a tag and we're not yet inside one either
1088
-				elseif (!$isClosingTag && $insideTag === null)
1089
-					$insideTag = $tagName;
1121
+				elseif (!$isClosingTag && $insideTag === null) {
1122
+									$insideTag = $tagName;
1123
+				}
1090 1124
 
1091 1125
 				// In all other cases, this tag must be invalid
1092
-				else
1093
-					unset($matches[$i]);
1126
+				else {
1127
+									unset($matches[$i]);
1128
+				}
1094 1129
 			}
1095 1130
 
1096 1131
 			// The next one is gonna be the other one.
@@ -1098,8 +1133,9 @@  discard block
 block discarded – undo
1098 1133
 		}
1099 1134
 
1100 1135
 		// We're still inside a tag and had no chance for closure?
1101
-		if ($insideTag !== null)
1102
-			$matches[] = '[/' . $insideTag . ']';
1136
+		if ($insideTag !== null) {
1137
+					$matches[] = '[/' . $insideTag . ']';
1138
+		}
1103 1139
 
1104 1140
 		// And a complete text string again.
1105 1141
 		$text = implode('', $matches);
@@ -1108,8 +1144,9 @@  discard block
 block discarded – undo
1108 1144
 	// Quickly remove any tags which are back to back.
1109 1145
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1110 1146
 	$lastlen = 0;
1111
-	while (strlen($text) !== $lastlen)
1112
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1147
+	while (strlen($text) !== $lastlen) {
1148
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1149
+	}
1113 1150
 
1114 1151
 	// Need to sort the tags by name length.
1115 1152
 	uksort($valid_tags, function ($a, $b) {
@@ -1148,8 +1185,9 @@  discard block
 block discarded – undo
1148 1185
 			$isCompetingTag = in_array($tag, $competing_tags);
1149 1186
 
1150 1187
 			// Check if this might be one of those cleaned out tags.
1151
-			if ($tag === '')
1152
-				continue;
1188
+			if ($tag === '') {
1189
+							continue;
1190
+			}
1153 1191
 
1154 1192
 			// Special case: inside [code] blocks any code is left untouched.
1155 1193
 			elseif ($tag === 'code')
@@ -1160,8 +1198,9 @@  discard block
 block discarded – undo
1160 1198
 					$inCode = false;
1161 1199
 
1162 1200
 					// Reopen tags that were closed before the code block.
1163
-					if (!empty($inlineElements))
1164
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1201
+					if (!empty($inlineElements)) {
1202
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1203
+					}
1165 1204
 				}
1166 1205
 
1167 1206
 				// We're outside a coding and nobbc block and opening it.
@@ -1190,8 +1229,9 @@  discard block
 block discarded – undo
1190 1229
 					$inNoBbc = false;
1191 1230
 
1192 1231
 					// Some inline elements might've been closed that need reopening.
1193
-					if (!empty($inlineElements))
1194
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1232
+					if (!empty($inlineElements)) {
1233
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1234
+					}
1195 1235
 				}
1196 1236
 
1197 1237
 				// We're outside a nobbc and coding block and opening it.
@@ -1211,8 +1251,9 @@  discard block
 block discarded – undo
1211 1251
 			}
1212 1252
 
1213 1253
 			// So, we're inside one of the special blocks: ignore any tag.
1214
-			elseif ($inCode || $inNoBbc)
1215
-				continue;
1254
+			elseif ($inCode || $inNoBbc) {
1255
+							continue;
1256
+			}
1216 1257
 
1217 1258
 			// We're dealing with an opening tag.
1218 1259
 			if ($isOpeningTag)
@@ -1253,8 +1294,9 @@  discard block
 block discarded – undo
1253 1294
 							if ($parts[$j + 3] === $tag)
1254 1295
 							{
1255 1296
 								// If it's an opening tag, increase the level.
1256
-								if ($parts[$j + 2] === '')
1257
-									$curLevel++;
1297
+								if ($parts[$j + 2] === '') {
1298
+																	$curLevel++;
1299
+								}
1258 1300
 
1259 1301
 								// A closing tag, decrease the level.
1260 1302
 								else
@@ -1277,13 +1319,15 @@  discard block
 block discarded – undo
1277 1319
 					{
1278 1320
 						if ($isCompetingTag)
1279 1321
 						{
1280
-							if (!isset($competingElements[$tag]))
1281
-								$competingElements[$tag] = array();
1322
+							if (!isset($competingElements[$tag])) {
1323
+															$competingElements[$tag] = array();
1324
+							}
1282 1325
 
1283 1326
 							$competingElements[$tag][] = $parts[$i + 4];
1284 1327
 
1285
-							if (count($competingElements[$tag]) > 1)
1286
-								$parts[$i] .= '[/' . $tag . ']';
1328
+							if (count($competingElements[$tag]) > 1) {
1329
+															$parts[$i] .= '[/' . $tag . ']';
1330
+							}
1287 1331
 						}
1288 1332
 
1289 1333
 						$inlineElements[$elementContent] = $tag;
@@ -1303,15 +1347,17 @@  discard block
 block discarded – undo
1303 1347
 						$addClosingTags = array();
1304 1348
 						while ($element = array_pop($blockElements))
1305 1349
 						{
1306
-							if ($element === $tag)
1307
-								break;
1350
+							if ($element === $tag) {
1351
+															break;
1352
+							}
1308 1353
 
1309 1354
 							// Still a block tag was open not equal to this tag.
1310 1355
 							$addClosingTags[] = $element['type'];
1311 1356
 						}
1312 1357
 
1313
-						if (!empty($addClosingTags))
1314
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1358
+						if (!empty($addClosingTags)) {
1359
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1360
+						}
1315 1361
 
1316 1362
 						// Apparently the closing tag was not found on the stack.
1317 1363
 						if (!is_string($element) || $element !== $tag)
@@ -1321,8 +1367,7 @@  discard block
 block discarded – undo
1321 1367
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1322 1368
 							continue;
1323 1369
 						}
1324
-					}
1325
-					else
1370
+					} else
1326 1371
 					{
1327 1372
 						// Get rid of this closing tag!
1328 1373
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1351,53 +1396,62 @@  discard block
 block discarded – undo
1351 1396
 							unset($inlineElements[$tagContentToBeClosed]);
1352 1397
 
1353 1398
 							// Was this the tag we were looking for?
1354
-							if ($tagToBeClosed === $tag)
1355
-								break;
1399
+							if ($tagToBeClosed === $tag) {
1400
+															break;
1401
+							}
1356 1402
 
1357 1403
 							// Nope, close it and look further!
1358
-							else
1359
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1404
+							else {
1405
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1406
+							}
1360 1407
 						}
1361 1408
 
1362 1409
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1363 1410
 						{
1364 1411
 							array_pop($competingElements[$tag]);
1365 1412
 
1366
-							if (count($competingElements[$tag]) > 0)
1367
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1413
+							if (count($competingElements[$tag]) > 0) {
1414
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1415
+							}
1368 1416
 						}
1369 1417
 					}
1370 1418
 
1371 1419
 					// Unexpected closing tag, ex-ter-mi-nate.
1372
-					else
1373
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1420
+					else {
1421
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1422
+					}
1374 1423
 				}
1375 1424
 			}
1376 1425
 		}
1377 1426
 
1378 1427
 		// Close the code tags.
1379
-		if ($inCode)
1380
-			$parts[$i] .= '[/code]';
1428
+		if ($inCode) {
1429
+					$parts[$i] .= '[/code]';
1430
+		}
1381 1431
 
1382 1432
 		// The same for nobbc tags.
1383
-		elseif ($inNoBbc)
1384
-			$parts[$i] .= '[/nobbc]';
1433
+		elseif ($inNoBbc) {
1434
+					$parts[$i] .= '[/nobbc]';
1435
+		}
1385 1436
 
1386 1437
 		// Still inline tags left unclosed? Close them now, better late than never.
1387
-		elseif (!empty($inlineElements))
1388
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1438
+		elseif (!empty($inlineElements)) {
1439
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1440
+		}
1389 1441
 
1390 1442
 		// Now close the block elements.
1391
-		if (!empty($blockElements))
1392
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1443
+		if (!empty($blockElements)) {
1444
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1445
+		}
1393 1446
 
1394 1447
 		$text = implode('', $parts);
1395 1448
 	}
1396 1449
 
1397 1450
 	// Final clean up of back to back tags.
1398 1451
 	$lastlen = 0;
1399
-	while (strlen($text) !== $lastlen)
1400
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1452
+	while (strlen($text) !== $lastlen) {
1453
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1454
+	}
1401 1455
 
1402 1456
 	return $text;
1403 1457
 }
@@ -1414,22 +1468,25 @@  discard block
 block discarded – undo
1414 1468
 	$context['template_layers'] = array();
1415 1469
 	// Lets make sure we aren't going to output anything nasty.
1416 1470
 	@ob_end_clean();
1417
-	if (!empty($modSettings['enableCompressedOutput']))
1418
-		@ob_start('ob_gzhandler');
1419
-	else
1420
-		@ob_start();
1471
+	if (!empty($modSettings['enableCompressedOutput'])) {
1472
+			@ob_start('ob_gzhandler');
1473
+	} else {
1474
+			@ob_start();
1475
+	}
1421 1476
 
1422 1477
 	// If we don't have any locale better avoid broken js
1423
-	if (empty($txt['lang_locale']))
1424
-		die();
1478
+	if (empty($txt['lang_locale'])) {
1479
+			die();
1480
+	}
1425 1481
 
1426 1482
 	$file_data = '(function ($) {
1427 1483
 	\'use strict\';
1428 1484
 
1429 1485
 	$.sceditor.locale[' . JavaScriptEscape($txt['lang_locale']) . '] = {';
1430
-	foreach ($editortxt as $key => $val)
1431
-		$file_data .= '
1486
+	foreach ($editortxt as $key => $val) {
1487
+			$file_data .= '
1432 1488
 		' . JavaScriptEscape($key) . ': ' . JavaScriptEscape($val) . ',';
1489
+	}
1433 1490
 
1434 1491
 	$file_data .= '
1435 1492
 		dateFormat: "day.month.year"
@@ -1497,8 +1554,9 @@  discard block
 block discarded – undo
1497 1554
 				)
1498 1555
 			);
1499 1556
 			$icon_data = array();
1500
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1501
-				$icon_data[] = $row;
1557
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1558
+							$icon_data[] = $row;
1559
+			}
1502 1560
 			$smcFunc['db_free_result']($request);
1503 1561
 
1504 1562
 			$icons = array();
@@ -1513,9 +1571,9 @@  discard block
 block discarded – undo
1513 1571
 			}
1514 1572
 
1515 1573
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1574
+		} else {
1575
+					$icons = $temp;
1516 1576
 		}
1517
-		else
1518
-			$icons = $temp;
1519 1577
 	}
1520 1578
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1521 1579
 
@@ -1544,8 +1602,9 @@  discard block
 block discarded – undo
1544 1602
 	{
1545 1603
 		// Some general stuff.
1546 1604
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1547
-		if (!empty($context['drafts_autosave']))
1548
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1605
+		if (!empty($context['drafts_autosave'])) {
1606
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1607
+		}
1549 1608
 
1550 1609
 		// This really has some WYSIWYG stuff.
1551 1610
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1562,8 +1621,9 @@  discard block
 block discarded – undo
1562 1621
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1563 1622
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1564 1623
 		// editor language file
1565
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1566
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1624
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1625
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1626
+		}
1567 1627
 
1568 1628
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))];
1569 1629
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_character_set'] == 'UTF-8' || function_exists('iconv'))));
@@ -1572,11 +1632,12 @@  discard block
 block discarded – undo
1572 1632
 			loadJavaScriptFile('spellcheck.js', array('minimize' => true), 'smf_spellcheck');
1573 1633
 
1574 1634
 			// Some hidden information is needed in order to make the spell checking work.
1575
-			if (!isset($_REQUEST['xml']))
1576
-				$context['insert_after_template'] .= '
1635
+			if (!isset($_REQUEST['xml'])) {
1636
+							$context['insert_after_template'] .= '
1577 1637
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1578 1638
 			<input type="hidden" name="spellstring" value="">
1579 1639
 		</form>';
1640
+			}
1580 1641
 		}
1581 1642
 	}
1582 1643
 
@@ -1768,8 +1829,9 @@  discard block
 block discarded – undo
1768 1829
 
1769 1830
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1770 1831
 		$disabled_tags = array();
1771
-		if (!empty($modSettings['disabledBBC']))
1772
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1832
+		if (!empty($modSettings['disabledBBC'])) {
1833
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1834
+		}
1773 1835
 
1774 1836
 		foreach ($disabled_tags as $tag)
1775 1837
 		{
@@ -1781,9 +1843,10 @@  discard block
 block discarded – undo
1781 1843
 				$context['disabled_tags']['orderedlist'] = true;
1782 1844
 			}
1783 1845
 
1784
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1785
-				if ($tag === $thisTag)
1846
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1847
+							if ($tag === $thisTag)
1786 1848
 					$context['disabled_tags'][$tagNameBBC] = true;
1849
+			}
1787 1850
 
1788 1851
 			$context['disabled_tags'][$tag] = true;
1789 1852
 		}
@@ -1794,8 +1857,9 @@  discard block
 block discarded – undo
1794 1857
 
1795 1858
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1796 1859
 		{
1797
-			if (!isset($context['bbc_toolbar'][$row]))
1798
-				$context['bbc_toolbar'][$row] = array();
1860
+			if (!isset($context['bbc_toolbar'][$row])) {
1861
+							$context['bbc_toolbar'][$row] = array();
1862
+			}
1799 1863
 
1800 1864
 			$tagsRow = array();
1801 1865
 
@@ -1831,20 +1895,21 @@  discard block
 block discarded – undo
1831 1895
 
1832 1896
 					$context['bbcodes_handlers'] .= '
1833 1897
 						});';
1834
-				}
1835
-				else
1898
+				} else
1836 1899
 				{
1837 1900
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1838 1901
 					$tagsRow = array();
1839 1902
 				}
1840 1903
 			}
1841 1904
 
1842
-			if (!empty($tagsRow))
1843
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1905
+			if (!empty($tagsRow)) {
1906
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1907
+			}
1844 1908
 		}
1845 1909
 
1846
-		if (!empty($bbcodes_styles))
1847
-			addInlineCss($bbcodes_styles);
1910
+		if (!empty($bbcodes_styles)) {
1911
+					addInlineCss($bbcodes_styles);
1912
+		}
1848 1913
 	}
1849 1914
 
1850 1915
 	// Initialize smiley array... if not loaded before.
@@ -1856,8 +1921,8 @@  discard block
 block discarded – undo
1856 1921
 		);
1857 1922
 
1858 1923
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1859
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1860
-			$context['smileys']['postform'][] = array(
1924
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1925
+					$context['smileys']['postform'][] = array(
1861 1926
 				'smileys' => array(
1862 1927
 					array(
1863 1928
 						'code' => ':)',
@@ -1943,7 +2008,7 @@  discard block
 block discarded – undo
1943 2008
 				),
1944 2009
 				'isLast' => true,
1945 2010
 			);
1946
-		elseif ($user_info['smiley_set'] != 'none')
2011
+		} elseif ($user_info['smiley_set'] != 'none')
1947 2012
 		{
1948 2013
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1949 2014
 			{
@@ -1966,29 +2031,32 @@  discard block
 block discarded – undo
1966 2031
 
1967 2032
 				foreach ($context['smileys'] as $section => $smileyRows)
1968 2033
 				{
1969
-					foreach ($smileyRows as $rowIndex => $smileys)
1970
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2034
+					foreach ($smileyRows as $rowIndex => $smileys) {
2035
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2036
+					}
1971 2037
 
1972
-					if (!empty($smileyRows))
1973
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2038
+					if (!empty($smileyRows)) {
2039
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2040
+					}
1974 2041
 				}
1975 2042
 
1976 2043
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2044
+			} else {
2045
+							$context['smileys'] = $temp;
1977 2046
 			}
1978
-			else
1979
-				$context['smileys'] = $temp;
1980 2047
 		}
1981 2048
 
1982 2049
 		// Set proper extensions; do this post caching so cache doesn't become extension-specific
1983 2050
 		array_walk_recursive($context['smileys'], function (&$filename, $key)
1984 2051
 			{
1985 2052
 				global $context, $user_info, $modSettings;
1986
-				if ($key == 'filename')
1987
-					// Need to use the default if user selection is disabled
2053
+				if ($key == 'filename') {
2054
+									// Need to use the default if user selection is disabled
1988 2055
 					if (empty($modSettings['smiley_sets_enable']))
1989 2056
 						$filename .= $context['user']['smiley_set_default_ext'];
1990
-					else
1991
-						$filename .= $user_info['smiley_set_ext'];
2057
+				} else {
2058
+											$filename .= $user_info['smiley_set_ext'];
2059
+					}
1992 2060
 				
1993 2061
 			}
1994 2062
 		);
@@ -2006,12 +2074,15 @@  discard block
 block discarded – undo
2006 2074
 		'plugins' => '',
2007 2075
 		'bbcodeTrim' => true,
2008 2076
 	);
2009
-	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale']))
2010
-		$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2011
-	if (!empty($context['right_to_left']))
2012
-		$sce_options['rtl'] = true;
2013
-	if ($editorOptions['id'] != 'quickReply')
2014
-		$sce_options['autofocus'] = true;
2077
+	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale'])) {
2078
+			$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2079
+	}
2080
+	if (!empty($context['right_to_left'])) {
2081
+			$sce_options['rtl'] = true;
2082
+	}
2083
+	if ($editorOptions['id'] != 'quickReply') {
2084
+			$sce_options['autofocus'] = true;
2085
+	}
2015 2086
 
2016 2087
 	$sce_options['emoticons'] = array();
2017 2088
 	$sce_options['emoticonsDescriptions'] = array();
@@ -2028,10 +2099,11 @@  discard block
 block discarded – undo
2028 2099
 			$countLocations--;
2029 2100
 
2030 2101
 			unset($smiley_location);
2031
-			if ($location == 'postform')
2032
-				$smiley_location = &$sce_options['emoticons']['dropdown'];
2033
-			elseif ($location == 'popup')
2034
-				$smiley_location = &$sce_options['emoticons']['popup'];
2102
+			if ($location == 'postform') {
2103
+							$smiley_location = &$sce_options['emoticons']['dropdown'];
2104
+			} elseif ($location == 'popup') {
2105
+							$smiley_location = &$sce_options['emoticons']['popup'];
2106
+			}
2035 2107
 
2036 2108
 			$numRows = count($smileyRows);
2037 2109
 
@@ -2045,8 +2117,9 @@  discard block
 block discarded – undo
2045 2117
 					$sce_options['emoticonsDescriptions'][$smiley['code']] = $smiley['description'];
2046 2118
 				}
2047 2119
 
2048
-				if (empty($smileyRow['isLast']) && $numRows != 1)
2049
-					$smiley_location['-' . $emptyPlaceholder++] = '';
2120
+				if (empty($smileyRow['isLast']) && $numRows != 1) {
2121
+									$smiley_location['-' . $emptyPlaceholder++] = '';
2122
+				}
2050 2123
 			}
2051 2124
 		}
2052 2125
 	}
@@ -2061,8 +2134,9 @@  discard block
 block discarded – undo
2061 2134
 
2062 2135
 			$count_tags--;
2063 2136
 
2064
-			if (!empty($count_tags))
2065
-				$sce_options['toolbar'] .= '||';
2137
+			if (!empty($count_tags)) {
2138
+							$sce_options['toolbar'] .= '||';
2139
+			}
2066 2140
 		}
2067 2141
 	}
2068 2142
 
@@ -2090,8 +2164,9 @@  discard block
 block discarded – undo
2090 2164
 		loadTemplate('GenericControls');
2091 2165
 
2092 2166
 		// Some javascript ma'am?
2093
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2094
-			loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha');
2167
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2168
+					loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha');
2169
+		}
2095 2170
 
2096 2171
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2097 2172
 
@@ -2104,8 +2179,8 @@  discard block
 block discarded – undo
2104 2179
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2105 2180
 
2106 2181
 	// Log this into our collection.
2107
-	if ($isNew)
2108
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2182
+	if ($isNew) {
2183
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2109 2184
 			'id' => $verificationOptions['id'],
2110 2185
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2111 2186
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2116,13 +2191,15 @@  discard block
 block discarded – undo
2116 2191
 			'questions' => array(),
2117 2192
 			'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']),
2118 2193
 		);
2194
+	}
2119 2195
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2120 2196
 
2121 2197
 	// Is there actually going to be anything?
2122
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha']))
2123
-		return false;
2124
-	elseif (!$isNew && !$do_test)
2125
-		return true;
2198
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) {
2199
+			return false;
2200
+	} elseif (!$isNew && !$do_test) {
2201
+			return true;
2202
+	}
2126 2203
 
2127 2204
 	// Sanitize reCAPTCHA fields?
2128 2205
 	if ($thisVerification['can_recaptcha'])
@@ -2135,11 +2212,12 @@  discard block
 block discarded – undo
2135 2212
 	}
2136 2213
 
2137 2214
 	// Add javascript for the object.
2138
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2139
-		$context['insert_after_template'] .= '
2215
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2216
+			$context['insert_after_template'] .= '
2140 2217
 			<script>
2141 2218
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2142 2219
 			</script>';
2220
+	}
2143 2221
 
2144 2222
 	// If we want questions do we have a cache of all the IDs?
2145 2223
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2162,8 +2240,9 @@  discard block
 block discarded – undo
2162 2240
 				unset ($row['id_question']);
2163 2241
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2164 2242
 				$row['answers'] = $smcFunc['json_decode']($row['answers'], true);
2165
-				foreach ($row['answers'] as $k => $v)
2166
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2243
+				foreach ($row['answers'] as $k => $v) {
2244
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2245
+				}
2167 2246
 
2168 2247
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2169 2248
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2174,35 +2253,42 @@  discard block
 block discarded – undo
2174 2253
 		}
2175 2254
 	}
2176 2255
 
2177
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2178
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2256
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2257
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2258
+	}
2179 2259
 
2180 2260
 	// Do we need to refresh the verification?
2181
-	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh']))
2182
-		$force_refresh = true;
2183
-	else
2184
-		$force_refresh = false;
2261
+	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) {
2262
+			$force_refresh = true;
2263
+	} else {
2264
+			$force_refresh = false;
2265
+	}
2185 2266
 
2186 2267
 	// This can also force a fresh, although unlikely.
2187
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2188
-		$force_refresh = true;
2268
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2269
+			$force_refresh = true;
2270
+	}
2189 2271
 
2190 2272
 	$verification_errors = array();
2191 2273
 	// Start with any testing.
2192 2274
 	if ($do_test)
2193 2275
 	{
2194 2276
 		// This cannot happen!
2195
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2196
-			fatal_lang_error('no_access', false);
2277
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2278
+					fatal_lang_error('no_access', false);
2279
+		}
2197 2280
 		// ... nor this!
2198
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2199
-			fatal_lang_error('no_access', false);
2281
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2282
+					fatal_lang_error('no_access', false);
2283
+		}
2200 2284
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2201
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2202
-			fatal_lang_error('no_access', false);
2285
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2286
+					fatal_lang_error('no_access', false);
2287
+		}
2203 2288
 		// While we're here, did the user do something bad?
2204
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2205
-			$verification_errors[] = 'wrong_verification_answer';
2289
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2290
+					$verification_errors[] = 'wrong_verification_answer';
2291
+		}
2206 2292
 
2207 2293
 		if ($thisVerification['can_recaptcha'])
2208 2294
 		{
@@ -2213,22 +2299,25 @@  discard block
 block discarded – undo
2213 2299
 			{
2214 2300
 				$resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']);
2215 2301
 
2216
-				if (!$resp->isSuccess())
2217
-					$verification_errors[] = 'wrong_verification_code';
2302
+				if (!$resp->isSuccess()) {
2303
+									$verification_errors[] = 'wrong_verification_code';
2304
+				}
2305
+			} else {
2306
+							$verification_errors[] = 'wrong_verification_code';
2218 2307
 			}
2219
-			else
2220
-				$verification_errors[] = 'wrong_verification_code';
2221 2308
 		}
2222
-		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code']))
2223
-			$verification_errors[] = 'wrong_verification_code';
2309
+		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) {
2310
+					$verification_errors[] = 'wrong_verification_code';
2311
+		}
2224 2312
 		if ($thisVerification['number_questions'])
2225 2313
 		{
2226 2314
 			$incorrectQuestions = array();
2227 2315
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2228 2316
 			{
2229 2317
 				// We don't have this question any more, thus no answers.
2230
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2231
-					continue;
2318
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2319
+									continue;
2320
+				}
2232 2321
 				// This is quite complex. We have our question but it might have multiple answers.
2233 2322
 				// First, did they actually answer this question?
2234 2323
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2240,24 +2329,28 @@  discard block
 block discarded – undo
2240 2329
 				else
2241 2330
 				{
2242 2331
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2243
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2244
-						$incorrectQuestions[] = $q;
2332
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2333
+											$incorrectQuestions[] = $q;
2334
+					}
2245 2335
 				}
2246 2336
 			}
2247 2337
 
2248
-			if (!empty($incorrectQuestions))
2249
-				$verification_errors[] = 'wrong_verification_answer';
2338
+			if (!empty($incorrectQuestions)) {
2339
+							$verification_errors[] = 'wrong_verification_answer';
2340
+			}
2250 2341
 		}
2251 2342
 	}
2252 2343
 
2253 2344
 	// Any errors means we refresh potentially.
2254 2345
 	if (!empty($verification_errors))
2255 2346
 	{
2256
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2257
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2347
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2348
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2349
+		}
2258 2350
 		// Too many errors?
2259
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2260
-			$force_refresh = true;
2351
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2352
+					$force_refresh = true;
2353
+		}
2261 2354
 
2262 2355
 		// Keep a track of these.
2263 2356
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2290,8 +2383,9 @@  discard block
 block discarded – undo
2290 2383
 			// Are we overriding the range?
2291 2384
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2292 2385
 
2293
-			for ($i = 0; $i < 6; $i++)
2294
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2386
+			for ($i = 0; $i < 6; $i++) {
2387
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2388
+			}
2295 2389
 		}
2296 2390
 
2297 2391
 		// Getting some new questions?
@@ -2299,8 +2393,9 @@  discard block
 block discarded – undo
2299 2393
 		{
2300 2394
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2301 2395
 			$possible_langs = array();
2302
-			if (isset($_SESSION['language']))
2303
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2396
+			if (isset($_SESSION['language'])) {
2397
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2398
+			}
2304 2399
 			if (!empty($user_info['language']));
2305 2400
 			$possible_langs[] = $user_info['language'];
2306 2401
 			$possible_langs[] = $language;
@@ -2319,8 +2414,7 @@  discard block
 block discarded – undo
2319 2414
 				}
2320 2415
 			}
2321 2416
 		}
2322
-	}
2323
-	else
2417
+	} else
2324 2418
 	{
2325 2419
 		// Same questions as before.
2326 2420
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2330,8 +2424,9 @@  discard block
 block discarded – undo
2330 2424
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2331 2425
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2332 2426
 	{
2333
-		if (!isset($context['html_headers']))
2334
-			$context['html_headers'] = '';
2427
+		if (!isset($context['html_headers'])) {
2428
+					$context['html_headers'] = '';
2429
+		}
2335 2430
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2336 2431
 	}
2337 2432
 
@@ -2357,11 +2452,13 @@  discard block
 block discarded – undo
2357 2452
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2358 2453
 
2359 2454
 	// Return errors if we have them.
2360
-	if (!empty($verification_errors))
2361
-		return $verification_errors;
2455
+	if (!empty($verification_errors)) {
2456
+			return $verification_errors;
2457
+	}
2362 2458
 	// If we had a test that one, make a note.
2363
-	elseif ($do_test)
2364
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2459
+	elseif ($do_test) {
2460
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2461
+	}
2365 2462
 
2366 2463
 	// Say that everything went well chaps.
2367 2464
 	return true;
@@ -2386,8 +2483,9 @@  discard block
 block discarded – undo
2386 2483
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2387 2484
 
2388 2485
 	// If we're just checking the callback function is registered return true or false.
2389
-	if ($checkRegistered != null)
2390
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2486
+	if ($checkRegistered != null) {
2487
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2488
+	}
2391 2489
 
2392 2490
 	checkSession('get');
2393 2491
 	loadTemplate('Xml');
@@ -2538,24 +2636,27 @@  discard block
 block discarded – undo
2538 2636
 		foreach ($possible_versions as $ver)
2539 2637
 		{
2540 2638
 			$ver = trim($ver);
2541
-			if (strpos($ver, 'SMF') === 0)
2542
-				$versions[] = $ver;
2639
+			if (strpos($ver, 'SMF') === 0) {
2640
+							$versions[] = $ver;
2641
+			}
2543 2642
 		}
2544 2643
 	}
2545 2644
 	$smcFunc['db_free_result']($request);
2546 2645
 
2547 2646
 	// Just in case we don't have ANYthing.
2548
-	if (empty($versions))
2549
-		$versions = array('SMF 2.0');
2647
+	if (empty($versions)) {
2648
+			$versions = array('SMF 2.0');
2649
+	}
2550 2650
 
2551
-	foreach ($versions as $id => $version)
2552
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2651
+	foreach ($versions as $id => $version) {
2652
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2553 2653
 			$xml_data['items']['children'][] = array(
2554 2654
 				'attributes' => array(
2555 2655
 					'id' => $id,
2556 2656
 				),
2557 2657
 				'value' => $version,
2558 2658
 			);
2659
+	}
2559 2660
 
2560 2661
 	return $xml_data;
2561 2662
 }
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +271 added lines, -198 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
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -65,13 +66,16 @@  discard block
 block discarded – undo
65 66
 			'db_native_replace'			=> 'smf_db_native_replace',
66 67
 			'db_cte_support'			=> 'smf_db_cte_support',
67 68
 		);
69
+	}
68 70
 
69
-	if (!empty($db_options['persist']))
70
-		$db_server = 'p:' . $db_server;
71
+	if (!empty($db_options['persist'])) {
72
+			$db_server = 'p:' . $db_server;
73
+	}
71 74
 
72 75
 	// We are not going to make it very far without these.
73
-	if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect'))
74
-		display_db_error();
76
+	if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) {
77
+			display_db_error();
78
+	}
75 79
 
76 80
 	$connection = mysqli_init();
77 81
 
@@ -81,29 +85,33 @@  discard block
 block discarded – undo
81 85
 
82 86
 	if ($connection)
83 87
 	{
84
-		if (!empty($db_options['port']))
85
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
86
-		else
87
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
88
+		if (!empty($db_options['port'])) {
89
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
90
+		} else {
91
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
92
+		}
88 93
 	}
89 94
 
90 95
 	// Something's wrong, show an error if its fatal (which we assume it is)
91 96
 	if ($success === false)
92 97
 	{
93
-		if (!empty($db_options['non_fatal']))
94
-			return null;
95
-		else
96
-			display_db_error();
98
+		if (!empty($db_options['non_fatal'])) {
99
+					return null;
100
+		} else {
101
+					display_db_error();
102
+		}
97 103
 	}
98 104
 
99 105
 	// Select the database, unless told not to
100
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
101
-		display_db_error();
106
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
107
+			display_db_error();
108
+	}
102 109
 
103 110
 	mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'');
104 111
 
105
-	if (!empty($db_options['db_mb4']))
106
-		$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
112
+	if (!empty($db_options['db_mb4'])) {
113
+			$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
114
+	}
107 115
 
108 116
 	return $connection;
109 117
 }
@@ -174,34 +182,42 @@  discard block
 block discarded – undo
174 182
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
175 183
 
176 184
 	list ($values, $connection) = $db_callback;
177
-	if (!is_object($connection))
178
-		display_db_error();
185
+	if (!is_object($connection)) {
186
+			display_db_error();
187
+	}
179 188
 
180
-	if ($matches[1] === 'db_prefix')
181
-		return $db_prefix;
189
+	if ($matches[1] === 'db_prefix') {
190
+			return $db_prefix;
191
+	}
182 192
 
183
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
184
-		return $user_info[$matches[1]];
193
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
194
+			return $user_info[$matches[1]];
195
+	}
185 196
 
186
-	if ($matches[1] === 'empty')
187
-		return '\'\'';
197
+	if ($matches[1] === 'empty') {
198
+			return '\'\'';
199
+	}
188 200
 
189
-	if (!isset($matches[2]))
190
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
201
+	if (!isset($matches[2])) {
202
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
203
+	}
191 204
 
192
-	if ($matches[1] === 'literal')
193
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
205
+	if ($matches[1] === 'literal') {
206
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
207
+	}
194 208
 
195
-	if (!isset($values[$matches[2]]))
196
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
209
+	if (!isset($values[$matches[2]])) {
210
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
211
+	}
197 212
 
198 213
 	$replacement = $values[$matches[2]];
199 214
 
200 215
 	switch ($matches[1])
201 216
 	{
202 217
 		case 'int':
203
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
204
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
219
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+			}
205 221
 			return (string) (int) $replacement;
206 222
 		break;
207 223
 
@@ -213,65 +229,73 @@  discard block
 block discarded – undo
213 229
 		case 'array_int':
214 230
 			if (is_array($replacement))
215 231
 			{
216
-				if (empty($replacement))
217
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
232
+				if (empty($replacement)) {
233
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234
+				}
218 235
 
219 236
 				foreach ($replacement as $key => $value)
220 237
 				{
221
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
222
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
238
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
239
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240
+					}
223 241
 
224 242
 					$replacement[$key] = (string) (int) $value;
225 243
 				}
226 244
 
227 245
 				return implode(', ', $replacement);
246
+			} else {
247
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228 248
 			}
229
-			else
230
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231 249
 
232 250
 		break;
233 251
 
234 252
 		case 'array_string':
235 253
 			if (is_array($replacement))
236 254
 			{
237
-				if (empty($replacement))
238
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+				if (empty($replacement)) {
256
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+				}
239 258
 
240
-				foreach ($replacement as $key => $value)
241
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
259
+				foreach ($replacement as $key => $value) {
260
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
261
+				}
242 262
 
243 263
 				return implode(', ', $replacement);
264
+			} else {
265
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
244 266
 			}
245
-			else
246
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
247 267
 		break;
248 268
 
249 269
 		case 'date':
250
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
251
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
252
-			else
253
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
271
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
272
+			} else {
273
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
274
+			}
254 275
 		break;
255 276
 
256 277
 		case 'time':
257
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
258
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
259
-			else
260
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
279
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
280
+			} else {
281
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
282
+			}
261 283
 		break;
262 284
 
263 285
 		case 'datetime':
264
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
265
-				return 'str_to_date('.
286
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
287
+							return 'str_to_date('.
266 288
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
267 289
 					',\'%Y-%m-%d %h:%i:%s\')';
268
-			else
269
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
290
+			} else {
291
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
292
+			}
270 293
 		break;
271 294
 
272 295
 		case 'float':
273
-			if (!is_numeric($replacement))
274
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
296
+			if (!is_numeric($replacement)) {
297
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
298
+			}
275 299
 			return (string) (float) $replacement;
276 300
 		break;
277 301
 
@@ -285,32 +309,37 @@  discard block
 block discarded – undo
285 309
 		break;
286 310
 
287 311
 		case 'inet':
288
-			if ($replacement == 'null' || $replacement == '')
289
-				return 'null';
290
-			if (!isValidIP($replacement))
291
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
312
+			if ($replacement == 'null' || $replacement == '') {
313
+							return 'null';
314
+			}
315
+			if (!isValidIP($replacement)) {
316
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
317
+			}
292 318
 			//we don't use the native support of mysql > 5.6.2
293 319
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
294 320
 
295 321
 		case 'array_inet':
296 322
 			if (is_array($replacement))
297 323
 			{
298
-				if (empty($replacement))
299
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
324
+				if (empty($replacement)) {
325
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
326
+				}
300 327
 
301 328
 				foreach ($replacement as $key => $value)
302 329
 				{
303
-					if ($replacement == 'null' || $replacement == '')
304
-						$replacement[$key] = 'null';
305
-					if (!isValidIP($value))
306
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
330
+					if ($replacement == 'null' || $replacement == '') {
331
+											$replacement[$key] = 'null';
332
+					}
333
+					if (!isValidIP($value)) {
334
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
335
+					}
307 336
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
308 337
 				}
309 338
 
310 339
 				return implode(', ', $replacement);
340
+			} else {
341
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
311 342
 			}
312
-			else
313
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
314 343
 		break;
315 344
 
316 345
 		default:
@@ -381,18 +410,20 @@  discard block
 block discarded – undo
381 410
 	// One more query....
382 411
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
383 412
 
384
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
385
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
413
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
414
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
415
+	}
386 416
 
387 417
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
388 418
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
389 419
 	{
390 420
 		// Add before LIMIT
391
-		if ($pos = strpos($db_string, 'LIMIT '))
392
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
393
-		else
394
-			// Append it.
421
+		if ($pos = strpos($db_string, 'LIMIT ')) {
422
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
423
+		} else {
424
+					// Append it.
395 425
 			$db_string .= "\n\t\t\tORDER BY null";
426
+		}
396 427
 	}
397 428
 
398 429
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -418,17 +449,18 @@  discard block
 block discarded – undo
418 449
 		while (true)
419 450
 		{
420 451
 			$pos = strpos($db_string_1, '\'', $pos + 1);
421
-			if ($pos === false)
422
-				break;
452
+			if ($pos === false) {
453
+							break;
454
+			}
423 455
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
424 456
 
425 457
 			while (true)
426 458
 			{
427 459
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
428 460
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
429
-				if ($pos1 === false)
430
-					break;
431
-				elseif ($pos2 === false || $pos2 > $pos1)
461
+				if ($pos1 === false) {
462
+									break;
463
+				} elseif ($pos2 === false || $pos2 > $pos1)
432 464
 				{
433 465
 					$pos = $pos1;
434 466
 					break;
@@ -444,16 +476,19 @@  discard block
 block discarded – undo
444 476
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
445 477
 
446 478
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
447
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
448
-			$fail = true;
479
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
480
+					$fail = true;
481
+		}
449 482
 		// Trying to change passwords, slow us down, or something?
450
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
451
-			$fail = true;
452
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
453
-			$fail = true;
483
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
484
+					$fail = true;
485
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
486
+					$fail = true;
487
+		}
454 488
 
455
-		if (!empty($fail) && function_exists('log_error'))
456
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
489
+		if (!empty($fail) && function_exists('log_error')) {
490
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
491
+		}
457 492
 	}
458 493
 
459 494
 	// Debugging.
@@ -463,8 +498,9 @@  discard block
 block discarded – undo
463 498
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
464 499
 
465 500
 		// Initialize $db_cache if not already initialized.
466
-		if (!isset($db_cache))
467
-			$db_cache = array();
501
+		if (!isset($db_cache)) {
502
+					$db_cache = array();
503
+		}
468 504
 
469 505
 		if (!empty($_SESSION['debug_redirect']))
470 506
 		{
@@ -480,17 +516,20 @@  discard block
 block discarded – undo
480 516
 		$db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start;
481 517
 	}
482 518
 
483
-	if (empty($db_unbuffered))
484
-		$ret = @mysqli_query($connection, $db_string);
485
-	else
486
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
519
+	if (empty($db_unbuffered)) {
520
+			$ret = @mysqli_query($connection, $db_string);
521
+	} else {
522
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
523
+	}
487 524
 
488
-	if ($ret === false && empty($db_values['db_error_skip']))
489
-		$ret = smf_db_error($db_string, $connection);
525
+	if ($ret === false && empty($db_values['db_error_skip'])) {
526
+			$ret = smf_db_error($db_string, $connection);
527
+	}
490 528
 
491 529
 	// Debugging.
492
-	if (isset($db_show_debug) && $db_show_debug === true)
493
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
530
+	if (isset($db_show_debug) && $db_show_debug === true) {
531
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
532
+	}
494 533
 
495 534
 	return $ret;
496 535
 }
@@ -537,12 +576,13 @@  discard block
 block discarded – undo
537 576
 	// Decide which connection to use
538 577
 	$connection = $connection === null ? $db_connection : $connection;
539 578
 
540
-	if ($type == 'begin')
541
-		return @mysqli_query($connection, 'BEGIN');
542
-	elseif ($type == 'rollback')
543
-		return @mysqli_query($connection, 'ROLLBACK');
544
-	elseif ($type == 'commit')
545
-		return @mysqli_query($connection, 'COMMIT');
579
+	if ($type == 'begin') {
580
+			return @mysqli_query($connection, 'BEGIN');
581
+	} elseif ($type == 'rollback') {
582
+			return @mysqli_query($connection, 'ROLLBACK');
583
+	} elseif ($type == 'commit') {
584
+			return @mysqli_query($connection, 'COMMIT');
585
+	}
546 586
 
547 587
 	return false;
548 588
 }
@@ -580,8 +620,9 @@  discard block
 block discarded – undo
580 620
 	//    1213: Deadlock found.
581 621
 
582 622
 	// Log the error.
583
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
584
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
623
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
624
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
625
+	}
585 626
 
586 627
 	// Database error auto fixing ;).
587 628
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -590,8 +631,9 @@  discard block
 block discarded – undo
590 631
 		$old_cache = @$modSettings['cache_enable'];
591 632
 		$modSettings['cache_enable'] = '1';
592 633
 
593
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
594
-			$db_last_error = max(@$db_last_error, $temp);
634
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
635
+					$db_last_error = max(@$db_last_error, $temp);
636
+		}
595 637
 
596 638
 		if (@$db_last_error < time() - 3600 * 24 * 3)
597 639
 		{
@@ -607,8 +649,9 @@  discard block
 block discarded – undo
607 649
 					foreach ($tables as $table)
608 650
 					{
609 651
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
610
-						if (trim($table) != '')
611
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
652
+						if (trim($table) != '') {
653
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
654
+						}
612 655
 					}
613 656
 				}
614 657
 
@@ -617,8 +660,9 @@  discard block
 block discarded – undo
617 660
 			// Table crashed.  Let's try to fix it.
618 661
 			elseif ($query_errno == 1016)
619 662
 			{
620
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
621
-					$fix_tables = array('`' . $match[1] . '`');
663
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
664
+									$fix_tables = array('`' . $match[1] . '`');
665
+				}
622 666
 			}
623 667
 			// Indexes crashed.  Should be easy to fix!
624 668
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -637,13 +681,15 @@  discard block
 block discarded – undo
637 681
 
638 682
 			// Make a note of the REPAIR...
639 683
 			cache_put_data('db_last_error', time(), 600);
640
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
641
-				updateSettingsFile(array('db_last_error' => time()));
684
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
685
+							updateSettingsFile(array('db_last_error' => time()));
686
+			}
642 687
 
643 688
 			// Attempt to find and repair the broken table.
644
-			foreach ($fix_tables as $table)
645
-				$smcFunc['db_query']('', "
689
+			foreach ($fix_tables as $table) {
690
+							$smcFunc['db_query']('', "
646 691
 					REPAIR TABLE $table", false, false);
692
+			}
647 693
 
648 694
 			// And send off an email!
649 695
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -652,11 +698,12 @@  discard block
 block discarded – undo
652 698
 
653 699
 			// Try the query again...?
654 700
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
655
-			if ($ret !== false)
656
-				return $ret;
701
+			if ($ret !== false) {
702
+							return $ret;
703
+			}
704
+		} else {
705
+					$modSettings['cache_enable'] = $old_cache;
657 706
 		}
658
-		else
659
-			$modSettings['cache_enable'] = $old_cache;
660 707
 
661 708
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
662 709
 		if (in_array($query_errno, array(1205, 1213)))
@@ -669,24 +716,27 @@  discard block
 block discarded – undo
669 716
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
670 717
 
671 718
 					$new_errno = mysqli_errno($db_connection);
672
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
673
-						break;
719
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
720
+											break;
721
+					}
674 722
 				}
675 723
 
676 724
 				// If it failed again, shucks to be you... we're not trying it over and over.
677
-				if ($ret !== false)
678
-					return $ret;
725
+				if ($ret !== false) {
726
+									return $ret;
727
+				}
679 728
 			}
680 729
 		}
681 730
 		// Are they out of space, perhaps?
682 731
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
683 732
 		{
684
-			if (!isset($txt))
685
-				$query_error .= ' - check database storage space.';
686
-			else
733
+			if (!isset($txt)) {
734
+							$query_error .= ' - check database storage space.';
735
+			} else
687 736
 			{
688
-				if (!isset($txt['mysql_error_space']))
689
-					loadLanguage('Errors');
737
+				if (!isset($txt['mysql_error_space'])) {
738
+									loadLanguage('Errors');
739
+				}
690 740
 
691 741
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
692 742
 			}
@@ -694,15 +744,17 @@  discard block
 block discarded – undo
694 744
 	}
695 745
 
696 746
 	// Nothing's defined yet... just die with it.
697
-	if (empty($context) || empty($txt))
698
-		die($query_error);
747
+	if (empty($context) || empty($txt)) {
748
+			die($query_error);
749
+	}
699 750
 
700 751
 	// Show an error message, if possible.
701 752
 	$context['error_title'] = $txt['database_error'];
702
-	if (allowedTo('admin_forum'))
703
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
704
-	else
705
-		$context['error_message'] = $txt['try_again'];
753
+	if (allowedTo('admin_forum')) {
754
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
755
+	} else {
756
+			$context['error_message'] = $txt['try_again'];
757
+	}
706 758
 
707 759
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
708 760
 	{
@@ -734,8 +786,9 @@  discard block
 block discarded – undo
734 786
 	$return_var = null;
735 787
 
736 788
 	// With nothing to insert, simply return.
737
-	if (empty($data))
738
-		return;
789
+	if (empty($data)) {
790
+			return;
791
+	}
739 792
 
740 793
 	// Replace the prefix holder with the actual prefix.
741 794
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -745,23 +798,26 @@  discard block
 block discarded – undo
745 798
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
746 799
 	{
747 800
 		$with_returning = true;
748
-		if ($returnmode == 2)
749
-			$return_var = array();
801
+		if ($returnmode == 2) {
802
+					$return_var = array();
803
+		}
750 804
 	}
751 805
 
752 806
 	// Inserting data as a single row can be done as a single array.
753
-	if (!is_array($data[array_rand($data)]))
754
-		$data = array($data);
807
+	if (!is_array($data[array_rand($data)])) {
808
+			$data = array($data);
809
+	}
755 810
 
756 811
 	// Create the mold for a single row insert.
757 812
 	$insertData = '(';
758 813
 	foreach ($columns as $columnName => $type)
759 814
 	{
760 815
 		// Are we restricting the length?
761
-		if (strpos($type, 'string-') !== false)
762
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
763
-		else
764
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
816
+		if (strpos($type, 'string-') !== false) {
817
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
818
+		} else {
819
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
820
+		}
765 821
 	}
766 822
 	$insertData = substr($insertData, 0, -2) . ')';
767 823
 
@@ -770,16 +826,18 @@  discard block
 block discarded – undo
770 826
 
771 827
 	// Here's where the variables are injected to the query.
772 828
 	$insertRows = array();
773
-	foreach ($data as $dataRow)
774
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
829
+	foreach ($data as $dataRow) {
830
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
831
+	}
775 832
 
776 833
 	// Determine the method of insertion.
777 834
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
778 835
 
779 836
 	// Sanity check for replace is key part of the columns array
780
-	if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys))
781
-		smf_db_error_backtrace('Primary Key field missing in insert call',
837
+	if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) {
838
+			smf_db_error_backtrace('Primary Key field missing in insert call',
782 839
 				'Change the method of db insert to insert or add the pk field to the columns array', E_USER_ERROR, __FILE__, __LINE__);
840
+	}
783 841
 
784 842
 	if (!$with_returning || $method != 'ingore')
785 843
 	{
@@ -795,8 +853,7 @@  discard block
 block discarded – undo
795 853
 			),
796 854
 			$connection
797 855
 		);
798
-	}
799
-	else //special way for ignore method with returning
856
+	} else //special way for ignore method with returning
800 857
 	{
801 858
 		$count = count($insertRows);
802 859
 		$ai = 0;
@@ -816,19 +873,21 @@  discard block
 block discarded – undo
816 873
 			);
817 874
 			$new_id = $smcFunc['db_insert_id']();
818 875
 
819
-			if ($last_id != $new_id) //the inserted value was new
876
+			if ($last_id != $new_id) {
877
+				//the inserted value was new
820 878
 			{
821 879
 				$ai = $new_id;
822 880
 			}
823
-			else	// the inserted value already exists we need to find the pk
881
+			} else	// the inserted value already exists we need to find the pk
824 882
 			{
825 883
 				$where_string = '';
826 884
 				$count2 = count($indexed_columns);
827 885
 				for ($x = 0; $x < $count2; $x++)
828 886
 				{
829 887
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
830
-					if (($x + 1) < $count2)
831
-						$where_string += ' AND ';
888
+					if (($x + 1) < $count2) {
889
+											$where_string += ' AND ';
890
+					}
832 891
 				}
833 892
 
834 893
 				$request = $smcFunc['db_query']('','
@@ -844,25 +903,27 @@  discard block
 block discarded – undo
844 903
 				}
845 904
 			}
846 905
 
847
-			if ($returnmode == 1)
848
-				$return_var = $ai;
849
-			else if ($returnmode == 2)
850
-				$return_var[] = $ai;
906
+			if ($returnmode == 1) {
907
+							$return_var = $ai;
908
+			} else if ($returnmode == 2) {
909
+							$return_var[] = $ai;
910
+			}
851 911
 		}
852 912
 	}
853 913
 
854 914
 
855 915
 	if ($with_returning)
856 916
 	{
857
-		if ($returnmode == 1 && empty($return_var))
858
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
859
-		else if ($returnmode == 2 && empty($return_var))
917
+		if ($returnmode == 1 && empty($return_var)) {
918
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
919
+		} else if ($returnmode == 2 && empty($return_var))
860 920
 		{
861 921
 			$return_var = array();
862 922
 			$count = count($insertRows);
863 923
 			$start = smf_db_insert_id($table, $keys[0]);
864
-			for ($i = 0; $i < $count; $i++ )
865
-				$return_var[] = $start + $i;
924
+			for ($i = 0; $i < $count; $i++ ) {
925
+							$return_var[] = $start + $i;
926
+			}
866 927
 		}
867 928
 		return $return_var;
868 929
 	}
@@ -880,8 +941,9 @@  discard block
 block discarded – undo
880 941
  */
881 942
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
882 943
 {
883
-	if (empty($log_message))
884
-		$log_message = $error_message;
944
+	if (empty($log_message)) {
945
+			$log_message = $error_message;
946
+	}
885 947
 
886 948
 	foreach (debug_backtrace() as $step)
887 949
 	{
@@ -900,12 +962,14 @@  discard block
 block discarded – undo
900 962
 	}
901 963
 
902 964
 	// A special case - we want the file and line numbers for debugging.
903
-	if ($error_type == 'return')
904
-		return array($file, $line);
965
+	if ($error_type == 'return') {
966
+			return array($file, $line);
967
+	}
905 968
 
906 969
 	// Is always a critical error.
907
-	if (function_exists('log_error'))
908
-		log_error($log_message, 'critical', $file, $line);
970
+	if (function_exists('log_error')) {
971
+			log_error($log_message, 'critical', $file, $line);
972
+	}
909 973
 
910 974
 	if (function_exists('fatal_error'))
911 975
 	{
@@ -913,12 +977,12 @@  discard block
 block discarded – undo
913 977
 
914 978
 		// Cannot continue...
915 979
 		exit;
980
+	} elseif ($error_type) {
981
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
982
+	} else {
983
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
984
+	}
916 985
 	}
917
-	elseif ($error_type)
918
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
919
-	else
920
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
921
-}
922 986
 
923 987
 /**
924 988
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -935,10 +999,11 @@  discard block
 block discarded – undo
935 999
 		'\\' => '\\\\',
936 1000
 	);
937 1001
 
938
-	if ($translate_human_wildcards)
939
-		$replacements += array(
1002
+	if ($translate_human_wildcards) {
1003
+			$replacements += array(
940 1004
 			'*' => '%',
941 1005
 		);
1006
+	}
942 1007
 
943 1008
 	return strtr($string, $replacements);
944 1009
 }
@@ -952,8 +1017,9 @@  discard block
 block discarded – undo
952 1017
  */
953 1018
 function smf_is_resource($result)
954 1019
 {
955
-	if ($result instanceof mysqli_result)
956
-		return true;
1020
+	if ($result instanceof mysqli_result) {
1021
+			return true;
1022
+	}
957 1023
 
958 1024
 	return false;
959 1025
 }
@@ -982,19 +1048,22 @@  discard block
 block discarded – undo
982 1048
 	static $mysql_error_data_prep;
983 1049
 
984 1050
 	// without database we can't do anything
985
-	if (empty($db_connection))
986
-		return;
1051
+	if (empty($db_connection)) {
1052
+			return;
1053
+	}
987 1054
 
988
-	if (empty($mysql_error_data_prep))
989
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1055
+	if (empty($mysql_error_data_prep)) {
1056
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
990 1057
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace)
991 1058
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?, ?)'
992 1059
 			);
1060
+	}
993 1061
 
994
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
995
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
996
-	else
997
-		$error_array[2] = null;
1062
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1063
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1064
+	} else {
1065
+			$error_array[2] = null;
1066
+	}
998 1067
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis',
999 1068
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
1000 1069
 		$error_array[7], $error_array[8], $error_array[9]);
@@ -1016,8 +1085,9 @@  discard block
 block discarded – undo
1016 1085
 	$count = count($array_values);
1017 1086
 	$then = ($desc ? ' THEN -' : ' THEN ');
1018 1087
 
1019
-	for ($i = 0; $i < $count; $i++)
1020
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1088
+	for ($i = 0; $i < $count; $i++) {
1089
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1090
+	}
1021 1091
 
1022 1092
 	$return .= 'END';
1023 1093
 	return $return;
@@ -1043,17 +1113,20 @@  discard block
 block discarded – undo
1043 1113
 	global $smcFunc;
1044 1114
 	static $return;
1045 1115
 
1046
-	if (isset($return))
1047
-		return $return;
1116
+	if (isset($return)) {
1117
+			return $return;
1118
+	}
1048 1119
 
1049 1120
 	db_extend('extra');
1050 1121
 
1051 1122
 	$version = $smcFunc['db_get_version']();
1052 1123
 
1053
-	if (strpos(strtolower($version), 'mariadb') !== false)
1054
-		$return = version_compare($version, '10.2.2', '>=');
1055
-	else //mysql
1124
+	if (strpos(strtolower($version), 'mariadb') !== false) {
1125
+			$return = version_compare($version, '10.2.2', '>=');
1126
+	} else {
1127
+		//mysql
1056 1128
 		$return = version_compare($version, '8.0.1', '>=');
1129
+	}
1057 1130
 
1058 1131
 	return $return;
1059 1132
 }
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +241 added lines, -177 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
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query'                  => 'smf_db_query',
40 41
 			'db_quote'                  => 'smf_db_quote',
41 42
 			'db_insert'                 => 'smf_db_insert',
@@ -66,15 +67,18 @@  discard block
 block discarded – undo
66 67
 			'db_native_replace'         => 'smf_db_native_replace',
67 68
 			'db_cte_support'            => 'smf_db_cte_support',
68 69
 		);
70
+	}
69 71
 
70 72
 	// We are not going to make it very far without these.
71
-	if (!function_exists('pg_pconnect'))
72
-		display_db_error();
73
+	if (!function_exists('pg_pconnect')) {
74
+			display_db_error();
75
+	}
73 76
 
74
-	if (!empty($db_options['persist']))
75
-		$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
76
-	else
77
-		$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
77
+	if (!empty($db_options['persist'])) {
78
+			$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
79
+	} else {
80
+			$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
81
+	}
78 82
 
79 83
 	// Something's wrong, show an error if its fatal (which we assume it is)
80 84
 	if (!$connection)
@@ -82,15 +86,15 @@  discard block
 block discarded – undo
82 86
 		if (!empty($db_options['non_fatal']))
83 87
 		{
84 88
 			return null;
85
-		}
86
-		else
89
+		} else
87 90
 		{
88 91
 			display_db_error();
89 92
 		}
90 93
 	}
91 94
 
92
-	if (!empty($db_options['db_mb4']))
93
-		$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
95
+	if (!empty($db_options['db_mb4'])) {
96
+			$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
97
+	}
94 98
 
95 99
 	return $connection;
96 100
 }
@@ -137,31 +141,38 @@  discard block
 block discarded – undo
137 141
 
138 142
 	list ($values, $connection) = $db_callback;
139 143
 
140
-	if ($matches[1] === 'db_prefix')
141
-		return $db_prefix;
144
+	if ($matches[1] === 'db_prefix') {
145
+			return $db_prefix;
146
+	}
142 147
 
143
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
144
-		return $user_info[$matches[1]];
148
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
149
+			return $user_info[$matches[1]];
150
+	}
145 151
 
146
-	if ($matches[1] === 'empty')
147
-		return '\'\'';
152
+	if ($matches[1] === 'empty') {
153
+			return '\'\'';
154
+	}
148 155
 
149
-	if (!isset($matches[2]))
150
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
156
+	if (!isset($matches[2])) {
157
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
158
+	}
151 159
 
152
-	if ($matches[1] === 'literal')
153
-		return '\'' . pg_escape_string($matches[2]) . '\'';
160
+	if ($matches[1] === 'literal') {
161
+			return '\'' . pg_escape_string($matches[2]) . '\'';
162
+	}
154 163
 
155
-	if (!isset($values[$matches[2]]))
156
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
164
+	if (!isset($values[$matches[2]])) {
165
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
166
+	}
157 167
 
158 168
 	$replacement = $values[$matches[2]];
159 169
 
160 170
 	switch ($matches[1])
161 171
 	{
162 172
 		case 'int':
163
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
164
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
173
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
174
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+			}
165 176
 			return (string) (int) $replacement;
166 177
 		break;
167 178
 
@@ -173,65 +184,73 @@  discard block
 block discarded – undo
173 184
 		case 'array_int':
174 185
 			if (is_array($replacement))
175 186
 			{
176
-				if (empty($replacement))
177
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
187
+				if (empty($replacement)) {
188
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
189
+				}
178 190
 
179 191
 				foreach ($replacement as $key => $value)
180 192
 				{
181
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
182
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
193
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
194
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195
+					}
183 196
 
184 197
 					$replacement[$key] = (string) (int) $value;
185 198
 				}
186 199
 
187 200
 				return implode(', ', $replacement);
201
+			} else {
202
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
188 203
 			}
189
-			else
190
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
191 204
 
192 205
 		break;
193 206
 
194 207
 		case 'array_string':
195 208
 			if (is_array($replacement))
196 209
 			{
197
-				if (empty($replacement))
198
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210
+				if (empty($replacement)) {
211
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
212
+				}
199 213
 
200
-				foreach ($replacement as $key => $value)
201
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
214
+				foreach ($replacement as $key => $value) {
215
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
216
+				}
202 217
 
203 218
 				return implode(', ', $replacement);
219
+			} else {
220
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
204 221
 			}
205
-			else
206
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
207 222
 		break;
208 223
 
209 224
 		case 'date':
210
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
211
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
212
-			else
213
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
226
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
227
+			} else {
228
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+			}
214 230
 		break;
215 231
 
216 232
 		case 'time':
217
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
218
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
219
-			else
220
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
234
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			}
221 238
 		break;
222 239
 
223 240
 		case 'datetime':
224
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
225
-				return 'to_timestamp('.
241
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
242
+							return 'to_timestamp('.
226 243
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
227 244
 					',\'YYYY-MM-DD HH24:MI:SS\')';
228
-			else
229
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+			} else {
246
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
247
+			}
230 248
 		break;
231 249
 
232 250
 		case 'float':
233
-			if (!is_numeric($replacement))
234
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
251
+			if (!is_numeric($replacement)) {
252
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
253
+			}
235 254
 			return (string) (float) $replacement;
236 255
 		break;
237 256
 
@@ -244,31 +263,36 @@  discard block
 block discarded – undo
244 263
 		break;
245 264
 
246 265
 		case 'inet':
247
-			if ($replacement == 'null' || $replacement == '')
248
-				return 'null';
249
-			if (inet_pton($replacement) === false)
250
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+			if ($replacement == 'null' || $replacement == '') {
267
+							return 'null';
268
+			}
269
+			if (inet_pton($replacement) === false) {
270
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+			}
251 272
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
252 273
 
253 274
 		case 'array_inet':
254 275
 			if (is_array($replacement))
255 276
 			{
256
-				if (empty($replacement))
257
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+				if (empty($replacement)) {
278
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+				}
258 280
 
259 281
 				foreach ($replacement as $key => $value)
260 282
 				{
261
-					if ($replacement == 'null' || $replacement == '')
262
-						$replacement[$key] = 'null';
263
-					if (!isValidIP($value))
264
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
283
+					if ($replacement == 'null' || $replacement == '') {
284
+											$replacement[$key] = 'null';
285
+					}
286
+					if (!isValidIP($value)) {
287
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+					}
265 289
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
266 290
 				}
267 291
 
268 292
 				return implode(', ', $replacement);
293
+			} else {
294
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269 295
 			}
270
-			else
271
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272 296
 		break;
273 297
 
274 298
 		default:
@@ -356,14 +380,16 @@  discard block
 block discarded – undo
356 380
 		),
357 381
 	);
358 382
 
359
-	if (isset($replacements[$identifier]))
360
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
383
+	if (isset($replacements[$identifier])) {
384
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
385
+	}
361 386
 
362 387
 	// Limits need to be a little different.
363 388
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
364 389
 
365
-	if (trim($db_string) == '')
366
-		return false;
390
+	if (trim($db_string) == '') {
391
+			return false;
392
+	}
367 393
 
368 394
 	// Comments that are allowed in a query are preg_removed.
369 395
 	static $allowed_comments_from = array(
@@ -383,8 +409,9 @@  discard block
 block discarded – undo
383 409
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
384 410
 	$db_replace_result = 0;
385 411
 
386
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
387
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
412
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
413
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
414
+	}
388 415
 
389 416
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
390 417
 	{
@@ -409,17 +436,18 @@  discard block
 block discarded – undo
409 436
 		while (true)
410 437
 		{
411 438
 			$pos = strpos($db_string_1, '\'', $pos + 1);
412
-			if ($pos === false)
413
-				break;
439
+			if ($pos === false) {
440
+							break;
441
+			}
414 442
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
415 443
 
416 444
 			while (true)
417 445
 			{
418 446
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
419 447
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
420
-				if ($pos1 === false)
421
-					break;
422
-				elseif ($pos2 === false || $pos2 > $pos1)
448
+				if ($pos1 === false) {
449
+									break;
450
+				} elseif ($pos2 === false || $pos2 > $pos1)
423 451
 				{
424 452
 					$pos = $pos1;
425 453
 					break;
@@ -435,16 +463,19 @@  discard block
 block discarded – undo
435 463
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
436 464
 
437 465
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
438
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
439
-			$fail = true;
466
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
467
+					$fail = true;
468
+		}
440 469
 		// Trying to change passwords, slow us down, or something?
441
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
442
-			$fail = true;
443
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
444
-			$fail = true;
470
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
471
+					$fail = true;
472
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
473
+					$fail = true;
474
+		}
445 475
 
446
-		if (!empty($fail) && function_exists('log_error'))
447
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
476
+		if (!empty($fail) && function_exists('log_error')) {
477
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
478
+		}
448 479
 	}
449 480
 
450 481
 	// Set optimize stuff
@@ -471,8 +502,9 @@  discard block
 block discarded – undo
471 502
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
472 503
 
473 504
 		// Initialize $db_cache if not already initialized.
474
-		if (!isset($db_cache))
475
-			$db_cache = array();
505
+		if (!isset($db_cache)) {
506
+					$db_cache = array();
507
+		}
476 508
 
477 509
 		if (!empty($_SESSION['debug_redirect']))
478 510
 		{
@@ -490,12 +522,14 @@  discard block
 block discarded – undo
490 522
 
491 523
 	$db_last_result = @pg_query($connection, $db_string);
492 524
 
493
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
494
-		$db_last_result = smf_db_error($db_string, $connection);
525
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
526
+			$db_last_result = smf_db_error($db_string, $connection);
527
+	}
495 528
 
496 529
 	// Debugging.
497
-	if (isset($db_show_debug) && $db_show_debug === true)
498
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
530
+	if (isset($db_show_debug) && $db_show_debug === true) {
531
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
532
+	}
499 533
 
500 534
 	return $db_last_result;
501 535
 }
@@ -512,10 +546,11 @@  discard block
 block discarded – undo
512 546
 {
513 547
 	global $db_last_result, $db_replace_result;
514 548
 
515
-	if ($db_replace_result)
516
-		return $db_replace_result;
517
-	elseif ($result === null && !$db_last_result)
518
-		return 0;
549
+	if ($db_replace_result) {
550
+			return $db_replace_result;
551
+	} elseif ($result === null && !$db_last_result) {
552
+			return 0;
553
+	}
519 554
 
520 555
 	return pg_affected_rows($result === null ? $db_last_result : $result);
521 556
 }
@@ -539,8 +574,9 @@  discard block
 block discarded – undo
539 574
 		array(
540 575
 		)
541 576
 	);
542
-	if (!$request)
543
-		return false;
577
+	if (!$request) {
578
+			return false;
579
+	}
544 580
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
545 581
 	$smcFunc['db_free_result']($request);
546 582
 
@@ -561,12 +597,13 @@  discard block
 block discarded – undo
561 597
 	// Decide which connection to use
562 598
 	$connection = $connection === null ? $db_connection : $connection;
563 599
 
564
-	if ($type == 'begin')
565
-		return @pg_query($connection, 'BEGIN');
566
-	elseif ($type == 'rollback')
567
-		return @pg_query($connection, 'ROLLBACK');
568
-	elseif ($type == 'commit')
569
-		return @pg_query($connection, 'COMMIT');
600
+	if ($type == 'begin') {
601
+			return @pg_query($connection, 'BEGIN');
602
+	} elseif ($type == 'rollback') {
603
+			return @pg_query($connection, 'ROLLBACK');
604
+	} elseif ($type == 'commit') {
605
+			return @pg_query($connection, 'COMMIT');
606
+	}
570 607
 
571 608
 	return false;
572 609
 }
@@ -594,19 +631,22 @@  discard block
 block discarded – undo
594 631
 	$query_error = @pg_last_error($connection);
595 632
 
596 633
 	// Log the error.
597
-	if (function_exists('log_error'))
598
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
634
+	if (function_exists('log_error')) {
635
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
636
+	}
599 637
 
600 638
 	// Nothing's defined yet... just die with it.
601
-	if (empty($context) || empty($txt))
602
-		die($query_error);
639
+	if (empty($context) || empty($txt)) {
640
+			die($query_error);
641
+	}
603 642
 
604 643
 	// Show an error message, if possible.
605 644
 	$context['error_title'] = $txt['database_error'];
606
-	if (allowedTo('admin_forum'))
607
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
608
-	else
609
-		$context['error_message'] = $txt['try_again'];
645
+	if (allowedTo('admin_forum')) {
646
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
647
+	} else {
648
+			$context['error_message'] = $txt['try_again'];
649
+	}
610 650
 
611 651
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
612 652
 	{
@@ -628,12 +668,14 @@  discard block
 block discarded – undo
628 668
 {
629 669
 	global $db_row_count;
630 670
 
631
-	if ($counter !== false)
632
-		return pg_fetch_row($request, $counter);
671
+	if ($counter !== false) {
672
+			return pg_fetch_row($request, $counter);
673
+	}
633 674
 
634 675
 	// Reset the row counter...
635
-	if (!isset($db_row_count[(int) $request]))
636
-		$db_row_count[(int) $request] = 0;
676
+	if (!isset($db_row_count[(int) $request])) {
677
+			$db_row_count[(int) $request] = 0;
678
+	}
637 679
 
638 680
 	// Return the right row.
639 681
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -650,12 +692,14 @@  discard block
 block discarded – undo
650 692
 {
651 693
 	global $db_row_count;
652 694
 
653
-	if ($counter !== false)
654
-		return pg_fetch_assoc($request, $counter);
695
+	if ($counter !== false) {
696
+			return pg_fetch_assoc($request, $counter);
697
+	}
655 698
 
656 699
 	// Reset the row counter...
657
-	if (!isset($db_row_count[(int) $request]))
658
-		$db_row_count[(int) $request] = 0;
700
+	if (!isset($db_row_count[(int) $request])) {
701
+			$db_row_count[(int) $request] = 0;
702
+	}
659 703
 
660 704
 	// Return the right row.
661 705
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -697,19 +741,22 @@  discard block
 block discarded – undo
697 741
 
698 742
 	$replace = '';
699 743
 
700
-	if (empty($data))
701
-		return;
744
+	if (empty($data)) {
745
+			return;
746
+	}
702 747
 
703
-	if (!is_array($data[array_rand($data)]))
704
-		$data = array($data);
748
+	if (!is_array($data[array_rand($data)])) {
749
+			$data = array($data);
750
+	}
705 751
 
706 752
 	// Replace the prefix holder with the actual prefix.
707 753
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
708 754
 
709 755
 	// Sanity check for replace is key part of the columns array
710
-	if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys))
711
-		smf_db_error_backtrace('Primary Key field missing in insert call',
756
+	if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) {
757
+			smf_db_error_backtrace('Primary Key field missing in insert call',
712 758
 				'Change the method of db insert to insert or add the pk field to the columns array', E_USER_ERROR, __FILE__, __LINE__);
759
+	}
713 760
 
714 761
 	// PostgreSQL doesn't support replace: we implement a MySQL-compatible behavior instead
715 762
 	if ($method == 'replace' || $method == 'ignore')
@@ -732,32 +779,35 @@  discard block
 block discarded – undo
732 779
 					$key_str .= ($count_pk > 0 ? ',' : '');
733 780
 					$key_str .= $columnName;
734 781
 					$count_pk++;
735
-				}
736
-				else if ($method == 'replace') //normal field
782
+				} else if ($method == 'replace') {
783
+					//normal field
737 784
 				{
738 785
 					$col_str .= ($count > 0 ? ',' : '');
786
+				}
739 787
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
740 788
 					$count++;
741 789
 				}
742 790
 			}
743
-			if ($method == 'replace')
744
-				$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
745
-			else
746
-				$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
747
-		}
748
-		else if ($method == 'replace')
791
+			if ($method == 'replace') {
792
+							$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
793
+			} else {
794
+							$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
795
+			}
796
+		} else if ($method == 'replace')
749 797
 		{
750 798
 			foreach ($columns as $columnName => $type)
751 799
 			{
752 800
 				// Are we restricting the length?
753
-				if (strpos($type, 'string-') !== false)
754
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
755
-				else
756
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
801
+				if (strpos($type, 'string-') !== false) {
802
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
803
+				} else {
804
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
805
+				}
757 806
 
758 807
 				// A key? That's what we were looking for.
759
-				if (in_array($columnName, $keys))
760
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
808
+				if (in_array($columnName, $keys)) {
809
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
810
+				}
761 811
 				$count++;
762 812
 			}
763 813
 
@@ -793,10 +843,11 @@  discard block
 block discarded – undo
793 843
 		foreach ($columns as $columnName => $type)
794 844
 		{
795 845
 			// Are we restricting the length?
796
-			if (strpos($type, 'string-') !== false)
797
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
798
-			else
799
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
846
+			if (strpos($type, 'string-') !== false) {
847
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
848
+			} else {
849
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
850
+			}
800 851
 		}
801 852
 		$insertData = substr($insertData, 0, -2) . ')';
802 853
 
@@ -805,8 +856,9 @@  discard block
 block discarded – undo
805 856
 
806 857
 		// Here's where the variables are injected to the query.
807 858
 		$insertRows = array();
808
-		foreach ($data as $dataRow)
809
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
859
+		foreach ($data as $dataRow) {
860
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
861
+		}
810 862
 
811 863
 		// Do the insert.
812 864
 		$request = $smcFunc['db_query']('', '
@@ -823,19 +875,21 @@  discard block
 block discarded – undo
823 875
 
824 876
 		if ($with_returning && $request !== false)
825 877
 		{
826
-			if ($returnmode === 2)
827
-				$return_var = array();
878
+			if ($returnmode === 2) {
879
+							$return_var = array();
880
+			}
828 881
 
829 882
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
830 883
 			{
831
-				if (is_numeric($row[0])) // try to emulate mysql limitation
884
+				if (is_numeric($row[0])) {
885
+					// try to emulate mysql limitation
832 886
 				{
833 887
 					if ($returnmode === 1)
834 888
 						$return_var = $row[0];
835
-					elseif ($returnmode === 2)
836
-						$return_var[] = $row[0];
837
-				}
838
-				else
889
+				} elseif ($returnmode === 2) {
890
+											$return_var[] = $row[0];
891
+					}
892
+				} else
839 893
 				{
840 894
 					$with_returning = false;
841 895
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -844,9 +898,10 @@  discard block
 block discarded – undo
844 898
 		}
845 899
 	}
846 900
 
847
-	if ($with_returning && !empty($return_var))
848
-		return $return_var;
849
-}
901
+	if ($with_returning && !empty($return_var)) {
902
+			return $return_var;
903
+	}
904
+	}
850 905
 
851 906
 /**
852 907
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -883,8 +938,9 @@  discard block
 block discarded – undo
883 938
  */
884 939
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
885 940
 {
886
-	if (empty($log_message))
887
-		$log_message = $error_message;
941
+	if (empty($log_message)) {
942
+			$log_message = $error_message;
943
+	}
888 944
 
889 945
 	foreach (debug_backtrace() as $step)
890 946
 	{
@@ -903,12 +959,14 @@  discard block
 block discarded – undo
903 959
 	}
904 960
 
905 961
 	// A special case - we want the file and line numbers for debugging.
906
-	if ($error_type == 'return')
907
-		return array($file, $line);
962
+	if ($error_type == 'return') {
963
+			return array($file, $line);
964
+	}
908 965
 
909 966
 	// Is always a critical error.
910
-	if (function_exists('log_error'))
911
-		log_error($log_message, 'critical', $file, $line);
967
+	if (function_exists('log_error')) {
968
+			log_error($log_message, 'critical', $file, $line);
969
+	}
912 970
 
913 971
 	if (function_exists('fatal_error'))
914 972
 	{
@@ -916,12 +974,12 @@  discard block
 block discarded – undo
916 974
 
917 975
 		// Cannot continue...
918 976
 		exit;
977
+	} elseif ($error_type) {
978
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
979
+	} else {
980
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
981
+	}
919 982
 	}
920
-	elseif ($error_type)
921
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
922
-	else
923
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
924
-}
925 983
 
926 984
 /**
927 985
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -938,10 +996,11 @@  discard block
 block discarded – undo
938 996
 		'\\' => '\\\\',
939 997
 	);
940 998
 
941
-	if ($translate_human_wildcards)
942
-		$replacements += array(
999
+	if ($translate_human_wildcards) {
1000
+			$replacements += array(
943 1001
 			'*' => '%',
944 1002
 		);
1003
+	}
945 1004
 
946 1005
 	return strtr($string, $replacements);
947 1006
 }
@@ -970,14 +1029,16 @@  discard block
 block discarded – undo
970 1029
 	static $pg_error_data_prep;
971 1030
 
972 1031
 	// without database we can't do anything
973
-	if (empty($db_connection))
974
-		return;
1032
+	if (empty($db_connection)) {
1033
+			return;
1034
+	}
975 1035
 
976
-	if (empty($pg_error_data_prep))
977
-			$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
1036
+	if (empty($pg_error_data_prep)) {
1037
+				$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
978 1038
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace)
979 1039
 													VALUES(		$1,		$2,		$3, $4, 	$5,		$6,			$7,		$8,	$9, $10)'
980 1040
 			);
1041
+	}
981 1042
 
982 1043
 	pg_execute($db_connection, 'smf_log_errors', $error_array);
983 1044
 }
@@ -997,8 +1058,9 @@  discard block
 block discarded – undo
997 1058
 	$count = count($array_values);
998 1059
 	$then = ($desc ? ' THEN -' : ' THEN ');
999 1060
 
1000
-	for ($i = 0; $i < $count; $i++)
1001
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1061
+	for ($i = 0; $i < $count; $i++) {
1062
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1063
+	}
1002 1064
 
1003 1065
 	$return .= 'END';
1004 1066
 	return $return;
@@ -1021,11 +1083,13 @@  discard block
 block discarded – undo
1021 1083
 		//pg 9.5 got replace support
1022 1084
 		$pg_version = $smcFunc['db_get_version']();
1023 1085
 		// if we got a Beta Version
1024
-		if (stripos($pg_version, 'beta') !== false)
1025
-			$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
1086
+		if (stripos($pg_version, 'beta') !== false) {
1087
+					$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
1088
+		}
1026 1089
 		// or RC
1027
-		if (stripos($pg_version, 'rc') !== false)
1028
-			$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
1090
+		if (stripos($pg_version, 'rc') !== false) {
1091
+					$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
1092
+		}
1029 1093
 
1030 1094
 		$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
1031 1095
 	}
Please login to merge, or discard this patch.