Completed
Pull Request — release-2.1 (#3761)
by Rick
14:55 queued 08:11
created
attachments/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('Location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Display.template.php 1 patch
Braces   +221 added lines, -151 removed lines patch added patch discarded remove patch
@@ -51,11 +51,13 @@  discard block
 block discarded – undo
51 51
 				<p>';
52 52
 
53 53
 		// Show just numbers...?
54
-		if ($settings['display_who_viewing'] == 1)
55
-				echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
54
+		if ($settings['display_who_viewing'] == 1) {
55
+						echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
56
+		}
56 57
 		// Or show the actual people viewing the topic?
57
-		else
58
-			echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
58
+		else {
59
+					echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
60
+		}
59 61
 
60 62
 		// Now show how many guests are here too.
61 63
 		echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_topic'], '
@@ -93,10 +95,11 @@  discard block
 block discarded – undo
93 95
 						<dt class="', $option['voted_this'] ? ' voted' : '', '">', $option['option'], '</dt>
94 96
 						<dd class="statsbar', $option['voted_this'] ? ' voted' : '', '">';
95 97
 
96
-				if ($context['allow_results_view'])
97
-					echo '
98
+				if ($context['allow_results_view']) {
99
+									echo '
98 100
 							', $option['bar_ndt'], '
99 101
 							<span class="percentage">', $option['votes'], ' (', $option['percent'], '%)</span>';
102
+				}
100 103
 
101 104
 				echo '
102 105
 						</dd>';
@@ -105,9 +108,10 @@  discard block
 block discarded – undo
105 108
 			echo '
106 109
 					</dl>';
107 110
 
108
-			if ($context['allow_results_view'])
109
-				echo '
111
+			if ($context['allow_results_view']) {
112
+							echo '
110 113
 						<p><strong>', $txt['poll_total_voters'], ':</strong> ', $context['poll']['total_votes'], '</p>';
114
+			}
111 115
 		}
112 116
 		// They are allowed to vote! Go to it!
113 117
 		else
@@ -116,17 +120,19 @@  discard block
 block discarded – undo
116 120
 						<form action="', $scripturl, '?action=vote;topic=', $context['current_topic'], '.', $context['start'], ';poll=', $context['poll']['id'], '" method="post" accept-charset="', $context['character_set'], '">';
117 121
 
118 122
 			// Show a warning if they are allowed more than one option.
119
-			if ($context['poll']['allowed_warning'])
120
-				echo '
123
+			if ($context['poll']['allowed_warning']) {
124
+							echo '
121 125
 							<p class="smallpadding">', $context['poll']['allowed_warning'], '</p>';
126
+			}
122 127
 
123 128
 			echo '
124 129
 							<ul class="options">';
125 130
 
126 131
 			// Show each option with its button - a radio likely.
127
-			foreach ($context['poll']['options'] as $option)
128
-				echo '
132
+			foreach ($context['poll']['options'] as $option) {
133
+							echo '
129 134
 								<li>', $option['vote_button'], ' <label for="', $option['id'], '">', $option['option'], '</label></li>';
135
+			}
130 136
 
131 137
 			echo '
132 138
 							</ul>
@@ -138,9 +144,10 @@  discard block
 block discarded – undo
138 144
 		}
139 145
 
140 146
 		// Is the clock ticking?
141
-		if (!empty($context['poll']['expire_time']))
142
-			echo '
147
+		if (!empty($context['poll']['expire_time'])) {
148
+					echo '
143 149
 						<p><strong>', ($context['poll']['is_expired'] ? $txt['poll_expired_on'] : $txt['poll_expires_on']), ':</strong> ', $context['poll']['expire_time'], '</p>';
150
+		}
144 151
 
145 152
 		echo '
146 153
 					</div>
@@ -170,11 +177,13 @@  discard block
 block discarded – undo
170 177
 					<li>
171 178
 						<b class="event_title"><a href="', $scripturl, '?action=calendar;event=', $event['id'], '">', $event['title'], '</a></b>';
172 179
 
173
-			if ($event['can_edit'])
174
-				echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
180
+			if ($event['can_edit']) {
181
+							echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
182
+			}
175 183
 
176
-			if ($event['can_export'])
177
-				echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
184
+			if ($event['can_export']) {
185
+							echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
186
+			}
178 187
 
179 188
 			echo '
180 189
 						<br>';
@@ -182,14 +191,14 @@  discard block
 block discarded – undo
182 191
 			if (!empty($event['allday']))
183 192
 			{
184 193
 				echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
185
-			}
186
-			else
194
+			} else
187 195
 			{
188 196
 				// Display event info relative to user's local timezone
189 197
 				echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
190 198
 
191
-				if ($event['start_date_local'] != $event['end_date_local'])
192
-					echo trim($event['end_date_local']) . ', ';
199
+				if ($event['start_date_local'] != $event['end_date_local']) {
200
+									echo trim($event['end_date_local']) . ', ';
201
+				}
193 202
 
194 203
 				echo trim($event['end_time_local']);
195 204
 
@@ -198,23 +207,27 @@  discard block
 block discarded – undo
198 207
 				{
199 208
 					echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
200 209
 
201
-					if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
202
-						echo trim($event['start_date_orig']), ', ';
210
+					if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) {
211
+											echo trim($event['start_date_orig']), ', ';
212
+					}
203 213
 
204 214
 					echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
205 215
 
206
-					if ($event['start_date_orig'] != $event['end_date_orig'])
207
-						echo trim($event['end_date_orig']) . ', ';
216
+					if ($event['start_date_orig'] != $event['end_date_orig']) {
217
+											echo trim($event['end_date_orig']) . ', ';
218
+					}
208 219
 
209 220
 					echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
210 221
 				}
211 222
 				// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
212
-				else
213
-					echo ' ', $event['tz_abbrev'], '</time>';
223
+				else {
224
+									echo ' ', $event['tz_abbrev'], '</time>';
225
+				}
214 226
 			}
215 227
 
216
-			if (!empty($event['location']))
217
-				echo '<br>', $event['location'];
228
+			if (!empty($event['location'])) {
229
+							echo '<br>', $event['location'];
230
+			}
218 231
 
219 232
 			echo '
220 233
 					</li>';
@@ -252,8 +265,9 @@  discard block
 block discarded – undo
252 265
 	$context['removableMessageIDs'] = array();
253 266
 
254 267
 	// Get all the messages...
255
-	while ($message = $context['get_message']())
256
-		template_single_post($message);
268
+	while ($message = $context['get_message']()) {
269
+			template_single_post($message);
270
+	}
257 271
 
258 272
 	echo '
259 273
 				</form>
@@ -290,8 +304,9 @@  discard block
 block discarded – undo
290 304
 			<div id="display_jump_to">&nbsp;</div>';
291 305
 
292 306
 	// Show quickreply
293
-	if ($context['can_reply'])
294
-	template_quickreply();
307
+	if ($context['can_reply']) {
308
+		template_quickreply();
309
+	}
295 310
 
296 311
 	// User action pop on mobile screen (or actually small screen), this uses responsive css does not check mobile device.
297 312
 	echo '
@@ -304,8 +319,8 @@  discard block
 block discarded – undo
304 319
 			</div>';
305 320
 
306 321
 	// Show the moderation button & pop only if user can moderate
307
-	if ($context['can_moderate_forum'] || $context['user']['is_mod'])
308
-		echo '
322
+	if ($context['can_moderate_forum'] || $context['user']['is_mod']) {
323
+			echo '
309 324
 			<div id="mobile_moderation" class="popup_container">
310 325
 				<div class="popup_window description">
311 326
 					<div class="popup_heading">', $txt['mobile_moderation'],'
@@ -315,6 +330,7 @@  discard block
 block discarded – undo
315 330
 					</div>
316 331
 				</div>
317 332
 			</div>';
333
+	}
318 334
 
319 335
 		echo '
320 336
 				<script>';
@@ -438,9 +454,10 @@  discard block
 block discarded – undo
438 454
 						});
439 455
 					}';
440 456
 
441
-	if (!empty($context['ignoredMsgs']))
442
-		echo '
457
+	if (!empty($context['ignoredMsgs'])) {
458
+			echo '
443 459
 					ignore_toggles([', implode(', ', $context['ignoredMsgs']), '], ', JavaScriptEscape($txt['show_ignore_user_post']), ');';
460
+	}
444 461
 
445 462
 	echo '
446 463
 				</script>';
@@ -457,8 +474,9 @@  discard block
 block discarded – undo
457 474
 
458 475
 	$ignoring = false;
459 476
 
460
-	if ($message['can_remove'])
461
-		$context['removableMessageIDs'][] = $message['id'];
477
+	if ($message['can_remove']) {
478
+			$context['removableMessageIDs'][] = $message['id'];
479
+	}
462 480
 
463 481
 	// Are we ignoring this message?
464 482
 	if (!empty($message['is_ignored']))
@@ -484,9 +502,10 @@  discard block
 block discarded – undo
484 502
 							<div class="custom_fields_above_member">
485 503
 								<ul class="nolist">';
486 504
 
487
-		foreach ($message['custom_fields']['above_member'] as $custom)
488
-			echo '
505
+		foreach ($message['custom_fields']['above_member'] as $custom) {
506
+					echo '
489 507
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
508
+		}
490 509
 
491 510
 		echo '
492 511
 								</ul>
@@ -497,9 +516,10 @@  discard block
 block discarded – undo
497 516
 									<h4>';
498 517
 
499 518
 	// Show online and offline buttons?
500
-	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
501
-		echo '
519
+	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest']) {
520
+			echo '
502 521
 								', $context['can_send_pm'] ? '<a href="' . $message['member']['online']['href'] . '" title="' . $message['member']['online']['label'] . '">' : '', '<span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>', $context['can_send_pm'] ? '</a>' : '';
522
+	}
503 523
 
504 524
 
505 525
 	// Show a link to the member's profile.
@@ -512,51 +532,59 @@  discard block
 block discarded – undo
512 532
 
513 533
 
514 534
 	// Show the user's avatar.
515
-	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
516
-		echo '
535
+	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image'])) {
536
+			echo '
517 537
 								<li class="avatar">
518 538
 									<a href="', $message['member']['href'], '">', $message['member']['avatar']['image'], '</a>
519 539
 								</li>';
540
+	}
520 541
 
521 542
 	// Are there any custom fields below the avatar?
522
-	if (!empty($message['custom_fields']['below_avatar']))
523
-		foreach ($message['custom_fields']['below_avatar'] as $custom)
543
+	if (!empty($message['custom_fields']['below_avatar'])) {
544
+			foreach ($message['custom_fields']['below_avatar'] as $custom)
524 545
 			echo '
525 546
 								<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
547
+	}
526 548
 
527 549
 	// Show the post group icons, but not for guests.
528
-	if (!$message['member']['is_guest'])
529
-		echo '
550
+	if (!$message['member']['is_guest']) {
551
+			echo '
530 552
 								<li class="icons">', $message['member']['group_icons'], '</li>';
553
+	}
531 554
 
532 555
 	// Show the member's primary group (like 'Administrator') if they have one.
533
-	if (!empty($message['member']['group']))
534
-		echo '
556
+	if (!empty($message['member']['group'])) {
557
+			echo '
535 558
 								<li class="membergroup">', $message['member']['group'], '</li>';
559
+	}
536 560
 
537 561
 	// Show the member's custom title, if they have one.
538
-	if (!empty($message['member']['title']))
539
-		echo '
562
+	if (!empty($message['member']['title'])) {
563
+			echo '
540 564
 								<li class="title">', $message['member']['title'], '</li>';
565
+	}
541 566
 
542 567
 	// Don't show these things for guests.
543 568
 	if (!$message['member']['is_guest'])
544 569
 	{
545 570
 
546 571
 		// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
547
-		if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group']))
548
-			echo '
572
+		if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group'])) {
573
+					echo '
549 574
 								<li class="postgroup">', $message['member']['post_group'], '</li>';
575
+		}
550 576
 
551 577
 		// Show how many posts they have made.
552
-		if (!isset($context['disabled_fields']['posts']))
553
-			echo '
578
+		if (!isset($context['disabled_fields']['posts'])) {
579
+					echo '
554 580
 								<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
581
+		}
555 582
 
556 583
 		// Show their personal text?
557
-		if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb']))
558
-			echo '
584
+		if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb'])) {
585
+					echo '
559 586
 								<li class="blurb">', $message['member']['blurb'], '</li>';
587
+		}
560 588
 
561 589
 		// Any custom fields to show as icons?
562 590
 		if (!empty($message['custom_fields']['icons']))
@@ -565,9 +593,10 @@  discard block
 block discarded – undo
565 593
 								<li class="im_icons">
566 594
 									<ol>';
567 595
 
568
-			foreach ($message['custom_fields']['icons'] as $custom)
569
-				echo '
596
+			foreach ($message['custom_fields']['icons'] as $custom) {
597
+							echo '
570 598
 										<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
599
+			}
571 600
 
572 601
 			echo '
573 602
 									</ol>
@@ -582,19 +611,22 @@  discard block
 block discarded – undo
582 611
 									<ol class="profile_icons">';
583 612
 
584 613
 			// Don't show an icon if they haven't specified a website.
585
-			if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website']))
586
-				echo '
614
+			if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website'])) {
615
+							echo '
587 616
 										<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" class="new_win">', ($settings['use_image_buttons'] ? '<span class="generic_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
617
+			}
588 618
 
589 619
 			// Since we know this person isn't a guest, you *can* message them.
590
-			if ($context['can_send_pm'])
591
-				echo '
620
+			if ($context['can_send_pm']) {
621
+							echo '
592 622
 										<li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<span class="generic_icons im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . ' centericon" title="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '"></span> ' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>';
623
+			}
593 624
 
594 625
 			// Show the email if necessary
595
-			if (!empty($message['member']['email']) && $message['member']['show_email'])
596
-				echo '
626
+			if (!empty($message['member']['email']) && $message['member']['show_email']) {
627
+							echo '
597 628
 										<li class="email"><a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
629
+			}
598 630
 
599 631
 				echo '
600 632
 									</ol>
@@ -602,48 +634,56 @@  discard block
 block discarded – undo
602 634
 		}
603 635
 
604 636
 		// Any custom fields for standard placement?
605
-		if (!empty($message['custom_fields']['standard']))
606
-			foreach ($message['custom_fields']['standard'] as $custom)
637
+		if (!empty($message['custom_fields']['standard'])) {
638
+					foreach ($message['custom_fields']['standard'] as $custom)
607 639
 				echo '
608 640
 								<li class="custom ', $custom['col_name'] ,'">', $custom['title'], ': ', $custom['value'], '</li>';
641
+		}
609 642
 
610 643
 	}
611 644
 	// Otherwise, show the guest's email.
612
-	elseif (!empty($message['member']['email']) && $message['member']['show_email'])
613
-		echo '
645
+	elseif (!empty($message['member']['email']) && $message['member']['show_email']) {
646
+			echo '
614 647
 								<li class="email"><a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
648
+	}
615 649
 
616 650
 	// Show the IP to this user for this post - because you can moderate?
617
-	if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip']))
618
-		echo '
651
+	if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip'])) {
652
+			echo '
619 653
 								<li class="poster_ip"><a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">(?)</a></li>';
654
+	}
620 655
 
621 656
 	// Or, should we show it because this is you?
622
-	elseif ($message['can_see_ip'])
623
-		echo '
657
+	elseif ($message['can_see_ip']) {
658
+			echo '
624 659
 								<li class="poster_ip"><a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $message['member']['ip'], '</a></li>';
660
+	}
625 661
 
626 662
 	// Okay, are you at least logged in? Then we can show something about why IPs are logged...
627
-	elseif (!$context['user']['is_guest'])
628
-		echo '
663
+	elseif (!$context['user']['is_guest']) {
664
+			echo '
629 665
 								<li class="poster_ip"><a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a></li>';
666
+	}
630 667
 
631 668
 	// Otherwise, you see NOTHING!
632
-	else
633
-		echo '
669
+	else {
670
+			echo '
634 671
 								<li class="poster_ip">', $txt['logged'], '</li>';
672
+	}
635 673
 
636 674
 	// Are we showing the warning status?
637 675
 	// Don't show these things for guests.
638
-	if (!$message['member']['is_guest'] && $message['member']['can_see_warning'])
639
-		echo '
676
+	if (!$message['member']['is_guest'] && $message['member']['can_see_warning']) {
677
+			echo '
640 678
 								<li class="warning">', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="generic_icons warning_', $message['member']['warning_status'], '"></span> ', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span></li>';
679
+	}
641 680
 
642 681
 	// Are there any custom fields to show at the bottom of the poster info?
643
-	if (!empty($message['custom_fields']['bottom_poster']))
644
-		foreach ($message['custom_fields']['bottom_poster'] as $custom)
682
+	if (!empty($message['custom_fields']['bottom_poster'])) {
683
+			foreach ($message['custom_fields']['bottom_poster'] as $custom)
645 684
 			echo '
646 685
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
686
+	}
647 687
 
648 688
 	// Poster info ends.
649 689
 	echo '
@@ -672,9 +712,10 @@  discard block
 block discarded – undo
672 712
 	echo '
673 713
 									<span class="smalltext modified" id="modified_', $message['id'], '">';
674 714
 
675
-	if (!empty($modSettings['show_modify']) && !empty($message['modified']['name']))
676
-		echo
715
+	if (!empty($modSettings['show_modify']) && !empty($message['modified']['name'])) {
716
+			echo
677 717
 										$message['modified']['last_edit_text'];
718
+	}
678 719
 
679 720
 	echo '
680 721
 									</span>';
@@ -685,22 +726,24 @@  discard block
 block discarded – undo
685 726
 							</div>';
686 727
 
687 728
 	// Ignoring this user? Hide the post.
688
-	if ($ignoring)
689
-		echo '
729
+	if ($ignoring) {
730
+			echo '
690 731
 							<div id="msg_', $message['id'], '_ignored_prompt">
691 732
 								', $txt['ignoring_user'], '
692 733
 								<a href="#" id="msg_', $message['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
693 734
 							</div>';
735
+	}
694 736
 
695 737
 	// Show the post itself, finally!
696 738
 	echo '
697 739
 							<div class="post">';
698 740
 
699
-	if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id'])
700
-		echo '
741
+	if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id']) {
742
+			echo '
701 743
 								<div class="approve_post">
702 744
 									', $txt['post_awaiting_approval'], '
703 745
 								</div>';
746
+	}
704 747
 	echo '
705 748
 								<div class="inner" data-msgid="', $message['id'], '" id="msg_', $message['id'], '"', $ignoring ? ' style="display:none;"' : '', '>', $message['body'], '</div>
706 749
 							</div>';
@@ -717,9 +760,9 @@  discard block
 block discarded – undo
717 760
 		foreach ($message['attachment'] as $attachment)
718 761
 		{
719 762
 			// Do we want this attachment to not be showed here?
720
-			if (!empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']]))
721
-				continue;
722
-			elseif (!$div_output)
763
+			if (!empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']])) {
764
+							continue;
765
+			} elseif (!$div_output)
723 766
 			{
724 767
 				$div_output = true;
725 768
 
@@ -735,9 +778,10 @@  discard block
 block discarded – undo
735 778
 								<fieldset>
736 779
 									<legend>', $txt['attach_awaiting_approve'];
737 780
 
738
-				if ($context['can_approve'])
739
-					echo '
781
+				if ($context['can_approve']) {
782
+									echo '
740 783
 										&nbsp;[<a href="', $scripturl, '?action=attachapprove;sa=all;mid=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve_all'], '</a>]';
784
+				}
741 785
 
742 786
 				echo '
743 787
 									</legend>';
@@ -751,12 +795,13 @@  discard block
 block discarded – undo
751 795
 				echo '
752 796
 										<div class="attachments_top">';
753 797
 
754
-				if ($attachment['thumbnail']['has_thumb'])
755
-					echo '
798
+				if ($attachment['thumbnail']['has_thumb']) {
799
+									echo '
756 800
 											<a href="', $attachment['href'], ';image" id="link_', $attachment['id'], '" onclick="', $attachment['thumbnail']['javascript'], '"><img src="', $attachment['thumbnail']['href'], '" alt="" id="thumb_', $attachment['id'], '" class="atc_img"></a>';
757
-				else
758
-					echo '
801
+				} else {
802
+									echo '
759 803
 											<img src="' . $attachment['href'] . ';image" alt="" width="' . $attachment['width'] . '" height="' . $attachment['height'] . '" class="atc_img">';
804
+				}
760 805
 
761 806
 				echo '
762 807
 										</div>';
@@ -766,9 +811,10 @@  discard block
 block discarded – undo
766 811
 										<div class="attachments_bot">
767 812
 											<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.png" class="centericon" alt="*">&nbsp;' . $attachment['name'] . '</a> ';
768 813
 
769
-			if (!$attachment['is_approved'] && $context['can_approve'])
770
-				echo '
814
+			if (!$attachment['is_approved'] && $context['can_approve']) {
815
+							echo '
771 816
 											[<a href="', $scripturl, '?action=attachapprove;sa=approve;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve'], '</a>]&nbsp;|&nbsp;[<a href="', $scripturl, '?action=attachapprove;sa=reject;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['delete'], '</a>] ';
817
+			}
772 818
 			echo '
773 819
 											<br>', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . '<br>' . sprintf($txt['attach_viewed'], $attachment['downloads']) : '<br>' . sprintf($txt['attach_downloaded'], $attachment['downloads'])), '
774 820
 										</div>';
@@ -777,33 +823,38 @@  discard block
 block discarded – undo
777 823
 									</div>';
778 824
 
779 825
 			// Next attachment line ?
780
-			if (++$i % $attachments_per_line === 0)
781
-				echo '
826
+			if (++$i % $attachments_per_line === 0) {
827
+							echo '
782 828
 									<br>';
829
+			}
783 830
 		}
784 831
 
785 832
 		// If we had unapproved attachments clean up.
786
-		if ($last_approved_state == 0)
787
-			echo '
833
+		if ($last_approved_state == 0) {
834
+					echo '
788 835
 								</fieldset>';
836
+		}
789 837
 
790 838
 		// Only do this if we output a div above - otherwise it'll break things
791
-		if ($div_output)
792
-			echo '
839
+		if ($div_output) {
840
+					echo '
793 841
 							</div>';
842
+		}
794 843
 	}
795 844
 
796 845
 	// And stuff below the attachments.
797
-	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote'])
798
-	echo '
846
+	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote']) {
847
+		echo '
799 848
 							<div class="under_message">';
849
+	}
800 850
 
801 851
 	// Maybe they want to report this post to the moderator(s)?
802
-	if ($context['can_report_moderator'])
803
-		echo '
852
+	if ($context['can_report_moderator']) {
853
+			echo '
804 854
 								<ul class="floatright smalltext">
805 855
 									<li class="report_link"><a href="', $scripturl, '?action=reporttm;topic=', $context['current_topic'], '.', $message['counter'], ';msg=', $message['id'], '">', $txt['report_to_mod'], '</a></li>
806 856
 								</ul>';
857
+	}
807 858
 
808 859
 	// What about likes?
809 860
 	if (!empty($modSettings['enable_likes']))
@@ -844,78 +895,91 @@  discard block
 block discarded – undo
844 895
 								<ul class="quickbuttons">';
845 896
 
846 897
 		// Can they quote? if so they can select and quote as well!
847
-		if ($context['can_quote'])
848
-			echo '
898
+		if ($context['can_quote']) {
899
+					echo '
849 900
 									<li><a href="', $scripturl, '?action=post;quote=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], ';last_msg=', $context['topic_last_message'], '" onclick="return oQuickReply.quote(', $message['id'], ');"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>
850 901
 									<li style="display:none;" id="quoteSelected_', $message['id'], '"><a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'] ,'</a></li>';
902
+		}
851 903
 
852 904
 		// Can the user modify the contents of this post? Show the modify inline image.
853
-		if ($message['can_modify'])
854
-			echo '
905
+		if ($message['can_modify']) {
906
+					echo '
855 907
 									<li class="quick_edit"><a title="', $txt['modify_msg'], '" class="modifybutton" id="modify_button_', $message['id'], '" onclick="oQuickModify.modifyMsg(\'', $message['id'], '\', \'', !empty($modSettings['toggle_subject']), '\')"><span class="generic_icons quick_edit_button"></span>', $txt['quick_edit'], '</a></li>';
908
+		}
856 909
 
857
-		if ($message['can_approve'] || $message['can_unapprove'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'])
858
-			echo '
910
+		if ($message['can_approve'] || $message['can_unapprove'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg']) {
911
+					echo '
859 912
 									<li class="post_options">', $txt['post_options'];
913
+		}
860 914
 
861 915
 		echo '
862 916
 										<ul>';
863 917
 
864 918
 		// Can the user modify the contents of this post?
865
-		if ($message['can_modify'])
866
-			echo '
919
+		if ($message['can_modify']) {
920
+					echo '
867 921
 											<li><a href="', $scripturl, '?action=post;msg=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], '"><span class="generic_icons modify_button"></span>', $txt['modify'], '</a></li>';
922
+		}
868 923
 
869 924
 		// How about... even... remove it entirely?!
870
-		if ($context['can_delete'] && ($context['topic_first_message'] == $message['id']))
871
-			echo '
925
+		if ($context['can_delete'] && ($context['topic_first_message'] == $message['id'])) {
926
+					echo '
872 927
 											<li><a href="', $scripturl, '?action=removetopic2;topic=', $context['current_topic'], '.', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['are_sure_remove_topic'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove_topic'],'</a></li>';
873
-		elseif ($message['can_remove'] && ($context['topic_first_message'] != $message['id']))
874
-			echo '
928
+		} elseif ($message['can_remove'] && ($context['topic_first_message'] != $message['id'])) {
929
+					echo '
875 930
 											<li><a href="', $scripturl, '?action=deletemsg;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message_question'] ,'" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
931
+		}
876 932
 
877 933
 		// What about splitting it off the rest of the topic?
878
-		if ($context['can_split'] && !empty($context['real_num_replies']))
879
-			echo '
934
+		if ($context['can_split'] && !empty($context['real_num_replies'])) {
935
+					echo '
880 936
 											<li><a href="', $scripturl, '?action=splittopics;topic=', $context['current_topic'], '.0;at=', $message['id'], '"><span class="generic_icons split_button"></span>', $txt['split'], '</a></li>';
937
+		}
881 938
 
882 939
 		// Can we issue a warning because of this post? Remember, we can't give guests warnings.
883
-		if ($context['can_issue_warning'] && !$message['is_message_author'] && !$message['member']['is_guest'])
884
-			echo '
940
+		if ($context['can_issue_warning'] && !$message['is_message_author'] && !$message['member']['is_guest']) {
941
+					echo '
885 942
 											<li><a href="', $scripturl, '?action=profile;area=issuewarning;u=', $message['member']['id'], ';msg=', $message['id'], '"><span class="generic_icons warn_button"></span>', $txt['issue_warning'], '</a></li>';
943
+		}
886 944
 
887 945
 		// Can we restore topics?
888
-		if ($context['can_restore_msg'])
889
-			echo '
946
+		if ($context['can_restore_msg']) {
947
+					echo '
890 948
 											<li><a href="', $scripturl, '?action=restoretopic;msgs=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons restore_button"></span>', $txt['restore_message'], '</a></li>';
949
+		}
891 950
 
892 951
 		// Maybe we can approve it, maybe we should?
893
-		if ($message['can_approve'])
894
-			echo '
952
+		if ($message['can_approve']) {
953
+					echo '
895 954
 											<li><a href="', $scripturl, '?action=moderate;area=postmod;sa=approve;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons approve_button"></span>', $txt['approve'], '</a></li>';
955
+		}
896 956
 
897 957
 		// Maybe we can unapprove it?
898
-		if ($message['can_unapprove'])
899
-			echo '
958
+		if ($message['can_unapprove']) {
959
+					echo '
900 960
 											<li><a href="', $scripturl, '?action=moderate;area=postmod;sa=approve;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons unapprove_button"></span>', $txt['unapprove'], '</a></li>';
961
+		}
901 962
 
902 963
 		echo '
903 964
 										</ul>
904 965
 									</li>';
905 966
 
906 967
 		// Show a checkbox for quick moderation?
907
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove'])
908
-			echo '
968
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove']) {
969
+					echo '
909 970
 									<li style="display: none;" id="in_topic_mod_check_', $message['id'], '"></li>';
971
+		}
910 972
 
911
-		if ($message['can_approve'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'])
912
-			echo '
973
+		if ($message['can_approve'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg']) {
974
+					echo '
913 975
 								</ul>';
976
+		}
914 977
 	}
915 978
 
916
-	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote'])
917
-	echo '
979
+	if ($context['can_report_moderator'] || !empty($context['can_see_likes']) || !empty($context['can_like']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote']) {
980
+		echo '
918 981
 							</div>';
982
+	}
919 983
 
920 984
 	echo '
921 985
 						</div>
@@ -928,9 +992,10 @@  discard block
 block discarded – undo
928 992
 							<div class="custom_fields_above_signature">
929 993
 								<ul class="nolist">';
930 994
 
931
-		foreach ($message['custom_fields']['above_signature'] as $custom)
932
-			echo '
995
+		foreach ($message['custom_fields']['above_signature'] as $custom) {
996
+					echo '
933 997
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
998
+		}
934 999
 
935 1000
 		echo '
936 1001
 								</ul>
@@ -938,9 +1003,10 @@  discard block
 block discarded – undo
938 1003
 	}
939 1004
 
940 1005
 	// Show the member's signature?
941
-	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
942
-		echo '
1006
+	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled']) {
1007
+			echo '
943 1008
 							<div class="signature" id="msg_', $message['id'], '_signature"', $ignoring ? ' style="display:none;"' : '', '>', $message['member']['signature'], '</div>';
1009
+	}
944 1010
 
945 1011
 
946 1012
 	// Are there any custom profile fields for below the signature?
@@ -950,9 +1016,10 @@  discard block
 block discarded – undo
950 1016
 							<div class="custom_fields_below_signature">
951 1017
 								<ul class="nolist">';
952 1018
 
953
-		foreach ($message['custom_fields']['below_signature'] as $custom)
954
-			echo '
1019
+		foreach ($message['custom_fields']['below_signature'] as $custom) {
1020
+					echo '
955 1021
 									<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
1022
+		}
956 1023
 
957 1024
 		echo '
958 1025
 								</ul>
@@ -1000,8 +1067,8 @@  discard block
 block discarded – undo
1000 1067
 						<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">';
1001 1068
 
1002 1069
 		// Guests just need more.
1003
-		if ($context['user']['is_guest'])
1004
-			echo '
1070
+		if ($context['user']['is_guest']) {
1071
+					echo '
1005 1072
 						<dl id="post_header">
1006 1073
 							<dt>
1007 1074
 								', $txt['name'], ':
@@ -1016,6 +1083,7 @@  discard block
 block discarded – undo
1016 1083
 								<input type="email" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" class="input_text" required>
1017 1084
 							</dd>
1018 1085
 						</dl>';
1086
+		}
1019 1087
 
1020 1088
 		echo '
1021 1089
 						', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message'), '
@@ -1063,8 +1131,8 @@  discard block
 block discarded – undo
1063 1131
 		<br class="clear">';
1064 1132
 
1065 1133
 	// draft autosave available and the user has it enabled?
1066
-	if (!empty($context['drafts_autosave']))
1067
-		echo '
1134
+	if (!empty($context['drafts_autosave'])) {
1135
+			echo '
1068 1136
 			<script>
1069 1137
 				var oDraftAutoSave = new smf_DraftAutoSave({
1070 1138
 					sSelf: \'oDraftAutoSave\',
@@ -1076,10 +1144,12 @@  discard block
 block discarded – undo
1076 1144
 					iFreq: ', (empty($modSettings['masterAutoSaveDraftsDelay']) ? 60000 : $modSettings['masterAutoSaveDraftsDelay'] * 1000), '
1077 1145
 				});
1078 1146
 			</script>';
1147
+	}
1079 1148
 
1080
-	if ($context['show_spellchecking'])
1081
-		echo '
1149
+	if ($context['show_spellchecking']) {
1150
+			echo '
1082 1151
 			<form action="', $scripturl, '?action=spellcheck" method="post" accept-charset="', $context['character_set'], '" name="spell_form" id="spell_form" target="spellWindow"><input type="hidden" name="spellstring" value=""></form>';
1152
+	}
1083 1153
 
1084 1154
 	echo '
1085 1155
 				<script>
Please login to merge, or discard this patch.
Themes/default/Post.template.php 1 patch
Braces   +98 added lines, -67 removed lines patch added patch discarded remove patch
@@ -22,22 +22,24 @@  discard block
 block discarded – undo
22 22
 		<script>';
23 23
 
24 24
 	// When using Go Back due to fatal_error, allow the form to be re-submitted with changes.
25
-	if (isBrowser('is_firefox'))
26
-		echo '
25
+	if (isBrowser('is_firefox')) {
26
+			echo '
27 27
 			window.addEventListener("pageshow", reActivate, false);';
28
+	}
28 29
 
29 30
 	// Start with message icons - and any missing from this theme.
30 31
 	echo '
31 32
 			var icon_urls = {';
32
-	foreach ($context['icons'] as $icon)
33
-		echo '
33
+	foreach ($context['icons'] as $icon) {
34
+			echo '
34 35
 				\'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ',';
36
+	}
35 37
 	echo '
36 38
 			};';
37 39
 
38 40
 	// If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations.
39
-	if ($context['make_poll'])
40
-		echo '
41
+	if ($context['make_poll']) {
42
+			echo '
41 43
 			var pollOptionNum = 0, pollTabIndex;
42 44
 			var pollOptionId = ', $context['last_choice_id'], ';
43 45
 			function addPollOption()
@@ -56,11 +58,13 @@  discard block
 block discarded – undo
56 58
 
57 59
 				setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<dt><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>:</dt><dd><input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('" class="input_text"></dd><p id="pollMoreOptions"></p>'), ');
58 60
 			}';
61
+	}
59 62
 
60 63
 	// If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here.
61
-	if ($context['make_event'])
62
-		echo '
64
+	if ($context['make_event']) {
65
+			echo '
63 66
 			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];';
67
+	}
64 68
 
65 69
 	// End of the javascript, start the form and display the link tree.
66 70
 	echo '
@@ -80,9 +84,10 @@  discard block
 block discarded – undo
80 84
 				</div>
81 85
 			</div><br>';
82 86
 
83
-	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board'])))
84
-		echo '
87
+	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board']))) {
88
+			echo '
85 89
 			<input type="hidden" name="eventid" value="', $context['event']['id'], '">';
90
+	}
86 91
 
87 92
 	// Start the main table.
88 93
 	echo '
@@ -117,26 +122,28 @@  discard block
 block discarded – undo
117 122
 	}
118 123
 
119 124
 	// If it's locked, show a message to warn the replier.
120
-	if (!empty($context['locked']))
121
-	echo '
125
+	if (!empty($context['locked'])) {
126
+		echo '
122 127
 					<p class="errorbox">
123 128
 						', $txt['topic_locked_no_reply'], '
124 129
 					</p>';
130
+	}
125 131
 
126
-	if (!empty($modSettings['drafts_post_enabled']))
127
-		echo '
132
+	if (!empty($modSettings['drafts_post_enabled'])) {
133
+			echo '
128 134
 					<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
129 135
 						sprintf($txt['draft_saved'], $scripturl . '?action=profile;u=' . $context['user']['id'] . ';area=showdrafts'), '
130 136
 						', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
131 137
 					</div>';
138
+	}
132 139
 
133 140
 	// The post header... important stuff
134 141
 	echo '
135 142
 					<dl id="post_header">';
136 143
 
137 144
 	// Custom posting fields.
138
-	if (!empty($context['posting_fields']) && is_array($context['posting_fields']))
139
-		foreach ($context['posting_fields'] as $pf)
145
+	if (!empty($context['posting_fields']) && is_array($context['posting_fields'])) {
146
+			foreach ($context['posting_fields'] as $pf)
140 147
 			echo '
141 148
 						<dt>
142 149
 							', $pf['dt'] ,'
@@ -144,6 +151,7 @@  discard block
 block discarded – undo
144 151
 						<dd>
145 152
 							', $pf['dd'] ,'
146 153
 						</dd>';
154
+	}
147 155
 
148 156
 
149 157
 	// Guests have to put in their name and email...
@@ -157,14 +165,15 @@  discard block
 block discarded – undo
157 165
 							<input type="text" name="guestname" size="25" value="', $context['name'], '" tabindex="', $context['tabindex']++, '" class="input_text">
158 166
 						</dd>';
159 167
 
