Completed
Push — release-2.1 ( 72357d...5fd6f8 )
by Michael
22s
created
cron.php 1 patch
Braces   +36 added lines, -28 removed lines patch added patch discarded remove patch
@@ -41,37 +41,43 @@  discard block
 block discarded – undo
41 41
 define('TIME_START', microtime(true));
42 42
 
43 43
 // Just being safe...
44
-foreach (array('db_character_set', 'cachedir') as $variable)
44
+foreach (array('db_character_set', 'cachedir') as $variable) {
45 45
 	if (isset($GLOBALS[$variable]))
46 46
 		unset($GLOBALS[$variable]);
47
+}
47 48
 
48 49
 // Get the forum's settings for database and file paths.
49 50
 require_once(dirname(__FILE__) . '/Settings.php');
50 51
 
51 52
 // Make absolutely sure the cache directory is defined.
52
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
53
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
53 54
 	$cachedir = $boarddir . '/cache';
55
+}
54 56
 
55 57
 // Don't do john didley if the forum's been shut down competely.
56
-if ($maintenance == 2)
58
+if ($maintenance == 2) {
57 59
 	die($mmessage);
60
+}
58 61
 
59 62
 // Fix for using the current directory as a path.
60
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
63
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
61 64
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
65
+}
62 66
 
63 67
 // Have we already turned this off? If so, exist gracefully.
64
-if (file_exists($cachedir . '/cron.lock'))
68
+if (file_exists($cachedir . '/cron.lock')) {
65 69
 	obExit_cron();
70
+}
66 71
 
67 72
 // Before we go any further, if this is not a CLI request, we need to do some checking.
68 73
 if (!FROM_CLI)
69 74
 {
70 75
 	// We will clean up $_GET shortly. But we want to this ASAP.
71 76
 	$ts = isset($_GET['ts']) ? (int) $_GET['ts'] : 0;
72
-	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20)
73
-		obExit_cron();
74
-}
77
+	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) {
78
+			obExit_cron();
79
+	}
80
+	}
75 81
 
76 82
 // Load the most important includes. In general, a background should be loading its own dependencies.
77 83
 require_once($sourcedir . '/Errors.php');
@@ -123,8 +129,9 @@  discard block
 block discarded – undo
123 129
 	global $smcFunc;
124 130
 
125 131
 	// Check we haven't run over our time limit.
126
-	if (microtime(true) - TIME_START > MAX_CRON_TIME)
127
-		return false;
132
+	if (microtime(true) - TIME_START > MAX_CRON_TIME) {
133
+			return false;
134
+	}
128 135
 
129 136
 	// Try to find a task. Specifically, try to find one that hasn't been claimed previously, or failing that,
130 137
 	// a task that was claimed but failed for whatever reason and failed long enough ago. We should not care
@@ -159,14 +166,12 @@  discard block
 block discarded – undo
159 166
 			// Update the time and go back.
160 167
 			$row['claimed_time'] = time();
161 168
 			return $row;
162
-		}
163
-		else
169
+		} else
164 170
 		{
165 171
 			// Uh oh, we just missed it. Try to claim another one, and let it fall through if there aren't any.
166 172
 			return fetch_task();
167 173
 		}
168
-	}
169
-	else
174
+	} else
170 175
 	{
171 176
 		// No dice. Clean up and go home.
172 177
 		$smcFunc['db_free_result']($request);
@@ -187,8 +192,9 @@  discard block
 block discarded – undo
187 192
 	if (!empty($task_details['task_file']))
188 193
 	{
189 194
 		$include = strtr(trim($task_details['task_file']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
190
-		if (file_exists($include))
191
-			require_once($include);
195
+		if (file_exists($include)) {
196
+					require_once($include);
197
+		}
192 198
 	}
193 199
 
194 200
 	if (empty($task_details['task_class']))
@@ -204,8 +210,7 @@  discard block
 block discarded – undo
204 210
 		$details = empty($task_details['task_data']) ? array() : $smcFunc['json_decode']($task_details['task_data'], true);
205 211
 		$bgtask = new $task_details['task_class']($details);
206 212
 		return $bgtask->execute();
207
-	}
208
-	else
213
+	} else
209 214
 	{
210 215
 		log_error('Invalid background task specified: (class: ' . $task_details['task_class'] . ', ' . (empty($task_details['task_file']) ? ' no file' : ' to load ' . $task_details['task_file']) . ')');
211 216
 		return true; // So we clear it from the queue.
@@ -224,8 +229,9 @@  discard block
 block discarded – undo
224 229
 	$scripturl = $boardurl . '/index.php';
225 230
 
226 231
 	// These keys shouldn't be set...ever.
227
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
228
-		die('Invalid request variable.');
232
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
233
+			die('Invalid request variable.');
234
+	}
229 235
 
230 236
 	// Save some memory.. (since we don't use these anyway.)
231 237
 	unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']);
@@ -246,26 +252,28 @@  discard block
 block discarded – undo
246 252
 	global $modSettings;
247 253
 
248 254
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.)
249
-	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging'])))
250
-		return;
255
+	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) {
256
+			return;
257
+	}
251 258
 
252 259
 	$error_type = 'cron';
253 260
 
254 261
 	log_error($error_level . ': ' . $error_string, $error_type, $file, $line);
255 262
 
256 263
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
257
-	if ($error_level % 255 == E_ERROR)
258
-		die('No direct access...');
259
-}
264
+	if ($error_level % 255 == E_ERROR) {
265
+			die('No direct access...');
266
+	}
267
+	}
260 268
 
261 269
 /**
262 270
  * The exit function
263 271
  */
264 272
 function obExit_cron()
265 273
 {
266
-	if (FROM_CLI)
267
-		die(0);
268
-	else
274
+	if (FROM_CLI) {
275
+			die(0);
276
+	} else
269 277
 	{
270 278
 		header('Content-Type: image/gif');
271 279
 		die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
Please login to merge, or discard this patch.
Themes/default/Packages.template.php 1 patch
Braces   +144 added lines, -104 removed lines patch added patch discarded remove patch
@@ -31,12 +31,13 @@  discard block
 block discarded – undo
31 31
 		</div>
32 32
 		<div class="information">';
33 33
 
34
-	if ($context['is_installed'])
35
-		echo '
34
+	if ($context['is_installed']) {
35
+			echo '
36 36
 			<strong>', $txt['package_installed_warning1'], '</strong><br>
37 37
 			<br>
38 38
 			', $txt['package_installed_warning2'], '<br>
39 39
 			<br>';
40
+	}
40 41
 
41 42
 	echo $txt['package_installed_warning3'], '
42 43
 		</div><br>';
@@ -63,8 +64,9 @@  discard block
 block discarded – undo
63 64
 				', $context['package_readme'], '
64 65
 				<span class="floatright">', $txt['package_available_readme_language'], '
65 66
 					<select name="readme_language" id="readme_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = smf_prepareScriptUrl(smf_scripturl + \'', '?action=admin;area=packages;sa=', $context['uninstalling'] ? 'uninstall' : 'install', ';package=', $context['filename'], ';readme=\' + this.options[this.selectedIndex].value + \';license=\' + get_selected(\'license_language\'));">';
66
-						foreach ($context['readmes'] as $a => $b)
67
-							echo '<option value="', $b, '"', $a === 'selected' ? ' selected' : '', '>', $b == 'default' ? $txt['package_readme_default'] : ucfirst($b), '</option>';
67
+						foreach ($context['readmes'] as $a => $b) {
68
+													echo '<option value="', $b, '"', $a === 'selected' ? ' selected' : '', '>', $b == 'default' ? $txt['package_readme_default'] : ucfirst($b), '</option>';
69
+						}
68 70
 			echo '
69 71
 					</select>
70 72
 				</span>
@@ -83,8 +85,9 @@  discard block
 block discarded – undo
83 85
 				', $context['package_license'], '
84 86
 				<span class="floatright">', $txt['package_available_license_language'], '
85 87
 					<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\'));">';
86
-						foreach ($context['licenses'] as $a => $b)
87
-							echo '<option value="', $b, '"', $a === 'selected' ? ' selected' : '', '>', $b == 'default' ? $txt['package_license_default'] : ucfirst($b), '</option>';
88
+						foreach ($context['licenses'] as $a => $b) {
89
+													echo '<option value="', $b, '"', $a === 'selected' ? ' selected' : '', '>', $b == 'default' ? $txt['package_license_default'] : ucfirst($b), '</option>';
90
+						}
88 91
 			echo '
89 92
 					</select>
90 93
 				</span>
@@ -111,9 +114,10 @@  discard block
 block discarded – undo
111 114
 					', $txt['package_db_uninstall_actions'], ':
112 115
 					<ul>';
113 116
 
114
-		foreach ($context['database_changes'] as $change)
115
-			echo '
117
+		foreach ($context['database_changes'] as $change) {
118
+					echo '
116 119
 						<li>', $change, '</li>';
120
+		}
117 121
 		echo '
118 122
 					</ul>
119 123
 				</div>
@@ -123,14 +127,14 @@  discard block
 block discarded – undo
123 127
 	echo '
124 128
 			<div class="information">';
125 129
 
126
-	if (empty($context['actions']) && empty($context['database_changes']))
127
-		echo '
130
+	if (empty($context['actions']) && empty($context['database_changes'])) {
131
+			echo '
128 132
 				<br>
129 133
 				<div class="errorbox">
130 134
 					', $txt['corrupt_compatible'], '
131 135
 				</div>
132 136
 			</div>';
133
-	else
137
+	} else
134 138
 	{
135 139
 		echo '
136 140
 					', $txt['perform_actions'], '
@@ -230,9 +234,10 @@  discard block
 block discarded – undo
230 234
 					<tr class="title_bar">
231 235
 						<td></td>
232 236
 						<td>';
233
-				if (!empty($context['themes_locked']))
234
-					echo '
237
+				if (!empty($context['themes_locked'])) {
238
+									echo '
235 239
 							<input type="hidden" name="custom_theme[]" value="', $id, '">';
240
+				}
236 241
 				echo '
237 242
 							<input type="checkbox" name="custom_theme[]" id="custom_theme_', $id, '" value="', $id, '" class="input_check" 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' : '', '>
238 243
 						</td>
@@ -373,14 +378,15 @@  discard block
 block discarded – undo
373 378
 	</script>';
374 379
 
375 380
 	// And a bit more for database changes.
376
-	if (!empty($context['database_changes']))
377
-		echo '
381
+	if (!empty($context['database_changes'])) {
382
+			echo '
378 383
 	<script>
379 384
 		var database_changes_area = document.getElementById(\'db_changes_div\');
380 385
 		var db_vis = false;
381 386
 		database_changes_area.style.display = "none";
382 387
 	</script>';
383
-}
388
+	}
389
+	}
384 390
 
385 391
 /**
386 392
  * Extract package contents
@@ -412,12 +418,12 @@  discard block
 block discarded – undo
412 418
 				<h3 class="catbg">', $context['uninstalling'] ? $txt['uninstall'] : $txt['extracting'], '</h3>
413 419
 			</div>
414 420
 			<div class="information">', $txt['package_installed_extract'], '</div>';
415
-	}
416
-	else
417
-		echo '
421
+	} else {
422
+			echo '
418 423
 			<div class="cat_bar">
419 424
 				<h3 class="catbg">', $txt['package_installed_redirecting'], '</h3>
420 425
 			</div>';
426
+	}
421 427
 
422 428
 	echo '
423 429
 		<div class="windowbg">';
@@ -428,25 +434,25 @@  discard block
 block discarded – undo
428 434
 		echo '
429 435
 			', $context['redirect_text'], '<br><br>
430 436
 			<a href="', $context['redirect_url'], '">', $txt['package_installed_redirect_go_now'], '</a> | <a href="', $scripturl, '?action=admin;area=packages;sa=browse">', $txt['package_installed_redirect_cancel'], '</a>';
431
-	}
432
-	elseif ($context['uninstalling'])
433
-		echo '
437
+	} elseif ($context['uninstalling']) {
438
+			echo '
434 439
 			', $txt['package_uninstall_done'];
435
-	elseif ($context['install_finished'])
440
+	} elseif ($context['install_finished'])
436 441
 	{
437
-		if ($context['extract_type'] == 'avatar')
438
-			echo '
442
+		if ($context['extract_type'] == 'avatar') {
443
+					echo '
439 444
 				', $txt['avatars_extracted'];
440
-		elseif ($context['extract_type'] == 'language')
441
-			echo '
445
+		} elseif ($context['extract_type'] == 'language') {
446
+					echo '
442 447
 				', $txt['language_extracted'];
443
-		else
444
-			echo '
448
+		} else {
449
+					echo '
445 450
 				', $txt['package_installed_done'];
446
-	}
447
-	else
448
-		echo '
451
+		}
452
+	} else {
453
+			echo '
449 454
 			', $txt['corrupt_compatible'];
455
+	}
450 456
 
451 457
 	echo '
452 458
 		</div>';
@@ -480,9 +486,10 @@  discard block
 block discarded – undo
480 486
 		<div class="windowbg">
481 487
 			<ol>';
482 488
 
483
-	foreach ($context['files'] as $fileinfo)
484
-		echo '
489
+	foreach ($context['files'] as $fileinfo) {
490
+			echo '
485 491
 				<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>';
492
+	}
486 493
 
487 494
 	echo '
488 495
 			</ol>
@@ -546,9 +553,10 @@  discard block
 block discarded – undo
546 553
 			</script>
547 554
 			<div id="yourVersion" style="display:none">', $context['forum_version'], '</div>';
548 555
 
549
-	if (empty($modSettings['disable_smf_js']))
550
-		echo '
556
+	if (empty($modSettings['disable_smf_js'])) {
557
+			echo '
551 558
 			<script src="', $scripturl, '?action=viewsmfile;filename=latest-news.js"></script>';
559
+	}
552 560
 
553 561
 	// This sets the announcements and current versions themselves ;).
554 562
 	echo '
@@ -587,12 +595,13 @@  discard block
 block discarded – undo
587 595
 		}
588 596
 	}
589 597
 
590
-	if (!$mods_available)
591
-		echo '
598
+	if (!$mods_available) {
599
+			echo '
592 600
 		<div class="noticebox">', $txt['no_packages'], '</div>';
593
-	else
594
-		echo '
601
+	} else {
602
+			echo '
595 603
 		<br>';
604
+	}
596 605
 
597 606
 	// the advanced (emulation) box, collapsed by default
598 607
 	echo '
@@ -681,11 +690,12 @@  discard block
 block discarded – undo
681 690
 {
682 691
 	global $context, $txt, $scripturl;
683 692
 
684
-	if (!empty($context['package_ftp']['error']))
685
-			echo '
693
+	if (!empty($context['package_ftp']['error'])) {
694
+				echo '
686 695
 					<div class="errorbox">
687 696
 						<pre>', $context['package_ftp']['error'], '</pre>
688 697
 					</div>';
698
+	}
689 699
 
690 700
 	echo '
691 701
 	<div id="admin_form_wrapper">
@@ -766,13 +776,14 @@  discard block
 block discarded – undo
766 776
 				<fieldset>
767 777
 					<legend>' . $txt['package_servers'] . '</legend>
768 778
 					<ul class="package_servers">';
769
-	foreach ($context['servers'] as $server)
770
-		echo '
779
+	foreach ($context['servers'] as $server) {
780
+			echo '
771 781
 						<li class="flow_auto">
772 782
 							<span class="floatleft">' . $server['name'] . '</span>
773 783
 							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=remove;server=' . $server['id'] . ';', $context['session_var'], '=', $context['session_id'], '">[ ' . $txt['delete'] . ' ]</a></span>
774 784
 							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $server['id'] . '">[ ' . $txt['package_browse'] . ' ]</a></span>
775 785
 						</li>';
786
+	}
776 787
 	echo '
777 788
 					</ul>
778 789
 				</fieldset>
@@ -859,11 +870,12 @@  discard block
 block discarded – undo
859 870
 		<div class="windowbg2">';
860 871
 
861 872
 	// No packages, as yet.
862
-	if (empty($context['package_list']))
863
-		echo '
873
+	if (empty($context['package_list'])) {
874
+			echo '
864 875
 			<ul>
865 876
 				<li>', $txt['no_packages'], '</li>
866 877
 			</ul>';
878
+	}
867 879
 	// List out the packages...
868 880
 	else
869 881
 	{
@@ -875,11 +887,12 @@  discard block
 block discarded – undo
875 887
 				<li>
876 888
 					<strong><span id="ps_img_', $i, '" class="toggle_up" alt="*" style="display: none;"></span> ', $packageSection['title'], '</strong>';
877 889
 
878
-			if (!empty($packageSection['text']))
879
-				echo '
890
+			if (!empty($packageSection['text'])) {
891
+							echo '
880 892
 					<div class="sub_bar">
881 893
 						<h3 class="subbg">', $packageSection['text'], '</h3>
882 894
 					</div>';
895
+			}
883 896
 
884 897
 			echo '
885 898
 					<', $context['list_type'], ' id="package_section_', $i, '" class="packages">';
@@ -889,13 +902,15 @@  discard block
 block discarded – undo
889 902
 				echo '
890 903
 						<li>';
891 904
 				// Textual message. Could be empty just for a blank line...
892
-				if ($package['is_text'])
893
-					echo '
905
+				if ($package['is_text']) {
906
+									echo '
894 907
 							', empty($package['name']) ? '&nbsp;' : $package['name'];
908
+				}
895 909
 				// This is supposed to be a rule..
896
-				elseif ($package['is_line'])
897
-					echo '
910
+				elseif ($package['is_line']) {
911
+									echo '
898 912
 						<hr>';
913
+				}
899 914
 				// A remote link.
900 915
 				elseif ($package['is_remote'])
901 916
 				{
@@ -917,21 +932,25 @@  discard block
 block discarded – undo
917 932
 						<ul id="package_section_', $i, '_pkg_', $id, '" class="package_section">';
918 933
 
919 934
 					// Show the mod type?
920
-					if ($package['type'] != '')
921
-						echo '
935
+					if ($package['type'] != '') {
936
+											echo '
922 937
 							<li class="package_section">', $txt['package_type'], ':&nbsp; ', $smcFunc['ucwords']($smcFunc['strtolower']($package['type'])), '</li>';
938
+					}
923 939
 					// Show the version number?
924
-					if ($package['version'] != '')
925
-						echo '
940
+					if ($package['version'] != '') {
941
+											echo '
926 942
 							<li class="package_section">', $txt['mod_version'], ':&nbsp; ', $package['version'], '</li>';
943
+					}
927 944
 					// How 'bout the author?
928
-					if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link']))
929
-						echo '
945
+					if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link'])) {
946
+											echo '
930 947
 							<li class="package_section">', $txt['mod_author'], ':&nbsp; ', $package['author']['link'], '</li>';
948
+					}
931 949
 					// The homepage....
932
-					if ($package['author']['website']['link'] != '')
933
-						echo '
950
+					if ($package['author']['website']['link'] != '') {
951
+											echo '
934 952
 							<li class="package_section">', $txt['author_website'], ':&nbsp; ', $package['author']['website']['link'], '</li>';
953
+					}
935 954
 
936 955
 					// Desciption: bleh bleh!
937 956
 					// Location of file: http://someplace/.
@@ -984,8 +1003,8 @@  discard block
 block discarded – undo
984 1003
 
985 1004
 				foreach ($ps['items'] as $id => $package)
986 1005
 				{
987
-					if (!$package['is_text'] && !$package['is_line'] && !$package['is_remote'])
988
-						echo '
1006
+					if (!$package['is_text'] && !$package['is_line'] && !$package['is_remote']) {
1007
+											echo '
989 1008
 				var oPackageToggle_', $section, '_pkg_', $id, ' = new smc_Toggle({
990 1009
 					bToggleEnabled: true,
991 1010
 					bCurrentlyCollapsed: true,
@@ -1000,6 +1019,7 @@  discard block
 block discarded – undo
1000 1019
 						}
1001 1020
 					]
1002 1021
 				});';
1022
+					}
1003 1023
 				}
1004 1024
 			}
1005 1025
 			echo '
@@ -1040,9 +1060,10 @@  discard block
 block discarded – undo
1040 1060
 {
1041 1061
 	global $context, $txt, $scripturl;
1042 1062
 
1043
-	if (!empty($context['saved_successful']))
1044
-		echo '
1063
+	if (!empty($context['saved_successful'])) {
1064
+			echo '
1045 1065
 	<div class="infobox">', $txt['settings_saved'], '</div>';
1066
+	}
1046 1067
 
1047 1068
 	echo '
1048 1069
 	<div id="admincenter">
@@ -1104,8 +1125,9 @@  discard block
 block discarded – undo
1104 1125
 	global $context, $txt;
1105 1126
 
1106 1127
 	// Nothing to do? Brilliant!
1107
-	if (empty($context['package_ftp']))
1108
-		return false;
1128
+	if (empty($context['package_ftp'])) {
1129
+			return false;
1130
+	}
1109 1131
 
1110 1132
 	if (empty($context['package_ftp']['form_elements_only']))
1111 1133
 	{
@@ -1114,19 +1136,21 @@  discard block
 block discarded – undo
1114 1136
 				<div id="need_writable_list" class="smalltext">
1115 1137
 					', $txt['package_ftp_why_file_list'], '
1116 1138
 					<ul style="display: inline;">';
1117
-		if (!empty($context['notwritable_files']))
1118
-			foreach ($context['notwritable_files'] as $file)
1139
+		if (!empty($context['notwritable_files'])) {
1140
+					foreach ($context['notwritable_files'] as $file)
1119 1141
 				echo '
1120 1142
 						<li>', $file, '</li>';
1143
+		}
1121 1144
 
1122 1145
 		echo '
1123 1146
 					</ul>';
1124 1147
 
1125
-		if (!$context['server']['is_windows'])
1126
-			echo '
1148
+		if (!$context['server']['is_windows']) {
1149
+					echo '
1127 1150
 				<hr>
1128 1151
 				', $txt['package_chmod_linux'], '<br />
1129 1152
 				<tt># chmod a+w ', implode(' ', $context['notwritable_files']), '</tt>';
1153
+		}
1130 1154
 
1131 1155
 		echo '
1132 1156
 				</div>';
@@ -1137,9 +1161,10 @@  discard block
 block discarded – undo
1137 1161
 					<tt id="ftp_error_message">', !empty($context['package_ftp']['error']) ? $context['package_ftp']['error'] : '', '</tt>
1138 1162
 				</div></div>';
1139 1163
 
1140
-	if (!empty($context['package_ftp']['destination']))
1141
-		echo '
1164
+	if (!empty($context['package_ftp']['destination'])) {
1165
+			echo '
1142 1166
 				<form action="', $context['package_ftp']['destination'], '" method="post" accept-charset="', $context['character_set'], '" style="margin: 0;">';
1167
+	}
1143 1168
 
1144 1169
 	echo '
1145 1170
 					<fieldset>
@@ -1172,25 +1197,28 @@  discard block
 block discarded – undo
1172 1197
 					</dl>
1173 1198
 					</fieldset>';
1174 1199
 
1175
-	if (empty($context['package_ftp']['form_elements_only']))
1176
-		echo '
1200
+	if (empty($context['package_ftp']['form_elements_only'])) {
1201
+			echo '
1177 1202
 
1178 1203
 					<div class="righttext" style="margin: 1ex;">
1179 1204
 						<span id="test_ftp_placeholder_full"></span>
1180 1205
 						<input type="submit" value="', $txt['package_proceed'], '" class="button_submit">
1181 1206
 					</div>';
1207
+	}
1182 1208
 
1183
-	if (!empty($context['package_ftp']['destination']))
1184
-		echo '
1209
+	if (!empty($context['package_ftp']['destination'])) {
1210
+			echo '
1185 1211
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1186 1212
 				</form>';
1213
+	}
1187 1214
 
1188 1215
 	// Hide the details of the list.
1189
-	if (empty($context['package_ftp']['form_elements_only']))
1190
-		echo '
1216
+	if (empty($context['package_ftp']['form_elements_only'])) {
1217
+			echo '
1191 1218
 		<script>
1192 1219
 			document.getElementById(\'need_writable_list\').style.display = \'none\';
1193 1220
 		</script>';
1221
+	}
1194 1222
 
1195 1223
 	// Quick generate the test button.
1196 1224
 	echo '
@@ -1546,9 +1574,10 @@  discard block
 block discarded – undo
1546 1574
 				<tr class="windowbg">
1547 1575
 					<td width="30%"><strong>';
1548 1576
 
1549
-				if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
1550
-					echo '
1577
+				if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive')) {
1578
+									echo '
1551 1579
 						<span class="generic_icons folder"></span>';
1580
+				}
1552 1581
 
1553 1582
 				echo '
1554 1583
 						', $name, '
@@ -1565,8 +1594,9 @@  discard block
 block discarded – undo
1565 1594
 				</tr>
1566 1595
 			';
1567 1596
 
1568
-		if (!empty($dir['contents']))
1569
-			template_permission_show_contents($name, $dir['contents'], 1);
1597
+		if (!empty($dir['contents'])) {
1598
+					template_permission_show_contents($name, $dir['contents'], 1);
1599
+		}
1570 1600
 	}
1571 1601
 
1572 1602
 	echo '
@@ -1602,13 +1632,14 @@  discard block
 block discarded – undo
1602 1632
 			</fieldset>';
1603 1633
 
1604 1634
 	// Likely to need FTP?
1605
-	if (empty($context['ftp_connected']))
1606
-		echo '
1635
+	if (empty($context['ftp_connected'])) {
1636
+			echo '
1607 1637
 			<p>
1608 1638
 				', $txt['package_file_perms_ftp_details'], ':
1609 1639
 			</p>
1610 1640
 			', template_control_chmod(), '
1611 1641
 			<div class="noticebox">', $txt['package_file_perms_ftp_retain'], '</div>';
1642
+	}
1612 1643
 
1613 1644
 	echo '
1614 1645
 			<span id="test_ftp_placeholder_full"></span>
@@ -1617,9 +1648,10 @@  discard block
 block discarded – undo
1617 1648
 		</div>';
1618 1649
 
1619 1650
 	// Any looks fors we've already done?
1620
-	foreach ($context['look_for'] as $path)
1621
-		echo '
1651
+	foreach ($context['look_for'] as $path) {
1652
+			echo '
1622 1653
 			<input type="hidden" name="back_look[]" value="', $path, '">';
1654
+	}
1623 1655
 	echo '
1624 1656
 	</form><br>';
1625 1657
 }
@@ -1658,9 +1690,10 @@  discard block
 block discarded – undo
1658 1690
 				<td class="smalltext" width="30%">' . str_repeat('&nbsp;', $level * 5), '
1659 1691
 					', (!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, "'\\") . '\');">' : '';
1660 1692
 
1661
-			if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
1662
-				echo '
1693
+			if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive')) {
1694
+							echo '
1663 1695
 						<span class="generic_icons folder"></span>';
1696
+			}
1664 1697
 
1665 1698
 			echo '
1666 1699
 					', $name, '
@@ -1686,14 +1719,15 @@  discard block
 block discarded – undo
1686 1719
 	}
1687 1720
 
1688 1721
 	// We have more files to show?
1689
-	if ($has_more)
1690
-		echo '
1722
+	if ($has_more) {
1723
+			echo '
1691 1724
 	<tr class="windowbg" id="content_', $js_ident, '_more">
1692 1725
 		<td class="smalltext" width="40%">' . str_repeat('&nbsp;', $level * 5), '
1693 1726
 			&#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;
1694 1727
 		</td>
1695 1728
 		<td colspan="6"></td>
1696 1729
 	</tr>';
1730
+	}
1697 1731
 
1698 1732
 	if ($drawn_div)
1699 1733
 	{
@@ -1701,15 +1735,17 @@  discard block
 block discarded – undo
1701 1735
 		$isFound = false;
1702 1736
 		foreach ($context['look_for'] as $tree)
1703 1737
 		{
1704
-			if (substr($tree, 0, strlen($ident)) == $ident)
1705
-				$isFound = true;
1738
+			if (substr($tree, 0, strlen($ident)) == $ident) {
1739
+							$isFound = true;
1740
+			}
1706 1741
 		}
1707 1742
 
1708
-		if ($level > 1 && !$isFound)
1709
-			echo '
1743
+		if ($level > 1 && !$isFound) {
1744
+					echo '
1710 1745
 		<script>
1711 1746
 			expandFolder(\'', $js_ident, '\', \'\');
1712 1747
 		</script>';
1748
+		}
1713 1749
 	}
1714 1750
 }
1715 1751
 
@@ -1729,11 +1765,12 @@  discard block
 block discarded – undo
1729 1765
 				<h3 class="catbg">', $txt['package_file_perms_applying'], '</h3>
1730 1766
 			</div>';
1731 1767
 
1732
-	if (!empty($context['skip_ftp']))
1733
-		echo '
1768
+	if (!empty($context['skip_ftp'])) {
1769
+			echo '
1734 1770
 			<div class="errorbox">
1735 1771
 				', $txt['package_file_perms_skipping_ftp'], '
1736 1772
 			</div>';
1773
+	}
1737 1774
 
1738 1775
 	// How many have we done?
1739 1776
 	$remaining_items = count($context['method'] == 'individual' ? $context['to_process'] : $context['directory_list']);
@@ -1771,28 +1808,31 @@  discard block
 block discarded – undo
1771 1808
 				<br>';
1772 1809
 
1773 1810
 	// Put out the right hidden data.
1774
-	if ($context['method'] == 'individual')
1775
-		echo '
1811
+	if ($context['method'] == 'individual') {
1812
+			echo '
1776 1813
 				<input type="hidden" name="custom_value" value="', $context['custom_value'], '">
1777 1814
 				<input type="hidden" name="totalItems" value="', $context['total_items'], '">
1778 1815
 				<input type="hidden" name="toProcess" value="', $context['to_process_encode'], '">';
1779
-	else
1780
-		echo '
1816
+	} else {
1817
+			echo '
1781 1818
 				<input type="hidden" name="predefined" value="', $context['predefined_type'], '">
1782 1819
 				<input type="hidden" name="fileOffset" value="', $context['file_offset'], '">
1783 1820
 				<input type="hidden" name="totalItems" value="', $context['total_items'], '">
1784 1821
 				<input type="hidden" name="dirList" value="', $context['directory_list_encode'], '">
1785 1822
 				<input type="hidden" name="specialFiles" value="', $context['special_files_encode'], '">';
1823
+	}
1786 1824
 
1787 1825
 	// Are we not using FTP for whatever reason.
1788
-	if (!empty($context['skip_ftp']))
1789
-		echo '
1826
+	if (!empty($context['skip_ftp'])) {
1827
+			echo '
1790 1828
 				<input type="hidden" name="skip_ftp" value="1">';
1829
+	}
1791 1830
 
1792 1831
 	// Retain state.
1793
-	foreach ($context['back_look_data'] as $path)
1794
-		echo '
1832
+	foreach ($context['back_look_data'] as $path) {
1833
+			echo '
1795 1834
 				<input type="hidden" name="back_look[]" value="', $path, '">';
1835
+	}
1796 1836
 
1797 1837
 	echo '
1798 1838
 				<input type="hidden" name="method" value="', $context['method'], '">
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1321 added lines, -983 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
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($type == 'int' && ($val === '+' || $val === '-'))
@@ -390,8 +399,9 @@  discard block
 block discarded – undo
390 399
 		{
391 400
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
392 401
 			{
393
-				if ($match[1] != '+ ')
394
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
402
+				if ($match[1] != '+ ') {
403
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
404
+				}
395 405
 				$type = 'raw';
396 406
 			}
397 407
 		}
@@ -412,8 +422,9 @@  discard block
 block discarded – undo
412 422
 	// Clear any caching?
413 423
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
414 424
 	{
415
-		if (!is_array($members))
416
-			$members = array($members);
425
+		if (!is_array($members)) {
426
+					$members = array($members);
427
+		}
417 428
 
418 429
 		foreach ($members as $member)
419 430
 		{
@@ -446,29 +457,32 @@  discard block
 block discarded – undo
446 457
 {
447 458
 	global $modSettings, $smcFunc;
448 459
 
449
-	if (empty($changeArray) || !is_array($changeArray))
450
-		return;
460
+	if (empty($changeArray) || !is_array($changeArray)) {
461
+			return;
462
+	}
451 463
 
452 464
 	$toRemove = array();
453 465
 
454 466
 	// Go check if there is any setting to be removed.
455
-	foreach ($changeArray as $k => $v)
456
-		if ($v === null)
467
+	foreach ($changeArray as $k => $v) {
468
+			if ($v === null)
457 469
 		{
458 470
 			// Found some, remove them from the original array and add them to ours.
459 471
 			unset($changeArray[$k]);
472
+	}
460 473
 			$toRemove[] = $k;
461 474
 		}
462 475
 
463 476
 	// Proceed with the deletion.
464
-	if (!empty($toRemove))
465
-		$smcFunc['db_query']('', '
477
+	if (!empty($toRemove)) {
478
+			$smcFunc['db_query']('', '
466 479
 			DELETE FROM {db_prefix}settings
467 480
 			WHERE variable IN ({array_string:remove})',
468 481
 			array(
469 482
 				'remove' => $toRemove,
470 483
 			)
471 484
 		);
485
+	}
472 486
 
473 487
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
474 488
 	if ($update)
@@ -497,19 +511,22 @@  discard block
 block discarded – undo
497 511
 	foreach ($changeArray as $variable => $value)
498 512
 	{
499 513
 		// Don't bother if it's already like that ;).
500
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
501
-			continue;
514
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
515
+					continue;
516
+		}
502 517
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
503
-		elseif (!isset($modSettings[$variable]) && empty($value))
504
-			continue;
518
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
519
+					continue;
520
+		}
505 521
 
506 522
 		$replaceArray[] = array($variable, $value);
507 523
 
508 524
 		$modSettings[$variable] = $value;
509 525
 	}
510 526
 
511
-	if (empty($replaceArray))
512
-		return;
527
+	if (empty($replaceArray)) {
528
+			return;
529
+	}
513 530
 
514 531
 	$smcFunc['db_insert']('replace',
515 532
 		'{db_prefix}settings',
@@ -555,20 +572,25 @@  discard block
 block discarded – undo
555 572
 	$start = (int) $start;
556 573
 	$start_invalid = $start < 0;
557 574
 	
558
-	if (!empty($options['low_id']))
559
-		$low_id = $options['low_id'];
560
-	if (!empty($options['max_id']))
561
-		$max_id = $options['max_id'];
575
+	if (!empty($options['low_id'])) {
576
+			$low_id = $options['low_id'];
577
+	}
578
+	if (!empty($options['max_id'])) {
579
+			$max_id = $options['max_id'];
580
+	}
562 581
 
563 582
 	// Make sure $start is a proper variable - not less than 0.
564
-	if ($start_invalid)
565
-		$start = 0;
583
+	if ($start_invalid) {
584
+			$start = 0;
585
+	}
566 586
 	// Not greater than the upper bound.
567
-	elseif ($start >= $max_value)
568
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
587
+	elseif ($start >= $max_value) {
588
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
589
+	}
569 590
 	// And it has to be a multiple of $num_per_page!
570
-	else
571
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
591
+	else {
592
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
593
+	}
572 594
 
573 595
 	$context['current_page'] = $start / $num_per_page;
574 596
 
@@ -596,101 +618,115 @@  discard block
 block discarded – undo
596 618
 	if (empty($modSettings['compactTopicPagesEnable']))
597 619
 	{
598 620
 		// Show the left arrow.
599
-		if (empty($low_id))
600
-			$pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
601
-		else
602
-			$pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L'.$low_id);
621
+		if (empty($low_id)) {
622
+					$pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
623
+		} else {
624
+					$pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L'.$low_id);
625
+		}
603 626
 		
604 627
 		// Show all the pages.
605 628
 		$display_page = 1;
606
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
607
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
629
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
630
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
631
+		}
608 632
 
609 633
 		// Show the right arrow.
610 634
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
611 635
 		if ($start != $counter - $max_value && !$start_invalid){
612
-			if (empty($max_id))
613
-				$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
614
-			else
615
-				$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page , $settings['page_index']['next_page'], 'M'.$max_id);
636
+			if (empty($max_id)) {
637
+							$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
638
+			} else {
639
+							$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page , $settings['page_index']['next_page'], 'M'.$max_id);
640
+			}
616 641
 		}
617 642
 			
618
-	}
619
-	else
643
+	} else
620 644
 	{
621 645
 		// If they didn't enter an odd value, pretend they did.
622 646
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
623 647
 
624 648
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
625
-		if (!empty($start) && $show_prevnext)
626
-			if (empty($low_id))
649
+		if (!empty($start) && $show_prevnext) {
650
+					if (empty($low_id))
627 651
 				$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
628
-			else
629
-				$pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L'.$low_id);
630
-		else
631
-			$pageindex .= '';
652
+		} else {
653
+							$pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L'.$low_id);
654
+			}
655
+		else {
656
+					$pageindex .= '';
657
+		}
632 658
 
633 659
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
634
-		if ($start > $num_per_page * $PageContiguous)
635
-			$pageindex .= sprintf($base_link, 0, '1');
660
+		if ($start > $num_per_page * $PageContiguous) {
661
+					$pageindex .= sprintf($base_link, 0, '1');
662
+		}
636 663
 
637 664
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
638
-		if ($start > $num_per_page * ($PageContiguous + 1))
639
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
665
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
666
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
640 667
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
641 668
 				'{FIRST_PAGE}' => $num_per_page,
642 669
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
643 670
 				'{PER_PAGE}' => $num_per_page,
644 671
 			));
672
+		}
645 673
 
646 674
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
647
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
648
-			if ($start >= $num_per_page * $nCont)
675
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
676
+					if ($start >= $num_per_page * $nCont)
649 677
 			{
650 678
 				$tmpStart = $start - $num_per_page * $nCont;
651
-				if($nCont != 1 || empty($low_id))
652
-					$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
653
-				else
654
-					$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L'.$low_id);
679
+		}
680
+				if($nCont != 1 || empty($low_id)) {
681
+									$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
682
+				} else {
683
+									$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L'.$low_id);
684
+				}
655 685
 			}
656 686
 
657 687
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
658
-		if (!$start_invalid)
659
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
660
-		else
661
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
688
+		if (!$start_invalid) {
689
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
690
+		} else {
691
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
692
+		}
662 693
 
663 694
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
664 695
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
665
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
666
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
696
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
697
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
667 698
 			{
668 699
 				$tmpStart = $start + $num_per_page * $nCont;
669
-				if($nCont != 1 || empty($max_id))
670
-					$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
671
-				else
672
-					$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M'.$max_id);
700
+		}
701
+				if($nCont != 1 || empty($max_id)) {
702
+									$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
703
+				} else {
704
+									$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M'.$max_id);
705
+				}
673 706
 			}
674 707
 
675 708
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
676
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
677
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
709
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
710
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678 711
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
679 712
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
680 713
 				'{LAST_PAGE}' => $tmpMaxPages,
681 714
 				'{PER_PAGE}' => $num_per_page,
682 715
 			));
716
+		}
683 717
 
684 718
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
685
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
686
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
719
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
720
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
721
+		}
687 722
 
688 723
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
689
-		if ($start != $tmpMaxPages && $show_prevnext)
690
-			if (empty($max_id))
724
+		if ($start != $tmpMaxPages && $show_prevnext) {
725
+					if (empty($max_id))
691 726
 				$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
692
-			else
693
-				$pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M'.$max_id);
727
+		} else {
728
+							$pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M'.$max_id);
729
+			}
694 730
 	}
695 731
 	$pageindex .= $settings['page_index']['extra_after'];
696 732
 
@@ -716,8 +752,9 @@  discard block
 block discarded – undo
716 752
 	if ($decimal_separator === null)
717 753
 	{
718 754
 		// Not set for whatever reason?
719
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
720
-			return $number;
755
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
756
+					return $number;
757
+		}
721 758
 
722 759
 		// Cache these each load...
723 760
 		$thousands_separator = $matches[1];
@@ -751,17 +788,20 @@  discard block
 block discarded – undo
751 788
 	static $local_cache;
752 789
 
753 790
 	// Offset the time.
754
-	if (!$offset_type)
755
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
791
+	if (!$offset_type) {
792
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
793
+	}
756 794
 	// Just the forum offset?
757
-	elseif ($offset_type == 'forum')
758
-		$time = $log_time + $modSettings['time_offset'] * 3600;
759
-	else
760
-		$time = $log_time;
795
+	elseif ($offset_type == 'forum') {
796
+			$time = $log_time + $modSettings['time_offset'] * 3600;
797
+	} else {
798
+			$time = $log_time;
799
+	}
761 800
 
762 801
 	// We can't have a negative date (on Windows, at least.)
763
-	if ($log_time < 0)
764
-		$log_time = 0;
802
+	if ($log_time < 0) {
803
+			$log_time = 0;
804
+	}
765 805
 
766 806
 	// Today and Yesterday?
767 807
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -778,56 +818,65 @@  discard block
 block discarded – undo
778 818
 		{
779 819
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
780 820
 			$today_fmt = $h . ':%M' . $s . ' %p';
821
+		} else {
822
+					$today_fmt = '%H:%M' . $s;
781 823
 		}
782
-		else
783
-			$today_fmt = '%H:%M' . $s;
784 824
 
785 825
 		// Same day of the year, same year.... Today!
786
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
787
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
826
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
827
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
828
+		}
788 829
 
789 830
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
790
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
791
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
831
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
832
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
833
+		}
792 834
 	}
793 835
 
794 836
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
795 837
 
796
-	if (!isset($local_cache))
797
-		$local_cache = setlocale(LC_TIME, $txt['lang_locale']);
838
+	if (!isset($local_cache)) {
839
+			$local_cache = setlocale(LC_TIME, $txt['lang_locale']);
840
+	}
798 841
 
799 842
 	if ($local_cache !== false)
800 843
 	{
801 844
 		//check if other process change the local
802 845
 		if ($process_safe === true)
803 846
 		{
804
-			if (setlocale(LC_TIME, '0') != $local_cache)
805
-				setlocale(LC_TIME, $txt['lang_locale']);
847
+			if (setlocale(LC_TIME, '0') != $local_cache) {
848
+							setlocale(LC_TIME, $txt['lang_locale']);
849
+			}
806 850
 		}
807 851
 
808
-		if (!isset($non_twelve_hour))
809
-			$non_twelve_hour = trim(strftime('%p')) === '';
810
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
811
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
852
+		if (!isset($non_twelve_hour)) {
853
+					$non_twelve_hour = trim(strftime('%p')) === '';
854
+		}
855
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
856
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
857
+		}
812 858
 
813
-		foreach (array('%a', '%A', '%b', '%B') as $token)
814
-			if (strpos($str, $token) !== false)
859
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
860
+					if (strpos($str, $token) !== false)
815 861
 				$str = str_replace($token, strftime($token, $time), $str);
816
-	}
817
-	else
862
+		}
863
+	} else
818 864
 	{
819 865
 		// Do-it-yourself time localization.  Fun.
820
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
821
-			if (strpos($str, $token) !== false)
866
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
867
+					if (strpos($str, $token) !== false)
822 868
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
869
+		}
823 870
 
824
-		if (strpos($str, '%p') !== false)
825
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
871
+		if (strpos($str, '%p') !== false) {
872
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
873
+		}
826 874
 	}
827 875
 
828 876
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
829
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
830
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
877
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
878
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
879
+	}
831 880
 
832 881
 	// Format any other characters..
833 882
 	return strftime($str, $time);
@@ -849,16 +898,19 @@  discard block
 block discarded – undo
849 898
 	static $translation = array();
850 899
 
851 900
 	// Determine the character set... Default to UTF-8
852
-	if (empty($context['character_set']))
853
-		$charset = 'UTF-8';
901
+	if (empty($context['character_set'])) {
902
+			$charset = 'UTF-8';
903
+	}
854 904
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
855
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
856
-		$charset = 'ISO-8859-1';
857
-	else
858
-		$charset = $context['character_set'];
905
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
906
+			$charset = 'ISO-8859-1';
907
+	} else {
908
+			$charset = $context['character_set'];
909
+	}
859 910
 
860
-	if (empty($translation))
861
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
911
+	if (empty($translation)) {
912
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
913
+	}
862 914
 
863 915
 	return strtr($string, $translation);
864 916
 }
@@ -880,8 +932,9 @@  discard block
 block discarded – undo
880 932
 	global $smcFunc;
881 933
 
882 934
 	// It was already short enough!
883
-	if ($smcFunc['strlen']($subject) <= $len)
884
-		return $subject;
935
+	if ($smcFunc['strlen']($subject) <= $len) {
936
+			return $subject;
937
+	}
885 938
 
886 939
 	// Shorten it by the length it was too long, and strip off junk from the end.
887 940
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -900,10 +953,11 @@  discard block
 block discarded – undo
900 953
 {
901 954
 	global $user_info, $modSettings;
902 955
 
903
-	if ($timestamp === null)
904
-		$timestamp = time();
905
-	elseif ($timestamp == 0)
906
-		return 0;
956
+	if ($timestamp === null) {
957
+			$timestamp = time();
958
+	} elseif ($timestamp == 0) {
959
+			return 0;
960
+	}
907 961
 
908 962
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
909 963
 }
@@ -932,8 +986,9 @@  discard block
 block discarded – undo
932 986
 		$array[$i] = $array[$j];
933 987
 		$array[$j] = $temp;
934 988
 
935
-		for ($i = 1; $p[$i] == 0; $i++)
936
-			$p[$i] = 1;
989
+		for ($i = 1; $p[$i] == 0; $i++) {
990
+					$p[$i] = 1;
991
+		}
937 992
 
938 993
 		$orders[] = $array;
939 994
 	}
@@ -965,12 +1020,14 @@  discard block
 block discarded – undo
965 1020
 	static $disabled;
966 1021
 
967 1022
 	// Don't waste cycles
968
-	if ($message === '')
969
-		return '';
1023
+	if ($message === '') {
1024
+			return '';
1025
+	}
970 1026
 
971 1027
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
972
-	if (!isset($context['utf8']))
973
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1028
+	if (!isset($context['utf8'])) {
1029
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1030
+	}
974 1031
 
975 1032
 	// Clean up any cut/paste issues we may have
976 1033
 	$message = sanitizeMSCutPaste($message);
@@ -982,13 +1039,15 @@  discard block
 block discarded – undo
982 1039
 		return $message;
983 1040
 	}
984 1041
 
985
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
986
-		$smileys = (bool) $smileys;
1042
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1043
+			$smileys = (bool) $smileys;
1044
+	}
987 1045
 
988 1046
 	if (empty($modSettings['enableBBC']) && $message !== false)
989 1047
 	{
990
-		if ($smileys === true)
991
-			parsesmileys($message);
1048
+		if ($smileys === true) {
1049
+					parsesmileys($message);
1050
+		}
992 1051
 
993 1052
 		return $message;
994 1053
 	}
@@ -1001,8 +1060,9 @@  discard block
 block discarded – undo
1001 1060
 	}
1002 1061
 
1003 1062
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1004
-	if (!empty($modSettings['autoLinkUrls']))
1005
-		set_tld_regex();
1063
+	if (!empty($modSettings['autoLinkUrls'])) {
1064
+			set_tld_regex();
1065
+	}
1006 1066
 
1007 1067
 	// Allow mods access before entering the main parse_bbc loop
1008 1068
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1016,12 +1076,14 @@  discard block
 block discarded – undo
1016 1076
 
1017 1077
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1018 1078
 
1019
-			foreach ($temp as $tag)
1020
-				$disabled[trim($tag)] = true;
1079
+			foreach ($temp as $tag) {
1080
+							$disabled[trim($tag)] = true;
1081
+			}
1021 1082
 		}
1022 1083
 
1023
-		if (empty($modSettings['enableEmbeddedFlash']))
1024
-			$disabled['flash'] = true;
1084
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1085
+					$disabled['flash'] = true;
1086
+		}
1025 1087
 
1026 1088
 		/* The following bbc are formatted as an array, with keys as follows:
1027 1089
 
@@ -1142,8 +1204,9 @@  discard block
 block discarded – undo
1142 1204
 					$returnContext = '';
1143 1205
 
1144 1206
 					// BBC or the entire attachments feature is disabled
1145
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1146
-						return $data;
1207
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1208
+											return $data;
1209
+					}
1147 1210
 
1148 1211
 					// Save the attach ID.
1149 1212
 					$attachID = $data;
@@ -1154,8 +1217,9 @@  discard block
 block discarded – undo
1154 1217
 					$currentAttachment = parseAttachBBC($attachID);
1155 1218
 
1156 1219
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1157
-					if (is_string($currentAttachment))
1158
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1220
+					if (is_string($currentAttachment)) {
1221
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1222
+					}
1159 1223
 
1160 1224
 					if (!empty($currentAttachment['is_image']))
1161 1225
 					{
@@ -1171,15 +1235,17 @@  discard block
 block discarded – undo
1171 1235
 							$height = ' height="' . $currentAttachment['height'] . '"';
1172 1236
 						}
1173 1237
 
1174
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1175
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1176
-						else
1177
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1238
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1239
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1240
+						} else {
1241
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1242
+						}
1178 1243
 					}
1179 1244
 
1180 1245
 					// No image. Show a link.
1181
-					else
1182
-						$returnContext .= $currentAttachment['link'];
1246
+					else {
1247
+											$returnContext .= $currentAttachment['link'];
1248
+					}
1183 1249
 
1184 1250
 					// Gotta append what we just did.
1185 1251
 					$data = $returnContext;
@@ -1210,8 +1276,9 @@  discard block
 block discarded – undo
1210 1276
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1211 1277
 						{
1212 1278
 							// Do PHP code coloring?
1213
-							if ($php_parts[$php_i] != '&lt;?php')
1214
-								continue;
1279
+							if ($php_parts[$php_i] != '&lt;?php') {
1280
+															continue;
1281
+							}
1215 1282
 
1216 1283
 							$php_string = '';
1217 1284
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1227,8 +1294,9 @@  discard block
 block discarded – undo
1227 1294
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1228 1295
 
1229 1296
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1230
-						if ($context['browser']['is_opera'])
1231
-							$data .= '&nbsp;';
1297
+						if ($context['browser']['is_opera']) {
1298
+													$data .= '&nbsp;';
1299
+						}
1232 1300
 					}
1233 1301
 				},
1234 1302
 				'block_level' => true,
@@ -1247,8 +1315,9 @@  discard block
 block discarded – undo
1247 1315
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1248 1316
 						{
1249 1317
 							// Do PHP code coloring?
1250
-							if ($php_parts[$php_i] != '&lt;?php')
1251
-								continue;
1318
+							if ($php_parts[$php_i] != '&lt;?php') {
1319
+															continue;
1320
+							}
1252 1321
 
1253 1322
 							$php_string = '';
1254 1323
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1264,8 +1333,9 @@  discard block
 block discarded – undo
1264 1333
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1265 1334
 
1266 1335
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1267
-						if ($context['browser']['is_opera'])
1268
-							$data[0] .= '&nbsp;';
1336
+						if ($context['browser']['is_opera']) {
1337
+													$data[0] .= '&nbsp;';
1338
+						}
1269 1339
 					}
1270 1340
 				},
1271 1341
 				'block_level' => true,
@@ -1303,11 +1373,13 @@  discard block
 block discarded – undo
1303 1373
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1304 1374
 				'validate' => function (&$tag, &$data, $disabled)
1305 1375
 				{
1306
-					if (isset($disabled['url']))
1307
-						$tag['content'] = '$1';
1376
+					if (isset($disabled['url'])) {
1377
+											$tag['content'] = '$1';
1378
+					}
1308 1379
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1309
-					if (empty($scheme))
1310
-						$data[0] = '//' . ltrim($data[0], ':/');
1380
+					if (empty($scheme)) {
1381
+											$data[0] = '//' . ltrim($data[0], ':/');
1382
+					}
1311 1383
 				},
1312 1384
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1313 1385
 			),
@@ -1321,10 +1393,11 @@  discard block
 block discarded – undo
1321 1393
 				{
1322 1394
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1323 1395
 
1324
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1325
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1326
-					else
1327
-						$css = '';
1396
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1397
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1398
+					} else {
1399
+											$css = '';
1400
+					}
1328 1401
 
1329 1402
 					$data = $class . $css;
1330 1403
 				},
@@ -1374,14 +1447,16 @@  discard block
 block discarded – undo
1374 1447
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1375 1448
 					if ($image_proxy_enabled)
1376 1449
 					{
1377
-						if (empty($scheme))
1378
-							$data = 'http://' . ltrim($data, ':/');
1450
+						if (empty($scheme)) {
1451
+													$data = 'http://' . ltrim($data, ':/');
1452
+						}
1379 1453
 
1380
-						if ($scheme != 'https')
1381
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1454
+						if ($scheme != 'https') {
1455
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1456
+						}
1457
+					} elseif (empty($scheme)) {
1458
+											$data = '//' . ltrim($data, ':/');
1382 1459
 					}
1383
-					elseif (empty($scheme))
1384
-						$data = '//' . ltrim($data, ':/');
1385 1460
 				},
1386 1461
 				'disabled_content' => '($1)',
1387 1462
 			),
@@ -1397,14 +1472,16 @@  discard block
 block discarded – undo
1397 1472
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1398 1473
 					if ($image_proxy_enabled)
1399 1474
 					{
1400
-						if (empty($scheme))
1401
-							$data = 'http://' . ltrim($data, ':/');
1475
+						if (empty($scheme)) {
1476
+													$data = 'http://' . ltrim($data, ':/');
1477
+						}
1402 1478
 
1403
-						if ($scheme != 'https')
1404
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1479
+						if ($scheme != 'https') {
1480
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1481
+						}
1482
+					} elseif (empty($scheme)) {
1483
+											$data = '//' . ltrim($data, ':/');
1405 1484
 					}
1406
-					elseif (empty($scheme))
1407
-						$data = '//' . ltrim($data, ':/');
1408 1485
 				},
1409 1486
 				'disabled_content' => '($1)',
1410 1487
 			),
@@ -1416,8 +1493,9 @@  discard block
 block discarded – undo
1416 1493
 				{
1417 1494
 					$data = strtr($data, array('<br>' => ''));
1418 1495
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1419
-					if (empty($scheme))
1420
-						$data = '//' . ltrim($data, ':/');
1496
+					if (empty($scheme)) {
1497
+											$data = '//' . ltrim($data, ':/');
1498
+					}
1421 1499
 				},
1422 1500
 			),
1423 1501
 			array(
@@ -1428,13 +1506,14 @@  discard block
 block discarded – undo
1428 1506
 				'after' => '</a>',
1429 1507
 				'validate' => function (&$tag, &$data, $disabled)
1430 1508
 				{
1431
-					if (substr($data, 0, 1) == '#')
1432
-						$data = '#post_' . substr($data, 1);
1433
-					else
1509
+					if (substr($data, 0, 1) == '#') {
1510
+											$data = '#post_' . substr($data, 1);
1511
+					} else
1434 1512
 					{
1435 1513
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1436
-						if (empty($scheme))
1437
-							$data = '//' . ltrim($data, ':/');
1514
+						if (empty($scheme)) {
1515
+													$data = '//' . ltrim($data, ':/');
1516
+						}
1438 1517
 					}
1439 1518
 				},
1440 1519
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1512,8 +1591,9 @@  discard block
 block discarded – undo
1512 1591
 					{
1513 1592
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1514 1593
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1515
-						if ($add_begin)
1516
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1594
+						if ($add_begin) {
1595
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1596
+						}
1517 1597
 					}
1518 1598
 				},
1519 1599
 				'block_level' => false,
@@ -1644,10 +1724,11 @@  discard block
 block discarded – undo
1644 1724
 				'content' => '$1',
1645 1725
 				'validate' => function (&$tag, &$data, $disabled)
1646 1726
 				{
1647
-					if (is_numeric($data))
1648
-						$data = timeformat($data);
1649
-					else
1650
-						$tag['content'] = '[time]$1[/time]';
1727
+					if (is_numeric($data)) {
1728
+											$data = timeformat($data);
1729
+					} else {
1730
+											$tag['content'] = '[time]$1[/time]';
1731
+					}
1651 1732
 				},
1652 1733
 			),
1653 1734
 			array(
@@ -1674,8 +1755,9 @@  discard block
 block discarded – undo
1674 1755
 				{
1675 1756
 					$data = strtr($data, array('<br>' => ''));
1676 1757
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1677
-					if (empty($scheme))
1678
-						$data = '//' . ltrim($data, ':/');
1758
+					if (empty($scheme)) {
1759
+											$data = '//' . ltrim($data, ':/');
1760
+					}
1679 1761
 				},
1680 1762
 			),
1681 1763
 			array(
@@ -1687,8 +1769,9 @@  discard block
 block discarded – undo
1687 1769
 				'validate' => function (&$tag, &$data, $disabled)
1688 1770
 				{
1689 1771
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1690
-					if (empty($scheme))
1691
-						$data = '//' . ltrim($data, ':/');
1772
+					if (empty($scheme)) {
1773
+											$data = '//' . ltrim($data, ':/');
1774
+					}
1692 1775
 				},
1693 1776
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1694 1777
 				'disabled_after' => ' ($1)',
@@ -1708,8 +1791,9 @@  discard block
 block discarded – undo
1708 1791
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1709 1792
 		if ($message === false)
1710 1793
 		{
1711
-			if (isset($temp_bbc))
1712
-				$bbc_codes = $temp_bbc;
1794
+			if (isset($temp_bbc)) {
1795
+							$bbc_codes = $temp_bbc;
1796
+			}
1713 1797
 			usort($codes, function ($a, $b) {
1714 1798
 				return strcmp($a['tag'], $b['tag']);
1715 1799
 			});
@@ -1729,8 +1813,9 @@  discard block
 block discarded – undo
1729 1813
 		);
1730 1814
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1731 1815
 		{
1732
-			foreach ($itemcodes as $c => $dummy)
1733
-				$bbc_codes[$c] = array();
1816
+			foreach ($itemcodes as $c => $dummy) {
1817
+							$bbc_codes[$c] = array();
1818
+			}
1734 1819
 		}
1735 1820
 
1736 1821
 		// Shhhh!
@@ -1751,12 +1836,14 @@  discard block
 block discarded – undo
1751 1836
 		foreach ($codes as $code)
1752 1837
 		{
1753 1838
 			// Make it easier to process parameters later
1754
-			if (!empty($code['parameters']))
1755
-				ksort($code['parameters'], SORT_STRING);
1839
+			if (!empty($code['parameters'])) {
1840
+							ksort($code['parameters'], SORT_STRING);
1841
+			}
1756 1842
 
1757 1843
 			// If we are not doing every tag only do ones we are interested in.
1758
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1759
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1844
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1845
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1846
+			}
1760 1847
 		}
1761 1848
 		$codes = null;
1762 1849
 	}
@@ -1767,8 +1854,9 @@  discard block
 block discarded – undo
1767 1854
 		// It's likely this will change if the message is modified.
1768 1855
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1769 1856
 
1770
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1771
-			return $temp;
1857
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1858
+					return $temp;
1859
+		}
1772 1860
 
1773 1861
 		$cache_t = microtime();
1774 1862
 	}
@@ -1800,8 +1888,9 @@  discard block
 block discarded – undo
1800 1888
 		$disabled['flash'] = true;
1801 1889
 
1802 1890
 		// @todo Change maybe?
1803
-		if (!isset($_GET['images']))
1804
-			$disabled['img'] = true;
1891
+		if (!isset($_GET['images'])) {
1892
+					$disabled['img'] = true;
1893
+		}
1805 1894
 
1806 1895
 		// @todo Interface/setting to add more?
1807 1896
 	}
@@ -1825,8 +1914,9 @@  discard block
 block discarded – undo
1825 1914
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1826 1915
 
1827 1916
 		// Failsafe.
1828
-		if ($pos === false || $last_pos > $pos)
1829
-			$pos = strlen($message) + 1;
1917
+		if ($pos === false || $last_pos > $pos) {
1918
+					$pos = strlen($message) + 1;
1919
+		}
1830 1920
 
1831 1921
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1832 1922
 		if ($last_pos < $pos - 1)
@@ -1845,8 +1935,9 @@  discard block
 block discarded – undo
1845 1935
 
1846 1936
 				// <br> should be empty.
1847 1937
 				$empty_tags = array('br', 'hr');
1848
-				foreach ($empty_tags as $tag)
1849
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1938
+				foreach ($empty_tags as $tag) {
1939
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1940
+				}
1850 1941
 
1851 1942
 				// b, u, i, s, pre... basic tags.
1852 1943
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1855,8 +1946,9 @@  discard block
 block discarded – undo
1855 1946
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1856 1947
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1857 1948
 
1858
-					if ($diff > 0)
1859
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1949
+					if ($diff > 0) {
1950
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1951
+					}
1860 1952
 				}
1861 1953
 
1862 1954
 				// Do <img ...> - with security... action= -> action-.
@@ -1869,8 +1961,9 @@  discard block
 block discarded – undo
1869 1961
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1870 1962
 
1871 1963
 						// Remove action= from the URL - no funny business, now.
1872
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1873
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1964
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1965
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1966
+						}
1874 1967
 
1875 1968
 						// Check if the image is larger than allowed.
1876 1969
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1891,9 +1984,9 @@  discard block
 block discarded – undo
1891 1984
 
1892 1985
 							// Set the new image tag.
1893 1986
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1987
+						} else {
1988
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1894 1989
 						}
1895
-						else
1896
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1897 1990
 					}
1898 1991
 
1899 1992
 					$data = strtr($data, $replaces);
@@ -1906,16 +1999,18 @@  discard block
 block discarded – undo
1906 1999
 				$no_autolink_area = false;
1907 2000
 				if (!empty($open_tags))
1908 2001
 				{
1909
-					foreach ($open_tags as $open_tag)
1910
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2002
+					foreach ($open_tags as $open_tag) {
2003
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1911 2004
 							$no_autolink_area = true;
2005
+					}
1912 2006
 				}
1913 2007
 
1914 2008
 				// Don't go backwards.
1915 2009
 				// @todo Don't think is the real solution....
1916 2010
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1917
-				if ($pos < $lastAutoPos)
1918
-					$no_autolink_area = true;
2011
+				if ($pos < $lastAutoPos) {
2012
+									$no_autolink_area = true;
2013
+				}
1919 2014
 				$lastAutoPos = $pos;
1920 2015
 
1921 2016
 				if (!$no_autolink_area)
@@ -2024,17 +2119,19 @@  discard block
 block discarded – undo
2024 2119
 							if ($scheme == 'mailto')
2025 2120
 							{
2026 2121
 								$email_address = str_replace('mailto:', '', $url);
2027
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2028
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2029
-								else
2030
-									return $url;
2122
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2123
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2124
+								} else {
2125
+																	return $url;
2126
+								}
2031 2127
 							}
2032 2128
 
2033 2129
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2034
-							if (empty($scheme))
2035
-								$fullUrl = '//' . ltrim($url, ':/');
2036
-							else
2037
-								$fullUrl = $url;
2130
+							if (empty($scheme)) {
2131
+															$fullUrl = '//' . ltrim($url, ':/');
2132
+							} else {
2133
+															$fullUrl = $url;
2134
+							}
2038 2135
 
2039 2136
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2040 2137
 						}, $data);
@@ -2083,16 +2180,18 @@  discard block
 block discarded – undo
2083 2180
 		}
2084 2181
 
2085 2182
 		// Are we there yet?  Are we there yet?
2086
-		if ($pos >= strlen($message) - 1)
2087
-			break;
2183
+		if ($pos >= strlen($message) - 1) {
2184
+					break;
2185
+		}
2088 2186
 
2089 2187
 		$tags = strtolower($message[$pos + 1]);
2090 2188
 
2091 2189
 		if ($tags == '/' && !empty($open_tags))
2092 2190
 		{
2093 2191
 			$pos2 = strpos($message, ']', $pos + 1);
2094
-			if ($pos2 == $pos + 2)
2095
-				continue;
2192
+			if ($pos2 == $pos + 2) {
2193
+							continue;
2194
+			}
2096 2195
 
2097 2196
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2098 2197
 
@@ -2102,8 +2201,9 @@  discard block
 block discarded – undo
2102 2201
 			do
2103 2202
 			{
2104 2203
 				$tag = array_pop($open_tags);
2105
-				if (!$tag)
2106
-					break;
2204
+				if (!$tag) {
2205
+									break;
2206
+				}
2107 2207
 
2108 2208
 				if (!empty($tag['block_level']))
2109 2209
 				{
@@ -2117,10 +2217,11 @@  discard block
 block discarded – undo
2117 2217
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2118 2218
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2119 2219
 					{
2120
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2121
-							if ($temp['tag'] == $look_for)
2220
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2221
+													if ($temp['tag'] == $look_for)
2122 2222
 							{
2123 2223
 								$block_level = !empty($temp['block_level']);
2224
+						}
2124 2225
 								break;
2125 2226
 							}
2126 2227
 					}
@@ -2142,15 +2243,15 @@  discard block
 block discarded – undo
2142 2243
 			{
2143 2244
 				$open_tags = $to_close;
2144 2245
 				continue;
2145
-			}
2146
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2246
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2147 2247
 			{
2148 2248
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2149 2249
 				{
2150
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2151
-						if ($temp['tag'] == $look_for)
2250
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2251
+											if ($temp['tag'] == $look_for)
2152 2252
 						{
2153 2253
 							$block_level = !empty($temp['block_level']);
2254
+					}
2154 2255
 							break;
2155 2256
 						}
2156 2257
 				}
@@ -2158,8 +2259,9 @@  discard block
 block discarded – undo
2158 2259
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2159 2260
 				if (!$block_level)
2160 2261
 				{
2161
-					foreach ($to_close as $tag)
2162
-						array_push($open_tags, $tag);
2262
+					foreach ($to_close as $tag) {
2263
+											array_push($open_tags, $tag);
2264
+					}
2163 2265
 					continue;
2164 2266
 				}
2165 2267
 			}
@@ -2172,14 +2274,17 @@  discard block
 block discarded – undo
2172 2274
 
2173 2275
 				// See the comment at the end of the big loop - just eating whitespace ;).
2174 2276
 				$whitespace_regex = '';
2175
-				if (!empty($tag['block_level']))
2176
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2277
+				if (!empty($tag['block_level'])) {
2278
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2279
+				}
2177 2280
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2178
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2179
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2281
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2282
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2283
+				}
2180 2284
 
2181
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2182
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2285
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2286
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2287
+				}
2183 2288
 			}
2184 2289
 
2185 2290
 			if (!empty($to_close))
@@ -2192,8 +2297,9 @@  discard block
 block discarded – undo
2192 2297
 		}
2193 2298
 
2194 2299
 		// No tags for this character, so just keep going (fastest possible course.)
2195
-		if (!isset($bbc_codes[$tags]))
2196
-			continue;
2300
+		if (!isset($bbc_codes[$tags])) {
2301
+					continue;
2302
+		}
2197 2303
 
2198 2304
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2199 2305
 		$tag = null;
@@ -2202,44 +2308,52 @@  discard block
 block discarded – undo
2202 2308
 			$pt_strlen = strlen($possible['tag']);
2203 2309
 
2204 2310
 			// Not a match?
2205
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2206
-				continue;
2311
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2312
+							continue;
2313
+			}
2207 2314
 
2208 2315
 			$next_c = $message[$pos + 1 + $pt_strlen];
2209 2316
 
2210 2317
 			// A test validation?
2211
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2212
-				continue;
2318
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2319
+							continue;
2320
+			}
2213 2321
 			// Do we want parameters?
2214 2322
 			elseif (!empty($possible['parameters']))
2215 2323
 			{
2216
-				if ($next_c != ' ')
2217
-					continue;
2218
-			}
2219
-			elseif (isset($possible['type']))
2324
+				if ($next_c != ' ') {
2325
+									continue;
2326
+				}
2327
+			} elseif (isset($possible['type']))
2220 2328
 			{
2221 2329
 				// Do we need an equal sign?
2222
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2223
-					continue;
2330
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2331
+									continue;
2332
+				}
2224 2333
 				// Maybe we just want a /...
2225
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2226
-					continue;
2334
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2335
+									continue;
2336
+				}
2227 2337
 				// An immediate ]?
2228
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2229
-					continue;
2338
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2339
+									continue;
2340
+				}
2230 2341
 			}
2231 2342
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2232
-			elseif ($next_c != ']')
2233
-				continue;
2343
+			elseif ($next_c != ']') {
2344
+							continue;
2345
+			}
2234 2346
 
2235 2347
 			// Check allowed tree?
2236
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2237
-				continue;
2238
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2239
-				continue;
2348
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2349
+							continue;
2350
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2351
+							continue;
2352
+			}
2240 2353
 			// If this is in the list of disallowed child tags, don't parse it.
2241
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2242
-				continue;
2354
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2355
+							continue;
2356
+			}
2243 2357
 
2244 2358
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2245 2359
 
@@ -2251,8 +2365,9 @@  discard block
 block discarded – undo
2251 2365
 				foreach ($open_tags as $open_quote)
2252 2366
 				{
2253 2367
 					// Every parent quote this quote has flips the styling
2254
-					if ($open_quote['tag'] == 'quote')
2255
-						$quote_alt = !$quote_alt;
2368
+					if ($open_quote['tag'] == 'quote') {
2369
+											$quote_alt = !$quote_alt;
2370
+					}
2256 2371
 				}
2257 2372
 				// Add a class to the quote to style alternating blockquotes
2258 2373
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2263,8 +2378,9 @@  discard block
 block discarded – undo
2263 2378
 			{
2264 2379
 				// Build a regular expression for each parameter for the current tag.
2265 2380
 				$preg = array();
2266
-				foreach ($possible['parameters'] as $p => $info)
2267
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2381
+				foreach ($possible['parameters'] as $p => $info) {
2382
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2383
+				}
2268 2384
 
2269 2385
 				// Extract the string that potentially holds our parameters.
2270 2386
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2284,24 +2400,27 @@  discard block
 block discarded – undo
2284 2400
 
2285 2401
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2286 2402
 
2287
-					if ($match)
2288
-						$blob_counter = count($blobs) + 1;
2403
+					if ($match) {
2404
+											$blob_counter = count($blobs) + 1;
2405
+					}
2289 2406
 				}
2290 2407
 
2291 2408
 				// Didn't match our parameter list, try the next possible.
2292
-				if (!$match)
2293
-					continue;
2409
+				if (!$match) {
2410
+									continue;
2411
+				}
2294 2412
 
2295 2413
 				$params = array();
2296 2414
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2297 2415
 				{
2298 2416
 					$key = strtok(ltrim($matches[$i]), '=');
2299
-					if (isset($possible['parameters'][$key]['value']))
2300
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2301
-					elseif (isset($possible['parameters'][$key]['validate']))
2302
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2303
-					else
2304
-						$params['{' . $key . '}'] = $matches[$i + 1];
2417
+					if (isset($possible['parameters'][$key]['value'])) {
2418
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2419
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2420
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2421
+					} else {
2422
+											$params['{' . $key . '}'] = $matches[$i + 1];
2423
+					}
2305 2424
 
2306 2425
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2307 2426
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2309,23 +2428,26 @@  discard block
 block discarded – undo
2309 2428
 
2310 2429
 				foreach ($possible['parameters'] as $p => $info)
2311 2430
 				{
2312
-					if (!isset($params['{' . $p . '}']))
2313
-						$params['{' . $p . '}'] = '';
2431
+					if (!isset($params['{' . $p . '}'])) {
2432
+											$params['{' . $p . '}'] = '';
2433
+					}
2314 2434
 				}
2315 2435
 
2316 2436
 				$tag = $possible;
2317 2437
 
2318 2438
 				// Put the parameters into the string.
2319
-				if (isset($tag['before']))
2320
-					$tag['before'] = strtr($tag['before'], $params);
2321
-				if (isset($tag['after']))
2322
-					$tag['after'] = strtr($tag['after'], $params);
2323
-				if (isset($tag['content']))
2324
-					$tag['content'] = strtr($tag['content'], $params);
2439
+				if (isset($tag['before'])) {
2440
+									$tag['before'] = strtr($tag['before'], $params);
2441
+				}
2442
+				if (isset($tag['after'])) {
2443
+									$tag['after'] = strtr($tag['after'], $params);
2444
+				}
2445
+				if (isset($tag['content'])) {
2446
+									$tag['content'] = strtr($tag['content'], $params);
2447
+				}
2325 2448
 
2326 2449
 				$pos1 += strlen($given_param_string);
2327
-			}
2328
-			else
2450
+			} else
2329 2451
 			{
2330 2452
 				$tag = $possible;
2331 2453
 				$params = array();
@@ -2336,8 +2458,9 @@  discard block
 block discarded – undo
2336 2458
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2337 2459
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2338 2460
 		{
2339
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2340
-				continue;
2461
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2462
+							continue;
2463
+			}
2341 2464
 
2342 2465
 			$tag = $itemcodes[$message[$pos + 1]];
2343 2466
 
@@ -2358,9 +2481,9 @@  discard block
 block discarded – undo
2358 2481
 			{
2359 2482
 				array_pop($open_tags);
2360 2483
 				$code = '</li>';
2484
+			} else {
2485
+							$code = '';
2361 2486
 			}
2362
-			else
2363
-				$code = '';
2364 2487
 
2365 2488
 			// Now we open a new tag.
2366 2489
 			$open_tags[] = array(
@@ -2407,12 +2530,14 @@  discard block
 block discarded – undo
2407 2530
 		}
2408 2531
 
2409 2532
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2410
-		if ($tag === null)
2411
-			continue;
2533
+		if ($tag === null) {
2534
+					continue;
2535
+		}
2412 2536
 
2413 2537
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2414
-		if (isset($inside['disallow_children']))
2415
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2538
+		if (isset($inside['disallow_children'])) {
2539
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2540
+		}
2416 2541
 
2417 2542
 		// Is this tag disabled?
2418 2543
 		if (isset($disabled[$tag['tag']]))
@@ -2422,14 +2547,13 @@  discard block
 block discarded – undo
2422 2547
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2423 2548
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2424 2549
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2425
-			}
2426
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2550
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2427 2551
 			{
2428 2552
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2429 2553
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2554
+			} else {
2555
+							$tag['content'] = $tag['disabled_content'];
2430 2556
 			}
2431
-			else
2432
-				$tag['content'] = $tag['disabled_content'];
2433 2557
 		}
2434 2558
 
2435 2559
 		// we use this a lot
@@ -2439,8 +2563,9 @@  discard block
 block discarded – undo
2439 2563
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2440 2564
 		{
2441 2565
 			$n = count($open_tags) - 1;
2442
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2443
-				$n--;
2566
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2567
+							$n--;
2568
+			}
2444 2569
 
2445 2570
 			// Close all the non block level tags so this tag isn't surrounded by them.
2446 2571
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2452,12 +2577,15 @@  discard block
 block discarded – undo
2452 2577
 
2453 2578
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2454 2579
 				$whitespace_regex = '';
2455
-				if (!empty($tag['block_level']))
2456
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2457
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2458
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2459
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2460
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2580
+				if (!empty($tag['block_level'])) {
2581
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2582
+				}
2583
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2584
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2585
+				}
2586
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2587
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2588
+				}
2461 2589
 
2462 2590
 				array_pop($open_tags);
2463 2591
 			}
@@ -2475,16 +2603,19 @@  discard block
 block discarded – undo
2475 2603
 		elseif ($tag['type'] == 'unparsed_content')
2476 2604
 		{
2477 2605
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2478
-			if ($pos2 === false)
2479
-				continue;
2606
+			if ($pos2 === false) {
2607
+							continue;
2608
+			}
2480 2609
 
2481 2610
 			$data = substr($message, $pos1, $pos2 - $pos1);
2482 2611
 
2483
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2484
-				$data = substr($data, 4);
2612
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2613
+							$data = substr($data, 4);
2614
+			}
2485 2615
 
2486
-			if (isset($tag['validate']))
2487
-				$tag['validate']($tag, $data, $disabled, $params);
2616
+			if (isset($tag['validate'])) {
2617
+							$tag['validate']($tag, $data, $disabled, $params);
2618
+			}
2488 2619
 
2489 2620
 			$code = strtr($tag['content'], array('$1' => $data));
2490 2621
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2500,34 +2631,40 @@  discard block
 block discarded – undo
2500 2631
 			if (isset($tag['quoted']))
2501 2632
 			{
2502 2633
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2503
-				if ($tag['quoted'] != 'optional' && !$quoted)
2504
-					continue;
2634
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2635
+									continue;
2636
+				}
2505 2637
 
2506
-				if ($quoted)
2507
-					$pos1 += 6;
2638
+				if ($quoted) {
2639
+									$pos1 += 6;
2640
+				}
2641
+			} else {
2642
+							$quoted = false;
2508 2643
 			}
2509
-			else
2510
-				$quoted = false;
2511 2644
 
2512 2645
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2513
-			if ($pos2 === false)
2514
-				continue;
2646
+			if ($pos2 === false) {
2647
+							continue;
2648
+			}
2515 2649
 
2516 2650
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2517
-			if ($pos3 === false)
2518
-				continue;
2651
+			if ($pos3 === false) {
2652
+							continue;
2653
+			}
2519 2654
 
2520 2655
 			$data = array(
2521 2656
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2522 2657
 				substr($message, $pos1, $pos2 - $pos1)
2523 2658
 			);
2524 2659
 
2525
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2526
-				$data[0] = substr($data[0], 4);
2660
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2661
+							$data[0] = substr($data[0], 4);
2662
+			}
2527 2663
 
2528 2664
 			// Validation for my parking, please!
2529
-			if (isset($tag['validate']))
2530
-				$tag['validate']($tag, $data, $disabled, $params);
2665
+			if (isset($tag['validate'])) {
2666
+							$tag['validate']($tag, $data, $disabled, $params);
2667
+			}
2531 2668
 
2532 2669
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2533 2670
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2544,23 +2681,27 @@  discard block
 block discarded – undo
2544 2681
 		elseif ($tag['type'] == 'unparsed_commas_content')
2545 2682
 		{
2546 2683
 			$pos2 = strpos($message, ']', $pos1);
2547
-			if ($pos2 === false)
2548
-				continue;
2684
+			if ($pos2 === false) {
2685
+							continue;
2686
+			}
2549 2687
 
2550 2688
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2551
-			if ($pos3 === false)
2552
-				continue;
2689
+			if ($pos3 === false) {
2690
+							continue;
2691
+			}
2553 2692
 
2554 2693
 			// We want $1 to be the content, and the rest to be csv.
2555 2694
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2556 2695
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2557 2696
 
2558
-			if (isset($tag['validate']))
2559
-				$tag['validate']($tag, $data, $disabled, $params);
2697
+			if (isset($tag['validate'])) {
2698
+							$tag['validate']($tag, $data, $disabled, $params);
2699
+			}
2560 2700
 
2561 2701
 			$code = $tag['content'];
2562
-			foreach ($data as $k => $d)
2563
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2702
+			foreach ($data as $k => $d) {
2703
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2704
+			}
2564 2705
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2565 2706
 			$pos += strlen($code) - 1 + 2;
2566 2707
 		}
@@ -2568,24 +2709,28 @@  discard block
 block discarded – undo
2568 2709
 		elseif ($tag['type'] == 'unparsed_commas')
2569 2710
 		{
2570 2711
 			$pos2 = strpos($message, ']', $pos1);
2571
-			if ($pos2 === false)
2572
-				continue;
2712
+			if ($pos2 === false) {
2713
+							continue;
2714
+			}
2573 2715
 
2574 2716
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2575 2717
 
2576
-			if (isset($tag['validate']))
2577
-				$tag['validate']($tag, $data, $disabled, $params);
2718
+			if (isset($tag['validate'])) {
2719
+							$tag['validate']($tag, $data, $disabled, $params);
2720
+			}
2578 2721
 
2579 2722
 			// Fix after, for disabled code mainly.
2580
-			foreach ($data as $k => $d)
2581
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2723
+			foreach ($data as $k => $d) {
2724
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2725
+			}
2582 2726
 
2583 2727
 			$open_tags[] = $tag;
2584 2728
 
2585 2729
 			// Replace them out, $1, $2, $3, $4, etc.
2586 2730
 			$code = $tag['before'];
2587
-			foreach ($data as $k => $d)
2588
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2731
+			foreach ($data as $k => $d) {
2732
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2733
+			}
2589 2734
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2590 2735
 			$pos += strlen($code) - 1 + 2;
2591 2736
 		}
@@ -2596,28 +2741,33 @@  discard block
 block discarded – undo
2596 2741
 			if (isset($tag['quoted']))
2597 2742
 			{
2598 2743
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2599
-				if ($tag['quoted'] != 'optional' && !$quoted)
2600
-					continue;
2744
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2745
+									continue;
2746
+				}
2601 2747
 
2602
-				if ($quoted)
2603
-					$pos1 += 6;
2748
+				if ($quoted) {
2749
+									$pos1 += 6;
2750
+				}
2751
+			} else {
2752
+							$quoted = false;
2604 2753
 			}
2605
-			else
2606
-				$quoted = false;
2607 2754
 
2608 2755
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2609
-			if ($pos2 === false)
2610
-				continue;
2756
+			if ($pos2 === false) {
2757
+							continue;
2758
+			}
2611 2759
 
2612 2760
 			$data = substr($message, $pos1, $pos2 - $pos1);
2613 2761
 
2614 2762
 			// Validation for my parking, please!
2615
-			if (isset($tag['validate']))
2616
-				$tag['validate']($tag, $data, $disabled, $params);
2763
+			if (isset($tag['validate'])) {
2764
+							$tag['validate']($tag, $data, $disabled, $params);
2765
+			}
2617 2766
 
2618 2767
 			// For parsed content, we must recurse to avoid security problems.
2619
-			if ($tag['type'] != 'unparsed_equals')
2620
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2768
+			if ($tag['type'] != 'unparsed_equals') {
2769
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2770
+			}
2621 2771
 
2622 2772
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2623 2773
 
@@ -2629,34 +2779,40 @@  discard block
 block discarded – undo
2629 2779
 		}
2630 2780
 
2631 2781
 		// If this is block level, eat any breaks after it.
2632
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2633
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2782
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2783
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2784
+		}
2634 2785
 
2635 2786
 		// Are we trimming outside this tag?
2636
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2637
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2787
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2788
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2789
+		}
2638 2790
 	}
2639 2791
 
2640 2792
 	// Close any remaining tags.
2641
-	while ($tag = array_pop($open_tags))
2642
-		$message .= "\n" . $tag['after'] . "\n";
2793
+	while ($tag = array_pop($open_tags)) {
2794
+			$message .= "\n" . $tag['after'] . "\n";
2795
+	}
2643 2796
 
2644 2797
 	// Parse the smileys within the parts where it can be done safely.
2645 2798
 	if ($smileys === true)
2646 2799
 	{
2647 2800
 		$message_parts = explode("\n", $message);
2648
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2649
-			parsesmileys($message_parts[$i]);
2801
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2802
+					parsesmileys($message_parts[$i]);
2803
+		}
2650 2804
 
2651 2805
 		$message = implode('', $message_parts);
2652 2806
 	}
2653 2807
 
2654 2808
 	// No smileys, just get rid of the markers.
2655
-	else
2656
-		$message = strtr($message, array("\n" => ''));
2809
+	else {
2810
+			$message = strtr($message, array("\n" => ''));
2811
+	}
2657 2812
 
2658
-	if ($message !== '' && $message[0] === ' ')
2659
-		$message = '&nbsp;' . substr($message, 1);
2813
+	if ($message !== '' && $message[0] === ' ') {
2814
+			$message = '&nbsp;' . substr($message, 1);
2815
+	}
2660 2816
 
2661 2817
 	// Cleanup whitespace.
2662 2818
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2665,15 +2821,16 @@  discard block
 block discarded – undo
2665 2821
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2666 2822
 
2667 2823
 	// Cache the output if it took some time...
2668
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2669
-		cache_put_data($cache_key, $message, 240);
2824
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2825
+			cache_put_data($cache_key, $message, 240);
2826
+	}
2670 2827
 
2671 2828
 	// If this was a force parse revert if needed.
2672 2829
 	if (!empty($parse_tags))
2673 2830
 	{
2674
-		if (empty($temp_bbc))
2675
-			$bbc_codes = array();
2676
-		else
2831
+		if (empty($temp_bbc)) {
2832
+					$bbc_codes = array();
2833
+		} else
2677 2834
 		{
2678 2835
 			$bbc_codes = $temp_bbc;
2679 2836
 			unset($temp_bbc);
@@ -2700,8 +2857,9 @@  discard block
 block discarded – undo
2700 2857
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2701 2858
 
2702 2859
 	// No smiley set at all?!
2703
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2704
-		return;
2860
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2861
+			return;
2862
+	}
2705 2863
 
2706 2864
 	// If smileyPregSearch hasn't been set, do it now.
2707 2865
 	if (empty($smileyPregSearch))
@@ -2712,8 +2870,7 @@  discard block
 block discarded – undo
2712 2870
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2713 2871
 			$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
2714 2872
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2715
-		}
2716
-		else
2873
+		} else
2717 2874
 		{
2718 2875
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2719 2876
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2737,9 +2894,9 @@  discard block
 block discarded – undo
2737 2894
 				$smcFunc['db_free_result']($result);
2738 2895
 
2739 2896
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2897
+			} else {
2898
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2740 2899
 			}
2741
-			else
2742
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2743 2900
 		}
2744 2901
 
2745 2902
 		// The non-breaking-space is a complex thing...
@@ -2816,35 +2973,41 @@  discard block
 block discarded – undo
2816 2973
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2817 2974
 
2818 2975
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2819
-	if (!empty($context['flush_mail']))
2820
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2976
+	if (!empty($context['flush_mail'])) {
2977
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2821 2978
 		AddMailQueue(true);
2979
+	}
2822 2980
 
2823 2981
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2824 2982
 
2825
-	if ($add)
2826
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2983
+	if ($add) {
2984
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2985
+	}
2827 2986
 
2828 2987
 	// Put the session ID in.
2829
-	if (defined('SID') && SID != '')
2830
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2988
+	if (defined('SID') && SID != '') {
2989
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2990
+	}
2831 2991
 	// Keep that debug in their for template debugging!
2832
-	elseif (isset($_GET['debug']))
2833
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2992
+	elseif (isset($_GET['debug'])) {
2993
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2994
+	}
2834 2995
 
2835 2996
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2836 2997
 	{
2837
-		if (defined('SID') && SID != '')
2838
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2998
+		if (defined('SID') && SID != '') {
2999
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2839 3000
 				function ($m) use ($scripturl)
2840 3001
 				{
2841 3002
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3003
+		}
2842 3004
 				}, $setLocation);
2843
-		else
2844
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3005
+		else {
3006
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2845 3007
 				function ($m) use ($scripturl)
2846 3008
 				{
2847 3009
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3010
+		}
2848 3011
 				}, $setLocation);
2849 3012
 	}
2850 3013
 
@@ -2855,8 +3018,9 @@  discard block
 block discarded – undo
2855 3018
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2856 3019
 
2857 3020
 	// Debugging.
2858
-	if (isset($db_show_debug) && $db_show_debug === true)
2859
-		$_SESSION['debug_redirect'] = $db_cache;
3021
+	if (isset($db_show_debug) && $db_show_debug === true) {
3022
+			$_SESSION['debug_redirect'] = $db_cache;
3023
+	}
2860 3024
 
2861 3025
 	obExit(false);
2862 3026
 }
@@ -2875,51 +3039,60 @@  discard block
 block discarded – undo
2875 3039
 
2876 3040
 	// Attempt to prevent a recursive loop.
2877 3041
 	++$level;
2878
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2879
-		exit;
2880
-	if ($from_fatal_error)
2881
-		$has_fatal_error = true;
3042
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3043
+			exit;
3044
+	}
3045
+	if ($from_fatal_error) {
3046
+			$has_fatal_error = true;
3047
+	}
2882 3048
 
2883 3049
 	// Clear out the stat cache.
2884 3050
 	trackStats();
2885 3051
 
2886 3052
 	// If we have mail to send, send it.
2887
-	if (!empty($context['flush_mail']))
2888
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3053
+	if (!empty($context['flush_mail'])) {
3054
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2889 3055
 		AddMailQueue(true);
3056
+	}
2890 3057
 
2891 3058
 	$do_header = $header === null ? !$header_done : $header;
2892
-	if ($do_footer === null)
2893
-		$do_footer = $do_header;
3059
+	if ($do_footer === null) {
3060
+			$do_footer = $do_header;
3061
+	}
2894 3062
 
2895 3063
 	// Has the template/header been done yet?
2896 3064
 	if ($do_header)
2897 3065
 	{
2898 3066
 		// Was the page title set last minute? Also update the HTML safe one.
2899
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2900
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3067
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3068
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3069
+		}
2901 3070
 
2902 3071
 		// Start up the session URL fixer.
2903 3072
 		ob_start('ob_sessrewrite');
2904 3073
 
2905
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2906
-			$buffers = explode(',', $settings['output_buffers']);
2907
-		elseif (!empty($settings['output_buffers']))
2908
-			$buffers = $settings['output_buffers'];
2909
-		else
2910
-			$buffers = array();
3074
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3075
+					$buffers = explode(',', $settings['output_buffers']);
3076
+		} elseif (!empty($settings['output_buffers'])) {
3077
+					$buffers = $settings['output_buffers'];
3078
+		} else {
3079
+					$buffers = array();
3080
+		}
2911 3081
 
2912
-		if (isset($modSettings['integrate_buffer']))
2913
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3082
+		if (isset($modSettings['integrate_buffer'])) {
3083
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3084
+		}
2914 3085
 
2915
-		if (!empty($buffers))
2916
-			foreach ($buffers as $function)
3086
+		if (!empty($buffers)) {
3087
+					foreach ($buffers as $function)
2917 3088
 			{
2918 3089
 				$call = call_helper($function, true);
3090
+		}
2919 3091
 
2920 3092
 				// Is it valid?
2921
-				if (!empty($call))
2922
-					ob_start($call);
3093
+				if (!empty($call)) {
3094
+									ob_start($call);
3095
+				}
2923 3096
 			}
2924 3097
 
2925 3098
 		// Display the screen in the logical order.
@@ -2931,8 +3104,9 @@  discard block
 block discarded – undo
2931 3104
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2932 3105
 
2933 3106
 		// Anything special to put out?
2934
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2935
-			echo $context['insert_after_template'];
3107
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3108
+					echo $context['insert_after_template'];
3109
+		}
2936 3110
 
2937 3111
 		// Just so we don't get caught in an endless loop of errors from the footer...
2938 3112
 		if (!$footer_done)
@@ -2941,14 +3115,16 @@  discard block
 block discarded – undo
2941 3115
 			template_footer();
2942 3116
 
2943 3117
 			// (since this is just debugging... it's okay that it's after </html>.)
2944
-			if (!isset($_REQUEST['xml']))
2945
-				displayDebug();
3118
+			if (!isset($_REQUEST['xml'])) {
3119
+							displayDebug();
3120
+			}
2946 3121
 		}
2947 3122
 	}
2948 3123
 
2949 3124
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2950
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2951
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3125
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3126
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3127
+	}
2952 3128
 
2953 3129
 	// For session check verification.... don't switch browsers...
2954 3130
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2957,9 +3133,10 @@  discard block
 block discarded – undo
2957 3133
 	call_integration_hook('integrate_exit', array($do_footer));
2958 3134
 
2959 3135
 	// Don't exit if we're coming from index.php; that will pass through normally.
2960
-	if (!$from_index)
2961
-		exit;
2962
-}
3136
+	if (!$from_index) {
3137
+			exit;
3138
+	}
3139
+	}
2963 3140
 
2964 3141
 /**
2965 3142
  * Get the size of a specified image with better error handling.
@@ -2978,8 +3155,9 @@  discard block
 block discarded – undo
2978 3155
 	$url = str_replace(' ', '%20', $url);
2979 3156
 
2980 3157
 	// Can we pull this from the cache... please please?
2981
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2982
-		return $temp;
3158
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3159
+			return $temp;
3160
+	}
2983 3161
 	$t = microtime();
2984 3162
 
2985 3163
 	// Get the host to pester...
@@ -2989,12 +3167,10 @@  discard block
 block discarded – undo
2989 3167
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2990 3168
 	{
2991 3169
 		return false;
2992
-	}
2993
-	elseif (!isset($match[1]))
3170
+	} elseif (!isset($match[1]))
2994 3171
 	{
2995 3172
 		$size = @getimagesize($url);
2996
-	}
2997
-	else
3173
+	} else
2998 3174
 	{
2999 3175
 		// Try to connect to the server... give it half a second.
3000 3176
 		$temp = 0;
@@ -3033,12 +3209,14 @@  discard block
 block discarded – undo
3033 3209
 	}
3034 3210
 
3035 3211
 	// If we didn't get it, we failed.
3036
-	if (!isset($size))
3037
-		$size = false;
3212
+	if (!isset($size)) {
3213
+			$size = false;
3214
+	}
3038 3215
 
3039 3216
 	// If this took a long time, we may never have to do it again, but then again we might...
3040
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3041
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3217
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3218
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3219
+	}
3042 3220
 
3043 3221
 	// Didn't work.
3044 3222
 	return $size;
@@ -3056,8 +3234,9 @@  discard block
 block discarded – undo
3056 3234
 
3057 3235
 	// Under SSI this function can be called more then once.  That can cause some problems.
3058 3236
 	//   So only run the function once unless we are forced to run it again.
3059
-	if ($loaded && !$forceload)
3060
-		return;
3237
+	if ($loaded && !$forceload) {
3238
+			return;
3239
+	}
3061 3240
 
3062 3241
 	$loaded = true;
3063 3242
 
@@ -3069,14 +3248,16 @@  discard block
 block discarded – undo
3069 3248
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3070 3249
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3071 3250
 	{
3072
-		if (trim($context['news_lines'][$i]) == '')
3073
-			continue;
3251
+		if (trim($context['news_lines'][$i]) == '') {
3252
+					continue;
3253
+		}
3074 3254
 
3075 3255
 		// Clean it up for presentation ;).
3076 3256
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3077 3257
 	}
3078
-	if (!empty($context['news_lines']))
3079
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3258
+	if (!empty($context['news_lines'])) {
3259
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3260
+	}
3080 3261
 
3081 3262
 	if (!$user_info['is_guest'])
3082 3263
 	{
@@ -3085,40 +3266,48 @@  discard block
 block discarded – undo
3085 3266
 		$context['user']['alerts'] = &$user_info['alerts'];
3086 3267
 
3087 3268
 		// Personal message popup...
3088
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3089
-			$context['user']['popup_messages'] = true;
3090
-		else
3091
-			$context['user']['popup_messages'] = false;
3269
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3270
+					$context['user']['popup_messages'] = true;
3271
+		} else {
3272
+					$context['user']['popup_messages'] = false;
3273
+		}
3092 3274
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3093 3275
 
3094
-		if (allowedTo('moderate_forum'))
3095
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3276
+		if (allowedTo('moderate_forum')) {
3277
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3278
+		}
3096 3279
 
3097 3280
 		$context['user']['avatar'] = array();
3098 3281
 
3099 3282
 		// Check for gravatar first since we might be forcing them...
3100 3283
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3101 3284
 		{
3102
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3103
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3104
-			else
3105
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3285
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3286
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3287
+			} else {
3288
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3289
+			}
3106 3290
 		}
3107 3291
 		// Uploaded?
3108
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3109
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3292
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3293
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3294
+		}
3110 3295
 		// Full URL?
3111
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3112
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3296
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3297
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3298
+		}
3113 3299
 		// Otherwise we assume it's server stored.
3114
-		elseif ($user_info['avatar']['url'] != '')
3115
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3300
+		elseif ($user_info['avatar']['url'] != '') {
3301
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3302
+		}
3116 3303
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3117
-		else
3118
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3304
+		else {
3305
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3306
+		}
3119 3307
 
3120
-		if (!empty($context['user']['avatar']))
3121
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3308
+		if (!empty($context['user']['avatar'])) {
3309
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3310
+		}
3122 3311
 
3123 3312
 		// Figure out how long they've been logged in.
3124 3313
 		$context['user']['total_time_logged_in'] = array(
@@ -3126,8 +3315,7 @@  discard block
 block discarded – undo
3126 3315
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3127 3316
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3128 3317
 		);
3129
-	}
3130
-	else
3318
+	} else
3131 3319
 	{
3132 3320
 		$context['user']['messages'] = 0;
3133 3321
 		$context['user']['unread_messages'] = 0;
@@ -3135,12 +3323,14 @@  discard block
 block discarded – undo
3135 3323
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3136 3324
 		$context['user']['popup_messages'] = false;
3137 3325
 
3138
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3139
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3326
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3327
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3328
+		}
3140 3329
 
3141 3330
 		// If we've upgraded recently, go easy on the passwords.
3142
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3143
-			$context['disable_login_hashing'] = true;
3331
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3332
+					$context['disable_login_hashing'] = true;
3333
+		}
3144 3334
 	}
3145 3335
 
3146 3336
 	// Setup the main menu items.
@@ -3153,8 +3343,8 @@  discard block
 block discarded – undo
3153 3343
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3154 3344
 
3155 3345
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3156
-	if ($context['show_pm_popup'])
3157
-		addInlineJavaScript('
3346
+	if ($context['show_pm_popup']) {
3347
+			addInlineJavaScript('
3158 3348
 		jQuery(document).ready(function($) {
3159 3349
 			new smc_Popup({
3160 3350
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3162,15 +3352,17 @@  discard block
 block discarded – undo
3162 3352
 				icon_class: \'generic_icons mail_new\'
3163 3353
 			});
3164 3354
 		});');
3355
+	}
3165 3356
 
3166 3357
 	// Add a generic "Are you sure?" confirmation message.
3167 3358
 	addInlineJavaScript('
3168 3359
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3169 3360
 
3170 3361
 	// Now add the capping code for avatars.
3171
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3172
-		addInlineCss('
3362
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3363
+			addInlineCss('
3173 3364
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3365
+	}
3174 3366
 
3175 3367
 	// This looks weird, but it's because BoardIndex.php references the variable.
3176 3368
 	$context['common_stats']['latest_member'] = array(
@@ -3187,11 +3379,13 @@  discard block
 block discarded – undo
3187 3379
 	);
3188 3380
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3189 3381
 
3190
-	if (empty($settings['theme_version']))
3191
-		addJavaScriptVar('smf_scripturl', $scripturl);
3382
+	if (empty($settings['theme_version'])) {
3383
+			addJavaScriptVar('smf_scripturl', $scripturl);
3384
+	}
3192 3385
 
3193
-	if (!isset($context['page_title']))
3194
-		$context['page_title'] = '';
3386
+	if (!isset($context['page_title'])) {
3387
+			$context['page_title'] = '';
3388
+	}
3195 3389
 
3196 3390
 	// Set some specific vars.
3197 3391
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3201,21 +3395,23 @@  discard block
 block discarded – undo
3201 3395
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3202 3396
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3203 3397
 
3204
-	if (!empty($context['meta_keywords']))
3205
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3398
+	if (!empty($context['meta_keywords'])) {
3399
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3400
+	}
3206 3401
 
3207
-	if (!empty($context['canonical_url']))
3208
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3402
+	if (!empty($context['canonical_url'])) {
3403
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3404
+	}
3209 3405
 
3210
-	if (!empty($settings['og_image']))
3211
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3406
+	if (!empty($settings['og_image'])) {
3407
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3408
+	}
3212 3409
 
3213 3410
 	if (!empty($context['meta_description']))
3214 3411
 	{
3215 3412
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3216 3413
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3217
-	}
3218
-	else
3414
+	} else
3219 3415
 	{
3220 3416
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3221 3417
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3240,8 +3436,9 @@  discard block
 block discarded – undo
3240 3436
 	$memory_needed = memoryReturnBytes($needed);
3241 3437
 
3242 3438
 	// should we account for how much is currently being used?
3243
-	if ($in_use)
3244
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3439
+	if ($in_use) {
3440
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3441
+	}
3245 3442
 
3246 3443
 	// if more is needed, request it
3247 3444
 	if ($memory_current < $memory_needed)
@@ -3264,8 +3461,9 @@  discard block
 block discarded – undo
3264 3461
  */
3265 3462
 function memoryReturnBytes($val)
3266 3463
 {
3267
-	if (is_integer($val))
3268
-		return $val;
3464
+	if (is_integer($val)) {
3465
+			return $val;
3466
+	}
3269 3467
 
3270 3468
 	// Separate the number from the designator
3271 3469
 	$val = trim($val);
@@ -3301,10 +3499,11 @@  discard block
 block discarded – undo
3301 3499
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3302 3500
 
3303 3501
 		// Are we debugging the template/html content?
3304
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3305
-			header('Content-Type: application/xhtml+xml');
3306
-		elseif (!isset($_REQUEST['xml']))
3307
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3502
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3503
+					header('Content-Type: application/xhtml+xml');
3504
+		} elseif (!isset($_REQUEST['xml'])) {
3505
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3506
+		}
3308 3507
 	}
3309 3508
 
3310 3509
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3313,8 +3512,9 @@  discard block
 block discarded – undo
3313 3512
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3314 3513
 	{
3315 3514
 		$position = array_search('body', $context['template_layers']);
3316
-		if ($position === false)
3317
-			$position = array_search('main', $context['template_layers']);
3515
+		if ($position === false) {
3516
+					$position = array_search('main', $context['template_layers']);
3517
+		}
3318 3518
 
3319 3519
 		if ($position !== false)
3320 3520
 		{
@@ -3342,23 +3542,25 @@  discard block
 block discarded – undo
3342 3542
 
3343 3543
 			foreach ($securityFiles as $i => $securityFile)
3344 3544
 			{
3345
-				if (!file_exists($boarddir . '/' . $securityFile))
3346
-					unset($securityFiles[$i]);
3545
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3546
+									unset($securityFiles[$i]);
3547
+				}
3347 3548
 			}
3348 3549
 
3349 3550
 			// We are already checking so many files...just few more doesn't make any difference! :P
3350
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3351
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3352
-
3353
-			else
3354
-				$path = $modSettings['attachmentUploadDir'];
3551
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3552
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3553
+			} else {
3554
+							$path = $modSettings['attachmentUploadDir'];
3555
+			}
3355 3556
 
3356 3557
 			secureDirectory($path, true);
3357 3558
 			secureDirectory($cachedir);
3358 3559
 
3359 3560
 			// If agreement is enabled, at least the english version shall exists
3360
-			if ($modSettings['requireAgreement'])
3361
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3561
+			if ($modSettings['requireAgreement']) {
3562
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3563
+			}
3362 3564
 
3363 3565
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3364 3566
 			{
@@ -3373,18 +3575,21 @@  discard block
 block discarded – undo
3373 3575
 					echo '
3374 3576
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3375 3577
 
3376
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3377
-						echo '
3578
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3579
+											echo '
3378 3580
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3581
+					}
3379 3582
 				}
3380 3583
 
3381
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3382
-					echo '
3584
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3585
+									echo '
3383 3586
 				<strong>', $txt['cache_writable'], '</strong><br>';
3587
+				}
3384 3588
 
3385
-				if (!empty($agreement))
3386
-					echo '
3589
+				if (!empty($agreement)) {
3590
+									echo '
3387 3591
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3592
+				}
3388 3593
 
3389 3594
 				echo '
3390 3595
 			</p>
@@ -3399,16 +3604,18 @@  discard block
 block discarded – undo
3399 3604
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3400 3605
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3401 3606
 
3402
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3403
-				echo '
3607
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3608
+							echo '
3404 3609
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3610
+			}
3405 3611
 
3406
-			if (!empty($_SESSION['ban']['expire_time']))
3407
-				echo '
3612
+			if (!empty($_SESSION['ban']['expire_time'])) {
3613
+							echo '
3408 3614
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3409
-			else
3410
-				echo '
3615
+			} else {
3616
+							echo '
3411 3617
 					<div>', $txt['your_ban_expires_never'], '</div>';
3618
+			}
3412 3619
 
3413 3620
 			echo '
3414 3621
 				</div>';
@@ -3424,8 +3631,9 @@  discard block
 block discarded – undo
3424 3631
 	global $forum_copyright, $software_year, $forum_version;
3425 3632
 
3426 3633
 	// Don't display copyright for things like SSI.
3427
-	if (!isset($forum_version) || !isset($software_year))
3428
-		return;
3634
+	if (!isset($forum_version) || !isset($software_year)) {
3635
+			return;
3636
+	}
3429 3637
 
3430 3638
 	// Put in the version...
3431 3639
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3443,9 +3651,10 @@  discard block
 block discarded – undo
3443 3651
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3444 3652
 	$context['load_queries'] = $db_count;
3445 3653
 
3446
-	foreach (array_reverse($context['template_layers']) as $layer)
3447
-		loadSubTemplate($layer . '_below', true);
3448
-}
3654
+	foreach (array_reverse($context['template_layers']) as $layer) {
3655
+			loadSubTemplate($layer . '_below', true);
3656
+	}
3657
+	}
3449 3658
 
3450 3659
 /**
3451 3660
  * Output the Javascript files
@@ -3476,8 +3685,7 @@  discard block
 block discarded – undo
3476 3685
 			{
3477 3686
 				echo '
3478 3687
 		var ', $key, ';';
3479
-			}
3480
-			else
3688
+			} else
3481 3689
 			{
3482 3690
 				echo '
3483 3691
 		var ', $key, ' = ', $value, ';';
@@ -3492,26 +3700,27 @@  discard block
 block discarded – undo
3492 3700
 	foreach ($context['javascript_files'] as $id => $js_file)
3493 3701
 	{
3494 3702
 		// Last minute call! allow theme authors to disable single files.
3495
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3496
-			continue;
3703
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3704
+					continue;
3705
+		}
3497 3706
 
3498 3707
 		// By default all files don't get minimized unless the file explicitly says so!
3499 3708
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3500 3709
 		{
3501
-			if ($do_deferred && !empty($js_file['options']['defer']))
3502
-				$toMinifyDefer[] = $js_file;
3503
-
3504
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3505
-				$toMinify[] = $js_file;
3710
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3711
+							$toMinifyDefer[] = $js_file;
3712
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3713
+							$toMinify[] = $js_file;
3714
+			}
3506 3715
 
3507 3716
 			// Grab a random seed.
3508
-			if (!isset($minSeed))
3509
-				$minSeed = $js_file['options']['seed'];
3510
-		}
3511
-
3512
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3513
-			echo '
3717
+			if (!isset($minSeed)) {
3718
+							$minSeed = $js_file['options']['seed'];
3719
+			}
3720
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3721
+					echo '
3514 3722
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3723
+		}
3515 3724
 	}
3516 3725
 
3517 3726
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3519,14 +3728,14 @@  discard block
 block discarded – undo
3519 3728
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3520 3729
 
3521 3730
 		// Minify process couldn't work, print each individual files.
3522
-		if (!empty($result) && is_array($result))
3523
-			foreach ($result as $minFailedFile)
3731
+		if (!empty($result) && is_array($result)) {
3732
+					foreach ($result as $minFailedFile)
3524 3733
 				echo '
3525 3734
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3526
-
3527
-		else
3528
-			echo '
3735
+		} else {
3736
+					echo '
3529 3737
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3738
+		}
3530 3739
 	}
3531 3740
 
3532 3741
 	// Inline JavaScript - Actually useful some times!
@@ -3537,8 +3746,9 @@  discard block
 block discarded – undo
3537 3746
 			echo '
3538 3747
 <script>';
3539 3748
 
3540
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3541
-				echo $js_code;
3749
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3750
+							echo $js_code;
3751
+			}
3542 3752
 
3543 3753
 			echo '
3544 3754
 </script>';
@@ -3549,8 +3759,9 @@  discard block
 block discarded – undo
3549 3759
 			echo '
3550 3760
 	<script>';
3551 3761
 
3552
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3553
-				echo $js_code;
3762
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3763
+							echo $js_code;
3764
+			}
3554 3765
 
3555 3766
 			echo '
3556 3767
 	</script>';
@@ -3575,8 +3786,9 @@  discard block
 block discarded – undo
3575 3786
 	foreach ($context['css_files'] as $id => $file)
3576 3787
 	{
3577 3788
 		// Last minute call! allow theme authors to disable single files.
3578
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3579
-			continue;
3789
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3790
+					continue;
3791
+		}
3580 3792
 
3581 3793
 		// By default all files don't get minimized unless the file explicitly says so!
3582 3794
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3584,12 +3796,12 @@  discard block
 block discarded – undo
3584 3796
 			$toMinify[] = $file;
3585 3797
 
3586 3798
 			// Grab a random seed.
3587
-			if (!isset($minSeed))
3588
-				$minSeed = $file['options']['seed'];
3799
+			if (!isset($minSeed)) {
3800
+							$minSeed = $file['options']['seed'];
3801
+			}
3802
+		} else {
3803
+					$normal[] = $file['fileUrl'];
3589 3804
 		}
3590
-
3591
-		else
3592
-			$normal[] = $file['fileUrl'];
3593 3805
 	}
3594 3806
 
3595 3807
 	if (!empty($toMinify))
@@ -3597,28 +3809,30 @@  discard block
 block discarded – undo
3597 3809
 		$result = custMinify($toMinify, 'css');
3598 3810
 
3599 3811
 		// Minify process couldn't work, print each individual files.
3600
-		if (!empty($result) && is_array($result))
3601
-			foreach ($result as $minFailedFile)
3812
+		if (!empty($result) && is_array($result)) {
3813
+					foreach ($result as $minFailedFile)
3602 3814
 				echo '
3603 3815
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3604
-
3605
-		else
3606
-			echo '
3816
+		} else {
3817
+					echo '
3607 3818
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3819
+		}
3608 3820
 	}
3609 3821
 
3610 3822
 	// Print the rest after the minified files.
3611
-	if (!empty($normal))
3612
-		foreach ($normal as $nf)
3823
+	if (!empty($normal)) {
3824
+			foreach ($normal as $nf)
3613 3825
 			echo '
3614 3826
 	<link rel="stylesheet" href="', $nf ,'">';
3827
+	}
3615 3828
 
3616 3829
 	if ($db_show_debug === true)
3617 3830
 	{
3618 3831
 		// Try to keep only what's useful.
3619 3832
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3620
-		foreach ($context['css_files'] as $file)
3621
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3833
+		foreach ($context['css_files'] as $file) {
3834
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3835
+		}
3622 3836
 	}
3623 3837
 
3624 3838
 	if (!empty($context['css_header']))
@@ -3626,9 +3840,10 @@  discard block
 block discarded – undo
3626 3840
 		echo '
3627 3841
 	<style>';
3628 3842
 
3629
-		foreach ($context['css_header'] as $css)
3630
-			echo $css .'
3843
+		foreach ($context['css_header'] as $css) {
3844
+					echo $css .'
3631 3845
 	';
3846
+		}
3632 3847
 
3633 3848
 		echo'
3634 3849
 	</style>';
@@ -3652,15 +3867,17 @@  discard block
 block discarded – undo
3652 3867
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3653 3868
 	$data = !empty($data) ? $data : false;
3654 3869
 
3655
-	if (empty($type) || empty($data))
3656
-		return false;
3870
+	if (empty($type) || empty($data)) {
3871
+			return false;
3872
+	}
3657 3873
 
3658 3874
 	// Did we already did this?
3659 3875
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3660 3876
 
3661 3877
 	// Already done?
3662
-	if (!empty($toCache))
3663
-		return true;
3878
+	if (!empty($toCache)) {
3879
+			return true;
3880
+	}
3664 3881
 
3665 3882
 	// No namespaces, sorry!
3666 3883
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3742,8 +3959,9 @@  discard block
 block discarded – undo
3742 3959
 	global $modSettings, $smcFunc;
3743 3960
 
3744 3961
 	// Just make up a nice hash...
3745
-	if ($new)
3746
-		return sha1(md5($filename . time()) . mt_rand());
3962
+	if ($new) {
3963
+			return sha1(md5($filename . time()) . mt_rand());
3964
+	}
3747 3965
 
3748 3966
 	// Just make sure that attachment id is only a int
3749 3967
 	$attachment_id = (int) $attachment_id;
@@ -3760,23 +3978,25 @@  discard block
 block discarded – undo
3760 3978
 				'id_attach' => $attachment_id,
3761 3979
 			));
3762 3980
 
3763
-		if ($smcFunc['db_num_rows']($request) === 0)
3764
-			return false;
3981
+		if ($smcFunc['db_num_rows']($request) === 0) {
3982
+					return false;
3983
+		}
3765 3984
 
3766 3985
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3767 3986
 		$smcFunc['db_free_result']($request);
3768 3987
 	}
3769 3988
 
3770 3989
 	// Still no hash? mmm...
3771
-	if (empty($file_hash))
3772
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3990
+	if (empty($file_hash)) {
3991
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3992
+	}
3773 3993
 
3774 3994
 	// Are we using multiple directories?
3775
-	if (is_array($modSettings['attachmentUploadDir']))
3776
-		$path = $modSettings['attachmentUploadDir'][$dir];
3777
-
3778
-	else
3779
-		$path = $modSettings['attachmentUploadDir'];
3995
+	if (is_array($modSettings['attachmentUploadDir'])) {
3996
+			$path = $modSettings['attachmentUploadDir'][$dir];
3997
+	} else {
3998
+			$path = $modSettings['attachmentUploadDir'];
3999
+	}
3780 4000
 
3781 4001
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3782 4002
 }
@@ -3791,8 +4011,9 @@  discard block
 block discarded – undo
3791 4011
 function ip2range($fullip)
3792 4012
 {
3793 4013
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3794
-	if ($fullip == 'unknown')
3795
-		$fullip = '255.255.255.255';
4014
+	if ($fullip == 'unknown') {
4015
+			$fullip = '255.255.255.255';
4016
+	}
3796 4017
 
3797 4018
 	$ip_parts = explode('-', $fullip);
3798 4019
 	$ip_array = array();
@@ -3816,10 +4037,11 @@  discard block
 block discarded – undo
3816 4037
 		$ip_array['low'] = $ip_parts[0];
3817 4038
 		$ip_array['high'] = $ip_parts[1];
3818 4039
 		return $ip_array;
3819
-	}
3820
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4040
+	} elseif (count($ip_parts) == 2) {
4041
+		// if ip 22.22.*-22.22.*
3821 4042
 	{
3822 4043
 		$valid_low = isValidIP($ip_parts[0]);
4044
+	}
3823 4045
 		$valid_high = isValidIP($ip_parts[1]);
3824 4046
 		$count = 0;
3825 4047
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3834,7 +4056,9 @@  discard block
 block discarded – undo
3834 4056
 				$ip_parts[0] .= $mode . $min;
3835 4057
 				$valid_low = isValidIP($ip_parts[0]);
3836 4058
 				$count++;
3837
-				if ($count > 9) break;
4059
+				if ($count > 9) {
4060
+					break;
4061
+				}
3838 4062
 			}
3839 4063
 		}
3840 4064
 
@@ -3848,7 +4072,9 @@  discard block
 block discarded – undo
3848 4072
 				$ip_parts[1] .= $mode . $max;
3849 4073
 				$valid_high = isValidIP($ip_parts[1]);
3850 4074
 				$count++;
3851
-				if ($count > 9) break;
4075
+				if ($count > 9) {
4076
+					break;
4077
+				}
3852 4078
 			}
3853 4079
 		}
3854 4080
 
@@ -3873,46 +4099,54 @@  discard block
 block discarded – undo
3873 4099
 {
3874 4100
 	global $modSettings;
3875 4101
 
3876
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3877
-		return $host;
4102
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4103
+			return $host;
4104
+	}
3878 4105
 	$t = microtime();
3879 4106
 
3880 4107
 	// Try the Linux host command, perhaps?
3881 4108
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3882 4109
 	{
3883
-		if (!isset($modSettings['host_to_dis']))
3884
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3885
-		else
3886
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4110
+		if (!isset($modSettings['host_to_dis'])) {
4111
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4112
+		} else {
4113
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4114
+		}
3887 4115
 
3888 4116
 		// Did host say it didn't find anything?
3889
-		if (strpos($test, 'not found') !== false)
3890
-			$host = '';
4117
+		if (strpos($test, 'not found') !== false) {
4118
+					$host = '';
4119
+		}
3891 4120
 		// Invalid server option?
3892
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3893
-			updateSettings(array('host_to_dis' => 1));
4121
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4122
+					updateSettings(array('host_to_dis' => 1));
4123
+		}
3894 4124
 		// Maybe it found something, after all?
3895
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3896
-			$host = $match[1];
4125
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4126
+					$host = $match[1];
4127
+		}
3897 4128
 	}
3898 4129
 
3899 4130
 	// This is nslookup; usually only Windows, but possibly some Unix?
3900 4131
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3901 4132
 	{
3902 4133
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3903
-		if (strpos($test, 'Non-existent domain') !== false)
3904
-			$host = '';
3905
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3906
-			$host = $match[1];
4134
+		if (strpos($test, 'Non-existent domain') !== false) {
4135
+					$host = '';
4136
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4137
+					$host = $match[1];
4138
+		}
3907 4139
 	}
3908 4140
 
3909 4141
 	// This is the last try :/.
3910
-	if (!isset($host) || $host === false)
3911
-		$host = @gethostbyaddr($ip);
4142
+	if (!isset($host) || $host === false) {
4143
+			$host = @gethostbyaddr($ip);
4144
+	}
3912 4145
 
3913 4146
 	// It took a long time, so let's cache it!
3914
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3915
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4147
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4148
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4149
+	}
3916 4150
 
3917 4151
 	return $host;
3918 4152
 }
@@ -3948,20 +4182,21 @@  discard block
 block discarded – undo
3948 4182
 			{
3949 4183
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3950 4184
 				$total = 0;
3951
-				for ($i = 0; $i < $max_chars; $i++)
3952
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4185
+				for ($i = 0; $i < $max_chars; $i++) {
4186
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4187
+				}
3953 4188
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3954 4189
 			}
3955 4190
 		}
3956 4191
 		return array_unique($returned_ints);
3957
-	}
3958
-	else
4192
+	} else
3959 4193
 	{
3960 4194
 		// Trim characters before and after and add slashes for database insertion.
3961 4195
 		$returned_words = array();
3962
-		foreach ($words as $word)
3963
-			if (($word = trim($word, '-_\'')) !== '')
4196
+		foreach ($words as $word) {
4197
+					if (($word = trim($word, '-_\'')) !== '')
3964 4198
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4199
+		}
3965 4200
 
3966 4201
 		// Filter out all words that occur more than once.
3967 4202
 		return array_unique($returned_words);
@@ -3983,16 +4218,18 @@  discard block
 block discarded – undo
3983 4218
 	global $settings, $txt;
3984 4219
 
3985 4220
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3986
-	if (function_exists('template_create_button') && !$force_use)
3987
-		return template_create_button($name, $alt, $label = '', $custom = '');
4221
+	if (function_exists('template_create_button') && !$force_use) {
4222
+			return template_create_button($name, $alt, $label = '', $custom = '');
4223
+	}
3988 4224
 
3989
-	if (!$settings['use_image_buttons'])
3990
-		return $txt[$alt];
3991
-	elseif (!empty($settings['use_buttons']))
3992
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3993
-	else
3994
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3995
-}
4225
+	if (!$settings['use_image_buttons']) {
4226
+			return $txt[$alt];
4227
+	} elseif (!empty($settings['use_buttons'])) {
4228
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4229
+	} else {
4230
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4231
+	}
4232
+	}
3996 4233
 
3997 4234
 /**
3998 4235
  * Sets up all of the top menu buttons
@@ -4035,9 +4272,10 @@  discard block
 block discarded – undo
4035 4272
 	var user_menus = new smc_PopupMenu();
4036 4273
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4037 4274
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4038
-		if ($context['allow_pm'])
4039
-			addInlineJavaScript('
4275
+		if ($context['allow_pm']) {
4276
+					addInlineJavaScript('
4040 4277
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4278
+		}
4041 4279
 
4042 4280
 		if (!empty($modSettings['enable_ajax_alerts']))
4043 4281
 		{
@@ -4197,88 +4435,96 @@  discard block
 block discarded – undo
4197 4435
 
4198 4436
 		// Now we put the buttons in the context so the theme can use them.
4199 4437
 		$menu_buttons = array();
4200
-		foreach ($buttons as $act => $button)
4201
-			if (!empty($button['show']))
4438
+		foreach ($buttons as $act => $button) {
4439
+					if (!empty($button['show']))
4202 4440
 			{
4203 4441
 				$button['active_button'] = false;
4442
+		}
4204 4443
 
4205 4444
 				// This button needs some action.
4206
-				if (isset($button['action_hook']))
4207
-					$needs_action_hook = true;
4445
+				if (isset($button['action_hook'])) {
4446
+									$needs_action_hook = true;
4447
+				}
4208 4448
 
4209 4449
 				// Make sure the last button truly is the last button.
4210 4450
 				if (!empty($button['is_last']))
4211 4451
 				{
4212
-					if (isset($last_button))
4213
-						unset($menu_buttons[$last_button]['is_last']);
4452
+					if (isset($last_button)) {
4453
+											unset($menu_buttons[$last_button]['is_last']);
4454
+					}
4214 4455
 					$last_button = $act;
4215 4456
 				}
4216 4457
 
4217 4458
 				// Go through the sub buttons if there are any.
4218
-				if (!empty($button['sub_buttons']))
4219
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4459
+				if (!empty($button['sub_buttons'])) {
4460
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4220 4461
 					{
4221 4462
 						if (empty($subbutton['show']))
4222 4463
 							unset($button['sub_buttons'][$key]);
4464
+				}
4223 4465
 
4224 4466
 						// 2nd level sub buttons next...
4225 4467
 						if (!empty($subbutton['sub_buttons']))
4226 4468
 						{
4227 4469
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4228 4470
 							{
4229
-								if (empty($sub_button2['show']))
4230
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4471
+								if (empty($sub_button2['show'])) {
4472
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4473
+								}
4231 4474
 							}
4232 4475
 						}
4233 4476
 					}
4234 4477
 
4235 4478
 				// Does this button have its own icon?
4236
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4237
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4238
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4239
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4240
-				elseif (isset($button['icon']))
4241
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4242
-				else
4243
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4479
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4480
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4481
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4482
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4483
+				} elseif (isset($button['icon'])) {
4484
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4485
+				} else {
4486
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4487
+				}
4244 4488
 
4245 4489
 				$menu_buttons[$act] = $button;
4246 4490
 			}
4247 4491
 
4248
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4249
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4492
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4493
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4494
+		}
4250 4495
 	}
4251 4496
 
4252 4497
 	$context['menu_buttons'] = $menu_buttons;
4253 4498
 
4254 4499
 	// Logging out requires the session id in the url.
4255
-	if (isset($context['menu_buttons']['logout']))
4256
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4500
+	if (isset($context['menu_buttons']['logout'])) {
4501
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4502
+	}
4257 4503
 
4258 4504
 	// Figure out which action we are doing so we can set the active tab.
4259 4505
 	// Default to home.
4260 4506
 	$current_action = 'home';
4261 4507
 
4262
-	if (isset($context['menu_buttons'][$context['current_action']]))
4263
-		$current_action = $context['current_action'];
4264
-	elseif ($context['current_action'] == 'search2')
4265
-		$current_action = 'search';
4266
-	elseif ($context['current_action'] == 'theme')
4267
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4268
-	elseif ($context['current_action'] == 'register2')
4269
-		$current_action = 'register';
4270
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4271
-		$current_action = 'login';
4272
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4273
-		$current_action = 'moderate';
4508
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4509
+			$current_action = $context['current_action'];
4510
+	} elseif ($context['current_action'] == 'search2') {
4511
+			$current_action = 'search';
4512
+	} elseif ($context['current_action'] == 'theme') {
4513
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4514
+	} elseif ($context['current_action'] == 'register2') {
4515
+			$current_action = 'register';
4516
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4517
+			$current_action = 'login';
4518
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4519
+			$current_action = 'moderate';
4520
+	}
4274 4521
 
4275 4522
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4276 4523
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4277 4524
 	{
4278 4525
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4279 4526
 		$context[$current_action] = true;
4280
-	}
4281
-	elseif ($context['current_action'] == 'pm')
4527
+	} elseif ($context['current_action'] == 'pm')
4282 4528
 	{
4283 4529
 		$current_action = 'self_pm';
4284 4530
 		$context['self_pm'] = true;
@@ -4319,12 +4565,14 @@  discard block
 block discarded – undo
4319 4565
 	}
4320 4566
 
4321 4567
 	// Not all actions are simple.
4322
-	if (!empty($needs_action_hook))
4323
-		call_integration_hook('integrate_current_action', array(&$current_action));
4568
+	if (!empty($needs_action_hook)) {
4569
+			call_integration_hook('integrate_current_action', array(&$current_action));
4570
+	}
4324 4571
 
4325
-	if (isset($context['menu_buttons'][$current_action]))
4326
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4327
-}
4572
+	if (isset($context['menu_buttons'][$current_action])) {
4573
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4574
+	}
4575
+	}
4328 4576
 
4329 4577
 /**
4330 4578
  * Generate a random seed and ensure it's stored in settings.
@@ -4348,30 +4596,35 @@  discard block
 block discarded – undo
4348 4596
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4349 4597
 	global $context, $txt;
4350 4598
 
4351
-	if ($db_show_debug === true)
4352
-		$context['debug']['hooks'][] = $hook;
4599
+	if ($db_show_debug === true) {
4600
+			$context['debug']['hooks'][] = $hook;
4601
+	}
4353 4602
 
4354 4603
 	// Need to have some control.
4355
-	if (!isset($context['instances']))
4356
-		$context['instances'] = array();
4604
+	if (!isset($context['instances'])) {
4605
+			$context['instances'] = array();
4606
+	}
4357 4607
 
4358 4608
 	$results = array();
4359
-	if (empty($modSettings[$hook]))
4360
-		return $results;
4609
+	if (empty($modSettings[$hook])) {
4610
+			return $results;
4611
+	}
4361 4612
 
4362 4613
 	$functions = explode(',', $modSettings[$hook]);
4363 4614
 	// Loop through each function.
4364 4615
 	foreach ($functions as $function)
4365 4616
 	{
4366 4617
 		// Hook has been marked as "disabled". Skip it!
4367
-		if (strpos($function, '!') !== false)
4368
-			continue;
4618
+		if (strpos($function, '!') !== false) {
4619
+					continue;
4620
+		}
4369 4621
 
4370 4622
 		$call = call_helper($function, true);
4371 4623
 
4372 4624
 		// Is it valid?
4373
-		if (!empty($call))
4374
-			$results[$function] = call_user_func_array($call, $parameters);
4625
+		if (!empty($call)) {
4626
+					$results[$function] = call_user_func_array($call, $parameters);
4627
+		}
4375 4628
 
4376 4629
 		// Whatever it was suppose to call, it failed :(
4377 4630
 		elseif (!empty($function))
@@ -4387,8 +4640,9 @@  discard block
 block discarded – undo
4387 4640
 			}
4388 4641
 
4389 4642
 			// "Assume" the file resides on $boarddir somewhere...
4390
-			else
4391
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4643
+			else {
4644
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4645
+			}
4392 4646
 		}
4393 4647
 	}
4394 4648
 
@@ -4410,12 +4664,14 @@  discard block
 block discarded – undo
4410 4664
 	global $smcFunc, $modSettings;
4411 4665
 
4412 4666
 	// Any objects?
4413
-	if ($object)
4414
-		$function = $function . '#';
4667
+	if ($object) {
4668
+			$function = $function . '#';
4669
+	}
4415 4670
 
4416 4671
 	// Any files  to load?
4417
-	if (!empty($file) && is_string($file))
4418
-		$function = $file . (!empty($function) ? '|' . $function : '');
4672
+	if (!empty($file) && is_string($file)) {
4673
+			$function = $file . (!empty($function) ? '|' . $function : '');
4674
+	}
4419 4675
 
4420 4676
 	// Get the correct string.
4421 4677
 	$integration_call = $function;
@@ -4437,13 +4693,14 @@  discard block
 block discarded – undo
4437 4693
 		if (!empty($current_functions))
4438 4694
 		{
4439 4695
 			$current_functions = explode(',', $current_functions);
4440
-			if (in_array($integration_call, $current_functions))
4441
-				return;
4696
+			if (in_array($integration_call, $current_functions)) {
4697
+							return;
4698
+			}
4442 4699
 
4443 4700
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4701
+		} else {
4702
+					$permanent_functions = array($integration_call);
4444 4703
 		}
4445
-		else
4446
-			$permanent_functions = array($integration_call);
4447 4704
 
4448 4705
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4449 4706
 	}
@@ -4452,8 +4709,9 @@  discard block
 block discarded – undo
4452 4709
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4453 4710
 
4454 4711
 	// Do nothing, if it's already there.
4455
-	if (in_array($integration_call, $functions))
4456
-		return;
4712
+	if (in_array($integration_call, $functions)) {
4713
+			return;
4714
+	}
4457 4715
 
4458 4716
 	$functions[] = $integration_call;
4459 4717
 	$modSettings[$hook] = implode(',', $functions);
@@ -4476,12 +4734,14 @@  discard block
 block discarded – undo
4476 4734
 	global $smcFunc, $modSettings;
4477 4735
 
4478 4736
 	// Any objects?
4479
-	if ($object)
4480
-		$function = $function . '#';
4737
+	if ($object) {
4738
+			$function = $function . '#';
4739
+	}
4481 4740
 
4482 4741
 	// Any files  to load?
4483
-	if (!empty($file) && is_string($file))
4484
-		$function = $file . '|' . $function;
4742
+	if (!empty($file) && is_string($file)) {
4743
+			$function = $file . '|' . $function;
4744
+	}
4485 4745
 
4486 4746
 	// Get the correct string.
4487 4747
 	$integration_call = $function;
@@ -4502,16 +4762,18 @@  discard block
 block discarded – undo
4502 4762
 	{
4503 4763
 		$current_functions = explode(',', $current_functions);
4504 4764
 
4505
-		if (in_array($integration_call, $current_functions))
4506
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4765
+		if (in_array($integration_call, $current_functions)) {
4766
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4767
+		}
4507 4768
 	}
4508 4769
 
4509 4770
 	// Turn the function list into something usable.
4510 4771
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4511 4772
 
4512 4773
 	// You can only remove it if it's available.
4513
-	if (!in_array($integration_call, $functions))
4514
-		return;
4774
+	if (!in_array($integration_call, $functions)) {
4775
+			return;
4776
+	}
4515 4777
 
4516 4778
 	$functions = array_diff($functions, array($integration_call));
4517 4779
 	$modSettings[$hook] = implode(',', $functions);
@@ -4532,17 +4794,20 @@  discard block
 block discarded – undo
4532 4794
 	global $context, $smcFunc, $txt, $db_show_debug;
4533 4795
 
4534 4796
 	// Really?
4535
-	if (empty($string))
4536
-		return false;
4797
+	if (empty($string)) {
4798
+			return false;
4799
+	}
4537 4800
 
4538 4801
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4539 4802
 	// A closure? should be a callable one.
4540
-	if (is_array($string) || $string instanceof Closure)
4541
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4803
+	if (is_array($string) || $string instanceof Closure) {
4804
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4805
+	}
4542 4806
 
4543 4807
 	// No full objects, sorry! pass a method or a property instead!
4544
-	if (is_object($string))
4545
-		return false;
4808
+	if (is_object($string)) {
4809
+			return false;
4810
+	}
4546 4811
 
4547 4812
 	// Stay vitaminized my friends...
4548 4813
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4551,8 +4816,9 @@  discard block
 block discarded – undo
4551 4816
 	$string = load_file($string);
4552 4817
 
4553 4818
 	// Loaded file failed
4554
-	if (empty($string))
4555
-		return false;
4819
+	if (empty($string)) {
4820
+			return false;
4821
+	}
4556 4822
 
4557 4823
 	// Found a method.
4558 4824
 	if (strpos($string, '::') !== false)
@@ -4573,8 +4839,9 @@  discard block
 block discarded – undo
4573 4839
 				// Add another one to the list.
4574 4840
 				if ($db_show_debug === true)
4575 4841
 				{
4576
-					if (!isset($context['debug']['instances']))
4577
-						$context['debug']['instances'] = array();
4842
+					if (!isset($context['debug']['instances'])) {
4843
+											$context['debug']['instances'] = array();
4844
+					}
4578 4845
 
4579 4846
 					$context['debug']['instances'][$class] = $class;
4580 4847
 				}
@@ -4584,13 +4851,15 @@  discard block
 block discarded – undo
4584 4851
 		}
4585 4852
 
4586 4853
 		// Right then. This is a call to a static method.
4587
-		else
4588
-			$func = array($class, $method);
4854
+		else {
4855
+					$func = array($class, $method);
4856
+		}
4589 4857
 	}
4590 4858
 
4591 4859
 	// Nope! just a plain regular function.
4592
-	else
4593
-		$func = $string;
4860
+	else {
4861
+			$func = $string;
4862
+	}
4594 4863
 
4595 4864
 	// Right, we got what we need, time to do some checks.
4596 4865
 	if (!is_callable($func, false, $callable_name))
@@ -4606,17 +4875,18 @@  discard block
 block discarded – undo
4606 4875
 	else
4607 4876
 	{
4608 4877
 		// What are we gonna do about it?
4609
-		if ($return)
4610
-			return $func;
4878
+		if ($return) {
4879
+					return $func;
4880
+		}
4611 4881
 
4612 4882
 		// If this is a plain function, avoid the heat of calling call_user_func().
4613 4883
 		else
4614 4884
 		{
4615
-			if (is_array($func))
4616
-				call_user_func($func);
4617
-
4618
-			else
4619
-				$func();
4885
+			if (is_array($func)) {
4886
+							call_user_func($func);
4887
+			} else {
4888
+							$func();
4889
+			}
4620 4890
 		}
4621 4891
 	}
4622 4892
 }
@@ -4633,31 +4903,34 @@  discard block
 block discarded – undo
4633 4903
 {
4634 4904
 	global $sourcedir, $txt, $boarddir, $settings;
4635 4905
 
4636
-	if (empty($string))
4637
-		return false;
4906
+	if (empty($string)) {
4907
+			return false;
4908
+	}
4638 4909
 
4639 4910
 	if (strpos($string, '|') !== false)
4640 4911
 	{
4641 4912
 		list ($file, $string) = explode('|', $string);
4642 4913
 
4643 4914
 		// Match the wildcards to their regular vars.
4644
-		if (empty($settings['theme_dir']))
4645
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4646
-
4647
-		else
4648
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4915
+		if (empty($settings['theme_dir'])) {
4916
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4917
+		} else {
4918
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4919
+		}
4649 4920
 
4650 4921
 		// Load the file if it can be loaded.
4651
-		if (file_exists($absPath))
4652
-			require_once($absPath);
4922
+		if (file_exists($absPath)) {
4923
+					require_once($absPath);
4924
+		}
4653 4925
 
4654 4926
 		// No? try a fallback to $sourcedir
4655 4927
 		else
4656 4928
 		{
4657 4929
 			$absPath = $sourcedir .'/'. $file;
4658 4930
 
4659
-			if (file_exists($absPath))
4660
-				require_once($absPath);
4931
+			if (file_exists($absPath)) {
4932
+							require_once($absPath);
4933
+			}
4661 4934
 
4662 4935
 			// Sorry, can't do much for you at this point.
4663 4936
 			else
@@ -4684,8 +4957,9 @@  discard block
 block discarded – undo
4684 4957
 	global $user_info, $smcFunc;
4685 4958
 
4686 4959
 	// Make sure we have something to work with.
4687
-	if (empty($topic))
4688
-		return array();
4960
+	if (empty($topic)) {
4961
+			return array();
4962
+	}
4689 4963
 
4690 4964
 
4691 4965
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4708,8 +4982,9 @@  discard block
 block discarded – undo
4708 4982
 				'topic' => $topic,
4709 4983
 			)
4710 4984
 		);
4711
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4712
-			$temp[] = (int) $row['content_id'];
4985
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4986
+					$temp[] = (int) $row['content_id'];
4987
+		}
4713 4988
 
4714 4989
 		cache_put_data($cache_key, $temp, $ttl);
4715 4990
 	}
@@ -4730,8 +5005,9 @@  discard block
 block discarded – undo
4730 5005
 {
4731 5006
 	global $context;
4732 5007
 
4733
-	if (empty($string))
4734
-		return $string;
5008
+	if (empty($string)) {
5009
+			return $string;
5010
+	}
4735 5011
 
4736 5012
 	// UTF-8 occurences of MS special characters
4737 5013
 	$findchars_utf8 = array(
@@ -4772,10 +5048,11 @@  discard block
 block discarded – undo
4772 5048
 		'--',	// &mdash;
4773 5049
 	);
4774 5050
 
4775
-	if ($context['utf8'])
4776
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4777
-	else
4778
-		$string = str_replace($findchars_iso, $replacechars, $string);
5051
+	if ($context['utf8']) {
5052
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5053
+	} else {
5054
+			$string = str_replace($findchars_iso, $replacechars, $string);
5055
+	}
4779 5056
 
4780 5057
 	return $string;
4781 5058
 }
@@ -4794,49 +5071,59 @@  discard block
 block discarded – undo
4794 5071
 {
4795 5072
 	global $context;
4796 5073
 
4797
-	if (!isset($matches[2]))
4798
-		return '';
5074
+	if (!isset($matches[2])) {
5075
+			return '';
5076
+	}
4799 5077
 
4800 5078
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4801 5079
 
4802 5080
 	// remove left to right / right to left overrides
4803
-	if ($num === 0x202D || $num === 0x202E)
4804
-		return '';
5081
+	if ($num === 0x202D || $num === 0x202E) {
5082
+			return '';
5083
+	}
4805 5084
 
4806 5085
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4807
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4808
-		return '&#' . $num . ';';
5086
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5087
+			return '&#' . $num . ';';
5088
+	}
4809 5089
 
4810 5090
 	if (empty($context['utf8']))
4811 5091
 	{
4812 5092
 		// no control characters
4813
-		if ($num < 0x20)
4814
-			return '';
5093
+		if ($num < 0x20) {
5094
+					return '';
5095
+		}
4815 5096
 		// text is text
4816
-		elseif ($num < 0x80)
4817
-			return chr($num);
5097
+		elseif ($num < 0x80) {
5098
+					return chr($num);
5099
+		}
4818 5100
 		// all others get html-ised
4819
-		else
4820
-			return '&#' . $matches[2] . ';';
4821
-	}
4822
-	else
5101
+		else {
5102
+					return '&#' . $matches[2] . ';';
5103
+		}
5104
+	} else
4823 5105
 	{
4824 5106
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4825 5107
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4826
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4827
-			return '';
5108
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5109
+					return '';
5110
+		}
4828 5111
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4829
-		elseif ($num < 0x80)
4830
-			return chr($num);
5112
+		elseif ($num < 0x80) {
5113
+					return chr($num);
5114
+		}
4831 5115
 		// <0x800 (2048)
4832
-		elseif ($num < 0x800)
4833
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5116
+		elseif ($num < 0x800) {
5117
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5118
+		}
4834 5119
 		// < 0x10000 (65536)
4835
-		elseif ($num < 0x10000)
4836
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5120
+		elseif ($num < 0x10000) {
5121
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5122
+		}
4837 5123
 		// <= 0x10FFFF (1114111)
4838
-		else
4839
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5124
+		else {
5125
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5126
+		}
4840 5127
 	}
4841 5128
 }
4842 5129
 
@@ -4852,28 +5139,34 @@  discard block
 block discarded – undo
4852 5139
  */
4853 5140
 function fixchar__callback($matches)
4854 5141
 {
4855
-	if (!isset($matches[1]))
4856
-		return '';
5142
+	if (!isset($matches[1])) {
5143
+			return '';
5144
+	}
4857 5145
 
4858 5146
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4859 5147
 
4860 5148
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4861 5149
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4862
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4863
-		return '';
5150
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5151
+			return '';
5152
+	}
4864 5153
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4865
-	elseif ($num < 0x80)
4866
-		return chr($num);
5154
+	elseif ($num < 0x80) {
5155
+			return chr($num);
5156
+	}
4867 5157
 	// <0x800 (2048)
4868
-	elseif ($num < 0x800)
4869
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5158
+	elseif ($num < 0x800) {
5159
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5160
+	}
4870 5161
 	// < 0x10000 (65536)
4871
-	elseif ($num < 0x10000)
4872
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5162
+	elseif ($num < 0x10000) {
5163
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5164
+	}
4873 5165
 	// <= 0x10FFFF (1114111)
4874
-	else
4875
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4876
-}
5166
+	else {
5167
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5168
+	}
5169
+	}
4877 5170
 
4878 5171
 /**
4879 5172
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4886,17 +5179,19 @@  discard block
 block discarded – undo
4886 5179
  */
4887 5180
 function entity_fix__callback($matches)
4888 5181
 {
4889
-	if (!isset($matches[2]))
4890
-		return '';
5182
+	if (!isset($matches[2])) {
5183
+			return '';
5184
+	}
4891 5185
 
4892 5186
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4893 5187
 
4894 5188
 	// we don't allow control characters, characters out of range, byte markers, etc
4895
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4896
-		return '';
4897
-	else
4898
-		return '&#' . $num . ';';
4899
-}
5189
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5190
+			return '';
5191
+	} else {
5192
+			return '&#' . $num . ';';
5193
+	}
5194
+	}
4900 5195
 
4901 5196
 /**
4902 5197
  * Return a Gravatar URL based on
@@ -4920,18 +5215,23 @@  discard block
 block discarded – undo
4920 5215
 		$ratings = array('G', 'PG', 'R', 'X');
4921 5216
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4922 5217
 		$url_params = array();
4923
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4924
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4925
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4926
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4927
-		if (!empty($modSettings['avatar_max_width_external']))
4928
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4929
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4930
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5218
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5219
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5220
+		}
5221
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5222
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5223
+		}
5224
+		if (!empty($modSettings['avatar_max_width_external'])) {
5225
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5226
+		}
5227
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5228
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4931 5229
 				$size_string = $modSettings['avatar_max_height_external'];
5230
+		}
4932 5231
 
4933
-		if (!empty($size_string))
4934
-			$url_params[] = 's=' . $size_string;
5232
+		if (!empty($size_string)) {
5233
+					$url_params[] = 's=' . $size_string;
5234
+		}
4935 5235
 	}
4936 5236
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4937 5237
 
@@ -4950,22 +5250,26 @@  discard block
 block discarded – undo
4950 5250
 	static $timezones = null, $lastwhen = null;
4951 5251
 
4952 5252
 	// No point doing this over if we already did it once
4953
-	if (!empty($timezones) && $when == $lastwhen)
4954
-		return $timezones;
4955
-	else
4956
-		$lastwhen = $when;
5253
+	if (!empty($timezones) && $when == $lastwhen) {
5254
+			return $timezones;
5255
+	} else {
5256
+			$lastwhen = $when;
5257
+	}
4957 5258
 
4958 5259
 	// Parseable datetime string?
4959
-	if (is_int($timestamp = strtotime($when)))
4960
-		$when = $timestamp;
5260
+	if (is_int($timestamp = strtotime($when))) {
5261
+			$when = $timestamp;
5262
+	}
4961 5263
 
4962 5264
 	// A Unix timestamp?
4963
-	elseif (is_numeric($when))
4964
-		$when = intval($when);
5265
+	elseif (is_numeric($when)) {
5266
+			$when = intval($when);
5267
+	}
4965 5268
 
4966 5269
 	// Invalid value? Just get current Unix timestamp.
4967
-	else
4968
-		$when = time();
5270
+	else {
5271
+			$when = time();
5272
+	}
4969 5273
 
4970 5274
 	// We'll need these too
4971 5275
 	$date_when = date_create('@' . $when);
@@ -5029,8 +5333,9 @@  discard block
 block discarded – undo
5029 5333
 	foreach ($priority_countries as $country)
5030 5334
 	{
5031 5335
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5032
-		if (!empty($country_tzids))
5033
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5336
+		if (!empty($country_tzids)) {
5337
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5338
+		}
5034 5339
 	}
5035 5340
 
5036 5341
 	// Process the preferred timezones first, then the rest.
@@ -5040,8 +5345,9 @@  discard block
 block discarded – undo
5040 5345
 	foreach ($tzids as $tzid)
5041 5346
 	{
5042 5347
 		// We don't want UTC right now
5043
-		if ($tzid == 'UTC')
5044
-			continue;
5348
+		if ($tzid == 'UTC') {
5349
+					continue;
5350
+		}
5045 5351
 
5046 5352
 		$tz = timezone_open($tzid);
5047 5353
 
@@ -5056,12 +5362,14 @@  discard block
 block discarded – undo
5056 5362
 		$tzgeo = timezone_location_get($tz);
5057 5363
 
5058 5364
 		// Don't overwrite our preferred tzids
5059
-		if (empty($zones[$tzkey]['tzid']))
5060
-			$zones[$tzkey]['tzid'] = $tzid;
5365
+		if (empty($zones[$tzkey]['tzid'])) {
5366
+					$zones[$tzkey]['tzid'] = $tzid;
5367
+		}
5061 5368
 
5062 5369
 		// A time zone from a prioritized country?
5063
-		if (in_array($tzid, $priority_tzids))
5064
-			$priority_zones[$tzkey] = true;
5370
+		if (in_array($tzid, $priority_tzids)) {
5371
+					$priority_zones[$tzkey] = true;
5372
+		}
5065 5373
 
5066 5374
 		// Keep track of the location and offset for this tzid
5067 5375
 		$tzid_parts = explode('/', $tzid);
@@ -5083,15 +5391,17 @@  discard block
 block discarded – undo
5083 5391
 
5084 5392
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5085 5393
 
5086
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5087
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5088
-		else
5089
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5394
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5395
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5396
+		} else {
5397
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5398
+		}
5090 5399
 
5091
-		if (isset($priority_zones[$tzkey]))
5092
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5093
-		else
5094
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5400
+		if (isset($priority_zones[$tzkey])) {
5401
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5402
+		} else {
5403
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5404
+		}
5095 5405
 	}
5096 5406
 
5097 5407
 	$timezones = array_merge(
@@ -5145,9 +5455,9 @@  discard block
 block discarded – undo
5145 5455
 			'Indian/Kerguelen' => 'TFT',
5146 5456
 		);
5147 5457
 
5148
-		if (!empty($missing_tz_abbrs[$tzid]))
5149
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5150
-		else
5458
+		if (!empty($missing_tz_abbrs[$tzid])) {
5459
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5460
+		} else
5151 5461
 		{
5152 5462
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5153 5463
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5175,8 +5485,9 @@  discard block
 block discarded – undo
5175 5485
  */
5176 5486
 function inet_ptod($ip_address)
5177 5487
 {
5178
-	if (!isValidIP($ip_address))
5179
-		return $ip_address;
5488
+	if (!isValidIP($ip_address)) {
5489
+			return $ip_address;
5490
+	}
5180 5491
 
5181 5492
 	$bin = inet_pton($ip_address);
5182 5493
 	return $bin;
@@ -5188,13 +5499,15 @@  discard block
 block discarded – undo
5188 5499
  */
5189 5500
 function inet_dtop($bin)
5190 5501
 {
5191
-	if(empty($bin))
5192
-		return '';
5502
+	if(empty($bin)) {
5503
+			return '';
5504
+	}
5193 5505
 
5194 5506
 	global $db_type;
5195 5507
 
5196
-	if ($db_type == 'postgresql')
5197
-		return $bin;
5508
+	if ($db_type == 'postgresql') {
5509
+			return $bin;
5510
+	}
5198 5511
 
5199 5512
 	$ip_address = inet_ntop($bin);
5200 5513
 
@@ -5219,26 +5532,32 @@  discard block
 block discarded – undo
5219 5532
  */
5220 5533
 function _safe_serialize($value)
5221 5534
 {
5222
-	if(is_null($value))
5223
-		return 'N;';
5535
+	if(is_null($value)) {
5536
+			return 'N;';
5537
+	}
5224 5538
 
5225
-	if(is_bool($value))
5226
-		return 'b:'. (int) $value .';';
5539
+	if(is_bool($value)) {
5540
+			return 'b:'. (int) $value .';';
5541
+	}
5227 5542
 
5228
-	if(is_int($value))
5229
-		return 'i:'. $value .';';
5543
+	if(is_int($value)) {
5544
+			return 'i:'. $value .';';
5545
+	}
5230 5546
 
5231
-	if(is_float($value))
5232
-		return 'd:'. str_replace(',', '.', $value) .';';
5547
+	if(is_float($value)) {
5548
+			return 'd:'. str_replace(',', '.', $value) .';';
5549
+	}
5233 5550
 
5234
-	if(is_string($value))
5235
-		return 's:'. strlen($value) .':"'. $value .'";';
5551
+	if(is_string($value)) {
5552
+			return 's:'. strlen($value) .':"'. $value .'";';
5553
+	}
5236 5554
 
5237 5555
 	if(is_array($value))
5238 5556
 	{
5239 5557
 		$out = '';
5240
-		foreach($value as $k => $v)
5241
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5558
+		foreach($value as $k => $v) {
5559
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5560
+		}
5242 5561
 
5243 5562
 		return 'a:'. count($value) .':{'. $out .'}';
5244 5563
 	}
@@ -5264,8 +5583,9 @@  discard block
 block discarded – undo
5264 5583
 
5265 5584
 	$out = _safe_serialize($value);
5266 5585
 
5267
-	if (isset($mbIntEnc))
5268
-		mb_internal_encoding($mbIntEnc);
5586
+	if (isset($mbIntEnc)) {
5587
+			mb_internal_encoding($mbIntEnc);
5588
+	}
5269 5589
 
5270 5590
 	return $out;
5271 5591
 }
@@ -5282,8 +5602,9 @@  discard block
 block discarded – undo
5282 5602
 function _safe_unserialize($str)
5283 5603
 {
5284 5604
 	// Input  is not a string.
5285
-	if(empty($str) || !is_string($str))
5286
-		return false;
5605
+	if(empty($str) || !is_string($str)) {
5606
+			return false;
5607
+	}
5287 5608
 
5288 5609
 	$stack = array();
5289 5610
 	$expected = array();
@@ -5299,43 +5620,38 @@  discard block
 block discarded – undo
5299 5620
 	while($state != 1)
5300 5621
 	{
5301 5622
 		$type = isset($str[0]) ? $str[0] : '';
5302
-		if($type == '}')
5303
-			$str = substr($str, 1);
5304
-
5305
-		else if($type == 'N' && $str[1] == ';')
5623
+		if($type == '}') {
5624
+					$str = substr($str, 1);
5625
+		} else if($type == 'N' && $str[1] == ';')
5306 5626
 		{
5307 5627
 			$value = null;
5308 5628
 			$str = substr($str, 2);
5309
-		}
5310
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5629
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5311 5630
 		{
5312 5631
 			$value = $matches[1] == '1' ? true : false;
5313 5632
 			$str = substr($str, 4);
5314
-		}
5315
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5633
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5316 5634
 		{
5317 5635
 			$value = (int)$matches[1];
5318 5636
 			$str = $matches[2];
5319
-		}
5320
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5637
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5321 5638
 		{
5322 5639
 			$value = (float)$matches[1];
5323 5640
 			$str = $matches[3];
5324
-		}
5325
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5641
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5326 5642
 		{
5327 5643
 			$value = substr($matches[2], 0, (int)$matches[1]);
5328 5644
 			$str = substr($matches[2], (int)$matches[1] + 2);
5329
-		}
5330
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5645
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5331 5646
 		{
5332 5647
 			$expectedLength = (int)$matches[1];
5333 5648
 			$str = $matches[2];
5334 5649
 		}
5335 5650
 
5336 5651
 		// Object or unknown/malformed type.
5337
-		else
5338
-			return false;
5652
+		else {
5653
+					return false;
5654
+		}
5339 5655
 
5340 5656
 		switch($state)
5341 5657
 		{
@@ -5363,8 +5679,9 @@  discard block
 block discarded – undo
5363 5679
 				if($type == '}')
5364 5680
 				{
5365 5681
 					// Array size is less than expected.
5366
-					if(count($list) < end($expected))
5367
-						return false;
5682
+					if(count($list) < end($expected)) {
5683
+											return false;
5684
+					}
5368 5685
 
5369 5686
 					unset($list);
5370 5687
 					$list = &$stack[count($stack)-1];
@@ -5373,8 +5690,9 @@  discard block
 block discarded – undo
5373 5690
 					// Go to terminal state if we're at the end of the root array.
5374 5691
 					array_pop($expected);
5375 5692
 
5376
-					if(count($expected) == 0)
5377
-						$state = 1;
5693
+					if(count($expected) == 0) {
5694
+											$state = 1;
5695
+					}
5378 5696
 
5379 5697
 					break;
5380 5698
 				}
@@ -5382,8 +5700,9 @@  discard block
 block discarded – undo
5382 5700
 				if($type == 'i' || $type == 's')
5383 5701
 				{
5384 5702
 					// Array size exceeds expected length.
5385
-					if(count($list) >= end($expected))
5386
-						return false;
5703
+					if(count($list) >= end($expected)) {
5704
+											return false;
5705
+					}
5387 5706
 
5388 5707
 					$key = $value;
5389 5708
 					$state = 3;
@@ -5417,8 +5736,9 @@  discard block
 block discarded – undo
5417 5736
 	}
5418 5737
 
5419 5738
 	// Trailing data in input.
5420
-	if(!empty($str))
5421
-		return false;
5739
+	if(!empty($str)) {
5740
+			return false;
5741
+	}
5422 5742
 
5423 5743
 	return $data;
5424 5744
 }
@@ -5441,8 +5761,9 @@  discard block
 block discarded – undo
5441 5761
 
5442 5762
 	$out = _safe_unserialize($str);
5443 5763
 
5444
-	if (isset($mbIntEnc))
5445
-		mb_internal_encoding($mbIntEnc);
5764
+	if (isset($mbIntEnc)) {
5765
+			mb_internal_encoding($mbIntEnc);
5766
+	}
5446 5767
 
5447 5768
 	return $out;
5448 5769
 }
@@ -5457,12 +5778,14 @@  discard block
 block discarded – undo
5457 5778
 function smf_chmod($file, $value = 0)
5458 5779
 {
5459 5780
 	// No file? no checks!
5460
-	if (empty($file))
5461
-		return false;
5781
+	if (empty($file)) {
5782
+			return false;
5783
+	}
5462 5784
 
5463 5785
 	// Already writable?
5464
-	if (is_writable($file))
5465
-		return true;
5786
+	if (is_writable($file)) {
5787
+			return true;
5788
+	}
5466 5789
 
5467 5790
 	// Do we have a file or a dir?
5468 5791
 	$isDir = is_dir($file);
@@ -5478,10 +5801,9 @@  discard block
 block discarded – undo
5478 5801
 		{
5479 5802
 			$isWritable = true;
5480 5803
 			break;
5804
+		} else {
5805
+					@chmod($file, $val);
5481 5806
 		}
5482
-
5483
-		else
5484
-			@chmod($file, $val);
5485 5807
 	}
5486 5808
 
5487 5809
 	return $isWritable;
@@ -5500,8 +5822,9 @@  discard block
 block discarded – undo
5500 5822
 	global $txt;
5501 5823
 
5502 5824
 	// Come on...
5503
-	if (empty($json) || !is_string($json))
5504
-		return array();
5825
+	if (empty($json) || !is_string($json)) {
5826
+			return array();
5827
+	}
5505 5828
 
5506 5829
 	$returnArray = @json_decode($json, $returnAsArray);
5507 5830
 
@@ -5539,11 +5862,11 @@  discard block
 block discarded – undo
5539 5862
 		$jsonDebug = $jsonDebug[0];
5540 5863
 		loadLanguage('Errors');
5541 5864
 
5542
-		if (!empty($jsonDebug))
5543
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5544
-
5545
-		else
5546
-			log_error($txt['json_'. $jsonError], 'critical');
5865
+		if (!empty($jsonDebug)) {
5866
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5867
+		} else {
5868
+					log_error($txt['json_'. $jsonError], 'critical');
5869
+		}
5547 5870
 
5548 5871
 		// Everyone expects an array.
5549 5872
 		return array();
@@ -5573,8 +5896,9 @@  discard block
 block discarded – undo
5573 5896
 	global $db_show_debug, $modSettings;
5574 5897
 
5575 5898
 	// Defensive programming anyone?
5576
-	if (empty($data))
5577
-		return false;
5899
+	if (empty($data)) {
5900
+			return false;
5901
+	}
5578 5902
 
5579 5903
 	// Don't need extra stuff...
5580 5904
 	$db_show_debug = false;
@@ -5582,11 +5906,11 @@  discard block
 block discarded – undo
5582 5906
 	// Kill anything else.
5583 5907
 	ob_end_clean();
5584 5908
 
5585
-	if (!empty($modSettings['CompressedOutput']))
5586
-		@ob_start('ob_gzhandler');
5587
-
5588
-	else
5589
-		ob_start();
5909
+	if (!empty($modSettings['CompressedOutput'])) {
5910
+			@ob_start('ob_gzhandler');
5911
+	} else {
5912
+			ob_start();
5913
+	}
5590 5914
 
5591 5915
 	// Set the header.
5592 5916
 	header($type);
@@ -5618,8 +5942,9 @@  discard block
 block discarded – undo
5618 5942
 	static $done = false;
5619 5943
 
5620 5944
 	// If we don't need to do anything, don't
5621
-	if (!$update && $done)
5622
-		return;
5945
+	if (!$update && $done) {
5946
+			return;
5947
+	}
5623 5948
 
5624 5949
 	// Should we get a new copy of the official list of TLDs?
5625 5950
 	if ($update)
@@ -5640,10 +5965,11 @@  discard block
 block discarded – undo
5640 5965
 		// Clean $tlds and convert it to an array
5641 5966
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5642 5967
 			$line = trim($line);
5643
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5644
-				return false;
5645
-			else
5646
-				return true;
5968
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5969
+							return false;
5970
+			} else {
5971
+							return true;
5972
+			}
5647 5973
 		});
5648 5974
 
5649 5975
 		// Convert Punycode to Unicode
@@ -5697,8 +6023,9 @@  discard block
 block discarded – undo
5697 6023
 						$idx += $digit * $w;
5698 6024
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5699 6025
 
5700
-						if ($digit < $t)
5701
-							break;
6026
+						if ($digit < $t) {
6027
+													break;
6028
+						}
5702 6029
 
5703 6030
 						$w = (int) ($w * ($base - $t));
5704 6031
 					}
@@ -5707,8 +6034,9 @@  discard block
 block discarded – undo
5707 6034
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5708 6035
 					$delta += intval($delta / ($deco_len + 1));
5709 6036
 
5710
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5711
-						$delta = intval($delta / ($base - $tmin));
6037
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
6038
+											$delta = intval($delta / ($base - $tmin));
6039
+					}
5712 6040
 
5713 6041
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5714 6042
 					$is_first = false;
@@ -5717,8 +6045,9 @@  discard block
 block discarded – undo
5717 6045
 
5718 6046
 					if ($deco_len > 0)
5719 6047
 					{
5720
-						for ($i = $deco_len; $i > $idx; $i--)
5721
-							$decoded[$i] = $decoded[($i - 1)];
6048
+						for ($i = $deco_len; $i > $idx; $i--) {
6049
+													$decoded[$i] = $decoded[($i - 1)];
6050
+						}
5722 6051
 					}
5723 6052
 					$decoded[$idx++] = $char;
5724 6053
 				}
@@ -5726,24 +6055,29 @@  discard block
 block discarded – undo
5726 6055
 				foreach ($decoded as $k => $v)
5727 6056
 				{
5728 6057
 					// 7bit are transferred literally
5729
-					if ($v < 128)
5730
-						$output .= chr($v);
6058
+					if ($v < 128) {
6059
+											$output .= chr($v);
6060
+					}
5731 6061
 
5732 6062
 					// 2 bytes
5733
-					elseif ($v < (1 << 11))
5734
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6063
+					elseif ($v < (1 << 11)) {
6064
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6065
+					}
5735 6066
 
5736 6067
 					// 3 bytes
5737
-					elseif ($v < (1 << 16))
5738
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6068
+					elseif ($v < (1 << 16)) {
6069
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6070
+					}
5739 6071
 
5740 6072
 					// 4 bytes
5741
-					elseif ($v < (1 << 21))
5742
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6073
+					elseif ($v < (1 << 21)) {
6074
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6075
+					}
5743 6076
 
5744 6077
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5745
-					else
5746
-						$output .= $safe_char;
6078
+					else {
6079
+											$output .= $safe_char;
6080
+					}
5747 6081
 				}
5748 6082
 
5749 6083
 				$output_parts[] = $output;
@@ -5838,8 +6172,7 @@  discard block
 block discarded – undo
5838 6172
 
5839 6173
 		$strlen = 'mb_strlen';
5840 6174
 		$substr = 'mb_substr';
5841
-	}
5842
-	else
6175
+	} else
5843 6176
 	{
5844 6177
 		$strlen = $smcFunc['strlen'];
5845 6178
 		$substr = $smcFunc['substr'];
@@ -5853,20 +6186,21 @@  discard block
 block discarded – undo
5853 6186
 
5854 6187
 		$first = $substr($string, 0, 1);
5855 6188
 
5856
-		if (empty($index[$first]))
5857
-			$index[$first] = array();
6189
+		if (empty($index[$first])) {
6190
+					$index[$first] = array();
6191
+		}
5858 6192
 
5859 6193
 		if ($strlen($string) > 1)
5860 6194
 		{
5861 6195
 			// Sanity check on recursion
5862
-			if ($depth > 99)
5863
-				$index[$first][$substr($string, 1)] = '';
5864
-
5865
-			else
5866
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6196
+			if ($depth > 99) {
6197
+							$index[$first][$substr($string, 1)] = '';
6198
+			} else {
6199
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6200
+			}
6201
+		} else {
6202
+					$index[$first][''] = '';
5867 6203
 		}
5868
-		else
5869
-			$index[$first][''] = '';
5870 6204
 
5871 6205
 		$depth--;
5872 6206
 		return $index;
@@ -5889,9 +6223,9 @@  discard block
 block discarded – undo
5889 6223
 			$key_regex = preg_quote($key, $delim);
5890 6224
 			$new_key = $key;
5891 6225
 
5892
-			if (empty($value))
5893
-				$sub_regex = '';
5894
-			else
6226
+			if (empty($value)) {
6227
+							$sub_regex = '';
6228
+			} else
5895 6229
 			{
5896 6230
 				$sub_regex = $index_to_regex($value, $delim);
5897 6231
 
@@ -5899,22 +6233,22 @@  discard block
 block discarded – undo
5899 6233
 				{
5900 6234
 					$new_key_array = explode('(?'.'>', $sub_regex);
5901 6235
 					$new_key .= $new_key_array[0];
6236
+				} else {
6237
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5902 6238
 				}
5903
-				else
5904
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5905 6239
 			}
5906 6240
 
5907
-			if ($depth > 1)
5908
-				$regex[$new_key] = $key_regex . $sub_regex;
5909
-			else
6241
+			if ($depth > 1) {
6242
+							$regex[$new_key] = $key_regex . $sub_regex;
6243
+			} else
5910 6244
 			{
5911 6245
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5912 6246
 				{
5913 6247
 					$regex[$new_key] = $key_regex . $sub_regex;
5914 6248
 					unset($index[$key]);
6249
+				} else {
6250
+									break;
5915 6251
 				}
5916
-				else
5917
-					break;
5918 6252
 			}
5919 6253
 		}
5920 6254
 
@@ -5923,10 +6257,11 @@  discard block
 block discarded – undo
5923 6257
 			$l1 = $strlen($k1);
5924 6258
 			$l2 = $strlen($k2);
5925 6259
 
5926
-			if ($l1 == $l2)
5927
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5928
-			else
5929
-				return $l1 > $l2 ? -1 : 1;
6260
+			if ($l1 == $l2) {
6261
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6262
+			} else {
6263
+							return $l1 > $l2 ? -1 : 1;
6264
+			}
5930 6265
 		});
5931 6266
 
5932 6267
 		$depth--;
@@ -5937,15 +6272,18 @@  discard block
 block discarded – undo
5937 6272
 	$index = array();
5938 6273
 	$regexes = array();
5939 6274
 
5940
-	foreach ($strings as $string)
5941
-		$index = $add_string_to_index($string, $index);
6275
+	foreach ($strings as $string) {
6276
+			$index = $add_string_to_index($string, $index);
6277
+	}
5942 6278
 
5943
-	while (!empty($index))
5944
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6279
+	while (!empty($index)) {
6280
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6281
+	}
5945 6282
 
5946 6283
 	// Restore PHP's internal character encoding to whatever it was originally
5947
-	if (!empty($current_encoding))
5948
-		mb_internal_encoding($current_encoding);
6284
+	if (!empty($current_encoding)) {
6285
+			mb_internal_encoding($current_encoding);
6286
+	}
5949 6287
 
5950 6288
 	return $regexes;
5951 6289
 }
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 1 patch
Braces   +277 added lines, -201 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 function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -506,15 +531,17 @@  discard block
 block discarded – undo
506 531
 
507 532
 		// Store this useful data!
508 533
 		$boards[$row['id_board']] = $row['id_board'];
509
-		if ($row['id_topic'])
510
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
511
-		else
512
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
534
+		if ($row['id_topic']) {
535
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
536
+		} else {
537
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
538
+		}
513 539
 	}
514 540
 	$smcFunc['db_free_result']($request);
515 541
 
516
-	if (empty($boards))
517
-		return true;
542
+	if (empty($boards)) {
543
+			return true;
544
+	}
518 545
 
519 546
 	// Just get the board names.
520 547
 	$request = $smcFunc['db_query']('', '
@@ -526,12 +553,14 @@  discard block
 block discarded – undo
526 553
 		)
527 554
 	);
528 555
 	$boards = array();
529
-	while ($row = $smcFunc['db_fetch_assoc']($request))
530
-		$boards[$row['id_board']] = $row['name'];
556
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
557
+			$boards[$row['id_board']] = $row['name'];
558
+	}
531 559
 	$smcFunc['db_free_result']($request);
532 560
 
533
-	if (empty($boards))
534
-		return true;
561
+	if (empty($boards)) {
562
+			return true;
563
+	}
535 564
 
536 565
 	// Get the actual topics...
537 566
 	$request = $smcFunc['db_query']('', '
@@ -551,52 +580,57 @@  discard block
 block discarded – undo
551 580
 	$types = array();
552 581
 	while ($row = $smcFunc['db_fetch_assoc']($request))
553 582
 	{
554
-		if (!isset($types[$row['note_type']][$row['id_board']]))
555
-			$types[$row['note_type']][$row['id_board']] = array(
583
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
584
+					$types[$row['note_type']][$row['id_board']] = array(
556 585
 				'lines' => array(),
557 586
 				'name' => $row['board_name'],
558 587
 				'id' => $row['id_board'],
559 588
 			);
589
+		}
560 590
 
561 591
 		if ($row['note_type'] == 'reply')
562 592
 		{
563
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
564
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
565
-			else
566
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
593
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
594
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
595
+			} else {
596
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
567 597
 					'id' => $row['id_topic'],
568 598
 					'subject' => un_htmlspecialchars($row['subject']),
569 599
 					'count' => 1,
570 600
 				);
571
-		}
572
-		elseif ($row['note_type'] == 'topic')
601
+			}
602
+		} elseif ($row['note_type'] == 'topic')
573 603
 		{
574
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
575
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
604
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
605
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
576 606
 					'id' => $row['id_topic'],
577 607
 					'subject' => un_htmlspecialchars($row['subject']),
578 608
 				);
579
-		}
580
-		else
609
+			}
610
+		} else
581 611
 		{
582
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
583
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
612
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
613
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
584 614
 					'id' => $row['id_topic'],
585 615
 					'subject' => un_htmlspecialchars($row['subject']),
586 616
 					'starter' => $row['id_member_started'],
587 617
 				);
618
+			}
588 619
 		}
589 620
 
590 621
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
591
-		if (!empty($notify['topics'][$row['id_topic']]))
592
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
593
-		if (!empty($notify['boards'][$row['id_board']]))
594
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
622
+		if (!empty($notify['topics'][$row['id_topic']])) {
623
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
624
+		}
625
+		if (!empty($notify['boards'][$row['id_board']])) {
626
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
627
+		}
595 628
 	}
596 629
 	$smcFunc['db_free_result']($request);
597 630
 
598
-	if (empty($types))
599
-		return true;
631
+	if (empty($types)) {
632
+			return true;
633
+	}
600 634
 
601 635
 	// Let's load all the languages into a cache thingy.
602 636
 	$langtxt = array();
@@ -637,8 +671,9 @@  discard block
 block discarded – undo
637 671
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
638 672
 
639 673
 		// Did they not elect to choose this?
640
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
641
-			continue;
674
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
675
+					continue;
676
+		}
642 677
 
643 678
 		// Right character set!
644 679
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -654,39 +689,43 @@  discard block
 block discarded – undo
654 689
 		if (isset($types['topic']))
655 690
 		{
656 691
 			$titled = false;
657
-			foreach ($types['topic'] as $id => $board)
658
-				foreach ($board['lines'] as $topic)
692
+			foreach ($types['topic'] as $id => $board) {
693
+							foreach ($board['lines'] as $topic)
659 694
 					if (in_array($mid, $topic['members']))
660 695
 					{
661 696
 						if (!$titled)
662 697
 						{
663 698
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
699
+			}
664 700
 							$titled = true;
665 701
 						}
666 702
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
667 703
 					}
668
-			if ($titled)
669
-				$email['body'] .= "\n";
704
+			if ($titled) {
705
+							$email['body'] .= "\n";
706
+			}
670 707
 		}
671 708
 
672 709
 		// What about replies?
673 710
 		if (isset($types['reply']))
674 711
 		{
675 712
 			$titled = false;
676
-			foreach ($types['reply'] as $id => $board)
677
-				foreach ($board['lines'] as $topic)
713
+			foreach ($types['reply'] as $id => $board) {
714
+							foreach ($board['lines'] as $topic)
678 715
 					if (in_array($mid, $topic['members']))
679 716
 					{
680 717
 						if (!$titled)
681 718
 						{
682 719
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
720
+			}
683 721
 							$titled = true;
684 722
 						}
685 723
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
686 724
 					}
687 725
 
688
-			if ($titled)
689
-				$email['body'] .= "\n";
726
+			if ($titled) {
727
+							$email['body'] .= "\n";
728
+			}
690 729
 		}
691 730
 
692 731
 		// Finally, moderation actions!
@@ -695,24 +734,27 @@  discard block
 block discarded – undo
695 734
 			$titled = false;
696 735
 			foreach ($types as $note_type => $type)
697 736
 			{
698
-				if ($note_type == 'topic' || $note_type == 'reply')
699
-					continue;
737
+				if ($note_type == 'topic' || $note_type == 'reply') {
738
+									continue;
739
+				}
700 740
 
701
-				foreach ($type as $id => $board)
702
-					foreach ($board['lines'] as $topic)
741
+				foreach ($type as $id => $board) {
742
+									foreach ($board['lines'] as $topic)
703 743
 						if (in_array($mid, $topic['members']))
704 744
 						{
705 745
 							if (!$titled)
706 746
 							{
707 747
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
748
+				}
708 749
 								$titled = true;
709 750
 							}
710 751
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
711 752
 						}
712 753
 			}
713 754
 		}
714
-		if ($titled)
715
-			$email['body'] .= "\n";
755
+		if ($titled) {
756
+					$email['body'] .= "\n";
757
+		}
716 758
 
717 759
 		// Then just say our goodbyes!
718 760
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -740,8 +782,7 @@  discard block
 block discarded – undo
740 782
 				'not_daily' => 0,
741 783
 			)
742 784
 		);
743
-	}
744
-	else
785
+	} else
745 786
 	{
746 787
 		// Clear any only weekly ones, and stop us from sending daily again.
747 788
 		$smcFunc['db_query']('', '
@@ -803,16 +844,19 @@  discard block
 block discarded – undo
803 844
 	global $modSettings, $smcFunc, $sourcedir;
804 845
 
805 846
 	// Are we intending another script to be sending out the queue?
806
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
807
-		return false;
847
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
848
+			return false;
849
+	}
808 850
 
809 851
 	// By default send 5 at once.
810
-	if (!$number)
811
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
852
+	if (!$number) {
853
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
854
+	}
812 855
 
813 856
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
814
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
815
-		return false;
857
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
858
+			return false;
859
+	}
816 860
 
817 861
 	// By default move the next sending on by 10 seconds, and require an affected row.
818 862
 	if (!$override_limit)
@@ -829,8 +873,9 @@  discard block
 block discarded – undo
829 873
 				'last_send' => $modSettings['mail_next_send'],
830 874
 			)
831 875
 		);
832
-		if ($smcFunc['db_affected_rows']() == 0)
833
-			return false;
876
+		if ($smcFunc['db_affected_rows']() == 0) {
877
+					return false;
878
+		}
834 879
 		$modSettings['mail_next_send'] = time() + $delay;
835 880
 	}
836 881
 
@@ -851,8 +896,9 @@  discard block
 block discarded – undo
851 896
 			$mn += $number;
852 897
 		}
853 898
 		// No more I'm afraid, return!
854
-		else
855
-			return false;
899
+		else {
900
+					return false;
901
+		}
856 902
 
857 903
 		// Reflect that we're about to send some, do it now to be safe.
858 904
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -887,14 +933,15 @@  discard block
 block discarded – undo
887 933
 	$smcFunc['db_free_result']($request);
888 934
 
889 935
 	// Delete, delete, delete!!!
890
-	if (!empty($ids))
891
-		$smcFunc['db_query']('', '
936
+	if (!empty($ids)) {
937
+			$smcFunc['db_query']('', '
892 938
 			DELETE FROM {db_prefix}mail_queue
893 939
 			WHERE id_mail IN ({array_int:mail_list})',
894 940
 			array(
895 941
 				'mail_list' => $ids,
896 942
 			)
897 943
 		);
944
+	}
898 945
 
899 946
 	// Don't believe we have any left?
900 947
 	if (count($ids) < $number)
@@ -912,11 +959,13 @@  discard block
 block discarded – undo
912 959
 		);
913 960
 	}
914 961
 
915
-	if (empty($ids))
916
-		return false;
962
+	if (empty($ids)) {
963
+			return false;
964
+	}
917 965
 
918
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
919
-		require_once($sourcedir . '/Subs-Post.php');
966
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
967
+			require_once($sourcedir . '/Subs-Post.php');
968
+	}
920 969
 
921 970
 	// Send each email, yea!
922 971
 	$failed_emails = array();
@@ -936,15 +985,17 @@  discard block
 block discarded – undo
936 985
 
937 986
 			// Try to stop a timeout, this would be bad...
938 987
 			@set_time_limit(300);
939
-			if (function_exists('apache_reset_timeout'))
940
-				@apache_reset_timeout();
988
+			if (function_exists('apache_reset_timeout')) {
989
+							@apache_reset_timeout();
990
+			}
991
+		} else {
992
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
941 993
 		}
942
-		else
943
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
944 994
 
945 995
 		// Hopefully it sent?
946
-		if (!$result)
947
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
996
+		if (!$result) {
997
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
998
+		}
948 999
 	}
949 1000
 
950 1001
 	// Any emails that didn't send?
@@ -959,8 +1010,8 @@  discard block
 block discarded – undo
959 1010
 		);
960 1011
 
961 1012
 		// If we have failed to many times, tell mail to wait a bit and try again.
962
-		if ($modSettings['mail_failed_attempts'] > 5)
963
-			$smcFunc['db_query']('', '
1013
+		if ($modSettings['mail_failed_attempts'] > 5) {
1014
+					$smcFunc['db_query']('', '
964 1015
 				UPDATE {db_prefix}settings
965 1016
 				SET value = {string:next_mail_send}
966 1017
 				WHERE variable = {literal:mail_next_send}
@@ -969,6 +1020,7 @@  discard block
 block discarded – undo
969 1020
 					'next_mail_send' => time() + 60,
970 1021
 					'last_send' => $modSettings['mail_next_send'],
971 1022
 			));
1023
+		}
972 1024
 
973 1025
 		// Add our email back to the queue, manually.
974 1026
 		$smcFunc['db_insert']('insert',
@@ -981,8 +1033,8 @@  discard block
 block discarded – undo
981 1033
 		return false;
982 1034
 	}
983 1035
 	// We where unable to send the email, clear our failed attempts.
984
-	elseif (!empty($modSettings['mail_failed_attempts']))
985
-		$smcFunc['db_query']('', '
1036
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1037
+			$smcFunc['db_query']('', '
986 1038
 			UPDATE {db_prefix}settings
987 1039
 			SET value = {string:zero}
988 1040
 			WHERE variable = {string:mail_failed_attempts}',
@@ -990,6 +1042,7 @@  discard block
 block discarded – undo
990 1042
 				'zero' => '0',
991 1043
 				'mail_failed_attempts' => 'mail_failed_attempts',
992 1044
 		));
1045
+	}
993 1046
 
994 1047
 	// Had something to send...
995 1048
 	return true;
@@ -1006,16 +1059,18 @@  discard block
 block discarded – undo
1006 1059
 	global $modSettings, $smcFunc;
1007 1060
 
1008 1061
 	$task_query = '';
1009
-	if (!is_array($tasks))
1010
-		$tasks = array($tasks);
1062
+	if (!is_array($tasks)) {
1063
+			$tasks = array($tasks);
1064
+	}
1011 1065
 
1012 1066
 	// Actually have something passed?
1013 1067
 	if (!empty($tasks))
1014 1068
 	{
1015
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1016
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1017
-		else
1018
-			$task_query = ' AND task IN ({array_string:tasks})';
1069
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1070
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1071
+		} else {
1072
+					$task_query = ' AND task IN ({array_string:tasks})';
1073
+		}
1019 1074
 	}
1020 1075
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1021 1076
 
@@ -1036,20 +1091,22 @@  discard block
 block discarded – undo
1036 1091
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1037 1092
 
1038 1093
 		// Only bother moving the task if it's out of place or we're forcing it!
1039
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1040
-			$tasks[$row['id_task']] = $next_time;
1041
-		else
1042
-			$next_time = $row['next_time'];
1094
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1095
+					$tasks[$row['id_task']] = $next_time;
1096
+		} else {
1097
+					$next_time = $row['next_time'];
1098
+		}
1043 1099
 
1044 1100
 		// If this is sooner than the current next task, make this the next task.
1045
-		if ($next_time < $nextTaskTime)
1046
-			$nextTaskTime = $next_time;
1101
+		if ($next_time < $nextTaskTime) {
1102
+					$nextTaskTime = $next_time;
1103
+		}
1047 1104
 	}
1048 1105
 	$smcFunc['db_free_result']($request);
1049 1106
 
1050 1107
 	// Now make the changes!
1051
-	foreach ($tasks as $id => $time)
1052
-		$smcFunc['db_query']('', '
1108
+	foreach ($tasks as $id => $time) {
1109
+			$smcFunc['db_query']('', '
1053 1110
 			UPDATE {db_prefix}scheduled_tasks
1054 1111
 			SET next_time = {int:next_time}
1055 1112
 			WHERE id_task = {int:id_task}',
@@ -1058,11 +1115,13 @@  discard block
 block discarded – undo
1058 1115
 				'id_task' => $id,
1059 1116
 			)
1060 1117
 		);
1118
+	}
1061 1119
 
1062 1120
 	// If the next task is now different update.
1063
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1064
-		updateSettings(array('next_task_time' => $nextTaskTime));
1065
-}
1121
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1122
+			updateSettings(array('next_task_time' => $nextTaskTime));
1123
+	}
1124
+	}
1066 1125
 
1067 1126
 /**
1068 1127
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1075,8 +1134,9 @@  discard block
 block discarded – undo
1075 1134
 function next_time($regularity, $unit, $offset)
1076 1135
 {
1077 1136
 	// Just in case!
1078
-	if ($regularity == 0)
1079
-		$regularity = 2;
1137
+	if ($regularity == 0) {
1138
+			$regularity = 2;
1139
+	}
1080 1140
 
1081 1141
 	$curMin = date('i', time());
1082 1142
 
@@ -1086,15 +1146,16 @@  discard block
 block discarded – undo
1086 1146
 		$off = date('i', $offset);
1087 1147
 
1088 1148
 		// If it's now just pretend it ain't,
1089
-		if ($off == $curMin)
1090
-			$next_time = time() + $regularity;
1091
-		else
1149
+		if ($off == $curMin) {
1150
+					$next_time = time() + $regularity;
1151
+		} else
1092 1152
 		{
1093 1153
 			// Make sure that the offset is always in the past.
1094 1154
 			$off = $off > $curMin ? $off - 60 : $off;
1095 1155
 
1096
-			while ($off <= $curMin)
1097
-				$off += $regularity;
1156
+			while ($off <= $curMin) {
1157
+							$off += $regularity;
1158
+			}
1098 1159
 
1099 1160
 			// Now we know when the time should be!
1100 1161
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1114,11 +1175,13 @@  discard block
 block discarded – undo
1114 1175
 		// Default we'll jump in hours.
1115 1176
 		$applyOffset = 3600;
1116 1177
 		// 24 hours = 1 day.
1117
-		if ($unit == 'd')
1118
-			$applyOffset = 86400;
1178
+		if ($unit == 'd') {
1179
+					$applyOffset = 86400;
1180
+		}
1119 1181
 		// Otherwise a week.
1120
-		if ($unit == 'w')
1121
-			$applyOffset = 604800;
1182
+		if ($unit == 'w') {
1183
+					$applyOffset = 604800;
1184
+		}
1122 1185
 
1123 1186
 		$applyOffset *= $regularity;
1124 1187
 
@@ -1155,8 +1218,9 @@  discard block
 block discarded – undo
1155 1218
 		$settings[$row['variable']] = $row['value'];
1156 1219
 
1157 1220
 		// Is this the default theme?
1158
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1159
-			$settings['default_' . $row['variable']] = $row['value'];
1221
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1222
+					$settings['default_' . $row['variable']] = $row['value'];
1223
+		}
1160 1224
 	}
1161 1225
 	$smcFunc['db_free_result']($result);
1162 1226
 
@@ -1166,12 +1230,14 @@  discard block
 block discarded – undo
1166 1230
 		$settings['template_dirs'] = array($settings['theme_dir']);
1167 1231
 
1168 1232
 		// Based on theme (if there is one).
1169
-		if (!empty($settings['base_theme_dir']))
1170
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1233
+		if (!empty($settings['base_theme_dir'])) {
1234
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1235
+		}
1171 1236
 
1172 1237
 		// Lastly the default theme.
1173
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1174
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1238
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1239
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1240
+		}
1175 1241
 	}
1176 1242
 
1177 1243
 	// Assume we want this.
@@ -1318,8 +1384,9 @@  discard block
 block discarded – undo
1318 1384
 	// Ok should we prune the logs?
1319 1385
 	if (!empty($modSettings['pruningOptions']))
1320 1386
 	{
1321
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1322
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1387
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1388
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1389
+		}
1323 1390
 
1324 1391
 		if (!empty($modSettings['pruneErrorLog']))
1325 1392
 		{
@@ -1385,8 +1452,9 @@  discard block
 block discarded – undo
1385 1452
 				)
1386 1453
 			);
1387 1454
 
1388
-			while ($row = $smcFunc['db_fetch_row']($result))
1389
-				$reports[] = $row[0];
1455
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1456
+							$reports[] = $row[0];
1457
+			}
1390 1458
 
1391 1459
 			$smcFunc['db_free_result']($result);
1392 1460
 
@@ -1548,8 +1616,9 @@  discard block
 block discarded – undo
1548 1616
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1549 1617
 
1550 1618
 		// Send the actual email.
1551
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1552
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1619
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1620
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1621
+		}
1553 1622
 
1554 1623
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1555 1624
 		{
@@ -1572,18 +1641,19 @@  discard block
 block discarded – undo
1572 1641
 	}
1573 1642
 
1574 1643
 	// Insert the alerts if any
1575
-	if (!empty($alert_rows))
1576
-		$smcFunc['db_insert']('',
1644
+	if (!empty($alert_rows)) {
1645
+			$smcFunc['db_insert']('',
1577 1646
 			'{db_prefix}user_alerts',
1578 1647
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1579 1648
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1580 1649
 			$alert_rows,
1581 1650
 			array()
1582 1651
 		);
1652
+	}
1583 1653
 
1584 1654
 	// Mark the reminder as sent.
1585
-	if (!empty($subs_reminded))
1586
-		$smcFunc['db_query']('', '
1655
+	if (!empty($subs_reminded)) {
1656
+			$smcFunc['db_query']('', '
1587 1657
 			UPDATE {db_prefix}log_subscribed
1588 1658
 			SET reminder_sent = {int:reminder_sent}
1589 1659
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1592,6 +1662,7 @@  discard block
 block discarded – undo
1592 1662
 				'reminder_sent' => 1,
1593 1663
 			)
1594 1664
 		);
1665
+	}
1595 1666
 
1596 1667
 	return true;
1597 1668
 }
@@ -1607,13 +1678,13 @@  discard block
 block discarded – undo
1607 1678
 	// We need to know where this thing is going.
1608 1679
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1609 1680
 	{
1610
-		if (!is_array($modSettings['attachmentUploadDir']))
1611
-			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1681
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1682
+					$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1683
+		}
1612 1684
 
1613 1685
 		// Just use the current path for temp files.
1614 1686
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1615
-	}
1616
-	else
1687
+	} else
1617 1688
 	{
1618 1689
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1619 1690
 	}
@@ -1632,14 +1703,16 @@  discard block
 block discarded – undo
1632 1703
 
1633 1704
 		while ($file = readdir($dir))
1634 1705
 		{
1635
-			if ($file == '.' || $file == '..')
1636
-				continue;
1706
+			if ($file == '.' || $file == '..') {
1707
+							continue;
1708
+			}
1637 1709
 
1638 1710
 			if (strpos($file, 'post_tmp_') !== false)
1639 1711
 			{
1640 1712
 				// Temp file is more than 5 hours old!
1641
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1642
-					@unlink($attach_dir . '/' . $file);
1713
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1714
+									@unlink($attach_dir . '/' . $file);
1715
+				}
1643 1716
 			}
1644 1717
 		}
1645 1718
 		closedir($dir);
@@ -1672,8 +1745,9 @@  discard block
 block discarded – undo
1672 1745
 		)
1673 1746
 	);
1674 1747
 
1675
-	while ($row = $smcFunc['db_fetch_row']($request))
1676
-		$topics[] = $row[0];
1748
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1749
+			$topics[] = $row[0];
1750
+	}
1677 1751
 	$smcFunc['db_free_result']($request);
1678 1752
 
1679 1753
 	// Zap, your gone
@@ -1693,8 +1767,9 @@  discard block
 block discarded – undo
1693 1767
 {
1694 1768
 	global $smcFunc, $sourcedir, $modSettings;
1695 1769
 
1696
-	if (empty($modSettings['drafts_keep_days']))
1697
-		return true;
1770
+	if (empty($modSettings['drafts_keep_days'])) {
1771
+			return true;
1772
+	}
1698 1773
 
1699 1774
 	// init
1700 1775
 	$drafts = array();
@@ -1712,8 +1787,9 @@  discard block
 block discarded – undo
1712 1787
 		)
1713 1788
 	);
1714 1789
 
1715
-	while ($row = $smcFunc['db_fetch_row']($request))
1716
-		$drafts[] = (int) $row[0];
1790
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1791
+			$drafts[] = (int) $row[0];
1792
+	}
1717 1793
 	$smcFunc['db_free_result']($request);
1718 1794
 
1719 1795
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/ManagePaid.php 1 patch
Braces   +202 added lines, -148 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
  * The main entrance point for the 'Paid Subscription' screen, calling
@@ -32,18 +33,19 @@  discard block
 block discarded – undo
32 33
 	loadLanguage('ManagePaid');
33 34
 	loadTemplate('ManagePaid');
34 35
 
35
-	if (!empty($modSettings['paid_enabled']))
36
-		$subActions = array(
36
+	if (!empty($modSettings['paid_enabled'])) {
37
+			$subActions = array(
37 38
 			'modify' => array('ModifySubscription', 'admin_forum'),
38 39
 			'modifyuser' => array('ModifyUserSubscription', 'admin_forum'),
39 40
 			'settings' => array('ModifySubscriptionSettings', 'admin_forum'),
40 41
 			'view' => array('ViewSubscriptions', 'admin_forum'),
41 42
 			'viewsub' => array('ViewSubscribedUsers', 'admin_forum'),
42 43
 		);
43
-	else
44
-		$subActions = array(
44
+	} else {
45
+			$subActions = array(
45 46
 			'settings' => array('ModifySubscriptionSettings', 'admin_forum'),
46 47
 		);
48
+	}
47 49
 
48 50
 	// Default the sub-action to 'view subscriptions', but only if they have already set things up..
49 51
 	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($modSettings['paid_currency_symbol']) && !empty($modSettings['paid_enabled']) ? 'view' : 'settings');
@@ -59,8 +61,8 @@  discard block
 block discarded – undo
59 61
 		'help' => '',
60 62
 		'description' => $txt['paid_subscriptions_desc'],
61 63
 	);
62
-	if (!empty($modSettings['paid_enabled']))
63
-		$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
64
+	if (!empty($modSettings['paid_enabled'])) {
65
+			$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
64 66
 			'view' => array(
65 67
 				'description' => $txt['paid_subs_view_desc'],
66 68
 			),
@@ -68,6 +70,7 @@  discard block
 block discarded – undo
68 70
 				'description' => $txt['paid_subs_settings_desc'],
69 71
 			),
70 72
 		);
73
+	}
71 74
 
72 75
 	call_integration_hook('integrate_manage_subscriptions', array(&$subActions));
73 76
 
@@ -92,8 +95,9 @@  discard block
 block discarded – undo
92 95
 	{
93 96
 		// If the currency is set to something different then we need to set it to other for this to work and set it back shortly.
94 97
 		$modSettings['paid_currency'] = !empty($modSettings['paid_currency_code']) ? $modSettings['paid_currency_code'] : '';
95
-		if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud')))
96
-			$modSettings['paid_currency'] = 'other';
98
+		if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud'))) {
99
+					$modSettings['paid_currency'] = 'other';
100
+		}
97 101
 
98 102
 		// These are all the default settings.
99 103
 		$config_vars = array(
@@ -156,8 +160,7 @@  discard block
 block discarded – undo
156 160
 			}
157 161
 		}
158 162
 		toggleOther();', true);
159
-	}
160
-	else
163
+	} else
161 164
 	{
162 165
 		$config_vars = array(
163 166
 			array('check', 'paid_enabled'),
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	}
167 170
 
168 171
 	// Just searching?
169
-	if ($return_config)
170
-		return $config_vars;
172
+	if ($return_config) {
173
+			return $config_vars;
174
+	}
171 175
 
172 176
 	// Get the settings template fired up.
173 177
 	require_once($sourcedir . '/ManageServer.php');
@@ -211,8 +215,9 @@  discard block
 block discarded – undo
211 215
 			foreach (explode(',', $_POST['paid_email_to']) as $email)
212 216
 			{
213 217
 				$email = trim($email);
214
-				if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL))
215
-					$email_addresses[] = $email;
218
+				if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
219
+									$email_addresses[] = $email;
220
+				}
216 221
 				$_POST['paid_email_to'] = implode(',', $email_addresses);
217 222
 			}
218 223
 		}
@@ -249,8 +254,9 @@  discard block
 block discarded – undo
249 254
 	global $context, $txt, $modSettings, $sourcedir, $scripturl;
250 255
 
251 256
 	// Not made the settings yet?
252
-	if (empty($modSettings['paid_currency_symbol']))
253
-		fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings');
257
+	if (empty($modSettings['paid_currency_symbol'])) {
258
+			fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings');
259
+	}
254 260
 
255 261
 	// Some basic stuff.
256 262
 	$context['page_title'] = $txt['paid_subs_view'];
@@ -270,10 +276,11 @@  discard block
 block discarded – undo
270 276
 
271 277
 				foreach ($context['subscriptions'] as $data)
272 278
 				{
273
-					if (++$counter < $start)
274
-						continue;
275
-					elseif ($counter == $start + $items_per_page)
276
-						break;
279
+					if (++$counter < $start) {
280
+											continue;
281
+					} elseif ($counter == $start + $items_per_page) {
282
+											break;
283
+					}
277 284
 
278 285
 					$subscriptions[] = $data;
279 286
 				}
@@ -450,8 +457,9 @@  discard block
 block discarded – undo
450 457
 			);
451 458
 			$id_group = 0;
452 459
 			$add_groups = '';
453
-			if ($smcFunc['db_num_rows']($request))
454
-				list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);
460
+			if ($smcFunc['db_num_rows']($request)) {
461
+							list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);
462
+			}
455 463
 			$smcFunc['db_free_result']($request);
456 464
 
457 465
 			$changes = array();
@@ -463,8 +471,9 @@  discard block
 block discarded – undo
463 471
 				{
464 472
 					// If their current primary group isn't what they had before the subscription, and their current group was
465 473
 					// granted by the sub, remove it.
466
-					if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group)
467
-						$changes[$id_member]['id_group'] = $member_data['old_id_group'];
474
+					if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group) {
475
+											$changes[$id_member]['id_group'] = $member_data['old_id_group'];
476
+					}
468 477
 				}
469 478
 			}
470 479
 
@@ -477,15 +486,17 @@  discard block
 block discarded – undo
477 486
 					// First let's get their groups sorted.
478 487
 					$current_groups = explode(',', $member_data['additional_groups']);
479 488
 					$new_groups = implode(',', array_diff($current_groups, $add_groups));
480
-					if ($new_groups != $member_data['additional_groups'])
481
-						$changes[$id_member]['additional_groups'] = $new_groups;
489
+					if ($new_groups != $member_data['additional_groups']) {
490
+											$changes[$id_member]['additional_groups'] = $new_groups;
491
+					}
482 492
 				}
483 493
 			}
484 494
 
485 495
 			// We're going through changes...
486
-			if (!empty($changes))
487
-				foreach ($changes as $id_member => $new_values)
496
+			if (!empty($changes)) {
497
+							foreach ($changes as $id_member => $new_values)
488 498
 					updateMemberData($id_member, $new_values);
499
+			}
489 500
 		}
490 501
 
491 502
 		// Delete the subscription
@@ -533,11 +544,13 @@  discard block
 block discarded – undo
533 544
 				'M' => 24,
534 545
 				'Y' => 5,
535 546
 			);
536
-			if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1)
537
-				fatal_lang_error('paid_invalid_duration', false);
547
+			if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1) {
548
+							fatal_lang_error('paid_invalid_duration', false);
549
+			}
538 550
 
539
-			if ($_POST['span_value'] > $limits[$_POST['span_unit']])
540
-				fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false);
551
+			if ($_POST['span_value'] > $limits[$_POST['span_unit']]) {
552
+							fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false);
553
+			}
541 554
 
542 555
 			// Clean the span.
543 556
 			$span = $_POST['span_value'] . $_POST['span_unit'];
@@ -546,8 +559,9 @@  discard block
 block discarded – undo
546 559
 			$cost = array('fixed' => sprintf('%01.2f', strtr($_POST['cost'], ',', '.')));
547 560
 
548 561
 			// There needs to be something.
549
-			if (empty($_POST['span_value']) || empty($_POST['cost']))
550
-				fatal_lang_error('paid_no_cost_value');
562
+			if (empty($_POST['span_value']) || empty($_POST['cost'])) {
563
+							fatal_lang_error('paid_no_cost_value');
564
+			}
551 565
 		}
552 566
 		// Flexible is harder but more fun ;)
553 567
 		else
@@ -561,8 +575,9 @@  discard block
 block discarded – undo
561 575
 				'year' => sprintf('%01.2f', strtr($_POST['cost_year'], ',', '.')),
562 576
 			);
563 577
 
564
-			if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year']))
565
-				fatal_lang_error('paid_all_freq_blank');
578
+			if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year'])) {
579
+							fatal_lang_error('paid_all_freq_blank');
580
+			}
566 581
 		}
567 582
 		$cost = $smcFunc['json_encode']($cost);
568 583
 
@@ -571,9 +586,10 @@  discard block
 block discarded – undo
571 586
 
572 587
 		// Yep, time to do additional groups.
573 588
 		$addgroups = array();
574
-		if (!empty($_POST['addgroup']))
575
-			foreach ($_POST['addgroup'] as $id => $dummy)
589
+		if (!empty($_POST['addgroup'])) {
590
+					foreach ($_POST['addgroup'] as $id => $dummy)
576 591
 				$addgroups[] = (int) $id;
592
+		}
577 593
 		$addgroups = implode(',', $addgroups);
578 594
 
579 595
 		// Is it new?!
@@ -683,18 +699,18 @@  discard block
 block discarded – undo
683 699
 			{
684 700
 				$span_value = $match[1];
685 701
 				$span_unit = $match[2];
686
-			}
687
-			else
702
+			} else
688 703
 			{
689 704
 				$span_value = 0;
690 705
 				$span_unit = 'D';
691 706
 			}
692 707
 
693 708
 			// Is this a flexible one?
694
-			if ($row['length'] == 'F')
695
-				$isFlexible = true;
696
-			else
697
-				$isFlexible = false;
709
+			if ($row['length'] == 'F') {
710
+							$isFlexible = true;
711
+			} else {
712
+							$isFlexible = false;
713
+			}
698 714
 
699 715
 			$context['sub'] = array(
700 716
 				'name' => $row['name'],
@@ -743,8 +759,9 @@  discard block
 block discarded – undo
743 759
 		)
744 760
 	);
745 761
 	$context['groups'] = array();
746
-	while ($row = $smcFunc['db_fetch_assoc']($request))
747
-		$context['groups'][$row['id_group']] = $row['group_name'];
762
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
763
+			$context['groups'][$row['id_group']] = $row['group_name'];
764
+	}
748 765
 	$smcFunc['db_free_result']($request);
749 766
 
750 767
 	// This always happens.
@@ -778,8 +795,9 @@  discard block
 block discarded – undo
778 795
 		)
779 796
 	);
780 797
 	// Something wrong?
781
-	if ($smcFunc['db_num_rows']($request) == 0)
782
-		fatal_lang_error('no_access', false);
798
+	if ($smcFunc['db_num_rows']($request) == 0) {
799
+			fatal_lang_error('no_access', false);
800
+	}
783 801
 	// Do the subscription context.
784 802
 	$row = $smcFunc['db_fetch_assoc']($request);
785 803
 	$context['subscription'] = array(
@@ -1014,8 +1032,8 @@  discard block
 block discarded – undo
1014 1032
 		))
1015 1033
 	);
1016 1034
 	$subscribers = array();
1017
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1018
-		$subscribers[] = array(
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$subscribers[] = array(
1019 1037
 			'id' => $row['id_sublog'],
1020 1038
 			'id_member' => $row['id_member'],
1021 1039
 			'name' => $row['name'],
@@ -1025,6 +1043,7 @@  discard block
 block discarded – undo
1025 1043
 			'status' => $row['status'],
1026 1044
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] == 0 ? $txt['paid_finished'] : $txt['paid_pending']) : $txt['paid_active'],
1027 1045
 		);
1046
+	}
1028 1047
 	$smcFunc['db_free_result']($request);
1029 1048
 
1030 1049
 	return $subscribers;
@@ -1059,14 +1078,16 @@  discard block
 block discarded – undo
1059 1078
 				'current_log_item' => $context['log_id'],
1060 1079
 			)
1061 1080
 		);
1062
-		if ($smcFunc['db_num_rows']($request) == 0)
1063
-			fatal_lang_error('no_access', false);
1081
+		if ($smcFunc['db_num_rows']($request) == 0) {
1082
+					fatal_lang_error('no_access', false);
1083
+		}
1064 1084
 		list ($context['sub_id']) = $smcFunc['db_fetch_row']($request);
1065 1085
 		$smcFunc['db_free_result']($request);
1066 1086
 	}
1067 1087
 
1068
-	if (!isset($context['subscriptions'][$context['sub_id']]))
1069
-		fatal_lang_error('no_access', false);
1088
+	if (!isset($context['subscriptions'][$context['sub_id']])) {
1089
+			fatal_lang_error('no_access', false);
1090
+	}
1070 1091
 	$context['current_subscription'] = $context['subscriptions'][$context['sub_id']];
1071 1092
 
1072 1093
 	// Searching?
@@ -1099,8 +1120,9 @@  discard block
 block discarded – undo
1099 1120
 					'name' => $_POST['name'],
1100 1121
 				)
1101 1122
 			);
1102
-			if ($smcFunc['db_num_rows']($request) == 0)
1103
-				fatal_lang_error('error_member_not_found');
1123
+			if ($smcFunc['db_num_rows']($request) == 0) {
1124
+							fatal_lang_error('error_member_not_found');
1125
+			}
1104 1126
 
1105 1127
 			list ($id_member, $id_group) = $smcFunc['db_fetch_row']($request);
1106 1128
 			$smcFunc['db_free_result']($request);
@@ -1116,14 +1138,15 @@  discard block
 block discarded – undo
1116 1138
 					'current_member' => $id_member,
1117 1139
 				)
1118 1140
 			);
1119
-			if ($smcFunc['db_num_rows']($request) != 0)
1120
-				fatal_lang_error('member_already_subscribed');
1141
+			if ($smcFunc['db_num_rows']($request) != 0) {
1142
+							fatal_lang_error('member_already_subscribed');
1143
+			}
1121 1144
 			$smcFunc['db_free_result']($request);
1122 1145
 
1123 1146
 			// Actually put the subscription in place.
1124
-			if ($status == 1)
1125
-				addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1126
-			else
1147
+			if ($status == 1) {
1148
+							addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1149
+			} else
1127 1150
 			{
1128 1151
 				$smcFunc['db_insert']('',
1129 1152
 					'{db_prefix}log_subscribed',
@@ -1150,20 +1173,20 @@  discard block
 block discarded – undo
1150 1173
 					'current_log_item' => $context['log_id'],
1151 1174
 				)
1152 1175
 			);
1153
-			if ($smcFunc['db_num_rows']($request) == 0)
1154
-				fatal_lang_error('no_access', false);
1176
+			if ($smcFunc['db_num_rows']($request) == 0) {
1177
+							fatal_lang_error('no_access', false);
1178
+			}
1155 1179
 
1156 1180
 			list ($id_member, $old_status) = $smcFunc['db_fetch_row']($request);
1157 1181
 			$smcFunc['db_free_result']($request);
1158 1182
 
1159 1183
 			// Pick the right permission stuff depending on what the status is changing from/to.
1160
-			if ($old_status == 1 && $status != 1)
1161
-				removeSubscription($context['sub_id'], $id_member);
1162
-			elseif ($status == 1 && $old_status != 1)
1184
+			if ($old_status == 1 && $status != 1) {
1185
+							removeSubscription($context['sub_id'], $id_member);
1186
+			} elseif ($status == 1 && $old_status != 1)
1163 1187
 			{
1164 1188
 				addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1165
-			}
1166
-			else
1189
+			} else
1167 1190
 			{
1168 1191
 				$smcFunc['db_query']('', '
1169 1192
 					UPDATE {db_prefix}log_subscribed
@@ -1191,8 +1214,9 @@  discard block
 block discarded – undo
1191 1214
 		if (!empty($_REQUEST['delsub']))
1192 1215
 		{
1193 1216
 			$toDelete = array();
1194
-			foreach ($_REQUEST['delsub'] as $id => $dummy)
1195
-				$toDelete[] = (int) $id;
1217
+			foreach ($_REQUEST['delsub'] as $id => $dummy) {
1218
+							$toDelete[] = (int) $id;
1219
+			}
1196 1220
 
1197 1221
 			$request = $smcFunc['db_query']('', '
1198 1222
 				SELECT id_subscribe, id_member
@@ -1202,8 +1226,9 @@  discard block
 block discarded – undo
1202 1226
 					'subscription_list' => $toDelete,
1203 1227
 				)
1204 1228
 			);
1205
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1206
-				removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete']));
1229
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1230
+							removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete']));
1231
+			}
1207 1232
 			$smcFunc['db_free_result']($request);
1208 1233
 		}
1209 1234
 		redirectexit('action=admin;area=paidsubscribe;sa=viewsub;sid=' . $context['sub_id']);
@@ -1247,9 +1272,9 @@  discard block
 block discarded – undo
1247 1272
 			);
1248 1273
 			list ($context['sub']['username']) = $smcFunc['db_fetch_row']($request);
1249 1274
 			$smcFunc['db_free_result']($request);
1275
+		} else {
1276
+					$context['sub']['username'] = '';
1250 1277
 		}
1251
-		else
1252
-			$context['sub']['username'] = '';
1253 1278
 	}
1254 1279
 	// Otherwise load the existing info.
1255 1280
 	else
@@ -1266,8 +1291,9 @@  discard block
 block discarded – undo
1266 1291
 				'blank_string' => '',
1267 1292
 			)
1268 1293
 		);
1269
-		if ($smcFunc['db_num_rows']($request) == 0)
1270
-			fatal_lang_error('no_access', false);
1294
+		if ($smcFunc['db_num_rows']($request) == 0) {
1295
+					fatal_lang_error('no_access', false);
1296
+		}
1271 1297
 		$row = $smcFunc['db_fetch_assoc']($request);
1272 1298
 		$smcFunc['db_free_result']($request);
1273 1299
 
@@ -1288,13 +1314,13 @@  discard block
 block discarded – undo
1288 1314
 					{
1289 1315
 						foreach ($costs as $duration => $cost)
1290 1316
 						{
1291
-							if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2])
1292
-								$context['pending_payments'][$id] = array(
1317
+							if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2]) {
1318
+															$context['pending_payments'][$id] = array(
1293 1319
 									'desc' => sprintf($modSettings['paid_currency_symbol'], $cost . '/' . $txt[$duration]),
1294 1320
 								);
1321
+							}
1295 1322
 						}
1296
-					}
1297
-					elseif ($costs['fixed'] == $pending[1])
1323
+					} elseif ($costs['fixed'] == $pending[1])
1298 1324
 					{
1299 1325
 						$context['pending_payments'][$id] = array(
1300 1326
 							'desc' => sprintf($modSettings['paid_currency_symbol'], $costs['fixed']),
@@ -1312,8 +1338,9 @@  discard block
 block discarded – undo
1312 1338
 					if ($_GET['pending'] == $id && $pending[3] == 'payback' && isset($context['pending_payments'][$id]))
1313 1339
 					{
1314 1340
 						// Flexible?
1315
-						if (isset($_GET['accept']))
1316
-							addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);
1341
+						if (isset($_GET['accept'])) {
1342
+													addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);
1343
+						}
1317 1344
 						unset($pending_details[$id]);
1318 1345
 
1319 1346
 						$new_details = $smcFunc['json_encode']($pending_details);
@@ -1375,8 +1402,9 @@  discard block
 block discarded – undo
1375 1402
 	global $smcFunc;
1376 1403
 
1377 1404
 	// Make it an array.
1378
-	if (!is_array($users))
1379
-		$users = array($users);
1405
+	if (!is_array($users)) {
1406
+			$users = array($users);
1407
+	}
1380 1408
 
1381 1409
 	// Get all the members current groups.
1382 1410
 	$groups = array();
@@ -1414,14 +1442,16 @@  discard block
 block discarded – undo
1414 1442
 		if ($row['id_group'] != 0)
1415 1443
 		{
1416 1444
 			// If this is changing - add the old one to the additional groups so it's not lost.
1417
-			if ($row['id_group'] != $groups[$row['id_member']]['primary'])
1418
-				$groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary'];
1445
+			if ($row['id_group'] != $groups[$row['id_member']]['primary']) {
1446
+							$groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary'];
1447
+			}
1419 1448
 			$groups[$row['id_member']]['primary'] = $row['id_group'];
1420 1449
 		}
1421 1450
 
1422 1451
 		// Additional groups.
1423
-		if (!empty($row['add_groups']))
1424
-			$groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups']));
1452
+		if (!empty($row['add_groups'])) {
1453
+					$groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups']));
1454
+		}
1425 1455
 	}
1426 1456
 	$smcFunc['db_free_result']($request);
1427 1457
 
@@ -1429,9 +1459,10 @@  discard block
 block discarded – undo
1429 1459
 	foreach ($groups as $id => $group)
1430 1460
 	{
1431 1461
 		$group['additional'] = array_unique($group['additional']);
1432
-		foreach ($group['additional'] as $key => $value)
1433
-			if (empty($value))
1462
+		foreach ($group['additional'] as $key => $value) {
1463
+					if (empty($value))
1434 1464
 				unset($group['additional'][$key]);
1465
+		}
1435 1466
 		$addgroups = implode(',', $group['additional']);
1436 1467
 
1437 1468
 		$smcFunc['db_query']('', '
@@ -1465,8 +1496,9 @@  discard block
 block discarded – undo
1465 1496
 	loadSubscriptions();
1466 1497
 
1467 1498
 	// Exists, yes?
1468
-	if (!isset($context['subscriptions'][$id_subscribe]))
1469
-		return;
1499
+	if (!isset($context['subscriptions'][$id_subscribe])) {
1500
+			return;
1501
+	}
1470 1502
 
1471 1503
 	$curSub = $context['subscriptions'][$id_subscribe];
1472 1504
 
@@ -1514,16 +1546,19 @@  discard block
 block discarded – undo
1514 1546
 		list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request);
1515 1547
 
1516 1548
 		// If this has already expired but is active, extension means the period from now.
1517
-		if ($endtime < time())
1518
-			$endtime = time();
1519
-		if ($starttime == 0)
1520
-			$starttime = time();
1549
+		if ($endtime < time()) {
1550
+					$endtime = time();
1551
+		}
1552
+		if ($starttime == 0) {
1553
+					$starttime = time();
1554
+		}
1521 1555
 
1522 1556
 		// Work out the new expiry date.
1523 1557
 		$endtime += $duration;
1524 1558
 
1525
-		if ($forceEndTime != 0)
1526
-			$endtime = $forceEndTime;
1559
+		if ($forceEndTime != 0) {
1560
+					$endtime = $forceEndTime;
1561
+		}
1527 1562
 
1528 1563
 		// As everything else should be good, just update!
1529 1564
 		$smcFunc['db_query']('', '
@@ -1553,8 +1588,9 @@  discard block
 block discarded – undo
1553 1588
 	);
1554 1589
 
1555 1590
 	// Just in case the member doesn't exist.
1556
-	if ($smcFunc['db_num_rows']($request) == 0)
1557
-		return;
1591
+	if ($smcFunc['db_num_rows']($request) == 0) {
1592
+			return;
1593
+	}
1558 1594
 
1559 1595
 	list ($old_id_group, $additional_groups) = $smcFunc['db_fetch_row']($request);
1560 1596
 	$smcFunc['db_free_result']($request);
@@ -1571,16 +1607,18 @@  discard block
 block discarded – undo
1571 1607
 		$id_group = $curSub['prim_group'];
1572 1608
 
1573 1609
 		// Ensure their old privileges are maintained.
1574
-		if ($old_id_group != 0)
1575
-			$newAddGroups[] = $old_id_group;
1610
+		if ($old_id_group != 0) {
1611
+					$newAddGroups[] = $old_id_group;
1612
+		}
1613
+	} else {
1614
+			$id_group = $old_id_group;
1576 1615
 	}
1577
-	else
1578
-		$id_group = $old_id_group;
1579 1616
 
1580 1617
 	// Yep, make sure it's unique, and no empties.
1581
-	foreach ($newAddGroups as $k => $v)
1582
-		if (empty($v))
1618
+	foreach ($newAddGroups as $k => $v) {
1619
+			if (empty($v))
1583 1620
 			unset($newAddGroups[$k]);
1621
+	}
1584 1622
 	$newAddGroups = array_unique($newAddGroups);
1585 1623
 	$newAddGroups = implode(',', $newAddGroups);
1586 1624
 
@@ -1616,16 +1654,19 @@  discard block
 block discarded – undo
1616 1654
 		list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request);
1617 1655
 
1618 1656
 		// If this has already expired but is active, extension means the period from now.
1619
-		if ($endtime < time())
1620
-			$endtime = time();
1621
-		if ($starttime == 0)
1622
-			$starttime = time();
1657
+		if ($endtime < time()) {
1658
+					$endtime = time();
1659
+		}
1660
+		if ($starttime == 0) {
1661
+					$starttime = time();
1662
+		}
1623 1663
 
1624 1664
 		// Work out the new expiry date.
1625 1665
 		$endtime += $duration;
1626 1666
 
1627
-		if ($forceEndTime != 0)
1628
-			$endtime = $forceEndTime;
1667
+		if ($forceEndTime != 0) {
1668
+					$endtime = $forceEndTime;
1669
+		}
1629 1670
 
1630 1671
 		// As everything else should be good, just update!
1631 1672
 		$smcFunc['db_query']('', '
@@ -1648,13 +1689,15 @@  discard block
 block discarded – undo
1648 1689
 
1649 1690
 	// Otherwise a very simple insert.
1650 1691
 	$endtime = time() + $duration;
1651
-	if ($forceEndTime != 0)
1652
-		$endtime = $forceEndTime;
1692
+	if ($forceEndTime != 0) {
1693
+			$endtime = $forceEndTime;
1694
+	}
1653 1695
 
1654
-	if ($forceStartTime == 0)
1655
-		$starttime = time();
1656
-	else
1657
-		$starttime = $forceStartTime;
1696
+	if ($forceStartTime == 0) {
1697
+			$starttime = time();
1698
+	} else {
1699
+			$starttime = $forceStartTime;
1700
+	}
1658 1701
 
1659 1702
 	$smcFunc['db_insert']('',
1660 1703
 		'{db_prefix}log_subscribed',
@@ -1727,15 +1770,17 @@  discard block
 block discarded – undo
1727 1770
 	$new_id_group = -1;
1728 1771
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1729 1772
 	{
1730
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
1731
-			continue;
1773
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
1774
+					continue;
1775
+		}
1732 1776
 
1733 1777
 		// The one we're removing?
1734 1778
 		if ($row['id_subscribe'] == $id_subscribe)
1735 1779
 		{
1736 1780
 			$removals = explode(',', $context['subscriptions'][$row['id_subscribe']]['add_groups']);
1737
-			if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0)
1738
-				$removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
1781
+			if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0) {
1782
+							$removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
1783
+			}
1739 1784
 			$old_id_group = $row['old_id_group'];
1740 1785
 		}
1741 1786
 		// Otherwise things we allow.
@@ -1753,30 +1798,33 @@  discard block
 block discarded – undo
1753 1798
 
1754 1799
 	// Now, for everything we are removing check they definitely are not allowed it.
1755 1800
 	$existingGroups = explode(',', $additional_groups);
1756
-	foreach ($existingGroups as $key => $group)
1757
-		if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed)))
1801
+	foreach ($existingGroups as $key => $group) {
1802
+			if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed)))
1758 1803
 			unset($existingGroups[$key]);
1804
+	}
1759 1805
 
1760 1806
 	// Finally, do something with the current primary group.
1761 1807
 	if (in_array($id_group, $removals))
1762 1808
 	{
1763 1809
 		// If this primary group is actually allowed keep it.
1764
-		if (in_array($id_group, $allowed))
1765
-			$existingGroups[] = $id_group;
1810
+		if (in_array($id_group, $allowed)) {
1811
+					$existingGroups[] = $id_group;
1812
+		}
1766 1813
 
1767 1814
 		// Either way, change the id_group back.
1768 1815
 		if ($new_id_group < 1)
1769 1816
 		{
1770 1817
 			// If we revert to the old id-group we need to ensure it wasn't from a subscription.
1771
-			foreach ($context['subscriptions'] as $id => $group)
1772
-				// It was? Make them a regular member then!
1818
+			foreach ($context['subscriptions'] as $id => $group) {
1819
+							// It was? Make them a regular member then!
1773 1820
 				if ($group['prim_group'] == $old_id_group)
1774 1821
 					$old_id_group = 0;
1822
+			}
1775 1823
 
1776 1824
 			$id_group = $old_id_group;
1825
+		} else {
1826
+					$id_group = $new_id_group;
1777 1827
 		}
1778
-		else
1779
-			$id_group = $new_id_group;
1780 1828
 	}
1781 1829
 
1782 1830
 	// Crazy stuff, we seem to have our groups fixed, just make them unique
@@ -1796,8 +1844,8 @@  discard block
 block discarded – undo
1796 1844
 	);
1797 1845
 
1798 1846
 	// Disable the subscription.
1799
-	if (!$delete)
1800
-		$smcFunc['db_query']('', '
1847
+	if (!$delete) {
1848
+			$smcFunc['db_query']('', '
1801 1849
 			UPDATE {db_prefix}log_subscribed
1802 1850
 			SET status = {int:not_active}
1803 1851
 			WHERE id_member = {int:current_member}
@@ -1808,9 +1856,10 @@  discard block
 block discarded – undo
1808 1856
 				'current_subscription' => $id_subscribe,
1809 1857
 			)
1810 1858
 		);
1859
+	}
1811 1860
 	// Otherwise delete it!
1812
-	else
1813
-		$smcFunc['db_query']('', '
1861
+	else {
1862
+			$smcFunc['db_query']('', '
1814 1863
 			DELETE FROM {db_prefix}log_subscribed
1815 1864
 			WHERE id_member = {int:current_member}
1816 1865
 				AND id_subscribe = {int:current_subscription}',
@@ -1819,7 +1868,8 @@  discard block
 block discarded – undo
1819 1868
 				'current_subscription' => $id_subscribe,
1820 1869
 			)
1821 1870
 		);
1822
-}
1871
+	}
1872
+	}
1823 1873
 
1824 1874
 /**
1825 1875
  * This just kind of caches all the subscription data.
@@ -1828,8 +1878,9 @@  discard block
 block discarded – undo
1828 1878
 {
1829 1879
 	global $context, $txt, $modSettings, $smcFunc;
1830 1880
 
1831
-	if (!empty($context['subscriptions']))
1832
-		return;
1881
+	if (!empty($context['subscriptions'])) {
1882
+			return;
1883
+	}
1833 1884
 
1834 1885
 	// Make sure this is loaded, just in case.
1835 1886
 	loadLanguage('ManagePaid');
@@ -1846,10 +1897,11 @@  discard block
 block discarded – undo
1846 1897
 		// Pick a cost.
1847 1898
 		$costs = $smcFunc['json_decode']($row['cost'], true);
1848 1899
 
1849
-		if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed']))
1850
-			$cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']);
1851
-		else
1852
-			$cost = '???';
1900
+		if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed'])) {
1901
+					$cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']);
1902
+		} else {
1903
+					$cost = '???';
1904
+		}
1853 1905
 
1854 1906
 		// Do the span.
1855 1907
 		preg_match('~(\d*)(\w)~', $row['length'], $match);
@@ -1876,9 +1928,9 @@  discard block
 block discarded – undo
1876 1928
 					$num_length *= 31556926;
1877 1929
 					break;
1878 1930
 			}
1931
+		} else {
1932
+					$length = '??';
1879 1933
 		}
1880
-		else
1881
-			$length = '??';
1882 1934
 
1883 1935
 		$context['subscriptions'][$row['id_subscribe']] = array(
1884 1936
 			'id' => $row['id_subscribe'],
@@ -1913,8 +1965,9 @@  discard block
 block discarded – undo
1913 1965
 	{
1914 1966
 		$ind = $row['status'] == 0 ? 'finished' : 'total';
1915 1967
 
1916
-		if (isset($context['subscriptions'][$row['id_subscribe']]))
1917
-			$context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count'];
1968
+		if (isset($context['subscriptions'][$row['id_subscribe']])) {
1969
+					$context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count'];
1970
+		}
1918 1971
 	}
1919 1972
 	$smcFunc['db_free_result']($request);
1920 1973
 
@@ -1928,8 +1981,9 @@  discard block
 block discarded – undo
1928 1981
 	);
1929 1982
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1930 1983
 	{
1931
-		if (isset($context['subscriptions'][$row['id_subscribe']]))
1932
-			$context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending'];
1984
+		if (isset($context['subscriptions'][$row['id_subscribe']])) {
1985
+					$context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending'];
1986
+		}
1933 1987
 	}
1934 1988
 	$smcFunc['db_free_result']($request);
1935 1989
 }
Please login to merge, or discard this patch.
Sources/ManageSearchEngines.php 1 patch
Braces   +109 added lines, -77 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
  * Entry point for this section.
@@ -38,8 +39,7 @@  discard block
 block discarded – undo
38 39
 			'stats' => 'SpiderStats',
39 40
 		);
40 41
 		$default = 'stats';
41
-	}
42
-	else
42
+	} else
43 43
 	{
44 44
 		$subActions = array(
45 45
 			'settings' => 'ManageSearchEngineSettings',
@@ -90,11 +90,12 @@  discard block
 block discarded – undo
90 90
 		{
91 91
 			disabledState = document.getElementById(\'spider_mode\').value == 0;';
92 92
 
93
-	foreach ($config_vars as $variable)
94
-		if ($variable[1] != 'spider_mode')
93
+	foreach ($config_vars as $variable) {
94
+			if ($variable[1] != 'spider_mode')
95 95
 			$javascript_function .= '
96 96
 			if (document.getElementById(\'' . $variable[1] . '\'))
97 97
 				document.getElementById(\'' . $variable[1] . '\').disabled = disabledState;';
98
+	}
98 99
 
99 100
 	$javascript_function .= '
100 101
 		}
@@ -102,8 +103,9 @@  discard block
 block discarded – undo
102 103
 
103 104
 	call_integration_hook('integrate_modify_search_engine_settings', array(&$config_vars));
104 105
 
105
-	if ($return_config)
106
-		return $config_vars;
106
+	if ($return_config) {
107
+			return $config_vars;
108
+	}
107 109
 
108 110
 	// We need to load the groups for the spider group thingy.
109 111
 	$request = $smcFunc['db_query']('', '
@@ -116,13 +118,15 @@  discard block
 block discarded – undo
116 118
 			'moderator_group' => 3,
117 119
 		)
118 120
 	);
119
-	while ($row = $smcFunc['db_fetch_assoc']($request))
120
-		$config_vars['spider_group'][2][$row['id_group']] = $row['group_name'];
121
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
122
+			$config_vars['spider_group'][2][$row['id_group']] = $row['group_name'];
123
+	}
121 124
 	$smcFunc['db_free_result']($request);
122 125
 
123 126
 	// Make sure it's valid - note that regular members are given id_group = 1 which is reversed in Load.php - no admins here!
124
-	if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']]))
125
-		$_POST['spider_group'] = 0;
127
+	if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']])) {
128
+			$_POST['spider_group'] = 0;
129
+	}
126 130
 
127 131
 	// We'll want this for our easy save.
128 132
 	require_once($sourcedir . '/ManageServer.php');
@@ -166,8 +170,9 @@  discard block
 block discarded – undo
166 170
 	}
167 171
 
168 172
 	// Are we adding a new one?
169
-	if (!empty($_POST['addSpider']))
170
-		return EditSpider();
173
+	if (!empty($_POST['addSpider'])) {
174
+			return EditSpider();
175
+	}
171 176
 	// User pressed the 'remove selection button'.
172 177
 	elseif (!empty($_POST['removeSpiders']) && !empty($_POST['remove']) && is_array($_POST['remove']))
173 178
 	{
@@ -175,8 +180,9 @@  discard block
 block discarded – undo
175 180
 		validateToken('admin-ser');
176 181
 
177 182
 		// Make sure every entry is a proper integer.
178
-		foreach ($_POST['remove'] as $index => $spider_id)
179
-			$_POST['remove'][(int) $index] = (int) $spider_id;
183
+		foreach ($_POST['remove'] as $index => $spider_id) {
184
+					$_POST['remove'][(int) $index] = (int) $spider_id;
185
+		}
180 186
 
181 187
 		// Delete them all!
182 188
 		$smcFunc['db_query']('', '
@@ -215,8 +221,9 @@  discard block
 block discarded – undo
215 221
 	);
216 222
 
217 223
 	$context['spider_last_seen'] = array();
218
-	while ($row = $smcFunc['db_fetch_assoc']($request))
219
-		$context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time'];
224
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
225
+			$context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time'];
226
+	}
220 227
 	$smcFunc['db_free_result']($request);
221 228
 
222 229
 	createToken('admin-ser');
@@ -346,8 +353,9 @@  discard block
 block discarded – undo
346 353
 		)
347 354
 	);
348 355
 	$spiders = array();
349
-	while ($row = $smcFunc['db_fetch_assoc']($request))
350
-		$spiders[$row['id_spider']] = $row;
356
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
357
+			$spiders[$row['id_spider']] = $row;
358
+	}
351 359
 	$smcFunc['db_free_result']($request);
352 360
 
353 361
 	return $spiders;
@@ -397,14 +405,15 @@  discard block
 block discarded – undo
397 405
 		foreach ($ip_sets as $set)
398 406
 		{
399 407
 			$test = ip2range(trim($set));
400
-			if (!empty($test))
401
-				$ips[] = $set;
408
+			if (!empty($test)) {
409
+							$ips[] = $set;
410
+			}
402 411
 		}
403 412
 		$ips = implode(',', $ips);
404 413
 
405 414
 		// Goes in as it is...
406
-		if ($context['id_spider'])
407
-			$smcFunc['db_query']('', '
415
+		if ($context['id_spider']) {
416
+					$smcFunc['db_query']('', '
408 417
 				UPDATE {db_prefix}spiders
409 418
 				SET spider_name = {string:spider_name}, user_agent = {string:spider_agent},
410 419
 					ip_info = {string:ip_info}
@@ -416,8 +425,8 @@  discard block
 block discarded – undo
416 425
 					'ip_info' => $ips,
417 426
 				)
418 427
 			);
419
-		else
420
-			$smcFunc['db_insert']('insert',
428
+		} else {
429
+					$smcFunc['db_insert']('insert',
421 430
 				'{db_prefix}spiders',
422 431
 				array(
423 432
 					'spider_name' => 'string', 'user_agent' => 'string', 'ip_info' => 'string',
@@ -427,6 +436,7 @@  discard block
 block discarded – undo
427 436
 				),
428 437
 				array('id_spider')
429 438
 			);
439
+		}
430 440
 
431 441
 
432 442
 		cache_put_data('spider_search', null);
@@ -454,13 +464,14 @@  discard block
 block discarded – undo
454 464
 				'current_spider' => $context['id_spider'],
455 465
 			)
456 466
 		);
457
-		if ($row = $smcFunc['db_fetch_assoc']($request))
458
-			$context['spider'] = array(
467
+		if ($row = $smcFunc['db_fetch_assoc']($request)) {
468
+					$context['spider'] = array(
459 469
 				'id' => $row['id_spider'],
460 470
 				'name' => $row['spider_name'],
461 471
 				'agent' => $row['user_agent'],
462 472
 				'ip_info' => $row['ip_info'],
463 473
 			);
474
+		}
464 475
 		$smcFunc['db_free_result']($request);
465 476
 	}
466 477
 
@@ -477,8 +488,9 @@  discard block
 block discarded – undo
477 488
 {
478 489
 	global $modSettings, $smcFunc;
479 490
 
480
-	if (isset($_SESSION['id_robot']))
481
-		unset($_SESSION['id_robot']);
491
+	if (isset($_SESSION['id_robot'])) {
492
+			unset($_SESSION['id_robot']);
493
+	}
482 494
 	$_SESSION['robot_check'] = time();
483 495
 
484 496
 	// We cache the spider data for ten minutes if we can.
@@ -492,15 +504,17 @@  discard block
 block discarded – undo
492 504
 			)
493 505
 		);
494 506
 		$spider_data = array();
495
-		while ($row = $smcFunc['db_fetch_assoc']($request))
496
-			$spider_data[] = $row;
507
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
508
+					$spider_data[] = $row;
509
+		}
497 510
 		$smcFunc['db_free_result']($request);
498 511
 
499 512
 		cache_put_data('spider_search', $spider_data, 600);
500 513
 	}
501 514
 
502
-	if (empty($spider_data))
503
-		return false;
515
+	if (empty($spider_data)) {
516
+			return false;
517
+	}
504 518
 
505 519
 	// Only do these bits once.
506 520
 	$ci_user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
@@ -508,33 +522,38 @@  discard block
 block discarded – undo
508 522
 	foreach ($spider_data as $spider)
509 523
 	{
510 524
 		// User agent is easy.
511
-		if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false)
512
-			$_SESSION['id_robot'] = $spider['id_spider'];
525
+		if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false) {
526
+					$_SESSION['id_robot'] = $spider['id_spider'];
527
+		}
513 528
 		// IP stuff is harder.
514 529
 		elseif ($_SERVER['REMOTE_ADDR'])
515 530
 		{
516 531
 			$ips = explode(',', $spider['ip_info']);
517 532
 			foreach ($ips as $ip)
518 533
 			{
519
-				if ($ip === '')
520
-					continue;
534
+				if ($ip === '') {
535
+									continue;
536
+				}
521 537
 
522 538
 				$ip = ip2range($ip);
523 539
 				if (!empty($ip))
524 540
 				{
525
-					if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR']))
526
-						$_SESSION['id_robot'] = $spider['id_spider'];
541
+					if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR'])) {
542
+											$_SESSION['id_robot'] = $spider['id_spider'];
543
+					}
527 544
 				}
528 545
 			}
529 546
 		}
530 547
 
531
-		if (isset($_SESSION['id_robot']))
532
-			break;
548
+		if (isset($_SESSION['id_robot'])) {
549
+					break;
550
+		}
533 551
 	}
534 552
 
535 553
 	// If this is low server tracking then log the spider here as opposed to the main logging function.
536
-	if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot']))
537
-		logSpider();
554
+	if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot'])) {
555
+			logSpider();
556
+	}
538 557
 
539 558
 	return !empty($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
540 559
 }
@@ -548,8 +567,9 @@  discard block
 block discarded – undo
548 567
 {
549 568
 	global $smcFunc, $modSettings, $context;
550 569
 
551
-	if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot']))
552
-		return;
570
+	if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot'])) {
571
+			return;
572
+	}
553 573
 
554 574
 	// Attempt to update today's entry.
555 575
 	if ($modSettings['spider_mode'] == 1)
@@ -590,9 +610,9 @@  discard block
 block discarded – undo
590 610
 			$url = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
591 611
 			unset($url['sesc'], $url[$context['session_var']]);
592 612
 			$url = $smcFunc['json_encode']($url);
613
+		} else {
614
+					$url = '';
593 615
 		}
594
-		else
595
-			$url = '';
596 616
 
597 617
 		$smcFunc['db_insert']('insert',
598 618
 			'{db_prefix}log_spider_hits',
@@ -620,12 +640,14 @@  discard block
 block discarded – undo
620 640
 		)
621 641
 	);
622 642
 	$spider_hits = array();
623
-	while ($row = $smcFunc['db_fetch_assoc']($request))
624
-		$spider_hits[] = $row;
643
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
644
+			$spider_hits[] = $row;
645
+	}
625 646
 	$smcFunc['db_free_result']($request);
626 647
 
627
-	if (empty($spider_hits))
628
-		return;
648
+	if (empty($spider_hits)) {
649
+			return;
650
+	}
629 651
 
630 652
 	// Attempt to update the master data.
631 653
 	$stat_inserts = array();
@@ -646,18 +668,20 @@  discard block
 block discarded – undo
646 668
 				'hits' => $stat['num_hits'],
647 669
 			)
648 670
 		);
649
-		if ($smcFunc['db_affected_rows']() == 0)
650
-			$stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']);
671
+		if ($smcFunc['db_affected_rows']() == 0) {
672
+					$stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']);
673
+		}
651 674
 	}
652 675
 
653 676
 	// New stats?
654
-	if (!empty($stat_inserts))
655
-		$smcFunc['db_insert']('ignore',
677
+	if (!empty($stat_inserts)) {
678
+			$smcFunc['db_insert']('ignore',
656 679
 			'{db_prefix}log_spider_stats',
657 680
 			array('stat_date' => 'date', 'id_spider' => 'int', 'page_hits' => 'int', 'last_seen' => 'int'),
658 681
 			$stat_inserts,
659 682
 			array('stat_date', 'id_spider')
660 683
 		);
684
+	}
661 685
 
662 686
 	// All processed.
663 687
 	$smcFunc['db_query']('', '
@@ -700,8 +724,7 @@  discard block
 block discarded – undo
700 724
 					'delete_period' => $deleteTime,
701 725
 				)
702 726
 			);
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			// Deleting all of them
707 730
 			$smcFunc['db_query']('', '
@@ -791,10 +814,11 @@  discard block
 block discarded – undo
791 814
 		foreach ($context['spider_logs']['rows'] as $k => $row)
792 815
 		{
793 816
 			// Feature disabled?
794
-			if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3)
795
-				$context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>';
796
-			else
797
-				$urls[$k] = array($row['data']['viewing']['value'], -1);
817
+			if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3) {
818
+							$context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>';
819
+			} else {
820
+							$urls[$k] = array($row['data']['viewing']['value'], -1);
821
+			}
798 822
 		}
799 823
 
800 824
 		// Now stick in the new URLs.
@@ -836,8 +860,9 @@  discard block
 block discarded – undo
836 860
 		)
837 861
 	);
838 862
 	$spider_logs = array();
839
-	while ($row = $smcFunc['db_fetch_assoc']($request))
840
-		$spider_logs[] = $row;
863
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
864
+			$spider_logs[] = $row;
865
+	}
841 866
 	$smcFunc['db_free_result']($request);
842 867
 
843 868
 	return $spider_logs;
@@ -913,14 +938,18 @@  discard block
 block discarded – undo
913 938
 
914 939
 	// Prepare the dates for the drop down.
915 940
 	$date_choices = array();
916
-	for ($y = $min_year; $y <= $max_year; $y++)
917
-		for ($m = 1; $m <= 12; $m++)
941
+	for ($y = $min_year; $y <= $max_year; $y++) {
942
+			for ($m = 1;
943
+	}
944
+	$m <= 12; $m++)
918 945
 		{
919 946
 			// This doesn't count?
920
-			if ($y == $min_year && $m < $min_month)
921
-				continue;
922
-			if ($y == $max_year && $m > $max_month)
923
-				break;
947
+			if ($y == $min_year && $m < $min_month) {
948
+							continue;
949
+			}
950
+			if ($y == $max_year && $m > $max_month) {
951
+							break;
952
+			}
924 953
 
925 954
 			$date_choices[$y . $m] = $txt['months_short'][$m] . ' ' . $y;
926 955
 		}
@@ -933,13 +962,14 @@  discard block
 block discarded – undo
933 962
 		' . $txt['spider_stats_select_month'] . ':
934 963
 		<select name="new_date" onchange="document.spider_stat_list.submit();">';
935 964
 
936
-	if (empty($date_choices))
937
-		$date_select .= '
965
+	if (empty($date_choices)) {
966
+			$date_select .= '
938 967
 			<option></option>';
939
-	else
940
-		foreach ($date_choices as $id => $text)
968
+	} else {
969
+			foreach ($date_choices as $id => $text)
941 970
 			$date_select .= '
942 971
 			<option value="' . $id . '"' . ($current_date == $id ? ' selected' : '') . '>' . $text . '</option>';
972
+	}
943 973
 
944 974
 	$date_select .= '
945 975
 		</select>
@@ -1063,8 +1093,9 @@  discard block
 block discarded – undo
1063 1093
 		)
1064 1094
 	);
1065 1095
 	$spider_stats = array();
1066
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1067
-		$spider_stats[] = $row;
1096
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1097
+			$spider_stats[] = $row;
1098
+	}
1068 1099
 	$smcFunc['db_free_result']($request);
1069 1100
 
1070 1101
 	return $spider_stats;
@@ -1105,8 +1136,9 @@  discard block
 block discarded – undo
1105 1136
 		array()
1106 1137
 	);
1107 1138
 	$spiders = array();
1108
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1109
-		$spiders[$row['id_spider']] = $row['spider_name'];
1139
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1140
+			$spiders[$row['id_spider']] = $row['spider_name'];
1141
+	}
1110 1142
 	$smcFunc['db_free_result']($request);
1111 1143
 
1112 1144
 	updateSettings(array('spider_name_cache' => $smcFunc['json_encode']($spiders)));
Please login to merge, or discard this patch.
Sources/Subs-Editor.php 1 patch
Braces   +402 added lines, -303 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
  * !!!Compatibility!!!
@@ -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);
@@ -107,8 +110,9 @@  discard block
 block discarded – undo
107 110
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
108 111
 
109 112
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
110
-	if (isBrowser('webkit'))
111
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
113
+	if (isBrowser('webkit')) {
114
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
115
+	}
112 116
 
113 117
 	// If there's a trailing break get rid of it - Firefox tends to add one.
114 118
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -123,8 +127,9 @@  discard block
 block discarded – undo
123 127
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
124 128
 		{
125 129
 			// Value of 2 means we're inside the tag.
126
-			if ($i % 4 == 2)
127
-				$parts[$i] = strip_tags($parts[$i]);
130
+			if ($i % 4 == 2) {
131
+							$parts[$i] = strip_tags($parts[$i]);
132
+			}
128 133
 		}
129 134
 
130 135
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -150,18 +155,19 @@  discard block
 block discarded – undo
150 155
 			{
151 156
 				$found = array_search($file, $smileysto);
152 157
 				// Note the weirdness here is to stop double spaces between smileys.
153
-				if ($found)
154
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
155
-				else
156
-					$matches[1][$k] = '';
158
+				if ($found) {
159
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
160
+				} else {
161
+									$matches[1][$k] = '';
162
+				}
157 163
 			}
158
-		}
159
-		else
164
+		} else
160 165
 		{
161 166
 			// Load all the smileys.
162 167
 			$names = array();
163
-			foreach ($matches[1] as $file)
164
-				$names[] = $file;
168
+			foreach ($matches[1] as $file) {
169
+							$names[] = $file;
170
+			}
165 171
 			$names = array_unique($names);
166 172
 
167 173
 			if (!empty($names))
@@ -175,13 +181,15 @@  discard block
 block discarded – undo
175 181
 					)
176 182
 				);
177 183
 				$mappings = array();
178
-				while ($row = $smcFunc['db_fetch_assoc']($request))
179
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
184
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
186
+				}
180 187
 				$smcFunc['db_free_result']($request);
181 188
 
182
-				foreach ($matches[1] as $k => $file)
183
-					if (isset($mappings[$file]))
189
+				foreach ($matches[1] as $k => $file) {
190
+									if (isset($mappings[$file]))
184 191
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
192
+				}
185 193
 			}
186 194
 		}
187 195
 
@@ -193,8 +201,9 @@  discard block
 block discarded – undo
193 201
 	}
194 202
 
195 203
 	// Only try to buy more time if the client didn't quit.
196
-	if (connection_aborted() && $context['server']['is_apache'])
197
-		@apache_reset_timeout();
204
+	if (connection_aborted() && $context['server']['is_apache']) {
205
+			@apache_reset_timeout();
206
+	}
198 207
 
199 208
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
200 209
 	$replacement = '';
@@ -205,9 +214,9 @@  discard block
 block discarded – undo
205 214
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
206 215
 		{
207 216
 			// If it's being closed instantly, we can't deal with it...yet.
208
-			if ($matches[5] === '/')
209
-				continue;
210
-			else
217
+			if ($matches[5] === '/') {
218
+							continue;
219
+			} else
211 220
 			{
212 221
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
213 222
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -223,8 +232,9 @@  discard block
 block discarded – undo
223 232
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
224 233
 
225 234
 					// Something like 'font-weight: bold' is expected here.
226
-					if (strpos($clean_type_value_pair, ':') === false)
227
-						continue;
235
+					if (strpos($clean_type_value_pair, ':') === false) {
236
+											continue;
237
+					}
228 238
 
229 239
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
230 240
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -246,8 +256,7 @@  discard block
 block discarded – undo
246 256
 							{
247 257
 								$curCloseTags .= '[/u]';
248 258
 								$replacement .= '[u]';
249
-							}
250
-							elseif ($style_value == 'line-through')
259
+							} elseif ($style_value == 'line-through')
251 260
 							{
252 261
 								$curCloseTags .= '[/s]';
253 262
 								$replacement .= '[s]';
@@ -259,13 +268,11 @@  discard block
 block discarded – undo
259 268
 							{
260 269
 								$curCloseTags .= '[/left]';
261 270
 								$replacement .= '[left]';
262
-							}
263
-							elseif ($style_value == 'center')
271
+							} elseif ($style_value == 'center')
264 272
 							{
265 273
 								$curCloseTags .= '[/center]';
266 274
 								$replacement .= '[center]';
267
-							}
268
-							elseif ($style_value == 'right')
275
+							} elseif ($style_value == 'right')
269 276
 							{
270 277
 								$curCloseTags .= '[/right]';
271 278
 								$replacement .= '[right]';
@@ -287,8 +294,9 @@  discard block
 block discarded – undo
287 294
 
288 295
 						case 'font-size':
289 296
 							// Sometimes people put decimals where decimals should not be.
290
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
291
-								$style_value = $dec_matches[1] . $dec_matches[2];
297
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
298
+															$style_value = $dec_matches[1] . $dec_matches[2];
299
+							}
292 300
 
293 301
 							$curCloseTags .= '[/size]';
294 302
 							$replacement .= '[size=' . $style_value . ']';
@@ -296,8 +304,9 @@  discard block
 block discarded – undo
296 304
 
297 305
 						case 'font-family':
298 306
 							// Only get the first freaking font if there's a list!
299
-							if (strpos($style_value, ',') !== false)
300
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
307
+							if (strpos($style_value, ',') !== false) {
308
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
309
+							}
301 310
 
302 311
 							$curCloseTags .= '[/font]';
303 312
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -306,13 +315,15 @@  discard block
 block discarded – undo
306 315
 						// This is a hack for images with dimensions embedded.
307 316
 						case 'width':
308 317
 						case 'height':
309
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
310
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
318
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
319
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
320
+							}
311 321
 						break;
312 322
 
313 323
 						case 'list-style-type':
314
-							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)
315
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
324
+							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) {
325
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
326
+							}
316 327
 						break;
317 328
 					}
318 329
 				}
@@ -325,18 +336,17 @@  discard block
 block discarded – undo
325 336
 				}
326 337
 
327 338
 				// If there's something that still needs closing, push it to the stack.
328
-				if (!empty($curCloseTags))
329
-					array_push($stack, array(
339
+				if (!empty($curCloseTags)) {
340
+									array_push($stack, array(
330 341
 							'element' => strtolower($curElement),
331 342
 							'closeTags' => $curCloseTags
332 343
 						)
333 344
 					);
334
-				elseif (!empty($extra_attr))
335
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
345
+				} elseif (!empty($extra_attr)) {
346
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
347
+				}
336 348
 			}
337
-		}
338
-
339
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
349
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
340 350
 		{
341 351
 			// Is this the element that we've been waiting for to be closed?
342 352
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -346,28 +356,32 @@  discard block
 block discarded – undo
346 356
 			}
347 357
 
348 358
 			// Must've been something else.
349
-			else
350
-				$replacement .= $part;
359
+			else {
360
+							$replacement .= $part;
361
+			}
351 362
 		}
352 363
 		// In all other cases, just add the part to the replacement.
353
-		else
354
-			$replacement .= $part;
364
+		else {
365
+					$replacement .= $part;
366
+		}
355 367
 	}
356 368
 
357 369
 	// Now put back the replacement in the text.
358 370
 	$text = $replacement;
359 371
 
360 372
 	// We are not finished yet, request more time.
361
-	if (connection_aborted() && $context['server']['is_apache'])
362
-		@apache_reset_timeout();
373
+	if (connection_aborted() && $context['server']['is_apache']) {
374
+			@apache_reset_timeout();
375
+	}
363 376
 
364 377
 	// Let's pull out any legacy alignments.
365 378
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
366 379
 	{
367 380
 		// Find the position in the text of this tag over again.
368 381
 		$start_pos = strpos($text, $matches[0]);
369
-		if ($start_pos === false)
370
-			break;
382
+		if ($start_pos === false) {
383
+					break;
384
+		}
371 385
 
372 386
 		// End tag?
373 387
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -381,8 +395,7 @@  discard block
 block discarded – undo
381 395
 
382 396
 			// Put the tags back into the body.
383 397
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
384
-		}
385
-		else
398
+		} else
386 399
 		{
387 400
 			// Just get rid of this evil tag.
388 401
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -395,8 +408,9 @@  discard block
 block discarded – undo
395 408
 		// Find the position of this again.
396 409
 		$start_pos = strpos($text, $matches[0]);
397 410
 		$end_pos = false;
398
-		if ($start_pos === false)
399
-			break;
411
+		if ($start_pos === false) {
412
+					break;
413
+		}
400 414
 
401 415
 		// This must have an end tag - and we must find the right one.
402 416
 		$lower_text = strtolower($text);
@@ -429,8 +443,9 @@  discard block
 block discarded – undo
429 443
 				break;
430 444
 			}
431 445
 		}
432
-		if ($end_pos === false)
433
-			break;
446
+		if ($end_pos === false) {
447
+					break;
448
+		}
434 449
 
435 450
 		// Now work out what the attributes are.
436 451
 		$attribs = fetchTagAttributes($matches[1]);
@@ -444,11 +459,11 @@  discard block
 block discarded – undo
444 459
 				$v = (int) trim($v);
445 460
 				$v = empty($v) ? 1 : $v;
446 461
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
462
+			} elseif ($s == 'face') {
463
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
464
+			} elseif ($s == 'color') {
465
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
447 466
 			}
448
-			elseif ($s == 'face')
449
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
450
-			elseif ($s == 'color')
451
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
452 467
 		}
453 468
 
454 469
 		// As before add in our tags.
@@ -456,8 +471,9 @@  discard block
 block discarded – undo
456 471
 		foreach ($tags as $tag)
457 472
 		{
458 473
 			$before .= $tag[0];
459
-			if (isset($tag[1]))
460
-				$after = $tag[1] . $after;
474
+			if (isset($tag[1])) {
475
+							$after = $tag[1] . $after;
476
+			}
461 477
 		}
462 478
 
463 479
 		// Remove the tag so it's never checked again.
@@ -468,8 +484,9 @@  discard block
 block discarded – undo
468 484
 	}
469 485
 
470 486
 	// Almost there, just a little more time.
471
-	if (connection_aborted() && $context['server']['is_apache'])
472
-		@apache_reset_timeout();
487
+	if (connection_aborted() && $context['server']['is_apache']) {
488
+			@apache_reset_timeout();
489
+	}
473 490
 
474 491
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
475 492
 	{
@@ -525,12 +542,13 @@  discard block
 block discarded – undo
525 542
 						{
526 543
 							$inList = true;
527 544
 
528
-							if ($tag === 'ol')
529
-								$listType = 'decimal';
530
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
531
-								$listType = $listTypeMapping[$match[1]];
532
-							else
533
-								$listType = null;
545
+							if ($tag === 'ol') {
546
+															$listType = 'decimal';
547
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
548
+															$listType = $listTypeMapping[$match[1]];
549
+							} else {
550
+															$listType = null;
551
+							}
534 552
 
535 553
 							$listDepth++;
536 554
 
@@ -594,9 +612,7 @@  discard block
 block discarded – undo
594 612
 							$parts[$i + 1] = '';
595 613
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
596 614
 							$parts[$i + 3] = '';
597
-						}
598
-
599
-						else
615
+						} else
600 616
 						{
601 617
 							// We're in a list item.
602 618
 							if ($listDepth > 0)
@@ -633,9 +649,7 @@  discard block
 block discarded – undo
633 649
 							$parts[$i + 1] = '';
634 650
 							$parts[$i + 2] = '';
635 651
 							$parts[$i + 3] = '';
636
-						}
637
-
638
-						else
652
+						} else
639 653
 						{
640 654
 							// Remove the trailing breaks from the list item.
641 655
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -673,8 +687,9 @@  discard block
 block discarded – undo
673 687
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
674 688
 		}
675 689
 
676
-		for ($i = $listDepth; $i > 0; $i--)
677
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
690
+		for ($i = $listDepth; $i > 0; $i--) {
691
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
692
+		}
678 693
 
679 694
 	}
680 695
 
@@ -683,8 +698,9 @@  discard block
 block discarded – undo
683 698
 	{
684 699
 		// Find the position of the image.
685 700
 		$start_pos = strpos($text, $matches[0]);
686
-		if ($start_pos === false)
687
-			break;
701
+		if ($start_pos === false) {
702
+					break;
703
+		}
688 704
 		$end_pos = $start_pos + strlen($matches[0]);
689 705
 
690 706
 		$params = '';
@@ -693,12 +709,13 @@  discard block
 block discarded – undo
693 709
 		$attrs = fetchTagAttributes($matches[1]);
694 710
 		foreach ($attrs as $attrib => $value)
695 711
 		{
696
-			if (in_array($attrib, array('width', 'height')))
697
-				$params .= ' ' . $attrib . '=' . (int) $value;
698
-			elseif ($attrib == 'alt' && trim($value) != '')
699
-				$params .= ' alt=' . trim($value);
700
-			elseif ($attrib == 'src')
701
-				$src = trim($value);
712
+			if (in_array($attrib, array('width', 'height'))) {
713
+							$params .= ' ' . $attrib . '=' . (int) $value;
714
+			} elseif ($attrib == 'alt' && trim($value) != '') {
715
+							$params .= ' alt=' . trim($value);
716
+			} elseif ($attrib == 'src') {
717
+							$src = trim($value);
718
+			}
702 719
 		}
703 720
 
704 721
 		$tag = '';
@@ -709,10 +726,11 @@  discard block
 block discarded – undo
709 726
 			{
710 727
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
711 728
 
712
-				if (substr($src, 0, 1) === '/')
713
-					$src = $baseURL . $src;
714
-				else
715
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
729
+				if (substr($src, 0, 1) === '/') {
730
+									$src = $baseURL . $src;
731
+				} else {
732
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
733
+				}
716 734
 			}
717 735
 
718 736
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -890,20 +908,23 @@  discard block
 block discarded – undo
890 908
 		},
891 909
 	);
892 910
 
893
-	foreach ($tags as $tag => $replace)
894
-		$text = preg_replace_callback($tag, $replace, $text);
911
+	foreach ($tags as $tag => $replace) {
912
+			$text = preg_replace_callback($tag, $replace, $text);
913
+	}
895 914
 
896 915
 	// Please give us just a little more time.
897
-	if (connection_aborted() && $context['server']['is_apache'])
898
-		@apache_reset_timeout();
916
+	if (connection_aborted() && $context['server']['is_apache']) {
917
+			@apache_reset_timeout();
918
+	}
899 919
 
900 920
 	// What about URL's - the pain in the ass of the tag world.
901 921
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
902 922
 	{
903 923
 		// Find the position of the URL.
904 924
 		$start_pos = strpos($text, $matches[0]);
905
-		if ($start_pos === false)
906
-			break;
925
+		if ($start_pos === false) {
926
+					break;
927
+		}
907 928
 		$end_pos = $start_pos + strlen($matches[0]);
908 929
 
909 930
 		$tag_type = 'url';
@@ -917,8 +938,9 @@  discard block
 block discarded – undo
917 938
 				$href = trim($value);
918 939
 
919 940
 				// Are we dealing with an FTP link?
920
-				if (preg_match('~^ftps?://~', $href) === 1)
921
-					$tag_type = 'ftp';
941
+				if (preg_match('~^ftps?://~', $href) === 1) {
942
+									$tag_type = 'ftp';
943
+				}
922 944
 
923 945
 				// Or is this a link to an email address?
924 946
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -932,28 +954,31 @@  discard block
 block discarded – undo
932 954
 				{
933 955
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
934 956
 
935
-					if (substr($href, 0, 1) === '/')
936
-						$href = $baseURL . $href;
937
-					else
938
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
957
+					if (substr($href, 0, 1) === '/') {
958
+											$href = $baseURL . $href;
959
+					} else {
960
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
961
+					}
939 962
 				}
940 963
 			}
941 964
 
942 965
 			// External URL?
943 966
 			if ($attrib == 'target' && $tag_type == 'url')
944 967
 			{
945
-				if (trim($value) == '_blank')
946
-					$tag_type == 'iurl';
968
+				if (trim($value) == '_blank') {
969
+									$tag_type == 'iurl';
970
+				}
947 971
 			}
948 972
 		}
949 973
 
950 974
 		$tag = '';
951 975
 		if ($href != '')
952 976
 		{
953
-			if ($matches[2] == $href)
954
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
955
-			else
956
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
977
+			if ($matches[2] == $href) {
978
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
979
+			} else {
980
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
981
+			}
957 982
 		}
958 983
 
959 984
 		// Replace the tag
@@ -992,17 +1017,18 @@  discard block
 block discarded – undo
992 1017
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
993 1018
 		if ($text[$i] == '=')
994 1019
 		{
995
-			if ($tag_state == 0)
996
-				$tag_state = 1;
997
-			elseif ($tag_state == 2)
998
-				$value .= '=';
1020
+			if ($tag_state == 0) {
1021
+							$tag_state = 1;
1022
+			} elseif ($tag_state == 2) {
1023
+							$value .= '=';
1024
+			}
999 1025
 		}
1000 1026
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
1001 1027
 		elseif ($text[$i] == ' ')
1002 1028
 		{
1003
-			if ($tag_state == 2)
1004
-				$value .= ' ';
1005
-			elseif ($tag_state == 1)
1029
+			if ($tag_state == 2) {
1030
+							$value .= ' ';
1031
+			} elseif ($tag_state == 1)
1006 1032
 			{
1007 1033
 				$attribs[$key] = $value;
1008 1034
 				$key = $value = '';
@@ -1013,24 +1039,27 @@  discard block
 block discarded – undo
1013 1039
 		elseif ($text[$i] == '"')
1014 1040
 		{
1015 1041
 			// Must be either going into or out of a string.
1016
-			if ($tag_state == 1)
1017
-				$tag_state = 2;
1018
-			else
1019
-				$tag_state = 1;
1042
+			if ($tag_state == 1) {
1043
+							$tag_state = 2;
1044
+			} else {
1045
+							$tag_state = 1;
1046
+			}
1020 1047
 		}
1021 1048
 		// Otherwise it's fine.
1022 1049
 		else
1023 1050
 		{
1024
-			if ($tag_state == 0)
1025
-				$key .= $text[$i];
1026
-			else
1027
-				$value .= $text[$i];
1051
+			if ($tag_state == 0) {
1052
+							$key .= $text[$i];
1053
+			} else {
1054
+							$value .= $text[$i];
1055
+			}
1028 1056
 		}
1029 1057
 	}
1030 1058
 
1031 1059
 	// Anything left?
1032
-	if ($key != '' && $value != '')
1033
-		$attribs[$key] = $value;
1060
+	if ($key != '' && $value != '') {
1061
+			$attribs[$key] = $value;
1062
+	}
1034 1063
 
1035 1064
 	return $attribs;
1036 1065
 }
@@ -1046,15 +1075,17 @@  discard block
 block discarded – undo
1046 1075
 	global $modSettings;
1047 1076
 
1048 1077
 	// Don't care about the texts that are too short.
1049
-	if (strlen($text) < 3)
1050
-		return $text;
1078
+	if (strlen($text) < 3) {
1079
+			return $text;
1080
+	}
1051 1081
 
1052 1082
 	// A list of tags that's disabled by the admin.
1053 1083
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
1054 1084
 
1055 1085
 	// Add flash if it's disabled as embedded tag.
1056
-	if (empty($modSettings['enableEmbeddedFlash']))
1057
-		$disabled['flash'] = true;
1086
+	if (empty($modSettings['enableEmbeddedFlash'])) {
1087
+			$disabled['flash'] = true;
1088
+	}
1058 1089
 
1059 1090
 	// Get a list of all the tags that are not disabled.
1060 1091
 	$all_tags = parse_bbc(false);
@@ -1062,10 +1093,12 @@  discard block
 block discarded – undo
1062 1093
 	$self_closing_tags = array();
1063 1094
 	foreach ($all_tags as $tag)
1064 1095
 	{
1065
-		if (!isset($disabled[$tag['tag']]))
1066
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1067
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1068
-			$self_closing_tags[] = $tag['tag'];
1096
+		if (!isset($disabled[$tag['tag']])) {
1097
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1098
+		}
1099
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1100
+					$self_closing_tags[] = $tag['tag'];
1101
+		}
1069 1102
 	}
1070 1103
 
1071 1104
 	// 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!
@@ -1092,16 +1125,19 @@  discard block
 block discarded – undo
1092 1125
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1093 1126
 
1094 1127
 				// We're closing the exact same tag that we opened.
1095
-				if ($isClosingTag && $insideTag === $tagName)
1096
-					$insideTag = null;
1128
+				if ($isClosingTag && $insideTag === $tagName) {
1129
+									$insideTag = null;
1130
+				}
1097 1131
 
1098 1132
 				// We're opening a tag and we're not yet inside one either
1099
-				elseif (!$isClosingTag && $insideTag === null)
1100
-					$insideTag = $tagName;
1133
+				elseif (!$isClosingTag && $insideTag === null) {
1134
+									$insideTag = $tagName;
1135
+				}
1101 1136
 
1102 1137
 				// In all other cases, this tag must be invalid
1103
-				else
1104
-					unset($matches[$i]);
1138
+				else {
1139
+									unset($matches[$i]);
1140
+				}
1105 1141
 			}
1106 1142
 
1107 1143
 			// The next one is gonna be the other one.
@@ -1109,8 +1145,9 @@  discard block
 block discarded – undo
1109 1145
 		}
1110 1146
 
1111 1147
 		// We're still inside a tag and had no chance for closure?
1112
-		if ($insideTag !== null)
1113
-			$matches[] = '[/' . $insideTag . ']';
1148
+		if ($insideTag !== null) {
1149
+					$matches[] = '[/' . $insideTag . ']';
1150
+		}
1114 1151
 
1115 1152
 		// And a complete text string again.
1116 1153
 		$text = implode('', $matches);
@@ -1119,8 +1156,9 @@  discard block
 block discarded – undo
1119 1156
 	// Quickly remove any tags which are back to back.
1120 1157
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1121 1158
 	$lastlen = 0;
1122
-	while (strlen($text) !== $lastlen)
1123
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1159
+	while (strlen($text) !== $lastlen) {
1160
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1161
+	}
1124 1162
 
1125 1163
 	// Need to sort the tags my name length.
1126 1164
 	uksort($valid_tags, 'sort_array_length');
@@ -1157,8 +1195,9 @@  discard block
 block discarded – undo
1157 1195
 			$isCompetingTag = in_array($tag, $competing_tags);
1158 1196
 
1159 1197
 			// Check if this might be one of those cleaned out tags.
1160
-			if ($tag === '')
1161
-				continue;
1198
+			if ($tag === '') {
1199
+							continue;
1200
+			}
1162 1201
 
1163 1202
 			// Special case: inside [code] blocks any code is left untouched.
1164 1203
 			elseif ($tag === 'code')
@@ -1169,8 +1208,9 @@  discard block
 block discarded – undo
1169 1208
 					$inCode = false;
1170 1209
 
1171 1210
 					// Reopen tags that were closed before the code block.
1172
-					if (!empty($inlineElements))
1173
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1211
+					if (!empty($inlineElements)) {
1212
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1213
+					}
1174 1214
 				}
1175 1215
 
1176 1216
 				// We're outside a coding and nobbc block and opening it.
@@ -1199,8 +1239,9 @@  discard block
 block discarded – undo
1199 1239
 					$inNoBbc = false;
1200 1240
 
1201 1241
 					// Some inline elements might've been closed that need reopening.
1202
-					if (!empty($inlineElements))
1203
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1242
+					if (!empty($inlineElements)) {
1243
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1244
+					}
1204 1245
 				}
1205 1246
 
1206 1247
 				// We're outside a nobbc and coding block and opening it.
@@ -1220,8 +1261,9 @@  discard block
 block discarded – undo
1220 1261
 			}
1221 1262
 
1222 1263
 			// So, we're inside one of the special blocks: ignore any tag.
1223
-			elseif ($inCode || $inNoBbc)
1224
-				continue;
1264
+			elseif ($inCode || $inNoBbc) {
1265
+							continue;
1266
+			}
1225 1267
 
1226 1268
 			// We're dealing with an opening tag.
1227 1269
 			if ($isOpeningTag)
@@ -1262,8 +1304,9 @@  discard block
 block discarded – undo
1262 1304
 							if ($parts[$j + 3] === $tag)
1263 1305
 							{
1264 1306
 								// If it's an opening tag, increase the level.
1265
-								if ($parts[$j + 2] === '')
1266
-									$curLevel++;
1307
+								if ($parts[$j + 2] === '') {
1308
+																	$curLevel++;
1309
+								}
1267 1310
 
1268 1311
 								// A closing tag, decrease the level.
1269 1312
 								else
@@ -1286,13 +1329,15 @@  discard block
 block discarded – undo
1286 1329
 					{
1287 1330
 						if ($isCompetingTag)
1288 1331
 						{
1289
-							if (!isset($competingElements[$tag]))
1290
-								$competingElements[$tag] = array();
1332
+							if (!isset($competingElements[$tag])) {
1333
+															$competingElements[$tag] = array();
1334
+							}
1291 1335
 
1292 1336
 							$competingElements[$tag][] = $parts[$i + 4];
1293 1337
 
1294
-							if (count($competingElements[$tag]) > 1)
1295
-								$parts[$i] .= '[/' . $tag . ']';
1338
+							if (count($competingElements[$tag]) > 1) {
1339
+															$parts[$i] .= '[/' . $tag . ']';
1340
+							}
1296 1341
 						}
1297 1342
 
1298 1343
 						$inlineElements[$elementContent] = $tag;
@@ -1313,15 +1358,17 @@  discard block
 block discarded – undo
1313 1358
 						$addClosingTags = array();
1314 1359
 						while ($element = array_pop($blockElements))
1315 1360
 						{
1316
-							if ($element === $tag)
1317
-								break;
1361
+							if ($element === $tag) {
1362
+															break;
1363
+							}
1318 1364
 
1319 1365
 							// Still a block tag was open not equal to this tag.
1320 1366
 							$addClosingTags[] = $element['type'];
1321 1367
 						}
1322 1368
 
1323
-						if (!empty($addClosingTags))
1324
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1369
+						if (!empty($addClosingTags)) {
1370
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1371
+						}
1325 1372
 
1326 1373
 						// Apparently the closing tag was not found on the stack.
1327 1374
 						if (!is_string($element) || $element !== $tag)
@@ -1331,8 +1378,7 @@  discard block
 block discarded – undo
1331 1378
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1332 1379
 							continue;
1333 1380
 						}
1334
-					}
1335
-					else
1381
+					} else
1336 1382
 					{
1337 1383
 						// Get rid of this closing tag!
1338 1384
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1361,53 +1407,62 @@  discard block
 block discarded – undo
1361 1407
 							unset($inlineElements[$tagContentToBeClosed]);
1362 1408
 
1363 1409
 							// Was this the tag we were looking for?
1364
-							if ($tagToBeClosed === $tag)
1365
-								break;
1410
+							if ($tagToBeClosed === $tag) {
1411
+															break;
1412
+							}
1366 1413
 
1367 1414
 							// Nope, close it and look further!
1368
-							else
1369
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1415
+							else {
1416
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1417
+							}
1370 1418
 						}
1371 1419
 
1372 1420
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1373 1421
 						{
1374 1422
 							array_pop($competingElements[$tag]);
1375 1423
 
1376
-							if (count($competingElements[$tag]) > 0)
1377
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1424
+							if (count($competingElements[$tag]) > 0) {
1425
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1426
+							}
1378 1427
 						}
1379 1428
 					}
1380 1429
 
1381 1430
 					// Unexpected closing tag, ex-ter-mi-nate.
1382
-					else
1383
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1431
+					else {
1432
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1433
+					}
1384 1434
 				}
1385 1435
 			}
1386 1436
 		}
1387 1437
 
1388 1438
 		// Close the code tags.
1389
-		if ($inCode)
1390
-			$parts[$i] .= '[/code]';
1439
+		if ($inCode) {
1440
+					$parts[$i] .= '[/code]';
1441
+		}
1391 1442
 
1392 1443
 		// The same for nobbc tags.
1393
-		elseif ($inNoBbc)
1394
-			$parts[$i] .= '[/nobbc]';
1444
+		elseif ($inNoBbc) {
1445
+					$parts[$i] .= '[/nobbc]';
1446
+		}
1395 1447
 
1396 1448
 		// Still inline tags left unclosed? Close them now, better late than never.
1397
-		elseif (!empty($inlineElements))
1398
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1449
+		elseif (!empty($inlineElements)) {
1450
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1451
+		}
1399 1452
 
1400 1453
 		// Now close the block elements.
1401
-		if (!empty($blockElements))
1402
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1454
+		if (!empty($blockElements)) {
1455
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1456
+		}
1403 1457
 
1404 1458
 		$text = implode('', $parts);
1405 1459
 	}
1406 1460
 
1407 1461
 	// Final clean up of back to back tags.
1408 1462
 	$lastlen = 0;
1409
-	while (strlen($text) !== $lastlen)
1410
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1463
+	while (strlen($text) !== $lastlen) {
1464
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1465
+	}
1411 1466
 
1412 1467
 	return $text;
1413 1468
 }
@@ -1436,22 +1491,25 @@  discard block
 block discarded – undo
1436 1491
 	$context['template_layers'] = array();
1437 1492
 	// Lets make sure we aren't going to output anything nasty.
1438 1493
 	@ob_end_clean();
1439
-	if (!empty($modSettings['enableCompressedOutput']))
1440
-		@ob_start('ob_gzhandler');
1441
-	else
1442
-		@ob_start();
1494
+	if (!empty($modSettings['enableCompressedOutput'])) {
1495
+			@ob_start('ob_gzhandler');
1496
+	} else {
1497
+			@ob_start();
1498
+	}
1443 1499
 
1444 1500
 	// If we don't have any locale better avoid broken js
1445
-	if (empty($txt['lang_locale']))
1446
-		die();
1501
+	if (empty($txt['lang_locale'])) {
1502
+			die();
1503
+	}
1447 1504
 
1448 1505
 	$file_data = '(function ($) {
1449 1506
 	\'use strict\';
1450 1507
 
1451 1508
 	$.sceditor.locale[' . javaScriptEscape($txt['lang_locale']) . '] = {';
1452
-	foreach ($editortxt as $key => $val)
1453
-		$file_data .= '
1509
+	foreach ($editortxt as $key => $val) {
1510
+			$file_data .= '
1454 1511
 		' . javaScriptEscape($key) . ': ' . javaScriptEscape($val) . ',';
1512
+	}
1455 1513
 
1456 1514
 	$file_data .= '
1457 1515
 		dateFormat: "day.month.year"
@@ -1519,8 +1577,9 @@  discard block
 block discarded – undo
1519 1577
 				)
1520 1578
 			);
1521 1579
 			$icon_data = array();
1522
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1523
-				$icon_data[] = $row;
1580
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1581
+							$icon_data[] = $row;
1582
+			}
1524 1583
 			$smcFunc['db_free_result']($request);
1525 1584
 
1526 1585
 			$icons = array();
@@ -1535,9 +1594,9 @@  discard block
 block discarded – undo
1535 1594
 			}
1536 1595
 
1537 1596
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1597
+		} else {
1598
+					$icons = $temp;
1538 1599
 		}
1539
-		else
1540
-			$icons = $temp;
1541 1600
 	}
1542 1601
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1543 1602
 
@@ -1578,8 +1637,9 @@  discard block
 block discarded – undo
1578 1637
 	{
1579 1638
 		// Some general stuff.
1580 1639
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1581
-		if (!empty($context['drafts_autosave']))
1582
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1640
+		if (!empty($context['drafts_autosave'])) {
1641
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1642
+		}
1583 1643
 
1584 1644
 		// This really has some WYSIWYG stuff.
1585 1645
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1595,8 +1655,9 @@  discard block
 block discarded – undo
1595 1655
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1596 1656
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1597 1657
 		// editor language file
1598
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1599
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1658
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1659
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1660
+		}
1600 1661
 
1601 1662
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))];
1602 1663
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
@@ -1605,11 +1666,12 @@  discard block
 block discarded – undo
1605 1666
 			loadJavaScriptFile('spellcheck.js', array(), 'smf_spellcheck');
1606 1667
 
1607 1668
 			// Some hidden information is needed in order to make the spell checking work.
1608
-			if (!isset($_REQUEST['xml']))
1609
-				$context['insert_after_template'] .= '
1669
+			if (!isset($_REQUEST['xml'])) {
1670
+							$context['insert_after_template'] .= '
1610 1671
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1611 1672
 			<input type="hidden" name="spellstring" value="">
1612 1673
 		</form>';
1674
+			}
1613 1675
 		}
1614 1676
 	}
1615 1677
 
@@ -1775,10 +1837,12 @@  discard block
 block discarded – undo
1775 1837
 
1776 1838
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1777 1839
 		$disabled_tags = array();
1778
-		if (!empty($modSettings['disabledBBC']))
1779
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1780
-		if (empty($modSettings['enableEmbeddedFlash']))
1781
-			$disabled_tags[] = 'flash';
1840
+		if (!empty($modSettings['disabledBBC'])) {
1841
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1842
+		}
1843
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1844
+					$disabled_tags[] = 'flash';
1845
+		}
1782 1846
 
1783 1847
 		foreach ($disabled_tags as $tag)
1784 1848
 		{
@@ -1788,9 +1852,10 @@  discard block
 block discarded – undo
1788 1852
 				$context['disabled_tags']['orderedlist'] = true;
1789 1853
 			}
1790 1854
 
1791
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1792
-				if ($tag === $thisTag)
1855
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1856
+							if ($tag === $thisTag)
1793 1857
 					$context['disabled_tags'][$tagNameBBC] = true;
1858
+			}
1794 1859
 
1795 1860
 			$context['disabled_tags'][trim($tag)] = true;
1796 1861
 		}
@@ -1800,19 +1865,21 @@  discard block
 block discarded – undo
1800 1865
 		$context['bbc_toolbar'] = array();
1801 1866
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1802 1867
 		{
1803
-			if (!isset($context['bbc_toolbar'][$row]))
1804
-				$context['bbc_toolbar'][$row] = array();
1868
+			if (!isset($context['bbc_toolbar'][$row])) {
1869
+							$context['bbc_toolbar'][$row] = array();
1870
+			}
1805 1871
 			$tagsRow = array();
1806 1872
 			foreach ($tagRow as $tag)
1807 1873
 			{
1808 1874
 				if ((!empty($tag['code'])) && empty($context['disabled_tags'][$tag['code']]))
1809 1875
 				{
1810 1876
 					$tagsRow[] = $tag['code'];
1811
-					if (isset($tag['image']))
1812
-						$bbcodes_styles .= '
1877
+					if (isset($tag['image'])) {
1878
+											$bbcodes_styles .= '
1813 1879
 			.sceditor-button-' . $tag['code'] . ' div {
1814 1880
 				background: url(\'' . $settings['default_theme_url'] . '/images/bbc/' . $tag['image'] . '.png\');
1815 1881
 			}';
1882
+					}
1816 1883
 					if (isset($tag['before']))
1817 1884
 					{
1818 1885
 						$context['bbcodes_handlers'] .= '
@@ -1826,8 +1893,7 @@  discard block
 block discarded – undo
1826 1893
 				});';
1827 1894
 					}
1828 1895
 
1829
-				}
1830
-				else
1896
+				} else
1831 1897
 				{
1832 1898
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1833 1899
 					$tagsRow = array();
@@ -1838,14 +1904,16 @@  discard block
 block discarded – undo
1838 1904
 			{
1839 1905
 				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1840 1906
 				$tagsRow = array();
1841
-				if (!isset($context['disabled_tags']['font']))
1842
-					$tagsRow[] = 'font';
1843
-				if (!isset($context['disabled_tags']['size']))
1844
-					$tagsRow[] = 'size';
1845
-				if (!isset($context['disabled_tags']['color']))
1846
-					$tagsRow[] = 'color';
1847
-			}
1848
-			elseif ($row == 1 && empty($modSettings['disable_wysiwyg']))
1907
+				if (!isset($context['disabled_tags']['font'])) {
1908
+									$tagsRow[] = 'font';
1909
+				}
1910
+				if (!isset($context['disabled_tags']['size'])) {
1911
+									$tagsRow[] = 'size';
1912
+				}
1913
+				if (!isset($context['disabled_tags']['color'])) {
1914
+									$tagsRow[] = 'color';
1915
+				}
1916
+			} elseif ($row == 1 && empty($modSettings['disable_wysiwyg']))
1849 1917
 			{
1850 1918
 				$tmp = array();
1851 1919
 				$tagsRow[] = 'removeformat';
@@ -1856,13 +1924,15 @@  discard block
 block discarded – undo
1856 1924
 				}
1857 1925
 			}
1858 1926
 
1859
-			if (!empty($tagsRow))
1860
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1927
+			if (!empty($tagsRow)) {
1928
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1929
+			}
1861 1930
 		}
1862
-		if (!empty($bbcodes_styles))
1863
-			$context['html_headers'] .= '
1931
+		if (!empty($bbcodes_styles)) {
1932
+					$context['html_headers'] .= '
1864 1933
 		<style>' . $bbcodes_styles . '
1865 1934
 		</style>';
1935
+		}
1866 1936
 	}
1867 1937
 
1868 1938
 	// Initialize smiley array... if not loaded before.
@@ -1874,8 +1944,8 @@  discard block
 block discarded – undo
1874 1944
 		);
1875 1945
 
1876 1946
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1877
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1878
-			$context['smileys']['postform'][] = array(
1947
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1948
+					$context['smileys']['postform'][] = array(
1879 1949
 				'smileys' => array(
1880 1950
 					array(
1881 1951
 						'code' => ':)',
@@ -1961,7 +2031,7 @@  discard block
 block discarded – undo
1961 2031
 				),
1962 2032
 				'isLast' => true,
1963 2033
 			);
1964
-		elseif ($user_info['smiley_set'] != 'none')
2034
+		} elseif ($user_info['smiley_set'] != 'none')
1965 2035
 		{
1966 2036
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1967 2037
 			{
@@ -1984,17 +2054,19 @@  discard block
 block discarded – undo
1984 2054
 
1985 2055
 				foreach ($context['smileys'] as $section => $smileyRows)
1986 2056
 				{
1987
-					foreach ($smileyRows as $rowIndex => $smileys)
1988
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2057
+					foreach ($smileyRows as $rowIndex => $smileys) {
2058
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2059
+					}
1989 2060
 
1990
-					if (!empty($smileyRows))
1991
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2061
+					if (!empty($smileyRows)) {
2062
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2063
+					}
1992 2064
 				}
1993 2065
 
1994 2066
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2067
+			} else {
2068
+							$context['smileys'] = $temp;
1995 2069
 			}
1996
-			else
1997
-				$context['smileys'] = $temp;
1998 2070
 		}
1999 2071
 	}
2000 2072
 
@@ -2020,8 +2092,9 @@  discard block
 block discarded – undo
2020 2092
 		loadTemplate('GenericControls');
2021 2093
 
2022 2094
 		// Some javascript ma'am?
2023
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2024
-			loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2095
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2096
+					loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2097
+		}
2025 2098
 
2026 2099
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2027 2100
 
@@ -2034,8 +2107,8 @@  discard block
 block discarded – undo
2034 2107
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2035 2108
 
2036 2109
 	// Log this into our collection.
2037
-	if ($isNew)
2038
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2110
+	if ($isNew) {
2111
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2039 2112
 			'id' => $verificationOptions['id'],
2040 2113
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2041 2114
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2046,13 +2119,15 @@  discard block
 block discarded – undo
2046 2119
 			'questions' => array(),
2047 2120
 			'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']),
2048 2121
 		);
2122
+	}
2049 2123
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2050 2124
 
2051 2125
 	// Is there actually going to be anything?
2052
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha']))
2053
-		return false;
2054
-	elseif (!$isNew && !$do_test)
2055
-		return true;
2126
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) {
2127
+			return false;
2128
+	} elseif (!$isNew && !$do_test) {
2129
+			return true;
2130
+	}
2056 2131
 
2057 2132
 	// Sanitize reCAPTCHA fields?
2058 2133
 	if ($thisVerification['can_recaptcha'])
@@ -2065,11 +2140,12 @@  discard block
 block discarded – undo
2065 2140
 	}
2066 2141
 
2067 2142
 	// Add javascript for the object.
2068
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2069
-		$context['insert_after_template'] .= '
2143
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2144
+			$context['insert_after_template'] .= '
2070 2145
 			<script>
2071 2146
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2072 2147
 			</script>';
2148
+	}
2073 2149
 
2074 2150
 	// If we want questions do we have a cache of all the IDs?
2075 2151
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2092,8 +2168,9 @@  discard block
 block discarded – undo
2092 2168
 				unset ($row['id_question']);
2093 2169
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2094 2170
 				$row['answers'] = $smcFunc['json_decode']($row['answers'], true);
2095
-				foreach ($row['answers'] as $k => $v)
2096
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2171
+				foreach ($row['answers'] as $k => $v) {
2172
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2173
+				}
2097 2174
 
2098 2175
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2099 2176
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2104,35 +2181,42 @@  discard block
 block discarded – undo
2104 2181
 		}
2105 2182
 	}
2106 2183
 
2107
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2108
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2184
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2185
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2186
+	}
2109 2187
 
2110 2188
 	// Do we need to refresh the verification?
2111
-	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']))
2112
-		$force_refresh = true;
2113
-	else
2114
-		$force_refresh = false;
2189
+	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'])) {
2190
+			$force_refresh = true;
2191
+	} else {
2192
+			$force_refresh = false;
2193
+	}
2115 2194
 
2116 2195
 	// This can also force a fresh, although unlikely.
2117
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2118
-		$force_refresh = true;
2196
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2197
+			$force_refresh = true;
2198
+	}
2119 2199
 
2120 2200
 	$verification_errors = array();
2121 2201
 	// Start with any testing.
2122 2202
 	if ($do_test)
2123 2203
 	{
2124 2204
 		// This cannot happen!
2125
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2126
-			fatal_lang_error('no_access', false);
2205
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2206
+					fatal_lang_error('no_access', false);
2207
+		}
2127 2208
 		// ... nor this!
2128
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2129
-			fatal_lang_error('no_access', false);
2209
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2210
+					fatal_lang_error('no_access', false);
2211
+		}
2130 2212
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2131
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2132
-			fatal_lang_error('no_access', false);
2213
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2214
+					fatal_lang_error('no_access', false);
2215
+		}
2133 2216
 		// While we're here, did the user do something bad?
2134
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2135
-			$verification_errors[] = 'wrong_verification_answer';
2217
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2218
+					$verification_errors[] = 'wrong_verification_answer';
2219
+		}
2136 2220
 
2137 2221
 		if ($thisVerification['can_recaptcha'])
2138 2222
 		{
@@ -2143,22 +2227,25 @@  discard block
 block discarded – undo
2143 2227
 			{
2144 2228
 				$resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']);
2145 2229
 
2146
-				if (!$resp->isSuccess())
2147
-					$verification_errors[] = 'wrong_verification_code';
2230
+				if (!$resp->isSuccess()) {
2231
+									$verification_errors[] = 'wrong_verification_code';
2232
+				}
2233
+			} else {
2234
+							$verification_errors[] = 'wrong_verification_code';
2148 2235
 			}
2149
-			else
2150
-				$verification_errors[] = 'wrong_verification_code';
2151 2236
 		}
2152
-		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']))
2153
-			$verification_errors[] = 'wrong_verification_code';
2237
+		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'])) {
2238
+					$verification_errors[] = 'wrong_verification_code';
2239
+		}
2154 2240
 		if ($thisVerification['number_questions'])
2155 2241
 		{
2156 2242
 			$incorrectQuestions = array();
2157 2243
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2158 2244
 			{
2159 2245
 				// We don't have this question any more, thus no answers.
2160
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2161
-					continue;
2246
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2247
+									continue;
2248
+				}
2162 2249
 				// This is quite complex. We have our question but it might have multiple answers.
2163 2250
 				// First, did they actually answer this question?
2164 2251
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2170,24 +2257,28 @@  discard block
 block discarded – undo
2170 2257
 				else
2171 2258
 				{
2172 2259
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2173
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2174
-						$incorrectQuestions[] = $q;
2260
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2261
+											$incorrectQuestions[] = $q;
2262
+					}
2175 2263
 				}
2176 2264
 			}
2177 2265
 
2178
-			if (!empty($incorrectQuestions))
2179
-				$verification_errors[] = 'wrong_verification_answer';
2266
+			if (!empty($incorrectQuestions)) {
2267
+							$verification_errors[] = 'wrong_verification_answer';
2268
+			}
2180 2269
 		}
2181 2270
 	}
2182 2271
 
2183 2272
 	// Any errors means we refresh potentially.
2184 2273
 	if (!empty($verification_errors))
2185 2274
 	{
2186
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2187
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2275
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2276
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2277
+		}
2188 2278
 		// Too many errors?
2189
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2190
-			$force_refresh = true;
2279
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2280
+					$force_refresh = true;
2281
+		}
2191 2282
 
2192 2283
 		// Keep a track of these.
2193 2284
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2220,8 +2311,9 @@  discard block
 block discarded – undo
2220 2311
 			// Are we overriding the range?
2221 2312
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2222 2313
 
2223
-			for ($i = 0; $i < 6; $i++)
2224
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2314
+			for ($i = 0; $i < 6; $i++) {
2315
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2316
+			}
2225 2317
 		}
2226 2318
 
2227 2319
 		// Getting some new questions?
@@ -2229,8 +2321,9 @@  discard block
 block discarded – undo
2229 2321
 		{
2230 2322
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2231 2323
 			$possible_langs = array();
2232
-			if (isset($_SESSION['language']))
2233
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2324
+			if (isset($_SESSION['language'])) {
2325
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2326
+			}
2234 2327
 			if (!empty($user_info['language']));
2235 2328
 			$possible_langs[] = $user_info['language'];
2236 2329
 			$possible_langs[] = $language;
@@ -2249,8 +2342,7 @@  discard block
 block discarded – undo
2249 2342
 				}
2250 2343
 			}
2251 2344
 		}
2252
-	}
2253
-	else
2345
+	} else
2254 2346
 	{
2255 2347
 		// Same questions as before.
2256 2348
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2260,8 +2352,9 @@  discard block
 block discarded – undo
2260 2352
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2261 2353
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2262 2354
 	{
2263
-		if (!isset($context['html_headers']))
2264
-			$context['html_headers'] = '';
2355
+		if (!isset($context['html_headers'])) {
2356
+					$context['html_headers'] = '';
2357
+		}
2265 2358
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2266 2359
 	}
2267 2360
 
@@ -2287,11 +2380,13 @@  discard block
 block discarded – undo
2287 2380
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2288 2381
 
2289 2382
 	// Return errors if we have them.
2290
-	if (!empty($verification_errors))
2291
-		return $verification_errors;
2383
+	if (!empty($verification_errors)) {
2384
+			return $verification_errors;
2385
+	}
2292 2386
 	// If we had a test that one, make a note.
2293
-	elseif ($do_test)
2294
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2387
+	elseif ($do_test) {
2388
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2389
+	}
2295 2390
 
2296 2391
 	// Say that everything went well chaps.
2297 2392
 	return true;
@@ -2316,8 +2411,9 @@  discard block
 block discarded – undo
2316 2411
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2317 2412
 
2318 2413
 	// If we're just checking the callback function is registered return true or false.
2319
-	if ($checkRegistered != null)
2320
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2414
+	if ($checkRegistered != null) {
2415
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2416
+	}
2321 2417
 
2322 2418
 	checkSession('get');
2323 2419
 	loadTemplate('Xml');
@@ -2468,24 +2564,27 @@  discard block
 block discarded – undo
2468 2564
 		foreach ($possible_versions as $ver)
2469 2565
 		{
2470 2566
 			$ver = trim($ver);
2471
-			if (strpos($ver, 'SMF') === 0)
2472
-				$versions[] = $ver;
2567
+			if (strpos($ver, 'SMF') === 0) {
2568
+							$versions[] = $ver;
2569
+			}
2473 2570
 		}
2474 2571
 	}
2475 2572
 	$smcFunc['db_free_result']($request);
2476 2573
 
2477 2574
 	// Just in case we don't have ANYthing.
2478
-	if (empty($versions))
2479
-		$versions = array('SMF 2.0');
2575
+	if (empty($versions)) {
2576
+			$versions = array('SMF 2.0');
2577
+	}
2480 2578
 
2481
-	foreach ($versions as $id => $version)
2482
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2579
+	foreach ($versions as $id => $version) {
2580
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2483 2581
 			$xml_data['items']['children'][] = array(
2484 2582
 				'attributes' => array(
2485 2583
 					'id' => $id,
2486 2584
 				),
2487 2585
 				'value' => $version,
2488 2586
 			);
2587
+	}
2489 2588
 
2490 2589
 	return $xml_data;
2491 2590
 }
Please login to merge, or discard this patch.
Sources/Who.php 1 patch
Braces   +126 added lines, -95 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
  * Who's online, and what are they doing?
@@ -35,8 +36,9 @@  discard block
 block discarded – undo
35 36
 	isAllowedTo('who_view');
36 37
 
37 38
 	// You can't do anything if this is off.
38
-	if (empty($modSettings['who_enabled']))
39
-		fatal_lang_error('who_off', false);
39
+	if (empty($modSettings['who_enabled'])) {
40
+			fatal_lang_error('who_off', false);
41
+	}
40 42
 
41 43
 	// Load the 'Who' template.
42 44
 	loadTemplate('Who');
@@ -71,9 +73,9 @@  discard block
 block discarded – undo
71 73
 		$show_methods['spiders'] = '(lo.id_member = 0 AND lo.id_spider > 0)';
72 74
 		$show_methods['guests'] = '(lo.id_member = 0 AND lo.id_spider = 0)';
73 75
 		$context['show_methods']['spiders'] = $txt['who_show_spiders_only'];
76
+	} elseif (empty($modSettings['show_spider_online']) && isset($_SESSION['who_online_filter']) && $_SESSION['who_online_filter'] == 'spiders') {
77
+			unset($_SESSION['who_online_filter']);
74 78
 	}
75
-	elseif (empty($modSettings['show_spider_online']) && isset($_SESSION['who_online_filter']) && $_SESSION['who_online_filter'] == 'spiders')
76
-		unset($_SESSION['who_online_filter']);
77 79
 
78 80
 	// Does the user prefer a different sort direction?
79 81
 	if (isset($_REQUEST['sort']) && isset($sort_methods[$_REQUEST['sort']]))
@@ -97,20 +99,24 @@  discard block
 block discarded – undo
97 99
 	$context['sort_direction'] = isset($_REQUEST['asc']) || (isset($_REQUEST['sort_dir']) && $_REQUEST['sort_dir'] == 'asc') ? 'up' : 'down';
98 100
 
99 101
 	$conditions = array();
100
-	if (!allowedTo('moderate_forum'))
101
-		$conditions[] = '(COALESCE(mem.show_online, 1) = 1)';
102
+	if (!allowedTo('moderate_forum')) {
103
+			$conditions[] = '(COALESCE(mem.show_online, 1) = 1)';
104
+	}
102 105
 
103 106
 	// Fallback to top filter?
104
-	if (isset($_REQUEST['submit_top']) && isset($_REQUEST['show_top']))
105
-		$_REQUEST['show'] = $_REQUEST['show_top'];
107
+	if (isset($_REQUEST['submit_top']) && isset($_REQUEST['show_top'])) {
108
+			$_REQUEST['show'] = $_REQUEST['show_top'];
109
+	}
106 110
 	// Does the user wish to apply a filter?
107
-	if (isset($_REQUEST['show']) && isset($show_methods[$_REQUEST['show']]))
108
-		$context['show_by'] = $_SESSION['who_online_filter'] = $_REQUEST['show'];
111
+	if (isset($_REQUEST['show']) && isset($show_methods[$_REQUEST['show']])) {
112
+			$context['show_by'] = $_SESSION['who_online_filter'] = $_REQUEST['show'];
113
+	}
109 114
 	// Perhaps we saved a filter earlier in the session?
110
-	elseif (isset($_SESSION['who_online_filter']))
111
-		$context['show_by'] = $_SESSION['who_online_filter'];
112
-	else
113
-		$context['show_by'] = 'members';
115
+	elseif (isset($_SESSION['who_online_filter'])) {
116
+			$context['show_by'] = $_SESSION['who_online_filter'];
117
+	} else {
118
+			$context['show_by'] = 'members';
119
+	}
114 120
 
115 121
 	$conditions[] = $show_methods[$context['show_by']];
116 122
 
@@ -156,8 +162,9 @@  discard block
 block discarded – undo
156 162
 	while ($row = $smcFunc['db_fetch_assoc']($request))
157 163
 	{
158 164
 		$actions = $smcFunc['json_decode']($row['url'], true);
159
-		if ($actions === false)
160
-			continue;
165
+		if ($actions === false) {
166
+					continue;
167
+		}
161 168
 
162 169
 		// Send the information to the template.
163 170
 		$context['members'][$row['session']] = array(
@@ -195,8 +202,8 @@  discard block
 block discarded – undo
195 202
 	$spiderContext = array();
196 203
 	if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] == 2 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache']))
197 204
 	{
198
-		foreach ($smcFunc['json_decode']($modSettings['spider_name_cache'], true) as $id => $name)
199
-			$spiderContext[$id] = array(
205
+		foreach ($smcFunc['json_decode']($modSettings['spider_name_cache'], true) as $id => $name) {
206
+					$spiderContext[$id] = array(
200 207
 				'id' => 0,
201 208
 				'name' => $name,
202 209
 				'group' => $txt['spiders'],
@@ -205,6 +212,7 @@  discard block
 block discarded – undo
205 212
 				'email' => $name,
206 213
 				'is_guest' => true
207 214
 			);
215
+		}
208 216
 	}
209 217
 
210 218
 	$url_data = determineActions($url_data);
@@ -219,16 +227,18 @@  discard block
 block discarded – undo
219 227
 	// Put it in the context variables.
220 228
 	foreach ($context['members'] as $i => $member)
221 229
 	{
222
-		if ($member['id'] != 0)
223
-			$member['id'] = loadMemberContext($member['id']) ? $member['id'] : 0;
230
+		if ($member['id'] != 0) {
231
+					$member['id'] = loadMemberContext($member['id']) ? $member['id'] : 0;
232
+		}
224 233
 
225 234
 		// Keep the IP that came from the database.
226 235
 		$memberContext[$member['id']]['ip'] = $member['ip'];
227 236
 		$context['members'][$i]['action'] = isset($url_data[$i]) ? $url_data[$i] : $txt['who_hidden'];
228
-		if ($member['id'] == 0 && isset($spiderContext[$member['id_spider']]))
229
-			$context['members'][$i] += $spiderContext[$member['id_spider']];
230
-		else
231
-			$context['members'][$i] += $memberContext[$member['id']];
237
+		if ($member['id'] == 0 && isset($spiderContext[$member['id_spider']])) {
238
+					$context['members'][$i] += $spiderContext[$member['id_spider']];
239
+		} else {
240
+					$context['members'][$i] += $memberContext[$member['id']];
241
+		}
232 242
 	}
233 243
 
234 244
 	// Some people can't send personal messages...
@@ -263,8 +273,9 @@  discard block
 block discarded – undo
263 273
 {
264 274
 	global $txt, $user_info, $modSettings, $smcFunc;
265 275
 
266
-	if (!allowedTo('who_view'))
267
-		return array();
276
+	if (!allowedTo('who_view')) {
277
+			return array();
278
+	}
268 279
 	loadLanguage('Who');
269 280
 
270 281
 	// Actions that require a specific permission level.
@@ -292,10 +303,11 @@  discard block
 block discarded – undo
292 303
 	);
293 304
 	call_integration_hook('who_allowed', array(&$allowedActions));
294 305
 
295
-	if (!is_array($urls))
296
-		$url_list = array(array($urls, $user_info['id']));
297
-	else
298
-		$url_list = $urls;
306
+	if (!is_array($urls)) {
307
+			$url_list = array(array($urls, $user_info['id']));
308
+	} else {
309
+			$url_list = $urls;
310
+	}
299 311
 
300 312
 	// These are done to later query these in large chunks. (instead of one by one.)
301 313
 	$topic_ids = array();
@@ -307,12 +319,14 @@  discard block
 block discarded – undo
307 319
 	{
308 320
 		// Get the request parameters..
309 321
 		$actions = $smcFunc['json_decode']($url[0], true);
310
-		if ($actions === false)
311
-			continue;
322
+		if ($actions === false) {
323
+					continue;
324
+		}
312 325
 
313 326
 		// If it's the admin or moderation center, and there is an area set, use that instead.
314
-		if (isset($actions['action']) && ($actions['action'] == 'admin' || $actions['action'] == 'moderate') && isset($actions['area']))
315
-			$actions['action'] = $actions['area'];
327
+		if (isset($actions['action']) && ($actions['action'] == 'admin' || $actions['action'] == 'moderate') && isset($actions['area'])) {
328
+					$actions['action'] = $actions['area'];
329
+		}
316 330
 
317 331
 		// Check if there was no action or the action is display.
318 332
 		if (!isset($actions['action']) || $actions['action'] == 'display')
@@ -332,12 +346,14 @@  discard block
 block discarded – undo
332 346
 				$board_ids[$actions['board']][$k] = $txt['who_board'];
333 347
 			}
334 348
 			// It's the board index!!  It must be!
335
-			else
336
-				$data[$k] = $txt['who_index'];
349
+			else {
350
+							$data[$k] = $txt['who_index'];
351
+			}
337 352
 		}
338 353
 		// Probably an error or some goon?
339
-		elseif ($actions['action'] == '')
340
-			$data[$k] = $txt['who_index'];
354
+		elseif ($actions['action'] == '') {
355
+					$data[$k] = $txt['who_index'];
356
+		}
341 357
 		// Some other normal action...?
342 358
 		else
343 359
 		{
@@ -345,23 +361,25 @@  discard block
 block discarded – undo
345 361
 			if ($actions['action'] == 'profile')
346 362
 			{
347 363
 				// Whose?  Their own?
348
-				if (empty($actions['u']))
349
-					$actions['u'] = $url[1];
364
+				if (empty($actions['u'])) {
365
+									$actions['u'] = $url[1];
366
+				}
350 367
 
351 368
 				$data[$k] = $txt['who_hidden'];
352 369
 				$profile_ids[(int) $actions['u']][$k] = $actions['u'] == $url[1] ? $txt['who_viewownprofile'] : $txt['who_viewprofile'];
353
-			}
354
-			elseif (($actions['action'] == 'post' || $actions['action'] == 'post2') && empty($actions['topic']) && isset($actions['board']))
370
+			} elseif (($actions['action'] == 'post' || $actions['action'] == 'post2') && empty($actions['topic']) && isset($actions['board']))
355 371
 			{
356 372
 				$data[$k] = $txt['who_hidden'];
357 373
 				$board_ids[(int) $actions['board']][$k] = isset($actions['poll']) ? $txt['who_poll'] : $txt['who_post'];
358 374
 			}
359 375
 			// A subaction anyone can view... if the language string is there, show it.
360
-			elseif (isset($actions['sa']) && isset($txt['whoall_' . $actions['action'] . '_' . $actions['sa']]))
361
-				$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']]) ? $txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']] : $txt['whoall_' . $actions['action'] . '_' . $actions['sa']];
376
+			elseif (isset($actions['sa']) && isset($txt['whoall_' . $actions['action'] . '_' . $actions['sa']])) {
377
+							$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']]) ? $txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']] : $txt['whoall_' . $actions['action'] . '_' . $actions['sa']];
378
+			}
362 379
 			// An action any old fellow can look at. (if ['whoall_' . $action] exists, we know everyone can see it.)
363
-			elseif (isset($txt['whoall_' . $actions['action']]))
364
-				$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action']]) ? $txt[$preferred_prefix . $actions['action']] : $txt['whoall_' . $actions['action']];
380
+			elseif (isset($txt['whoall_' . $actions['action']])) {
381
+							$data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action']]) ? $txt[$preferred_prefix . $actions['action']] : $txt['whoall_' . $actions['action']];
382
+			}
365 383
 			// Viewable if and only if they can see the board...
366 384
 			elseif (isset($txt['whotopic_' . $actions['action']]))
367 385
 			{
@@ -370,8 +388,7 @@  discard block
 block discarded – undo
370 388
 
371 389
 				$data[$k] = $txt['who_hidden'];
372 390
 				$topic_ids[$topic][$k] = $txt['whotopic_' . $actions['action']];
373
-			}
374
-			elseif (isset($txt['whopost_' . $actions['action']]))
391
+			} elseif (isset($txt['whopost_' . $actions['action']]))
375 392
 			{
376 393
 				// Find out what message they are accessing.
377 394
 				$msgid = (int) (isset($actions['msg']) ? $actions['msg'] : (isset($actions['quote']) ? $actions['quote'] : 0));
@@ -394,41 +411,46 @@  discard block
 block discarded – undo
394 411
 				$data[$k] = sprintf($txt['whopost_' . $actions['action']], $id_topic, $subject);
395 412
 				$smcFunc['db_free_result']($result);
396 413
 
397
-				if (empty($id_topic))
398
-					$data[$k] = $txt['who_hidden'];
414
+				if (empty($id_topic)) {
415
+									$data[$k] = $txt['who_hidden'];
416
+				}
399 417
 			}
400 418
 			// Viewable only by administrators.. (if it starts with whoadmin, it's admin only!)
401
-			elseif (allowedTo('moderate_forum') && isset($txt['whoadmin_' . $actions['action']]))
402
-				$data[$k] = $txt['whoadmin_' . $actions['action']];
419
+			elseif (allowedTo('moderate_forum') && isset($txt['whoadmin_' . $actions['action']])) {
420
+							$data[$k] = $txt['whoadmin_' . $actions['action']];
421
+			}
403 422
 			// Viewable by permission level.
404 423
 			elseif (isset($allowedActions[$actions['action']]))
405 424
 			{
406
-				if (allowedTo($allowedActions[$actions['action']]))
407
-					$data[$k] = $txt['whoallow_' . $actions['action']];
408
-				elseif (in_array('moderate_forum', $allowedActions[$actions['action']]))
409
-					$data[$k] = $txt['who_moderate'];
410
-				elseif (in_array('admin_forum', $allowedActions[$actions['action']]))
411
-					$data[$k] = $txt['who_admin'];
412
-				else
413
-					$data[$k] = $txt['who_hidden'];
425
+				if (allowedTo($allowedActions[$actions['action']])) {
426
+									$data[$k] = $txt['whoallow_' . $actions['action']];
427
+				} elseif (in_array('moderate_forum', $allowedActions[$actions['action']])) {
428
+									$data[$k] = $txt['who_moderate'];
429
+				} elseif (in_array('admin_forum', $allowedActions[$actions['action']])) {
430
+									$data[$k] = $txt['who_admin'];
431
+				} else {
432
+									$data[$k] = $txt['who_hidden'];
433
+				}
434
+			} elseif (!empty($actions['action'])) {
435
+							$data[$k] = $txt['who_generic'] . ' ' . $actions['action'];
436
+			} else {
437
+							$data[$k] = $txt['who_unknown'];
414 438
 			}
415
-			elseif (!empty($actions['action']))
416
-				$data[$k] = $txt['who_generic'] . ' ' . $actions['action'];
417
-			else
418
-				$data[$k] = $txt['who_unknown'];
419 439
 		}
420 440
 
421 441
 		if (isset($actions['error']))
422 442
 		{
423
-			if (isset($txt[$actions['error']]))
424
-				$error_message = str_replace('"', '&quot;', empty($actions['who_error_params']) ? $txt[$actions['error']] : vsprintf($txt[$actions['error']], $actions['who_error_params']));
425
-			elseif ($actions['error'] == 'guest_login')
426
-				$error_message = str_replace('"', '&quot;', $txt['who_guest_login']);
427
-			else
428
-				$error_message = str_replace('"', '&quot;', $actions['error']);
429
-
430
-			if (!empty($error_message))
431
-				$data[$k] .= ' <span class="generic_icons error" title="' . $error_message . '"></span>';
443
+			if (isset($txt[$actions['error']])) {
444
+							$error_message = str_replace('"', '&quot;', empty($actions['who_error_params']) ? $txt[$actions['error']] : vsprintf($txt[$actions['error']], $actions['who_error_params']));
445
+			} elseif ($actions['error'] == 'guest_login') {
446
+							$error_message = str_replace('"', '&quot;', $txt['who_guest_login']);
447
+			} else {
448
+							$error_message = str_replace('"', '&quot;', $actions['error']);
449
+			}
450
+
451
+			if (!empty($error_message)) {
452
+							$data[$k] .= ' <span class="generic_icons error" title="' . $error_message . '"></span>';
453
+			}
432 454
 		}
433 455
 
434 456
 		// Maybe the action is integrated into another system?
@@ -439,12 +461,15 @@  discard block
 block discarded – undo
439 461
 				if (!empty($integrate_action))
440 462
 				{
441 463
 					$data[$k] = $integrate_action;
442
-					if (isset($actions['topic']) && isset($topic_ids[(int) $actions['topic']][$k]))
443
-						$topic_ids[(int) $actions['topic']][$k] = $integrate_action;
444
-					if (isset($actions['board']) && isset($board_ids[(int) $actions['board']][$k]))
445
-						$board_ids[(int) $actions['board']][$k] = $integrate_action;
446
-					if (isset($actions['u']) && isset($profile_ids[(int) $actions['u']][$k]))
447
-						$profile_ids[(int) $actions['u']][$k] = $integrate_action;
464
+					if (isset($actions['topic']) && isset($topic_ids[(int) $actions['topic']][$k])) {
465
+											$topic_ids[(int) $actions['topic']][$k] = $integrate_action;
466
+					}
467
+					if (isset($actions['board']) && isset($board_ids[(int) $actions['board']][$k])) {
468
+											$board_ids[(int) $actions['board']][$k] = $integrate_action;
469
+					}
470
+					if (isset($actions['u']) && isset($profile_ids[(int) $actions['u']][$k])) {
471
+											$profile_ids[(int) $actions['u']][$k] = $integrate_action;
472
+					}
448 473
 					break;
449 474
 				}
450 475
 			}
@@ -472,8 +497,9 @@  discard block
 block discarded – undo
472 497
 		while ($row = $smcFunc['db_fetch_assoc']($result))
473 498
 		{
474 499
 			// Show the topic's subject for each of the actions.
475
-			foreach ($topic_ids[$row['id_topic']] as $k => $session_text)
476
-				$data[$k] = sprintf($session_text, $row['id_topic'], censorText($row['subject']));
500
+			foreach ($topic_ids[$row['id_topic']] as $k => $session_text) {
501
+							$data[$k] = sprintf($session_text, $row['id_topic'], censorText($row['subject']));
502
+			}
477 503
 		}
478 504
 		$smcFunc['db_free_result']($result);
479 505
 	}
@@ -495,8 +521,9 @@  discard block
 block discarded – undo
495 521
 		while ($row = $smcFunc['db_fetch_assoc']($result))
496 522
 		{
497 523
 			// Put the board name into the string for each member...
498
-			foreach ($board_ids[$row['id_board']] as $k => $session_text)
499
-				$data[$k] = sprintf($session_text, $row['id_board'], $row['name']);
524
+			foreach ($board_ids[$row['id_board']] as $k => $session_text) {
525
+							$data[$k] = sprintf($session_text, $row['id_board'], $row['name']);
526
+			}
500 527
 		}
501 528
 		$smcFunc['db_free_result']($result);
502 529
 	}
@@ -518,23 +545,26 @@  discard block
 block discarded – undo
518 545
 		while ($row = $smcFunc['db_fetch_assoc']($result))
519 546
 		{
520 547
 			// If they aren't allowed to view this person's profile, skip it.
521
-			if (!$allow_view_any && ($user_info['id'] != $row['id_member']))
522
-				continue;
548
+			if (!$allow_view_any && ($user_info['id'] != $row['id_member'])) {
549
+							continue;
550
+			}
523 551
 
524 552
 			// Set their action on each - session/text to sprintf.
525
-			foreach ($profile_ids[$row['id_member']] as $k => $session_text)
526
-				$data[$k] = sprintf($session_text, $row['id_member'], $row['real_name']);
553
+			foreach ($profile_ids[$row['id_member']] as $k => $session_text) {
554
+							$data[$k] = sprintf($session_text, $row['id_member'], $row['real_name']);
555
+			}
527 556
 		}
528 557
 		$smcFunc['db_free_result']($result);
529 558
 	}
530 559
 
531 560
 	call_integration_hook('whos_online_after', array(&$urls, &$data));
532 561
 
533
-	if (!is_array($urls))
534
-		return isset($data[0]) ? $data[0] : false;
535
-	else
536
-		return $data;
537
-}
562
+	if (!is_array($urls)) {
563
+			return isset($data[0]) ? $data[0] : false;
564
+	} else {
565
+			return $data;
566
+	}
567
+	}
538 568
 
539 569
 /**
540 570
  * It prepares credit and copyright information for the credits page or the admin page
@@ -710,8 +740,8 @@  discard block
 block discarded – undo
710 740
 	);
711 741
 
712 742
 	// Give the translators some credit for their hard work.
713
-	if (!empty($txt['translation_credits']))
714
-		$context['credits'][] = array(
743
+	if (!empty($txt['translation_credits'])) {
744
+			$context['credits'][] = array(
715 745
 			'title' => $txt['credits_groups_translation'],
716 746
 			'groups' => array(
717 747
 				array(
@@ -720,6 +750,7 @@  discard block
 block discarded – undo
720 750
 				),
721 751
 			),
722 752
 		);
753
+	}
723 754
 
724 755
 	$context['credits'][] = array(
725 756
 		'title' => $txt['credits_special'],
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +297 added lines, -224 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $smcFunc, $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -54,21 +57,25 @@  discard block
 block discarded – undo
54 57
 
55 58
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
56 59
 	{
57
-			if (!is_array($modSettings['attachment_basedirectories']))
58
-				$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
60
+			if (!is_array($modSettings['attachment_basedirectories'])) {
61
+							$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
62
+			}
59 63
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
64
+	} else {
65
+			$base_dir = 0;
60 66
 	}
61
-	else
62
-		$base_dir = 0;
63 67
 
64 68
 	if ($modSettings['automanage_attachments'] == 1)
65 69
 	{
66
-		if (!isset($modSettings['last_attachments_directory']))
67
-			$modSettings['last_attachments_directory'] = array();
68
-		if (!is_array($modSettings['last_attachments_directory']))
69
-			$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
70
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
71
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
70
+		if (!isset($modSettings['last_attachments_directory'])) {
71
+					$modSettings['last_attachments_directory'] = array();
72
+		}
73
+		if (!is_array($modSettings['last_attachments_directory'])) {
74
+					$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
75
+		}
76
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
77
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
78
+		}
72 79
 	}
73 80
 
74 81
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -97,12 +104,14 @@  discard block
 block discarded – undo
97 104
 			$updir = '';
98 105
 	}
99 106
 
100
-	if (!is_array($modSettings['attachmentUploadDir']))
101
-		$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
102
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
103
-		$outputCreation = automanage_attachments_create_directory($updir);
104
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
105
-		$outputCreation = true;
107
+	if (!is_array($modSettings['attachmentUploadDir'])) {
108
+			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
109
+	}
110
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
111
+			$outputCreation = automanage_attachments_create_directory($updir);
112
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
113
+			$outputCreation = true;
114
+	}
106 115
 
107 116
 	if ($outputCreation)
108 117
 	{
@@ -139,8 +148,9 @@  discard block
 block discarded – undo
139 148
 		$count = count($tree);
140 149
 
141 150
 		$directory = attachments_init_dir($tree, $count);
142
-		if ($directory === false)
143
-			return false;
151
+		if ($directory === false) {
152
+					return false;
153
+		}
144 154
 	}
145 155
 
146 156
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -168,8 +178,9 @@  discard block
 block discarded – undo
168 178
 	}
169 179
 
170 180
 	// Everything seems fine...let's create the .htaccess
171
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
172
-		secureDirectory($updir, true);
181
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
182
+			secureDirectory($updir, true);
183
+	}
173 184
 
174 185
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
175 186
 	$updir = rtrim($updir, $sep);
@@ -201,8 +212,9 @@  discard block
 block discarded – undo
201 212
 {
202 213
 	global $smcFunc, $modSettings, $boarddir;
203 214
 
204
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
205
-		return;
215
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
216
+			return;
217
+	}
206 218
 
207 219
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
208 220
 	// Just to be sure: I don't want directory separators at the end
@@ -214,13 +226,14 @@  discard block
 block discarded – undo
214 226
 	{
215 227
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
216 228
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
229
+	} else {
230
+			$base_dir = 0;
217 231
 	}
218
-	else
219
-		$base_dir = 0;
220 232
 
221 233
 	// Get the last attachment directory for that base directory
222
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
223
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
234
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
235
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
236
+	}
224 237
 	// And increment it.
225 238
 	$modSettings['last_attachments_directory'][$base_dir]++;
226 239
 
@@ -235,10 +248,10 @@  discard block
 block discarded – undo
235 248
 		$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
236 249
 
237 250
 		return true;
251
+	} else {
252
+			return false;
253
+	}
238 254
 	}
239
-	else
240
-		return false;
241
-}
242 255
 
243 256
 /**
244 257
  * Split a path into a list of all directories and subdirectories
@@ -256,12 +269,13 @@  discard block
 block discarded – undo
256 269
 			* in Windows we need to explode for both \ and /
257 270
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
258 271
 	*/
259
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
260
-		$tree = preg_split('#[\\\/]#', $directory);
261
-	else
272
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
273
+			$tree = preg_split('#[\\\/]#', $directory);
274
+	} else
262 275
 	{
263
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
264
-			return false;
276
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
277
+					return false;
278
+		}
265 279
 
266 280
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
267 281
 	}
@@ -285,10 +299,11 @@  discard block
 block discarded – undo
285 299
 		 //Better be sure that the first part of the path is actually a drive letter...
286 300
 		 //...even if, I should check this in the admin page...isn't it?
287 301
 		 //...NHAAA Let's leave space for users' complains! :P
288
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
289
-			$directory = array_shift($tree);
290
-		else
291
-			return false;
302
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
303
+					$directory = array_shift($tree);
304
+		} else {
305
+					return false;
306
+		}
292 307
 
293 308
 		$count--;
294 309
 	}
@@ -303,18 +318,20 @@  discard block
 block discarded – undo
303 318
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
304 319
 
305 320
 	// Make sure we're uploading to the right place.
306
-	if (!empty($modSettings['automanage_attachments']))
307
-		automanage_attachments_check_directory();
321
+	if (!empty($modSettings['automanage_attachments'])) {
322
+			automanage_attachments_check_directory();
323
+	}
308 324
 
309
-	if (!is_array($modSettings['attachmentUploadDir']))
310
-		$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
325
+	if (!is_array($modSettings['attachmentUploadDir'])) {
326
+			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
327
+	}
311 328
 
312 329
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
313 330
 
314 331
 	// Is the attachments folder actualy there?
315
-	if (!empty($context['dir_creation_error']))
316
-		$initial_error = $context['dir_creation_error'];
317
-	elseif (!is_dir($context['attach_dir']))
332
+	if (!empty($context['dir_creation_error'])) {
333
+			$initial_error = $context['dir_creation_error'];
334
+	} elseif (!is_dir($context['attach_dir']))
318 335
 	{
319 336
 		$initial_error = 'attach_folder_warning';
320 337
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -337,12 +354,12 @@  discard block
 block discarded – undo
337 354
 			);
338 355
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
339 356
 			$smcFunc['db_free_result']($request);
340
-		}
341
-		else
342
-			$context['attachments'] = array(
357
+		} else {
358
+					$context['attachments'] = array(
343 359
 				'quantity' => 0,
344 360
 				'total_size' => 0,
345 361
 			);
362
+		}
346 363
 	}
347 364
 
348 365
 	// Hmm. There are still files in session.
@@ -352,39 +369,44 @@  discard block
 block discarded – undo
352 369
 		// Let's try to keep them. But...
353 370
 		$ignore_temp = true;
354 371
 		// If new files are being added. We can't ignore those
355
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
356
-			if (!empty($dummy))
372
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
373
+					if (!empty($dummy))
357 374
 			{
358 375
 				$ignore_temp = false;
376
+		}
359 377
 				break;
360 378
 			}
361 379
 
362 380
 		// Need to make space for the new files. So, bye bye.
363 381
 		if (!$ignore_temp)
364 382
 		{
365
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
366
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
383
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
384
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
367 385
 					unlink($attachment['tmp_name']);
386
+			}
368 387
 
369 388
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
370 389
 			$_SESSION['temp_attachments'] = array();
371 390
 		}
372 391
 	}
373 392
 
374
-	if (!isset($_FILES['attachment']['name']))
375
-		$_FILES['attachment']['tmp_name'] = array();
393
+	if (!isset($_FILES['attachment']['name'])) {
394
+			$_FILES['attachment']['tmp_name'] = array();
395
+	}
376 396
 
377
-	if (!isset($_SESSION['temp_attachments']))
378
-		$_SESSION['temp_attachments'] = array();
397
+	if (!isset($_SESSION['temp_attachments'])) {
398
+			$_SESSION['temp_attachments'] = array();
399
+	}
379 400
 
380 401
 	// Remember where we are at. If it's anywhere at all.
381
-	if (!$ignore_temp)
382
-		$_SESSION['temp_attachments']['post'] = array(
402
+	if (!$ignore_temp) {
403
+			$_SESSION['temp_attachments']['post'] = array(
383 404
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
384 405
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
385 406
 			'topic' => !empty($topic) ? $topic : 0,
386 407
 			'board' => !empty($board) ? $board : 0,
387 408
 		);
409
+	}
388 410
 
389 411
 	// If we have an initial error, lets just display it.
390 412
 	if (!empty($initial_error))
@@ -392,9 +414,10 @@  discard block
 block discarded – undo
392 414
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
393 415
 
394 416
 		// And delete the files 'cos they ain't going nowhere.
395
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
396
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
417
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
418
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
397 419
 				unlink($_FILES['attachment']['tmp_name'][$n]);
420
+		}
398 421
 
399 422
 		$_FILES['attachment']['tmp_name'] = array();
400 423
 	}
@@ -402,21 +425,24 @@  discard block
 block discarded – undo
402 425
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
403 426
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
404 427
 	{
405
-		if ($_FILES['attachment']['name'][$n] == '')
406
-			continue;
428
+		if ($_FILES['attachment']['name'][$n] == '') {
429
+					continue;
430
+		}
407 431
 
408 432
 		// First, let's first check for PHP upload errors.
409 433
 		$errors = array();
410 434
 		if (!empty($_FILES['attachment']['error'][$n]))
411 435
 		{
412
-			if ($_FILES['attachment']['error'][$n] == 2)
413
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
414
-			elseif ($_FILES['attachment']['error'][$n] == 6)
415
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
416
-			else
417
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
418
-			if (empty($errors))
419
-				$errors[] = 'attach_php_error';
436
+			if ($_FILES['attachment']['error'][$n] == 2) {
437
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
438
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
439
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
440
+			} else {
441
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
442
+			}
443
+			if (empty($errors)) {
444
+							$errors[] = 'attach_php_error';
445
+			}
420 446
 		}
421 447
 
422 448
 		// Try to move and rename the file before doing any more checks on it.
@@ -426,8 +452,9 @@  discard block
 block discarded – undo
426 452
 		{
427 453
 			// The reported MIME type of the attachment might not be reliable.
428 454
 			// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
429
-			if (function_exists('mime_content_type'))
430
-				$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
455
+			if (function_exists('mime_content_type')) {
456
+							$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
457
+			}
431 458
 
432 459
 			$_SESSION['temp_attachments'][$attachID] = array(
433 460
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -439,16 +466,16 @@  discard block
 block discarded – undo
439 466
 			);
440 467
 
441 468
 			// Move the file to the attachments folder with a temp name for now.
442
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
443
-				smf_chmod($destName, 0644);
444
-			else
469
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
470
+							smf_chmod($destName, 0644);
471
+			} else
445 472
 			{
446 473
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
447
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
448
-					unlink($_FILES['attachment']['tmp_name'][$n]);
474
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
475
+									unlink($_FILES['attachment']['tmp_name'][$n]);
476
+				}
449 477
 			}
450
-		}
451
-		else
478
+		} else
452 479
 		{
453 480
 			$_SESSION['temp_attachments'][$attachID] = array(
454 481
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -456,12 +483,14 @@  discard block
 block discarded – undo
456 483
 				'errors' => $errors,
457 484
 			);
458 485
 
459
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
460
-				unlink($_FILES['attachment']['tmp_name'][$n]);
486
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
487
+							unlink($_FILES['attachment']['tmp_name'][$n]);
488
+			}
461 489
 		}
462 490
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
463
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
464
-			attachmentChecks($attachID);
491
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
492
+					attachmentChecks($attachID);
493
+		}
465 494
 	}
466 495
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
467 496
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -488,21 +517,20 @@  discard block
 block discarded – undo
488 517
 	global $modSettings, $context, $sourcedir, $smcFunc;
489 518
 
490 519
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
491
-	if (empty($_SESSION['temp_attachments'][$attachID]))
492
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
493
-
494
-	elseif (empty($attachID))
495
-		$error = '$attachID';
496
-
497
-	elseif (empty($context['attachments']))
498
-		$error = '$context[\'attachments\']';
499
-
500
-	elseif (empty($context['attach_dir']))
501
-		$error = '$context[\'attach_dir\']';
520
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
521
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
522
+	} elseif (empty($attachID)) {
523
+			$error = '$attachID';
524
+	} elseif (empty($context['attachments'])) {
525
+			$error = '$context[\'attachments\']';
526
+	} elseif (empty($context['attach_dir'])) {
527
+			$error = '$context[\'attach_dir\']';
528
+	}
502 529
 
503 530
 	// Let's get their attention.
504
-	if (!empty($error))
505
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
531
+	if (!empty($error)) {
532
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
533
+	}
506 534
 
507 535
 	// Just in case this slipped by the first checks, we stop it here and now
508 536
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -531,8 +559,9 @@  discard block
 block discarded – undo
531 559
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
532 560
 			if (!(empty($size)) && ($size[2] != $old_format))
533 561
 			{
534
-				if (isset($context['validImageTypes'][$size[2]]))
535
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
562
+				if (isset($context['validImageTypes'][$size[2]])) {
563
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
564
+				}
536 565
 			}
537 566
 		}
538 567
 	}
@@ -586,42 +615,48 @@  discard block
 block discarded – undo
586 615
 				// Or, let the user know that it ain't gonna happen.
587 616
 				else
588 617
 				{
589
-					if (isset($context['dir_creation_error']))
590
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
591
-					else
592
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
618
+					if (isset($context['dir_creation_error'])) {
619
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
620
+					} else {
621
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
622
+					}
593 623
 				}
624
+			} else {
625
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
594 626
 			}
595
-			else
596
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
597 627
 		}
598 628
 	}
599 629
 
600 630
 	// Is the file too big?
601 631
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
602
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
632
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
634
+	}
604 635
 
605 636
 	// Check the total upload size for this post...
606
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
607
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
637
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
638
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
639
+	}
608 640
 
609 641
 	// Have we reached the maximum number of files we are allowed?
610 642
 	$context['attachments']['quantity']++;
611 643
 
612 644
 	// Set a max limit if none exists
613
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
614
-		$modSettings['attachmentNumPerPostLimit'] = 50;
645
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
646
+			$modSettings['attachmentNumPerPostLimit'] = 50;
647
+	}
615 648
 
616
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
617
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
649
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
650
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
651
+	}
618 652
 
619 653
 	// File extension check
620 654
 	if (!empty($modSettings['attachmentCheckExtensions']))
621 655
 	{
622 656
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
623
-		foreach ($allowed as $k => $dummy)
624
-			$allowed[$k] = trim($dummy);
657
+		foreach ($allowed as $k => $dummy) {
658
+					$allowed[$k] = trim($dummy);
659
+		}
625 660
 
626 661
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
627 662
 		{
@@ -633,10 +668,12 @@  discard block
 block discarded – undo
633 668
 	// Undo the math if there's an error
634 669
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
635 670
 	{
636
-		if (isset($context['dir_size']))
637
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
638
-		if (isset($context['dir_files']))
639
-			$context['dir_files']--;
671
+		if (isset($context['dir_size'])) {
672
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
673
+		}
674
+		if (isset($context['dir_files'])) {
675
+					$context['dir_files']--;
676
+		}
640 677
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
641 678
 		$context['attachments']['quantity']--;
642 679
 		return false;
@@ -668,12 +705,14 @@  discard block
 block discarded – undo
668 705
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
669 706
 	{
670 707
 		// Got a proper mime type?
671
-		if (!empty($size['mime']))
672
-			$attachmentOptions['mime_type'] = $size['mime'];
708
+		if (!empty($size['mime'])) {
709
+					$attachmentOptions['mime_type'] = $size['mime'];
710
+		}
673 711
 
674 712
 		// Otherwise a valid one?
675
-		elseif (isset($context['validImageTypes'][$size[2]]))
676
-			$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
713
+		elseif (isset($context['validImageTypes'][$size[2]])) {
714
+					$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
715
+		}
677 716
 	}
678 717
 
679 718
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -685,15 +724,17 @@  discard block
 block discarded – undo
685 724
 	}
686 725
 
687 726
 	// Get the hash if no hash has been given yet.
688
-	if (empty($attachmentOptions['file_hash']))
689
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
727
+	if (empty($attachmentOptions['file_hash'])) {
728
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
729
+	}
690 730
 
691 731
 	// Assuming no-one set the extension let's take a look at it.
692 732
 	if (empty($attachmentOptions['fileext']))
693 733
 	{
694 734
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
695
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
696
-			$attachmentOptions['fileext'] = '';
735
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
736
+					$attachmentOptions['fileext'] = '';
737
+		}
697 738
 	}
698 739
 
699 740
 	// Last chance to change stuff!
@@ -702,8 +743,9 @@  discard block
 block discarded – undo
702 743
 	// Make sure the folder is valid...
703 744
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
704 745
 	$folders = array_keys($tmp);
705
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
706
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
746
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
747
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
748
+	}
707 749
 
708 750
 	$attachmentOptions['id'] = $smcFunc['db_insert']('',
709 751
 		'{db_prefix}attachments',
@@ -734,8 +776,8 @@  discard block
 block discarded – undo
734 776
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
735 777
 
736 778
 	// If it's not approved then add to the approval queue.
737
-	if (!$attachmentOptions['approved'])
738
-		$smcFunc['db_insert']('',
779
+	if (!$attachmentOptions['approved']) {
780
+			$smcFunc['db_insert']('',
739 781
 			'{db_prefix}approval_queue',
740 782
 			array(
741 783
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -745,9 +787,11 @@  discard block
 block discarded – undo
745 787
 			),
746 788
 			array()
747 789
 		);
790
+	}
748 791
 
749
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
750
-		return true;
792
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
793
+			return true;
794
+	}
751 795
 
752 796
 	// Like thumbnails, do we?
753 797
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -758,13 +802,15 @@  discard block
 block discarded – undo
758 802
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
759 803
 			list ($thumb_width, $thumb_height) = $size;
760 804
 
761
-			if (!empty($size['mime']))
762
-				$thumb_mime = $size['mime'];
763
-			elseif (isset($context['validImageTypes'][$size[2]]))
764
-				$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
805
+			if (!empty($size['mime'])) {
806
+							$thumb_mime = $size['mime'];
807
+			} elseif (isset($context['validImageTypes'][$size[2]])) {
808
+							$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
809
+			}
765 810
 			// Lord only knows how this happened...
766
-			else
767
-				$thumb_mime = '';
811
+			else {
812
+							$thumb_mime = '';
813
+			}
768 814
 
769 815
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
770 816
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -844,15 +890,17 @@  discard block
 block discarded – undo
844 890
 	global $smcFunc;
845 891
 
846 892
 	// Oh, come on!
847
-	if (empty($attachIDs) || empty($msgID))
848
-		return false;
893
+	if (empty($attachIDs) || empty($msgID)) {
894
+			return false;
895
+	}
849 896
 
850 897
 	// "I see what is right and approve, but I do what is wrong."
851 898
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
852 899
 
853 900
 	// One last check
854
-	if (empty($attachIDs))
855
-		return false;
901
+	if (empty($attachIDs)) {
902
+			return false;
903
+	}
856 904
 
857 905
 	// Perform.
858 906
 	$smcFunc['db_query']('', '
@@ -880,8 +928,9 @@  discard block
 block discarded – undo
880 928
 	global $board, $modSettings, $context, $scripturl, $smcFunc;
881 929
 
882 930
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
931
+	if (empty($attachID)) {
932
+			return 'attachments_no_data_loaded';
933
+	}
885 934
 
886 935
 	// Make it easy.
887 936
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +939,23 @@  discard block
 block discarded – undo
890 939
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 940
 
892 941
 	// "I am innocent of the blood of this just person: see ye to it."
893
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
894
-		return $externalParse;
942
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
943
+			return $externalParse;
944
+	}
895 945
 
896 946
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
947
+	if (empty($modSettings['attachmentEnable'])) {
948
+			return 'attachments_not_enable';
949
+	}
899 950
 
900 951
 	// Previewing much? no msg ID has been set yet.
901 952
 	if (!empty($context['preview_message']))
902 953
 	{
903 954
 		$allAttachments = getAttachsByMsg(0);
904 955
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
956
+		if (empty($allAttachments[0][$attachID])) {
957
+					return 'attachments_no_data_loaded';
958
+		}
907 959
 
908 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
909 961
 
@@ -915,57 +967,66 @@  discard block
 block discarded – undo
915 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
916 968
 
917 969
 		// Fix the thumbnail too, if the image has one.
918
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
919
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
970
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
971
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		}
920 973
 
921 974
 		return $attachContext;
922 975
 	}
923 976
 
924 977
 	// There is always the chance someone else has already done our dirty work...
925 978
 	// If so, all pertinent checks were already done. Hopefully...
926
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
927
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
928 982
 
929 983
 	// If we are lucky enough to be in $board's scope then check it!
930
-	if (!empty($board) && !allowedTo('view_attachments', $board))
931
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
932 987
 
933 988
 	// Get the message info associated with this particular attach ID.
934 989
 	$attachInfo = getAttachMsgInfo($attachID);
935 990
 
936 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
937
-	if (empty($attachInfo) || empty($attachInfo['msg']))
938
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
939 995
 
940 996
 	// Hold it! got the info now check if you can see this attachment.
941
-	if (!allowedTo('view_attachments', $attachInfo['board']))
942
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
943 1000
 
944 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
945 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
946 1003
 
947 1004
 	// No point in keep going further.
948
-	if (!allowedTo('view_attachments', $attachContext['board']))
949
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
950 1008
 
951 1009
 	// Load this particular attach's context.
952
-	if (!empty($attachContext))
953
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
954 1013
 
955 1014
 	// One last check, you know, gotta be paranoid...
956
-	else
957
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
958 1018
 
959 1019
 	// This is the last "if" I promise!
960
-	if (empty($attachLoaded))
961
-		return 'attachments_no_data_loaded';
962
-
963
-	else
964
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
965 1025
 
966 1026
 	// You may or may not want to show this under the post.
967
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
968
-		$context['show_attach_under_post'][$attachID] = $attachID;
1027
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1028
+			$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	}
969 1030
 
970 1031
 	// Last minute changes?
971 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -985,8 +1046,9 @@  discard block
 block discarded – undo
985 1046
 {
986 1047
 	global $smcFunc, $modSettings;
987 1048
 
988
-	if (empty($attachIDs))
989
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
990 1052
 
991 1053
 	$return = array();
992 1054
 
@@ -1002,11 +1064,12 @@  discard block
 block discarded – undo
1002 1064
 		)
1003 1065
 	);
1004 1066
 
1005
-	if ($smcFunc['db_num_rows']($request) != 1)
1006
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1007 1070
 
1008
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1009
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1010 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1011 1074
 			'size' => $row['size'],
1012 1075
 			'attachID' => $row['id_attach'],
@@ -1015,6 +1078,7 @@  discard block
 block discarded – undo
1015 1078
 			'mime_type' => $row['mime_type'],
1016 1079
 			'thumb' => $row['id_thumb'],
1017 1080
 		);
1081
+	}
1018 1082
 	$smcFunc['db_free_result']($request);
1019 1083
 
1020 1084
 	return $return;
@@ -1031,8 +1095,9 @@  discard block
 block discarded – undo
1031 1095
 {
1032 1096
 	global $smcFunc;
1033 1097
 
1034
-	if (empty($attachID))
1035
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1036 1101
 
1037 1102
 	$request = $smcFunc['db_query']('', '
1038 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1045,8 +1110,9 @@  discard block
 block discarded – undo
1045 1110
 		)
1046 1111
 	);
1047 1112
 
1048
-	if ($smcFunc['db_num_rows']($request) != 1)
1049
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1050 1116
 
1051 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1052 1118
 	$smcFunc['db_free_result']($request);
@@ -1087,8 +1153,9 @@  discard block
 block discarded – undo
1087 1153
 		$temp = array();
1088 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1089 1155
 		{
1090
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1091
-				continue;
1156
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1157
+							continue;
1158
+			}
1092 1159
 
1093 1160
 			$temp[$row['id_attach']] = $row;
1094 1161
 		}
@@ -1117,8 +1184,9 @@  discard block
 block discarded – undo
1117 1184
 {
1118 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1119 1186
 
1120
-	if (empty($attachments) || empty($attachments[$id_msg]))
1121
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1122 1190
 
1123 1191
 	// Set up the attachment info - based on code by Meriadoc.
1124 1192
 	$attachmentData = array();
@@ -1142,11 +1210,13 @@  discard block
 block discarded – undo
1142 1210
 			);
1143 1211
 
1144 1212
 			// If something is unapproved we'll note it so we can sort them.
1145
-			if (!$attachment['approved'])
1146
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1147 1216
 
1148
-			if (!$attachmentData[$i]['is_image'])
1149
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1150 1220
 
1151 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1152 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1167,11 +1237,11 @@  discard block
 block discarded – undo
1167 1237
 						// So what folder are we putting this image in?
1168 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1169 1239
 						{
1170
-							if (!is_array($modSettings['attachmentUploadDir']))
1171
-								$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1242
+							}
1172 1243
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1173
-						}
1174
-						else
1244
+						} else
1175 1245
 						{
1176 1246
 							$id_folder_thumb = 1;
1177 1247
 						}
@@ -1185,10 +1255,11 @@  discard block
 block discarded – undo
1185 1255
 						$thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : '';
1186 1256
 
1187 1257
 						// Figure out the mime type.
1188
-						if (!empty($size['mime']))
1189
-							$thumb_mime = $size['mime'];
1190
-						else
1191
-							$thumb_mime = 'image/' . $thumb_ext;
1258
+						if (!empty($size['mime'])) {
1259
+													$thumb_mime = $size['mime'];
1260
+						} else {
1261
+													$thumb_mime = 'image/' . $thumb_ext;
1262
+						}
1192 1263
 
1193 1264
 						$thumb_filename = $attachment['filename'] . '_thumb';
1194 1265
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1235,11 +1306,12 @@  discard block
 block discarded – undo
1235 1306
 				}
1236 1307
 			}
1237 1308
 
1238
-			if (!empty($attachment['id_thumb']))
1239
-				$attachmentData[$i]['thumbnail'] = array(
1309
+			if (!empty($attachment['id_thumb'])) {
1310
+							$attachmentData[$i]['thumbnail'] = array(
1240 1311
 					'id' => $attachment['id_thumb'],
1241 1312
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1242 1313
 				);
1314
+			}
1243 1315
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1244 1316
 
1245 1317
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1249,30 +1321,31 @@  discard block
 block discarded – undo
1249 1321
 				{
1250 1322
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1251 1323
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1252
-				}
1253
-				elseif (!empty($modSettings['max_image_width']))
1324
+				} elseif (!empty($modSettings['max_image_width']))
1254 1325
 				{
1255 1326
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1256 1327
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1257 1328
 				}
1258
-			}
1259
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1329
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1260 1330
 			{
1261 1331
 				// If the image is too large to show inline, make it a popup.
1262
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1263
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1264
-				else
1265
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1332
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1333
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1334
+				} else {
1335
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1336
+				}
1266 1337
 			}
1267 1338
 
1268
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1269
-				$attachmentData[$i]['downloads']++;
1339
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1340
+							$attachmentData[$i]['downloads']++;
1341
+			}
1270 1342
 		}
1271 1343
 	}
1272 1344
 
1273 1345
 	// Do we need to instigate a sort?
1274
-	if ($have_unapproved)
1275
-		usort($attachmentData, 'approved_attach_sort');
1346
+	if ($have_unapproved) {
1347
+			usort($attachmentData, 'approved_attach_sort');
1348
+	}
1276 1349
 
1277 1350
 	return $attachmentData;
1278 1351
 }
Please login to merge, or discard this patch.