160
-		if (empty($modSettings['guest_post_no_email']))
161
-			echo '
168
+		if (empty($modSettings['guest_post_no_email'])) {
169
+					echo '
162 170
 						<dt>
163 171
 							<span', isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? ' class="error"' : '', ' id="caption_email">', $txt['email'], ':</span>
164 172
 						</dt>
165 173
 						<dd>
166 174
 							<input type="email" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" class="input_text" required>
167 175
 						</dd>';
176
+		}
168 177
 	}
169 178
 
170 179
 	// Now show the subject box for this post.
@@ -182,9 +191,10 @@  discard block
 block discarded – undo
182 191
 							<select name="icon" id="icon" onchange="showimage()">';
183 192
 
184 193
 	// Loop through each message icon allowed, adding it to the drop down list.
185
-	foreach ($context['icons'] as $icon)
186
-		echo '
194
+	foreach ($context['icons'] as $icon) {
195
+			echo '
187 196
 								<option value="', $icon['value'], '"', $icon['value'] == $context['icon'] ? ' selected' : '', '>', $icon['name'], '</option>';
197
+	}
188 198
 
189 199
 	echo '
190 200
 							</select>
@@ -219,9 +229,10 @@  discard block
 block discarded – undo
219 229
 				{
220 230
 					echo '
221 231
 										<optgroup label="', $category['name'], '">';
222
-					foreach ($category['boards'] as $board)
223
-						echo '
232
+					foreach ($category['boards'] as $board) {
233
+											echo '
224 234
 											<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
235
+					}
225 236
 					echo '
226 237
 										</optgroup>';
227 238
 				}
@@ -257,9 +268,10 @@  discard block
 block discarded – undo
257 268
 									<span class="label">', $txt['calendar_timezone'], '</span>
258 269
 									<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
259 270
 
260
-			foreach ($context['all_timezones'] as $tz => $tzname)
261
-				echo '
271
+			foreach ($context['all_timezones'] as $tz => $tzname) {
272
+							echo '
262 273
 										<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
274
+			}
263 275
 
264 276
 			echo '
265 277
 									</select>
@@ -325,14 +337,15 @@  discard block
 block discarded – undo
325 337
 									<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', ' class="input_check">
326 338
 								</dd>';
327 339
 
328
-		if ($context['poll_options']['guest_vote_enabled'])
329
-			echo '
340
+		if ($context['poll_options']['guest_vote_enabled']) {
341
+					echo '
330 342
 								<dt>
331 343
 									<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
332 344
 								</dt>
333 345
 								<dd>
334 346
 									<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked' : '', ' class="input_check">
335 347
 								</dd>';
348
+		}
336 349
 
337 350
 		echo '
338 351
 								<dt>
@@ -353,8 +366,8 @@  discard block
 block discarded – undo
353 366
 					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
354 367
 
355 368
 	// If we're editing and displaying edit details, show a box where they can say why
356
-	if (isset($context['editing']) && $modSettings['show_modify'])
357
-		echo '
369
+	if (isset($context['editing']) && $modSettings['show_modify']) {
370
+			echo '
358 371
 					<dl>
359 372
 						<dt class="clear">
360 373
 							<span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span>
@@ -363,20 +376,23 @@  discard block
 block discarded – undo
363 376
 							<input type="text" name="modify_reason"', isset($context['last_modified_reason']) ? ' value="' . $context['last_modified_reason'] . '"' : '', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text">
364 377
 						</dd>
365 378
 					</dl>';
379
+	}
366 380
 
367 381
 	// If this message has been edited in the past - display when it was.
368
-	if (isset($context['last_modified']))
369
-		echo '
382
+	if (isset($context['last_modified'])) {
383
+			echo '
370 384
 					<div class="padding smalltext">
371 385
 						', $context['last_modified_text'], '
372 386
 					</div>';
387
+	}
373 388
 
374 389
 	// If the admin has enabled the hiding of the additional options - show a link and image for it.
375
-	if (!empty($modSettings['additional_options_collapsable']))
376
-		echo '
390
+	if (!empty($modSettings['additional_options_collapsable'])) {
391
+			echo '
377 392
 					<div id="postAdditionalOptionsHeader">
378 393
 						<strong><a href="#" id="postMoreExpandLink"> ', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong>
379 394
 					</div>';
395
+	}
380 396
 
381 397
 	echo '
382 398
 					<div id="postAdditionalOptions">';
@@ -408,19 +424,21 @@  discard block
 block discarded – undo
408 424
 								<input type="hidden" name="attach_del[]" value="0">
409 425
 								', $txt['uncheck_unwatchd_attach'], ':
410 426
 							</dd>';
411
-		foreach ($context['current_attachments'] as $attachment)
412
-			echo '
427
+		foreach ($context['current_attachments'] as $attachment) {
428
+					echo '
413 429
 							<dd class="smalltext">
414 430
 								<label for="attachment_', $attachment['attachID'], '"><input type="checkbox" id="attachment_', $attachment['attachID'], '" name="attach_del[]" value="', $attachment['attachID'], '"', empty($attachment['unchecked']) ? ' checked' : '', ' class="input_check"> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''),
415 431
 								!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1028) / 1028), 0)) : '', '</label>
416 432
 							</dd>';
433
+		}
417 434
 
418 435
 		echo '
419 436
 						</dl>';
420 437
 
421
-		if (!empty($context['files_in_session_warning']))
422
-			echo '
438
+		if (!empty($context['files_in_session_warning'])) {
439
+					echo '
423 440
 						<div class="smalltext">', $context['files_in_session_warning'], '</div>';
441
+		}
424 442
 	}
425 443
 
426 444
 	// Is the user allowed to post any additional ones? If so give them the boxes to do it!
@@ -473,8 +491,8 @@  discard block
 block discarded – undo
473 491
 								', empty($modSettings['attachmentSizeLimit']) ? '' : ('<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1028 . '">');
474 492
 
475 493
 		// Show more boxes if they aren't approaching that limit.
476
-		if ($context['num_allowed_attachments'] > 1)
477
-			echo '
494
+		if ($context['num_allowed_attachments'] > 1) {
495
+					echo '
478 496
 										<script>
479 497
 											var allowed_attachments = ', $context['num_allowed_attachments'], ';
480 498
 											var current_attachment = 1;
@@ -495,9 +513,10 @@  discard block
 block discarded – undo
495 513
 									</div>
496 514
 								</div>
497 515
 							</dd>';
498
-		else
499
-			echo '
516
+		} else {
517
+					echo '
500 518
 							</dd>';
519
+		}
501 520
 
502 521
 		// Add any template changes for an alternative upload system here.
503 522
 		call_integration_hook('integrate_upload_template');
@@ -506,21 +525,25 @@  discard block
 block discarded – undo
506 525
 							<dd class="smalltext">';
507 526
 
508 527
 		// Show some useful information such as allowed extensions, maximum size and amount of attachments allowed.
509
-		if (!empty($modSettings['attachmentCheckExtensions']))
510
-			echo '
528
+		if (!empty($modSettings['attachmentCheckExtensions'])) {
529
+					echo '
511 530
 								', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br>';
531
+		}
512 532
 
513
-		if (!empty($context['attachment_restrictions']))
514
-			echo '
533
+		if (!empty($context['attachment_restrictions'])) {
534
+					echo '
515 535
 								', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br>';
536
+		}
516 537
 
517
-		if ($context['num_allowed_attachments'] == 0)
518
-			echo '
538
+		if ($context['num_allowed_attachments'] == 0) {
539
+					echo '
519 540
 								', $txt['attach_limit_nag'], '<br>';
541
+		}
520 542
 
521
-		if (!$context['can_post_attachment_unapproved'])
522
-			echo '
543
+		if (!$context['can_post_attachment_unapproved']) {
544
+					echo '
523 545
 								<span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br>';
546
+		}
524 547
 
525 548
 		echo '
526 549
 							</dd>
@@ -543,10 +566,11 @@  discard block
 block discarded – undo
543 566
 							<dt><strong>', $txt['subject'], '</strong></dt>
544 567
 							<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
545 568
 
546
-		foreach ($context['drafts'] as $draft)
547
-			echo '
569
+		foreach ($context['drafts'] as $draft) {
570
+					echo '
548 571
 							<dt>', $draft['link'], '</dt>
549 572
 							<dd>', $draft['poster_time'], '</dd>';
573
+		}
550 574
 		echo '
551 575
 						</dl>
552 576
 					</div>';
@@ -571,9 +595,10 @@  discard block
 block discarded – undo
571 595
 						', template_control_richedit_buttons($context['post_box_name']);
572 596
 
573 597
 	// Option to delete an event if user is editing one.
574
-	if ($context['make_event'] && !$context['event']['new'])
575
-		echo '
598
+	if ($context['make_event'] && !$context['event']['new']) {
599
+			echo '
576 600
 						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button_submit you_sure">';
601
+	}
577 602
 
578 603
 	echo '
579 604
 					</span>
@@ -582,9 +607,10 @@  discard block
 block discarded – undo
582 607
 			<br class="clear">';
583 608
 
584 609
 	// Assuming this isn't a new topic pass across the last message id.
585
-	if (isset($context['topic_last_message']))
586
-		echo '
610
+	if (isset($context['topic_last_message'])) {
611
+			echo '
587 612
 			<input type="hidden" name="last_msg" value="', $context['topic_last_message'], '">';
613
+	}
588 614
 
589 615
 	echo '
590 616
 			<input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '">
@@ -726,9 +752,10 @@  discard block
 block discarded – undo
726 752
 
727 753
 						newPostsHTML += \'<div class="windowbg\' + (++reply_counter % 2 == 0 ? \'2\' : \'\') + \'"><div id="msg\' + newPosts[i].getAttribute("id") + \'"><div class="floatleft"><h5>', $txt['posted_by'], ': \' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + \'</h5><span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> \' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue + \'&nbsp;&#187;</span> <span class="new_posts" id="image_new_\' + newPosts[i].getAttribute("id") + \'">', $txt['new'], '</span></div>\';';
728 754
 
729
-	if ($context['can_quote'])
730
-		echo '
755
+	if ($context['can_quote']) {
756
+			echo '
731 757
 						newPostsHTML += \'<ul class="quickbuttons" id="msg_\' + newPosts[i].getAttribute("id") + \'_quote"><li><a href="#postmodify" onclick="return insertQuoteFast(\\\'\' + newPosts[i].getAttribute("id") + \'\\\');" class="quote_button"><span>', $txt['quote'], '</span><\' + \'/a></li></ul>\';';
758
+	}
732 759
 
733 760
 	echo '
734 761
 						newPostsHTML += \'<br class="clear">\';
@@ -771,8 +798,8 @@  discard block
 block discarded – undo
771 798
 			}';
772 799
 
773 800
 	// Code for showing and hiding additional options.
774
-	if (!empty($modSettings['additional_options_collapsable']))
775
-		echo '
801
+	if (!empty($modSettings['additional_options_collapsable'])) {
802
+			echo '
776 803
 			var oSwapAdditionalOptions = new smc_Toggle({
777 804
 				bToggleEnabled: true,
778 805
 				bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ',
@@ -800,10 +827,11 @@  discard block
 block discarded – undo
800 827
 					}
801 828
 				]
802 829
 			});';
830
+	}
803 831
 
804 832
 	// Code for showing and hiding drafts
805
-	if (!empty($context['drafts']))
806
-		echo '
833
+	if (!empty($context['drafts'])) {
834
+			echo '
807 835
 			var oSwapDraftOptions = new smc_Toggle({
808 836
 				bToggleEnabled: true,
809 837
 				bCurrentlyCollapsed: true,
@@ -825,6 +853,7 @@  discard block
 block discarded – undo
825 853
 					}
826 854
 				]
827 855
 			});';
856
+	}
828 857
 
829 858
 	echo '
830 859
 			var oEditorID = "', $context['post_box_name'] ,'";
@@ -845,8 +874,9 @@  discard block
 block discarded – undo
845 874
 		foreach ($context['previous_posts'] as $post)
846 875
 		{
847 876
 			$ignoring = false;
848
-			if (!empty($post['is_ignored']))
849
-				$ignored_posts[] = $ignoring = $post['id'];
877
+			if (!empty($post['is_ignored'])) {
878
+							$ignored_posts[] = $ignoring = $post['id'];
879
+			}
850 880
 
851 881
 			echo '
852 882
 			<div class="windowbg">
@@ -1029,10 +1059,10 @@  discard block
 block discarded – undo
1029 1059
 		<div id="temporary_posting_area" style="display: none;"></div>
1030 1060
 		<script>';
1031 1061
 
1032
-	if ($context['close_window'])
1033
-		echo '
1062
+	if ($context['close_window']) {
1063
+			echo '
1034 1064
 			window.close();';
1035
-	else
1065
+	} else
1036 1066
 	{
1037 1067
 		// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;).
1038 1068
 		echo '
@@ -1086,11 +1116,12 @@  discard block
 block discarded – undo
1086 1116
 				</p>
1087 1117
 				<ul>';
1088 1118
 
1089
-	foreach ($context['groups'] as $group)
1090
-		echo '
1119
+	foreach ($context['groups'] as $group) {
1120
+			echo '
1091 1121
 					<li>
1092 1122
 						<label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked class="input_check"> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em>
1093 1123
 					</li>';
1124
+	}
1094 1125
 
1095 1126
 	echo '
1096 1127
 					<li>
Please login to merge, or discard this patch.
Sources/Calendar.php 1 patch
Braces   +105 added lines, -83 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Show the calendar.
@@ -47,12 +48,14 @@  discard block
 block discarded – undo
47 48
 		'post' => 'CalendarPost',
48 49
 	);
49 50
 
50
-	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']]))
51
-		return call_helper($subActions[$_GET['sa']]);
51
+	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']])) {
52
+			return call_helper($subActions[$_GET['sa']]);
53
+	}
52 54
 
53 55
 	// You can't do anything if the calendar is off.
54
-	if (empty($modSettings['cal_enabled']))
55
-		fatal_lang_error('calendar_off', false);
56
+	if (empty($modSettings['cal_enabled'])) {
57
+			fatal_lang_error('calendar_off', false);
58
+	}
56 59
 
57 60
 	// This is gonna be needed...
58 61
 	loadTemplate('Calendar');
@@ -97,8 +100,9 @@  discard block
 block discarded – undo
97 100
 	$context['view_week'] = isset($_GET['viewweek']);
98 101
 
99 102
 	// Don't let search engines index weekly calendar pages.
100
-	if ($context['view_week'])
101
-		$context['robot_no_index'] = true;
103
+	if ($context['view_week']) {
104
+			$context['robot_no_index'] = true;
105
+	}
102 106
 
103 107
 	// Get the current day of month...
104 108
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -112,17 +116,20 @@  discard block
 block discarded – undo
112 116
 	);
113 117
 
114 118
 	// Make sure the year and month are in valid ranges.
115
-	if ($curPage['month'] < 1 || $curPage['month'] > 12)
116
-		fatal_lang_error('invalid_month', false);
117
-	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear'])
118
-		fatal_lang_error('invalid_year', false);
119
+	if ($curPage['month'] < 1 || $curPage['month'] > 12) {
120
+			fatal_lang_error('invalid_month', false);
121
+	}
122
+	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) {
123
+			fatal_lang_error('invalid_year', false);
124
+	}
119 125
 	// If we have a day clean that too.
120 126
 	if ($context['view_week'])
121 127
 	{
122 128
 		// Note $isValid is -1 < PHP 5.1
123 129
 		$isValid = mktime(0, 0, 0, $curPage['month'], $curPage['day'], $curPage['year']);
124
-		if ($curPage['day'] > 31 || !$isValid || $isValid == -1)
125
-			fatal_lang_error('invalid_day', false);
130
+		if ($curPage['day'] > 31 || !$isValid || $isValid == -1) {
131
+					fatal_lang_error('invalid_day', false);
132
+		}
126 133
 	}
127 134
 
128 135
 	// Load all the context information needed to show the calendar grid.
@@ -144,21 +151,24 @@  discard block
 block discarded – undo
144 151
 	);
145 152
 
146 153
 	// Load up the main view.
147
-	if ($context['view_week'])
148
-		$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
149
-	else
150
-		$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154
+	if ($context['view_week']) {
155
+			$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
156
+	} else {
157
+			$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
158
+	}
151 159
 
152 160
 	// Load up the previous and next months.
153 161
 	$context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154 162
 
155 163
 	// Only show previous month if it isn't pre-January of the min-year
156
-	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1)
157
-		$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
164
+	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) {
165
+			$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
166
+	}
158 167
 
159 168
 	// Only show next month if it isn't post-December of the max-year
160
-	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12)
161
-		$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
169
+	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) {
170
+			$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
171
+	}
162 172
 
163 173
 	// Basic template stuff.
164 174
 	$context['allow_calendar_event'] = allowedTo('calendar_post');
@@ -191,17 +201,19 @@  discard block
 block discarded – undo
191 201
 		'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year']
192 202
 	);
193 203
 	// If applicable, add the current week to the linktree.
194
-	if ($context['view_week'])
195
-		$context['linktree'][] = array(
204
+	if ($context['view_week']) {
205
+			$context['linktree'][] = array(
196 206
 			'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'],
197 207
 			'name' => $context['calendar_grid_main']['week_title'],
198 208
 		);
209
+	}
199 210
 
200 211
 	// Build the calendar button array.
201 212
 	$context['calendar_buttons'] = array();
202 213
 
203
-	if ($context['can_post'])
204
-		$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
214
+	if ($context['can_post']) {
215
+			$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
216
+	}
205 217
 
206 218
 	// Allow mods to add additional buttons here
207 219
 	call_integration_hook('integrate_calendar_buttons');
@@ -230,14 +242,16 @@  discard block
 block discarded – undo
230 242
 	require_once($sourcedir . '/Subs.php');
231 243
 
232 244
 	// Cast this for safety...
233
-	if (isset($_REQUEST['eventid']))
234
-		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
245
+	if (isset($_REQUEST['eventid'])) {
246
+			$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
247
+	}
235 248
 
236 249
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
237
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
238
-		$time_string = '%k:%M';
239
-	else
240
-		$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
250
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
251
+			$time_string = '%k:%M';
252
+	} else {
253
+			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
254
+	}
241 255
 
242 256
 	$js_time_string = str_replace(
243 257
 		array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -251,12 +265,14 @@  discard block
 block discarded – undo
251 265
 		checkSession();
252 266
 
253 267
 		// Validate the post...
254
-		if (!isset($_POST['link_to_board']))
255
-			validateEventPost();
268
+		if (!isset($_POST['link_to_board'])) {
269
+					validateEventPost();
270
+		}
256 271
 
257 272
 		// If you're not allowed to edit any events, you have to be the poster.
258
-		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any'))
259
-			isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
273
+		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) {
274
+					isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
275
+		}
260 276
 
261 277
 		// New - and directing?
262 278
 		if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked']))
@@ -279,8 +295,9 @@  discard block
 block discarded – undo
279 295
 		}
280 296
 
281 297
 		// Deleting...
282
-		elseif (isset($_REQUEST['deleteevent']))
283
-			removeEvent($_REQUEST['eventid']);
298
+		elseif (isset($_REQUEST['deleteevent'])) {
299
+					removeEvent($_REQUEST['eventid']);
300
+		}
284 301
 
285 302
 		// ... or just update it?
286 303
 		else
@@ -302,14 +319,12 @@  discard block
 block discarded – undo
302 319
 			$d = date_parse($_POST['start_date']);
303 320
 			$year = $d['year'];
304 321
 			$month = $d['month'];
305
-		}
306
-		elseif (isset($_POST['start_datetime']))
322
+		} elseif (isset($_POST['start_datetime']))
307 323
 		{
308 324
 			$d = date_parse($_POST['start_datetime']);
309 325
 			$year = $d['year'];
310 326
 			$month = $d['month'];
311
-		}
312
-		else
327
+		} else
313 328
 		{
314 329
 			$today = getdate();
315 330
 			$year = isset($_POST['year']) ? $_POST['year'] : $today['year'];
@@ -342,13 +357,13 @@  discard block
 block discarded – undo
342 357
 		$context['event'] = array_merge($context['event'], $eventDatetimes);
343 358
 
344 359
 		$context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
345
-	}
346
-	else
360
+	} else
347 361
 	{
348 362
 		$context['event'] = getEventProperties($_REQUEST['eventid']);
349 363
 
350
-		if ($context['event'] === false)
351
-			fatal_lang_error('no_access', false);
364
+		if ($context['event'] === false) {
365
+					fatal_lang_error('no_access', false);
366
+		}
352 367
 
353 368
 		// If it has a board, then they should be editing it within the topic.
354 369
 		if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg']))
@@ -359,10 +374,11 @@  discard block
 block discarded – undo
359 374
 		}
360 375
 
361 376
 		// Make sure the user is allowed to edit this event.
362
-		if ($context['event']['member'] != $user_info['id'])
363
-			isAllowedTo('calendar_edit_any');
364
-		elseif (!allowedTo('calendar_edit_any'))
365
-			isAllowedTo('calendar_edit_own');
377
+		if ($context['event']['member'] != $user_info['id']) {
378
+					isAllowedTo('calendar_edit_any');
379
+		} elseif (!allowedTo('calendar_edit_any')) {
380
+					isAllowedTo('calendar_edit_own');
381
+		}
366 382
 	}
367 383
 
368 384
 	// An all day event? Set up some nice defaults in case the user wants to change that
@@ -396,8 +412,7 @@  discard block
 block discarded – undo
396 412
 	{
397 413
 		// You can post new events but can't link them to anything...
398 414
 		$context['event']['categories'] = array();
399
-	}
400
-	else
415
+	} else
401 416
 	{
402 417
 		// Load the list of boards and categories in the context.
403 418
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -484,12 +499,14 @@  discard block
 block discarded – undo
484 499
 	global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname;
485 500
 
486 501
 	// You can't export if the calendar export feature is off.
487
-	if (empty($modSettings['cal_export']))
488
-		fatal_lang_error('calendar_export_off', false);
502
+	if (empty($modSettings['cal_export'])) {
503
+			fatal_lang_error('calendar_export_off', false);
504
+	}
489 505
 
490 506
 	// Goes without saying that this is required.
491
-	if (!isset($_REQUEST['eventid']))
492
-		fatal_lang_error('no_access', false);
507
+	if (!isset($_REQUEST['eventid'])) {
508
+			fatal_lang_error('no_access', false);
509
+	}
493 510
 
494 511
 	// This is kinda wanted.
495 512
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -497,15 +514,17 @@  discard block
 block discarded – undo
497 514
 	// Load up the event in question and check it exists.
498 515
 	$event = getEventProperties($_REQUEST['eventid']);
499 516
 
500
-	if ($event === false)
501
-		fatal_lang_error('no_access', false);
517
+	if ($event === false) {
518
+			fatal_lang_error('no_access', false);
519
+	}
502 520
 
503 521
 	// Check the title isn't too long - iCal requires some formatting if so.
504 522
 	$title = str_split($event['title'], 30);
505 523
 	foreach ($title as $id => $line)
506 524
 	{
507
-		if ($id != 0)
508
-			$title[$id] = ' ' . $title[$id];
525
+		if ($id != 0) {
526
+					$title[$id] = ' ' . $title[$id];
527
+		}
509 528
 		$title[$id] .= "\n";
510 529
 	}
511 530
 
@@ -518,8 +537,7 @@  discard block
 block discarded – undo
518 537
 	{
519 538
 		$datestart = date_format($start_date, 'Ymd\THis');
520 539
 		$dateend = date_format($end_date, 'Ymd\THis');
521
-	}
522
-	else
540
+	} else
523 541
 	{
524 542
 		$datestart = date_format($start_date, 'Ymd');
525 543
 
@@ -540,15 +558,18 @@  discard block
 block discarded – undo
540 558
 	$filecontents .= 'DTSTART' . (!empty($event['start_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $datestart . "\n";
541 559
 
542 560
 	// event has a duration
543
-	if ($event['start_iso_gmdate'] != $event['end_iso_gmdate'])
544
-		$filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n";
561
+	if ($event['start_iso_gmdate'] != $event['end_iso_gmdate']) {
562
+			$filecontents .= 'DTEND' . (!empty($event['end_time']) ? ';TZID=' . $event['tz'] : ';VALUE=DATE') . ':' . $dateend . "\n";
563
+	}
545 564
 
546 565
 	// event has changed? advance the sequence for this UID
547
-	if ($event['sequence'] > 0)
548
-		$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
566
+	if ($event['sequence'] > 0) {
567
+			$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
568
+	}
549 569
 
550
-	if (!empty($event['location']))
551
-		$filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n";
570
+	if (!empty($event['location'])) {
571
+			$filecontents .= 'LOCATION:' . str_replace(',', '\,', $event['location']) . "\n";
572
+	}
552 573
 
553 574
 	$filecontents .= 'SUMMARY:' . implode('', $title);
554 575
 	$filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n";
@@ -557,23 +578,26 @@  discard block
 block discarded – undo
557 578
 
558 579
 	// Send some standard headers.
559 580
 	ob_end_clean();
560
-	if (!empty($modSettings['enableCompressedOutput']))
561
-		@ob_start('ob_gzhandler');
562
-	else
563
-		ob_start();
581
+	if (!empty($modSettings['enableCompressedOutput'])) {
582
+			@ob_start('ob_gzhandler');
583
+	} else {
584
+			ob_start();
585
+	}
564 586
 
565 587
 	// Send the file headers
566 588
 	header('Pragma: ');
567 589
 	header('Cache-Control: no-cache');
568
-	if (!isBrowser('gecko'))
569
-		header('Content-Transfer-Encoding: binary');
590
+	if (!isBrowser('gecko')) {
591
+			header('Content-Transfer-Encoding: binary');
592
+	}
570 593
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
571 594
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT');
572 595
 	header('Accept-Ranges: bytes');
573 596
 	header('Connection: close');
574 597
 	header('Content-Disposition: attachment; filename="' . $event['title'] . '.ics"');
575
-	if (empty($modSettings['enableCompressedOutput']))
576
-		header('Content-Length: ' . $smcFunc['strlen']($filecontents));
598
+	if (empty($modSettings['enableCompressedOutput'])) {
599
+			header('Content-Length: ' . $smcFunc['strlen']($filecontents));
600
+	}
577 601
 
578 602
 	// This is a calendar item!
579 603
 	header('Content-Type: text/calendar');
@@ -612,20 +636,17 @@  discard block
 block discarded – undo
612 636
 		$context['sub_template'] = 'bcd';
613 637
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD');
614 638
 		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjI6ImgxIjthOjI6e2k6MDtpOjI7aToxO2k6MTt9czoyOiJoMiI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjI6Im0xIjthOjM6e2k6MDtpOjQ7aToxO2k6MjtpOjI7aToxO31zOjI6Im0yIjthOjQ6e2k6MDtpOjg7aToxO2k6NDtpOjI7aToyO2k6MztpOjE7fXM6MjoiczEiO2E6Mzp7aTowO2k6NDtpOjE7aToyO2k6MjtpOjE7fXM6MjoiczIiO2E6NDp7aTowO2k6ODtpOjE7aTo0O2k6MjtpOjI7aTozO2k6MTt9fQ=='));
615
-	}
616
-	elseif (!$omfg && !isset($_REQUEST['time']))
639
+	} elseif (!$omfg && !isset($_REQUEST['time']))
617 640
 	{
618 641
 		$context['sub_template'] = 'hms';
619 642
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary');
620 643
 		$context['clockicons'] = safe_unserialize(base64_decode('YTozOntzOjE6ImgiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czoxOiJtIjthOjY6e2k6MDtpOjMyO2k6MTtpOjE2O2k6MjtpOjg7aTozO2k6NDtpOjQ7aToyO2k6NTtpOjE7fXM6MToicyI7YTo2OntpOjA7aTozMjtpOjE7aToxNjtpOjI7aTo4O2k6MztpOjQ7aTo0O2k6MjtpOjU7aToxO319'));
621
-	}
622
-	elseif ($omfg)
644
+	} elseif ($omfg)
623 645
 	{
624 646
 		$context['sub_template'] = 'omfg';
625 647
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG');
626 648
 		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjQ6InllYXIiO2E6Nzp7aTowO2k6NjQ7aToxO2k6MzI7aToyO2k6MTY7aTozO2k6ODtpOjQ7aTo0O2k6NTtpOjI7aTo2O2k6MTt9czo1OiJtb250aCI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjM6ImRheSI7YTo1OntpOjA7aToxNjtpOjE7aTo4O2k6MjtpOjQ7aTozO2k6MjtpOjQ7aToxO31zOjQ6ImhvdXIiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czozOiJtaW4iO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9czozOiJzZWMiO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9fQ=='));
627
-	}
628
-	elseif (isset($_REQUEST['time']))
649
+	} elseif (isset($_REQUEST['time']))
629 650
 	{
630 651
 		$context['sub_template'] = 'thetime';
631 652
 		$time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']);
@@ -685,12 +706,13 @@  discard block
 block discarded – undo
685 706
 			),
686 707
 		);
687 708
 
688
-		foreach ($context['clockicons'] as $t => $vs)
689
-			foreach ($vs as $v => $dumb)
709
+		foreach ($context['clockicons'] as $t => $vs) {
710
+					foreach ($vs as $v => $dumb)
690 711
 			{
691 712
 				if ($$t >= $v)
692 713
 				{
693 714
 					$$t -= $v;
715
+		}
694 716
 					$context['clockicons'][$t][$v] = true;
695 717
 				}
696 718
 			}
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +230 added lines, -168 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query' => 'smf_db_query',
39 40
 			'db_quote' => 'smf_db_quote',
40 41
 			'db_fetch_assoc' => 'mysql_fetch_assoc',
@@ -58,36 +59,42 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource' => 'is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['port']))
63
-		$db_server .= ':' . $db_options['port'];
64
+	if (!empty($db_options['port'])) {
65
+			$db_server .= ':' . $db_options['port'];
66
+	}
64 67
 	
65 68
 	$flags = 2; //#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
66 69
 
67
-	if (!empty($db_options['persist']))
68
-		$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
69
-	else
70
-		$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
70
+	if (!empty($db_options['persist'])) {
71
+			$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
72
+	} else {
73
+			$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
74
+	}
71 75
 
72 76
 	// Something's wrong, show an error if its fatal (which we assume it is)
73 77
 	if (!$connection)
74 78
 	{
75
-		if (!empty($db_options['non_fatal']))
76
-			return null;
77
-		else
78
-			display_db_error();
79
+		if (!empty($db_options['non_fatal'])) {
80
+					return null;
81
+		} else {
82
+					display_db_error();
83
+		}
79 84
 	}
80 85
 
81 86
 	// Select the database, unless told not to
82
-	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal']))
83
-		display_db_error();
87
+	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) {
88
+			display_db_error();
89
+	}
84 90
 
85 91
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
86
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
87
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
92
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
93
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
88 94
 		array(),
89 95
 		false
90 96
 	);
97
+	}
91 98
 
92 99
 	return $connection;
93 100
 }
@@ -134,37 +141,46 @@  discard block
 block discarded – undo
134 141
 	list ($values, $connection) = $db_callback;
135 142
 
136 143
 	// Connection gone???  This should *never* happen at this point, yet it does :'(
137
-	if (!is_resource($connection))
138
-		display_db_error();
144
+	if (!is_resource($connection)) {
145
+			display_db_error();
146
+	}
139 147
 
140
-	if ($matches[1] === 'db_prefix')
141
-		return $db_prefix;
148
+	if ($matches[1] === 'db_prefix') {
149
+			return $db_prefix;
150
+	}
142 151
 
143
-	if ($matches[1] === 'query_see_board')
144
-		return $user_info['query_see_board'];
152
+	if ($matches[1] === 'query_see_board') {
153
+			return $user_info['query_see_board'];
154
+	}
145 155
 
146
-	if ($matches[1] === 'query_wanna_see_board')
147
-		return $user_info['query_wanna_see_board'];
156
+	if ($matches[1] === 'query_wanna_see_board') {
157
+			return $user_info['query_wanna_see_board'];
158
+	}
148 159
 
149
-	if ($matches[1] === 'empty')
150
-		return '\'\'';
160
+	if ($matches[1] === 'empty') {
161
+			return '\'\'';
162
+	}
151 163
 
152
-	if (!isset($matches[2]))
153
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
164
+	if (!isset($matches[2])) {
165
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
166
+	}
154 167
 
155
-	if ($matches[1] === 'literal')
156
-		return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
168
+	if ($matches[1] === 'literal') {
169
+			return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
170
+	}
157 171
 
158
-	if (!isset($values[$matches[2]]))
159
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
172
+	if (!isset($values[$matches[2]])) {
173
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
174
+	}
160 175
 
161 176
 	$replacement = $values[$matches[2]];
162 177
 
163 178
 	switch ($matches[1])
164 179
 	{
165 180
 		case 'int':
166
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
167
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
182
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+			}
168 184
 			return (string) (int) $replacement;
169 185
 		break;
170 186
 
@@ -176,56 +192,63 @@  discard block
 block discarded – undo
176 192
 		case 'array_int':
177 193
 			if (is_array($replacement))
178 194
 			{
179
-				if (empty($replacement))
180
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195
+				if (empty($replacement)) {
196
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
197
+				}
181 198
 
182 199
 				foreach ($replacement as $key => $value)
183 200
 				{
184
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
185
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
201
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
202
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
203
+					}
186 204
 
187 205
 					$replacement[$key] = (string) (int) $value;
188 206
 				}
189 207
 
190 208
 				return implode(', ', $replacement);
209
+			} else {
210
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
191 211
 			}
192
-			else
193
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
194 212
 
195 213
 		break;
196 214
 
197 215
 		case 'array_string':
198 216
 			if (is_array($replacement))
199 217
 			{
200
-				if (empty($replacement))
201
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+				if (empty($replacement)) {
219
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				}
202 221
 
203
-				foreach ($replacement as $key => $value)
204
-					$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
222
+				foreach ($replacement as $key => $value) {
223
+									$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
224
+				}
205 225
 
206 226
 				return implode(', ', $replacement);
227
+			} else {
228
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
207 229
 			}
208
-			else
209
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210 230
 		break;
211 231
 
212 232
 		case 'date':
213
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
214
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
-			else
216
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
234
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			}
217 238
 		break;
218 239
 
219 240
 		case 'time':
220
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
221
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
242
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
243
+			} else {
244
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+			}
224 246
 		break;
225 247
 
226 248
 		case 'float':
227
-			if (!is_numeric($replacement))
228
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+			if (!is_numeric($replacement)) {
250
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
251
+			}
229 252
 			return (string) (float) $replacement;
230 253
 		break;
231 254
 
@@ -239,32 +262,37 @@  discard block
 block discarded – undo
239 262
 		break;
240 263
 
241 264
 		case 'inet':
242
-			if ($replacement == 'null' || $replacement == '')
243
-				return 'null';
244
-			if (!isValidIP($replacement))
245
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			if ($replacement == 'null' || $replacement == '') {
266
+							return 'null';
267
+			}
268
+			if (!isValidIP($replacement)) {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
246 271
 			//we don't use the native support of mysql > 5.6.2
247 272
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
248 273
 
249 274
 		case 'array_inet':
250 275
 			if (is_array($replacement))
251 276
 			{
252
-				if (empty($replacement))
253
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+				if (empty($replacement)) {
278
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+				}
254 280
 
255 281
 				foreach ($replacement as $key => $value)
256 282
 				{
257
-					if ($replacement == 'null' || $replacement == '')
258
-						$replacement[$key] = 'null';
259
-					if (!isValidIP($value))
260
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
283
+					if ($replacement == 'null' || $replacement == '') {
284
+											$replacement[$key] = 'null';
285
+					}
286
+					if (!isValidIP($value)) {
287
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+					}
261 289
 					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
262 290
 				}
263 291
 
264 292
 				return implode(', ', $replacement);
293
+			} else {
294
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265 295
 			}
266
-			else
267
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268 296
 		break;
269 297
 
270 298
 		default:
@@ -335,18 +363,20 @@  discard block
 block discarded – undo
335 363
 	// One more query....
336 364
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
337 365
 
338
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
339
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
366
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
367
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
368
+	}
340 369
 
341 370
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
342 371
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
343 372
 	{
344 373
 		// Add before LIMIT
345
-		if ($pos = strpos($db_string, 'LIMIT '))
346
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
347
-		else
348
-			// Append it.
374
+		if ($pos = strpos($db_string, 'LIMIT ')) {
375
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
376
+		} else {
377
+					// Append it.
349 378
 			$db_string .= "\n\t\t\tORDER BY null";
379
+		}
350 380
 	}
351 381
 
352 382
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -368,8 +398,9 @@  discard block
 block discarded – undo
368 398
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
369 399
 
370 400
 		// Initialize $db_cache if not already initialized.
371
-		if (!isset($db_cache))
372
-			$db_cache = array();
401
+		if (!isset($db_cache)) {
402
+					$db_cache = array();
403
+		}
373 404
 
374 405
 		if (!empty($_SESSION['debug_redirect']))
375 406
 		{
@@ -395,17 +426,18 @@  discard block
 block discarded – undo
395 426
 		while (true)
396 427
 		{
397 428
 			$pos = strpos($db_string, '\'', $pos + 1);
398
-			if ($pos === false)
399
-				break;
429
+			if ($pos === false) {
430
+							break;
431
+			}
400 432
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
401 433
 
402 434
 			while (true)
403 435
 			{
404 436
 				$pos1 = strpos($db_string, '\'', $pos + 1);
405 437
 				$pos2 = strpos($db_string, '\\', $pos + 1);
406
-				if ($pos1 === false)
407
-					break;
408
-				elseif ($pos2 === false || $pos2 > $pos1)
438
+				if ($pos1 === false) {
439
+									break;
440
+				} elseif ($pos2 === false || $pos2 > $pos1)
409 441
 				{
410 442
 					$pos = $pos1;
411 443
 					break;
@@ -421,29 +453,35 @@  discard block
 block discarded – undo
421 453
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
422 454
 
423 455
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
424
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
425
-			$fail = true;
456
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
457
+					$fail = true;
458
+		}
426 459
 		// Trying to change passwords, slow us down, or something?
427
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
428
-			$fail = true;
429
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
430
-			$fail = true;
460
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
461
+					$fail = true;
462
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
463
+					$fail = true;
464
+		}
431 465
 
432
-		if (!empty($fail) && function_exists('log_error'))
433
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
466
+		if (!empty($fail) && function_exists('log_error')) {
467
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
468
+		}
434 469
 	}
435 470
 
436
-	if (empty($db_unbuffered))
437
-		$ret = @mysql_query($db_string, $connection);
438
-	else
439
-		$ret = @mysql_unbuffered_query($db_string, $connection);
471
+	if (empty($db_unbuffered)) {
472
+			$ret = @mysql_query($db_string, $connection);
473
+	} else {
474
+			$ret = @mysql_unbuffered_query($db_string, $connection);
475
+	}
440 476
 
441
-	if ($ret === false && empty($db_values['db_error_skip']))
442
-		$ret = smf_db_error($db_string, $connection);
477
+	if ($ret === false && empty($db_values['db_error_skip'])) {
478
+			$ret = smf_db_error($db_string, $connection);
479
+	}
443 480
 
444 481
 	// Debugging.
445
-	if (isset($db_show_debug) && $db_show_debug === true)
446
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
482
+	if (isset($db_show_debug) && $db_show_debug === true) {
483
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
484
+	}
447 485
 
448 486
 	return $ret;
449 487
 }
@@ -492,12 +530,13 @@  discard block
 block discarded – undo
492 530
 	// Decide which connection to use
493 531
 	$connection = $connection === null ? $db_connection : $connection;
494 532
 
495
-	if ($type == 'begin')
496
-		return @mysql_query('BEGIN', $connection);
497
-	elseif ($type == 'rollback')
498
-		return @mysql_query('ROLLBACK', $connection);
499
-	elseif ($type == 'commit')
500
-		return @mysql_query('COMMIT', $connection);
533
+	if ($type == 'begin') {
534
+			return @mysql_query('BEGIN', $connection);
535
+	} elseif ($type == 'rollback') {
536
+			return @mysql_query('ROLLBACK', $connection);
537
+	} elseif ($type == 'commit') {
538
+			return @mysql_query('COMMIT', $connection);
539
+	}
501 540
 
502 541
 	return false;
503 542
 }
@@ -537,8 +576,9 @@  discard block
 block discarded – undo
537 576
 	//    2013: Lost connection to server during query.
538 577
 
539 578
 	// Log the error.
540
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
541
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
579
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
580
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
581
+	}
542 582
 
543 583
 	// Database error auto fixing ;).
544 584
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -547,8 +587,9 @@  discard block
 block discarded – undo
547 587
 		$old_cache = @$modSettings['cache_enable'];
548 588
 		$modSettings['cache_enable'] = '1';
549 589
 
550
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
551
-			$db_last_error = max(@$db_last_error, $temp);
590
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
591
+					$db_last_error = max(@$db_last_error, $temp);
592
+		}
552 593
 
553 594
 		if (@$db_last_error < time() - 3600 * 24 * 3)
554 595
 		{
@@ -564,8 +605,9 @@  discard block
 block discarded – undo
564 605
 					foreach ($tables as $table)
565 606
 					{
566 607
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
567
-						if (trim($table) != '')
568
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
608
+						if (trim($table) != '') {
609
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
610
+						}
569 611
 					}
570 612
 				}
571 613
 
@@ -574,8 +616,9 @@  discard block
 block discarded – undo
574 616
 			// Table crashed.  Let's try to fix it.
575 617
 			elseif ($query_errno == 1016)
576 618
 			{
577
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
578
-					$fix_tables = array('`' . $match[1] . '`');
619
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
620
+									$fix_tables = array('`' . $match[1] . '`');
621
+				}
579 622
 			}
580 623
 			// Indexes crashed.  Should be easy to fix!
581 624
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -594,13 +637,15 @@  discard block
 block discarded – undo
594 637
 
595 638
 			// Make a note of the REPAIR...
596 639
 			cache_put_data('db_last_error', time(), 600);
597
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
598
-				updateSettingsFile(array('db_last_error' => time()));
640
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
641
+							updateSettingsFile(array('db_last_error' => time()));
642
+			}
599 643
 
600 644
 			// Attempt to find and repair the broken table.
601
-			foreach ($fix_tables as $table)
602
-				$smcFunc['db_query']('', "
645
+			foreach ($fix_tables as $table) {
646
+							$smcFunc['db_query']('', "
603 647
 					REPAIR TABLE $table", false, false);
648
+			}
604 649
 
605 650
 			// And send off an email!
606 651
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -609,11 +654,12 @@  discard block
 block discarded – undo
609 654
 
610 655
 			// Try the query again...?
611 656
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
612
-			if ($ret !== false)
613
-				return $ret;
657
+			if ($ret !== false) {
658
+							return $ret;
659
+			}
660
+		} else {
661
+					$modSettings['cache_enable'] = $old_cache;
614 662
 		}
615
-		else
616
-			$modSettings['cache_enable'] = $old_cache;
617 663
 
618 664
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
619 665
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -623,22 +669,25 @@  discard block
 block discarded – undo
623 669
 				// Are we in SSI mode?  If so try that username and password first
624 670
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
625 671
 				{
626
-					if (empty($db_persist))
627
-						$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
628
-					else
629
-						$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
672
+					if (empty($db_persist)) {
673
+											$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
674
+					} else {
675
+											$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
676
+					}
630 677
 				}
631 678
 				// Fall back to the regular username and password if need be
632 679
 				if (!$db_connection)
633 680
 				{
634
-					if (empty($db_persist))
635
-						$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
636
-					else
637
-						$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
681
+					if (empty($db_persist)) {
682
+											$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
683
+					} else {
684
+											$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
685
+					}
638 686
 				}
639 687
 
640
-				if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
641
-					$db_connection = false;
688
+				if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) {
689
+									$db_connection = false;
690
+				}
642 691
 			}
643 692
 
644 693
 			if ($db_connection)
@@ -649,24 +698,27 @@  discard block
 block discarded – undo
649 698
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
650 699
 
651 700
 					$new_errno = mysql_errno($db_connection);
652
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
653
-						break;
701
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
702
+											break;
703
+					}
654 704
 				}
655 705
 
656 706
 				// If it failed again, shucks to be you... we're not trying it over and over.
657
-				if ($ret !== false)
658
-					return $ret;
707
+				if ($ret !== false) {
708
+									return $ret;
709
+				}
659 710
 			}
660 711
 		}
661 712
 		// Are they out of space, perhaps?
662 713
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
663 714
 		{
664
-			if (!isset($txt))
665
-				$query_error .= ' - check database storage space.';
666
-			else
715
+			if (!isset($txt)) {
716
+							$query_error .= ' - check database storage space.';
717
+			} else
667 718
 			{
668
-				if (!isset($txt['mysql_error_space']))
669
-					loadLanguage('Errors');
719
+				if (!isset($txt['mysql_error_space'])) {
720
+									loadLanguage('Errors');
721
+				}
670 722
 
671 723
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
672 724
 			}
@@ -674,15 +726,17 @@  discard block
 block discarded – undo
674 726
 	}
675 727
 
676 728
 	// Nothing's defined yet... just die with it.
677
-	if (empty($context) || empty($txt))
678
-		die($query_error);
729
+	if (empty($context) || empty($txt)) {
730
+			die($query_error);
731
+	}
679 732
 
680 733
 	// Show an error message, if possible.
681 734
 	$context['error_title'] = $txt['database_error'];
682
-	if (allowedTo('admin_forum'))
683
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
684
-	else
685
-		$context['error_message'] = $txt['try_again'];
735
+	if (allowedTo('admin_forum')) {
736
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
737
+	} else {
738
+			$context['error_message'] = $txt['try_again'];
739
+	}
686 740
 
687 741
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
688 742
 	{
@@ -711,25 +765,28 @@  discard block
 block discarded – undo
711 765
 	$connection = $connection === null ? $db_connection : $connection;
712 766
 
713 767
 	// With nothing to insert, simply return.
714
-	if (empty($data))
715
-		return;
768
+	if (empty($data)) {
769
+			return;
770
+	}
716 771
 
717 772
 	// Replace the prefix holder with the actual prefix.
718 773
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
719 774
 
720 775
 	// Inserting data as a single row can be done as a single array.
721
-	if (!is_array($data[array_rand($data)]))
722
-		$data = array($data);
776
+	if (!is_array($data[array_rand($data)])) {
777
+			$data = array($data);
778
+	}
723 779
 
724 780
 	// Create the mold for a single row insert.
725 781
 	$insertData = '(';
726 782
 	foreach ($columns as $columnName => $type)
727 783
 	{
728 784
 		// Are we restricting the length?
729
-		if (strpos($type, 'string-') !== false)
730
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
731
-		else
732
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
785
+		if (strpos($type, 'string-') !== false) {
786
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
787
+		} else {
788
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
789
+		}
733 790
 	}
734 791
 	$insertData = substr($insertData, 0, -2) . ')';
735 792
 
@@ -738,8 +795,9 @@  discard block
 block discarded – undo
738 795
 
739 796
 	// Here's where the variables are injected to the query.
740 797
 	$insertRows = array();
741
-	foreach ($data as $dataRow)
742
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
798
+	foreach ($data as $dataRow) {
799
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
800
+	}
743 801
 
744 802
 	// Determine the method of insertion.
745 803
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -770,8 +828,9 @@  discard block
 block discarded – undo
770 828
  */
771 829
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
772 830
 {
773
-	if (empty($log_message))
774
-		$log_message = $error_message;
831
+	if (empty($log_message)) {
832
+			$log_message = $error_message;
833
+	}
775 834
 
776 835
 	foreach (debug_backtrace() as $step)
777 836
 	{
@@ -790,12 +849,14 @@  discard block
 block discarded – undo
790 849
 	}
791 850
 
792 851
 	// A special case - we want the file and line numbers for debugging.
793
-	if ($error_type == 'return')
794
-		return array($file, $line);
852
+	if ($error_type == 'return') {
853
+			return array($file, $line);
854
+	}
795 855
 
796 856
 	// Is always a critical error.
797
-	if (function_exists('log_error'))
798
-		log_error($log_message, 'critical', $file, $line);
857
+	if (function_exists('log_error')) {
858
+			log_error($log_message, 'critical', $file, $line);
859
+	}
799 860
 
800 861
 	if (function_exists('fatal_error'))
801 862
 	{
@@ -803,12 +864,12 @@  discard block
 block discarded – undo
803 864
 
804 865
 		// Cannot continue...
805 866
 		exit;
867
+	} elseif ($error_type) {
868
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
869
+	} else {
870
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
871
+	}
806 872
 	}
807
-	elseif ($error_type)
808
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
809
-	else
810
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
811
-}
812 873
 
813 874
 /**
814 875
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -825,10 +886,11 @@  discard block
 block discarded – undo
825 886
 		'\\' => '\\\\',
826 887
 	);
827 888
 
828
-	if ($translate_human_wildcards)
829
-		$replacements += array(
889
+	if ($translate_human_wildcards) {
890
+			$replacements += array(
830 891
 			'*' => '%',
831 892
 		);
893
+	}
832 894
 
833 895
 	return strtr($string, $replacements);
834 896
 }
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1277 added lines, -949 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * 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,14 +572,17 @@  discard block
 block discarded – undo
555 572
 	$start_invalid = $start < 0;
556 573
 
557 574
 	// Make sure $start is a proper variable - not less than 0.
558
-	if ($start_invalid)
559
-		$start = 0;
575
+	if ($start_invalid) {
576
+			$start = 0;
577
+	}
560 578
 	// Not greater than the upper bound.
561
-	elseif ($start >= $max_value)
562
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
579
+	elseif ($start >= $max_value) {
580
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
581
+	}
563 582
 	// And it has to be a multiple of $num_per_page!
564
-	else
565
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
583
+	else {
584
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
585
+	}
566 586
 
567 587
 	$context['current_page'] = $start / $num_per_page;
568 588
 
@@ -592,77 +612,87 @@  discard block
 block discarded – undo
592 612
 
593 613
 		// Show all the pages.
594 614
 		$display_page = 1;
595
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
596
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
615
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
616
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
617
+		}
597 618
 
598 619
 		// Show the right arrow.
599 620
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
600
-		if ($start != $counter - $max_value && !$start_invalid)
601
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
602
-	}
603
-	else
621
+		if ($start != $counter - $max_value && !$start_invalid) {
622
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
623
+		}
624
+	} else
604 625
 	{
605 626
 		// If they didn't enter an odd value, pretend they did.
606 627
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
607 628
 
608 629
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
609
-		if (!empty($start) && $show_prevnext)
610
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
611
-		else
612
-			$pageindex .= '';
630
+		if (!empty($start) && $show_prevnext) {
631
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
632
+		} else {
633
+					$pageindex .= '';
634
+		}
613 635
 
614 636
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
615
-		if ($start > $num_per_page * $PageContiguous)
616
-			$pageindex .= sprintf($base_link, 0, '1');
637
+		if ($start > $num_per_page * $PageContiguous) {
638
+					$pageindex .= sprintf($base_link, 0, '1');
639
+		}
617 640
 
618 641
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
619
-		if ($start > $num_per_page * ($PageContiguous + 1))
620
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
642
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
643
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
621 644
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
622 645
 				'{FIRST_PAGE}' => $num_per_page,
623 646
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
624 647
 				'{PER_PAGE}' => $num_per_page,
625 648
 			));
649
+		}
626 650
 
627 651
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
628
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
629
-			if ($start >= $num_per_page * $nCont)
652
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
653
+					if ($start >= $num_per_page * $nCont)
630 654
 			{
631 655
 				$tmpStart = $start - $num_per_page * $nCont;
656
+		}
632 657
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
633 658
 			}
634 659
 
635 660
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
636
-		if (!$start_invalid)
637
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
638
-		else
639
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
661
+		if (!$start_invalid) {
662
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
663
+		} else {
664
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
665
+		}
640 666
 
641 667
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
642 668
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
643
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
644
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
669
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
670
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
645 671
 			{
646 672
 				$tmpStart = $start + $num_per_page * $nCont;
673
+		}
647 674
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
648 675
 			}
649 676
 
650 677
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
651
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
652
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
679
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
653 680
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
654 681
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
655 682
 				'{LAST_PAGE}' => $tmpMaxPages,
656 683
 				'{PER_PAGE}' => $num_per_page,
657 684
 			));
685
+		}
658 686
 
659 687
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
660
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
661
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
688
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
689
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
690
+		}
662 691
 
663 692
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
664
-		if ($start != $tmpMaxPages && $show_prevnext)
665
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
693
+		if ($start != $tmpMaxPages && $show_prevnext) {
694
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
695
+		}
666 696
 	}
667 697
 	$pageindex .= $settings['page_index']['extra_after'];
668 698
 
@@ -688,8 +718,9 @@  discard block
 block discarded – undo
688 718
 	if ($decimal_separator === null)
689 719
 	{
690 720
 		// Not set for whatever reason?
691
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
692
-			return $number;
721
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
722
+					return $number;
723
+		}
693 724
 
694 725
 		// Cache these each load...
695 726
 		$thousands_separator = $matches[1];
@@ -721,17 +752,20 @@  discard block
 block discarded – undo
721 752
 	static $non_twelve_hour;
722 753
 
723 754
 	// Offset the time.
724
-	if (!$offset_type)
725
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
755
+	if (!$offset_type) {
756
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
757
+	}
726 758
 	// Just the forum offset?
727
-	elseif ($offset_type == 'forum')
728
-		$time = $log_time + $modSettings['time_offset'] * 3600;
729
-	else
730
-		$time = $log_time;
759
+	elseif ($offset_type == 'forum') {
760
+			$time = $log_time + $modSettings['time_offset'] * 3600;
761
+	} else {
762
+			$time = $log_time;
763
+	}
731 764
 
732 765
 	// We can't have a negative date (on Windows, at least.)
733
-	if ($log_time < 0)
734
-		$log_time = 0;
766
+	if ($log_time < 0) {
767
+			$log_time = 0;
768
+	}
735 769
 
736 770
 	// Today and Yesterday?
737 771
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -748,46 +782,53 @@  discard block
 block discarded – undo
748 782
 		{
749 783
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
750 784
 			$today_fmt = $h . ':%M' . $s . ' %p';
785
+		} else {
786
+					$today_fmt = '%H:%M' . $s;
751 787
 		}
752
-		else
753
-			$today_fmt = '%H:%M' . $s;
754 788
 
755 789
 		// Same day of the year, same year.... Today!
756
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
757
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
790
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
791
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
792
+		}
758 793
 
759 794
 		// 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...
760
-		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))
761
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
795
+		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)) {
796
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
797
+		}
762 798
 	}
763 799
 
764 800
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
765 801
 
766 802
 	if (setlocale(LC_TIME, $txt['lang_locale']))
767 803
 	{
768
-		if (!isset($non_twelve_hour))
769
-			$non_twelve_hour = trim(strftime('%p')) === '';
770
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
771
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
804
+		if (!isset($non_twelve_hour)) {
805
+					$non_twelve_hour = trim(strftime('%p')) === '';
806
+		}
807
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
808
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
809
+		}
772 810
 
773
-		foreach (array('%a', '%A', '%b', '%B') as $token)
774
-			if (strpos($str, $token) !== false)
811
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
812
+					if (strpos($str, $token) !== false)
775 813
 				$str = str_replace($token, strftime($token, $time), $str);
776
-	}
777
-	else
814
+		}
815
+	} else
778 816
 	{
779 817
 		// Do-it-yourself time localization.  Fun.
780
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
781
-			if (strpos($str, $token) !== false)
818
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
819
+					if (strpos($str, $token) !== false)
782 820
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
821
+		}
783 822
 
784
-		if (strpos($str, '%p') !== false)
785
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
823
+		if (strpos($str, '%p') !== false) {
824
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
825
+		}
786 826
 	}
787 827
 
788 828
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
789
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
790
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
829
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
830
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
831
+	}
791 832
 
792 833
 	// Format any other characters..
793 834
 	return strftime($str, $time);
@@ -809,16 +850,19 @@  discard block
 block discarded – undo
809 850
 	static $translation = array();
810 851
 
811 852
 	// Determine the character set... Default to UTF-8
812
-	if (empty($context['character_set']))
813
-		$charset = 'UTF-8';
853
+	if (empty($context['character_set'])) {
854
+			$charset = 'UTF-8';
855
+	}
814 856
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
815
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
816
-		$charset = 'ISO-8859-1';
817
-	else
818
-		$charset = $context['character_set'];
857
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
858
+			$charset = 'ISO-8859-1';
859
+	} else {
860
+			$charset = $context['character_set'];
861
+	}
819 862
 
820
-	if (empty($translation))
821
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
863
+	if (empty($translation)) {
864
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
865
+	}
822 866
 
823 867
 	return strtr($string, $translation);
824 868
 }
@@ -840,8 +884,9 @@  discard block
 block discarded – undo
840 884
 	global $smcFunc;
841 885
 
842 886
 	// It was already short enough!
843
-	if ($smcFunc['strlen']($subject) <= $len)
844
-		return $subject;
887
+	if ($smcFunc['strlen']($subject) <= $len) {
888
+			return $subject;
889
+	}
845 890
 
846 891
 	// Shorten it by the length it was too long, and strip off junk from the end.
847 892
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -860,10 +905,11 @@  discard block
 block discarded – undo
860 905
 {
861 906
 	global $user_info, $modSettings;
862 907
 
863
-	if ($timestamp === null)
864
-		$timestamp = time();
865
-	elseif ($timestamp == 0)
866
-		return 0;
908
+	if ($timestamp === null) {
909
+			$timestamp = time();
910
+	} elseif ($timestamp == 0) {
911
+			return 0;
912
+	}
867 913
 
868 914
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
869 915
 }
@@ -892,8 +938,9 @@  discard block
 block discarded – undo
892 938
 		$array[$i] = $array[$j];
893 939
 		$array[$j] = $temp;
894 940
 
895
-		for ($i = 1; $p[$i] == 0; $i++)
896
-			$p[$i] = 1;
941
+		for ($i = 1; $p[$i] == 0; $i++) {
942
+					$p[$i] = 1;
943
+		}
897 944
 
898 945
 		$orders[] = $array;
899 946
 	}
@@ -925,12 +972,14 @@  discard block
 block discarded – undo
925 972
 	static $disabled;
926 973
 
927 974
 	// Don't waste cycles
928
-	if ($message === '')
929
-		return '';
975
+	if ($message === '') {
976
+			return '';
977
+	}
930 978
 
931 979
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
932
-	if (!isset($context['utf8']))
933
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
980
+	if (!isset($context['utf8'])) {
981
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
982
+	}
934 983
 
935 984
 	// Clean up any cut/paste issues we may have
936 985
 	$message = sanitizeMSCutPaste($message);
@@ -942,13 +991,15 @@  discard block
 block discarded – undo
942 991
 		return $message;
943 992
 	}
944 993
 
945
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
946
-		$smileys = (bool) $smileys;
994
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
995
+			$smileys = (bool) $smileys;
996
+	}
947 997
 
948 998
 	if (empty($modSettings['enableBBC']) && $message !== false)
949 999
 	{
950
-		if ($smileys === true)
951
-			parsesmileys($message);
1000
+		if ($smileys === true) {
1001
+					parsesmileys($message);
1002
+		}
952 1003
 
953 1004
 		return $message;
954 1005
 	}
@@ -961,8 +1012,9 @@  discard block
 block discarded – undo
961 1012
 	}
962 1013
 
963 1014
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
964
-	if (!empty($modSettings['autoLinkUrls']))
965
-		set_tld_regex();
1015
+	if (!empty($modSettings['autoLinkUrls'])) {
1016
+			set_tld_regex();
1017
+	}
966 1018
 
967 1019
 	// Allow mods access before entering the main parse_bbc loop
968 1020
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -976,12 +1028,14 @@  discard block
 block discarded – undo
976 1028
 
977 1029
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
978 1030
 
979
-			foreach ($temp as $tag)
980
-				$disabled[trim($tag)] = true;
1031
+			foreach ($temp as $tag) {
1032
+							$disabled[trim($tag)] = true;
1033
+			}
981 1034
 		}
982 1035
 
983
-		if (empty($modSettings['enableEmbeddedFlash']))
984
-			$disabled['flash'] = true;
1036
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1037
+					$disabled['flash'] = true;
1038
+		}
985 1039
 
986 1040
 		/* The following bbc are formatted as an array, with keys as follows:
987 1041
 
@@ -1102,8 +1156,9 @@  discard block
 block discarded – undo
1102 1156
 					$returnContext = '';
1103 1157
 
1104 1158
 					// BBC or the entire attachments feature is disabled
1105
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1106
-						return $data;
1159
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1160
+											return $data;
1161
+					}
1107 1162
 
1108 1163
 					// Save the attach ID.
1109 1164
 					$attachID = $data;
@@ -1114,8 +1169,9 @@  discard block
 block discarded – undo
1114 1169
 					$currentAttachment = parseAttachBBC($attachID);
1115 1170
 
1116 1171
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1117
-					if (is_string($currentAttachment))
1118
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1172
+					if (is_string($currentAttachment)) {
1173
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1174
+					}
1119 1175
 
1120 1176
 					if (!empty($currentAttachment['is_image']))
1121 1177
 					{
@@ -1131,15 +1187,17 @@  discard block
 block discarded – undo
1131 1187
 							$height = ' height="' . $currentAttachment['height'] . '"';
1132 1188
 						}
1133 1189
 
1134
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '" alt="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>';
1136
-						else
1137
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>';
1190
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1191
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '" alt="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>';
1192
+						} else {
1193
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>';
1194
+						}
1138 1195
 					}
1139 1196
 
1140 1197
 					// No image. Show a link.
1141
-					else
1142
-						$returnContext .= $currentAttachment['link'];
1198
+					else {
1199
+											$returnContext .= $currentAttachment['link'];
1200
+					}
1143 1201
 
1144 1202
 					// Gotta append what we just did.
1145 1203
 					$data = $returnContext;
@@ -1170,8 +1228,9 @@  discard block
 block discarded – undo
1170 1228
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1171 1229
 						{
1172 1230
 							// Do PHP code coloring?
1173
-							if ($php_parts[$php_i] != '&lt;?php')
1174
-								continue;
1231
+							if ($php_parts[$php_i] != '&lt;?php') {
1232
+															continue;
1233
+							}
1175 1234
 
1176 1235
 							$php_string = '';
1177 1236
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1188 1247
 
1189 1248
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1190
-						if ($context['browser']['is_opera'])
1191
-							$data .= '&nbsp;';
1249
+						if ($context['browser']['is_opera']) {
1250
+													$data .= '&nbsp;';
1251
+						}
1192 1252
 					}
1193 1253
 				},
1194 1254
 				'block_level' => true,
@@ -1207,8 +1267,9 @@  discard block
 block discarded – undo
1207 1267
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1208 1268
 						{
1209 1269
 							// Do PHP code coloring?
1210
-							if ($php_parts[$php_i] != '&lt;?php')
1211
-								continue;
1270
+							if ($php_parts[$php_i] != '&lt;?php') {
1271
+															continue;
1272
+							}
1212 1273
 
1213 1274
 							$php_string = '';
1214 1275
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1224,8 +1285,9 @@  discard block
 block discarded – undo
1224 1285
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1225 1286
 
1226 1287
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1227
-						if ($context['browser']['is_opera'])
1228
-							$data[0] .= '&nbsp;';
1288
+						if ($context['browser']['is_opera']) {
1289
+													$data[0] .= '&nbsp;';
1290
+						}
1229 1291
 					}
1230 1292
 				},
1231 1293
 				'block_level' => true,
@@ -1263,11 +1325,13 @@  discard block
 block discarded – undo
1263 1325
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264 1326
 				'validate' => function (&$tag, &$data, $disabled)
1265 1327
 				{
1266
-					if (isset($disabled['url']))
1267
-						$tag['content'] = '$1';
1328
+					if (isset($disabled['url'])) {
1329
+											$tag['content'] = '$1';
1330
+					}
1268 1331
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1269
-					if (empty($scheme))
1270
-						$data[0] = '//' . ltrim($data[0], ':/');
1332
+					if (empty($scheme)) {
1333
+											$data[0] = '//' . ltrim($data[0], ':/');
1334
+					}
1271 1335
 				},
1272 1336
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1273 1337
 			),
@@ -1314,14 +1378,16 @@  discard block
 block discarded – undo
1314 1378
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1315 1379
 					if ($image_proxy_enabled)
1316 1380
 					{
1317
-						if (empty($scheme))
1318
-							$data = 'http://' . ltrim($data, ':/');
1381
+						if (empty($scheme)) {
1382
+													$data = 'http://' . ltrim($data, ':/');
1383
+						}
1319 1384
 
1320
-						if ($scheme != 'https')
1321
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1385
+						if ($scheme != 'https') {
1386
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1387
+						}
1388
+					} elseif (empty($scheme)) {
1389
+											$data = '//' . ltrim($data, ':/');
1322 1390
 					}
1323
-					elseif (empty($scheme))
1324
-						$data = '//' . ltrim($data, ':/');
1325 1391
 				},
1326 1392
 				'disabled_content' => '($1)',
1327 1393
 			),
@@ -1337,14 +1403,16 @@  discard block
 block discarded – undo
1337 1403
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1338 1404
 					if ($image_proxy_enabled)
1339 1405
 					{
1340
-						if (empty($scheme))
1341
-							$data = 'http://' . ltrim($data, ':/');
1406
+						if (empty($scheme)) {
1407
+													$data = 'http://' . ltrim($data, ':/');
1408
+						}
1342 1409
 
1343
-						if ($scheme != 'https')
1344
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1410
+						if ($scheme != 'https') {
1411
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1412
+						}
1413
+					} elseif (empty($scheme)) {
1414
+											$data = '//' . ltrim($data, ':/');
1345 1415
 					}
1346
-					elseif (empty($scheme))
1347
-						$data = '//' . ltrim($data, ':/');
1348 1416
 				},
1349 1417
 				'disabled_content' => '($1)',
1350 1418
 			),
@@ -1356,8 +1424,9 @@  discard block
 block discarded – undo
1356 1424
 				{
1357 1425
 					$data = strtr($data, array('<br>' => ''));
1358 1426
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1359
-					if (empty($scheme))
1360
-						$data = '//' . ltrim($data, ':/');
1427
+					if (empty($scheme)) {
1428
+											$data = '//' . ltrim($data, ':/');
1429
+					}
1361 1430
 				},
1362 1431
 			),
1363 1432
 			array(
@@ -1368,13 +1437,14 @@  discard block
 block discarded – undo
1368 1437
 				'after' => '</a>',
1369 1438
 				'validate' => function (&$tag, &$data, $disabled)
1370 1439
 				{
1371
-					if (substr($data, 0, 1) == '#')
1372
-						$data = '#post_' . substr($data, 1);
1373
-					else
1440
+					if (substr($data, 0, 1) == '#') {
1441
+											$data = '#post_' . substr($data, 1);
1442
+					} else
1374 1443
 					{
1375 1444
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1376
-						if (empty($scheme))
1377
-							$data = '//' . ltrim($data, ':/');
1445
+						if (empty($scheme)) {
1446
+													$data = '//' . ltrim($data, ':/');
1447
+						}
1378 1448
 					}
1379 1449
 				},
1380 1450
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1452,8 +1522,9 @@  discard block
 block discarded – undo
1452 1522
 					{
1453 1523
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1454 1524
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1455
-						if ($add_begin)
1456
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1525
+						if ($add_begin) {
1526
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1527
+						}
1457 1528
 					}
1458 1529
 				},
1459 1530
 				'block_level' => false,
@@ -1584,10 +1655,11 @@  discard block
 block discarded – undo
1584 1655
 				'content' => '$1',
1585 1656
 				'validate' => function (&$tag, &$data, $disabled)
1586 1657
 				{
1587
-					if (is_numeric($data))
1588
-						$data = timeformat($data);
1589
-					else
1590
-						$tag['content'] = '[time]$1[/time]';
1658
+					if (is_numeric($data)) {
1659
+											$data = timeformat($data);
1660
+					} else {
1661
+											$tag['content'] = '[time]$1[/time]';
1662
+					}
1591 1663
 				},
1592 1664
 			),
1593 1665
 			array(
@@ -1614,8 +1686,9 @@  discard block
 block discarded – undo
1614 1686
 				{
1615 1687
 					$data = strtr($data, array('<br>' => ''));
1616 1688
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1617
-					if (empty($scheme))
1618
-						$data = '//' . ltrim($data, ':/');
1689
+					if (empty($scheme)) {
1690
+											$data = '//' . ltrim($data, ':/');
1691
+					}
1619 1692
 				},
1620 1693
 			),
1621 1694
 			array(
@@ -1627,8 +1700,9 @@  discard block
 block discarded – undo
1627 1700
 				'validate' => function (&$tag, &$data, $disabled)
1628 1701
 				{
1629 1702
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1630
-					if (empty($scheme))
1631
-						$data = '//' . ltrim($data, ':/');
1703
+					if (empty($scheme)) {
1704
+											$data = '//' . ltrim($data, ':/');
1705
+					}
1632 1706
 				},
1633 1707
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1634 1708
 				'disabled_after' => ' ($1)',
@@ -1648,8 +1722,9 @@  discard block
 block discarded – undo
1648 1722
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1649 1723
 		if ($message === false)
1650 1724
 		{
1651
-			if (isset($temp_bbc))
1652
-				$bbc_codes = $temp_bbc;
1725
+			if (isset($temp_bbc)) {
1726
+							$bbc_codes = $temp_bbc;
1727
+			}
1653 1728
 			usort($codes, function ($a, $b) {
1654 1729
 				return strcmp($a['tag'], $b['tag']);
1655 1730
 			});
@@ -1669,8 +1744,9 @@  discard block
 block discarded – undo
1669 1744
 		);
1670 1745
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1671 1746
 		{
1672
-			foreach ($itemcodes as $c => $dummy)
1673
-				$bbc_codes[$c] = array();
1747
+			foreach ($itemcodes as $c => $dummy) {
1748
+							$bbc_codes[$c] = array();
1749
+			}
1674 1750
 		}
1675 1751
 
1676 1752
 		// Shhhh!
@@ -1691,12 +1767,14 @@  discard block
 block discarded – undo
1691 1767
 		foreach ($codes as $code)
1692 1768
 		{
1693 1769
 			// Make it easier to process parameters later
1694
-			if (!empty($code['parameters']))
1695
-				ksort($code['parameters'], SORT_STRING);
1770
+			if (!empty($code['parameters'])) {
1771
+							ksort($code['parameters'], SORT_STRING);
1772
+			}
1696 1773
 
1697 1774
 			// If we are not doing every tag only do ones we are interested in.
1698
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1699
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1775
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1776
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1777
+			}
1700 1778
 		}
1701 1779
 		$codes = null;
1702 1780
 	}
@@ -1707,8 +1785,9 @@  discard block
 block discarded – undo
1707 1785
 		// It's likely this will change if the message is modified.
1708 1786
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1709 1787
 
1710
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1711
-			return $temp;
1788
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1789
+					return $temp;
1790
+		}
1712 1791
 
1713 1792
 		$cache_t = microtime();
1714 1793
 	}
@@ -1740,8 +1819,9 @@  discard block
 block discarded – undo
1740 1819
 		$disabled['flash'] = true;
1741 1820
 
1742 1821
 		// @todo Change maybe?
1743
-		if (!isset($_GET['images']))
1744
-			$disabled['img'] = true;
1822
+		if (!isset($_GET['images'])) {
1823
+					$disabled['img'] = true;
1824
+		}
1745 1825
 
1746 1826
 		// @todo Interface/setting to add more?
1747 1827
 	}
@@ -1767,8 +1847,9 @@  discard block
 block discarded – undo
1767 1847
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1768 1848
 
1769 1849
 		// Failsafe.
1770
-		if ($pos === false || $last_pos > $pos)
1771
-			$pos = strlen($message) + 1;
1850
+		if ($pos === false || $last_pos > $pos) {
1851
+					$pos = strlen($message) + 1;
1852
+		}
1772 1853
 
1773 1854
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1774 1855
 		if ($last_pos < $pos - 1)
@@ -1787,8 +1868,9 @@  discard block
 block discarded – undo
1787 1868
 
1788 1869
 				// <br> should be empty.
1789 1870
 				$empty_tags = array('br', 'hr');
1790
-				foreach ($empty_tags as $tag)
1791
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1871
+				foreach ($empty_tags as $tag) {
1872
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1873
+				}
1792 1874
 
1793 1875
 				// b, u, i, s, pre... basic tags.
1794 1876
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1797,8 +1879,9 @@  discard block
 block discarded – undo
1797 1879
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1798 1880
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1799 1881
 
1800
-					if ($diff > 0)
1801
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1882
+					if ($diff > 0) {
1883
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1884
+					}
1802 1885
 				}
1803 1886
 
1804 1887
 				// Do <img ...> - with security... action= -> action-.
@@ -1811,8 +1894,9 @@  discard block
 block discarded – undo
1811 1894
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1812 1895
 
1813 1896
 						// Remove action= from the URL - no funny business, now.
1814
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1815
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1897
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1898
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1899
+						}
1816 1900
 
1817 1901
 						// Check if the image is larger than allowed.
1818 1902
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1833,9 +1917,9 @@  discard block
 block discarded – undo
1833 1917
 
1834 1918
 							// Set the new image tag.
1835 1919
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1920
+						} else {
1921
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1836 1922
 						}
1837
-						else
1838
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1839 1923
 					}
1840 1924
 
1841 1925
 					$data = strtr($data, $replaces);
@@ -1848,16 +1932,18 @@  discard block
 block discarded – undo
1848 1932
 				$no_autolink_area = false;
1849 1933
 				if (!empty($open_tags))
1850 1934
 				{
1851
-					foreach ($open_tags as $open_tag)
1852
-						if (in_array($open_tag['tag'], $no_autolink_tags))
1935
+					foreach ($open_tags as $open_tag) {
1936
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1853 1937
 							$no_autolink_area = true;
1938
+					}
1854 1939
 				}
1855 1940
 
1856 1941
 				// Don't go backwards.
1857 1942
 				// @todo Don't think is the real solution....
1858 1943
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1859
-				if ($pos < $lastAutoPos)
1860
-					$no_autolink_area = true;
1944
+				if ($pos < $lastAutoPos) {
1945
+									$no_autolink_area = true;
1946
+				}
1861 1947
 				$lastAutoPos = $pos;
1862 1948
 
1863 1949
 				if (!$no_autolink_area)
@@ -1966,17 +2052,19 @@  discard block
 block discarded – undo
1966 2052
 							if ($scheme == 'mailto')
1967 2053
 							{
1968 2054
 								$email_address = str_replace('mailto:', '', $url);
1969
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
1970
-									return '[email=' . $email_address . ']' . $url . '[/email]';
1971
-								else
1972
-									return $url;
2055
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2056
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2057
+								} else {
2058
+																	return $url;
2059
+								}
1973 2060
 							}
1974 2061
 
1975 2062
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
1976
-							if (empty($scheme))
1977
-								$fullUrl = '//' . ltrim($url, ':/');
1978
-							else
1979
-								$fullUrl = $url;
2063
+							if (empty($scheme)) {
2064
+															$fullUrl = '//' . ltrim($url, ':/');
2065
+							} else {
2066
+															$fullUrl = $url;
2067
+							}
1980 2068
 
1981 2069
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
1982 2070
 						}, $data);
@@ -2025,16 +2113,18 @@  discard block
 block discarded – undo
2025 2113
 		}
2026 2114
 
2027 2115
 		// Are we there yet?  Are we there yet?
2028
-		if ($pos >= strlen($message) - 1)
2029
-			break;
2116
+		if ($pos >= strlen($message) - 1) {
2117
+					break;
2118
+		}
2030 2119
 
2031 2120
 		$tags = strtolower($message[$pos + 1]);
2032 2121
 
2033 2122
 		if ($tags == '/' && !empty($open_tags))
2034 2123
 		{
2035 2124
 			$pos2 = strpos($message, ']', $pos + 1);
2036
-			if ($pos2 == $pos + 2)
2037
-				continue;
2125
+			if ($pos2 == $pos + 2) {
2126
+							continue;
2127
+			}
2038 2128
 
2039 2129
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2040 2130
 
@@ -2044,8 +2134,9 @@  discard block
 block discarded – undo
2044 2134
 			do
2045 2135
 			{
2046 2136
 				$tag = array_pop($open_tags);
2047
-				if (!$tag)
2048
-					break;
2137
+				if (!$tag) {
2138
+									break;
2139
+				}
2049 2140
 
2050 2141
 				if (!empty($tag['block_level']))
2051 2142
 				{
@@ -2059,10 +2150,11 @@  discard block
 block discarded – undo
2059 2150
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2060 2151
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2061 2152
 					{
2062
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2063
-							if ($temp['tag'] == $look_for)
2153
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2154
+													if ($temp['tag'] == $look_for)
2064 2155
 							{
2065 2156
 								$block_level = !empty($temp['block_level']);
2157
+						}
2066 2158
 								break;
2067 2159
 							}
2068 2160
 					}
@@ -2084,15 +2176,15 @@  discard block
 block discarded – undo
2084 2176
 			{
2085 2177
 				$open_tags = $to_close;
2086 2178
 				continue;
2087
-			}
2088
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2179
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2089 2180
 			{
2090 2181
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2091 2182
 				{
2092
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2093
-						if ($temp['tag'] == $look_for)
2183
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2184
+											if ($temp['tag'] == $look_for)
2094 2185
 						{
2095 2186
 							$block_level = !empty($temp['block_level']);
2187
+					}
2096 2188
 							break;
2097 2189
 						}
2098 2190
 				}
@@ -2100,8 +2192,9 @@  discard block
 block discarded – undo
2100 2192
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2101 2193
 				if (!$block_level)
2102 2194
 				{
2103
-					foreach ($to_close as $tag)
2104
-						array_push($open_tags, $tag);
2195
+					foreach ($to_close as $tag) {
2196
+											array_push($open_tags, $tag);
2197
+					}
2105 2198
 					continue;
2106 2199
 				}
2107 2200
 			}
@@ -2113,10 +2206,12 @@  discard block
 block discarded – undo
2113 2206
 				$pos2 = $pos - 1;
2114 2207
 
2115 2208
 				// See the comment at the end of the big loop - just eating whitespace ;).
2116
-				if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>')
2117
-					$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2118
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0)
2119
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2209
+				if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') {
2210
+									$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2211
+				}
2212
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0) {
2213
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2214
+				}
2120 2215
 			}
2121 2216
 
2122 2217
 			if (!empty($to_close))
@@ -2129,8 +2224,9 @@  discard block
 block discarded – undo
2129 2224
 		}
2130 2225
 
2131 2226
 		// No tags for this character, so just keep going (fastest possible course.)
2132
-		if (!isset($bbc_codes[$tags]))
2133
-			continue;
2227
+		if (!isset($bbc_codes[$tags])) {
2228
+					continue;
2229
+		}
2134 2230
 
2135 2231
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2136 2232
 		$tag = null;
@@ -2139,44 +2235,52 @@  discard block
 block discarded – undo
2139 2235
 			$pt_strlen = strlen($possible['tag']);
2140 2236
 
2141 2237
 			// Not a match?
2142
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2143
-				continue;
2238
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2239
+							continue;
2240
+			}
2144 2241
 
2145 2242
 			$next_c = $message[$pos + 1 + $pt_strlen];
2146 2243
 
2147 2244
 			// A test validation?
2148
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2149
-				continue;
2245
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2246
+							continue;
2247
+			}
2150 2248
 			// Do we want parameters?
2151 2249
 			elseif (!empty($possible['parameters']))
2152 2250
 			{
2153
-				if ($next_c != ' ')
2154
-					continue;
2155
-			}
2156
-			elseif (isset($possible['type']))
2251
+				if ($next_c != ' ') {
2252
+									continue;
2253
+				}
2254
+			} elseif (isset($possible['type']))
2157 2255
 			{
2158 2256
 				// Do we need an equal sign?
2159
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2160
-					continue;
2257
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2258
+									continue;
2259
+				}
2161 2260
 				// Maybe we just want a /...
2162
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2163
-					continue;
2261
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2262
+									continue;
2263
+				}
2164 2264
 				// An immediate ]?
2165
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2166
-					continue;
2265
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2266
+									continue;
2267
+				}
2167 2268
 			}
2168 2269
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2169
-			elseif ($next_c != ']')
2170
-				continue;
2270
+			elseif ($next_c != ']') {
2271
+							continue;
2272
+			}
2171 2273
 
2172 2274
 			// Check allowed tree?
2173
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2174
-				continue;
2175
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2176
-				continue;
2275
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2276
+							continue;
2277
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2278
+							continue;
2279
+			}
2177 2280
 			// If this is in the list of disallowed child tags, don't parse it.
2178
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2179
-				continue;
2281
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2282
+							continue;
2283
+			}
2180 2284
 
2181 2285
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2182 2286
 
@@ -2188,8 +2292,9 @@  discard block
 block discarded – undo
2188 2292
 				foreach ($open_tags as $open_quote)
2189 2293
 				{
2190 2294
 					// Every parent quote this quote has flips the styling
2191
-					if ($open_quote['tag'] == 'quote')
2192
-						$quote_alt = !$quote_alt;
2295
+					if ($open_quote['tag'] == 'quote') {
2296
+											$quote_alt = !$quote_alt;
2297
+					}
2193 2298
 				}
2194 2299
 				// Add a class to the quote to style alternating blockquotes
2195 2300
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2200,8 +2305,9 @@  discard block
 block discarded – undo
2200 2305
 			{
2201 2306
 				// Build a regular expression for each parameter for the current tag.
2202 2307
 				$preg = array();
2203
-				foreach ($possible['parameters'] as $p => $info)
2204
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2308
+				foreach ($possible['parameters'] as $p => $info) {
2309
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2310
+				}
2205 2311
 
2206 2312
 				// Extract the string that potentially holds our parameters.
2207 2313
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2221,24 +2327,27 @@  discard block
 block discarded – undo
2221 2327
 
2222 2328
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2223 2329
 
2224
-					if ($match)
2225
-						$blob_counter = count($blobs) + 1;
2330
+					if ($match) {
2331
+											$blob_counter = count($blobs) + 1;
2332
+					}
2226 2333
 				}
2227 2334
 
2228 2335
 				// Didn't match our parameter list, try the next possible.
2229
-				if (!$match)
2230
-					continue;
2336
+				if (!$match) {
2337
+									continue;
2338
+				}
2231 2339
 
2232 2340
 				$params = array();
2233 2341
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2234 2342
 				{
2235 2343
 					$key = strtok(ltrim($matches[$i]), '=');
2236
-					if (isset($possible['parameters'][$key]['value']))
2237
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2238
-					elseif (isset($possible['parameters'][$key]['validate']))
2239
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2240
-					else
2241
-						$params['{' . $key . '}'] = $matches[$i + 1];
2344
+					if (isset($possible['parameters'][$key]['value'])) {
2345
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2346
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2347
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2348
+					} else {
2349
+											$params['{' . $key . '}'] = $matches[$i + 1];
2350
+					}
2242 2351
 
2243 2352
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2244 2353
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2246,23 +2355,26 @@  discard block
 block discarded – undo
2246 2355
 
2247 2356
 				foreach ($possible['parameters'] as $p => $info)
2248 2357
 				{
2249
-					if (!isset($params['{' . $p . '}']))
2250
-						$params['{' . $p . '}'] = '';
2358
+					if (!isset($params['{' . $p . '}'])) {
2359
+											$params['{' . $p . '}'] = '';
2360
+					}
2251 2361
 				}
2252 2362
 
2253 2363
 				$tag = $possible;
2254 2364
 
2255 2365
 				// Put the parameters into the string.
2256
-				if (isset($tag['before']))
2257
-					$tag['before'] = strtr($tag['before'], $params);
2258
-				if (isset($tag['after']))
2259
-					$tag['after'] = strtr($tag['after'], $params);
2260
-				if (isset($tag['content']))
2261
-					$tag['content'] = strtr($tag['content'], $params);
2366
+				if (isset($tag['before'])) {
2367
+									$tag['before'] = strtr($tag['before'], $params);
2368
+				}
2369
+				if (isset($tag['after'])) {
2370
+									$tag['after'] = strtr($tag['after'], $params);
2371
+				}
2372
+				if (isset($tag['content'])) {
2373
+									$tag['content'] = strtr($tag['content'], $params);
2374
+				}
2262 2375
 
2263 2376
 				$pos1 += strlen($given_param_string);
2264
-			}
2265
-			else
2377
+			} else
2266 2378
 			{
2267 2379
 				$tag = $possible;
2268 2380
 				$params = array();
@@ -2273,8 +2385,9 @@  discard block
 block discarded – undo
2273 2385
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2274 2386
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2275 2387
 		{
2276
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2277
-				continue;
2388
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2389
+							continue;
2390
+			}
2278 2391
 
2279 2392
 			$tag = $itemcodes[$message[$pos + 1]];
2280 2393
 
@@ -2295,9 +2408,9 @@  discard block
 block discarded – undo
2295 2408
 			{
2296 2409
 				array_pop($open_tags);
2297 2410
 				$code = '</li>';
2411
+			} else {
2412
+							$code = '';
2298 2413
 			}
2299
-			else
2300
-				$code = '';
2301 2414
 
2302 2415
 			// Now we open a new tag.
2303 2416
 			$open_tags[] = array(
@@ -2344,12 +2457,14 @@  discard block
 block discarded – undo
2344 2457
 		}
2345 2458
 
2346 2459
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2347
-		if ($tag === null)
2348
-			continue;
2460
+		if ($tag === null) {
2461
+					continue;
2462
+		}
2349 2463
 
2350 2464
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2351
-		if (isset($inside['disallow_children']))
2352
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2465
+		if (isset($inside['disallow_children'])) {
2466
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2467
+		}
2353 2468
 
2354 2469
 		// Is this tag disabled?
2355 2470
 		if (isset($disabled[$tag['tag']]))
@@ -2359,14 +2474,13 @@  discard block
 block discarded – undo
2359 2474
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2360 2475
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2361 2476
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2362
-			}
2363
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2477
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2364 2478
 			{
2365 2479
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2366 2480
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2481
+			} else {
2482
+							$tag['content'] = $tag['disabled_content'];
2367 2483
 			}
2368
-			else
2369
-				$tag['content'] = $tag['disabled_content'];
2370 2484
 		}
2371 2485
 
2372 2486
 		// we use this a lot
@@ -2376,8 +2490,9 @@  discard block
 block discarded – undo
2376 2490
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2377 2491
 		{
2378 2492
 			$n = count($open_tags) - 1;
2379
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2380
-				$n--;
2493
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2494
+							$n--;
2495
+			}
2381 2496
 
2382 2497
 			// Close all the non block level tags so this tag isn't surrounded by them.
2383 2498
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2388,10 +2503,12 @@  discard block
 block discarded – undo
2388 2503
 				$pos1 += $ot_strlen + 2;
2389 2504
 
2390 2505
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2391
-				if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>')
2392
-					$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2393
-				if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0)
2394
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2506
+				if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') {
2507
+									$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2508
+				}
2509
+				if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0) {
2510
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2511
+				}
2395 2512
 
2396 2513
 				array_pop($open_tags);
2397 2514
 			}
@@ -2409,16 +2526,19 @@  discard block
 block discarded – undo
2409 2526
 		elseif ($tag['type'] == 'unparsed_content')
2410 2527
 		{
2411 2528
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2412
-			if ($pos2 === false)
2413
-				continue;
2529
+			if ($pos2 === false) {
2530
+							continue;
2531
+			}
2414 2532
 
2415 2533
 			$data = substr($message, $pos1, $pos2 - $pos1);
2416 2534
 
2417
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2418
-				$data = substr($data, 4);
2535
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2536
+							$data = substr($data, 4);
2537
+			}
2419 2538
 
2420
-			if (isset($tag['validate']))
2421
-				$tag['validate']($tag, $data, $disabled, $params);
2539
+			if (isset($tag['validate'])) {
2540
+							$tag['validate']($tag, $data, $disabled, $params);
2541
+			}
2422 2542
 
2423 2543
 			$code = strtr($tag['content'], array('$1' => $data));
2424 2544
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2434,34 +2554,40 @@  discard block
 block discarded – undo
2434 2554
 			if (isset($tag['quoted']))
2435 2555
 			{
2436 2556
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2437
-				if ($tag['quoted'] != 'optional' && !$quoted)
2438
-					continue;
2557
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2558
+									continue;
2559
+				}
2439 2560
 
2440
-				if ($quoted)
2441
-					$pos1 += 6;
2561
+				if ($quoted) {
2562
+									$pos1 += 6;
2563
+				}
2564
+			} else {
2565
+							$quoted = false;
2442 2566
 			}
2443
-			else
2444
-				$quoted = false;
2445 2567
 
2446 2568
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2447
-			if ($pos2 === false)
2448
-				continue;
2569
+			if ($pos2 === false) {
2570
+							continue;
2571
+			}
2449 2572
 
2450 2573
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2451
-			if ($pos3 === false)
2452
-				continue;
2574
+			if ($pos3 === false) {
2575
+							continue;
2576
+			}
2453 2577
 
2454 2578
 			$data = array(
2455 2579
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2456 2580
 				substr($message, $pos1, $pos2 - $pos1)
2457 2581
 			);
2458 2582
 
2459
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2460
-				$data[0] = substr($data[0], 4);
2583
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2584
+							$data[0] = substr($data[0], 4);
2585
+			}
2461 2586
 
2462 2587
 			// Validation for my parking, please!
2463
-			if (isset($tag['validate']))
2464
-				$tag['validate']($tag, $data, $disabled, $params);
2588
+			if (isset($tag['validate'])) {
2589
+							$tag['validate']($tag, $data, $disabled, $params);
2590
+			}
2465 2591
 
2466 2592
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2467 2593
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2478,23 +2604,27 @@  discard block
 block discarded – undo
2478 2604
 		elseif ($tag['type'] == 'unparsed_commas_content')
2479 2605
 		{
2480 2606
 			$pos2 = strpos($message, ']', $pos1);
2481
-			if ($pos2 === false)
2482
-				continue;
2607
+			if ($pos2 === false) {
2608
+							continue;
2609
+			}
2483 2610
 
2484 2611
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2485
-			if ($pos3 === false)
2486
-				continue;
2612
+			if ($pos3 === false) {
2613
+							continue;
2614
+			}
2487 2615
 
2488 2616
 			// We want $1 to be the content, and the rest to be csv.
2489 2617
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2490 2618
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2491 2619
 
2492
-			if (isset($tag['validate']))
2493
-				$tag['validate']($tag, $data, $disabled, $params);
2620
+			if (isset($tag['validate'])) {
2621
+							$tag['validate']($tag, $data, $disabled, $params);
2622
+			}
2494 2623
 
2495 2624
 			$code = $tag['content'];
2496
-			foreach ($data as $k => $d)
2497
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2625
+			foreach ($data as $k => $d) {
2626
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2627
+			}
2498 2628
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2499 2629
 			$pos += strlen($code) - 1 + 2;
2500 2630
 		}
@@ -2502,24 +2632,28 @@  discard block
 block discarded – undo
2502 2632
 		elseif ($tag['type'] == 'unparsed_commas')
2503 2633
 		{
2504 2634
 			$pos2 = strpos($message, ']', $pos1);
2505
-			if ($pos2 === false)
2506
-				continue;
2635
+			if ($pos2 === false) {
2636
+							continue;
2637
+			}
2507 2638
 
2508 2639
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2509 2640
 
2510
-			if (isset($tag['validate']))
2511
-				$tag['validate']($tag, $data, $disabled, $params);
2641
+			if (isset($tag['validate'])) {
2642
+							$tag['validate']($tag, $data, $disabled, $params);
2643
+			}
2512 2644
 
2513 2645
 			// Fix after, for disabled code mainly.
2514
-			foreach ($data as $k => $d)
2515
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2646
+			foreach ($data as $k => $d) {
2647
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2648
+			}
2516 2649
 
2517 2650
 			$open_tags[] = $tag;
2518 2651
 
2519 2652
 			// Replace them out, $1, $2, $3, $4, etc.
2520 2653
 			$code = $tag['before'];
2521
-			foreach ($data as $k => $d)
2522
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2654
+			foreach ($data as $k => $d) {
2655
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2656
+			}
2523 2657
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2524 2658
 			$pos += strlen($code) - 1 + 2;
2525 2659
 		}
@@ -2530,28 +2664,33 @@  discard block
 block discarded – undo
2530 2664
 			if (isset($tag['quoted']))
2531 2665
 			{
2532 2666
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2533
-				if ($tag['quoted'] != 'optional' && !$quoted)
2534
-					continue;
2667
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2668
+									continue;
2669
+				}
2535 2670
 
2536
-				if ($quoted)
2537
-					$pos1 += 6;
2671
+				if ($quoted) {
2672
+									$pos1 += 6;
2673
+				}
2674
+			} else {
2675
+							$quoted = false;
2538 2676
 			}
2539
-			else
2540
-				$quoted = false;
2541 2677
 
2542 2678
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2543
-			if ($pos2 === false)
2544
-				continue;
2679
+			if ($pos2 === false) {
2680
+							continue;
2681
+			}
2545 2682
 
2546 2683
 			$data = substr($message, $pos1, $pos2 - $pos1);
2547 2684
 
2548 2685
 			// Validation for my parking, please!
2549
-			if (isset($tag['validate']))
2550
-				$tag['validate']($tag, $data, $disabled, $params);
2686
+			if (isset($tag['validate'])) {
2687
+							$tag['validate']($tag, $data, $disabled, $params);
2688
+			}
2551 2689
 
2552 2690
 			// For parsed content, we must recurse to avoid security problems.
2553
-			if ($tag['type'] != 'unparsed_equals')
2554
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2691
+			if ($tag['type'] != 'unparsed_equals') {
2692
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2693
+			}
2555 2694
 
2556 2695
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2557 2696
 
@@ -2563,34 +2702,40 @@  discard block
 block discarded – undo
2563 2702
 		}
2564 2703
 
2565 2704
 		// If this is block level, eat any breaks after it.
2566
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2567
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2705
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2706
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2707
+		}
2568 2708
 
2569 2709
 		// Are we trimming outside this tag?
2570
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2571
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2710
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2711
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2712
+		}
2572 2713
 	}
2573 2714
 
2574 2715
 	// Close any remaining tags.
2575
-	while ($tag = array_pop($open_tags))
2576
-		$message .= "\n" . $tag['after'] . "\n";
2716
+	while ($tag = array_pop($open_tags)) {
2717
+			$message .= "\n" . $tag['after'] . "\n";
2718
+	}
2577 2719
 
2578 2720
 	// Parse the smileys within the parts where it can be done safely.
2579 2721
 	if ($smileys === true)
2580 2722
 	{
2581 2723
 		$message_parts = explode("\n", $message);
2582
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2583
-			parsesmileys($message_parts[$i]);
2724
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2725
+					parsesmileys($message_parts[$i]);
2726
+		}
2584 2727
 
2585 2728
 		$message = implode('', $message_parts);
2586 2729
 	}
2587 2730
 
2588 2731
 	// No smileys, just get rid of the markers.
2589
-	else
2590
-		$message = strtr($message, array("\n" => ''));
2732
+	else {
2733
+			$message = strtr($message, array("\n" => ''));
2734
+	}
2591 2735
 
2592
-	if ($message !== '' && $message[0] === ' ')
2593
-		$message = '&nbsp;' . substr($message, 1);
2736
+	if ($message !== '' && $message[0] === ' ') {
2737
+			$message = '&nbsp;' . substr($message, 1);
2738
+	}
2594 2739
 
2595 2740
 	// Cleanup whitespace.
2596 2741
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2599,15 +2744,16 @@  discard block
 block discarded – undo
2599 2744
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2600 2745
 
2601 2746
 	// Cache the output if it took some time...
2602
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2603
-		cache_put_data($cache_key, $message, 240);
2747
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2748
+			cache_put_data($cache_key, $message, 240);
2749
+	}
2604 2750
 
2605 2751
 	// If this was a force parse revert if needed.
2606 2752
 	if (!empty($parse_tags))
2607 2753
 	{
2608
-		if (empty($temp_bbc))
2609
-			$bbc_codes = array();
2610
-		else
2754
+		if (empty($temp_bbc)) {
2755
+					$bbc_codes = array();
2756
+		} else
2611 2757
 		{
2612 2758
 			$bbc_codes = $temp_bbc;
2613 2759
 			unset($temp_bbc);
@@ -2634,8 +2780,9 @@  discard block
 block discarded – undo
2634 2780
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2635 2781
 
2636 2782
 	// No smiley set at all?!
2637
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2638
-		return;
2783
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2784
+			return;
2785
+	}
2639 2786
 
2640 2787
 	// If smileyPregSearch hasn't been set, do it now.
2641 2788
 	if (empty($smileyPregSearch))
@@ -2646,8 +2793,7 @@  discard block
 block discarded – undo
2646 2793
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2647 2794
 			$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');
2648 2795
 			$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'], '', '', '', '');
2649
-		}
2650
-		else
2796
+		} else
2651 2797
 		{
2652 2798
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2653 2799
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2671,9 +2817,9 @@  discard block
 block discarded – undo
2671 2817
 				$smcFunc['db_free_result']($result);
2672 2818
 
2673 2819
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2820
+			} else {
2821
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2674 2822
 			}
2675
-			else
2676
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2677 2823
 		}
2678 2824
 
2679 2825
 		// The non-breaking-space is a complex thing...
@@ -2750,35 +2896,41 @@  discard block
 block discarded – undo
2750 2896
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2751 2897
 
2752 2898
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2753
-	if (!empty($context['flush_mail']))
2754
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2899
+	if (!empty($context['flush_mail'])) {
2900
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2755 2901
 		AddMailQueue(true);
2902
+	}
2756 2903
 
2757 2904
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2758 2905
 
2759
-	if ($add)
2760
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2906
+	if ($add) {
2907
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2908
+	}
2761 2909
 
2762 2910
 	// Put the session ID in.
2763
-	if (defined('SID') && SID != '')
2764
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2911
+	if (defined('SID') && SID != '') {
2912
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2913
+	}
2765 2914
 	// Keep that debug in their for template debugging!
2766
-	elseif (isset($_GET['debug']))
2767
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2915
+	elseif (isset($_GET['debug'])) {
2916
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2917
+	}
2768 2918
 
2769 2919
 	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'])))
2770 2920
 	{
2771
-		if (defined('SID') && SID != '')
2772
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2921
+		if (defined('SID') && SID != '') {
2922
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2773 2923
 				function ($m) use ($scripturl)
2774 2924
 				{
2775 2925
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2926
+		}
2776 2927
 				}, $setLocation);
2777
-		else
2778
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2928
+		else {
2929
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2779 2930
 				function ($m) use ($scripturl)
2780 2931
 				{
2781 2932
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2933
+		}
2782 2934
 				}, $setLocation);
2783 2935
 	}
2784 2936
 
@@ -2789,8 +2941,9 @@  discard block
 block discarded – undo
2789 2941
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2790 2942
 
2791 2943
 	// Debugging.
2792
-	if (isset($db_show_debug) && $db_show_debug === true)
2793
-		$_SESSION['debug_redirect'] = $db_cache;
2944
+	if (isset($db_show_debug) && $db_show_debug === true) {
2945
+			$_SESSION['debug_redirect'] = $db_cache;
2946
+	}
2794 2947
 
2795 2948
 	obExit(false);
2796 2949
 }
@@ -2809,51 +2962,60 @@  discard block
 block discarded – undo
2809 2962
 
2810 2963
 	// Attempt to prevent a recursive loop.
2811 2964
 	++$level;
2812
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2813
-		exit;
2814
-	if ($from_fatal_error)
2815
-		$has_fatal_error = true;
2965
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
2966
+			exit;
2967
+	}
2968
+	if ($from_fatal_error) {
2969
+			$has_fatal_error = true;
2970
+	}
2816 2971
 
2817 2972
 	// Clear out the stat cache.
2818 2973
 	trackStats();
2819 2974
 
2820 2975
 	// If we have mail to send, send it.
2821
-	if (!empty($context['flush_mail']))
2822
-		// @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... :\
2823 2978
 		AddMailQueue(true);
2979
+	}
2824 2980
 
2825 2981
 	$do_header = $header === null ? !$header_done : $header;
2826
-	if ($do_footer === null)
2827
-		$do_footer = $do_header;
2982
+	if ($do_footer === null) {
2983
+			$do_footer = $do_header;
2984
+	}
2828 2985
 
2829 2986
 	// Has the template/header been done yet?
2830 2987
 	if ($do_header)
2831 2988
 	{
2832 2989
 		// Was the page title set last minute? Also update the HTML safe one.
2833
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2834
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
2990
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
2991
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
2992
+		}
2835 2993
 
2836 2994
 		// Start up the session URL fixer.
2837 2995
 		ob_start('ob_sessrewrite');
2838 2996
 
2839
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2840
-			$buffers = explode(',', $settings['output_buffers']);
2841
-		elseif (!empty($settings['output_buffers']))
2842
-			$buffers = $settings['output_buffers'];
2843
-		else
2844
-			$buffers = array();
2997
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
2998
+					$buffers = explode(',', $settings['output_buffers']);
2999
+		} elseif (!empty($settings['output_buffers'])) {
3000
+					$buffers = $settings['output_buffers'];
3001
+		} else {
3002
+					$buffers = array();
3003
+		}
2845 3004
 
2846
-		if (isset($modSettings['integrate_buffer']))
2847
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3005
+		if (isset($modSettings['integrate_buffer'])) {
3006
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3007
+		}
2848 3008
 
2849
-		if (!empty($buffers))
2850
-			foreach ($buffers as $function)
3009
+		if (!empty($buffers)) {
3010
+					foreach ($buffers as $function)
2851 3011
 			{
2852 3012
 				$call = call_helper($function, true);
3013
+		}
2853 3014
 
2854 3015
 				// Is it valid?
2855
-				if (!empty($call))
2856
-					ob_start($call);
3016
+				if (!empty($call)) {
3017
+									ob_start($call);
3018
+				}
2857 3019
 			}
2858 3020
 
2859 3021
 		// Display the screen in the logical order.
@@ -2865,8 +3027,9 @@  discard block
 block discarded – undo
2865 3027
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2866 3028
 
2867 3029
 		// Anything special to put out?
2868
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2869
-			echo $context['insert_after_template'];
3030
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3031
+					echo $context['insert_after_template'];
3032
+		}
2870 3033
 
2871 3034
 		// Just so we don't get caught in an endless loop of errors from the footer...
2872 3035
 		if (!$footer_done)
@@ -2875,14 +3038,16 @@  discard block
 block discarded – undo
2875 3038
 			template_footer();
2876 3039
 
2877 3040
 			// (since this is just debugging... it's okay that it's after </html>.)
2878
-			if (!isset($_REQUEST['xml']))
2879
-				displayDebug();
3041
+			if (!isset($_REQUEST['xml'])) {
3042
+							displayDebug();
3043
+			}
2880 3044
 		}
2881 3045
 	}
2882 3046
 
2883 3047
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2884
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2885
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3048
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3049
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3050
+	}
2886 3051
 
2887 3052
 	// For session check verification.... don't switch browsers...
2888 3053
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2891,9 +3056,10 @@  discard block
 block discarded – undo
2891 3056
 	call_integration_hook('integrate_exit', array($do_footer));
2892 3057
 
2893 3058
 	// Don't exit if we're coming from index.php; that will pass through normally.
2894
-	if (!$from_index)
2895
-		exit;
2896
-}
3059
+	if (!$from_index) {
3060
+			exit;
3061
+	}
3062
+	}
2897 3063
 
2898 3064
 /**
2899 3065
  * Get the size of a specified image with better error handling.
@@ -2912,8 +3078,9 @@  discard block
 block discarded – undo
2912 3078
 	$url = str_replace(' ', '%20', $url);
2913 3079
 
2914 3080
 	// Can we pull this from the cache... please please?
2915
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2916
-		return $temp;
3081
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3082
+			return $temp;
3083
+	}
2917 3084
 	$t = microtime();
2918 3085
 
2919 3086
 	// Get the host to pester...
@@ -2923,12 +3090,10 @@  discard block
 block discarded – undo
2923 3090
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2924 3091
 	{
2925 3092
 		return false;
2926
-	}
2927
-	elseif (!isset($match[1]))
3093
+	} elseif (!isset($match[1]))
2928 3094
 	{
2929 3095
 		$size = @getimagesize($url);
2930
-	}
2931
-	else
3096
+	} else
2932 3097
 	{
2933 3098
 		// Try to connect to the server... give it half a second.
2934 3099
 		$temp = 0;
@@ -2967,12 +3132,14 @@  discard block
 block discarded – undo
2967 3132
 	}
2968 3133
 
2969 3134
 	// If we didn't get it, we failed.
2970
-	if (!isset($size))
2971
-		$size = false;
3135
+	if (!isset($size)) {
3136
+			$size = false;
3137
+	}
2972 3138
 
2973 3139
 	// If this took a long time, we may never have to do it again, but then again we might...
2974
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
2975
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3140
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3141
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3142
+	}
2976 3143
 
2977 3144
 	// Didn't work.
2978 3145
 	return $size;
@@ -2990,8 +3157,9 @@  discard block
 block discarded – undo
2990 3157
 
2991 3158
 	// Under SSI this function can be called more then once.  That can cause some problems.
2992 3159
 	//   So only run the function once unless we are forced to run it again.
2993
-	if ($loaded && !$forceload)
2994
-		return;
3160
+	if ($loaded && !$forceload) {
3161
+			return;
3162
+	}
2995 3163
 
2996 3164
 	$loaded = true;
2997 3165
 
@@ -3003,14 +3171,16 @@  discard block
 block discarded – undo
3003 3171
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3004 3172
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3005 3173
 	{
3006
-		if (trim($context['news_lines'][$i]) == '')
3007
-			continue;
3174
+		if (trim($context['news_lines'][$i]) == '') {
3175
+					continue;
3176
+		}
3008 3177
 
3009 3178
 		// Clean it up for presentation ;).
3010 3179
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3011 3180
 	}
3012
-	if (!empty($context['news_lines']))
3013
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3181
+	if (!empty($context['news_lines'])) {
3182
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3183
+	}
3014 3184
 
3015 3185
 	if (!$user_info['is_guest'])
3016 3186
 	{
@@ -3019,40 +3189,48 @@  discard block
 block discarded – undo
3019 3189
 		$context['user']['alerts'] = &$user_info['alerts'];
3020 3190
 
3021 3191
 		// Personal message popup...
3022
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3023
-			$context['user']['popup_messages'] = true;
3024
-		else
3025
-			$context['user']['popup_messages'] = false;
3192
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3193
+					$context['user']['popup_messages'] = true;
3194
+		} else {
3195
+					$context['user']['popup_messages'] = false;
3196
+		}
3026 3197
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3027 3198
 
3028
-		if (allowedTo('moderate_forum'))
3029
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3199
+		if (allowedTo('moderate_forum')) {
3200
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3201
+		}
3030 3202
 
3031 3203
 		$context['user']['avatar'] = array();
3032 3204
 
3033 3205
 		// Check for gravatar first since we might be forcing them...
3034 3206
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3035 3207
 		{
3036
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3037
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3038
-			else
3039
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3208
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3209
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3210
+			} else {
3211
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3212
+			}
3040 3213
 		}
3041 3214
 		// Uploaded?
3042
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3043
-			$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';
3215
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3216
+					$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';
3217
+		}
3044 3218
 		// Full URL?
3045
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3046
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3219
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3220
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3221
+		}
3047 3222
 		// Otherwise we assume it's server stored.
3048
-		elseif ($user_info['avatar']['url'] != '')
3049
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3223
+		elseif ($user_info['avatar']['url'] != '') {
3224
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3225
+		}
3050 3226
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3051
-		else
3052
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3227
+		else {
3228
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3229
+		}
3053 3230
 
3054
-		if (!empty($context['user']['avatar']))
3055
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3231
+		if (!empty($context['user']['avatar'])) {
3232
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3233
+		}
3056 3234
 
3057 3235
 		// Figure out how long they've been logged in.
3058 3236
 		$context['user']['total_time_logged_in'] = array(
@@ -3060,8 +3238,7 @@  discard block
 block discarded – undo
3060 3238
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3061 3239
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3062 3240
 		);
3063
-	}
3064
-	else
3241
+	} else
3065 3242
 	{
3066 3243
 		$context['user']['messages'] = 0;
3067 3244
 		$context['user']['unread_messages'] = 0;
@@ -3069,12 +3246,14 @@  discard block
 block discarded – undo
3069 3246
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3070 3247
 		$context['user']['popup_messages'] = false;
3071 3248
 
3072
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3073
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3249
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3250
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3251
+		}
3074 3252
 
3075 3253
 		// If we've upgraded recently, go easy on the passwords.
3076
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3077
-			$context['disable_login_hashing'] = true;
3254
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3255
+					$context['disable_login_hashing'] = true;
3256
+		}
3078 3257
 	}
3079 3258
 
3080 3259
 	// Setup the main menu items.
@@ -3087,8 +3266,8 @@  discard block
 block discarded – undo
3087 3266
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3088 3267
 
3089 3268
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3090
-	if ($context['show_pm_popup'])
3091
-		addInlineJavaScript('
3269
+	if ($context['show_pm_popup']) {
3270
+			addInlineJavaScript('
3092 3271
 		jQuery(document).ready(function($) {
3093 3272
 			new smc_Popup({
3094 3273
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3096,15 +3275,17 @@  discard block
 block discarded – undo
3096 3275
 				icon_class: \'generic_icons mail_new\'
3097 3276
 			});
3098 3277
 		});');
3278
+	}
3099 3279
 
3100 3280
 	// Add a generic "Are you sure?" confirmation message.
3101 3281
 	addInlineJavaScript('
3102 3282
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3103 3283
 
3104 3284
 	// Now add the capping code for avatars.
3105
-	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')
3106
-		addInlineCss('
3285
+	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') {
3286
+			addInlineCss('
3107 3287
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3288
+	}
3108 3289
 
3109 3290
 	// This looks weird, but it's because BoardIndex.php references the variable.
3110 3291
 	$context['common_stats']['latest_member'] = array(
@@ -3121,11 +3302,13 @@  discard block
 block discarded – undo
3121 3302
 	);
3122 3303
 	$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']);
3123 3304
 
3124
-	if (empty($settings['theme_version']))
3125
-		addJavaScriptVar('smf_scripturl', $scripturl);
3305
+	if (empty($settings['theme_version'])) {
3306
+			addJavaScriptVar('smf_scripturl', $scripturl);
3307
+	}
3126 3308
 
3127
-	if (!isset($context['page_title']))
3128
-		$context['page_title'] = '';
3309
+	if (!isset($context['page_title'])) {
3310
+			$context['page_title'] = '';
3311
+	}
3129 3312
 
3130 3313
 	// Set some specific vars.
3131 3314
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3135,21 +3318,23 @@  discard block
 block discarded – undo
3135 3318
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3136 3319
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3137 3320
 
3138
-	if (!empty($context['meta_keywords']))
3139
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3321
+	if (!empty($context['meta_keywords'])) {
3322
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3323
+	}
3140 3324
 
3141
-	if (!empty($context['canonical_url']))
3142
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3325
+	if (!empty($context['canonical_url'])) {
3326
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3327
+	}
3143 3328
 
3144
-	if (!empty($settings['og_image']))
3145
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3329
+	if (!empty($settings['og_image'])) {
3330
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3331
+	}
3146 3332
 
3147 3333
 	if (!empty($context['meta_description']))
3148 3334
 	{
3149 3335
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3150 3336
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3151
-	}
3152
-	else
3337
+	} else
3153 3338
 	{
3154 3339
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3155 3340
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3175,8 +3360,9 @@  discard block
 block discarded – undo
3175 3360
 	$memory_needed = memoryReturnBytes($needed);
3176 3361
 
3177 3362
 	// should we account for how much is currently being used?
3178
-	if ($in_use)
3179
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3363
+	if ($in_use) {
3364
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3365
+	}
3180 3366
 
3181 3367
 	// if more is needed, request it
3182 3368
 	if ($memory_current < $memory_needed)
@@ -3199,8 +3385,9 @@  discard block
 block discarded – undo
3199 3385
  */
3200 3386
 function memoryReturnBytes($val)
3201 3387
 {
3202
-	if (is_integer($val))
3203
-		return $val;
3388
+	if (is_integer($val)) {
3389
+			return $val;
3390
+	}
3204 3391
 
3205 3392
 	// Separate the number from the designator
3206 3393
 	$val = trim($val);
@@ -3236,10 +3423,11 @@  discard block
 block discarded – undo
3236 3423
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3237 3424
 
3238 3425
 		// Are we debugging the template/html content?
3239
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3240
-			header('Content-Type: application/xhtml+xml');
3241
-		elseif (!isset($_REQUEST['xml']))
3242
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3426
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3427
+					header('Content-Type: application/xhtml+xml');
3428
+		} elseif (!isset($_REQUEST['xml'])) {
3429
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3430
+		}
3243 3431
 	}
3244 3432
 
3245 3433
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3248,8 +3436,9 @@  discard block
 block discarded – undo
3248 3436
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3249 3437
 	{
3250 3438
 		$position = array_search('body', $context['template_layers']);
3251
-		if ($position === false)
3252
-			$position = array_search('main', $context['template_layers']);
3439
+		if ($position === false) {
3440
+					$position = array_search('main', $context['template_layers']);
3441
+		}
3253 3442
 
3254 3443
 		if ($position !== false)
3255 3444
 		{
@@ -3277,15 +3466,15 @@  discard block
 block discarded – undo
3277 3466
 
3278 3467
 			foreach ($securityFiles as $i => $securityFile)
3279 3468
 			{
3280
-				if (!file_exists($boarddir . '/' . $securityFile))
3281
-					unset($securityFiles[$i]);
3469
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3470
+									unset($securityFiles[$i]);
3471
+				}
3282 3472
 			}
3283 3473
 
3284 3474
 			// We are already checking so many files...just few more doesn't make any difference! :P
3285
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3286
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3287
-
3288
-			else
3475
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3476
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3477
+			} else
3289 3478
 			{
3290 3479
 				$path = $modSettings['attachmentUploadDir'];
3291 3480
 				$id_folder_thumb = 1;
@@ -3294,8 +3483,9 @@  discard block
 block discarded – undo
3294 3483
 			secureDirectory($cachedir);
3295 3484
 
3296 3485
 			// If agreement is enabled, at least the english version shall exists
3297
-			if ($modSettings['requireAgreement'])
3298
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3486
+			if ($modSettings['requireAgreement']) {
3487
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3488
+			}
3299 3489
 
3300 3490
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3301 3491
 			{
@@ -3310,18 +3500,21 @@  discard block
 block discarded – undo
3310 3500
 					echo '
3311 3501
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3312 3502
 
3313
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3314
-						echo '
3503
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3504
+											echo '
3315 3505
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3506
+					}
3316 3507
 				}
3317 3508
 
3318
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3319
-					echo '
3509
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3510
+									echo '
3320 3511
 				<strong>', $txt['cache_writable'], '</strong><br>';
3512
+				}
3321 3513
 
3322
-				if (!empty($agreement))
3323
-					echo '
3514
+				if (!empty($agreement)) {
3515
+									echo '
3324 3516
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3517
+				}
3325 3518
 
3326 3519
 				echo '
3327 3520
 			</p>
@@ -3336,16 +3529,18 @@  discard block
 block discarded – undo
3336 3529
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3337 3530
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3338 3531
 
3339
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3340
-				echo '
3532
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3533
+							echo '
3341 3534
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3535
+			}
3342 3536
 
3343
-			if (!empty($_SESSION['ban']['expire_time']))
3344
-				echo '
3537
+			if (!empty($_SESSION['ban']['expire_time'])) {
3538
+							echo '
3345 3539
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3346
-			else
3347
-				echo '
3540
+			} else {
3541
+							echo '
3348 3542
 					<div>', $txt['your_ban_expires_never'], '</div>';
3543
+			}
3349 3544
 
3350 3545
 			echo '
3351 3546
 				</div>';
@@ -3361,8 +3556,9 @@  discard block
 block discarded – undo
3361 3556
 	global $forum_copyright, $software_year, $forum_version;
3362 3557
 
3363 3558
 	// Don't display copyright for things like SSI.
3364
-	if (!isset($forum_version) || !isset($software_year))
3365
-		return;
3559
+	if (!isset($forum_version) || !isset($software_year)) {
3560
+			return;
3561
+	}
3366 3562
 
3367 3563
 	// Put in the version...
3368 3564
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3380,9 +3576,10 @@  discard block
 block discarded – undo
3380 3576
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3381 3577
 	$context['load_queries'] = $db_count;
3382 3578
 
3383
-	foreach (array_reverse($context['template_layers']) as $layer)
3384
-		loadSubTemplate($layer . '_below', true);
3385
-}
3579
+	foreach (array_reverse($context['template_layers']) as $layer) {
3580
+			loadSubTemplate($layer . '_below', true);
3581
+	}
3582
+	}
3386 3583
 
3387 3584
 /**
3388 3585
  * Output the Javascript files
@@ -3413,8 +3610,7 @@  discard block
 block discarded – undo
3413 3610
 			{
3414 3611
 				echo '
3415 3612
 		var ', $key, ';';
3416
-			}
3417
-			else
3613
+			} else
3418 3614
 			{
3419 3615
 				echo '
3420 3616
 		var ', $key, ' = ', $value, ';';
@@ -3429,26 +3625,27 @@  discard block
 block discarded – undo
3429 3625
 	foreach ($context['javascript_files'] as $id => $js_file)
3430 3626
 	{
3431 3627
 		// Last minute call! allow theme authors to disable single files.
3432
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3433
-			continue;
3628
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3629
+					continue;
3630
+		}
3434 3631
 
3435 3632
 		// By default all files don't get minimized unless the file explicitly says so!
3436 3633
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3437 3634
 		{
3438
-			if ($do_deferred && !empty($js_file['options']['defer']))
3439
-				$toMinifyDefer[] = $js_file;
3440
-
3441
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3442
-				$toMinify[] = $js_file;
3635
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3636
+							$toMinifyDefer[] = $js_file;
3637
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3638
+							$toMinify[] = $js_file;
3639
+			}
3443 3640
 
3444 3641
 			// Grab a random seed.
3445
-			if (!isset($minSeed))
3446
-				$minSeed = $js_file['options']['seed'];
3447
-		}
3448
-
3449
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3450
-			echo '
3642
+			if (!isset($minSeed)) {
3643
+							$minSeed = $js_file['options']['seed'];
3644
+			}
3645
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3646
+					echo '
3451 3647
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3648
+		}
3452 3649
 	}
3453 3650
 
3454 3651
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3456,14 +3653,14 @@  discard block
 block discarded – undo
3456 3653
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3457 3654
 
3458 3655
 		// Minify process couldn't work, print each individual files.
3459
-		if (!empty($result) && is_array($result))
3460
-			foreach ($result as $minFailedFile)
3656
+		if (!empty($result) && is_array($result)) {
3657
+					foreach ($result as $minFailedFile)
3461 3658
 				echo '
3462 3659
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3463
-
3464
-		else
3465
-			echo '
3660
+		} else {
3661
+					echo '
3466 3662
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3663
+		}
3467 3664
 	}
3468 3665
 
3469 3666
 	// Inline JavaScript - Actually useful some times!
@@ -3474,8 +3671,9 @@  discard block
 block discarded – undo
3474 3671
 			echo '
3475 3672
 <script>';
3476 3673
 
3477
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3478
-				echo $js_code;
3674
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3675
+							echo $js_code;
3676
+			}
3479 3677
 
3480 3678
 			echo '
3481 3679
 </script>';
@@ -3486,8 +3684,9 @@  discard block
 block discarded – undo
3486 3684
 			echo '
3487 3685
 	<script>';
3488 3686
 
3489
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3490
-				echo $js_code;
3687
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3688
+							echo $js_code;
3689
+			}
3491 3690
 
3492 3691
 			echo '
3493 3692
 	</script>';
@@ -3512,8 +3711,9 @@  discard block
 block discarded – undo
3512 3711
 	foreach ($context['css_files'] as $id => $file)
3513 3712
 	{
3514 3713
 		// Last minute call! allow theme authors to disable single files.
3515
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3516
-			continue;
3714
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3715
+					continue;
3716
+		}
3517 3717
 
3518 3718
 		// By default all files don't get minimized unless the file explicitly says so!
3519 3719
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3521,12 +3721,12 @@  discard block
 block discarded – undo
3521 3721
 			$toMinify[] = $file;
3522 3722
 
3523 3723
 			// Grab a random seed.
3524
-			if (!isset($minSeed))
3525
-				$minSeed = $file['options']['seed'];
3724
+			if (!isset($minSeed)) {
3725
+							$minSeed = $file['options']['seed'];
3726
+			}
3727
+		} else {
3728
+					$normal[] = $file['fileUrl'];
3526 3729
 		}
3527
-
3528
-		else
3529
-			$normal[] = $file['fileUrl'];
3530 3730
 	}
3531 3731
 
3532 3732
 	if (!empty($toMinify))
@@ -3534,28 +3734,30 @@  discard block
 block discarded – undo
3534 3734
 		$result = custMinify($toMinify, 'css');
3535 3735
 
3536 3736
 		// Minify process couldn't work, print each individual files.
3537
-		if (!empty($result) && is_array($result))
3538
-			foreach ($result as $minFailedFile)
3737
+		if (!empty($result) && is_array($result)) {
3738
+					foreach ($result as $minFailedFile)
3539 3739
 				echo '
3540 3740
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3541
-
3542
-		else
3543
-			echo '
3741
+		} else {
3742
+					echo '
3544 3743
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3744
+		}
3545 3745
 	}
3546 3746
 
3547 3747
 	// Print the rest after the minified files.
3548
-	if (!empty($normal))
3549
-		foreach ($normal as $nf)
3748
+	if (!empty($normal)) {
3749
+			foreach ($normal as $nf)
3550 3750
 			echo '
3551 3751
 	<link rel="stylesheet" href="', $nf ,'">';
3752
+	}
3552 3753
 
3553 3754
 	if ($db_show_debug === true)
3554 3755
 	{
3555 3756
 		// Try to keep only what's useful.
3556 3757
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3557
-		foreach ($context['css_files'] as $file)
3558
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3758
+		foreach ($context['css_files'] as $file) {
3759
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3760
+		}
3559 3761
 	}
3560 3762
 
3561 3763
 	if (!empty($context['css_header']))
@@ -3563,9 +3765,10 @@  discard block
 block discarded – undo
3563 3765
 		echo '
3564 3766
 	<style>';
3565 3767
 
3566
-		foreach ($context['css_header'] as $css)
3567
-			echo $css .'
3768
+		foreach ($context['css_header'] as $css) {
3769
+					echo $css .'
3568 3770
 	';
3771
+		}
3569 3772
 
3570 3773
 		echo'
3571 3774
 	</style>';
@@ -3590,15 +3793,17 @@  discard block
 block discarded – undo
3590 3793
 	$data = !empty($data) ? $data : false;
3591 3794
 	$minFailed = array();
3592 3795
 
3593
-	if (empty($type) || empty($data))
3594
-		return false;
3796
+	if (empty($type) || empty($data)) {
3797
+			return false;
3798
+	}
3595 3799
 
3596 3800
 	// Did we already did this?
3597 3801
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3598 3802
 
3599 3803
 	// Already done?
3600
-	if (!empty($toCache))
3601
-		return true;
3804
+	if (!empty($toCache)) {
3805
+			return true;
3806
+	}
3602 3807
 
3603 3808
 	// Yep, need a bunch of files.
3604 3809
 	require_once($sourcedir . '/minify/src/Minify.php');
@@ -3686,8 +3891,9 @@  discard block
 block discarded – undo
3686 3891
 	global $modSettings, $smcFunc;
3687 3892
 
3688 3893
 	// Just make up a nice hash...
3689
-	if ($new)
3690
-		return sha1(md5($filename . time()) . mt_rand());
3894
+	if ($new) {
3895
+			return sha1(md5($filename . time()) . mt_rand());
3896
+	}
3691 3897
 
3692 3898
 	// Grab the file hash if it wasn't added.
3693 3899
 	// Left this for legacy.
@@ -3701,23 +3907,25 @@  discard block
 block discarded – undo
3701 3907
 				'id_attach' => $attachment_id,
3702 3908
 			));
3703 3909
 
3704
-		if ($smcFunc['db_num_rows']($request) === 0)
3705
-			return false;
3910
+		if ($smcFunc['db_num_rows']($request) === 0) {
3911
+					return false;
3912
+		}
3706 3913
 
3707 3914
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3708 3915
 		$smcFunc['db_free_result']($request);
3709 3916
 	}
3710 3917
 
3711 3918
 	// Still no hash? mmm...
3712
-	if (empty($file_hash))
3713
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3919
+	if (empty($file_hash)) {
3920
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3921
+	}
3714 3922
 
3715 3923
 	// Are we using multiple directories?
3716
-	if (!empty($modSettings['currentAttachmentUploadDir']))
3717
-		$path = $modSettings['attachmentUploadDir'][$dir];
3718
-
3719
-	else
3720
-		$path = $modSettings['attachmentUploadDir'];
3924
+	if (!empty($modSettings['currentAttachmentUploadDir'])) {
3925
+			$path = $modSettings['attachmentUploadDir'][$dir];
3926
+	} else {
3927
+			$path = $modSettings['attachmentUploadDir'];
3928
+	}
3721 3929
 
3722 3930
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3723 3931
 }
@@ -3732,8 +3940,9 @@  discard block
 block discarded – undo
3732 3940
 function ip2range($fullip)
3733 3941
 {
3734 3942
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3735
-	if ($fullip == 'unknown')
3736
-		$fullip = '255.255.255.255';
3943
+	if ($fullip == 'unknown') {
3944
+			$fullip = '255.255.255.255';
3945
+	}
3737 3946
 
3738 3947
 	$ip_parts = explode('-', $fullip);
3739 3948
 	$ip_array = array();
@@ -3757,10 +3966,11 @@  discard block
 block discarded – undo
3757 3966
 		$ip_array['low'] = $ip_parts[0];
3758 3967
 		$ip_array['high'] = $ip_parts[1];
3759 3968
 		return $ip_array;
3760
-	}
3761
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
3969
+	} elseif (count($ip_parts) == 2) {
3970
+		// if ip 22.22.*-22.22.*
3762 3971
 	{
3763 3972
 		$valid_low = isValidIP($ip_parts[0]);
3973
+	}
3764 3974
 		$valid_high = isValidIP($ip_parts[1]);
3765 3975
 		$count = 0;
3766 3976
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3775,7 +3985,9 @@  discard block
 block discarded – undo
3775 3985
 				$ip_parts[0] .= $mode . $min;
3776 3986
 				$valid_low = isValidIP($ip_parts[0]);
3777 3987
 				$count++;
3778
-				if ($count > 9) break;
3988
+				if ($count > 9) {
3989
+					break;
3990
+				}
3779 3991
 			}
3780 3992
 		}
3781 3993
 
@@ -3789,7 +4001,9 @@  discard block
 block discarded – undo
3789 4001
 				$ip_parts[1] .= $mode . $max;
3790 4002
 				$valid_high = isValidIP($ip_parts[1]);
3791 4003
 				$count++;
3792
-				if ($count > 9) break;
4004
+				if ($count > 9) {
4005
+					break;
4006
+				}
3793 4007
 			}
3794 4008
 		}
3795 4009
 
@@ -3814,46 +4028,54 @@  discard block
 block discarded – undo
3814 4028
 {
3815 4029
 	global $modSettings;
3816 4030
 
3817
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3818
-		return $host;
4031
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4032
+			return $host;
4033
+	}
3819 4034
 	$t = microtime();
3820 4035
 
3821 4036
 	// Try the Linux host command, perhaps?
3822 4037
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3823 4038
 	{
3824
-		if (!isset($modSettings['host_to_dis']))
3825
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3826
-		else
3827
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4039
+		if (!isset($modSettings['host_to_dis'])) {
4040
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4041
+		} else {
4042
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4043
+		}
3828 4044
 
3829 4045
 		// Did host say it didn't find anything?
3830
-		if (strpos($test, 'not found') !== false)
3831
-			$host = '';
4046
+		if (strpos($test, 'not found') !== false) {
4047
+					$host = '';
4048
+		}
3832 4049
 		// Invalid server option?
3833
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3834
-			updateSettings(array('host_to_dis' => 1));
4050
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4051
+					updateSettings(array('host_to_dis' => 1));
4052
+		}
3835 4053
 		// Maybe it found something, after all?
3836
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3837
-			$host = $match[1];
4054
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4055
+					$host = $match[1];
4056
+		}
3838 4057
 	}
3839 4058
 
3840 4059
 	// This is nslookup; usually only Windows, but possibly some Unix?
3841 4060
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3842 4061
 	{
3843 4062
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3844
-		if (strpos($test, 'Non-existent domain') !== false)
3845
-			$host = '';
3846
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3847
-			$host = $match[1];
4063
+		if (strpos($test, 'Non-existent domain') !== false) {
4064
+					$host = '';
4065
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4066
+					$host = $match[1];
4067
+		}
3848 4068
 	}
3849 4069
 
3850 4070
 	// This is the last try :/.
3851
-	if (!isset($host) || $host === false)
3852
-		$host = @gethostbyaddr($ip);
4071
+	if (!isset($host) || $host === false) {
4072
+			$host = @gethostbyaddr($ip);
4073
+	}
3853 4074
 
3854 4075
 	// It took a long time, so let's cache it!
3855
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3856
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4076
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4077
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4078
+	}
3857 4079
 
3858 4080
 	return $host;
3859 4081
 }
@@ -3889,20 +4111,21 @@  discard block
 block discarded – undo
3889 4111
 			{
3890 4112
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3891 4113
 				$total = 0;
3892
-				for ($i = 0; $i < $max_chars; $i++)
3893
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4114
+				for ($i = 0; $i < $max_chars; $i++) {
4115
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4116
+				}
3894 4117
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3895 4118
 			}
3896 4119
 		}
3897 4120
 		return array_unique($returned_ints);
3898
-	}
3899
-	else
4121
+	} else
3900 4122
 	{
3901 4123
 		// Trim characters before and after and add slashes for database insertion.
3902 4124
 		$returned_words = array();
3903
-		foreach ($words as $word)
3904
-			if (($word = trim($word, '-_\'')) !== '')
4125
+		foreach ($words as $word) {
4126
+					if (($word = trim($word, '-_\'')) !== '')
3905 4127
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4128
+		}
3906 4129
 
3907 4130
 		// Filter out all words that occur more than once.
3908 4131
 		return array_unique($returned_words);
@@ -3924,16 +4147,18 @@  discard block
 block discarded – undo
3924 4147
 	global $settings, $txt;
3925 4148
 
3926 4149
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3927
-	if (function_exists('template_create_button') && !$force_use)
3928
-		return template_create_button($name, $alt, $label = '', $custom = '');
4150
+	if (function_exists('template_create_button') && !$force_use) {
4151
+			return template_create_button($name, $alt, $label = '', $custom = '');
4152
+	}
3929 4153
 
3930
-	if (!$settings['use_image_buttons'])
3931
-		return $txt[$alt];
3932
-	elseif (!empty($settings['use_buttons']))
3933
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3934
-	else
3935
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3936
-}
4154
+	if (!$settings['use_image_buttons']) {
4155
+			return $txt[$alt];
4156
+	} elseif (!empty($settings['use_buttons'])) {
4157
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4158
+	} else {
4159
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4160
+	}
4161
+	}
3937 4162
 
3938 4163
 /**
3939 4164
  * Sets up all of the top menu buttons
@@ -3976,9 +4201,10 @@  discard block
 block discarded – undo
3976 4201
 	var user_menus = new smc_PopupMenu();
3977 4202
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3978 4203
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3979
-		if ($context['allow_pm'])
3980
-			addInlineJavaScript('
4204
+		if ($context['allow_pm']) {
4205
+					addInlineJavaScript('
3981 4206
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4207
+		}
3982 4208
 
3983 4209
 		if (!empty($modSettings['enable_ajax_alerts']))
3984 4210
 		{
@@ -4138,88 +4364,96 @@  discard block
 block discarded – undo
4138 4364
 
4139 4365
 		// Now we put the buttons in the context so the theme can use them.
4140 4366
 		$menu_buttons = array();
4141
-		foreach ($buttons as $act => $button)
4142
-			if (!empty($button['show']))
4367
+		foreach ($buttons as $act => $button) {
4368
+					if (!empty($button['show']))
4143 4369
 			{
4144 4370
 				$button['active_button'] = false;
4371
+		}
4145 4372
 
4146 4373
 				// This button needs some action.
4147
-				if (isset($button['action_hook']))
4148
-					$needs_action_hook = true;
4374
+				if (isset($button['action_hook'])) {
4375
+									$needs_action_hook = true;
4376
+				}
4149 4377
 
4150 4378
 				// Make sure the last button truly is the last button.
4151 4379
 				if (!empty($button['is_last']))
4152 4380
 				{
4153
-					if (isset($last_button))
4154
-						unset($menu_buttons[$last_button]['is_last']);
4381
+					if (isset($last_button)) {
4382
+											unset($menu_buttons[$last_button]['is_last']);
4383
+					}
4155 4384
 					$last_button = $act;
4156 4385
 				}
4157 4386
 
4158 4387
 				// Go through the sub buttons if there are any.
4159
-				if (!empty($button['sub_buttons']))
4160
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4388
+				if (!empty($button['sub_buttons'])) {
4389
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4161 4390
 					{
4162 4391
 						if (empty($subbutton['show']))
4163 4392
 							unset($button['sub_buttons'][$key]);
4393
+				}
4164 4394
 
4165 4395
 						// 2nd level sub buttons next...
4166 4396
 						if (!empty($subbutton['sub_buttons']))
4167 4397
 						{
4168 4398
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4169 4399
 							{
4170
-								if (empty($sub_button2['show']))
4171
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4400
+								if (empty($sub_button2['show'])) {
4401
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4402
+								}
4172 4403
 							}
4173 4404
 						}
4174 4405
 					}
4175 4406
 
4176 4407
 				// Does this button have its own icon?
4177
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4178
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4179
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4180
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4181
-				elseif (isset($button['icon']))
4182
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4183
-				else
4184
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4408
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4409
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4410
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4411
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4412
+				} elseif (isset($button['icon'])) {
4413
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4414
+				} else {
4415
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4416
+				}
4185 4417
 
4186 4418
 				$menu_buttons[$act] = $button;
4187 4419
 			}
4188 4420
 
4189
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4190
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4421
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4422
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4423
+		}
4191 4424
 	}
4192 4425
 
4193 4426
 	$context['menu_buttons'] = $menu_buttons;
4194 4427
 
4195 4428
 	// Logging out requires the session id in the url.
4196
-	if (isset($context['menu_buttons']['logout']))
4197
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4429
+	if (isset($context['menu_buttons']['logout'])) {
4430
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4431
+	}
4198 4432
 
4199 4433
 	// Figure out which action we are doing so we can set the active tab.
4200 4434
 	// Default to home.
4201 4435
 	$current_action = 'home';
4202 4436
 
4203
-	if (isset($context['menu_buttons'][$context['current_action']]))
4204
-		$current_action = $context['current_action'];
4205
-	elseif ($context['current_action'] == 'search2')
4206
-		$current_action = 'search';
4207
-	elseif ($context['current_action'] == 'theme')
4208
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4209
-	elseif ($context['current_action'] == 'register2')
4210
-		$current_action = 'register';
4211
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4212
-		$current_action = 'login';
4213
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4214
-		$current_action = 'moderate';
4437
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4438
+			$current_action = $context['current_action'];
4439
+	} elseif ($context['current_action'] == 'search2') {
4440
+			$current_action = 'search';
4441
+	} elseif ($context['current_action'] == 'theme') {
4442
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4443
+	} elseif ($context['current_action'] == 'register2') {
4444
+			$current_action = 'register';
4445
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4446
+			$current_action = 'login';
4447
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4448
+			$current_action = 'moderate';
4449
+	}
4215 4450
 
4216 4451
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4217 4452
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4218 4453
 	{
4219 4454
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4220 4455
 		$context[$current_action] = true;
4221
-	}
4222
-	elseif ($context['current_action'] == 'pm')
4456
+	} elseif ($context['current_action'] == 'pm')
4223 4457
 	{
4224 4458
 		$current_action = 'self_pm';
4225 4459
 		$context['self_pm'] = true;
@@ -4262,12 +4496,14 @@  discard block
 block discarded – undo
4262 4496
 	}
4263 4497
 
4264 4498
 	// Not all actions are simple.
4265
-	if (!empty($needs_action_hook))
4266
-		call_integration_hook('integrate_current_action', array(&$current_action));
4499
+	if (!empty($needs_action_hook)) {
4500
+			call_integration_hook('integrate_current_action', array(&$current_action));
4501
+	}
4267 4502
 
4268
-	if (isset($context['menu_buttons'][$current_action]))
4269
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4270
-}
4503
+	if (isset($context['menu_buttons'][$current_action])) {
4504
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4505
+	}
4506
+	}
4271 4507
 
4272 4508
 /**
4273 4509
  * Generate a random seed and ensure it's stored in settings.
@@ -4291,16 +4527,19 @@  discard block
 block discarded – undo
4291 4527
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4292 4528
 	global $context, $txt;
4293 4529
 
4294
-	if ($db_show_debug === true)
4295
-		$context['debug']['hooks'][] = $hook;
4530
+	if ($db_show_debug === true) {
4531
+			$context['debug']['hooks'][] = $hook;
4532
+	}
4296 4533
 
4297 4534
 	// Need to have some control.
4298
-	if (!isset($context['instances']))
4299
-		$context['instances'] = array();
4535
+	if (!isset($context['instances'])) {
4536
+			$context['instances'] = array();
4537
+	}
4300 4538
 
4301 4539
 	$results = array();
4302
-	if (empty($modSettings[$hook]))
4303
-		return $results;
4540
+	if (empty($modSettings[$hook])) {
4541
+			return $results;
4542
+	}
4304 4543
 
4305 4544
 	// Define some needed vars.
4306 4545
 	$function = false;
@@ -4310,14 +4549,16 @@  discard block
 block discarded – undo
4310 4549
 	foreach ($functions as $function)
4311 4550
 	{
4312 4551
 		// Hook has been marked as "disabled". Skip it!
4313
-		if (strpos($function, '!') !== false)
4314
-			continue;
4552
+		if (strpos($function, '!') !== false) {
4553
+					continue;
4554
+		}
4315 4555
 
4316 4556
 		$call = call_helper($function, true);
4317 4557
 
4318 4558
 		// Is it valid?
4319
-		if (!empty($call))
4320
-			$results[$function] = call_user_func_array($call, $parameters);
4559
+		if (!empty($call)) {
4560
+					$results[$function] = call_user_func_array($call, $parameters);
4561
+		}
4321 4562
 
4322 4563
 		// Whatever it was suppose to call, it failed :(
4323 4564
 		elseif (!empty($function))
@@ -4333,8 +4574,9 @@  discard block
 block discarded – undo
4333 4574
 			}
4334 4575
 
4335 4576
 			// "Assume" the file resides on $boarddir somewhere...
4336
-			else
4337
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4577
+			else {
4578
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4579
+			}
4338 4580
 		}
4339 4581
 	}
4340 4582
 
@@ -4356,12 +4598,14 @@  discard block
 block discarded – undo
4356 4598
 	global $smcFunc, $modSettings;
4357 4599
 
4358 4600
 	// Any objects?
4359
-	if ($object)
4360
-		$function = $function . '#';
4601
+	if ($object) {
4602
+			$function = $function . '#';
4603
+	}
4361 4604
 
4362 4605
 	// Any files  to load?
4363
-	if (!empty($file) && is_string($file))
4364
-		$function = $file . (!empty($function) ? '|' . $function : '');
4606
+	if (!empty($file) && is_string($file)) {
4607
+			$function = $file . (!empty($function) ? '|' . $function : '');
4608
+	}
4365 4609
 
4366 4610
 	// Get the correct string.
4367 4611
 	$integration_call = $function;
@@ -4383,13 +4627,14 @@  discard block
 block discarded – undo
4383 4627
 		if (!empty($current_functions))
4384 4628
 		{
4385 4629
 			$current_functions = explode(',', $current_functions);
4386
-			if (in_array($integration_call, $current_functions))
4387
-				return;
4630
+			if (in_array($integration_call, $current_functions)) {
4631
+							return;
4632
+			}
4388 4633
 
4389 4634
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4635
+		} else {
4636
+					$permanent_functions = array($integration_call);
4390 4637
 		}
4391
-		else
4392
-			$permanent_functions = array($integration_call);
4393 4638
 
4394 4639
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4395 4640
 	}
@@ -4398,8 +4643,9 @@  discard block
 block discarded – undo
4398 4643
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4399 4644
 
4400 4645
 	// Do nothing, if it's already there.
4401
-	if (in_array($integration_call, $functions))
4402
-		return;
4646
+	if (in_array($integration_call, $functions)) {
4647
+			return;
4648
+	}
4403 4649
 
4404 4650
 	$functions[] = $integration_call;
4405 4651
 	$modSettings[$hook] = implode(',', $functions);
@@ -4422,12 +4668,14 @@  discard block
 block discarded – undo
4422 4668
 	global $smcFunc, $modSettings;
4423 4669
 
4424 4670
 	// Any objects?
4425
-	if ($object)
4426
-		$function = $function . '#';
4671
+	if ($object) {
4672
+			$function = $function . '#';
4673
+	}
4427 4674
 
4428 4675
 	// Any files  to load?
4429
-	if (!empty($file) && is_string($file))
4430
-		$function = $file . '|' . $function;
4676
+	if (!empty($file) && is_string($file)) {
4677
+			$function = $file . '|' . $function;
4678
+	}
4431 4679
 
4432 4680
 	// Get the correct string.
4433 4681
 	$integration_call = $function;
@@ -4448,16 +4696,18 @@  discard block
 block discarded – undo
4448 4696
 	{
4449 4697
 		$current_functions = explode(',', $current_functions);
4450 4698
 
4451
-		if (in_array($integration_call, $current_functions))
4452
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4699
+		if (in_array($integration_call, $current_functions)) {
4700
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4701
+		}
4453 4702
 	}
4454 4703
 
4455 4704
 	// Turn the function list into something usable.
4456 4705
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4457 4706
 
4458 4707
 	// You can only remove it if it's available.
4459
-	if (!in_array($integration_call, $functions))
4460
-		return;
4708
+	if (!in_array($integration_call, $functions)) {
4709
+			return;
4710
+	}
4461 4711
 
4462 4712
 	$functions = array_diff($functions, array($integration_call));
4463 4713
 	$modSettings[$hook] = implode(',', $functions);
@@ -4478,17 +4728,20 @@  discard block
 block discarded – undo
4478 4728
 	global $context, $smcFunc, $txt, $db_show_debug;
4479 4729
 
4480 4730
 	// Really?
4481
-	if (empty($string))
4482
-		return false;
4731
+	if (empty($string)) {
4732
+			return false;
4733
+	}
4483 4734
 
4484 4735
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4485 4736
 	// A closure? should be a callable one.
4486
-	if (is_array($string) || $string instanceof Closure)
4487
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4737
+	if (is_array($string) || $string instanceof Closure) {
4738
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4739
+	}
4488 4740
 
4489 4741
 	// No full objects, sorry! pass a method or a property instead!
4490
-	if (is_object($string))
4491
-		return false;
4742
+	if (is_object($string)) {
4743
+			return false;
4744
+	}
4492 4745
 
4493 4746
 	// Stay vitaminized my friends...
4494 4747
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4500,8 +4753,9 @@  discard block
 block discarded – undo
4500 4753
 	$string = load_file($string);
4501 4754
 
4502 4755
 	// Loaded file failed
4503
-	if (empty($string))
4504
-		return false;
4756
+	if (empty($string)) {
4757
+			return false;
4758
+	}
4505 4759
 
4506 4760
 	// Found a method.
4507 4761
 	if (strpos($string, '::') !== false)
@@ -4522,8 +4776,9 @@  discard block
 block discarded – undo
4522 4776
 				// Add another one to the list.
4523 4777
 				if ($db_show_debug === true)
4524 4778
 				{
4525
-					if (!isset($context['debug']['instances']))
4526
-						$context['debug']['instances'] = array();
4779
+					if (!isset($context['debug']['instances'])) {
4780
+											$context['debug']['instances'] = array();
4781
+					}
4527 4782
 
4528 4783
 					$context['debug']['instances'][$class] = $class;
4529 4784
 				}
@@ -4533,13 +4788,15 @@  discard block
 block discarded – undo
4533 4788
 		}
4534 4789
 
4535 4790
 		// Right then. This is a call to a static method.
4536
-		else
4537
-			$func = array($class, $method);
4791
+		else {
4792
+					$func = array($class, $method);
4793
+		}
4538 4794
 	}
4539 4795
 
4540 4796
 	// Nope! just a plain regular function.
4541
-	else
4542
-		$func = $string;
4797
+	else {
4798
+			$func = $string;
4799
+	}
4543 4800
 
4544 4801
 	// Right, we got what we need, time to do some checks.
4545 4802
 	if (!is_callable($func, false, $callable_name))
@@ -4555,17 +4812,18 @@  discard block
 block discarded – undo
4555 4812
 	else
4556 4813
 	{
4557 4814
 		// What are we gonna do about it?
4558
-		if ($return)
4559
-			return $func;
4815
+		if ($return) {
4816
+					return $func;
4817
+		}
4560 4818
 
4561 4819
 		// If this is a plain function, avoid the heat of calling call_user_func().
4562 4820
 		else
4563 4821
 		{
4564
-			if (is_array($func))
4565
-				call_user_func($func);
4566
-
4567
-			else
4568
-				$func();
4822
+			if (is_array($func)) {
4823
+							call_user_func($func);
4824
+			} else {
4825
+							$func();
4826
+			}
4569 4827
 		}
4570 4828
 	}
4571 4829
 }
@@ -4582,31 +4840,34 @@  discard block
 block discarded – undo
4582 4840
 {
4583 4841
 	global $sourcedir, $txt, $boarddir, $settings;
4584 4842
 
4585
-	if (empty($string))
4586
-		return false;
4843
+	if (empty($string)) {
4844
+			return false;
4845
+	}
4587 4846
 
4588 4847
 	if (strpos($string, '|') !== false)
4589 4848
 	{
4590 4849
 		list ($file, $string) = explode('|', $string);
4591 4850
 
4592 4851
 		// Match the wildcards to their regular vars.
4593
-		if (empty($settings['theme_dir']))
4594
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4595
-
4596
-		else
4597
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4852
+		if (empty($settings['theme_dir'])) {
4853
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4854
+		} else {
4855
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4856
+		}
4598 4857
 
4599 4858
 		// Load the file if it can be loaded.
4600
-		if (file_exists($absPath))
4601
-			require_once($absPath);
4859
+		if (file_exists($absPath)) {
4860
+					require_once($absPath);
4861
+		}
4602 4862
 
4603 4863
 		// No? try a fallback to $sourcedir
4604 4864
 		else
4605 4865
 		{
4606 4866
 			$absPath = $sourcedir .'/'. $file;
4607 4867
 
4608
-			if (file_exists($absPath))
4609
-				require_once($absPath);
4868
+			if (file_exists($absPath)) {
4869
+							require_once($absPath);
4870
+			}
4610 4871
 
4611 4872
 			// Sorry, can't do much for you at this point.
4612 4873
 			else
@@ -4633,8 +4894,9 @@  discard block
 block discarded – undo
4633 4894
 	global $user_info, $smcFunc;
4634 4895
 
4635 4896
 	// Make sure we have something to work with.
4636
-	if (empty($topic))
4637
-		return array();
4897
+	if (empty($topic)) {
4898
+			return array();
4899
+	}
4638 4900
 
4639 4901
 
4640 4902
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4657,8 +4919,9 @@  discard block
 block discarded – undo
4657 4919
 				'topic' => $topic,
4658 4920
 			)
4659 4921
 		);
4660
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4661
-			$temp[] = (int) $row['content_id'];
4922
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4923
+					$temp[] = (int) $row['content_id'];
4924
+		}
4662 4925
 
4663 4926
 		cache_put_data($cache_key, $temp, $ttl);
4664 4927
 	}
@@ -4679,8 +4942,9 @@  discard block
 block discarded – undo
4679 4942
 {
4680 4943
 	global $context;
4681 4944
 
4682
-	if (empty($string))
4683
-		return $string;
4945
+	if (empty($string)) {
4946
+			return $string;
4947
+	}
4684 4948
 
4685 4949
 	// UTF-8 occurences of MS special characters
4686 4950
 	$findchars_utf8 = array(
@@ -4721,10 +4985,11 @@  discard block
 block discarded – undo
4721 4985
 		'--',	// &mdash;
4722 4986
 	);
4723 4987
 
4724
-	if ($context['utf8'])
4725
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4726
-	else
4727
-		$string = str_replace($findchars_iso, $replacechars, $string);
4988
+	if ($context['utf8']) {
4989
+			$string = str_replace($findchars_utf8, $replacechars, $string);
4990
+	} else {
4991
+			$string = str_replace($findchars_iso, $replacechars, $string);
4992
+	}
4728 4993
 
4729 4994
 	return $string;
4730 4995
 }
@@ -4743,49 +5008,59 @@  discard block
 block discarded – undo
4743 5008
 {
4744 5009
 	global $context;
4745 5010
 
4746
-	if (!isset($matches[2]))
4747
-		return '';
5011
+	if (!isset($matches[2])) {
5012
+			return '';
5013
+	}
4748 5014
 
4749 5015
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4750 5016
 
4751 5017
 	// remove left to right / right to left overrides
4752
-	if ($num === 0x202D || $num === 0x202E)
4753
-		return '';
5018
+	if ($num === 0x202D || $num === 0x202E) {
5019
+			return '';
5020
+	}
4754 5021
 
4755 5022
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4756
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4757
-		return '&#' . $num . ';';
5023
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5024
+			return '&#' . $num . ';';
5025
+	}
4758 5026
 
4759 5027
 	if (empty($context['utf8']))
4760 5028
 	{
4761 5029
 		// no control characters
4762
-		if ($num < 0x20)
4763
-			return '';
5030
+		if ($num < 0x20) {
5031
+					return '';
5032
+		}
4764 5033
 		// text is text
4765
-		elseif ($num < 0x80)
4766
-			return chr($num);
5034
+		elseif ($num < 0x80) {
5035
+					return chr($num);
5036
+		}
4767 5037
 		// all others get html-ised
4768
-		else
4769
-			return '&#' . $matches[2] . ';';
4770
-	}
4771
-	else
5038
+		else {
5039
+					return '&#' . $matches[2] . ';';
5040
+		}
5041
+	} else
4772 5042
 	{
4773 5043
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4774 5044
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4775
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4776
-			return '';
5045
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5046
+					return '';
5047
+		}
4777 5048
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4778
-		elseif ($num < 0x80)
4779
-			return chr($num);
5049
+		elseif ($num < 0x80) {
5050
+					return chr($num);
5051
+		}
4780 5052
 		// <0x800 (2048)
4781
-		elseif ($num < 0x800)
4782
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5053
+		elseif ($num < 0x800) {
5054
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5055
+		}
4783 5056
 		// < 0x10000 (65536)
4784
-		elseif ($num < 0x10000)
4785
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5057
+		elseif ($num < 0x10000) {
5058
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5059
+		}
4786 5060
 		// <= 0x10FFFF (1114111)
4787
-		else
4788
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5061
+		else {
5062
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5063
+		}
4789 5064
 	}
4790 5065
 }
4791 5066
 
@@ -4801,28 +5076,34 @@  discard block
 block discarded – undo
4801 5076
  */
4802 5077
 function fixchar__callback($matches)
4803 5078
 {
4804
-	if (!isset($matches[1]))
4805
-		return '';
5079
+	if (!isset($matches[1])) {
5080
+			return '';
5081
+	}
4806 5082
 
4807 5083
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4808 5084
 
4809 5085
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4810 5086
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4811
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4812
-		return '';
5087
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5088
+			return '';
5089
+	}
4813 5090
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4814
-	elseif ($num < 0x80)
4815
-		return chr($num);
5091
+	elseif ($num < 0x80) {
5092
+			return chr($num);
5093
+	}
4816 5094
 	// <0x800 (2048)
4817
-	elseif ($num < 0x800)
4818
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5095
+	elseif ($num < 0x800) {
5096
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5097
+	}
4819 5098
 	// < 0x10000 (65536)
4820
-	elseif ($num < 0x10000)
4821
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5099
+	elseif ($num < 0x10000) {
5100
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5101
+	}
4822 5102
 	// <= 0x10FFFF (1114111)
4823
-	else
4824
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4825
-}
5103
+	else {
5104
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5105
+	}
5106
+	}
4826 5107
 
4827 5108
 /**
4828 5109
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4835,17 +5116,19 @@  discard block
 block discarded – undo
4835 5116
  */
4836 5117
 function entity_fix__callback($matches)
4837 5118
 {
4838
-	if (!isset($matches[2]))
4839
-		return '';
5119
+	if (!isset($matches[2])) {
5120
+			return '';
5121
+	}
4840 5122
 
4841 5123
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4842 5124
 
4843 5125
 	// we don't allow control characters, characters out of range, byte markers, etc
4844
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4845
-		return '';
4846
-	else
4847
-		return '&#' . $num . ';';
4848
-}
5126
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5127
+			return '';
5128
+	} else {
5129
+			return '&#' . $num . ';';
5130
+	}
5131
+	}
4849 5132
 
4850 5133
 /**
4851 5134
  * Return a Gravatar URL based on
@@ -4869,18 +5152,23 @@  discard block
 block discarded – undo
4869 5152
 		$ratings = array('G', 'PG', 'R', 'X');
4870 5153
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4871 5154
 		$url_params = array();
4872
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4873
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4874
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4875
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4876
-		if (!empty($modSettings['avatar_max_width_external']))
4877
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4878
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4879
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5155
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5156
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5157
+		}
5158
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5159
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5160
+		}
5161
+		if (!empty($modSettings['avatar_max_width_external'])) {
5162
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5163
+		}
5164
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5165
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4880 5166
 				$size_string = $modSettings['avatar_max_height_external'];
5167
+		}
4881 5168
 
4882
-		if (!empty($size_string))
4883
-			$url_params[] = 's=' . $size_string;
5169
+		if (!empty($size_string)) {
5170
+					$url_params[] = 's=' . $size_string;
5171
+		}
4884 5172
 	}
4885 5173
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4886 5174
 
@@ -4899,22 +5187,26 @@  discard block
 block discarded – undo
4899 5187
 	static $timezones = null, $lastwhen = null;
4900 5188
 
4901 5189
 	// No point doing this over if we already did it once
4902
-	if (!empty($timezones) && $when == $lastwhen)
4903
-		return $timezones;
4904
-	else
4905
-		$lastwhen = $when;
5190
+	if (!empty($timezones) && $when == $lastwhen) {
5191
+			return $timezones;
5192
+	} else {
5193
+			$lastwhen = $when;
5194
+	}
4906 5195
 
4907 5196
 	// Parseable datetime string?
4908
-	if (is_int($timestamp = strtotime($when)))
4909
-		$when = $timestamp;
5197
+	if (is_int($timestamp = strtotime($when))) {
5198
+			$when = $timestamp;
5199
+	}
4910 5200
 
4911 5201
 	// A Unix timestamp?
4912
-	elseif (is_numeric($when))
4913
-		$when = intval($when);
5202
+	elseif (is_numeric($when)) {
5203
+			$when = intval($when);
5204
+	}
4914 5205
 
4915 5206
 	// Invalid value? Just get current Unix timestamp.
4916
-	else
4917
-		$when = time();
5207
+	else {
5208
+			$when = time();
5209
+	}
4918 5210
 
4919 5211
 	// We'll need this too
4920 5212
 	$later = (int) date_format(date_add(date_create('@' . $when), date_interval_create_from_date_string('1 year')), 'U');
@@ -4977,8 +5269,9 @@  discard block
 block discarded – undo
4977 5269
 	foreach ($priority_countries as $country)
4978 5270
 	{
4979 5271
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
4980
-		if (!empty($country_tzids))
4981
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5272
+		if (!empty($country_tzids)) {
5273
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5274
+		}
4982 5275
 	}
4983 5276
 
4984 5277
 	// Process the preferred timezones first, then the rest.
@@ -4988,8 +5281,9 @@  discard block
 block discarded – undo
4988 5281
 	foreach ($tzids as $tzid)
4989 5282
 	{
4990 5283
 		// We don't want UTC right now
4991
-		if ($tzid == 'UTC')
4992
-			continue;
5284
+		if ($tzid == 'UTC') {
5285
+					continue;
5286
+		}
4993 5287
 
4994 5288
 		// First, get the set of transition rules for this tzid
4995 5289
 		$tzinfo = timezone_transitions_get(timezone_open($tzid), $when, $later);
@@ -5000,8 +5294,9 @@  discard block
 block discarded – undo
5000 5294
 			$tz_location = timezone_location_get(timezone_open($tzid));
5001 5295
 
5002 5296
 			// Kazakstan
5003
-			if ($tz_location['country_code'] == 'KZ')
5004
-				$tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']);
5297
+			if ($tz_location['country_code'] == 'KZ') {
5298
+							$tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']);
5299
+			}
5005 5300
 
5006 5301
 			// Russia likes to experiment with time zones
5007 5302
 			if ($tz_location['country_code'] == 'RU')
@@ -5012,19 +5307,22 @@  discard block
 block discarded – undo
5012 5307
 			}
5013 5308
 
5014 5309
 			// Still no good? We'll just mark it as a UTC offset
5015
-			if (strspn($tzinfo[0]['abbr'], '+-') > 0)
5016
-				$tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr'];
5310
+			if (strspn($tzinfo[0]['abbr'], '+-') > 0) {
5311
+							$tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr'];
5312
+			}
5017 5313
 		}
5018 5314
 
5019 5315
 		$tzkey = serialize($tzinfo);
5020 5316
 
5021 5317
 		// Don't overwrite our preferred tzids
5022
-		if (empty($zones[$tzkey]['tzid']))
5023
-			$zones[$tzkey]['tzid'] = $tzid;
5318
+		if (empty($zones[$tzkey]['tzid'])) {
5319
+					$zones[$tzkey]['tzid'] = $tzid;
5320
+		}
5024 5321
 
5025 5322
 		// A time zone from a prioritized country?
5026
-		if (in_array($tzid, $priority_tzids))
5027
-			$priority_zones[$tzkey] = true;
5323
+		if (in_array($tzid, $priority_tzids)) {
5324
+					$priority_zones[$tzkey] = true;
5325
+		}
5028 5326
 
5029 5327
 		// Keep track of the location and offset for this tzid
5030 5328
 		$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop(explode('/', $tzid)));
@@ -5041,15 +5339,17 @@  discard block
 block discarded – undo
5041 5339
 	{
5042 5340
 		$tzinfo = unserialize($tzkey);
5043 5341
 
5044
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5045
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5046
-		else
5047
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5342
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5343
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5344
+		} else {
5345
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5346
+		}
5048 5347
 
5049
-		if (isset($priority_zones[$tzkey]))
5050
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5051
-		else
5052
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5348
+		if (isset($priority_zones[$tzkey])) {
5349
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5350
+		} else {
5351
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5352
+		}
5053 5353
 	}
5054 5354
 
5055 5355
 	$timezones = array_merge(
@@ -5067,8 +5367,9 @@  discard block
 block discarded – undo
5067 5367
  */
5068 5368
 function inet_ptod($ip_address)
5069 5369
 {
5070
-	if (!isValidIP($ip_address))
5071
-		return $ip_address;
5370
+	if (!isValidIP($ip_address)) {
5371
+			return $ip_address;
5372
+	}
5072 5373
 
5073 5374
 	$bin = inet_pton($ip_address);
5074 5375
 	return $bin;
@@ -5080,13 +5381,15 @@  discard block
 block discarded – undo
5080 5381
  */
5081 5382
 function inet_dtop($bin)
5082 5383
 {
5083
-	if(empty($bin))
5084
-		return '';
5384
+	if(empty($bin)) {
5385
+			return '';
5386
+	}
5085 5387
 
5086 5388
 	global $db_type;
5087 5389
 
5088
-	if ($db_type == 'postgresql')
5089
-		return $bin;
5390
+	if ($db_type == 'postgresql') {
5391
+			return $bin;
5392
+	}
5090 5393
 
5091 5394
 	$ip_address = inet_ntop($bin);
5092 5395
 
@@ -5111,26 +5414,32 @@  discard block
 block discarded – undo
5111 5414
  */
5112 5415
 function _safe_serialize($value)
5113 5416
 {
5114
-	if(is_null($value))
5115
-		return 'N;';
5417
+	if(is_null($value)) {
5418
+			return 'N;';
5419
+	}
5116 5420
 
5117
-	if(is_bool($value))
5118
-		return 'b:'. (int) $value .';';
5421
+	if(is_bool($value)) {
5422
+			return 'b:'. (int) $value .';';
5423
+	}
5119 5424
 
5120
-	if(is_int($value))
5121
-		return 'i:'. $value .';';
5425
+	if(is_int($value)) {
5426
+			return 'i:'. $value .';';
5427
+	}
5122 5428
 
5123
-	if(is_float($value))
5124
-		return 'd:'. str_replace(',', '.', $value) .';';
5429
+	if(is_float($value)) {
5430
+			return 'd:'. str_replace(',', '.', $value) .';';
5431
+	}
5125 5432
 
5126
-	if(is_string($value))
5127
-		return 's:'. strlen($value) .':"'. $value .'";';
5433
+	if(is_string($value)) {
5434
+			return 's:'. strlen($value) .':"'. $value .'";';
5435
+	}
5128 5436
 
5129 5437
 	if(is_array($value))
5130 5438
 	{
5131 5439
 		$out = '';
5132
-		foreach($value as $k => $v)
5133
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5440
+		foreach($value as $k => $v) {
5441
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5442
+		}
5134 5443
 
5135 5444
 		return 'a:'. count($value) .':{'. $out .'}';
5136 5445
 	}
@@ -5156,8 +5465,9 @@  discard block
 block discarded – undo
5156 5465
 
5157 5466
 	$out = _safe_serialize($value);
5158 5467
 
5159
-	if (isset($mbIntEnc))
5160
-		mb_internal_encoding($mbIntEnc);
5468
+	if (isset($mbIntEnc)) {
5469
+			mb_internal_encoding($mbIntEnc);
5470
+	}
5161 5471
 
5162 5472
 	return $out;
5163 5473
 }
@@ -5174,8 +5484,9 @@  discard block
 block discarded – undo
5174 5484
 function _safe_unserialize($str)
5175 5485
 {
5176 5486
 	// Input  is not a string.
5177
-	if(empty($str) || !is_string($str))
5178
-		return false;
5487
+	if(empty($str) || !is_string($str)) {
5488
+			return false;
5489
+	}
5179 5490
 
5180 5491
 	$stack = array();
5181 5492
 	$expected = array();
@@ -5191,43 +5502,38 @@  discard block
 block discarded – undo
5191 5502
 	while($state != 1)
5192 5503
 	{
5193 5504
 		$type = isset($str[0]) ? $str[0] : '';
5194
-		if($type == '}')
5195
-			$str = substr($str, 1);
5196
-
5197
-		else if($type == 'N' && $str[1] == ';')
5505
+		if($type == '}') {
5506
+					$str = substr($str, 1);
5507
+		} else if($type == 'N' && $str[1] == ';')
5198 5508
 		{
5199 5509
 			$value = null;
5200 5510
 			$str = substr($str, 2);
5201
-		}
5202
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5511
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5203 5512
 		{
5204 5513
 			$value = $matches[1] == '1' ? true : false;
5205 5514
 			$str = substr($str, 4);
5206
-		}
5207
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5515
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5208 5516
 		{
5209 5517
 			$value = (int)$matches[1];
5210 5518
 			$str = $matches[2];
5211
-		}
5212
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5519
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5213 5520
 		{
5214 5521
 			$value = (float)$matches[1];
5215 5522
 			$str = $matches[3];
5216
-		}
5217
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5523
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5218 5524
 		{
5219 5525
 			$value = substr($matches[2], 0, (int)$matches[1]);
5220 5526
 			$str = substr($matches[2], (int)$matches[1] + 2);
5221
-		}
5222
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5527
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5223 5528
 		{
5224 5529
 			$expectedLength = (int)$matches[1];
5225 5530
 			$str = $matches[2];
5226 5531
 		}
5227 5532
 
5228 5533
 		// Object or unknown/malformed type.
5229
-		else
5230
-			return false;
5534
+		else {
5535
+					return false;
5536
+		}
5231 5537
 
5232 5538
 		switch($state)
5233 5539
 		{
@@ -5255,8 +5561,9 @@  discard block
 block discarded – undo
5255 5561
 				if($type == '}')
5256 5562
 				{
5257 5563
 					// Array size is less than expected.
5258
-					if(count($list) < end($expected))
5259
-						return false;
5564
+					if(count($list) < end($expected)) {
5565
+											return false;
5566
+					}
5260 5567
 
5261 5568
 					unset($list);
5262 5569
 					$list = &$stack[count($stack)-1];
@@ -5265,8 +5572,9 @@  discard block
 block discarded – undo
5265 5572
 					// Go to terminal state if we're at the end of the root array.
5266 5573
 					array_pop($expected);
5267 5574
 
5268
-					if(count($expected) == 0)
5269
-						$state = 1;
5575
+					if(count($expected) == 0) {
5576
+											$state = 1;
5577
+					}
5270 5578
 
5271 5579
 					break;
5272 5580
 				}
@@ -5274,8 +5582,9 @@  discard block
 block discarded – undo
5274 5582
 				if($type == 'i' || $type == 's')
5275 5583
 				{
5276 5584
 					// Array size exceeds expected length.
5277
-					if(count($list) >= end($expected))
5278
-						return false;
5585
+					if(count($list) >= end($expected)) {
5586
+											return false;
5587
+					}
5279 5588
 
5280 5589
 					$key = $value;
5281 5590
 					$state = 3;
@@ -5309,8 +5618,9 @@  discard block
 block discarded – undo
5309 5618
 	}
5310 5619
 
5311 5620
 	// Trailing data in input.
5312
-	if(!empty($str))
5313
-		return false;
5621
+	if(!empty($str)) {
5622
+			return false;
5623
+	}
5314 5624
 
5315 5625
 	return $data;
5316 5626
 }
@@ -5333,8 +5643,9 @@  discard block
 block discarded – undo
5333 5643
 
5334 5644
 	$out = _safe_unserialize($str);
5335 5645
 
5336
-	if (isset($mbIntEnc))
5337
-		mb_internal_encoding($mbIntEnc);
5646
+	if (isset($mbIntEnc)) {
5647
+			mb_internal_encoding($mbIntEnc);
5648
+	}
5338 5649
 
5339 5650
 	return $out;
5340 5651
 }
@@ -5349,12 +5660,14 @@  discard block
 block discarded – undo
5349 5660
 function smf_chmod($file, $value = 0)
5350 5661
 {
5351 5662
 	// No file? no checks!
5352
-	if (empty($file))
5353
-		return false;
5663
+	if (empty($file)) {
5664
+			return false;
5665
+	}
5354 5666
 
5355 5667
 	// Already writable?
5356
-	if (is_writable($file))
5357
-		return true;
5668
+	if (is_writable($file)) {
5669
+			return true;
5670
+	}
5358 5671
 
5359 5672
 	// Do we have a file or a dir?
5360 5673
 	$isDir = is_dir($file);
@@ -5370,10 +5683,9 @@  discard block
 block discarded – undo
5370 5683
 		{
5371 5684
 			$isWritable = true;
5372 5685
 			break;
5686
+		} else {
5687
+					@chmod($file, $val);
5373 5688
 		}
5374
-
5375
-		else
5376
-			@chmod($file, $val);
5377 5689
 	}
5378 5690
 
5379 5691
 	return $isWritable;
@@ -5392,8 +5704,9 @@  discard block
 block discarded – undo
5392 5704
 	global $txt;
5393 5705
 
5394 5706
 	// Come on...
5395
-	if (empty($json) || !is_string($json))
5396
-		return array();
5707
+	if (empty($json) || !is_string($json)) {
5708
+			return array();
5709
+	}
5397 5710
 
5398 5711
 	$returnArray = array();
5399 5712
 	$jsonError = false;
@@ -5434,11 +5747,11 @@  discard block
 block discarded – undo
5434 5747
 		$jsonDebug = $jsonDebug[0];
5435 5748
 		loadLanguage('Errors');
5436 5749
 
5437
-		if (!empty($jsonDebug))
5438
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5439
-
5440
-		else
5441
-			log_error($txt['json_'. $jsonError], 'critical');
5750
+		if (!empty($jsonDebug)) {
5751
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5752
+		} else {
5753
+					log_error($txt['json_'. $jsonError], 'critical');
5754
+		}
5442 5755
 
5443 5756
 		// Everyone expects an array.
5444 5757
 		return array();
@@ -5468,8 +5781,9 @@  discard block
 block discarded – undo
5468 5781
 	global $db_show_debug, $modSettings;
5469 5782
 
5470 5783
 	// Defensive programming anyone?
5471
-	if (empty($data))
5472
-		return false;
5784
+	if (empty($data)) {
5785
+			return false;
5786
+	}
5473 5787
 
5474 5788
 	// Don't need extra stuff...
5475 5789
 	$db_show_debug = false;
@@ -5477,11 +5791,11 @@  discard block
 block discarded – undo
5477 5791
 	// Kill anything else.
5478 5792
 	ob_end_clean();
5479 5793
 
5480
-	if (!empty($modSettings['CompressedOutput']))
5481
-		@ob_start('ob_gzhandler');
5482
-
5483
-	else
5484
-		ob_start();
5794
+	if (!empty($modSettings['CompressedOutput'])) {
5795
+			@ob_start('ob_gzhandler');
5796
+	} else {
5797
+			ob_start();
5798
+	}
5485 5799
 
5486 5800
 	// Set the header.
5487 5801
 	header($type);
@@ -5513,8 +5827,9 @@  discard block
 block discarded – undo
5513 5827
 	static $done = false;
5514 5828
 
5515 5829
 	// If we don't need to do anything, don't
5516
-	if (!$update && $done)
5517
-		return;
5830
+	if (!$update && $done) {
5831
+			return;
5832
+	}
5518 5833
 
5519 5834
 	// Should we get a new copy of the official list of TLDs?
5520 5835
 	if ($update)
@@ -5535,10 +5850,11 @@  discard block
 block discarded – undo
5535 5850
 		// Clean $tlds and convert it to an array
5536 5851
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5537 5852
 			$line = trim($line);
5538
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5539
-				return false;
5540
-			else
5541
-				return true;
5853
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5854
+							return false;
5855
+			} else {
5856
+							return true;
5857
+			}
5542 5858
 		});
5543 5859
 
5544 5860
 		// Convert Punycode to Unicode
@@ -5592,8 +5908,9 @@  discard block
 block discarded – undo
5592 5908
 						$idx += $digit * $w;
5593 5909
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5594 5910
 
5595
-						if ($digit < $t)
5596
-							break;
5911
+						if ($digit < $t) {
5912
+													break;
5913
+						}
5597 5914
 
5598 5915
 						$w = (int) ($w * ($base - $t));
5599 5916
 					}
@@ -5602,8 +5919,9 @@  discard block
 block discarded – undo
5602 5919
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5603 5920
 					$delta += intval($delta / ($deco_len + 1));
5604 5921
 
5605
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5606
-						$delta = intval($delta / ($base - $tmin));
5922
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
5923
+											$delta = intval($delta / ($base - $tmin));
5924
+					}
5607 5925
 
5608 5926
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5609 5927
 					$is_first = false;
@@ -5612,8 +5930,9 @@  discard block
 block discarded – undo
5612 5930
 
5613 5931
 					if ($deco_len > 0)
5614 5932
 					{
5615
-						for ($i = $deco_len; $i > $idx; $i--)
5616
-							$decoded[$i] = $decoded[($i - 1)];
5933
+						for ($i = $deco_len; $i > $idx; $i--) {
5934
+													$decoded[$i] = $decoded[($i - 1)];
5935
+						}
5617 5936
 					}
5618 5937
 					$decoded[$idx++] = $char;
5619 5938
 				}
@@ -5621,24 +5940,29 @@  discard block
 block discarded – undo
5621 5940
 				foreach ($decoded as $k => $v)
5622 5941
 				{
5623 5942
 					// 7bit are transferred literally
5624
-					if ($v < 128)
5625
-						$output .= chr($v);
5943
+					if ($v < 128) {
5944
+											$output .= chr($v);
5945
+					}
5626 5946
 
5627 5947
 					// 2 bytes
5628
-					elseif ($v < (1 << 11))
5629
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5948
+					elseif ($v < (1 << 11)) {
5949
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5950
+					}
5630 5951
 
5631 5952
 					// 3 bytes
5632
-					elseif ($v < (1 << 16))
5633
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5953
+					elseif ($v < (1 << 16)) {
5954
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5955
+					}
5634 5956
 
5635 5957
 					// 4 bytes
5636
-					elseif ($v < (1 << 21))
5637
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5958
+					elseif ($v < (1 << 21)) {
5959
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5960
+					}
5638 5961
 
5639 5962
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5640
-					else
5641
-						$output .= $safe_char;
5963
+					else {
5964
+											$output .= $safe_char;
5965
+					}
5642 5966
 				}
5643 5967
 
5644 5968
 				$output_parts[] = $output;
@@ -5733,8 +6057,7 @@  discard block
 block discarded – undo
5733 6057
 
5734 6058
 		$strlen = 'mb_strlen';
5735 6059
 		$substr = 'mb_substr';
5736
-	}
5737
-	else
6060
+	} else
5738 6061
 	{
5739 6062
 		$strlen = $smcFunc['strlen'];
5740 6063
 		$substr = $smcFunc['substr'];
@@ -5748,20 +6071,21 @@  discard block
 block discarded – undo
5748 6071
 
5749 6072
 		$first = $substr($string, 0, 1);
5750 6073
 
5751
-		if (empty($index[$first]))
5752
-			$index[$first] = array();
6074
+		if (empty($index[$first])) {
6075
+					$index[$first] = array();
6076
+		}
5753 6077
 
5754 6078
 		if ($strlen($string) > 1)
5755 6079
 		{
5756 6080
 			// Sanity check on recursion
5757
-			if ($depth > 99)
5758
-				$index[$first][$substr($string, 1)] = '';
5759
-
5760
-			else
5761
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6081
+			if ($depth > 99) {
6082
+							$index[$first][$substr($string, 1)] = '';
6083
+			} else {
6084
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6085
+			}
6086
+		} else {
6087
+					$index[$first][''] = '';
5762 6088
 		}
5763
-		else
5764
-			$index[$first][''] = '';
5765 6089
 
5766 6090
 		$depth--;
5767 6091
 		return $index;
@@ -5784,9 +6108,9 @@  discard block
 block discarded – undo
5784 6108
 			$key_regex = preg_quote($key, $delim);
5785 6109
 			$new_key = $key;
5786 6110
 
5787
-			if (empty($value))
5788
-				$sub_regex = '';
5789
-			else
6111
+			if (empty($value)) {
6112
+							$sub_regex = '';
6113
+			} else
5790 6114
 			{
5791 6115
 				$sub_regex = $index_to_regex($value, $delim);
5792 6116
 
@@ -5794,22 +6118,22 @@  discard block
 block discarded – undo
5794 6118
 				{
5795 6119
 					$new_key_array = explode('(?'.'>', $sub_regex);
5796 6120
 					$new_key .= $new_key_array[0];
6121
+				} else {
6122
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5797 6123
 				}
5798
-				else
5799
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5800 6124
 			}
5801 6125
 
5802
-			if ($depth > 1)
5803
-				$regex[$new_key] = $key_regex . $sub_regex;
5804
-			else
6126
+			if ($depth > 1) {
6127
+							$regex[$new_key] = $key_regex . $sub_regex;
6128
+			} else
5805 6129
 			{
5806 6130
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5807 6131
 				{
5808 6132
 					$regex[$new_key] = $key_regex . $sub_regex;
5809 6133
 					unset($index[$key]);
6134
+				} else {
6135
+									break;
5810 6136
 				}
5811
-				else
5812
-					break;
5813 6137
 			}
5814 6138
 		}
5815 6139
 
@@ -5818,10 +6142,11 @@  discard block
 block discarded – undo
5818 6142
 			$l1 = $strlen($k1);
5819 6143
 			$l2 = $strlen($k2);
5820 6144
 
5821
-			if ($l1 == $l2)
5822
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5823
-			else
5824
-				return $l1 > $l2 ? -1 : 1;
6145
+			if ($l1 == $l2) {
6146
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6147
+			} else {
6148
+							return $l1 > $l2 ? -1 : 1;
6149
+			}
5825 6150
 		});
5826 6151
 
5827 6152
 		$depth--;
@@ -5832,15 +6157,18 @@  discard block
 block discarded – undo
5832 6157
 	$index = array();
5833 6158
 	$regexes = array();
5834 6159
 
5835
-	foreach ($strings as $string)
5836
-		$index = $add_string_to_index($string, $index);
6160
+	foreach ($strings as $string) {
6161
+			$index = $add_string_to_index($string, $index);
6162
+	}
5837 6163
 
5838
-	while (!empty($index))
5839
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6164
+	while (!empty($index)) {
6165
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6166
+	}
5840 6167
 
5841 6168
 	// Restore PHP's internal character encoding to whatever it was originally
5842
-	if (!empty($current_encoding))
5843
-		mb_internal_encoding($current_encoding);
6169
+	if (!empty($current_encoding)) {
6170
+			mb_internal_encoding($current_encoding);
6171
+	}
5844 6172
 
5845 6173
 	return $regexes;
5846 6174
 }
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +206 added lines, -149 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -61,10 +62,11 @@  discard block
 block discarded – undo
61 62
 	$bday = array();
62 63
 	while ($row = $smcFunc['db_fetch_assoc']($result))
63 64
 	{
64
-		if ($year_low != $year_high)
65
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
66
-		else
67
-			$age_year = $year_low;
65
+		if ($year_low != $year_high) {
66
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
67
+		} else {
68
+					$age_year = $year_low;
69
+		}
68 70
 
69 71
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
70 72
 			'id' => $row['id_member'],
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$smcFunc['db_free_result']($result);
77 79
 
78 80
 	// Set is_last, so the themes know when to stop placing separators.
79
-	foreach ($bday as $mday => $array)
80
-		$bday[$mday][count($array) - 1]['is_last'] = true;
81
+	foreach ($bday as $mday => $array) {
82
+			$bday[$mday][count($array) - 1]['is_last'] = true;
83
+	}
81 84
 
82 85
 	return $bday;
83 86
 }
@@ -125,8 +128,9 @@  discard block
 block discarded – undo
125 128
 	while ($row = $smcFunc['db_fetch_assoc']($result))
126 129
 	{
127 130
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
128
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
129
-			continue;
131
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
132
+					continue;
133
+		}
130 134
 
131 135
 		// Force a censor of the title - as often these are used by others.
132 136
 		censorText($row['title'], $use_permissions ? false : true);
@@ -137,8 +141,9 @@  discard block
 block discarded – undo
137 141
 		list($start, $end, $allday, $span, $tz_abbrev) = buildEventDatetimes($row);
138 142
 
139 143
 		// Sanity check
140
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
141
-			continue;
144
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
145
+					continue;
146
+		}
142 147
 
143 148
 		// Get set up for the loop
144 149
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -202,8 +207,8 @@  discard block
 block discarded – undo
202 207
 			);
203 208
 
204 209
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
205
-			if ($use_permissions)
206
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
210
+			if ($use_permissions) {
211
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
207 212
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
208 213
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
209 214
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -211,9 +216,10 @@  discard block
 block discarded – undo
211 216
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
212 217
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
213 218
 				));
219
+			}
214 220
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
215
-			else
216
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
221
+			else {
222
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
217 223
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
218 224
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
219 225
 					'can_edit' => false,
@@ -223,6 +229,7 @@  discard block
 block discarded – undo
223 229
 					'poster' => $row['id_member'],
224 230
 					'allowed_groups' => explode(',', $row['member_groups']),
225 231
 				));
232
+			}
226 233
 
227 234
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
228 235
 		}
@@ -232,8 +239,9 @@  discard block
 block discarded – undo
232 239
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
233 240
 	if ($use_permissions)
234 241
 	{
235
-		foreach ($events as $mday => $array)
236
-			$events[$mday][count($array) - 1]['is_last'] = true;
242
+		foreach ($events as $mday => $array) {
243
+					$events[$mday][count($array) - 1]['is_last'] = true;
244
+		}
237 245
 	}
238 246
 
239 247
 	return $events;
@@ -251,11 +259,12 @@  discard block
 block discarded – undo
251 259
 	global $smcFunc;
252 260
 
253 261
 	// Get the lowest and highest dates for "all years".
254
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
255
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
262
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
263
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
256 264
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
257
-	else
258
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
265
+	} else {
266
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
267
+	}
259 268
 
260 269
 	// Find some holidays... ;).
261 270
 	$result = $smcFunc['db_query']('', '
@@ -275,10 +284,11 @@  discard block
 block discarded – undo
275 284
 	$holidays = array();
276 285
 	while ($row = $smcFunc['db_fetch_assoc']($result))
277 286
 	{
278
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
279
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
280
-		else
281
-			$event_year = substr($low_date, 0, 4);
287
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
288
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
289
+		} else {
290
+					$event_year = substr($low_date, 0, 4);
291
+		}
282 292
 
283 293
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
284 294
 	}
@@ -302,10 +312,12 @@  discard block
 block discarded – undo
302 312
 	isAllowedTo('calendar_post');
303 313
 
304 314
 	// No board?  No topic?!?
305
-	if (empty($board))
306
-		fatal_lang_error('missing_board_id', false);
307
-	if (empty($topic))
308
-		fatal_lang_error('missing_topic_id', false);
315
+	if (empty($board)) {
316
+			fatal_lang_error('missing_board_id', false);
317
+	}
318
+	if (empty($topic)) {
319
+			fatal_lang_error('missing_topic_id', false);
320
+	}
309 321
 
310 322
 	// Administrator, Moderator, or owner.  Period.
311 323
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -323,12 +335,14 @@  discard block
 block discarded – undo
323 335
 		if ($row = $smcFunc['db_fetch_assoc']($result))
324 336
 		{
325 337
 			// Not the owner of the topic.
326
-			if ($row['id_member_started'] != $user_info['id'])
327
-				fatal_lang_error('not_your_topic', 'user');
338
+			if ($row['id_member_started'] != $user_info['id']) {
339
+							fatal_lang_error('not_your_topic', 'user');
340
+			}
328 341
 		}
329 342
 		// Topic/Board doesn't exist.....
330
-		else
331
-			fatal_lang_error('calendar_no_topic', 'general');
343
+		else {
344
+					fatal_lang_error('calendar_no_topic', 'general');
345
+		}
332 346
 		$smcFunc['db_free_result']($result);
333 347
 	}
334 348
 }
@@ -416,14 +430,16 @@  discard block
 block discarded – undo
416 430
 	if (!empty($calendarOptions['start_day']))
417 431
 	{
418 432
 		$nShift -= $calendarOptions['start_day'];
419
-		if ($nShift < 0)
420
-			$nShift = 7 + $nShift;
433
+		if ($nShift < 0) {
434
+					$nShift = 7 + $nShift;
435
+		}
421 436
 	}
422 437
 
423 438
 	// Number of rows required to fit the month.
424 439
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
425
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
426
-		$nRows++;
440
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
441
+			$nRows++;
442
+	}
427 443
 
428 444
 	// Fetch the arrays for birthdays, posted events, and holidays.
429 445
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -436,8 +452,9 @@  discard block
 block discarded – undo
436 452
 	{
437 453
 		$calendarGrid['week_days'][] = $count;
438 454
 		$count++;
439
-		if ($count == 7)
440
-			$count = 0;
455
+		if ($count == 7) {
456
+					$count = 0;
457
+		}
441 458
 	}
442 459
 
443 460
 	// Iterate through each week.
@@ -454,8 +471,9 @@  discard block
 block discarded – undo
454 471
 		{
455 472
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
456 473
 
457
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
458
-				$nDay = 0;
474
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
475
+							$nDay = 0;
476
+			}
459 477
 
460 478
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
461 479
 
@@ -473,8 +491,9 @@  discard block
 block discarded – undo
473 491
 	}
474 492
 
475 493
 	// What is the last day of the month?
476
-	if ($is_previous === true)
477
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
494
+	if ($is_previous === true) {
495
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
496
+	}
478 497
 
479 498
 	// We'll use the shift in the template.
480 499
 	$calendarGrid['shift'] = $nShift;
@@ -508,8 +527,9 @@  discard block
 block discarded – undo
508 527
 	{
509 528
 		// Here we offset accordingly to get things to the real start of a week.
510 529
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
511
-		if ($date_diff < 0)
512
-			$date_diff += 7;
530
+		if ($date_diff < 0) {
531
+					$date_diff += 7;
532
+		}
513 533
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
514 534
 		$day = (int) strftime('%d', $new_timestamp);
515 535
 		$month = (int) strftime('%m', $new_timestamp);
@@ -660,8 +680,9 @@  discard block
 block discarded – undo
660 680
 	// Holidays between now and now + days.
661 681
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
662 682
 	{
663
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
664
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
683
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
684
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
685
+		}
665 686
 	}
666 687
 
667 688
 	// Happy Birthday, guys and gals!
@@ -670,8 +691,9 @@  discard block
 block discarded – undo
670 691
 		$loop_date = strftime('%Y-%m-%d', $i);
671 692
 		if (isset($cached_data['birthdays'][$loop_date]))
672 693
 		{
673
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
674
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
694
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
695
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
696
+			}
675 697
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
676 698
 		}
677 699
 	}
@@ -683,8 +705,9 @@  discard block
 block discarded – undo
683 705
 		$loop_date = strftime('%Y-%m-%d', $i);
684 706
 
685 707
 		// No events today? Check the next day.
686
-		if (empty($cached_data['events'][$loop_date]))
687
-			continue;
708
+		if (empty($cached_data['events'][$loop_date])) {
709
+					continue;
710
+		}
688 711
 
689 712
 		// Loop through all events to add a few last-minute values.
690 713
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -697,9 +720,9 @@  discard block
 block discarded – undo
697 720
 			{
698 721
 				unset($cached_data['events'][$loop_date][$ev]);
699 722
 				continue;
723
+			} else {
724
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
700 725
 			}
701
-			else
702
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
703 726
 
704 727
 			// Might be set to true afterwards, depending on the permissions.
705 728
 			$this_event['can_edit'] = false;
@@ -707,15 +730,18 @@  discard block
 block discarded – undo
707 730
 			$this_event['date'] = $loop_date;
708 731
 		}
709 732
 
710
-		if (!empty($cached_data['events'][$loop_date]))
711
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
733
+		if (!empty($cached_data['events'][$loop_date])) {
734
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
735
+		}
712 736
 	}
713 737
 
714 738
 	// Mark the last item so that a list separator can be used in the template.
715
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
716
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
717
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
718
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
739
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
740
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
741
+	}
742
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
743
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
744
+	}
719 745
 
720 746
 	return array(
721 747
 		'data' => $return_data,
@@ -763,37 +789,46 @@  discard block
 block discarded – undo
763 789
 		if (isset($_POST['start_date']))
764 790
 		{
765 791
 			$d = date_parse($_POST['start_date']);
766
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
767
-				fatal_lang_error('invalid_date', false);
768
-			if (empty($d['year']))
769
-				fatal_lang_error('event_year_missing', false);
770
-			if (empty($d['month']))
771
-				fatal_lang_error('event_month_missing', false);
772
-		}
773
-		elseif (isset($_POST['start_datetime']))
792
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
793
+							fatal_lang_error('invalid_date', false);
794
+			}
795
+			if (empty($d['year'])) {
796
+							fatal_lang_error('event_year_missing', false);
797
+			}
798
+			if (empty($d['month'])) {
799
+							fatal_lang_error('event_month_missing', false);
800
+			}
801
+		} elseif (isset($_POST['start_datetime']))
774 802
 		{
775 803
 			$d = date_parse($_POST['start_datetime']);
776
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
777
-				fatal_lang_error('invalid_date', false);
778
-			if (empty($d['year']))
779
-				fatal_lang_error('event_year_missing', false);
780
-			if (empty($d['month']))
781
-				fatal_lang_error('event_month_missing', false);
804
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
805
+							fatal_lang_error('invalid_date', false);
806
+			}
807
+			if (empty($d['year'])) {
808
+							fatal_lang_error('event_year_missing', false);
809
+			}
810
+			if (empty($d['month'])) {
811
+							fatal_lang_error('event_month_missing', false);
812
+			}
782 813
 		}
783 814
 		// The 2.0 way
784 815
 		else
785 816
 		{
786 817
 			// No month?  No year?
787
-			if (!isset($_POST['month']))
788
-				fatal_lang_error('event_month_missing', false);
789
-			if (!isset($_POST['year']))
790
-				fatal_lang_error('event_year_missing', false);
818
+			if (!isset($_POST['month'])) {
819
+							fatal_lang_error('event_month_missing', false);
820
+			}
821
+			if (!isset($_POST['year'])) {
822
+							fatal_lang_error('event_year_missing', false);
823
+			}
791 824
 
792 825
 			// Check the month and year...
793
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
794
-				fatal_lang_error('invalid_month', false);
795
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
796
-				fatal_lang_error('invalid_year', false);
826
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
827
+							fatal_lang_error('invalid_month', false);
828
+			}
829
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
830
+							fatal_lang_error('invalid_year', false);
831
+			}
797 832
 		}
798 833
 	}
799 834
 
@@ -803,8 +838,9 @@  discard block
 block discarded – undo
803 838
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
804 839
 	if (isset($_POST['span']))
805 840
 	{
806
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
807
-			fatal_lang_error('invalid_days_numb', false);
841
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
842
+					fatal_lang_error('invalid_days_numb', false);
843
+		}
808 844
 	}
809 845
 
810 846
 	// There is no need to validate the following values if we are just deleting the event.
@@ -814,24 +850,29 @@  discard block
 block discarded – undo
814 850
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
815 851
 		{
816 852
 			// No day?
817
-			if (!isset($_POST['day']))
818
-				fatal_lang_error('event_day_missing', false);
853
+			if (!isset($_POST['day'])) {
854
+							fatal_lang_error('event_day_missing', false);
855
+			}
819 856
 
820 857
 			// Bad day?
821
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
822
-				fatal_lang_error('invalid_date', false);
858
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
859
+							fatal_lang_error('invalid_date', false);
860
+			}
823 861
 		}
824 862
 
825
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
826
-			fatal_lang_error('event_title_missing', false);
827
-		elseif (!isset($_POST['evtitle']))
828
-			$_POST['evtitle'] = $_POST['subject'];
863
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
864
+					fatal_lang_error('event_title_missing', false);
865
+		} elseif (!isset($_POST['evtitle'])) {
866
+					$_POST['evtitle'] = $_POST['subject'];
867
+		}
829 868
 
830 869
 		// No title?
831
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
832
-			fatal_lang_error('no_event_title', false);
833
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
834
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
870
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
871
+					fatal_lang_error('no_event_title', false);
872
+		}
873
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
874
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
875
+		}
835 876
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
836 877
 	}
837 878
 }
@@ -858,8 +899,9 @@  discard block
 block discarded – undo
858 899
 	);
859 900
 
860 901
 	// No results, return false.
861
-	if ($smcFunc['db_num_rows'] === 0)
862
-		return false;
902
+	if ($smcFunc['db_num_rows'] === 0) {
903
+			return false;
904
+	}
863 905
 
864 906
 	// Grab the results and return.
865 907
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -995,8 +1037,9 @@  discard block
 block discarded – undo
995 1037
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
996 1038
 
997 1039
 	$column_clauses = array();
998
-	foreach ($event_columns as $col => $crit)
999
-		$column_clauses[] = $col . ' = ' . $crit;
1040
+	foreach ($event_columns as $col => $crit) {
1041
+			$column_clauses[] = $col . ' = ' . $crit;
1042
+	}
1000 1043
 
1001 1044
 	$smcFunc['db_query']('', '
1002 1045
 		UPDATE {db_prefix}calendar
@@ -1081,8 +1124,9 @@  discard block
 block discarded – undo
1081 1124
 	);
1082 1125
 
1083 1126
 	// If nothing returned, we are in poo, poo.
1084
-	if ($smcFunc['db_num_rows']($request) === 0)
1085
-		return false;
1127
+	if ($smcFunc['db_num_rows']($request) === 0) {
1128
+			return false;
1129
+	}
1086 1130
 
1087 1131
 	$row = $smcFunc['db_fetch_assoc']($request);
1088 1132
 	$smcFunc['db_free_result']($request);
@@ -1090,8 +1134,9 @@  discard block
 block discarded – undo
1090 1134
 	list($start, $end, $allday, $span, $tz_abbrev) = buildEventDatetimes($row);
1091 1135
 
1092 1136
 	// Sanity check
1093
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1094
-		return false;
1137
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1138
+			return false;
1139
+	}
1095 1140
 
1096 1141
 	$return_value = array(
1097 1142
 		'boards' => array(),
@@ -1161,10 +1206,11 @@  discard block
 block discarded – undo
1161 1206
 	$allday = isset($_REQUEST['allday']) ? 1 : (isset($_REQUEST['start_time']) ? 0 : 1);
1162 1207
 	$span = isset($_REQUEST['span']) && filter_var($_REQUEST['span'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 0))) ? $_REQUEST['span'] : 1;
1163 1208
 
1164
-	if (!empty($_REQUEST['tz']) && in_array($_REQUEST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1165
-		$tz = $_REQUEST['tz'];
1166
-	else
1167
-		$tz = getUserTimezone();
1209
+	if (!empty($_REQUEST['tz']) && in_array($_REQUEST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1210
+			$tz = $_REQUEST['tz'];
1211
+	} else {
1212
+			$tz = getUserTimezone();
1213
+	}
1168 1214
 
1169 1215
 	// Was the input given as individual parameters?
1170 1216
 	$start_year = isset($_REQUEST['year']) ? $_REQUEST['year'] : $today['year'];
@@ -1275,24 +1321,27 @@  discard block
 block discarded – undo
1275 1321
 
1276 1322
 	// Set $span, in case we need it
1277 1323
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1278
-	if ($span > 0)
1279
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1324
+	if ($span > 0) {
1325
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1326
+	}
1280 1327
 
1281 1328
 	// Define the timezone for this event, falling back to the default if not provided
1282
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1283
-		$tz = $eventOptions['tz'];
1284
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1285
-		$tz = $_POST['tz'];
1286
-	else
1287
-		$tz = getUserTimezone();
1329
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1330
+			$tz = $eventOptions['tz'];
1331
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1332
+			$tz = $_POST['tz'];
1333
+	} else {
1334
+			$tz = getUserTimezone();
1335
+	}
1288 1336
 
1289 1337
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1290
-	if (isset($eventOptions['allday']))
1291
-		$allday = $eventOptions['allday'];
1292
-	elseif (empty($_POST['allday']))
1293
-		$allday = false;
1294
-	else
1295
-		$allday = true;
1338
+	if (isset($eventOptions['allday'])) {
1339
+			$allday = $eventOptions['allday'];
1340
+	} elseif (empty($_POST['allday'])) {
1341
+			$allday = false;
1342
+	} else {
1343
+			$allday = true;
1344
+	}
1296 1345
 
1297 1346
 	// Input might come as individual parameters...
1298 1347
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1319,10 +1368,12 @@  discard block
 block discarded – undo
1319 1368
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1320 1369
 
1321 1370
 	// If the date and time were given in separate strings, combine them
1322
-	if (empty($start_string) && isset($start_date_string))
1323
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1324
-	if (empty($end_string) && isset($end_date_string))
1325
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1371
+	if (empty($start_string) && isset($start_date_string)) {
1372
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1373
+	}
1374
+	if (empty($end_string) && isset($end_date_string)) {
1375
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1376
+	}
1326 1377
 
1327 1378
 	// If some form of string input was given, override individually defined options with it
1328 1379
 	if (isset($start_string))
@@ -1413,10 +1464,11 @@  discard block
 block discarded – undo
1413 1464
 	if ($start_object >= $end_object)
1414 1465
 	{
1415 1466
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1416
-		if ($span > 0)
1417
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1418
-		else
1419
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1467
+		if ($span > 0) {
1468
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1469
+		} else {
1470
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1471
+		}
1420 1472
 	}
1421 1473
 
1422 1474
 	// Is $end_object too late?
@@ -1430,9 +1482,9 @@  discard block
 block discarded – undo
1430 1482
 			{
1431 1483
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1432 1484
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1485
+			} else {
1486
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1433 1487
 			}
1434
-			else
1435
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1436 1488
 		}
1437 1489
 	}
1438 1490
 
@@ -1445,8 +1497,7 @@  discard block
 block discarded – undo
1445 1497
 		$start_time = null;
1446 1498
 		$end_time = null;
1447 1499
 		$tz = null;
1448
-	}
1449
-	else
1500
+	} else
1450 1501
 	{
1451 1502
 		$start_time = date_format($start_object, 'H:i:s');
1452 1503
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1469,19 +1520,22 @@  discard block
 block discarded – undo
1469 1520
 	require_once($sourcedir . '/Subs.php');
1470 1521
 
1471 1522
 	// First, try to create a better date format, ignoring the "time" elements.
1472
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1473
-		$date_format = '%F';
1474
-	else
1475
-		$date_format = $matches[0];
1523
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1524
+			$date_format = '%F';
1525
+	} else {
1526
+			$date_format = $matches[0];
1527
+	}
1476 1528
 
1477
-	if (empty($row['timezone']))
1478
-		$row['timezone'] = getUserTimezone();
1529
+	if (empty($row['timezone'])) {
1530
+			$row['timezone'] = getUserTimezone();
1531
+	}
1479 1532
 
1480 1533
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1481
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1482
-		$time_format = '%k:%M';
1483
-	else
1484
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1534
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1535
+			$time_format = '%k:%M';
1536
+	} else {
1537
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1538
+	}
1485 1539
 
1486 1540
 	$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
1487 1541
 
@@ -1527,8 +1581,9 @@  discard block
 block discarded – undo
1527 1581
 {
1528 1582
 	global $smcFunc, $context, $sourcedir, $user_info;
1529 1583
 
1530
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1531
-		$id_member = $context['user']['id'];
1584
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1585
+			$id_member = $context['user']['id'];
1586
+	}
1532 1587
 
1533 1588
 	if (isset($id_member))
1534 1589
 	{
@@ -1544,8 +1599,9 @@  discard block
 block discarded – undo
1544 1599
 		$smcFunc['db_free_result']($request);
1545 1600
 	}
1546 1601
 
1547
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1548
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1602
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1603
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1604
+	}
1549 1605
 
1550 1606
 	return $timezone;
1551 1607
 }
@@ -1574,8 +1630,9 @@  discard block
 block discarded – undo
1574 1630
 		)
1575 1631
 	);
1576 1632
 	$holidays = array();
1577
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1578
-		$holidays[] = $row;
1633
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1634
+			$holidays[] = $row;
1635
+	}
1579 1636
 	$smcFunc['db_free_result']($request);
1580 1637
 
1581 1638
 	return $holidays;
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +438 added lines, -326 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -83,12 +84,14 @@  discard block
 block discarded – undo
83 84
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
84 85
 
85 86
 			// Is it reserved?
86
-			if ($value == 'pg_')
87
-				return $txt['error_db_prefix_reserved'];
87
+			if ($value == 'pg_') {
88
+							return $txt['error_db_prefix_reserved'];
89
+			}
88 90
 
89 91
 			// Is the prefix numeric?
90
-			if (preg_match('~^\d~', $value))
91
-				return $txt['error_db_prefix_numeric'];
92
+			if (preg_match('~^\d~', $value)) {
93
+							return $txt['error_db_prefix_numeric'];
94
+			}
92 95
 
93 96
 			return true;
94 97
 		},
@@ -135,10 +138,11 @@  discard block
 block discarded – undo
135 138
 		$incontext['skip'] = false;
136 139
 
137 140
 		// Call the step and if it returns false that means pause!
138
-		if (function_exists($step[2]) && $step[2]() === false)
139
-			break;
140
-		elseif (function_exists($step[2]))
141
-			$incontext['current_step']++;
141
+		if (function_exists($step[2]) && $step[2]() === false) {
142
+					break;
143
+		} elseif (function_exists($step[2])) {
144
+					$incontext['current_step']++;
145
+		}
142 146
 
143 147
 		// No warnings pass on.
144 148
 		$incontext['warning'] = '';
@@ -154,12 +158,14 @@  discard block
 block discarded – undo
154 158
 	global $databases, $incontext;
155 159
 
156 160
 	// Just so people using older versions of PHP aren't left in the cold.
157
-	if (!isset($_SERVER['PHP_SELF']))
158
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
161
+	if (!isset($_SERVER['PHP_SELF'])) {
162
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
163
+	}
159 164
 
160 165
 	// Turn off magic quotes runtime and enable error reporting.
161
-	if (function_exists('set_magic_quotes_runtime'))
162
-		@set_magic_quotes_runtime(0);
166
+	if (function_exists('set_magic_quotes_runtime')) {
167
+			@set_magic_quotes_runtime(0);
168
+	}
163 169
 	error_reporting(E_ALL);
164 170
 
165 171
 	// Fun.  Low PHP version...
@@ -173,21 +179,23 @@  discard block
 block discarded – undo
173 179
 	{
174 180
 		ob_start();
175 181
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
178
-		if (function_exists('session_start'))
179
-			@session_start();
180
-	}
181
-	else
182
+		if (ini_get('session.save_handler') == 'user') {
183
+					@ini_set('session.save_handler', 'files');
184
+		}
185
+		if (function_exists('session_start')) {
186
+					@session_start();
187
+		}
188
+	} else
182 189
 	{
183 190
 		ob_start('ob_gzhandler');
184 191
 
185
-		if (ini_get('session.save_handler') == 'user')
186
-			@ini_set('session.save_handler', 'files');
192
+		if (ini_get('session.save_handler') == 'user') {
193
+					@ini_set('session.save_handler', 'files');
194
+		}
187 195
 		session_start();
188 196
 
189
-		if (!headers_sent())
190
-			echo '<!DOCTYPE html>
197
+		if (!headers_sent()) {
198
+					echo '<!DOCTYPE html>
191 199
 <html>
192 200
 	<head>
193 201
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -196,6 +204,7 @@  discard block
 block discarded – undo
196 204
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
197 205
 	</body>
198 206
 </html>';
207
+		}
199 208
 		exit;
200 209
 	}
201 210
 
@@ -204,16 +213,18 @@  discard block
 block discarded – undo
204 213
 	{
205 214
 		$incontext['remote_files_available'] = false;
206 215
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
207
-		if ($test)
208
-			$incontext['remote_files_available'] = true;
216
+		if ($test) {
217
+					$incontext['remote_files_available'] = true;
218
+		}
209 219
 		@fclose($test);
210 220
 	}
211 221
 
212 222
 	// Add slashes, as long as they aren't already being added.
213
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
214
-		foreach ($_POST as $k => $v)
223
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
224
+			foreach ($_POST as $k => $v)
215 225
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
216 226
 				$_POST[$k] = addslashes($v);
227
+	}
217 228
 
218 229
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
219 230
 	if (isset($_GET['delete']))
@@ -234,8 +245,7 @@  discard block
 block discarded – undo
234 245
 			$ftp->close();
235 246
 
236 247
 			unset($_SESSION['installer_temp_ftp']);
237
-		}
238
-		else
248
+		} else
239 249
 		{
240 250
 			@unlink(__FILE__);
241 251
 
@@ -256,10 +266,11 @@  discard block
 block discarded – undo
256 266
 	{
257 267
 		// Get PHP's default timezone, if set
258 268
 		$ini_tz = ini_get('date.timezone');
259
-		if (!empty($ini_tz))
260
-			$timezone_id = $ini_tz;
261
-		else
262
-			$timezone_id = '';
269
+		if (!empty($ini_tz)) {
270
+					$timezone_id = $ini_tz;
271
+		} else {
272
+					$timezone_id = '';
273
+		}
263 274
 
264 275
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
265 276
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -289,8 +300,9 @@  discard block
 block discarded – undo
289 300
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
290 301
 		while ($entry = $dir->read())
291 302
 		{
292
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
293
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
303
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
304
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
305
+			}
294 306
 		}
295 307
 		$dir->close();
296 308
 	}
@@ -325,10 +337,11 @@  discard block
 block discarded – undo
325 337
 	}
326 338
 
327 339
 	// Override the language file?
328
-	if (isset($_GET['lang_file']))
329
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
331
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
340
+	if (isset($_GET['lang_file'])) {
341
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
342
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
343
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
344
+	}
332 345
 
333 346
 	// Make sure it exists, if it doesn't reset it.
334 347
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -337,8 +350,9 @@  discard block
 block discarded – undo
337 350
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
338 351
 
339 352
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
340
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
341
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
353
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
354
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
355
+		}
342 356
 	}
343 357
 
344 358
 	// And now include the actual language file itself.
@@ -351,15 +365,18 @@  discard block
 block discarded – undo
351 365
 	global $db_prefix, $db_connection, $sourcedir;
352 366
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
353 367
 
354
-	if (empty($sourcedir))
355
-		$sourcedir = dirname(__FILE__) . '/Sources';
368
+	if (empty($sourcedir)) {
369
+			$sourcedir = dirname(__FILE__) . '/Sources';
370
+	}
356 371
 
357 372
 	// Need this to check whether we need the database password.
358 373
 	require(dirname(__FILE__) . '/Settings.php');
359
-	if (!defined('SMF'))
360
-		define('SMF', 1);
361
-	if (empty($smcFunc))
362
-		$smcFunc = array();
374
+	if (!defined('SMF')) {
375
+			define('SMF', 1);
376
+	}
377
+	if (empty($smcFunc)) {
378
+			$smcFunc = array();
379
+	}
363 380
 
364 381
 	$modSettings['disableQueryCheck'] = true;
365 382
 
@@ -367,8 +384,9 @@  discard block
 block discarded – undo
367 384
 	if (!$db_connection)
368 385
 	{
369 386
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
370
-		if (version_compare(PHP_VERSION, '5', '<'))
371
-			require_once($sourcedir . '/Subs-Compat.php');
387
+		if (version_compare(PHP_VERSION, '5', '<')) {
388
+					require_once($sourcedir . '/Subs-Compat.php');
389
+		}
372 390
 
373 391
 		$db_options = array('persist' => $db_persist);
374 392
 		$port = '';
@@ -379,19 +397,20 @@  discard block
 block discarded – undo
379 397
 			if ($db_type == 'mysql' || $db_type == 'mysqli')
380 398
 			{
381 399
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
382
-			}
383
-			elseif ($db_type == 'postgresql')
400
+			} elseif ($db_type == 'postgresql')
384 401
 			{
385 402
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
386 403
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
387 404
 			}
388 405
 		}
389 406
 
390
-		if (!empty($port))
391
-			$db_options['port'] = $port;
407
+		if (!empty($port)) {
408
+					$db_options['port'] = $port;
409
+		}
392 410
 
393
-		if (!$db_connection)
394
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
411
+		if (!$db_connection) {
412
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
413
+		}
395 414
 	}
396 415
 }
397 416
 
@@ -419,8 +438,9 @@  discard block
 block discarded – undo
419 438
 		// @todo REMOVE THIS!!
420 439
 		else
421 440
 		{
422
-			if (function_exists('doStep' . $_GET['step']))
423
-				call_user_func('doStep' . $_GET['step']);
441
+			if (function_exists('doStep' . $_GET['step'])) {
442
+							call_user_func('doStep' . $_GET['step']);
443
+			}
424 444
 		}
425 445
 		// Show the footer.
426 446
 		template_install_below();
@@ -438,8 +458,9 @@  discard block
 block discarded – undo
438 458
 	$incontext['sub_template'] = 'welcome_message';
439 459
 
440 460
 	// Done the submission?
441
-	if (isset($_POST['contbutt']))
442
-		return true;
461
+	if (isset($_POST['contbutt'])) {
462
+			return true;
463
+	}
443 464
 
444 465
 	// See if we think they have already installed it?
445 466
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -447,14 +468,17 @@  discard block
 block discarded – undo
447 468
 		$probably_installed = 0;
448 469
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
449 470
 		{
450
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
451
-				$probably_installed++;
452
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
453
-				$probably_installed++;
471
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
472
+							$probably_installed++;
473
+			}
474
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
475
+							$probably_installed++;
476
+			}
454 477
 		}
455 478
 
456
-		if ($probably_installed == 2)
457
-			$incontext['warning'] = $txt['error_already_installed'];
479
+		if ($probably_installed == 2) {
480
+					$incontext['warning'] = $txt['error_already_installed'];
481
+		}
458 482
 	}
459 483
 
460 484
 	// Is some database support even compiled in?
@@ -469,8 +493,7 @@  discard block
 block discarded – undo
469 493
 				$databases[$key]['supported'] = false;
470 494
 				$notFoundSQLFile = true;
471 495
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
472
-			}
473
-			else
496
+			} else
474 497
 			{
475 498
 				$db_type = $key;
476 499
 				$incontext['supported_databases'][] = $db;
@@ -479,29 +502,36 @@  discard block
 block discarded – undo
479 502
 	}
480 503
 
481 504
 	// Check the PHP version.
482
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
483
-		$error = 'error_php_too_low';
505
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
506
+			$error = 'error_php_too_low';
507
+	}
484 508
 	// Make sure we have a supported database
485
-	elseif (empty($incontext['supported_databases']))
486
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
509
+	elseif (empty($incontext['supported_databases'])) {
510
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
511
+	}
487 512
 	// How about session support?  Some crazy sysadmin remove it?
488
-	elseif (!function_exists('session_start'))
489
-		$error = 'error_session_missing';
513
+	elseif (!function_exists('session_start')) {
514
+			$error = 'error_session_missing';
515
+	}
490 516
 	// Make sure they uploaded all the files.
491
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
492
-		$error = 'error_missing_files';
517
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
518
+			$error = 'error_missing_files';
519
+	}
493 520
 	// Very simple check on the session.save_path for Windows.
494 521
 	// @todo Move this down later if they don't use database-driven sessions?
495
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
496
-		$error = 'error_session_save_path';
522
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
523
+			$error = 'error_session_save_path';
524
+	}
497 525
 
498 526
 	// Since each of the three messages would look the same, anyway...
499
-	if (isset($error))
500
-		$incontext['error'] = $txt[$error];
527
+	if (isset($error)) {
528
+			$incontext['error'] = $txt[$error];
529
+	}
501 530
 
502 531
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
503
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
504
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
532
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
533
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
534
+	}
505 535
 
506 536
 	return false;
507 537
 }
@@ -524,15 +554,18 @@  discard block
 block discarded – undo
524 554
 		'agreement.txt',
525 555
 		'Settings.php'
526 556
 	);
527
-	if (file_exists(dirname(__FILE__) . '/Settings_bak.php'))
528
-		$writable_files[] = 'Settings_bak.php';
557
+	if (file_exists(dirname(__FILE__) . '/Settings_bak.php')) {
558
+			$writable_files[] = 'Settings_bak.php';
559
+	}
529 560
 
530
-	foreach ($incontext['detected_languages'] as $lang => $temp)
531
-		$extra_files[] = 'Themes/default/languages/' . $lang;
561
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
562
+			$extra_files[] = 'Themes/default/languages/' . $lang;
563
+	}
532 564
 
533 565
 	// With mod_security installed, we could attempt to fix it with .htaccess.
534
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
535
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
566
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
567
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
568
+	}
536 569
 
537 570
 	$failed_files = array();
538 571
 
@@ -548,12 +581,14 @@  discard block
 block discarded – undo
548 581
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
549 582
 
550 583
 				// Well, 755 hopefully worked... if not, try 777.
551
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
552
-					$failed_files[] = $file;
584
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
585
+									$failed_files[] = $file;
586
+				}
553 587
 			}
554 588
 		}
555
-		foreach ($extra_files as $file)
556
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
589
+		foreach ($extra_files as $file) {
590
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
591
+		}
557 592
 	}
558 593
 	// Windows is trickier.  Let's try opening for r+...
559 594
 	else
@@ -563,30 +598,35 @@  discard block
 block discarded – undo
563 598
 		foreach ($writable_files as $file)
564 599
 		{
565 600
 			// Folders can't be opened for write... but the index.php in them can ;)
566
-			if (is_dir(dirname(__FILE__) . '/' . $file))
567
-				$file .= '/index.php';
601
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
602
+							$file .= '/index.php';
603
+			}
568 604
 
569 605
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
570 606
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
571 607
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
572 608
 
573 609
 			// Hmm, okay, try just for write in that case...
574
-			if (!is_resource($fp))
575
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
610
+			if (!is_resource($fp)) {
611
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
612
+			}
576 613
 
577
-			if (!is_resource($fp))
578
-				$failed_files[] = $file;
614
+			if (!is_resource($fp)) {
615
+							$failed_files[] = $file;
616
+			}
579 617
 
580 618
 			@fclose($fp);
581 619
 		}
582
-		foreach ($extra_files as $file)
583
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
620
+		foreach ($extra_files as $file) {
621
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
622
+		}
584 623
 	}
585 624
 
586 625
 	$failure = count($failed_files) >= 1;
587 626
 
588
-	if (!isset($_SERVER))
589
-		return !$failure;
627
+	if (!isset($_SERVER)) {
628
+			return !$failure;
629
+	}
590 630
 
591 631
 	// Put the list into context.
592 632
 	$incontext['failed_files'] = $failed_files;
@@ -634,19 +674,23 @@  discard block
 block discarded – undo
634 674
 
635 675
 		if (!isset($ftp) || $ftp->error !== false)
636 676
 		{
637
-			if (!isset($ftp))
638
-				$ftp = new ftp_connection(null);
677
+			if (!isset($ftp)) {
678
+							$ftp = new ftp_connection(null);
679
+			}
639 680
 			// Save the error so we can mess with listing...
640
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
641
-				$incontext['ftp_errors'][] = $ftp->last_message;
681
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
682
+							$incontext['ftp_errors'][] = $ftp->last_message;
683
+			}
642 684
 
643 685
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
644 686
 
645
-			if (empty($_POST['ftp_path']) && $found_path)
646
-				$_POST['ftp_path'] = $detect_path;
687
+			if (empty($_POST['ftp_path']) && $found_path) {
688
+							$_POST['ftp_path'] = $detect_path;
689
+			}
647 690
 
648
-			if (!isset($_POST['ftp_username']))
649
-				$_POST['ftp_username'] = $username;
691
+			if (!isset($_POST['ftp_username'])) {
692
+							$_POST['ftp_username'] = $username;
693
+			}
650 694
 
651 695
 			// Set the username etc, into context.
652 696
 			$incontext['ftp'] = array(
@@ -658,8 +702,7 @@  discard block
 block discarded – undo
658 702
 			);
659 703
 
660 704
 			return false;
661
-		}
662
-		else
705
+		} else
663 706
 		{
664 707
 			$_SESSION['installer_temp_ftp'] = array(
665 708
 				'server' => $_POST['ftp_server'],
@@ -673,10 +716,12 @@  discard block
 block discarded – undo
673 716
 
674 717
 			foreach ($failed_files as $file)
675 718
 			{
676
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
677
-					$ftp->chmod($file, 0755);
678
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
679
-					$ftp->chmod($file, 0777);
719
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
720
+									$ftp->chmod($file, 0755);
721
+				}
722
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
723
+									$ftp->chmod($file, 0777);
724
+				}
680 725
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
681 726
 				{
682 727
 					$failed_files_updated[] = $file;
@@ -731,15 +776,17 @@  discard block
 block discarded – undo
731 776
 
732 777
 			if (!$foundOne)
733 778
 			{
734
-				if (isset($db['default_host']))
735
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
779
+				if (isset($db['default_host'])) {
780
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
781
+				}
736 782
 				if (isset($db['default_user']))
737 783
 				{
738 784
 					$incontext['db']['user'] = ini_get($db['default_user']);
739 785
 					$incontext['db']['name'] = ini_get($db['default_user']);
740 786
 				}
741
-				if (isset($db['default_password']))
742
-					$incontext['db']['pass'] = ini_get($db['default_password']);
787
+				if (isset($db['default_password'])) {
788
+									$incontext['db']['pass'] = ini_get($db['default_password']);
789
+				}
743 790
 
744 791
 				// For simplicity and less confusion, leave the port blank by default
745 792
 				$incontext['db']['port'] = '';
@@ -758,10 +805,10 @@  discard block
 block discarded – undo
758 805
 		$incontext['db']['server'] = $_POST['db_server'];
759 806
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
760 807
 
761
-		if (!empty($_POST['db_port']))
762
-			$incontext['db']['port'] = $_POST['db_port'];
763
-	}
764
-	else
808
+		if (!empty($_POST['db_port'])) {
809
+					$incontext['db']['port'] = $_POST['db_port'];
810
+		}
811
+	} else
765 812
 	{
766 813
 		$incontext['db']['prefix'] = 'smf_';
767 814
 	}
@@ -797,10 +844,11 @@  discard block
 block discarded – undo
797 844
 		if (!empty($_POST['db_port']))
798 845
 		{
799 846
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
800
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
801
-				$vars['db_port'] = (int) $_POST['db_port'];
802
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
803
-				$vars['db_port'] = (int) $_POST['db_port'];
847
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
848
+							$vars['db_port'] = (int) $_POST['db_port'];
849
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
850
+							$vars['db_port'] = (int) $_POST['db_port'];
851
+			}
804 852
 		}
805 853
 
806 854
 		// God I hope it saved!
@@ -813,8 +861,9 @@  discard block
 block discarded – undo
813 861
 		// Make sure it works.
814 862
 		require(dirname(__FILE__) . '/Settings.php');
815 863
 
816
-		if (empty($sourcedir))
817
-			$sourcedir = dirname(__FILE__) . '/Sources';
864
+		if (empty($sourcedir)) {
865
+					$sourcedir = dirname(__FILE__) . '/Sources';
866
+		}
818 867
 
819 868
 		// Better find the database file!
820 869
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -824,18 +873,21 @@  discard block
 block discarded – undo
824 873
 		}
825 874
 
826 875
 		// Now include it for database functions!
827
-		if (!defined('SMF'))
828
-			define('SMF', 1);
876
+		if (!defined('SMF')) {
877
+					define('SMF', 1);
878
+		}
829 879
 
830 880
 		$modSettings['disableQueryCheck'] = true;
831
-		if (empty($smcFunc))
832
-			$smcFunc = array();
881
+		if (empty($smcFunc)) {
882
+					$smcFunc = array();
883
+		}
833 884
 
834 885
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
835 886
 
836 887
 		// What - running PHP4? The shame!
837
-		if (version_compare(PHP_VERSION, '5', '<'))
838
-			require_once($sourcedir . '/Subs-Compat.php');
888
+		if (version_compare(PHP_VERSION, '5', '<')) {
889
+					require_once($sourcedir . '/Subs-Compat.php');
890
+		}
839 891
 
840 892
 		// Attempt a connection.
841 893
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -923,12 +975,14 @@  discard block
 block discarded – undo
923 975
 	$incontext['page_title'] = $txt['install_settings'];
924 976
 
925 977
 	// Let's see if we got the database type correct.
926
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
927
-		$db_type = $_POST['db_type'];
978
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
979
+			$db_type = $_POST['db_type'];
980
+	}
928 981
 
929 982
 	// Else we'd better be able to get the connection.
930
-	else
931
-		load_database();
983
+	else {
984
+			load_database();
985
+	}
932 986
 
933 987
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
934 988
 
@@ -948,12 +1002,14 @@  discard block
 block discarded – undo
948 1002
 	// Submitting?
949 1003
 	if (isset($_POST['boardurl']))
950 1004
 	{
951
-		if (substr($_POST['boardurl'], -10) == '/index.php')
952
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
953
-		elseif (substr($_POST['boardurl'], -1) == '/')
954
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
955
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
956
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1005
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1006
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1007
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1008
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1009
+		}
1010
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1011
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1012
+		}
957 1013
 
958 1014
 		// Save these variables.
959 1015
 		$vars = array(
@@ -984,10 +1040,10 @@  discard block
 block discarded – undo
984 1040
 			{
985 1041
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
986 1042
 				return false;
987
-			}
988
-			else
989
-				// Set the character set here.
1043
+			} else {
1044
+							// Set the character set here.
990 1045
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1046
+			}
991 1047
 		}
992 1048
 
993 1049
 		// Good, skip on.
@@ -1007,8 +1063,9 @@  discard block
 block discarded – undo
1007 1063
 	$incontext['continue'] = 1;
1008 1064
 
1009 1065
 	// Already done?
1010
-	if (isset($_POST['pop_done']))
1011
-		return true;
1066
+	if (isset($_POST['pop_done'])) {
1067
+			return true;
1068
+	}
1012 1069
 
1013 1070
 	// Reload settings.
1014 1071
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1026,8 +1083,9 @@  discard block
 block discarded – undo
1026 1083
 	$modSettings = array();
1027 1084
 	if ($result !== false)
1028 1085
 	{
1029
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1030
-			$modSettings[$row['variable']] = $row['value'];
1086
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1087
+					$modSettings[$row['variable']] = $row['value'];
1088
+		}
1031 1089
 		$smcFunc['db_free_result']($result);
1032 1090
 
1033 1091
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1040,20 +1098,22 @@  discard block
 block discarded – undo
1040 1098
 	$modSettings['disableQueryCheck'] = true;
1041 1099
 
1042 1100
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1043
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1044
-		$smcFunc['db_query']('', '
1101
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1102
+			$smcFunc['db_query']('', '
1045 1103
 			SET NAMES {string:utf8}',
1046 1104
 			array(
1047 1105
 				'db_error_skip' => true,
1048 1106
 				'utf8' => 'utf8',
1049 1107
 			)
1050 1108
 		);
1109
+	}
1051 1110
 
1052 1111
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1053
-	if (substr(__DIR__, -1) == '\\')
1054
-		$attachdir = __DIR__ . 'attachments';
1055
-	else
1056
-		$attachdir = __DIR__ . '/attachments';
1112
+	if (substr(__DIR__, -1) == '\\') {
1113
+			$attachdir = __DIR__ . 'attachments';
1114
+	} else {
1115
+			$attachdir = __DIR__ . '/attachments';
1116
+	}
1057 1117
 
1058 1118
 	$replaces = array(
1059 1119
 		'{$db_prefix}' => $db_prefix,
@@ -1070,8 +1130,9 @@  discard block
 block discarded – undo
1070 1130
 
1071 1131
 	foreach ($txt as $key => $value)
1072 1132
 	{
1073
-		if (substr($key, 0, 8) == 'default_')
1074
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1133
+		if (substr($key, 0, 8) == 'default_') {
1134
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1135
+		}
1075 1136
 	}
1076 1137
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1077 1138
 
@@ -1086,8 +1147,9 @@  discard block
 block discarded – undo
1086 1147
 
1087 1148
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1088 1149
 		{
1089
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1090
-				$engines[] = $row['Engine'];
1150
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1151
+							$engines[] = $row['Engine'];
1152
+			}
1091 1153
 		}
1092 1154
 
1093 1155
 		// Done with this now
@@ -1111,8 +1173,7 @@  discard block
 block discarded – undo
1111 1173
 			$replaces['START TRANSACTION;'] = '';
1112 1174
 			$replaces['COMMIT;'] = '';
1113 1175
 		}
1114
-	}
1115
-	else
1176
+	} else
1116 1177
 	{
1117 1178
 		$has_innodb = false;
1118 1179
 	}
@@ -1134,21 +1195,24 @@  discard block
 block discarded – undo
1134 1195
 	foreach ($sql_lines as $count => $line)
1135 1196
 	{
1136 1197
 		// No comments allowed!
1137
-		if (substr(trim($line), 0, 1) != '#')
1138
-			$current_statement .= "\n" . rtrim($line);
1198
+		if (substr(trim($line), 0, 1) != '#') {
1199
+					$current_statement .= "\n" . rtrim($line);
1200
+		}
1139 1201
 
1140 1202
 		// Is this the end of the query string?
1141
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1142
-			continue;
1203
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1204
+					continue;
1205
+		}
1143 1206
 
1144 1207
 		// Does this table already exist?  If so, don't insert more data into it!
1145 1208
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1146 1209
 		{
1147 1210
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1148
-			if (!empty($matches[0]))
1149
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1150
-			else
1151
-				$incontext['sql_results']['insert_dups']++;
1211
+			if (!empty($matches[0])) {
1212
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1213
+			} else {
1214
+							$incontext['sql_results']['insert_dups']++;
1215
+			}
1152 1216
 
1153 1217
 			$current_statement = '';
1154 1218
 			continue;
@@ -1157,8 +1221,9 @@  discard block
 block discarded – undo
1157 1221
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1158 1222
 		{
1159 1223
 			// Use the appropriate function based on the DB type
1160
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1161
-				$db_errorno = $db_type . '_errno';
1224
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1225
+							$db_errorno = $db_type . '_errno';
1226
+			}
1162 1227
 
1163 1228
 			// Error 1050: Table already exists!
1164 1229
 			// @todo Needs to be made better!
@@ -1173,18 +1238,18 @@  discard block
 block discarded – undo
1173 1238
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1174 1239
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1175 1240
 			}
1176
-		}
1177
-		else
1241
+		} else
1178 1242
 		{
1179
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1180
-				$incontext['sql_results']['tables']++;
1181
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1243
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1244
+							$incontext['sql_results']['tables']++;
1245
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1182 1246
 			{
1183 1247
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1184
-				if (!empty($matches[0]))
1185
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1186
-				else
1187
-					$incontext['sql_results']['inserts']++;
1248
+				if (!empty($matches[0])) {
1249
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1250
+				} else {
1251
+									$incontext['sql_results']['inserts']++;
1252
+				}
1188 1253
 			}
1189 1254
 		}
1190 1255
 
@@ -1197,15 +1262,17 @@  discard block
 block discarded – undo
1197 1262
 	// Sort out the context for the SQL.
1198 1263
 	foreach ($incontext['sql_results'] as $key => $number)
1199 1264
 	{
1200
-		if ($number == 0)
1201
-			unset($incontext['sql_results'][$key]);
1202
-		else
1203
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1265
+		if ($number == 0) {
1266
+					unset($incontext['sql_results'][$key]);
1267
+		} else {
1268
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1269
+		}
1204 1270
 	}
1205 1271
 
1206 1272
 	// Make sure UTF will be used globally.
1207
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1208
-		$newSettings[] = array('global_character_set', 'UTF-8');
1273
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1274
+			$newSettings[] = array('global_character_set', 'UTF-8');
1275
+	}
1209 1276
 
1210 1277
 	// Maybe we can auto-detect better cookie settings?
1211 1278
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1216,16 +1283,20 @@  discard block
 block discarded – undo
1216 1283
 		$globalCookies = false;
1217 1284
 
1218 1285
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1219
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1220
-			$globalCookies = true;
1286
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1287
+					$globalCookies = true;
1288
+		}
1221 1289
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1222
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1223
-			$localCookies = true;
1290
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1291
+					$localCookies = true;
1292
+		}
1224 1293
 
1225
-		if ($globalCookies)
1226
-			$newSettings[] = array('globalCookies', '1');
1227
-		if ($localCookies)
1228
-			$newSettings[] = array('localCookies', '1');
1294
+		if ($globalCookies) {
1295
+					$newSettings[] = array('globalCookies', '1');
1296
+		}
1297
+		if ($localCookies) {
1298
+					$newSettings[] = array('localCookies', '1');
1299
+		}
1229 1300
 	}
1230 1301
 
1231 1302
 	// Are we allowing stat collection?
@@ -1241,32 +1312,36 @@  discard block
 block discarded – undo
1241 1312
 			fwrite($fp, $out);
1242 1313
 
1243 1314
 			$return_data = '';
1244
-			while (!feof($fp))
1245
-				$return_data .= fgets($fp, 128);
1315
+			while (!feof($fp)) {
1316
+							$return_data .= fgets($fp, 128);
1317
+			}
1246 1318
 
1247 1319
 			fclose($fp);
1248 1320
 
1249 1321
 			// Get the unique site ID.
1250 1322
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1251 1323
 
1252
-			if (!empty($ID[1]))
1253
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1324
+			if (!empty($ID[1])) {
1325
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1326
+			}
1254 1327
 		}
1255 1328
 	}
1256 1329
 
1257 1330
 	// Are we enabling SSL?
1258
-	if (!empty($_POST['force_ssl']))
1259
-		$newSettings[] = array('force_ssl', 2);
1331
+	if (!empty($_POST['force_ssl'])) {
1332
+			$newSettings[] = array('force_ssl', 2);
1333
+	}
1260 1334
 
1261 1335
 	// Setting a timezone is required.
1262 1336
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1263 1337
 	{
1264 1338
 		// Get PHP's default timezone, if set
1265 1339
 		$ini_tz = ini_get('date.timezone');
1266
-		if (!empty($ini_tz))
1267
-			$timezone_id = $ini_tz;
1268
-		else
1269
-			$timezone_id = '';
1340
+		if (!empty($ini_tz)) {
1341
+					$timezone_id = $ini_tz;
1342
+		} else {
1343
+					$timezone_id = '';
1344
+		}
1270 1345
 
1271 1346
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1272 1347
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1275,8 +1350,9 @@  discard block
 block discarded – undo
1275 1350
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1276 1351
 		}
1277 1352
 
1278
-		if (date_default_timezone_set($timezone_id))
1279
-			$newSettings[] = array('default_timezone', $timezone_id);
1353
+		if (date_default_timezone_set($timezone_id)) {
1354
+					$newSettings[] = array('default_timezone', $timezone_id);
1355
+		}
1280 1356
 	}
1281 1357
 
1282 1358
 	if (!empty($newSettings))
@@ -1307,16 +1383,18 @@  discard block
 block discarded – undo
1307 1383
 	}
1308 1384
 
1309 1385
 	// MySQL specific stuff
1310
-	if (substr($db_type, 0, 5) != 'mysql')
1311
-		return false;
1386
+	if (substr($db_type, 0, 5) != 'mysql') {
1387
+			return false;
1388
+	}
1312 1389
 
1313 1390
 	// Find database user privileges.
1314 1391
 	$privs = array();
1315 1392
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1316 1393
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1317 1394
 	{
1318
-		if ($row['Privilege'] == 'Alter')
1319
-			$privs[] = $row['Privilege'];
1395
+		if ($row['Privilege'] == 'Alter') {
1396
+					$privs[] = $row['Privilege'];
1397
+		}
1320 1398
 	}
1321 1399
 	$smcFunc['db_free_result']($get_privs);
1322 1400
 
@@ -1346,8 +1424,9 @@  discard block
 block discarded – undo
1346 1424
 	$incontext['continue'] = 1;
1347 1425
 
1348 1426
 	// Skipping?
1349
-	if (!empty($_POST['skip']))
1350
-		return true;
1427
+	if (!empty($_POST['skip'])) {
1428
+			return true;
1429
+	}
1351 1430
 
1352 1431
 	// Need this to check whether we need the database password.
1353 1432
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1360,18 +1439,22 @@  discard block
 block discarded – undo
1360 1439
 	// We need this to properly hash the password for Admin
1361 1440
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1362 1441
 			global $sourcedir;
1363
-			if (function_exists('mb_strtolower'))
1364
-				return mb_strtolower($string, 'UTF-8');
1442
+			if (function_exists('mb_strtolower')) {
1443
+							return mb_strtolower($string, 'UTF-8');
1444
+			}
1365 1445
 			require_once($sourcedir . '/Subs-Charset.php');
1366 1446
 			return utf8_strtolower($string);
1367 1447
 		};
1368 1448
 
1369
-	if (!isset($_POST['username']))
1370
-		$_POST['username'] = '';
1371
-	if (!isset($_POST['email']))
1372
-		$_POST['email'] = '';
1373
-	if (!isset($_POST['server_email']))
1374
-		$_POST['server_email'] = '';
1449
+	if (!isset($_POST['username'])) {
1450
+			$_POST['username'] = '';
1451
+	}
1452
+	if (!isset($_POST['email'])) {
1453
+			$_POST['email'] = '';
1454
+	}
1455
+	if (!isset($_POST['server_email'])) {
1456
+			$_POST['server_email'] = '';
1457
+	}
1375 1458
 
1376 1459
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1377 1460
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1390,8 +1473,9 @@  discard block
 block discarded – undo
1390 1473
 			'admin_group' => 1,
1391 1474
 		)
1392 1475
 	);
1393
-	if ($smcFunc['db_num_rows']($request) != 0)
1394
-		$incontext['skip'] = 1;
1476
+	if ($smcFunc['db_num_rows']($request) != 0) {
1477
+			$incontext['skip'] = 1;
1478
+	}
1395 1479
 	$smcFunc['db_free_result']($request);
1396 1480
 
1397 1481
 	// Trying to create an account?
@@ -1422,8 +1506,9 @@  discard block
 block discarded – undo
1422 1506
 		}
1423 1507
 
1424 1508
 		// Update the webmaster's email?
1425
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1426
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1509
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1510
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1511
+		}
1427 1512
 
1428 1513
 		// Work out whether we're going to have dodgy characters and remove them.
1429 1514
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1446,32 +1531,27 @@  discard block
 block discarded – undo
1446 1531
 			$smcFunc['db_free_result']($result);
1447 1532
 
1448 1533
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1449
-		}
1450
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1534
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1451 1535
 		{
1452 1536
 			// Try the previous step again.
1453 1537
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1454 1538
 			return false;
1455
-		}
1456
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1539
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1457 1540
 		{
1458 1541
 			// Try the previous step again.
1459 1542
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1460 1543
 			return false;
1461
-		}
1462
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1544
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1463 1545
 		{
1464 1546
 			// One step back, this time fill out a proper admin email address.
1465 1547
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1466 1548
 			return false;
1467
-		}
1468
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1549
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1469 1550
 		{
1470 1551
 			// One step back, this time fill out a proper admin email address.
1471 1552
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1472 1553
 			return false;
1473
-		}
1474
-		elseif ($_POST['username'] != '')
1554
+		} elseif ($_POST['username'] != '')
1475 1555
 		{
1476 1556
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1477 1557
 
@@ -1546,17 +1626,19 @@  discard block
 block discarded – undo
1546 1626
 	require_once($sourcedir . '/Subs-Auth.php');
1547 1627
 
1548 1628
 	// Bring a warning over.
1549
-	if (!empty($incontext['account_existed']))
1550
-		$incontext['warning'] = $incontext['account_existed'];
1629
+	if (!empty($incontext['account_existed'])) {
1630
+			$incontext['warning'] = $incontext['account_existed'];
1631
+	}
1551 1632
 
1552
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1553
-		$smcFunc['db_query']('', '
1633
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1634
+			$smcFunc['db_query']('', '
1554 1635
 			SET NAMES {string:db_character_set}',
1555 1636
 			array(
1556 1637
 				'db_character_set' => $db_character_set,
1557 1638
 				'db_error_skip' => true,
1558 1639
 			)
1559 1640
 		);
1641
+	}
1560 1642
 
1561 1643
 	// As track stats is by default enabled let's add some activity.
1562 1644
 	$smcFunc['db_insert']('ignore',
@@ -1577,14 +1659,16 @@  discard block
 block discarded – undo
1577 1659
 	// Only proceed if we can load the data.
1578 1660
 	if ($request)
1579 1661
 	{
1580
-		while ($row = $smcFunc['db_fetch_row']($request))
1581
-			$modSettings[$row[0]] = $row[1];
1662
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1663
+					$modSettings[$row[0]] = $row[1];
1664
+		}
1582 1665
 		$smcFunc['db_free_result']($request);
1583 1666
 	}
1584 1667
 
1585 1668
 	// Automatically log them in ;)
1586
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1587
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1669
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1670
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1671
+	}
1588 1672
 
1589 1673
 	$result = $smcFunc['db_query']('', '
1590 1674
 		SELECT value
@@ -1595,13 +1679,14 @@  discard block
 block discarded – undo
1595 1679
 			'db_error_skip' => true,
1596 1680
 		)
1597 1681
 	);
1598
-	if ($smcFunc['db_num_rows']($result) != 0)
1599
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1682
+	if ($smcFunc['db_num_rows']($result) != 0) {
1683
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1684
+	}
1600 1685
 	$smcFunc['db_free_result']($result);
1601 1686
 
1602
-	if (empty($db_sessions))
1603
-		$_SESSION['admin_time'] = time();
1604
-	else
1687
+	if (empty($db_sessions)) {
1688
+			$_SESSION['admin_time'] = time();
1689
+	} else
1605 1690
 	{
1606 1691
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1607 1692
 
@@ -1625,8 +1710,9 @@  discard block
 block discarded – undo
1625 1710
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1626 1711
 		function($string){
1627 1712
 			global $sourcedir;
1628
-			if (function_exists('mb_strtolower'))
1629
-				return mb_strtolower($string, 'UTF-8');
1713
+			if (function_exists('mb_strtolower')) {
1714
+							return mb_strtolower($string, 'UTF-8');
1715
+			}
1630 1716
 			require_once($sourcedir . '/Subs-Charset.php');
1631 1717
 			return utf8_strtolower($string);
1632 1718
 		};
@@ -1642,8 +1728,9 @@  discard block
 block discarded – undo
1642 1728
 		)
1643 1729
 	);
1644 1730
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1645
-	if ($smcFunc['db_num_rows']($request) > 0)
1646
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1731
+	if ($smcFunc['db_num_rows']($request) > 0) {
1732
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1733
+	}
1647 1734
 	$smcFunc['db_free_result']($request);
1648 1735
 
1649 1736
 	// Now is the perfect time to fetch the SM files.
@@ -1662,8 +1749,9 @@  discard block
 block discarded – undo
1662 1749
 
1663 1750
 	// Check if we need some stupid MySQL fix.
1664 1751
 	$server_version = $smcFunc['db_server_info']();
1665
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1666
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1752
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1753
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1754
+	}
1667 1755
 
1668 1756
 	// Some final context for the template.
1669 1757
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1683,8 +1771,9 @@  discard block
 block discarded – undo
1683 1771
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1684 1772
 
1685 1773
 	// @todo Do we just want to read the file in clean, and split it this way always?
1686
-	if (count($settingsArray) == 1)
1687
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1774
+	if (count($settingsArray) == 1) {
1775
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1776
+	}
1688 1777
 
1689 1778
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1690 1779
 	{
@@ -1699,19 +1788,22 @@  discard block
 block discarded – undo
1699 1788
 			continue;
1700 1789
 		}
1701 1790
 
1702
-		if (trim($settingsArray[$i]) == '?' . '>')
1703
-			$settingsArray[$i] = '';
1791
+		if (trim($settingsArray[$i]) == '?' . '>') {
1792
+					$settingsArray[$i] = '';
1793
+		}
1704 1794
 
1705 1795
 		// Don't trim or bother with it if it's not a variable.
1706
-		if (substr($settingsArray[$i], 0, 1) != '$')
1707
-			continue;
1796
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1797
+					continue;
1798
+		}
1708 1799
 
1709 1800
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1710 1801
 
1711
-		foreach ($vars as $var => $val)
1712
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1802
+		foreach ($vars as $var => $val) {
1803
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1713 1804
 			{
1714 1805
 				$comment = strstr($settingsArray[$i], '#');
1806
+		}
1715 1807
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1716 1808
 				unset($vars[$var]);
1717 1809
 			}
@@ -1721,36 +1813,41 @@  discard block
 block discarded – undo
1721 1813
 	if (!empty($vars))
1722 1814
 	{
1723 1815
 		$settingsArray[$i++] = '';
1724
-		foreach ($vars as $var => $val)
1725
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1816
+		foreach ($vars as $var => $val) {
1817
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1818
+		}
1726 1819
 	}
1727 1820
 
1728 1821
 	// Blank out the file - done to fix a oddity with some servers.
1729 1822
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1730
-	if (!$fp)
1731
-		return false;
1823
+	if (!$fp) {
1824
+			return false;
1825
+	}
1732 1826
 	fclose($fp);
1733 1827
 
1734 1828
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1735 1829
 
1736 1830
 	// Gotta have one of these ;)
1737
-	if (trim($settingsArray[0]) != '<?php')
1738
-		fwrite($fp, "<?php\n");
1831
+	if (trim($settingsArray[0]) != '<?php') {
1832
+			fwrite($fp, "<?php\n");
1833
+	}
1739 1834
 
1740 1835
 	$lines = count($settingsArray);
1741 1836
 	for ($i = 0; $i < $lines - 1; $i++)
1742 1837
 	{
1743 1838
 		// Don't just write a bunch of blank lines.
1744
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1745
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1839
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1840
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1841
+		}
1746 1842
 	}
1747 1843
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1748 1844
 	fclose($fp);
1749 1845
 
1750 1846
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1751 1847
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1752
-	if (function_exists('opcache_invalidate'))
1753
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1848
+	if (function_exists('opcache_invalidate')) {
1849
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1850
+	}
1754 1851
 
1755 1852
 	return true;
1756 1853
 }
@@ -1775,9 +1872,9 @@  discard block
 block discarded – undo
1775 1872
 	SecFilterScanPOST Off
1776 1873
 </IfModule>';
1777 1874
 
1778
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1779
-		return true;
1780
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1875
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1876
+			return true;
1877
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1781 1878
 	{
1782 1879
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1783 1880
 
@@ -1789,29 +1886,28 @@  discard block
 block discarded – undo
1789 1886
 				fwrite($ht_handle, $htaccess_addition);
1790 1887
 				fclose($ht_handle);
1791 1888
 				return true;
1889
+			} else {
1890
+							return false;
1792 1891
 			}
1793
-			else
1794
-				return false;
1892
+		} else {
1893
+					return true;
1795 1894
 		}
1796
-		else
1797
-			return true;
1798
-	}
1799
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1800
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1801
-	elseif (is_writable(dirname(__FILE__)))
1895
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1896
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1897
+	} elseif (is_writable(dirname(__FILE__)))
1802 1898
 	{
1803 1899
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1804 1900
 		{
1805 1901
 			fwrite($ht_handle, $htaccess_addition);
1806 1902
 			fclose($ht_handle);
1807 1903
 			return true;
1904
+		} else {
1905
+					return false;
1808 1906
 		}
1809
-		else
1907
+	} else {
1810 1908
 			return false;
1811 1909
 	}
1812
-	else
1813
-		return false;
1814
-}
1910
+	}
1815 1911
 
1816 1912
 function template_install_above()
1817 1913
 {
@@ -1849,9 +1945,10 @@  discard block
 block discarded – undo
1849 1945
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1850 1946
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1851 1947
 
1852
-		foreach ($incontext['detected_languages'] as $lang => $name)
1853
-			echo '
1948
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1949
+					echo '
1854 1950
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1951
+		}
1855 1952
 
1856 1953
 		echo '
1857 1954
 								</select>
@@ -1871,9 +1968,10 @@  discard block
 block discarded – undo
1871 1968
 						<h2>', $txt['upgrade_progress'], '</h2>
1872 1969
 						<ul>';
1873 1970
 
1874
-	foreach ($incontext['steps'] as $num => $step)
1875
-		echo '
1971
+	foreach ($incontext['steps'] as $num => $step) {
1972
+			echo '
1876 1973
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1974
+	}
1877 1975
 
1878 1976
 	echo '
1879 1977
 						</ul>
@@ -1898,20 +1996,23 @@  discard block
 block discarded – undo
1898 1996
 		echo '
1899 1997
 								<div>';
1900 1998
 
1901
-		if (!empty($incontext['continue']))
1902
-			echo '
1999
+		if (!empty($incontext['continue'])) {
2000
+					echo '
1903 2001
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1904
-		if (!empty($incontext['skip']))
1905
-			echo '
2002
+		}
2003
+		if (!empty($incontext['skip'])) {
2004
+					echo '
1906 2005
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
2006
+		}
1907 2007
 		echo '
1908 2008
 								</div>';
1909 2009
 	}
1910 2010
 
1911 2011
 	// Show the closing form tag and other data only if not in the last step
1912
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1913
-		echo '
2012
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2013
+			echo '
1914 2014
 							</form>';
2015
+	}
1915 2016
 
1916 2017
 	echo '
1917 2018
 						</div>
@@ -1946,13 +2047,15 @@  discard block
 block discarded – undo
1946 2047
 		</div>';
1947 2048
 
1948 2049
 	// Show the warnings, or not.
1949
-	if (template_warning_divs())
1950
-		echo '
2050
+	if (template_warning_divs()) {
2051
+			echo '
1951 2052
 		<h3>', $txt['install_all_lovely'], '</h3>';
2053
+	}
1952 2054
 
1953 2055
 	// Say we want the continue button!
1954
-	if (empty($incontext['error']))
1955
-		$incontext['continue'] = 1;
2056
+	if (empty($incontext['error'])) {
2057
+			$incontext['continue'] = 1;
2058
+	}
1956 2059
 
1957 2060
 	// For the latest version stuff.
1958 2061
 	echo '
@@ -1986,8 +2089,8 @@  discard block
 block discarded – undo
1986 2089
 	global $txt, $incontext;
1987 2090
 
1988 2091
 	// Errors are very serious..
1989
-	if (!empty($incontext['error']))
1990
-		echo '
2092
+	if (!empty($incontext['error'])) {
2093
+			echo '
1991 2094
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1992 2095
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1993 2096
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1995,9 +2098,10 @@  discard block
 block discarded – undo
1995 2098
 				', $incontext['error'], '
1996 2099
 			</div>
1997 2100
 		</div>';
2101
+	}
1998 2102
 	// A warning message?
1999
-	elseif (!empty($incontext['warning']))
2000
-		echo '
2103
+	elseif (!empty($incontext['warning'])) {
2104
+			echo '
2001 2105
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2002 2106
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2003 2107
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2005,6 +2109,7 @@  discard block
 block discarded – undo
2005 2109
 				', $incontext['warning'], '
2006 2110
 			</div>
2007 2111
 		</div>';
2112
+	}
2008 2113
 
2009 2114
 	return empty($incontext['error']) && empty($incontext['warning']);
2010 2115
 }
@@ -2020,27 +2125,30 @@  discard block
 block discarded – undo
2020 2125
 			<li>', $incontext['failed_files']), '</li>
2021 2126
 		</ul>';
2022 2127
 
2023
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2024
-		echo '
2128
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2129
+			echo '
2025 2130
 		<hr>
2026 2131
 		<p>', $txt['chmod_linux_info'], '</p>
2027 2132
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2133
+	}
2028 2134
 
2029 2135
 	// This is serious!
2030
-	if (!template_warning_divs())
2031
-		return;
2136
+	if (!template_warning_divs()) {
2137
+			return;
2138
+	}
2032 2139
 
2033 2140
 	echo '
2034 2141
 		<hr>
2035 2142
 		<p>', $txt['ftp_setup_info'], '</p>';
2036 2143
 
2037
-	if (!empty($incontext['ftp_errors']))
2038
-		echo '
2144
+	if (!empty($incontext['ftp_errors'])) {
2145
+			echo '
2039 2146
 		<div class="error_message">
2040 2147
 			', $txt['error_ftp_no_connect'], '<br><br>
2041 2148
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2042 2149
 		</div>
2043 2150
 		<br>';
2151
+	}
2044 2152
 
2045 2153
 	echo '
2046 2154
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2100,17 +2208,17 @@  discard block
 block discarded – undo
2100 2208
 				<td>
2101 2209
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2102 2210
 
2103
-	foreach ($incontext['supported_databases'] as $key => $db)
2104
-			echo '
2211
+	foreach ($incontext['supported_databases'] as $key => $db) {
2212
+				echo '
2105 2213
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2214
+	}
2106 2215
 
2107 2216
 	echo '
2108 2217
 					</select>
2109 2218
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2110 2219
 				</td>
2111 2220
 			</tr>';
2112
-	}
2113
-	else
2221
+	} else
2114 2222
 	{
2115 2223
 		echo '
2116 2224
 			<tr style="display: none;">
@@ -2302,9 +2410,10 @@  discard block
 block discarded – undo
2302 2410
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2303 2411
 				<ul>';
2304 2412
 
2305
-		foreach ($incontext['failures'] as $line => $fail)
2306
-			echo '
2413
+		foreach ($incontext['failures'] as $line => $fail) {
2414
+					echo '
2307 2415
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2416
+		}
2308 2417
 
2309 2418
 		echo '
2310 2419
 				</ul>';
@@ -2365,15 +2474,16 @@  discard block
 block discarded – undo
2365 2474
 			</tr>
2366 2475
 		</table>';
2367 2476
 
2368
-	if ($incontext['require_db_confirm'])
2369
-		echo '
2477
+	if ($incontext['require_db_confirm']) {
2478
+			echo '
2370 2479
 		<h2>', $txt['user_settings_database'], '</h2>
2371 2480
 		<p>', $txt['user_settings_database_info'], '</p>
2372 2481
 
2373 2482
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2374 2483
 			<input type="password" name="password3" size="30" class="input_password" />
2375 2484
 		</div>';
2376
-}
2485
+	}
2486
+	}
2377 2487
 
2378 2488
 // Tell them it's done, and to delete.
2379 2489
 function template_delete_install()
@@ -2386,14 +2496,15 @@  discard block
 block discarded – undo
2386 2496
 	template_warning_divs();
2387 2497
 
2388 2498
 	// Install directory still writable?
2389
-	if ($incontext['dir_still_writable'])
2390
-		echo '
2499
+	if ($incontext['dir_still_writable']) {
2500
+			echo '
2391 2501
 		<em>', $txt['still_writable'], '</em><br>
2392 2502
 		<br>';
2503
+	}
2393 2504
 
2394 2505
 	// Don't show the box if it's like 99% sure it won't work :P.
2395
-	if ($incontext['probably_delete_install'])
2396
-		echo '
2506
+	if ($incontext['probably_delete_install']) {
2507
+			echo '
2397 2508
 		<div style="margin: 1ex; font-weight: bold;">
2398 2509
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2399 2510
 		</div>
@@ -2409,6 +2520,7 @@  discard block
 block discarded – undo
2409 2520
 			}
2410 2521
 		</script>
2411 2522
 		<br>';
2523
+	}
2412 2524
 
2413 2525
 	echo '
2414 2526
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
index.php 1 patch
Braces   +37 added lines, -25 removed lines patch added patch discarded remove patch
@@ -25,8 +25,9 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Get everything started up...
27 27
 define('SMF', 1);
28
-if (function_exists('set_magic_quotes_runtime') && strnatcmp(phpversion(), '5.3.0') < 0)
28
+if (function_exists('set_magic_quotes_runtime') && strnatcmp(phpversion(), '5.3.0') < 0) {
29 29
 	@set_magic_quotes_runtime(0);
30
+}
30 31
 error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
31 32
 $time_start = microtime();
32 33
 
@@ -34,16 +35,18 @@  discard block
 block discarded – undo
34 35
 ob_start();
35 36
 
36 37
 // Do some cleaning, just in case.
37
-foreach (array('db_character_set', 'cachedir') as $variable)
38
+foreach (array('db_character_set', 'cachedir') as $variable) {
38 39
 	if (isset($GLOBALS[$variable]))
39 40
 		unset($GLOBALS[$variable], $GLOBALS[$variable]);
41
+}
40 42
 
41 43
 // Load the settings...
42 44
 require_once(dirname(__FILE__) . '/Settings.php');
43 45
 
44 46
 // Make absolutely sure the cache directory is defined.
45
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
47
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
46 48
 	$cachedir = $boarddir . '/cache';
49
+}
47 50
 
48 51
 // Without those we can't go anywhere
49 52
 require_once($sourcedir . '/QueryString.php');
@@ -53,8 +56,9 @@  discard block
 block discarded – undo
53 56
 require_once($sourcedir . '/Load.php');
54 57
 
55 58
 // If $maintenance is set specifically to 2, then we're upgrading or something.
56
-if (!empty($maintenance) && $maintenance == 2)
59
+if (!empty($maintenance) && $maintenance == 2) {
57 60
 	display_maintenance_message();
61
+}
58 62
 
59 63
 // Create a variable to store some SMF specific functions in.
60 64
 $smcFunc = array();
@@ -69,8 +73,9 @@  discard block
 block discarded – undo
69 73
 cleanRequest();
70 74
 
71 75
 // Seed the random generator.
72
-if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
76
+if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
73 77
 	smf_seed_generator();
78
+}
74 79
 
75 80
 // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out!
76 81
 if (isset($_GET['scheduled']))
@@ -90,9 +95,9 @@  discard block
 block discarded – undo
90 95
 if (!empty($modSettings['enableCompressedOutput']) && !headers_sent())
91 96
 {
92 97
 	// If zlib is being used, turn off output compression.
93
-	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler')
94
-		$modSettings['enableCompressedOutput'] = '0';
95
-	else
98
+	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') {
99
+			$modSettings['enableCompressedOutput'] = '0';
100
+	} else
96 101
 	{
97 102
 		ob_end_clean();
98 103
 		ob_start('ob_gzhandler');
@@ -141,18 +146,21 @@  discard block
 block discarded – undo
141 146
 	loadPermissions();
142 147
 
143 148
 	// Attachments don't require the entire theme to be loaded.
144
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach')
145
-		detectBrowser();
149
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') {
150
+			detectBrowser();
151
+	}
146 152
 	// Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
147
-	else
148
-		loadTheme();
153
+	else {
154
+			loadTheme();
155
+	}
149 156
 
150 157
 	// Check if the user should be disallowed access.
151 158
 	is_not_banned();
152 159
 
153 160
 	// If we are in a topic and don't have permission to approve it then duck out now.
154
-	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest']))
155
-		fatal_lang_error('not_a_topic', false);
161
+	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) {
162
+			fatal_lang_error('not_a_topic', false);
163
+	}
156 164
 
157 165
 	$no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile');
158 166
 	call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions));
@@ -163,8 +171,9 @@  discard block
 block discarded – undo
163 171
 		writeLog();
164 172
 
165 173
 		// Track forum statistics and hits...?
166
-		if (!empty($modSettings['hitStats']))
167
-			trackStats(array('hits' => '+'));
174
+		if (!empty($modSettings['hitStats'])) {
175
+					trackStats(array('hits' => '+'));
176
+		}
168 177
 	}
169 178
 	unset($no_stat_actions);
170 179
 
@@ -178,13 +187,14 @@  discard block
 block discarded – undo
178 187
 			return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout'));
179 188
 		}
180 189
 		// Don't even try it, sonny.
181
-		else
182
-			return 'InMaintenance';
190
+		else {
191
+					return 'InMaintenance';
192
+		}
183 193
 	}
184 194
 	// If guest access is off, a guest can only do one of the very few following actions.
185
-	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2'))))
186
-		return 'KickGuest';
187
-	elseif (empty($_REQUEST['action']))
195
+	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) {
196
+			return 'KickGuest';
197
+	} elseif (empty($_REQUEST['action']))
188 198
 	{
189 199
 		// Action and board are both empty... BoardIndex! Unless someone else wants to do something different.
190 200
 		if (empty($board) && empty($topic))
@@ -200,8 +210,9 @@  discard block
 block discarded – undo
200 210
 
201 211
 				$call = call_helper($defaultAction, true);
202 212
 
203
-				if (!empty($call))
204
-					return $call;
213
+				if (!empty($call)) {
214
+									return $call;
215
+				}
205 216
 			}
206 217
 
207 218
 			// No default action huh? then go to our good old BoardIndex.
@@ -331,8 +342,9 @@  discard block
 block discarded – undo
331 342
 
332 343
 			$call = call_helper($fallbackAction, true);
333 344
 
334
-			if (!empty($call))
335
-				return $call;
345
+			if (!empty($call)) {
346
+							return $call;
347
+			}
336 348
 		}
337 349
 
338 350
 		// No fallback action, huh?
Please login to merge, or discard this patch.