Completed
Push — release-2.1 ( 121660...f19596 )
by Mathias
09:09
created
Sources/PersonalMessage.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4070,7 +4070,7 @@
 block discarded – undo
4070 4070
  *
4071 4071
  * @param int $pmID The ID of the PM
4072 4072
  * @param string $validFor Which folders this is valud for - can be 'inbox', 'outbox' or 'in_or_outbox'
4073
- * @return boolean Whether the PM is accessible in that folder for the current user
4073
+ * @return boolean|null Whether the PM is accessible in that folder for the current user
4074 4074
  */
4075 4075
 function isAccessiblePM($pmID, $validFor = 'in_or_outbox')
4076 4076
 {
Please login to merge, or discard this patch.
Braces   +633 added lines, -471 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This helps organize things...
@@ -37,13 +38,14 @@  discard block
 block discarded – undo
37 38
 
38 39
 	loadLanguage('PersonalMessage+Drafts');
39 40
 
40
-	if (!isset($_REQUEST['xml']))
41
-		loadTemplate('PersonalMessage');
41
+	if (!isset($_REQUEST['xml'])) {
42
+			loadTemplate('PersonalMessage');
43
+	}
42 44
 
43 45
 	// Load up the members maximum message capacity.
44
-	if ($user_info['is_admin'])
45
-		$context['message_limit'] = 0;
46
-	elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
46
+	if ($user_info['is_admin']) {
47
+			$context['message_limit'] = 0;
48
+	} elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
47 49
 	{
48 50
 		// @todo Why do we do this?  It seems like if they have any limit we should use it.
49 51
 		$request = $smcFunc['db_query']('', '
@@ -78,8 +80,9 @@  discard block
 block discarded – undo
78 80
 	}
79 81
 
80 82
 	// a previous message was sent successfully? show a small indication.
81
-	if (isset($_GET['done']) && ($_GET['done'] == 'sent'))
82
-		$context['pm_sent'] = true;
83
+	if (isset($_GET['done']) && ($_GET['done'] == 'sent')) {
84
+			$context['pm_sent'] = true;
85
+	}
83 86
 
84 87
 	$context['labels'] = array();
85 88
 
@@ -210,11 +213,11 @@  discard block
 block discarded – undo
210 213
 	{
211 214
 		$_REQUEST['sa'] = '';
212 215
 		MessageFolder();
213
-	}
214
-	else
216
+	} else
215 217
 	{
216
-		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup')
217
-			messageIndexBar($_REQUEST['sa']);
218
+		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') {
219
+					messageIndexBar($_REQUEST['sa']);
220
+		}
218 221
 
219 222
 		call_helper($subActions[$_REQUEST['sa']]);
220 223
 	}
@@ -291,16 +294,17 @@  discard block
 block discarded – undo
291 294
 	);
292 295
 
293 296
 	// Handle labels.
294
-	if (empty($context['currently_using_labels']))
295
-		unset($pm_areas['labels']);
296
-	else
297
+	if (empty($context['currently_using_labels'])) {
298
+			unset($pm_areas['labels']);
299
+	} else
297 300
 	{
298 301
 		// Note we send labels by id as it will have less problems in the querystring.
299 302
 		$unread_in_labels = 0;
300 303
 		foreach ($context['labels'] as $label)
301 304
 		{
302
-			if ($label['id'] == -1)
303
-				continue;
305
+			if ($label['id'] == -1) {
306
+							continue;
307
+			}
304 308
 
305 309
 			// Count the amount of unread items in labels.
306 310
 			$unread_in_labels += $label['unread_messages'];
@@ -314,8 +318,9 @@  discard block
 block discarded – undo
314 318
 			);
315 319
 		}
316 320
 
317
-		if (!empty($unread_in_labels))
318
-			$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
321
+		if (!empty($unread_in_labels)) {
322
+					$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
323
+		}
319 324
 	}
320 325
 
321 326
 	$pm_areas['folders']['areas']['inbox']['unread_messages'] = &$context['labels'][-1]['unread_messages'];
@@ -353,8 +358,9 @@  discard block
 block discarded – undo
353 358
 	unset($pm_areas);
354 359
 
355 360
 	// No menu means no access.
356
-	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession()))
357
-		fatal_lang_error('no_access', false);
361
+	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) {
362
+			fatal_lang_error('no_access', false);
363
+	}
358 364
 
359 365
 	// Make a note of the Unique ID for this menu.
360 366
 	$context['pm_menu_id'] = $context['max_menu_id'];
@@ -365,9 +371,10 @@  discard block
 block discarded – undo
365 371
 	$context['menu_item_selected'] = $current_area;
366 372
 
367 373
 	// Set the template for this area and add the profile layer.
368
-	if (!isset($_REQUEST['xml']))
369
-		$context['template_layers'][] = 'pm';
370
-}
374
+	if (!isset($_REQUEST['xml'])) {
375
+			$context['template_layers'][] = 'pm';
376
+	}
377
+	}
371 378
 
372 379
 /**
373 380
  * The popup for when we ask for the popup from the user.
@@ -399,8 +406,9 @@  discard block
 block discarded – undo
399 406
 		)
400 407
 	);
401 408
 	$pms = array();
402
-	while ($row = $smcFunc['db_fetch_row']($request))
403
-		$pms[] = $row[0];
409
+	while ($row = $smcFunc['db_fetch_row']($request)) {
410
+			$pms[] = $row[0];
411
+	}
404 412
 	$smcFunc['db_free_result']($request);
405 413
 
406 414
 	if (!empty($pms))
@@ -428,8 +436,9 @@  discard block
 block discarded – undo
428 436
 		);
429 437
 		while ($row = $smcFunc['db_fetch_assoc']($request))
430 438
 		{
431
-			if (!empty($row['id_member_from']))
432
-				$senders[] = $row['id_member_from'];
439
+			if (!empty($row['id_member_from'])) {
440
+							$senders[] = $row['id_member_from'];
441
+			}
433 442
 
434 443
 			$row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head'];
435 444
 			$row['time'] = timeformat($row['timestamp']);
@@ -439,13 +448,15 @@  discard block
 block discarded – undo
439 448
 		$smcFunc['db_free_result']($request);
440 449
 
441 450
 		$senders = loadMemberData($senders);
442
-		foreach ($senders as $member)
443
-			loadMemberContext($member);
451
+		foreach ($senders as $member) {
452
+					loadMemberContext($member);
453
+		}
444 454
 
445 455
 		// Having loaded everyone, attach them to the PMs.
446
-		foreach ($context['unread_pms'] as $id_pm => $details)
447
-			if (!empty($memberContext[$details['id_member_from']]))
456
+		foreach ($context['unread_pms'] as $id_pm => $details) {
457
+					if (!empty($memberContext[$details['id_member_from']]))
448 458
 				$context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']];
459
+		}
449 460
 	}
450 461
 }
451 462
 
@@ -465,12 +476,13 @@  discard block
 block discarded – undo
465 476
 	}
466 477
 
467 478
 	// Make sure the starting location is valid.
468
-	if (isset($_GET['start']) && $_GET['start'] != 'new')
469
-		$_GET['start'] = (int) $_GET['start'];
470
-	elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first']))
471
-		$_GET['start'] = 0;
472
-	else
473
-		$_GET['start'] = 'new';
479
+	if (isset($_GET['start']) && $_GET['start'] != 'new') {
480
+			$_GET['start'] = (int) $_GET['start'];
481
+	} elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) {
482
+			$_GET['start'] = 0;
483
+	} else {
484
+			$_GET['start'] = 'new';
485
+	}
474 486
 
475 487
 	// Set up some basic theme stuff.
476 488
 	$context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to';
@@ -487,8 +499,7 @@  discard block
 block discarded – undo
487 499
 	{
488 500
 		$labelQuery = '
489 501
 			AND pmr.in_inbox = 1';
490
-	}
491
-	elseif ($context['folder'] != 'sent')
502
+	} elseif ($context['folder'] != 'sent')
492 503
 	{
493 504
 		$labelJoin = '
494 505
 			INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)';
@@ -530,22 +541,24 @@  discard block
 block discarded – undo
530 541
 	$txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']);
531 542
 
532 543
 	// Now, build the link tree!
533
-	if ($context['current_label_id'] == -1)
534
-		$context['linktree'][] = array(
544
+	if ($context['current_label_id'] == -1) {
545
+			$context['linktree'][] = array(
535 546
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'],
536 547
 			'name' => $pmbox
537 548
 		);
549
+	}
538 550
 
539 551
 	// Build it further for a label.
540
-	if ($context['current_label_id'] != -1)
541
-		$context['linktree'][] = array(
552
+	if ($context['current_label_id'] != -1) {
553
+			$context['linktree'][] = array(
542 554
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'],
543 555
 			'name' => $txt['pm_current_label'] . ': ' . $context['current_label']
544 556
 		);
557
+	}
545 558
 
546 559
 	// Figure out how many messages there are.
547
-	if ($context['folder'] == 'sent')
548
-		$request = $smcFunc['db_query']('', '
560
+	if ($context['folder'] == 'sent') {
561
+			$request = $smcFunc['db_query']('', '
549 562
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
550 563
 			FROM {db_prefix}personal_messages AS pm
551 564
 			WHERE pm.id_member_from = {int:current_member}
@@ -555,8 +568,8 @@  discard block
 block discarded – undo
555 568
 				'not_deleted' => 0,
556 569
 			)
557 570
 		);
558
-	else
559
-		$request = $smcFunc['db_query']('', '
571
+	} else {
572
+			$request = $smcFunc['db_query']('', '
560 573
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
561 574
 			FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
562 575
 				INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -567,6 +580,7 @@  discard block
 block discarded – undo
567 580
 				'not_deleted' => 0,
568 581
 			)
569 582
 		);
583
+	}
570 584
 	list ($max_messages) = $smcFunc['db_fetch_row']($request);
571 585
 	$smcFunc['db_free_result']($request);
572 586
 
@@ -575,10 +589,11 @@  discard block
 block discarded – undo
575 589
 	$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
576 590
 
577 591
 	// Start on the last page.
578
-	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages)
579
-		$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
580
-	elseif ($_GET['start'] < 0)
581
-		$_GET['start'] = 0;
592
+	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) {
593
+			$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
594
+	} elseif ($_GET['start'] < 0) {
595
+			$_GET['start'] = 0;
596
+	}
582 597
 
583 598
 	// ... but wait - what if we want to start from a specific message?
584 599
 	if (isset($_GET['pmid']))
@@ -586,19 +601,21 @@  discard block
 block discarded – undo
586 601
 		$pmID = (int) $_GET['pmid'];
587 602
 
588 603
 		// Make sure you have access to this PM.
589
-		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
590
-			fatal_lang_error('no_access', false);
604
+		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
605
+					fatal_lang_error('no_access', false);
606
+		}
591 607
 
592 608
 		$context['current_pm'] = $pmID;
593 609
 
594 610
 		// With only one page of PM's we're gonna want page 1.
595
-		if ($max_messages <= $maxPerPage)
596
-			$_GET['start'] = 0;
611
+		if ($max_messages <= $maxPerPage) {
612
+					$_GET['start'] = 0;
613
+		}
597 614
 		// If we pass kstart we assume we're in the right place.
598 615
 		elseif (!isset($_GET['kstart']))
599 616
 		{
600
-			if ($context['folder'] == 'sent')
601
-				$request = $smcFunc['db_query']('', '
617
+			if ($context['folder'] == 'sent') {
618
+							$request = $smcFunc['db_query']('', '
602 619
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
603 620
 					FROM {db_prefix}personal_messages
604 621
 					WHERE id_member_from = {int:current_member}
@@ -610,8 +627,8 @@  discard block
 block discarded – undo
610 627
 						'id_pm' => $pmID,
611 628
 					)
612 629
 				);
613
-			else
614
-				$request = $smcFunc['db_query']('', '
630
+			} else {
631
+							$request = $smcFunc['db_query']('', '
615 632
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
616 633
 					FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
617 634
 						INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -624,6 +641,7 @@  discard block
 block discarded – undo
624 641
 						'id_pm' => $pmID,
625 642
 					)
626 643
 				);
644
+			}
627 645
 
628 646
 			list ($_GET['start']) = $smcFunc['db_fetch_row']($request);
629 647
 			$smcFunc['db_free_result']($request);
@@ -638,8 +656,9 @@  discard block
 block discarded – undo
638 656
 	{
639 657
 		$pmsg = (int) $_GET['pmsg'];
640 658
 
641
-		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
642
-			fatal_lang_error('no_access', false);
659
+		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
660
+					fatal_lang_error('no_access', false);
661
+		}
643 662
 	}
644 663
 
645 664
 	// Set up the page index.
@@ -734,8 +753,9 @@  discard block
 block discarded – undo
734 753
 	{
735 754
 		if (!isset($recipients[$row['id_pm']]))
736 755
 		{
737
-			if (isset($row['id_member_from']))
738
-				$posters[$row['id_pm']] = $row['id_member_from'];
756
+			if (isset($row['id_member_from'])) {
757
+							$posters[$row['id_pm']] = $row['id_member_from'];
758
+			}
739 759
 			$pms[$row['id_pm']] = $row['id_pm'];
740 760
 			$recipients[$row['id_pm']] = array(
741 761
 				'to' => array(),
@@ -744,29 +764,33 @@  discard block
 block discarded – undo
744 764
 		}
745 765
 
746 766
 		// Keep track of the last message so we know what the head is without another query!
747
-		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm']))
748
-			$lastData = array(
767
+		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) {
768
+					$lastData = array(
749 769
 				'id' => $row['id_pm'],
750 770
 				'head' => $row['id_pm_head'],
751 771
 			);
772
+		}
752 773
 	}
753 774
 	$smcFunc['db_free_result']($request);
754 775
 
755 776
 	// Make sure that we have been given a correct head pm id!
756
-	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id'])
757
-		fatal_lang_error('no_access', false);
777
+	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) {
778
+			fatal_lang_error('no_access', false);
779
+	}
758 780
 
759 781
 	if (!empty($pms))
760 782
 	{
761 783
 		// Select the correct current message.
762
-		if (empty($pmID))
763
-			$context['current_pm'] = $lastData['id'];
784
+		if (empty($pmID)) {
785
+					$context['current_pm'] = $lastData['id'];
786
+		}
764 787
 
765 788
 		// This is a list of the pm's that are used for "full" display.
766
-		if ($context['display_mode'] == 0)
767
-			$display_pms = $pms;
768
-		else
769
-			$display_pms = array($context['current_pm']);
789
+		if ($context['display_mode'] == 0) {
790
+					$display_pms = $pms;
791
+		} else {
792
+					$display_pms = array($context['current_pm']);
793
+		}
770 794
 
771 795
 		// At this point we know the main id_pm's. But - if we are looking at conversations we need the others!
772 796
 		if ($context['display_mode'] == 2)
@@ -788,16 +812,18 @@  discard block
 block discarded – undo
788 812
 			while ($row = $smcFunc['db_fetch_assoc']($request))
789 813
 			{
790 814
 				// This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn!
791
-				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1)
792
-					continue;
793
-				elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1)
794
-					continue;
815
+				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) {
816
+									continue;
817
+				} elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) {
818
+									continue;
819
+				}
795 820
 
796
-				if (!isset($recipients[$row['id_pm']]))
797
-					$recipients[$row['id_pm']] = array(
821
+				if (!isset($recipients[$row['id_pm']])) {
822
+									$recipients[$row['id_pm']] = array(
798 823
 						'to' => array(),
799 824
 						'bcc' => array()
800 825
 					);
826
+				}
801 827
 				$display_pms[] = $row['id_pm'];
802 828
 				$posters[$row['id_pm']] = $row['id_member_from'];
803 829
 			}
@@ -848,8 +874,9 @@  discard block
 block discarded – undo
848 874
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
849 875
 				{
850 876
 					$l_id = $row2['id_label'];
851
-					if (isset($context['labels'][$l_id]))
852
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
877
+					if (isset($context['labels'][$l_id])) {
878
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
879
+					}
853 880
 				}
854 881
 
855 882
 				$smcFunc['db_free_result']($request2);
@@ -866,9 +893,10 @@  discard block
 block discarded – undo
866 893
 		// Make sure we don't load unnecessary data.
867 894
 		if ($context['display_mode'] == 1)
868 895
 		{
869
-			foreach ($posters as $k => $v)
870
-				if (!in_array($k, $display_pms))
896
+			foreach ($posters as $k => $v) {
897
+							if (!in_array($k, $display_pms))
871 898
 					unset($posters[$k]);
899
+			}
872 900
 		}
873 901
 
874 902
 		// Load any users....
@@ -879,8 +907,9 @@  discard block
 block discarded – undo
879 907
 		{
880 908
 			// Get the order right.
881 909
 			$orderBy = array();
882
-			foreach (array_reverse($pms) as $pm)
883
-				$orderBy[] = 'pm.id_pm = ' . $pm;
910
+			foreach (array_reverse($pms) as $pm) {
911
+							$orderBy[] = 'pm.id_pm = ' . $pm;
912
+			}
884 913
 
885 914
 			// Seperate query for these bits!
886 915
 			$subjects_request = $smcFunc['db_query']('', '
@@ -926,9 +955,9 @@  discard block
 block discarded – undo
926 955
 			// Allow mods to add additional buttons here
927 956
 			call_integration_hook('integrate_conversation_buttons');
928 957
 		}
958
+	} else {
959
+			$messages_request = false;
929 960
 	}
930
-	else
931
-		$messages_request = false;
932 961
 
933 962
 	$context['can_send_pm'] = allowedTo('pm_send');
934 963
 	$context['can_send_email'] = allowedTo('moderate_forum');
@@ -939,11 +968,13 @@  discard block
 block discarded – undo
939 968
 	if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages']))
940 969
 	{
941 970
 		// If the display mode is "old sk00l" do them all...
942
-		if ($context['display_mode'] == 0)
943
-			markMessages(null, $context['current_label_id']);
971
+		if ($context['display_mode'] == 0) {
972
+					markMessages(null, $context['current_label_id']);
973
+		}
944 974
 		// Otherwise do just the current one!
945
-		elseif (!empty($context['current_pm']))
946
-			markMessages($display_pms, $context['current_label_id']);
975
+		elseif (!empty($context['current_pm'])) {
976
+					markMessages($display_pms, $context['current_label_id']);
977
+		}
947 978
 	}
948 979
 }
949 980
 
@@ -961,8 +992,9 @@  discard block
 block discarded – undo
961 992
 
962 993
 	// Count the current message number....
963 994
 	static $counter = null;
964
-	if ($counter === null || $reset)
965
-		$counter = $context['start'];
995
+	if ($counter === null || $reset) {
996
+			$counter = $context['start'];
997
+	}
966 998
 
967 999
 	static $temp_pm_selected = null;
968 1000
 	if ($temp_pm_selected === null)
@@ -1007,19 +1039,22 @@  discard block
 block discarded – undo
1007 1039
 	}
1008 1040
 
1009 1041
 	// Bail if it's false, ie. no messages.
1010
-	if ($messages_request == false)
1011
-		return false;
1042
+	if ($messages_request == false) {
1043
+			return false;
1044
+	}
1012 1045
 
1013 1046
 	// Reset the data?
1014
-	if ($reset == true)
1015
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1047
+	if ($reset == true) {
1048
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1049
+	}
1016 1050
 
1017 1051
 	// Get the next one... bail if anything goes wrong.
1018 1052
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1019 1053
 	if (!$message)
1020 1054
 	{
1021
-		if ($type != 'subject')
1022
-			$smcFunc['db_free_result']($messages_request);
1055
+		if ($type != 'subject') {
1056
+					$smcFunc['db_free_result']($messages_request);
1057
+		}
1023 1058
 
1024 1059
 		return false;
1025 1060
 	}
@@ -1039,8 +1074,7 @@  discard block
 block discarded – undo
1039 1074
 		$memberContext[$message['id_member_from']]['email'] = '';
1040 1075
 		$memberContext[$message['id_member_from']]['show_email'] = false;
1041 1076
 		$memberContext[$message['id_member_from']]['is_guest'] = true;
1042
-	}
1043
-	else
1077
+	} else
1044 1078
 	{
1045 1079
 		$memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']);
1046 1080
 		$memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id'])));
@@ -1081,12 +1115,13 @@  discard block
 block discarded – undo
1081 1115
 	$counter++;
1082 1116
 
1083 1117
 	// Any custom profile fields?
1084
-	if (!empty($memberContext[$message['id_member_from']]['custom_fields']))
1085
-		foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1118
+	if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) {
1119
+			foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1086 1120
 			switch ($custom['placement'])
1087 1121
 			{
1088 1122
 				case 1:
1089 1123
 					$output['custom_fields']['icons'][] = $custom;
1124
+	}
1090 1125
 					break;
1091 1126
 				case 2:
1092 1127
 					$output['custom_fields']['above_signature'][] = $custom;
@@ -1129,22 +1164,28 @@  discard block
 block discarded – undo
1129 1164
 			$context['search_params'][$k] = $v;
1130 1165
 		}
1131 1166
 	}
1132
-	if (isset($_REQUEST['search']))
1133
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1167
+	if (isset($_REQUEST['search'])) {
1168
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1169
+	}
1134 1170
 
1135
-	if (isset($context['search_params']['search']))
1136
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1137
-	if (isset($context['search_params']['userspec']))
1138
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1171
+	if (isset($context['search_params']['search'])) {
1172
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1173
+	}
1174
+	if (isset($context['search_params']['userspec'])) {
1175
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1176
+	}
1139 1177
 
1140
-	if (!empty($context['search_params']['searchtype']))
1141
-		$context['search_params']['searchtype'] = 2;
1178
+	if (!empty($context['search_params']['searchtype'])) {
1179
+			$context['search_params']['searchtype'] = 2;
1180
+	}
1142 1181
 
1143
-	if (!empty($context['search_params']['minage']))
1144
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1182
+	if (!empty($context['search_params']['minage'])) {
1183
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1184
+	}
1145 1185
 
1146
-	if (!empty($context['search_params']['maxage']))
1147
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1186
+	if (!empty($context['search_params']['maxage'])) {
1187
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1188
+	}
1148 1189
 
1149 1190
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
1150 1191
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
@@ -1171,8 +1212,9 @@  discard block
 block discarded – undo
1171 1212
 		$context['search_errors']['messages'] = array();
1172 1213
 		foreach ($context['search_errors'] as $search_error => $dummy)
1173 1214
 		{
1174
-			if ($search_error == 'messages')
1175
-				continue;
1215
+			if ($search_error == 'messages') {
1216
+							continue;
1217
+			}
1176 1218
 
1177 1219
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
1178 1220
 		}
@@ -1194,8 +1236,9 @@  discard block
 block discarded – undo
1194 1236
 	global $scripturl, $modSettings, $user_info, $context, $txt;
1195 1237
 	global $memberContext, $smcFunc;
1196 1238
 
1197
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
1198
-		fatal_lang_error('loadavg_search_disabled', false);
1239
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
1240
+			fatal_lang_error('loadavg_search_disabled', false);
1241
+	}
1199 1242
 
1200 1243
 	/**
1201 1244
 	 * @todo For the moment force the folder to the inbox.
@@ -1224,35 +1267,40 @@  discard block
 block discarded – undo
1224 1267
 	$context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1225 1268
 
1226 1269
 	// Store whether simple search was used (needed if the user wants to do another query).
1227
-	if (!isset($search_params['advanced']))
1228
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1270
+	if (!isset($search_params['advanced'])) {
1271
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1272
+	}
1229 1273
 
1230 1274
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
1231
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
1232
-		$search_params['searchtype'] = 2;
1275
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
1276
+			$search_params['searchtype'] = 2;
1277
+	}
1233 1278
 
1234 1279
 	// Minimum age of messages. Default to zero (don't set param in that case).
1235
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
1236
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1280
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
1281
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1282
+	}
1237 1283
 
1238 1284
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
1239
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999))
1240
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1285
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) {
1286
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1287
+	}
1241 1288
 
1242 1289
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
1243 1290
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
1244 1291
 
1245 1292
 	// Default the user name to a wildcard matching every user (*).
1246
-	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
1247
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1293
+	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
1294
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1295
+	}
1248 1296
 
1249 1297
 	// This will be full of all kinds of parameters!
1250 1298
 	$searchq_parameters = array();
1251 1299
 
1252 1300
 	// If there's no specific user, then don't mention it in the main query.
1253
-	if (empty($search_params['userspec']))
1254
-		$userQuery = '';
1255
-	else
1301
+	if (empty($search_params['userspec'])) {
1302
+			$userQuery = '';
1303
+	} else
1256 1304
 	{
1257 1305
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
1258 1306
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -1264,8 +1312,9 @@  discard block
 block discarded – undo
1264 1312
 		{
1265 1313
 			$possible_users[$k] = trim($possible_users[$k]);
1266 1314
 
1267
-			if (strlen($possible_users[$k]) == 0)
1268
-				unset($possible_users[$k]);
1315
+			if (strlen($possible_users[$k]) == 0) {
1316
+							unset($possible_users[$k]);
1317
+			}
1269 1318
 		}
1270 1319
 
1271 1320
 		if (!empty($possible_users))
@@ -1277,8 +1326,9 @@  discard block
 block discarded – undo
1277 1326
 			{
1278 1327
 				$where_params['name_' . $k] = $v;
1279 1328
 				$where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}';
1280
-				if (!isset($where_params['real_name']))
1281
-					$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1329
+				if (!isset($where_params['real_name'])) {
1330
+									$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1331
+				}
1282 1332
 			}
1283 1333
 
1284 1334
 			// Who matches those criteria?
@@ -1291,28 +1341,28 @@  discard block
 block discarded – undo
1291 1341
 			);
1292 1342
 
1293 1343
 			// Simply do nothing if there're too many members matching the criteria.
1294
-			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
1295
-				$userQuery = '';
1296
-			elseif ($smcFunc['db_num_rows']($request) == 0)
1344
+			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
1345
+							$userQuery = '';
1346
+			} elseif ($smcFunc['db_num_rows']($request) == 0)
1297 1347
 			{
1298 1348
 				$userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})';
1299 1349
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1300 1350
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1301
-			}
1302
-			else
1351
+			} else
1303 1352
 			{
1304 1353
 				$memberlist = array();
1305
-				while ($row = $smcFunc['db_fetch_assoc']($request))
1306
-					$memberlist[] = $row['id_member'];
1354
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
1355
+									$memberlist[] = $row['id_member'];
1356
+				}
1307 1357
 				$userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))';
1308 1358
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1309 1359
 				$searchq_parameters['member_list'] = $memberlist;
1310 1360
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1311 1361
 			}
1312 1362
 			$smcFunc['db_free_result']($request);
1363
+		} else {
1364
+					$userQuery = '';
1313 1365
 		}
1314
-		else
1315
-			$userQuery = '';
1316 1366
 	}
1317 1367
 
1318 1368
 	// Setup the sorting variables...
@@ -1320,8 +1370,9 @@  discard block
 block discarded – undo
1320 1370
 	$sort_columns = array(
1321 1371
 		'pm.id_pm',
1322 1372
 	);
1323
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
1324
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1373
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
1374
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1375
+	}
1325 1376
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';
1326 1377
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
1327 1378
 
@@ -1331,24 +1382,27 @@  discard block
 block discarded – undo
1331 1382
 	if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels'])
1332 1383
 	{
1333 1384
 		// Came here from pagination?  Put them back into $_REQUEST for sanitization.
1334
-		if (isset($search_params['labels']))
1335
-			$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1385
+		if (isset($search_params['labels'])) {
1386
+					$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1387
+		}
1336 1388
 
1337 1389
 		// Assuming we have some labels - make them all integers.
1338 1390
 		if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel']))
1339 1391
 		{
1340
-			foreach ($_REQUEST['searchlabel'] as $key => $id)
1341
-				$_REQUEST['searchlabel'][$key] = (int) $id;
1392
+			foreach ($_REQUEST['searchlabel'] as $key => $id) {
1393
+							$_REQUEST['searchlabel'][$key] = (int) $id;
1394
+			}
1395
+		} else {
1396
+					$_REQUEST['searchlabel'] = array();
1342 1397
 		}
1343
-		else
1344
-			$_REQUEST['searchlabel'] = array();
1345 1398
 
1346 1399
 		// Now that everything is cleaned up a bit, make the labels a param.
1347 1400
 		$search_params['labels'] = implode(',', $_REQUEST['searchlabel']);
1348 1401
 
1349 1402
 		// No labels selected? That must be an error!
1350
-		if (empty($_REQUEST['searchlabel']))
1351
-			$context['search_errors']['no_labels_selected'] = true;
1403
+		if (empty($_REQUEST['searchlabel'])) {
1404
+					$context['search_errors']['no_labels_selected'] = true;
1405
+		}
1352 1406
 		// Otherwise prepare the query!
1353 1407
 		elseif (count($_REQUEST['searchlabel']) != count($context['labels']))
1354 1408
 		{
@@ -1371,8 +1425,7 @@  discard block
 block discarded – undo
1371 1425
 					// Not searching the inbox - PM must be labeled
1372 1426
 					$labelQuery = ' AND pml.id_label IN ({array_int:labels})';
1373 1427
 					$labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)';
1374
-				}
1375
-				else
1428
+				} else
1376 1429
 				{
1377 1430
 					// Searching the inbox - PM doesn't have to be labeled
1378 1431
 					$labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))';
@@ -1387,8 +1440,9 @@  discard block
 block discarded – undo
1387 1440
 	// What are we actually searching for?
1388 1441
 	$search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');
1389 1442
 	// If we ain't got nothing - we should error!
1390
-	if (!isset($search_params['search']) || $search_params['search'] == '')
1391
-		$context['search_errors']['invalid_search_string'] = true;
1443
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
1444
+			$context['search_errors']['invalid_search_string'] = true;
1445
+	}
1392 1446
 
1393 1447
 	// Extract phrase parts first (e.g. some words "this is a phrase" some more words.)
1394 1448
 	preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER);
@@ -1401,12 +1455,14 @@  discard block
 block discarded – undo
1401 1455
 	$excludedWords = array();
1402 1456
 
1403 1457
 	// .. first, we check for things like -"some words", but not "-some words".
1404
-	foreach ($matches[1] as $index => $word)
1405
-		if ($word == '-')
1458
+	foreach ($matches[1] as $index => $word) {
1459
+			if ($word == '-')
1406 1460
 		{
1407 1461
 			$word = $smcFunc['strtolower'](trim($searchArray[$index]));
1408
-			if (strlen($word) > 0)
1409
-				$excludedWords[] = $word;
1462
+	}
1463
+			if (strlen($word) > 0) {
1464
+							$excludedWords[] = $word;
1465
+			}
1410 1466
 			unset($searchArray[$index]);
1411 1467
 		}
1412 1468
 
@@ -1416,8 +1472,9 @@  discard block
 block discarded – undo
1416 1472
 		if (strpos(trim($word), '-') === 0)
1417 1473
 		{
1418 1474
 			$word = substr($smcFunc['strtolower']($word), 1);
1419
-			if (strlen($word) > 0)
1420
-				$excludedWords[] = $word;
1475
+			if (strlen($word) > 0) {
1476
+							$excludedWords[] = $word;
1477
+			}
1421 1478
 			unset($tempSearch[$index]);
1422 1479
 		}
1423 1480
 	}
@@ -1428,9 +1485,9 @@  discard block
 block discarded – undo
1428 1485
 	foreach ($searchArray as $index => $value)
1429 1486
 	{
1430 1487
 		$searchArray[$index] = $smcFunc['strtolower'](trim($value));
1431
-		if ($searchArray[$index] == '')
1432
-			unset($searchArray[$index]);
1433
-		else
1488
+		if ($searchArray[$index] == '') {
1489
+					unset($searchArray[$index]);
1490
+		} else
1434 1491
 		{
1435 1492
 			// Sort out entities first.
1436 1493
 			$searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]);
@@ -1440,27 +1497,32 @@  discard block
 block discarded – undo
1440 1497
 
1441 1498
 	// Create an array of replacements for highlighting.
1442 1499
 	$context['mark'] = array();
1443
-	foreach ($searchArray as $word)
1444
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1500
+	foreach ($searchArray as $word) {
1501
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1502
+	}
1445 1503
 
1446 1504
 	// This contains *everything*
1447 1505
 	$searchWords = array_merge($searchArray, $excludedWords);
1448 1506
 
1449 1507
 	// Make sure at least one word is being searched for.
1450
-	if (empty($searchArray))
1451
-		$context['search_errors']['invalid_search_string'] = true;
1508
+	if (empty($searchArray)) {
1509
+			$context['search_errors']['invalid_search_string'] = true;
1510
+	}
1452 1511
 
1453 1512
 	// Sort out the search query so the user can edit it - if they want.
1454 1513
 	$context['search_params'] = $search_params;
1455
-	if (isset($context['search_params']['search']))
1456
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1457
-	if (isset($context['search_params']['userspec']))
1458
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1514
+	if (isset($context['search_params']['search'])) {
1515
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1516
+	}
1517
+	if (isset($context['search_params']['userspec'])) {
1518
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1519
+	}
1459 1520
 
1460 1521
 	// Now we have all the parameters, combine them together for pagination and the like...
1461 1522
 	$context['params'] = array();
1462
-	foreach ($search_params as $k => $v)
1463
-		$context['params'][] = $k . '|\'|' . $v;
1523
+	foreach ($search_params as $k => $v) {
1524
+			$context['params'][] = $k . '|\'|' . $v;
1525
+	}
1464 1526
 	$context['params'] = base64_encode(implode('|"|', $context['params']));
1465 1527
 
1466 1528
 	// Compile the subject query part.
@@ -1468,26 +1530,31 @@  discard block
 block discarded – undo
1468 1530
 
1469 1531
 	foreach ($searchWords as $index => $word)
1470 1532
 	{
1471
-		if ($word == '')
1472
-			continue;
1533
+		if ($word == '') {
1534
+					continue;
1535
+		}
1473 1536
 
1474
-		if ($search_params['subject_only'])
1475
-			$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1476
-		else
1477
-			$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1537
+		if ($search_params['subject_only']) {
1538
+					$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1539
+		} else {
1540
+					$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1541
+		}
1478 1542
 		$searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%';
1479 1543
 	}
1480 1544
 
1481 1545
 	$searchQuery = ' 1=1';
1482
-	if (!empty($andQueryParts))
1483
-		$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1546
+	if (!empty($andQueryParts)) {
1547
+			$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1548
+	}
1484 1549
 
1485 1550
 	// Age limits?
1486 1551
 	$timeQuery = '';
1487
-	if (!empty($search_params['minage']))
1488
-		$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1489
-	if (!empty($search_params['maxage']))
1490
-		$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1552
+	if (!empty($search_params['minage'])) {
1553
+			$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1554
+	}
1555
+	if (!empty($search_params['maxage'])) {
1556
+			$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1557
+	}
1491 1558
 
1492 1559
 	// If we have errors - return back to the first screen...
1493 1560
 	if (!empty($context['search_errors']))
@@ -1573,8 +1640,9 @@  discard block
 block discarded – undo
1573 1640
 			)
1574 1641
 		);
1575 1642
 		$real_pm_ids = array();
1576
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1577
-			$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1643
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1644
+					$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1645
+		}
1578 1646
 		$smcFunc['db_free_result']($request);
1579 1647
 	}
1580 1648
 
@@ -1604,8 +1672,9 @@  discard block
 block discarded – undo
1604 1672
 		);
1605 1673
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1606 1674
 		{
1607
-			if ($context['folder'] == 'sent' || empty($row['bcc']))
1608
-				$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1675
+			if ($context['folder'] == 'sent' || empty($row['bcc'])) {
1676
+							$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1677
+			}
1609 1678
 
1610 1679
 			if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
1611 1680
 			{
@@ -1626,12 +1695,14 @@  discard block
 block discarded – undo
1626 1695
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
1627 1696
 				{
1628 1697
 					$l_id = $row2['id_label'];
1629
-					if (isset($context['labels'][$l_id]))
1630
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1698
+					if (isset($context['labels'][$l_id])) {
1699
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1700
+					}
1631 1701
 
1632 1702
 					// Here we find the first label on a message - for linking to posts in results
1633
-					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1)
1634
-						$context['first_label'][$row['id_pm']] = $l_id;
1703
+					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) {
1704
+											$context['first_label'][$row['id_pm']] = $l_id;
1705
+					}
1635 1706
 				}
1636 1707
 
1637 1708
 				$smcFunc['db_free_result']($request2);
@@ -1758,8 +1829,9 @@  discard block
 block discarded – undo
1758 1829
 		list ($postCount) = $smcFunc['db_fetch_row']($request);
1759 1830
 		$smcFunc['db_free_result']($request);
1760 1831
 
1761
-		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
1762
-			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1832
+		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) {
1833
+					fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1834
+		}
1763 1835
 	}
1764 1836
 
1765 1837
 	// Quoting/Replying to a message?
@@ -1768,8 +1840,9 @@  discard block
 block discarded – undo
1768 1840
 		$pmsg = (int) $_REQUEST['pmsg'];
1769 1841
 
1770 1842
 		// Make sure this is yours.
1771
-		if (!isAccessiblePM($pmsg))
1772
-			fatal_lang_error('no_access', false);
1843
+		if (!isAccessiblePM($pmsg)) {
1844
+					fatal_lang_error('no_access', false);
1845
+		}
1773 1846
 
1774 1847
 		// Work out whether this is one you've received?
1775 1848
 		$request = $smcFunc['db_query']('', '
@@ -1806,8 +1879,9 @@  discard block
 block discarded – undo
1806 1879
 				'id_pm' => $pmsg,
1807 1880
 			)
1808 1881
 		);
1809
-		if ($smcFunc['db_num_rows']($request) == 0)
1810
-			fatal_lang_error('pm_not_yours', false);
1882
+		if ($smcFunc['db_num_rows']($request) == 0) {
1883
+					fatal_lang_error('pm_not_yours', false);
1884
+		}
1811 1885
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
1812 1886
 		$smcFunc['db_free_result']($request);
1813 1887
 
@@ -1818,9 +1892,9 @@  discard block
 block discarded – undo
1818 1892
 		// Add 'Re: ' to it....
1819 1893
 		if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
1820 1894
 		{
1821
-			if ($language === $user_info['language'])
1822
-				$context['response_prefix'] = $txt['response_prefix'];
1823
-			else
1895
+			if ($language === $user_info['language']) {
1896
+							$context['response_prefix'] = $txt['response_prefix'];
1897
+			} else
1824 1898
 			{
1825 1899
 				loadLanguage('index', $language, false);
1826 1900
 				$context['response_prefix'] = $txt['response_prefix'];
@@ -1829,22 +1903,25 @@  discard block
 block discarded – undo
1829 1903
 			cache_put_data('response_prefix', $context['response_prefix'], 600);
1830 1904
 		}
1831 1905
 		$form_subject = $row_quoted['subject'];
1832
-		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
1833
-			$form_subject = $context['response_prefix'] . $form_subject;
1906
+		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
1907
+					$form_subject = $context['response_prefix'] . $form_subject;
1908
+		}
1834 1909
 
1835 1910
 		if (isset($_REQUEST['quote']))
1836 1911
 		{
1837 1912
 			// Remove any nested quotes and <br>...
1838 1913
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']);
1839
-			if (!empty($modSettings['removeNestedQuotes']))
1840
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1841
-			if (empty($row_quoted['id_member']))
1842
-				$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1843
-			else
1844
-				$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1914
+			if (!empty($modSettings['removeNestedQuotes'])) {
1915
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1916
+			}
1917
+			if (empty($row_quoted['id_member'])) {
1918
+							$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1919
+			} else {
1920
+							$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1921
+			}
1922
+		} else {
1923
+					$form_message = '';
1845 1924
 		}
1846
-		else
1847
-			$form_message = '';
1848 1925
 
1849 1926
 		// Do the BBC thang on the message.
1850 1927
 		$row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);
@@ -1865,8 +1942,7 @@  discard block
 block discarded – undo
1865 1942
 			'timestamp' => forum_time(true, $row_quoted['msgtime']),
1866 1943
 			'body' => $row_quoted['body']
1867 1944
 		);
1868
-	}
1869
-	else
1945
+	} else
1870 1946
 	{
1871 1947
 		$context['quoted_message'] = false;
1872 1948
 		$form_subject = '';
@@ -1885,11 +1961,12 @@  discard block
 block discarded – undo
1885 1961
 		if ($_REQUEST['u'] == 'all' && isset($row_quoted))
1886 1962
 		{
1887 1963
 			// Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.
1888
-			if ($row_quoted['id_member'] != $user_info['id'])
1889
-				$context['recipients']['to'][] = array(
1964
+			if ($row_quoted['id_member'] != $user_info['id']) {
1965
+							$context['recipients']['to'][] = array(
1890 1966
 					'id' => $row_quoted['id_member'],
1891 1967
 					'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']),
1892 1968
 				);
1969
+			}
1893 1970
 
1894 1971
 			// Now to get the others.
1895 1972
 			$request = $smcFunc['db_query']('', '
@@ -1905,18 +1982,19 @@  discard block
 block discarded – undo
1905 1982
 					'not_bcc' => 0,
1906 1983
 				)
1907 1984
 			);
1908
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1909
-				$context['recipients']['to'][] = array(
1985
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1986
+							$context['recipients']['to'][] = array(
1910 1987
 					'id' => $row['id_member'],
1911 1988
 					'name' => $row['real_name'],
1912 1989
 				);
1990
+			}
1913 1991
 			$smcFunc['db_free_result']($request);
1914
-		}
1915
-		else
1992
+		} else
1916 1993
 		{
1917 1994
 			$_REQUEST['u'] = explode(',', $_REQUEST['u']);
1918
-			foreach ($_REQUEST['u'] as $key => $uID)
1919
-				$_REQUEST['u'][$key] = (int) $uID;
1995
+			foreach ($_REQUEST['u'] as $key => $uID) {
1996
+							$_REQUEST['u'][$key] = (int) $uID;
1997
+			}
1920 1998
 
1921 1999
 			$_REQUEST['u'] = array_unique($_REQUEST['u']);
1922 2000
 
@@ -1930,22 +2008,24 @@  discard block
 block discarded – undo
1930 2008
 					'limit' => count($_REQUEST['u']),
1931 2009
 				)
1932 2010
 			);
1933
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1934
-				$context['recipients']['to'][] = array(
2011
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2012
+							$context['recipients']['to'][] = array(
1935 2013
 					'id' => $row['id_member'],
1936 2014
 					'name' => $row['real_name'],
1937 2015
 				);
2016
+			}
1938 2017
 			$smcFunc['db_free_result']($request);
1939 2018
 		}
1940 2019
 
1941 2020
 		// Get a literal name list in case the user has JavaScript disabled.
1942 2021
 		$names = array();
1943
-		foreach ($context['recipients']['to'] as $to)
1944
-			$names[] = $to['name'];
2022
+		foreach ($context['recipients']['to'] as $to) {
2023
+					$names[] = $to['name'];
2024
+		}
1945 2025
 		$context['to_value'] = empty($names) ? '' : '&quot;' . implode('&quot;, &quot;', $names) . '&quot;';
2026
+	} else {
2027
+			$context['to_value'] = '';
1946 2028
 	}
1947
-	else
1948
-		$context['to_value'] = '';
1949 2029
 
1950 2030
 	// Set the defaults...
1951 2031
 	$context['subject'] = $form_subject;
@@ -2015,8 +2095,9 @@  discard block
 block discarded – undo
2015 2095
 
2016 2096
 	// validate with loadMemberData()
2017 2097
 	$memberResult = loadMemberData($user_info['id'], false);
2018
-	if (!$memberResult)
2019
-		fatal_lang_error('not_a_user', false);
2098
+	if (!$memberResult) {
2099
+			fatal_lang_error('not_a_user', false);
2100
+	}
2020 2101
 	list ($memID) = $memberResult;
2021 2102
 
2022 2103
 	// drafts is where the functions reside
@@ -2042,9 +2123,9 @@  discard block
 block discarded – undo
2042 2123
 		$context['sub_template'] = 'send';
2043 2124
 		loadJavaScriptFile('PersonalMessage.js', array('defer' => false), 'smf_pms');
2044 2125
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
2126
+	} else {
2127
+			$context['sub_template'] = 'pm';
2045 2128
 	}
2046
-	else
2047
-		$context['sub_template'] = 'pm';
2048 2129
 
2049 2130
 	$context['page_title'] = $txt['send_message'];
2050 2131
 
@@ -2105,10 +2186,11 @@  discard block
 block discarded – undo
2105 2186
 		);
2106 2187
 		if ($smcFunc['db_num_rows']($request) == 0)
2107 2188
 		{
2108
-			if (!isset($_REQUEST['xml']))
2109
-				fatal_lang_error('pm_not_yours', false);
2110
-			else
2111
-				$error_types[] = 'pm_not_yours';
2189
+			if (!isset($_REQUEST['xml'])) {
2190
+							fatal_lang_error('pm_not_yours', false);
2191
+			} else {
2192
+							$error_types[] = 'pm_not_yours';
2193
+			}
2112 2194
 		}
2113 2195
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
2114 2196
 		$smcFunc['db_free_result']($request);
@@ -2155,14 +2237,16 @@  discard block
 block discarded – undo
2155 2237
 		$context['post_error'][$error_type] = true;
2156 2238
 		if (isset($txt['error_' . $error_type]))
2157 2239
 		{
2158
-			if ($error_type == 'long_message')
2159
-				$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2240
+			if ($error_type == 'long_message') {
2241
+							$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2242
+			}
2160 2243
 			$context['post_error']['messages'][] = $txt['error_' . $error_type];
2161 2244
 		}
2162 2245
 
2163 2246
 		// If it's not a minor error flag it as such.
2164
-		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject')))
2165
-			$context['error_type'] = 'serious';
2247
+		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) {
2248
+					$context['error_type'] = 'serious';
2249
+		}
2166 2250
 	}
2167 2251
 
2168 2252
 	// We need to load the editor once more.
@@ -2220,8 +2304,9 @@  discard block
 block discarded – undo
2220 2304
 	require_once($sourcedir . '/Subs-Auth.php');
2221 2305
 
2222 2306
 	// PM Drafts enabled and needed?
2223
-	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft'])))
2224
-		require_once($sourcedir . '/Drafts.php');
2307
+	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) {
2308
+			require_once($sourcedir . '/Drafts.php');
2309
+	}
2225 2310
 
2226 2311
 	loadLanguage('PersonalMessage', '', false);
2227 2312
 
@@ -2251,24 +2336,27 @@  discard block
 block discarded – undo
2251 2336
 
2252 2337
 		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
2253 2338
 		{
2254
-			if (!isset($_REQUEST['xml']))
2255
-				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2256
-			else
2257
-				$post_errors[] = 'pm_too_many_per_hour';
2339
+			if (!isset($_REQUEST['xml'])) {
2340
+							fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2341
+			} else {
2342
+							$post_errors[] = 'pm_too_many_per_hour';
2343
+			}
2258 2344
 		}
2259 2345
 	}
2260 2346
 
2261 2347
 	// If your session timed out, show an error, but do allow to re-submit.
2262
-	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '')
2263
-		$post_errors[] = 'session_timeout';
2348
+	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') {
2349
+			$post_errors[] = 'session_timeout';
2350
+	}
2264 2351
 
2265 2352
 	$_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
2266 2353
 	$_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];
2267 2354
 	$_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];
2268 2355
 
2269 2356
 	// Route the input from the 'u' parameter to the 'to'-list.
2270
-	if (!empty($_POST['u']))
2271
-		$_POST['recipient_to'] = explode(',', $_POST['u']);
2357
+	if (!empty($_POST['u'])) {
2358
+			$_POST['recipient_to'] = explode(',', $_POST['u']);
2359
+	}
2272 2360
 
2273 2361
 	// Construct the list of recipients.
2274 2362
 	$recipientList = array();
@@ -2280,8 +2368,9 @@  discard block
 block discarded – undo
2280 2368
 		$recipientList[$recipientType] = array();
2281 2369
 		if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))
2282 2370
 		{
2283
-			foreach ($_POST['recipient_' . $recipientType] as $recipient)
2284
-				$recipientList[$recipientType][] = (int) $recipient;
2371
+			foreach ($_POST['recipient_' . $recipientType] as $recipient) {
2372
+							$recipientList[$recipientType][] = (int) $recipient;
2373
+			}
2285 2374
 		}
2286 2375
 
2287 2376
 		// Are there also literal names set?
@@ -2295,10 +2384,11 @@  discard block
 block discarded – undo
2295 2384
 
2296 2385
 			foreach ($namedRecipientList[$recipientType] as $index => $recipient)
2297 2386
 			{
2298
-				if (strlen(trim($recipient)) > 0)
2299
-					$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2300
-				else
2301
-					unset($namedRecipientList[$recipientType][$index]);
2387
+				if (strlen(trim($recipient)) > 0) {
2388
+									$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2389
+				} else {
2390
+									unset($namedRecipientList[$recipientType][$index]);
2391
+				}
2302 2392
 			}
2303 2393
 
2304 2394
 			if (!empty($namedRecipientList[$recipientType]))
@@ -2328,8 +2418,9 @@  discard block
 block discarded – undo
2328 2418
 		}
2329 2419
 
2330 2420
 		// Selected a recipient to be deleted? Remove them now.
2331
-		if (!empty($_POST['delete_recipient']))
2332
-			$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2421
+		if (!empty($_POST['delete_recipient'])) {
2422
+					$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2423
+		}
2333 2424
 
2334 2425
 		// Make sure we don't include the same name twice
2335 2426
 		$recipientList[$recipientType] = array_unique($recipientList[$recipientType]);
@@ -2339,8 +2430,9 @@  discard block
 block discarded – undo
2339 2430
 	$is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']);
2340 2431
 
2341 2432
 	// Check if there's at least one recipient.
2342
-	if (empty($recipientList['to']) && empty($recipientList['bcc']))
2343
-		$post_errors[] = 'no_to';
2433
+	if (empty($recipientList['to']) && empty($recipientList['bcc'])) {
2434
+			$post_errors[] = 'no_to';
2435
+	}
2344 2436
 
2345 2437
 	// Make sure that we remove the members who did get it from the screen.
2346 2438
 	if (!$is_recipient_change)
@@ -2354,28 +2446,31 @@  discard block
 block discarded – undo
2354 2446
 				// Since we already have a post error, remove the previous one.
2355 2447
 				$post_errors = array_diff($post_errors, array('no_to'));
2356 2448
 
2357
-				foreach ($namesNotFound[$recipientType] as $name)
2358
-					$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2449
+				foreach ($namesNotFound[$recipientType] as $name) {
2450
+									$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2451
+				}
2359 2452
 			}
2360 2453
 		}
2361 2454
 	}
2362 2455
 
2363 2456
 	// Did they make any mistakes?
2364
-	if ($_REQUEST['subject'] == '')
2365
-		$post_errors[] = 'no_subject';
2366
-	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '')
2367
-		$post_errors[] = 'no_message';
2368
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength'])
2369
-		$post_errors[] = 'long_message';
2370
-	else
2457
+	if ($_REQUEST['subject'] == '') {
2458
+			$post_errors[] = 'no_subject';
2459
+	}
2460
+	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
2461
+			$post_errors[] = 'no_message';
2462
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) {
2463
+			$post_errors[] = 'long_message';
2464
+	} else
2371 2465
 	{
2372 2466
 		// Preparse the message.
2373 2467
 		$message = $_REQUEST['message'];
2374 2468
 		preparsecode($message);
2375 2469
 
2376 2470
 		// Make sure there's still some content left without the tags.
2377
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false))
2378
-			$post_errors[] = 'no_message';
2471
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) {
2472
+					$post_errors[] = 'no_message';
2473
+		}
2379 2474
 	}
2380 2475
 
2381 2476
 	// Wrong verification code?
@@ -2387,13 +2482,15 @@  discard block
 block discarded – undo
2387 2482
 		);
2388 2483
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
2389 2484
 
2390
-		if (is_array($context['require_verification']))
2391
-			$post_errors = array_merge($post_errors, $context['require_verification']);
2485
+		if (is_array($context['require_verification'])) {
2486
+					$post_errors = array_merge($post_errors, $context['require_verification']);
2487
+		}
2392 2488
 	}
2393 2489
 
2394 2490
 	// If they did, give a chance to make ammends.
2395
-	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml']))
2396
-		return messagePostError($post_errors, $namedRecipientList, $recipientList);
2491
+	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) {
2492
+			return messagePostError($post_errors, $namedRecipientList, $recipientList);
2493
+	}
2397 2494
 
2398 2495
 	// Want to take a second glance before you send?
2399 2496
 	if (isset($_REQUEST['preview']))
@@ -2424,8 +2521,9 @@  discard block
 block discarded – undo
2424 2521
 		foreach ($namesNotFound as $recipientType => $names)
2425 2522
 		{
2426 2523
 			$post_errors[] = 'bad_' . $recipientType;
2427
-			foreach ($names as $name)
2428
-				$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2524
+			foreach ($names as $name) {
2525
+							$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2526
+			}
2429 2527
 		}
2430 2528
 
2431 2529
 		return messagePostError(array(), $namedRecipientList, $recipientList);
@@ -2455,13 +2553,14 @@  discard block
 block discarded – undo
2455 2553
 	checkSubmitOnce('check');
2456 2554
 
2457 2555
 	// Do the actual sending of the PM.
2458
-	if (!empty($recipientList['to']) || !empty($recipientList['bcc']))
2459
-		$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2460
-	else
2461
-		$context['send_log'] = array(
2556
+	if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) {
2557
+			$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2558
+	} else {
2559
+			$context['send_log'] = array(
2462 2560
 			'sent' => array(),
2463 2561
 			'failed' => array()
2464 2562
 		);
2563
+	}
2465 2564
 
2466 2565
 	// Mark the message as "replied to".
2467 2566
 	if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox')
@@ -2479,11 +2578,12 @@  discard block
 block discarded – undo
2479 2578
 	}
2480 2579
 
2481 2580
 	// If one or more of the recipient were invalid, go back to the post screen with the failed usernames.
2482
-	if (!empty($context['send_log']['failed']))
2483
-		return messagePostError($post_errors, $namesNotFound, array(
2581
+	if (!empty($context['send_log']['failed'])) {
2582
+			return messagePostError($post_errors, $namesNotFound, array(
2484 2583
 			'to' => array_intersect($recipientList['to'], $context['send_log']['failed']),
2485 2584
 			'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed'])
2486 2585
 		));
2586
+	}
2487 2587
 
2488 2588
 	// Message sent successfully?
2489 2589
 	if (!empty($context['send_log']) && empty($context['send_log']['failed']))
@@ -2491,8 +2591,9 @@  discard block
 block discarded – undo
2491 2591
 		$context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent';
2492 2592
 
2493 2593
 		// If we had a PM draft for this one, then its time to remove it since it was just sent
2494
-		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft']))
2495
-			DeleteDraft($_POST['id_pm_draft']);
2594
+		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) {
2595
+					DeleteDraft($_POST['id_pm_draft']);
2596
+		}
2496 2597
 	}
2497 2598
 
2498 2599
 	// Go back to the where they sent from, if possible...
@@ -2507,24 +2608,28 @@  discard block
 block discarded – undo
2507 2608
 
2508 2609
 	checkSession('request');
2509 2610
 
2510
-	if (isset($_REQUEST['del_selected']))
2511
-		$_REQUEST['pm_action'] = 'delete';
2611
+	if (isset($_REQUEST['del_selected'])) {
2612
+			$_REQUEST['pm_action'] = 'delete';
2613
+	}
2512 2614
 
2513 2615
 	if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms']))
2514 2616
 	{
2515
-		foreach ($_REQUEST['pms'] as $pm)
2516
-			$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2617
+		foreach ($_REQUEST['pms'] as $pm) {
2618
+					$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2619
+		}
2517 2620
 	}
2518 2621
 
2519
-	if (empty($_REQUEST['pm_actions']))
2520
-		redirectexit($context['current_label_redirect']);
2622
+	if (empty($_REQUEST['pm_actions'])) {
2623
+			redirectexit($context['current_label_redirect']);
2624
+	}
2521 2625
 
2522 2626
 	// If we are in conversation, we may need to apply this to every message in the conversation.
2523 2627
 	if ($context['display_mode'] == 2 && isset($_REQUEST['conversation']))
2524 2628
 	{
2525 2629
 		$id_pms = array();
2526
-		foreach ($_REQUEST['pm_actions'] as $pm => $dummy)
2527
-			$id_pms[] = (int) $pm;
2630
+		foreach ($_REQUEST['pm_actions'] as $pm => $dummy) {
2631
+					$id_pms[] = (int) $pm;
2632
+		}
2528 2633
 
2529 2634
 		$request = $smcFunc['db_query']('', '
2530 2635
 			SELECT id_pm_head, id_pm
@@ -2535,8 +2640,9 @@  discard block
 block discarded – undo
2535 2640
 			)
2536 2641
 		);
2537 2642
 		$pm_heads = array();
2538
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2539
-			$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2643
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2644
+					$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2645
+		}
2540 2646
 		$smcFunc['db_free_result']($request);
2541 2647
 
2542 2648
 		$request = $smcFunc['db_query']('', '
@@ -2550,8 +2656,9 @@  discard block
 block discarded – undo
2550 2656
 		// Copy the action from the single to PM to the others.
2551 2657
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2552 2658
 		{
2553
-			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]))
2554
-				$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2659
+			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) {
2660
+							$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2661
+			}
2555 2662
 		}
2556 2663
 		$smcFunc['db_free_result']($request);
2557 2664
 	}
@@ -2562,22 +2669,21 @@  discard block
 block discarded – undo
2562 2669
 	$labels = array();
2563 2670
 	foreach ($_REQUEST['pm_actions'] as $pm => $action)
2564 2671
 	{
2565
-		if ($action === 'delete')
2566
-			$to_delete[] = (int) $pm;
2567
-		else
2672
+		if ($action === 'delete') {
2673
+					$to_delete[] = (int) $pm;
2674
+		} else
2568 2675
 		{
2569 2676
 			if (substr($action, 0, 4) == 'add_')
2570 2677
 			{
2571 2678
 				$type = 'add';
2572 2679
 				$action = substr($action, 4);
2573
-			}
2574
-			elseif (substr($action, 0, 4) == 'rem_')
2680
+			} elseif (substr($action, 0, 4) == 'rem_')
2575 2681
 			{
2576 2682
 				$type = 'rem';
2577 2683
 				$action = substr($action, 4);
2684
+			} else {
2685
+							$type = 'unk';
2578 2686
 			}
2579
-			else
2580
-				$type = 'unk';
2581 2687
 
2582 2688
 			if ($action == '-1' || (int) $action > 0)
2583 2689
 			{
@@ -2588,8 +2694,9 @@  discard block
 block discarded – undo
2588 2694
 	}
2589 2695
 
2590 2696
 	// Deleting, it looks like?
2591
-	if (!empty($to_delete))
2592
-		deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2697
+	if (!empty($to_delete)) {
2698
+			deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2699
+	}
2593 2700
 
2594 2701
 	// Are we labeling anything?
2595 2702
 	if (!empty($to_label) && $context['folder'] == 'inbox')
@@ -2655,8 +2762,7 @@  discard block
 block discarded – undo
2655 2762
 				}
2656 2763
 
2657 2764
 				$smcFunc['db_free_result']($request2);
2658
-			}
2659
-			elseif ($type == 'rem')
2765
+			} elseif ($type == 'rem')
2660 2766
 			{
2661 2767
 				// If we're removing from the inbox, see if we have at least one other label.
2662 2768
 				// This query is faster than the one above
@@ -2688,21 +2794,25 @@  discard block
 block discarded – undo
2688 2794
 			if ($to_label[$row['id_pm']] != '-1')
2689 2795
 			{
2690 2796
 				// If this label is in the list and we're not adding it, remove it
2691
-				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add')
2692
-					unset($labels[$to_label[$row['id_pm']]]);
2693
-				else if ($type !== 'rem')
2694
-					$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2797
+				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') {
2798
+									unset($labels[$to_label[$row['id_pm']]]);
2799
+				} else if ($type !== 'rem') {
2800
+									$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2801
+				}
2695 2802
 			}
2696 2803
 
2697 2804
 			// Removing all labels or just removing the inbox label
2698
-			if ($type == 'rem' && empty($labels))
2699
-				$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2805
+			if ($type == 'rem' && empty($labels)) {
2806
+							$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2807
+			}
2700 2808
 			// Adding new labels, but removing inbox and applying new ones
2701
-			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels))
2702
-				$in_inbox = 0;
2809
+			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) {
2810
+							$in_inbox = 0;
2811
+			}
2703 2812
 			// Just adding it to the inbox
2704
-			else
2705
-				$in_inbox = 1;
2813
+			else {
2814
+							$in_inbox = 1;
2815
+			}
2706 2816
 
2707 2817
 			// Are we adding it to or removing it from the inbox?
2708 2818
 			if ($in_inbox != $row['in_inbox'])
@@ -2744,8 +2854,9 @@  discard block
 block discarded – undo
2744 2854
 			if (!empty($labels_to_apply))
2745 2855
 			{
2746 2856
 				$inserts = array();
2747
-				foreach ($labels_to_apply as $label)
2748
-					$inserts[] = array($row['id_pm'], $label);
2857
+				foreach ($labels_to_apply as $label) {
2858
+									$inserts[] = array($row['id_pm'], $label);
2859
+				}
2749 2860
 
2750 2861
 				$smcFunc['db_insert']('',
2751 2862
 					'{db_prefix}pm_labeled_messages',
@@ -2789,11 +2900,13 @@  discard block
 block discarded – undo
2789 2900
 	checkSession('get');
2790 2901
 
2791 2902
 	// If all then delete all messages the user has.
2792
-	if ($_REQUEST['f'] == 'all')
2793
-		deleteMessages(null, null);
2903
+	if ($_REQUEST['f'] == 'all') {
2904
+			deleteMessages(null, null);
2905
+	}
2794 2906
 	// Otherwise just the selected folder.
2795
-	else
2796
-		deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2907
+	else {
2908
+			deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2909
+	}
2797 2910
 
2798 2911
 	// Done... all gone.
2799 2912
 	redirectexit($context['current_label_redirect']);
@@ -2830,8 +2943,9 @@  discard block
 block discarded – undo
2830 2943
 				'msgtime' => $deleteTime,
2831 2944
 			)
2832 2945
 		);
2833
-		while ($row = $smcFunc['db_fetch_row']($request))
2834
-			$toDelete[] = $row[0];
2946
+		while ($row = $smcFunc['db_fetch_row']($request)) {
2947
+					$toDelete[] = $row[0];
2948
+		}
2835 2949
 		$smcFunc['db_free_result']($request);
2836 2950
 
2837 2951
 		// Select all messages in their inbox older than $deleteTime.
@@ -2848,8 +2962,9 @@  discard block
 block discarded – undo
2848 2962
 				'msgtime' => $deleteTime,
2849 2963
 			)
2850 2964
 		);
2851
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2852
-			$toDelete[] = $row['id_pm'];
2965
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2966
+					$toDelete[] = $row['id_pm'];
2967
+		}
2853 2968
 		$smcFunc['db_free_result']($request);
2854 2969
 
2855 2970
 		// Delete the actual messages.
@@ -2880,26 +2995,29 @@  discard block
 block discarded – undo
2880 2995
 {
2881 2996
 	global $user_info, $smcFunc;
2882 2997
 
2883
-	if ($owner === null)
2884
-		$owner = array($user_info['id']);
2885
-	elseif (empty($owner))
2886
-		return;
2887
-	elseif (!is_array($owner))
2888
-		$owner = array($owner);
2998
+	if ($owner === null) {
2999
+			$owner = array($user_info['id']);
3000
+	} elseif (empty($owner)) {
3001
+			return;
3002
+	} elseif (!is_array($owner)) {
3003
+			$owner = array($owner);
3004
+	}
2889 3005
 
2890 3006
 	if ($personal_messages !== null)
2891 3007
 	{
2892
-		if (empty($personal_messages) || !is_array($personal_messages))
2893
-			return;
3008
+		if (empty($personal_messages) || !is_array($personal_messages)) {
3009
+					return;
3010
+		}
2894 3011
 
2895
-		foreach ($personal_messages as $index => $delete_id)
2896
-			$personal_messages[$index] = (int) $delete_id;
3012
+		foreach ($personal_messages as $index => $delete_id) {
3013
+					$personal_messages[$index] = (int) $delete_id;
3014
+		}
2897 3015
 
2898 3016
 		$where = '
2899 3017
 				AND id_pm IN ({array_int:pm_list})';
3018
+	} else {
3019
+			$where = '';
2900 3020
 	}
2901
-	else
2902
-		$where = '';
2903 3021
 
2904 3022
 	if ($folder == 'sent' || $folder === null)
2905 3023
 	{
@@ -2934,17 +3052,19 @@  discard block
 block discarded – undo
2934 3052
 		// ...And update the statistics accordingly - now including unread messages!.
2935 3053
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2936 3054
 		{
2937
-			if ($row['is_read'])
2938
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
2939
-			else
2940
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3055
+			if ($row['is_read']) {
3056
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
3057
+			} else {
3058
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3059
+			}
2941 3060
 
2942 3061
 			// If this is the current member we need to make their message count correct.
2943 3062
 			if ($user_info['id'] == $row['id_member'])
2944 3063
 			{
2945 3064
 				$user_info['messages'] -= $row['num_deleted_messages'];
2946
-				if (!($row['is_read']))
2947
-					$user_info['unread_messages'] -= $row['num_deleted_messages'];
3065
+				if (!($row['is_read'])) {
3066
+									$user_info['unread_messages'] -= $row['num_deleted_messages'];
3067
+				}
2948 3068
 			}
2949 3069
 		}
2950 3070
 		$smcFunc['db_free_result']($request);
@@ -3012,8 +3132,9 @@  discard block
 block discarded – undo
3012 3132
 		)
3013 3133
 	);
3014 3134
 	$remove_pms = array();
3015
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3016
-		$remove_pms[] = $row['sender'];
3135
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3136
+			$remove_pms[] = $row['sender'];
3137
+	}
3017 3138
 	$smcFunc['db_free_result']($request);
3018 3139
 
3019 3140
 	if (!empty($remove_pms))
@@ -3058,8 +3179,9 @@  discard block
 block discarded – undo
3058 3179
 {
3059 3180
 	global $user_info, $context, $smcFunc;
3060 3181
 
3061
-	if ($owner === null)
3062
-		$owner = $user_info['id'];
3182
+	if ($owner === null) {
3183
+			$owner = $user_info['id'];
3184
+	}
3063 3185
 
3064 3186
 	$in_inbox = '';
3065 3187
 
@@ -3083,8 +3205,7 @@  discard block
 block discarded – undo
3083 3205
 		}
3084 3206
 
3085 3207
 		$smcFunc['db_free_result']($get_messages);
3086
-	}
3087
-	elseif ($label = '-1')
3208
+	} elseif ($label = '-1')
3088 3209
 	{
3089 3210
 		// Marking all PMs in your inbox read
3090 3211
 		$in_inbox = '
@@ -3109,8 +3230,9 @@  discard block
 block discarded – undo
3109 3230
 	{
3110 3231
 		if ($owner == $user_info['id'])
3111 3232
 		{
3112
-			foreach ($context['labels'] as $label)
3113
-				$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3233
+			foreach ($context['labels'] as $label) {
3234
+							$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3235
+			}
3114 3236
 		}
3115 3237
 
3116 3238
 		$result = $smcFunc['db_query']('', '
@@ -3130,8 +3252,9 @@  discard block
 block discarded – undo
3130 3252
 		{
3131 3253
 			$total_unread += $row['num'];
3132 3254
 
3133
-			if ($owner != $user_info['id'] || empty($row['id_pm']))
3134
-				continue;
3255
+			if ($owner != $user_info['id'] || empty($row['id_pm'])) {
3256
+							continue;
3257
+			}
3135 3258
 
3136 3259
 			$this_labels = array();
3137 3260
 
@@ -3155,11 +3278,13 @@  discard block
 block discarded – undo
3155 3278
 
3156 3279
 			$smcFunc['db_free_result']($result2);
3157 3280
 
3158
-			foreach ($this_labels as $this_label)
3159
-				$context['labels'][$this_label]['unread_messages'] += $row['num'];
3281
+			foreach ($this_labels as $this_label) {
3282
+							$context['labels'][$this_label]['unread_messages'] += $row['num'];
3283
+			}
3160 3284
 
3161
-			if ($row['in_inbox'] == 1)
3162
-				$context['labels'][-1]['unread_messages'] += $row['num'];
3285
+			if ($row['in_inbox'] == 1) {
3286
+							$context['labels'][-1]['unread_messages'] += $row['num'];
3287
+			}
3163 3288
 		}
3164 3289
 		$smcFunc['db_free_result']($result);
3165 3290
 
@@ -3168,8 +3293,9 @@  discard block
 block discarded – undo
3168 3293
 		updateMemberData($owner, array('unread_messages' => $total_unread));
3169 3294
 
3170 3295
 		// If it was for the current member, reflect this in the $user_info array too.
3171
-		if ($owner == $user_info['id'])
3172
-			$user_info['unread_messages'] = $total_unread;
3296
+		if ($owner == $user_info['id']) {
3297
+					$user_info['unread_messages'] = $total_unread;
3298
+		}
3173 3299
 	}
3174 3300
 }
3175 3301
 
@@ -3197,8 +3323,9 @@  discard block
 block discarded – undo
3197 3323
 	// Add all existing labels to the array to save, slashing them as necessary...
3198 3324
 	foreach ($context['labels'] as $label)
3199 3325
 	{
3200
-		if ($label['id'] != -1)
3201
-			$the_labels[$label['id']] = $label['name'];
3326
+		if ($label['id'] != -1) {
3327
+					$the_labels[$label['id']] = $label['name'];
3328
+		}
3202 3329
 	}
3203 3330
 
3204 3331
 	if (isset($_POST[$context['session_var']]))
@@ -3217,8 +3344,9 @@  discard block
 block discarded – undo
3217 3344
 		{
3218 3345
 			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => '&#044;'));
3219 3346
 
3220
-			if ($smcFunc['strlen']($_POST['label']) > 30)
3221
-				$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3347
+			if ($smcFunc['strlen']($_POST['label']) > 30) {
3348
+							$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3349
+			}
3222 3350
 			if ($_POST['label'] != '')
3223 3351
 			{
3224 3352
 				$the_labels[] = $_POST['label'];
@@ -3239,24 +3367,25 @@  discard block
 block discarded – undo
3239 3367
 		{
3240 3368
 			foreach ($the_labels as $id => $name)
3241 3369
 			{
3242
-				if ($id == -1)
3243
-					continue;
3244
-				elseif (isset($_POST['label_name'][$id]))
3370
+				if ($id == -1) {
3371
+									continue;
3372
+				} elseif (isset($_POST['label_name'][$id]))
3245 3373
 				{
3246 3374
 					$_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => '&#044;')));
3247 3375
 
3248
-					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30)
3249
-						$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3376
+					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) {
3377
+											$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3378
+					}
3250 3379
 					if ($_POST['label_name'][$id] != '')
3251 3380
 					{
3252 3381
 						// Changing the name of this label?
3253
-						if ($the_labels[$id] != $_POST['label_name'][$id])
3254
-							$label_updates[$id] = $_POST['label_name'][$id];
3382
+						if ($the_labels[$id] != $_POST['label_name'][$id]) {
3383
+													$label_updates[$id] = $_POST['label_name'][$id];
3384
+						}
3255 3385
 
3256 3386
 						$the_labels[(int) $id] = $_POST['label_name'][$id];
3257 3387
 
3258
-					}
3259
-					else
3388
+					} else
3260 3389
 					{
3261 3390
 						unset($the_labels[(int) $id]);
3262 3391
 						$labels_to_remove[] = $id;
@@ -3270,8 +3399,9 @@  discard block
 block discarded – undo
3270 3399
 		if (!empty($labels_to_add))
3271 3400
 		{
3272 3401
 			$inserts = array();
3273
-			foreach ($labels_to_add AS $label)
3274
-				$inserts[] = array($user_info['id'], $label);
3402
+			foreach ($labels_to_add AS $label) {
3403
+							$inserts[] = array($user_info['id'], $label);
3404
+			}
3275 3405
 
3276 3406
 			$smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
3277 3407
 		}
@@ -3361,8 +3491,9 @@  discard block
 block discarded – undo
3361 3491
 				// Each action...
3362 3492
 				foreach ($rule['actions'] as $k2 => $action)
3363 3493
 				{
3364
-					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove))
3365
-						continue;
3494
+					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) {
3495
+											continue;
3496
+					}
3366 3497
 
3367 3498
 					$rule_changes[] = $rule['id'];
3368 3499
 
@@ -3377,8 +3508,8 @@  discard block
 block discarded – undo
3377 3508
 		{
3378 3509
 			$rule_changes = array_unique($rule_changes);
3379 3510
 			// Update/delete as appropriate.
3380
-			foreach ($rule_changes as $k => $id)
3381
-				if (!empty($context['rules'][$id]['actions']))
3511
+			foreach ($rule_changes as $k => $id) {
3512
+							if (!empty($context['rules'][$id]['actions']))
3382 3513
 				{
3383 3514
 					$smcFunc['db_query']('', '
3384 3515
 						UPDATE {db_prefix}pm_rules
@@ -3391,12 +3522,13 @@  discard block
 block discarded – undo
3391 3522
 							'actions' => $smcFunc['json_encode']($context['rules'][$id]['actions']),
3392 3523
 						)
3393 3524
 					);
3525
+			}
3394 3526
 					unset($rule_changes[$k]);
3395 3527
 				}
3396 3528
 
3397 3529
 			// Anything left here means it's lost all actions...
3398
-			if (!empty($rule_changes))
3399
-				$smcFunc['db_query']('', '
3530
+			if (!empty($rule_changes)) {
3531
+							$smcFunc['db_query']('', '
3400 3532
 					DELETE FROM {db_prefix}pm_rules
3401 3533
 					WHERE id_rule IN ({array_int:rule_list})
3402 3534
 							AND id_member = {int:current_member}',
@@ -3405,6 +3537,7 @@  discard block
 block discarded – undo
3405 3537
 						'rule_list' => $rule_changes,
3406 3538
 					)
3407 3539
 				);
3540
+			}
3408 3541
 		}
3409 3542
 
3410 3543
 		// Make sure we're not caching this!
@@ -3474,8 +3607,9 @@  discard block
 block discarded – undo
3474 3607
 		// Save the fields.
3475 3608
 		saveProfileFields();
3476 3609
 
3477
-		if (!empty($profile_vars))
3478
-			updateMemberData($user_info['id'], $profile_vars);
3610
+		if (!empty($profile_vars)) {
3611
+					updateMemberData($user_info['id'], $profile_vars);
3612
+		}
3479 3613
 	}
3480 3614
 
3481 3615
 	setupProfileContext(
@@ -3500,13 +3634,15 @@  discard block
 block discarded – undo
3500 3634
 	global $user_info, $language, $modSettings, $smcFunc;
3501 3635
 
3502 3636
 	// Check that this feature is even enabled!
3503
-	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg']))
3504
-		fatal_lang_error('no_access', false);
3637
+	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) {
3638
+			fatal_lang_error('no_access', false);
3639
+	}
3505 3640
 
3506 3641
 	$pmsg = (int) $_REQUEST['pmsg'];
3507 3642
 
3508
-	if (!isAccessiblePM($pmsg, 'inbox'))
3509
-		fatal_lang_error('no_access', false);
3643
+	if (!isAccessiblePM($pmsg, 'inbox')) {
3644
+			fatal_lang_error('no_access', false);
3645
+	}
3510 3646
 
3511 3647
 	$context['pm_id'] = $pmsg;
3512 3648
 	$context['page_title'] = $txt['pm_report_title'];
@@ -3528,8 +3664,9 @@  discard block
 block discarded – undo
3528 3664
 			)
3529 3665
 		);
3530 3666
 		$context['admins'] = array();
3531
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3532
-			$context['admins'][$row['id_member']] = $row['real_name'];
3667
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3668
+					$context['admins'][$row['id_member']] = $row['real_name'];
3669
+		}
3533 3670
 		$smcFunc['db_free_result']($request);
3534 3671
 
3535 3672
 		// How many admins in total?
@@ -3558,8 +3695,9 @@  discard block
 block discarded – undo
3558 3695
 			)
3559 3696
 		);
3560 3697
 		// Can only be a hacker here!
3561
-		if ($smcFunc['db_num_rows']($request) == 0)
3562
-			fatal_lang_error('no_access', false);
3698
+		if ($smcFunc['db_num_rows']($request) == 0) {
3699
+					fatal_lang_error('no_access', false);
3700
+		}
3563 3701
 		list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);
3564 3702
 		$smcFunc['db_free_result']($request);
3565 3703
 
@@ -3583,15 +3721,17 @@  discard block
 block discarded – undo
3583 3721
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3584 3722
 		{
3585 3723
 			// If it's hidden still don't reveal their names - privacy after all ;)
3586
-			if ($row['bcc'])
3587
-				$hidden_recipients++;
3588
-			else
3589
-				$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3724
+			if ($row['bcc']) {
3725
+							$hidden_recipients++;
3726
+			} else {
3727
+							$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3728
+			}
3590 3729
 		}
3591 3730
 		$smcFunc['db_free_result']($request);
3592 3731
 
3593
-		if ($hidden_recipients)
3594
-			$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3732
+		if ($hidden_recipients) {
3733
+					$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3734
+		}
3595 3735
 
3596 3736
 		// Now let's get out and loop through the admins.
3597 3737
 		$request = $smcFunc['db_query']('', '
@@ -3607,8 +3747,9 @@  discard block
 block discarded – undo
3607 3747
 		);
3608 3748
 
3609 3749
 		// Maybe we shouldn't advertise this?
3610
-		if ($smcFunc['db_num_rows']($request) == 0)
3611
-			fatal_lang_error('no_access', false);
3750
+		if ($smcFunc['db_num_rows']($request) == 0) {
3751
+					fatal_lang_error('no_access', false);
3752
+		}
3612 3753
 
3613 3754
 		$memberFromName = un_htmlspecialchars($memberFromName);
3614 3755
 
@@ -3627,8 +3768,9 @@  discard block
 block discarded – undo
3627 3768
 				// Make the body.
3628 3769
 				$report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']);
3629 3770
 				$report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n";
3630
-				if (!empty($recipients))
3631
-					$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3771
+				if (!empty($recipients)) {
3772
+									$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3773
+				}
3632 3774
 				$report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '&quot;' . $memberFromName . '&quot;' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]';
3633 3775
 
3634 3776
 				// Plonk it in the array ;)
@@ -3648,12 +3790,14 @@  discard block
 block discarded – undo
3648 3790
 		$smcFunc['db_free_result']($request);
3649 3791
 
3650 3792
 		// Send a different email for each language.
3651
-		foreach ($messagesToSend as $lang => $message)
3652
-			sendpm($message['recipients'], $message['subject'], $message['body']);
3793
+		foreach ($messagesToSend as $lang => $message) {
3794
+					sendpm($message['recipients'], $message['subject'], $message['body']);
3795
+		}
3653 3796
 
3654 3797
 		// Give the user their own language back!
3655
-		if (!empty($modSettings['userLanguage']))
3656
-			loadLanguage('PersonalMessage', '', false);
3798
+		if (!empty($modSettings['userLanguage'])) {
3799
+					loadLanguage('PersonalMessage', '', false);
3800
+		}
3657 3801
 
3658 3802
 		// Leave them with a template.
3659 3803
 		$context['sub_template'] = 'report_message_complete';
@@ -3699,8 +3843,9 @@  discard block
 block discarded – undo
3699 3843
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3700 3844
 	{
3701 3845
 		// Hide hidden groups!
3702
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
3703
-			continue;
3846
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
3847
+					continue;
3848
+		}
3704 3849
 
3705 3850
 		$context['groups'][$row['id_group']] = $row['group_name'];
3706 3851
 	}
@@ -3726,9 +3871,10 @@  discard block
 block discarded – undo
3726 3871
 			$context['rule'] = $context['rules'][$context['rid']];
3727 3872
 			$members = array();
3728 3873
 			// Need to get member names!
3729
-			foreach ($context['rule']['criteria'] as $k => $criteria)
3730
-				if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3874
+			foreach ($context['rule']['criteria'] as $k => $criteria) {
3875
+							if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3731 3876
 					$members[(int) $criteria['v']] = $k;
3877
+			}
3732 3878
 
3733 3879
 			if (!empty($members))
3734 3880
 			{
@@ -3740,19 +3886,20 @@  discard block
 block discarded – undo
3740 3886
 						'member_list' => array_keys($members),
3741 3887
 					)
3742 3888
 				);
3743
-				while ($row = $smcFunc['db_fetch_assoc']($request))
3744
-					$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3889
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
3890
+									$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3891
+				}
3745 3892
 				$smcFunc['db_free_result']($request);
3746 3893
 			}
3747
-		}
3748
-		else
3749
-			$context['rule'] = array(
3894
+		} else {
3895
+					$context['rule'] = array(
3750 3896
 				'id' => '',
3751 3897
 				'name' => '',
3752 3898
 				'criteria' => array(),
3753 3899
 				'actions' => array(),
3754 3900
 				'logic' => 'and',
3755 3901
 			);
3902
+		}
3756 3903
 	}
3757 3904
 	// Saving?
3758 3905
 	elseif (isset($_GET['save']))
@@ -3762,22 +3909,25 @@  discard block
 block discarded – undo
3762 3909
 
3763 3910
 		// Name is easy!
3764 3911
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
3765
-		if (empty($ruleName))
3766
-			fatal_lang_error('pm_rule_no_name', false);
3912
+		if (empty($ruleName)) {
3913
+					fatal_lang_error('pm_rule_no_name', false);
3914
+		}
3767 3915
 
3768 3916
 		// Sanity check...
3769
-		if (empty($_POST['ruletype']) || empty($_POST['acttype']))
3770
-			fatal_lang_error('pm_rule_no_criteria', false);
3917
+		if (empty($_POST['ruletype']) || empty($_POST['acttype'])) {
3918
+					fatal_lang_error('pm_rule_no_criteria', false);
3919
+		}
3771 3920
 
3772 3921
 		// Let's do the criteria first - it's also hardest!
3773 3922
 		$criteria = array();
3774 3923
 		foreach ($_POST['ruletype'] as $ind => $type)
3775 3924
 		{
3776 3925
 			// Check everything is here...
3777
-			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]])))
3778
-				continue;
3779
-			elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind]))
3780
-				continue;
3926
+			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) {
3927
+							continue;
3928
+			} elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) {
3929
+							continue;
3930
+			}
3781 3931
 
3782 3932
 			// Members need to be found.
3783 3933
 			if ($type == 'mid')
@@ -3801,13 +3951,13 @@  discard block
 block discarded – undo
3801 3951
 				$smcFunc['db_free_result']($request);
3802 3952
 
3803 3953
 				$criteria[] = array('t' => 'mid', 'v' => $memID);
3954
+			} elseif ($type == 'bud') {
3955
+							$criteria[] = array('t' => 'bud', 'v' => 1);
3956
+			} elseif ($type == 'gid') {
3957
+							$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3958
+			} elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') {
3959
+							$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3804 3960
 			}
3805
-			elseif ($type == 'bud')
3806
-				$criteria[] = array('t' => 'bud', 'v' => 1);
3807
-			elseif ($type == 'gid')
3808
-				$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3809
-			elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '')
3810
-				$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3811 3961
 		}
3812 3962
 
3813 3963
 		// Also do the actions!
@@ -3817,26 +3967,29 @@  discard block
 block discarded – undo
3817 3967
 		foreach ($_POST['acttype'] as $ind => $type)
3818 3968
 		{
3819 3969
 			// Picking a valid label?
3820
-			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]])))
3821
-				continue;
3970
+			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) {
3971
+							continue;
3972
+			}
3822 3973
 
3823 3974
 			// Record what we're doing.
3824
-			if ($type == 'del')
3825
-				$doDelete = 1;
3826
-			elseif ($type == 'lab')
3827
-				$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3975
+			if ($type == 'del') {
3976
+							$doDelete = 1;
3977
+			} elseif ($type == 'lab') {
3978
+							$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3979
+			}
3828 3980
 		}
3829 3981
 
3830
-		if (empty($criteria) || (empty($actions) && !$doDelete))
3831
-			fatal_lang_error('pm_rule_no_criteria', false);
3982
+		if (empty($criteria) || (empty($actions) && !$doDelete)) {
3983
+					fatal_lang_error('pm_rule_no_criteria', false);
3984
+		}
3832 3985
 
3833 3986
 		// What are we storing?
3834 3987
 		$criteria = $smcFunc['json_encode']($criteria);
3835 3988
 		$actions = $smcFunc['json_encode']($actions);
3836 3989
 
3837 3990
 		// Create the rule?
3838
-		if (empty($context['rid']))
3839
-			$smcFunc['db_insert']('',
3991
+		if (empty($context['rid'])) {
3992
+					$smcFunc['db_insert']('',
3840 3993
 				'{db_prefix}pm_rules',
3841 3994
 				array(
3842 3995
 					'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string',
@@ -3847,8 +4000,8 @@  discard block
 block discarded – undo
3847 4000
 				),
3848 4001
 				array('id_rule')
3849 4002
 			);
3850
-		else
3851
-			$smcFunc['db_query']('', '
4003
+		} else {
4004
+					$smcFunc['db_query']('', '
3852 4005
 				UPDATE {db_prefix}pm_rules
3853 4006
 				SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions},
3854 4007
 					delete_pm = {int:delete_pm}, is_or = {int:is_or}
@@ -3864,6 +4017,7 @@  discard block
 block discarded – undo
3864 4017
 					'actions' => $actions,
3865 4018
 				)
3866 4019
 			);
4020
+		}
3867 4021
 
3868 4022
 		redirectexit('action=pm;sa=manrules');
3869 4023
 	}
@@ -3872,11 +4026,12 @@  discard block
 block discarded – undo
3872 4026
 	{
3873 4027
 		checkSession();
3874 4028
 		$toDelete = array();
3875
-		foreach ($_POST['delrule'] as $k => $v)
3876
-			$toDelete[] = (int) $k;
4029
+		foreach ($_POST['delrule'] as $k => $v) {
4030
+					$toDelete[] = (int) $k;
4031
+		}
3877 4032
 
3878
-		if (!empty($toDelete))
3879
-			$smcFunc['db_query']('', '
4033
+		if (!empty($toDelete)) {
4034
+					$smcFunc['db_query']('', '
3880 4035
 				DELETE FROM {db_prefix}pm_rules
3881 4036
 				WHERE id_rule IN ({array_int:delete_list})
3882 4037
 					AND id_member = {int:current_member}',
@@ -3885,6 +4040,7 @@  discard block
 block discarded – undo
3885 4040
 					'delete_list' => $toDelete,
3886 4041
 				)
3887 4042
 			);
4043
+		}
3888 4044
 
3889 4045
 		redirectexit('action=pm;sa=manrules');
3890 4046
 	}
@@ -3903,8 +4059,9 @@  discard block
 block discarded – undo
3903 4059
 	loadRules();
3904 4060
 
3905 4061
 	// No rules?
3906
-	if (empty($context['rules']))
3907
-		return;
4062
+	if (empty($context['rules'])) {
4063
+			return;
4064
+	}
3908 4065
 
3909 4066
 	// Just unread ones?
3910 4067
 	$ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1';
@@ -3934,8 +4091,9 @@  discard block
 block discarded – undo
3934 4091
 			// Loop through all the criteria hoping to make a match.
3935 4092
 			foreach ($rule['criteria'] as $criterium)
3936 4093
 			{
3937
-				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false))
3938
-					$match = true;
4094
+				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) {
4095
+									$match = true;
4096
+				}
3939 4097
 				// If we're adding and one criteria don't match then we stop!
3940 4098
 				elseif ($rule['logic'] == 'and')
3941 4099
 				{
@@ -3947,17 +4105,18 @@  discard block
 block discarded – undo
3947 4105
 			// If we have a match the rule must be true - act!
3948 4106
 			if ($match)
3949 4107
 			{
3950
-				if ($rule['delete'])
3951
-					$actions['deletes'][] = $row['id_pm'];
3952
-				else
4108
+				if ($rule['delete']) {
4109
+									$actions['deletes'][] = $row['id_pm'];
4110
+				} else
3953 4111
 				{
3954 4112
 					foreach ($rule['actions'] as $ruleAction)
3955 4113
 					{
3956 4114
 						if ($ruleAction['t'] == 'lab')
3957 4115
 						{
3958 4116
 							// Get a basic pot started!
3959
-							if (!isset($actions['labels'][$row['id_pm']]))
3960
-								$actions['labels'][$row['id_pm']] = array();
4117
+							if (!isset($actions['labels'][$row['id_pm']])) {
4118
+															$actions['labels'][$row['id_pm']] = array();
4119
+							}
3961 4120
 							$actions['labels'][$row['id_pm']][] = $ruleAction['v'];
3962 4121
 						}
3963 4122
 					}
@@ -3968,8 +4127,9 @@  discard block
 block discarded – undo
3968 4127
 	$smcFunc['db_free_result']($request);
3969 4128
 
3970 4129
 	// Deletes are easy!
3971
-	if (!empty($actions['deletes']))
3972
-		deleteMessages($actions['deletes']);
4130
+	if (!empty($actions['deletes'])) {
4131
+			deleteMessages($actions['deletes']);
4132
+	}
3973 4133
 
3974 4134
 	// Relabel?
3975 4135
 	if (!empty($actions['labels']))
@@ -3996,8 +4156,7 @@  discard block
 block discarded – undo
3996 4156
 								'current_member' => $user_info['id'],
3997 4157
 							)
3998 4158
 						);
3999
-					}
4000
-					else
4159
+					} else
4001 4160
 					{
4002 4161
 						$realLabels[] = $label['id'];
4003 4162
 					}
@@ -4006,8 +4165,9 @@  discard block
 block discarded – undo
4006 4165
 
4007 4166
 			$inserts = array();
4008 4167
 			// Now we insert the label info
4009
-			foreach ($realLabels as $a_label)
4010
-				$inserts[] = array($pm, $a_label);
4168
+			foreach ($realLabels as $a_label) {
4169
+							$inserts[] = array($pm, $a_label);
4170
+			}
4011 4171
 
4012 4172
 			$smcFunc['db_insert']('ignore',
4013 4173
 				'{db_prefix}pm_labeled_messages',
@@ -4028,8 +4188,9 @@  discard block
 block discarded – undo
4028 4188
 {
4029 4189
 	global $user_info, $context, $smcFunc;
4030 4190
 
4031
-	if (isset($context['rules']) && !$reload)
4032
-		return;
4191
+	if (isset($context['rules']) && !$reload) {
4192
+			return;
4193
+	}
4033 4194
 
4034 4195
 	$request = $smcFunc['db_query']('', '
4035 4196
 		SELECT
@@ -4053,8 +4214,9 @@  discard block
 block discarded – undo
4053 4214
 			'logic' => $row['is_or'] ? 'or' : 'and',
4054 4215
 		);
4055 4216
 
4056
-		if ($row['delete_pm'])
4057
-			$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4217
+		if ($row['delete_pm']) {
4218
+					$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4219
+		}
4058 4220
 	}
4059 4221
 	$smcFunc['db_free_result']($request);
4060 4222
 }
Please login to merge, or discard this patch.
Sources/Subs.php 4 patches
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -5370,7 +5370,6 @@  discard block
 block discarded – undo
5370 5370
 
5371 5371
 /**
5372 5372
  * Tries different modes to make file/dirs writable. Wrapper function for chmod()
5373
-
5374 5373
  * @param string $file The file/dir full path.
5375 5374
  * @param int $value Not needed, added for legacy reasons.
5376 5375
  * @return boolean  true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable.
@@ -5410,7 +5409,6 @@  discard block
 block discarded – undo
5410 5409
 
5411 5410
 /**
5412 5411
  * Wrapper function for json_decode() with error handling.
5413
-
5414 5412
  * @param string $json The string to decode.
5415 5413
  * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default.
5416 5414
  * @param bool $logIt To specify if the error will be logged if theres any.
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
  * - caches the formatting data from the setting for optimization.
677 677
  *
678 678
  * @param float $number A number
679
- * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
679
+ * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
680 680
  * @return string A formatted number
681 681
  */
682 682
 function comma_format($number, $override_decimal_count = false)
@@ -5527,7 +5527,7 @@  discard block
 block discarded – undo
5527 5527
  * It assumes the data is already a string.
5528 5528
  * @param string $data The data to print
5529 5529
  * @param string $type The content type. Defaults to Json.
5530
- * @return void
5530
+ * @return false|null
5531 5531
  */
5532 5532
 function smf_serverResponse($data = '', $type = 'Content-Type: application/json')
5533 5533
 {
Please login to merge, or discard this patch.
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
 			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
801 801
 		if (empty($unsupportedFormats))
802 802
 		{
803
-			foreach($strftimeFormatSubstitutions as $format => $substitution)
803
+			foreach ($strftimeFormatSubstitutions as $format => $substitution)
804 804
 			{
805 805
 				$value = @strftime('%' . $format);
806 806
 
@@ -1165,7 +1165,7 @@  discard block
 block discarded – undo
1165 1165
 					'height' => array('optional' => true, 'match' => '(\d+)'),
1166 1166
 				),
1167 1167
 				'content' => '$1',
1168
-				'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1168
+				'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1169 1169
 				{
1170 1170
 					$returnContext = '';
1171 1171
 
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 						}
1201 1201
 
1202 1202
 						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1203
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1203
+							$returnContext .= '<a href="' . $currentAttachment['href'] . ';image" id="link_' . $currentAttachment['id'] . '" onclick="' . $currentAttachment['thumbnail']['javascript'] . '"><img src="' . $currentAttachment['thumbnail']['href'] . '"' . $alt . $title . ' id="thumb_' . $currentAttachment['id'] . '" class="atc_img"></a>';
1204 1204
 						else
1205 1205
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1206 1206
 					}
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
 				'type' => 'unparsed_content',
1230 1230
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1231 1231
 				// @todo Maybe this can be simplified?
1232
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1232
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1233 1233
 				{
1234 1234
 					if (!isset($disabled['code']))
1235 1235
 					{
@@ -1266,7 +1266,7 @@  discard block
 block discarded – undo
1266 1266
 				'type' => 'unparsed_equals_content',
1267 1267
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1268 1268
 				// @todo Maybe this can be simplified?
1269
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1269
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1270 1270
 				{
1271 1271
 					if (!isset($disabled['code']))
1272 1272
 					{
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 				'type' => 'unparsed_content',
1311 1311
 				'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
1312 1312
 				// @todo Should this respect guest_hideContacts?
1313
-				'validate' => function (&$tag, &$data, $disabled)
1313
+				'validate' => function(&$tag, &$data, $disabled)
1314 1314
 				{
1315 1315
 					$data = strtr($data, array('<br>' => ''));
1316 1316
 				},
@@ -1329,7 +1329,7 @@  discard block
 block discarded – undo
1329 1329
 				'type' => 'unparsed_commas_content',
1330 1330
 				'test' => '\d+,\d+\]',
1331 1331
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1332
-				'validate' => function (&$tag, &$data, $disabled)
1332
+				'validate' => function(&$tag, &$data, $disabled)
1333 1333
 				{
1334 1334
 					if (isset($disabled['url']))
1335 1335
 						$tag['content'] = '$1';
@@ -1345,7 +1345,7 @@  discard block
 block discarded – undo
1345 1345
 				'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]',
1346 1346
 				'before' => '<div $1>',
1347 1347
 				'after' => '</div>',
1348
-				'validate' => function (&$tag, &$data, $disabled)
1348
+				'validate' => function(&$tag, &$data, $disabled)
1349 1349
 				{
1350 1350
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1351 1351
 
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1395 1395
 				),
1396 1396
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1397
-				'validate' => function (&$tag, &$data, $disabled)
1397
+				'validate' => function(&$tag, &$data, $disabled)
1398 1398
 				{
1399 1399
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1400 1400
 
@@ -1417,7 +1417,7 @@  discard block
 block discarded – undo
1417 1417
 				'tag' => 'img',
1418 1418
 				'type' => 'unparsed_content',
1419 1419
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1420
-				'validate' => function (&$tag, &$data, $disabled)
1420
+				'validate' => function(&$tag, &$data, $disabled)
1421 1421
 				{
1422 1422
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1423 1423
 
@@ -1440,7 +1440,7 @@  discard block
 block discarded – undo
1440 1440
 				'tag' => 'iurl',
1441 1441
 				'type' => 'unparsed_content',
1442 1442
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1443
-				'validate' => function (&$tag, &$data, $disabled)
1443
+				'validate' => function(&$tag, &$data, $disabled)
1444 1444
 				{
1445 1445
 					$data = strtr($data, array('<br>' => ''));
1446 1446
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1454,7 +1454,7 @@  discard block
 block discarded – undo
1454 1454
 				'quoted' => 'optional',
1455 1455
 				'before' => '<a href="$1" class="bbc_link">',
1456 1456
 				'after' => '</a>',
1457
-				'validate' => function (&$tag, &$data, $disabled)
1457
+				'validate' => function(&$tag, &$data, $disabled)
1458 1458
 				{
1459 1459
 					if (substr($data, 0, 1) == '#')
1460 1460
 						$data = '#post_' . substr($data, 1);
@@ -1534,7 +1534,7 @@  discard block
 block discarded – undo
1534 1534
 				'tag' => 'php',
1535 1535
 				'type' => 'unparsed_content',
1536 1536
 				'content' => '<span class="phpcode">$1</span>',
1537
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1537
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1538 1538
 				{
1539 1539
 					if (!isset($disabled['php']))
1540 1540
 					{
@@ -1632,7 +1632,7 @@  discard block
 block discarded – undo
1632 1632
 				'test' => '[1-7]\]',
1633 1633
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1634 1634
 				'after' => '</span>',
1635
-				'validate' => function (&$tag, &$data, $disabled)
1635
+				'validate' => function(&$tag, &$data, $disabled)
1636 1636
 				{
1637 1637
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1638 1638
 					$data = $sizes[$data] . 'em';
@@ -1670,7 +1670,7 @@  discard block
 block discarded – undo
1670 1670
 				'tag' => 'time',
1671 1671
 				'type' => 'unparsed_content',
1672 1672
 				'content' => '$1',
1673
-				'validate' => function (&$tag, &$data, $disabled)
1673
+				'validate' => function(&$tag, &$data, $disabled)
1674 1674
 				{
1675 1675
 					if (is_numeric($data))
1676 1676
 						$data = timeformat($data);
@@ -1698,7 +1698,7 @@  discard block
 block discarded – undo
1698 1698
 				'tag' => 'url',
1699 1699
 				'type' => 'unparsed_content',
1700 1700
 				'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
1701
-				'validate' => function (&$tag, &$data, $disabled)
1701
+				'validate' => function(&$tag, &$data, $disabled)
1702 1702
 				{
1703 1703
 					$data = strtr($data, array('<br>' => ''));
1704 1704
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
 				'quoted' => 'optional',
1713 1713
 				'before' => '<a href="$1" class="bbc_link" target="_blank">',
1714 1714
 				'after' => '</a>',
1715
-				'validate' => function (&$tag, &$data, $disabled)
1715
+				'validate' => function(&$tag, &$data, $disabled)
1716 1716
 				{
1717 1717
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1718 1718
 					if (empty($scheme))
@@ -1738,7 +1738,7 @@  discard block
 block discarded – undo
1738 1738
 		{
1739 1739
 			if (isset($temp_bbc))
1740 1740
 				$bbc_codes = $temp_bbc;
1741
-			usort($codes, function ($a, $b) {
1741
+			usort($codes, function($a, $b) {
1742 1742
 				return strcmp($a['tag'], $b['tag']);
1743 1743
 			});
1744 1744
 			return $codes;
@@ -1976,7 +1976,7 @@  discard block
 block discarded – undo
1976 1976
 										# a run of Unicode domain name characters and a dot
1977 1977
 										[\p{L}\p{M}\p{N}\-.:@]+\.
1978 1978
 										# and then a TLD valid in the DNS or the reserved "local" TLD
1979
-										(?:'. $modSettings['tld_regex'] .'|local)
1979
+										(?:'. $modSettings['tld_regex'] . '|local)
1980 1980
 									)
1981 1981
 									# followed by a non-domain character or end of line
1982 1982
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -2044,7 +2044,7 @@  discard block
 block discarded – undo
2044 2044
 						)?
2045 2045
 						';
2046 2046
 
2047
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
2047
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
2048 2048
 							$url = array_shift($matches);
2049 2049
 
2050 2050
 							$scheme = parse_url($url, PHP_URL_SCHEME);
@@ -2781,7 +2781,7 @@  discard block
 block discarded – undo
2781 2781
 		for ($i = 0, $n = count($smileysfrom); $i < $n; $i++)
2782 2782
 		{
2783 2783
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2784
-			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2784
+			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2785 2785
 
2786 2786
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2787 2787
 
@@ -2798,7 +2798,7 @@  discard block
 block discarded – undo
2798 2798
 
2799 2799
 	// Replace away!
2800 2800
 	$message = preg_replace_callback($smileyPregSearch,
2801
-		function ($matches) use ($smileyPregReplacements)
2801
+		function($matches) use ($smileyPregReplacements)
2802 2802
 		{
2803 2803
 			return $smileyPregReplacements[$matches[1]];
2804 2804
 		}, $message);
@@ -2864,13 +2864,13 @@  discard block
 block discarded – undo
2864 2864
 	{
2865 2865
 		if (defined('SID') && SID != '')
2866 2866
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2867
-				function ($m) use ($scripturl)
2867
+				function($m) use ($scripturl)
2868 2868
 				{
2869
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2869
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
2870 2870
 				}, $setLocation);
2871 2871
 		else
2872 2872
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2873
-				function ($m) use ($scripturl)
2873
+				function($m) use ($scripturl)
2874 2874
 				{
2875 2875
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2876 2876
 				}, $setLocation);
@@ -3193,7 +3193,7 @@  discard block
 block discarded – undo
3193 3193
 
3194 3194
 	// Add a generic "Are you sure?" confirmation message.
3195 3195
 	addInlineJavaScript('
3196
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3196
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3197 3197
 
3198 3198
 	// Now add the capping code for avatars.
3199 3199
 	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')
@@ -3554,7 +3554,7 @@  discard block
 block discarded – undo
3554 3554
 
3555 3555
 		else
3556 3556
 			echo '
3557
-	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3557
+	<script src="', $settings['theme_url'], '/scripts/minified', ($do_deferred ? '_deferred' : ''), '.js', $minSeed, '"></script>';
3558 3558
 	}
3559 3559
 
3560 3560
 	// Inline JavaScript - Actually useful some times!
@@ -3632,14 +3632,14 @@  discard block
 block discarded – undo
3632 3632
 
3633 3633
 		else
3634 3634
 			echo '
3635
-	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3635
+	<link rel="stylesheet" href="', $settings['theme_url'], '/css/minified.css', $minSeed, '">';
3636 3636
 	}
3637 3637
 
3638 3638
 	// Print the rest after the minified files.
3639 3639
 	if (!empty($normal))
3640 3640
 		foreach ($normal as $nf)
3641 3641
 			echo '
3642
-	<link rel="stylesheet" href="', $nf ,'">';
3642
+	<link rel="stylesheet" href="', $nf, '">';
3643 3643
 
3644 3644
 	if ($db_show_debug === true)
3645 3645
 	{
@@ -3655,7 +3655,7 @@  discard block
 block discarded – undo
3655 3655
 	<style>';
3656 3656
 
3657 3657
 		foreach ($context['css_header'] as $css)
3658
-			echo $css .'
3658
+			echo $css . '
3659 3659
 	';
3660 3660
 
3661 3661
 		echo'
@@ -3684,27 +3684,27 @@  discard block
 block discarded – undo
3684 3684
 		return false;
3685 3685
 
3686 3686
 	// Did we already did this?
3687
-	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3687
+	$toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type, 86400);
3688 3688
 
3689 3689
 	// Already done?
3690 3690
 	if (!empty($toCache))
3691 3691
 		return true;
3692 3692
 
3693 3693
 	// No namespaces, sorry!
3694
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3694
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3695 3695
 
3696 3696
 	// Temp path.
3697
-	$cTempPath = $settings['theme_dir'] .'/'. ($type == 'css' ? 'css' : 'scripts') .'/';
3697
+	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
3698 3698
 
3699 3699
 	// What kind of file are we going to create?
3700
-	$toCreate = $cTempPath .'minified'. ($do_deferred ? '_deferred' : '') .'.'. $type;
3700
+	$toCreate = $cTempPath . 'minified' . ($do_deferred ? '_deferred' : '') . '.' . $type;
3701 3701
 
3702 3702
 	// File has to exists, if it isn't try to create it.
3703 3703
 	if ((!file_exists($toCreate) && @fopen($toCreate, 'w') === false) || !smf_chmod($toCreate))
3704 3704
 	{
3705 3705
 		loadLanguage('Errors');
3706 3706
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3707
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3707
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3708 3708
 
3709 3709
 		// The process failed so roll back to print each individual file.
3710 3710
 		return $data;
@@ -3739,14 +3739,14 @@  discard block
 block discarded – undo
3739 3739
 	{
3740 3740
 		loadLanguage('Errors');
3741 3741
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3742
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3742
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3743 3743
 
3744 3744
 		// The process failed so roll back to print each individual file.
3745 3745
 		return $data;
3746 3746
 	}
3747 3747
 
3748 3748
 	// And create a long lived cache entry.
3749
-	cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, $toCreate, 86400);
3749
+	cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, $toCreate, 86400);
3750 3750
 
3751 3751
 	return true;
3752 3752
 }
@@ -3806,7 +3806,7 @@  discard block
 block discarded – undo
3806 3806
 	else
3807 3807
 		$path = $modSettings['attachmentUploadDir'];
3808 3808
 
3809
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3809
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
3810 3810
 }
3811 3811
 
3812 3812
 /**
@@ -3850,10 +3850,10 @@  discard block
 block discarded – undo
3850 3850
 		$valid_low = isValidIP($ip_parts[0]);
3851 3851
 		$valid_high = isValidIP($ip_parts[1]);
3852 3852
 		$count = 0;
3853
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
3853
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
3854 3854
 		$max = ($mode == ':' ? 'ffff' : '255');
3855 3855
 		$min = 0;
3856
-		if(!$valid_low)
3856
+		if (!$valid_low)
3857 3857
 		{
3858 3858
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
3859 3859
 			$valid_low = isValidIP($ip_parts[0]);
@@ -3867,7 +3867,7 @@  discard block
 block discarded – undo
3867 3867
 		}
3868 3868
 
3869 3869
 		$count = 0;
3870
-		if(!$valid_high)
3870
+		if (!$valid_high)
3871 3871
 		{
3872 3872
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
3873 3873
 			$valid_high = isValidIP($ip_parts[1]);
@@ -3880,7 +3880,7 @@  discard block
 block discarded – undo
3880 3880
 			}
3881 3881
 		}
3882 3882
 
3883
-		if($valid_high && $valid_low)
3883
+		if ($valid_high && $valid_low)
3884 3884
 		{
3885 3885
 			$ip_array['low'] = $ip_parts[0];
3886 3886
 			$ip_array['high'] = $ip_parts[1];
@@ -4062,7 +4062,7 @@  discard block
 block discarded – undo
4062 4062
 		addInlineJavaScript('
4063 4063
 	var user_menus = new smc_PopupMenu();
4064 4064
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4065
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4065
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
4066 4066
 		if ($context['allow_pm'])
4067 4067
 			addInlineJavaScript('
4068 4068
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -4682,7 +4682,7 @@  discard block
 block discarded – undo
4682 4682
 		// No? try a fallback to $sourcedir
4683 4683
 		else
4684 4684
 		{
4685
-			$absPath = $sourcedir .'/'. $file;
4685
+			$absPath = $sourcedir . '/' . $file;
4686 4686
 
4687 4687
 			if (file_exists($absPath))
4688 4688
 				require_once($absPath);
@@ -4763,15 +4763,15 @@  discard block
 block discarded – undo
4763 4763
 
4764 4764
 	// UTF-8 occurences of MS special characters
4765 4765
 	$findchars_utf8 = array(
4766
-		"\xe2\x80\x9a",	// single low-9 quotation mark
4767
-		"\xe2\x80\x9e",	// double low-9 quotation mark
4768
-		"\xe2\x80\xa6",	// horizontal ellipsis
4769
-		"\xe2\x80\x98",	// left single curly quote
4770
-		"\xe2\x80\x99",	// right single curly quote
4771
-		"\xe2\x80\x9c",	// left double curly quote
4772
-		"\xe2\x80\x9d",	// right double curly quote
4773
-		"\xe2\x80\x93",	// en dash
4774
-		"\xe2\x80\x94",	// em dash
4766
+		"\xe2\x80\x9a", // single low-9 quotation mark
4767
+		"\xe2\x80\x9e", // double low-9 quotation mark
4768
+		"\xe2\x80\xa6", // horizontal ellipsis
4769
+		"\xe2\x80\x98", // left single curly quote
4770
+		"\xe2\x80\x99", // right single curly quote
4771
+		"\xe2\x80\x9c", // left double curly quote
4772
+		"\xe2\x80\x9d", // right double curly quote
4773
+		"\xe2\x80\x93", // en dash
4774
+		"\xe2\x80\x94", // em dash
4775 4775
 	);
4776 4776
 
4777 4777
 	// windows 1252 / iso equivalents
@@ -4789,15 +4789,15 @@  discard block
 block discarded – undo
4789 4789
 
4790 4790
 	// safe replacements
4791 4791
 	$replacechars = array(
4792
-		',',	// &sbquo;
4793
-		',,',	// &bdquo;
4794
-		'...',	// &hellip;
4795
-		"'",	// &lsquo;
4796
-		"'",	// &rsquo;
4797
-		'"',	// &ldquo;
4798
-		'"',	// &rdquo;
4799
-		'-',	// &ndash;
4800
-		'--',	// &mdash;
4792
+		',', // &sbquo;
4793
+		',,', // &bdquo;
4794
+		'...', // &hellip;
4795
+		"'", // &lsquo;
4796
+		"'", // &rsquo;
4797
+		'"', // &ldquo;
4798
+		'"', // &rdquo;
4799
+		'-', // &ndash;
4800
+		'--', // &mdash;
4801 4801
 	);
4802 4802
 
4803 4803
 	if ($context['utf8'])
@@ -5216,7 +5216,7 @@  discard block
 block discarded – undo
5216 5216
  */
5217 5217
 function inet_dtop($bin)
5218 5218
 {
5219
-	if(empty($bin))
5219
+	if (empty($bin))
5220 5220
 		return '';
5221 5221
 
5222 5222
 	global $db_type;
@@ -5247,28 +5247,28 @@  discard block
 block discarded – undo
5247 5247
  */
5248 5248
 function _safe_serialize($value)
5249 5249
 {
5250
-	if(is_null($value))
5250
+	if (is_null($value))
5251 5251
 		return 'N;';
5252 5252
 
5253
-	if(is_bool($value))
5254
-		return 'b:'. (int) $value .';';
5253
+	if (is_bool($value))
5254
+		return 'b:' . (int) $value . ';';
5255 5255
 
5256
-	if(is_int($value))
5257
-		return 'i:'. $value .';';
5256
+	if (is_int($value))
5257
+		return 'i:' . $value . ';';
5258 5258
 
5259
-	if(is_float($value))
5260
-		return 'd:'. str_replace(',', '.', $value) .';';
5259
+	if (is_float($value))
5260
+		return 'd:' . str_replace(',', '.', $value) . ';';
5261 5261
 
5262
-	if(is_string($value))
5263
-		return 's:'. strlen($value) .':"'. $value .'";';
5262
+	if (is_string($value))
5263
+		return 's:' . strlen($value) . ':"' . $value . '";';
5264 5264
 
5265
-	if(is_array($value))
5265
+	if (is_array($value))
5266 5266
 	{
5267 5267
 		$out = '';
5268
-		foreach($value as $k => $v)
5268
+		foreach ($value as $k => $v)
5269 5269
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5270 5270
 
5271
-		return 'a:'. count($value) .':{'. $out .'}';
5271
+		return 'a:' . count($value) . ':{' . $out . '}';
5272 5272
 	}
5273 5273
 
5274 5274
 	// safe_serialize cannot serialize resources or objects.
@@ -5310,7 +5310,7 @@  discard block
 block discarded – undo
5310 5310
 function _safe_unserialize($str)
5311 5311
 {
5312 5312
 	// Input  is not a string.
5313
-	if(empty($str) || !is_string($str))
5313
+	if (empty($str) || !is_string($str))
5314 5314
 		return false;
5315 5315
 
5316 5316
 	$stack = array();
@@ -5324,40 +5324,40 @@  discard block
 block discarded – undo
5324 5324
 	 *   3 - in array, expecting value or another array
5325 5325
 	 */
5326 5326
 	$state = 0;
5327
-	while($state != 1)
5327
+	while ($state != 1)
5328 5328
 	{
5329 5329
 		$type = isset($str[0]) ? $str[0] : '';
5330
-		if($type == '}')
5330
+		if ($type == '}')
5331 5331
 			$str = substr($str, 1);
5332 5332
 
5333
-		else if($type == 'N' && $str[1] == ';')
5333
+		else if ($type == 'N' && $str[1] == ';')
5334 5334
 		{
5335 5335
 			$value = null;
5336 5336
 			$str = substr($str, 2);
5337 5337
 		}
5338
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5338
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5339 5339
 		{
5340 5340
 			$value = $matches[1] == '1' ? true : false;
5341 5341
 			$str = substr($str, 4);
5342 5342
 		}
5343
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5343
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5344 5344
 		{
5345
-			$value = (int)$matches[1];
5345
+			$value = (int) $matches[1];
5346 5346
 			$str = $matches[2];
5347 5347
 		}
5348
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5348
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5349 5349
 		{
5350
-			$value = (float)$matches[1];
5350
+			$value = (float) $matches[1];
5351 5351
 			$str = $matches[3];
5352 5352
 		}
5353
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5353
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5354 5354
 		{
5355
-			$value = substr($matches[2], 0, (int)$matches[1]);
5356
-			$str = substr($matches[2], (int)$matches[1] + 2);
5355
+			$value = substr($matches[2], 0, (int) $matches[1]);
5356
+			$str = substr($matches[2], (int) $matches[1] + 2);
5357 5357
 		}
5358
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5358
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5359 5359
 		{
5360
-			$expectedLength = (int)$matches[1];
5360
+			$expectedLength = (int) $matches[1];
5361 5361
 			$str = $matches[2];
5362 5362
 		}
5363 5363
 
@@ -5365,10 +5365,10 @@  discard block
 block discarded – undo
5365 5365
 		else
5366 5366
 			return false;
5367 5367
 
5368
-		switch($state)
5368
+		switch ($state)
5369 5369
 		{
5370 5370
 			case 3: // In array, expecting value or another array.
5371
-				if($type == 'a')
5371
+				if ($type == 'a')
5372 5372
 				{
5373 5373
 					$stack[] = &$list;
5374 5374
 					$list[$key] = array();
@@ -5377,7 +5377,7 @@  discard block
 block discarded – undo
5377 5377
 					$state = 2;
5378 5378
 					break;
5379 5379
 				}
5380
-				if($type != '}')
5380
+				if ($type != '}')
5381 5381
 				{
5382 5382
 					$list[$key] = $value;
5383 5383
 					$state = 2;
@@ -5388,29 +5388,29 @@  discard block
 block discarded – undo
5388 5388
 				return false;
5389 5389
 
5390 5390
 			case 2: // in array, expecting end of array or a key
5391
-				if($type == '}')
5391
+				if ($type == '}')
5392 5392
 				{
5393 5393
 					// Array size is less than expected.
5394
-					if(count($list) < end($expected))
5394
+					if (count($list) < end($expected))
5395 5395
 						return false;
5396 5396
 
5397 5397
 					unset($list);
5398
-					$list = &$stack[count($stack)-1];
5398
+					$list = &$stack[count($stack) - 1];
5399 5399
 					array_pop($stack);
5400 5400
 
5401 5401
 					// Go to terminal state if we're at the end of the root array.
5402 5402
 					array_pop($expected);
5403 5403
 
5404
-					if(count($expected) == 0)
5404
+					if (count($expected) == 0)
5405 5405
 						$state = 1;
5406 5406
 
5407 5407
 					break;
5408 5408
 				}
5409 5409
 
5410
-				if($type == 'i' || $type == 's')
5410
+				if ($type == 'i' || $type == 's')
5411 5411
 				{
5412 5412
 					// Array size exceeds expected length.
5413
-					if(count($list) >= end($expected))
5413
+					if (count($list) >= end($expected))
5414 5414
 						return false;
5415 5415
 
5416 5416
 					$key = $value;
@@ -5423,7 +5423,7 @@  discard block
 block discarded – undo
5423 5423
 
5424 5424
 			// Expecting array or value.
5425 5425
 			case 0:
5426
-				if($type == 'a')
5426
+				if ($type == 'a')
5427 5427
 				{
5428 5428
 					$data = array();
5429 5429
 					$list = &$data;
@@ -5432,7 +5432,7 @@  discard block
 block discarded – undo
5432 5432
 					break;
5433 5433
 				}
5434 5434
 
5435
-				if($type != '}')
5435
+				if ($type != '}')
5436 5436
 				{
5437 5437
 					$data = $value;
5438 5438
 					$state = 1;
@@ -5445,7 +5445,7 @@  discard block
 block discarded – undo
5445 5445
 	}
5446 5446
 
5447 5447
 	// Trailing data in input.
5448
-	if(!empty($str))
5448
+	if (!empty($str))
5449 5449
 		return false;
5450 5450
 
5451 5451
 	return $data;
@@ -5499,7 +5499,7 @@  discard block
 block discarded – undo
5499 5499
 	// Set different modes.
5500 5500
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5501 5501
 
5502
-	foreach($chmodValues as $val)
5502
+	foreach ($chmodValues as $val)
5503 5503
 	{
5504 5504
 		// If it's writable, break out of the loop.
5505 5505
 		if (is_writable($file))
@@ -5534,13 +5534,13 @@  discard block
 block discarded – undo
5534 5534
 	$returnArray = @json_decode($json, $returnAsArray);
5535 5535
 
5536 5536
 	// PHP 5.3 so no json_last_error_msg()
5537
-	switch(json_last_error())
5537
+	switch (json_last_error())
5538 5538
 	{
5539 5539
 		case JSON_ERROR_NONE:
5540 5540
 			$jsonError = false;
5541 5541
 			break;
5542 5542
 		case JSON_ERROR_DEPTH:
5543
-			$jsonError =  'JSON_ERROR_DEPTH';
5543
+			$jsonError = 'JSON_ERROR_DEPTH';
5544 5544
 			break;
5545 5545
 		case JSON_ERROR_STATE_MISMATCH:
5546 5546
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -5568,10 +5568,10 @@  discard block
 block discarded – undo
5568 5568
 		loadLanguage('Errors');
5569 5569
 
5570 5570
 		if (!empty($jsonDebug))
5571
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5571
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5572 5572
 
5573 5573
 		else
5574
-			log_error($txt['json_'. $jsonError], 'critical');
5574
+			log_error($txt['json_' . $jsonError], 'critical');
5575 5575
 
5576 5576
 		// Everyone expects an array.
5577 5577
 		return array();
@@ -5679,7 +5679,7 @@  discard block
 block discarded – undo
5679 5679
 		});
5680 5680
 
5681 5681
 		// Convert Punycode to Unicode
5682
-		$tlds = array_map(function ($input) {
5682
+		$tlds = array_map(function($input) {
5683 5683
 			$prefix = 'xn--';
5684 5684
 			$safe_char = 0xFFFC;
5685 5685
 			$base = 36;
@@ -5695,7 +5695,7 @@  discard block
 block discarded – undo
5695 5695
 
5696 5696
 			foreach ($enco_parts as $encoded)
5697 5697
 			{
5698
-				if (strpos($encoded,$prefix) !== 0 || strlen(trim(str_replace($prefix,'',$encoded))) == 0)
5698
+				if (strpos($encoded, $prefix) !== 0 || strlen(trim(str_replace($prefix, '', $encoded))) == 0)
5699 5699
 				{
5700 5700
 					$output_parts[] = $encoded;
5701 5701
 					continue;
@@ -5706,7 +5706,7 @@  discard block
 block discarded – undo
5706 5706
 				$idx = 0;
5707 5707
 				$char = 0x80;
5708 5708
 				$decoded = array();
5709
-				$output='';
5709
+				$output = '';
5710 5710
 				$delim_pos = strrpos($encoded, '-');
5711 5711
 
5712 5712
 				if ($delim_pos > strlen($prefix))
@@ -5722,7 +5722,7 @@  discard block
 block discarded – undo
5722 5722
 
5723 5723
 				for ($enco_idx = $delim_pos ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len)
5724 5724
 				{
5725
-					for ($old_idx = $idx, $w = 1, $k = $base; 1 ; $k += $base)
5725
+					for ($old_idx = $idx, $w = 1, $k = $base; 1; $k += $base)
5726 5726
 					{
5727 5727
 						$cp = ord($encoded{$enco_idx++});
5728 5728
 						$digit = ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $base));
@@ -5763,15 +5763,15 @@  discard block
 block discarded – undo
5763 5763
 
5764 5764
 					// 2 bytes
5765 5765
 					elseif ($v < (1 << 11))
5766
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5766
+						$output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
5767 5767
 
5768 5768
 					// 3 bytes
5769 5769
 					elseif ($v < (1 << 16))
5770
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5770
+						$output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5771 5771
 
5772 5772
 					// 4 bytes
5773 5773
 					elseif ($v < (1 << 21))
5774
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5774
+						$output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5775 5775
 
5776 5776
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5777 5777
 					else
@@ -5877,7 +5877,7 @@  discard block
 block discarded – undo
5877 5877
 	}
5878 5878
 
5879 5879
 	// This recursive function creates the index array from the strings
5880
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5880
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5881 5881
 	{
5882 5882
 		static $depth = 0;
5883 5883
 		$depth++;
@@ -5904,7 +5904,7 @@  discard block
 block discarded – undo
5904 5904
 	};
5905 5905
 
5906 5906
 	// This recursive function turns the index array into a regular expression
5907
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
5907
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
5908 5908
 	{
5909 5909
 		static $depth = 0;
5910 5910
 		$depth++;
@@ -5928,11 +5928,11 @@  discard block
 block discarded – undo
5928 5928
 
5929 5929
 				if (count(array_keys($value)) == 1)
5930 5930
 				{
5931
-					$new_key_array = explode('(?'.'>', $sub_regex);
5931
+					$new_key_array = explode('(?' . '>', $sub_regex);
5932 5932
 					$new_key .= $new_key_array[0];
5933 5933
 				}
5934 5934
 				else
5935
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5935
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
5936 5936
 			}
5937 5937
 
5938 5938
 			if ($depth > 1)
@@ -5972,7 +5972,7 @@  discard block
 block discarded – undo
5972 5972
 		$index = $add_string_to_index($string, $index);
5973 5973
 
5974 5974
 	while (!empty($index))
5975
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
5975
+		$regexes[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
5976 5976
 
5977 5977
 	// Restore PHP's internal character encoding to whatever it was originally
5978 5978
 	if (!empty($current_encoding))
Please login to merge, or discard this patch.
Braces   +1308 added lines, -971 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($type == 'int' && ($val === '+' || $val === '-'))
@@ -390,8 +399,9 @@  discard block
 block discarded – undo
390 399
 		{
391 400
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
392 401
 			{
393
-				if ($match[1] != '+ ')
394
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
402
+				if ($match[1] != '+ ') {
403
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
404
+				}
395 405
 				$type = 'raw';
396 406
 			}
397 407
 		}
@@ -412,8 +422,9 @@  discard block
 block discarded – undo
412 422
 	// Clear any caching?
413 423
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
414 424
 	{
415
-		if (!is_array($members))
416
-			$members = array($members);
425
+		if (!is_array($members)) {
426
+					$members = array($members);
427
+		}
417 428
 
418 429
 		foreach ($members as $member)
419 430
 		{
@@ -446,29 +457,32 @@  discard block
 block discarded – undo
446 457
 {
447 458
 	global $modSettings, $smcFunc;
448 459
 
449
-	if (empty($changeArray) || !is_array($changeArray))
450
-		return;
460
+	if (empty($changeArray) || !is_array($changeArray)) {
461
+			return;
462
+	}
451 463
 
452 464
 	$toRemove = array();
453 465
 
454 466
 	// Go check if there is any setting to be removed.
455
-	foreach ($changeArray as $k => $v)
456
-		if ($v === null)
467
+	foreach ($changeArray as $k => $v) {
468
+			if ($v === null)
457 469
 		{
458 470
 			// Found some, remove them from the original array and add them to ours.
459 471
 			unset($changeArray[$k]);
472
+	}
460 473
 			$toRemove[] = $k;
461 474
 		}
462 475
 
463 476
 	// Proceed with the deletion.
464
-	if (!empty($toRemove))
465
-		$smcFunc['db_query']('', '
477
+	if (!empty($toRemove)) {
478
+			$smcFunc['db_query']('', '
466 479
 			DELETE FROM {db_prefix}settings
467 480
 			WHERE variable IN ({array_string:remove})',
468 481
 			array(
469 482
 				'remove' => $toRemove,
470 483
 			)
471 484
 		);
485
+	}
472 486
 
473 487
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
474 488
 	if ($update)
@@ -497,19 +511,22 @@  discard block
 block discarded – undo
497 511
 	foreach ($changeArray as $variable => $value)
498 512
 	{
499 513
 		// Don't bother if it's already like that ;).
500
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
501
-			continue;
514
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
515
+					continue;
516
+		}
502 517
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
503
-		elseif (!isset($modSettings[$variable]) && empty($value))
504
-			continue;
518
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
519
+					continue;
520
+		}
505 521
 
506 522
 		$replaceArray[] = array($variable, $value);
507 523
 
508 524
 		$modSettings[$variable] = $value;
509 525
 	}
510 526
 
511
-	if (empty($replaceArray))
512
-		return;
527
+	if (empty($replaceArray)) {
528
+			return;
529
+	}
513 530
 
514 531
 	$smcFunc['db_insert']('replace',
515 532
 		'{db_prefix}settings',
@@ -555,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];
@@ -723,17 +754,20 @@  discard block
 block discarded – undo
723 754
 	static $unsupportedFormats, $finalizedFormats;
724 755
 
725 756
 	// Offset the time.
726
-	if (!$offset_type)
727
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
757
+	if (!$offset_type) {
758
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
759
+	}
728 760
 	// Just the forum offset?
729
-	elseif ($offset_type == 'forum')
730
-		$time = $log_time + $modSettings['time_offset'] * 3600;
731
-	else
732
-		$time = $log_time;
761
+	elseif ($offset_type == 'forum') {
762
+			$time = $log_time + $modSettings['time_offset'] * 3600;
763
+	} else {
764
+			$time = $log_time;
765
+	}
733 766
 
734 767
 	// We can't have a negative date (on Windows, at least.)
735
-	if ($log_time < 0)
736
-		$log_time = 0;
768
+	if ($log_time < 0) {
769
+			$log_time = 0;
770
+	}
737 771
 
738 772
 	// Today and Yesterday?
739 773
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -750,24 +784,27 @@  discard block
 block discarded – undo
750 784
 		{
751 785
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
752 786
 			$today_fmt = $h . ':%M' . $s . ' %p';
787
+		} else {
788
+					$today_fmt = '%H:%M' . $s;
753 789
 		}
754
-		else
755
-			$today_fmt = '%H:%M' . $s;
756 790
 
757 791
 		// Same day of the year, same year.... Today!
758
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
759
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
792
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
793
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
794
+		}
760 795
 
761 796
 		// 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...
762
-		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))
763
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
797
+		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)) {
798
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
799
+		}
764 800
 	}
765 801
 
766 802
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
767 803
 
768 804
 	// Use the cached formats if available
769
-	if (is_null($finalizedFormats))
770
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
805
+	if (is_null($finalizedFormats)) {
806
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
807
+	}
771 808
 
772 809
 	// Make a supported version for this format if we don't already have one
773 810
 	if (empty($finalizedFormats[$str]))
@@ -796,8 +833,9 @@  discard block
 block discarded – undo
796 833
 		);
797 834
 
798 835
 		// No need to do this part again if we already did it once
799
-		if (is_null($unsupportedFormats))
800
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
836
+		if (is_null($unsupportedFormats)) {
837
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
838
+		}
801 839
 		if (empty($unsupportedFormats))
802 840
 		{
803 841
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -806,20 +844,23 @@  discard block
 block discarded – undo
806 844
 
807 845
 				// Windows will return false for unsupported formats
808 846
 				// Other operating systems return the format string as a literal
809
-				if ($value === false || $value === $format)
810
-					$unsupportedFormats[] = $format;
847
+				if ($value === false || $value === $format) {
848
+									$unsupportedFormats[] = $format;
849
+				}
811 850
 			}
812 851
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
813 852
 		}
814 853
 
815 854
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
816
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
817
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
855
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
856
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
857
+		}
818 858
 
819 859
 		// Substitute unsupported formats with supported ones
820
-		if (!empty($unsupportedFormats))
821
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
860
+		if (!empty($unsupportedFormats)) {
861
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
822 862
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
863
+		}
823 864
 
824 865
 		// Remember this so we don't need to do it again
825 866
 		$finalizedFormats[$str] = $timeformat;
@@ -828,33 +869,39 @@  discard block
 block discarded – undo
828 869
 
829 870
 	$str = $finalizedFormats[$str];
830 871
 
831
-	if (!isset($locale_cache))
832
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale']);
872
+	if (!isset($locale_cache)) {
873
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale']);
874
+	}
833 875
 
834 876
 	if ($locale_cache !== false)
835 877
 	{
836 878
 		// Check if another process changed the locale
837
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
838
-			setlocale(LC_TIME, $txt['lang_locale']);
879
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
880
+					setlocale(LC_TIME, $txt['lang_locale']);
881
+		}
839 882
 
840
-		if (!isset($non_twelve_hour))
841
-			$non_twelve_hour = trim(strftime('%p')) === '';
842
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
843
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
883
+		if (!isset($non_twelve_hour)) {
884
+					$non_twelve_hour = trim(strftime('%p')) === '';
885
+		}
886
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
887
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
888
+		}
844 889
 
845
-		foreach (array('%a', '%A', '%b', '%B') as $token)
846
-			if (strpos($str, $token) !== false)
890
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
891
+					if (strpos($str, $token) !== false)
847 892
 				$str = str_replace($token, strftime($token, $time), $str);
848
-	}
849
-	else
893
+		}
894
+	} else
850 895
 	{
851 896
 		// Do-it-yourself time localization.  Fun.
852
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
853
-			if (strpos($str, $token) !== false)
897
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
898
+					if (strpos($str, $token) !== false)
854 899
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
900
+		}
855 901
 
856
-		if (strpos($str, '%p') !== false)
857
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
902
+		if (strpos($str, '%p') !== false) {
903
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
904
+		}
858 905
 	}
859 906
 
860 907
 	// Format the time and then restore any literal percent characters
@@ -877,16 +924,19 @@  discard block
 block discarded – undo
877 924
 	static $translation = array();
878 925
 
879 926
 	// Determine the character set... Default to UTF-8
880
-	if (empty($context['character_set']))
881
-		$charset = 'UTF-8';
927
+	if (empty($context['character_set'])) {
928
+			$charset = 'UTF-8';
929
+	}
882 930
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
883
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
884
-		$charset = 'ISO-8859-1';
885
-	else
886
-		$charset = $context['character_set'];
931
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
932
+			$charset = 'ISO-8859-1';
933
+	} else {
934
+			$charset = $context['character_set'];
935
+	}
887 936
 
888
-	if (empty($translation))
889
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
937
+	if (empty($translation)) {
938
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
939
+	}
890 940
 
891 941
 	return strtr($string, $translation);
892 942
 }
@@ -908,8 +958,9 @@  discard block
 block discarded – undo
908 958
 	global $smcFunc;
909 959
 
910 960
 	// It was already short enough!
911
-	if ($smcFunc['strlen']($subject) <= $len)
912
-		return $subject;
961
+	if ($smcFunc['strlen']($subject) <= $len) {
962
+			return $subject;
963
+	}
913 964
 
914 965
 	// Shorten it by the length it was too long, and strip off junk from the end.
915 966
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -928,10 +979,11 @@  discard block
 block discarded – undo
928 979
 {
929 980
 	global $user_info, $modSettings;
930 981
 
931
-	if ($timestamp === null)
932
-		$timestamp = time();
933
-	elseif ($timestamp == 0)
934
-		return 0;
982
+	if ($timestamp === null) {
983
+			$timestamp = time();
984
+	} elseif ($timestamp == 0) {
985
+			return 0;
986
+	}
935 987
 
936 988
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
937 989
 }
@@ -960,8 +1012,9 @@  discard block
 block discarded – undo
960 1012
 		$array[$i] = $array[$j];
961 1013
 		$array[$j] = $temp;
962 1014
 
963
-		for ($i = 1; $p[$i] == 0; $i++)
964
-			$p[$i] = 1;
1015
+		for ($i = 1; $p[$i] == 0; $i++) {
1016
+					$p[$i] = 1;
1017
+		}
965 1018
 
966 1019
 		$orders[] = $array;
967 1020
 	}
@@ -993,12 +1046,14 @@  discard block
 block discarded – undo
993 1046
 	static $disabled;
994 1047
 
995 1048
 	// Don't waste cycles
996
-	if ($message === '')
997
-		return '';
1049
+	if ($message === '') {
1050
+			return '';
1051
+	}
998 1052
 
999 1053
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1000
-	if (!isset($context['utf8']))
1001
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1054
+	if (!isset($context['utf8'])) {
1055
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1056
+	}
1002 1057
 
1003 1058
 	// Clean up any cut/paste issues we may have
1004 1059
 	$message = sanitizeMSCutPaste($message);
@@ -1010,13 +1065,15 @@  discard block
 block discarded – undo
1010 1065
 		return $message;
1011 1066
 	}
1012 1067
 
1013
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1014
-		$smileys = (bool) $smileys;
1068
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1069
+			$smileys = (bool) $smileys;
1070
+	}
1015 1071
 
1016 1072
 	if (empty($modSettings['enableBBC']) && $message !== false)
1017 1073
 	{
1018
-		if ($smileys === true)
1019
-			parsesmileys($message);
1074
+		if ($smileys === true) {
1075
+					parsesmileys($message);
1076
+		}
1020 1077
 
1021 1078
 		return $message;
1022 1079
 	}
@@ -1029,8 +1086,9 @@  discard block
 block discarded – undo
1029 1086
 	}
1030 1087
 
1031 1088
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1032
-	if (!empty($modSettings['autoLinkUrls']))
1033
-		set_tld_regex();
1089
+	if (!empty($modSettings['autoLinkUrls'])) {
1090
+			set_tld_regex();
1091
+	}
1034 1092
 
1035 1093
 	// Allow mods access before entering the main parse_bbc loop
1036 1094
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1044,12 +1102,14 @@  discard block
 block discarded – undo
1044 1102
 
1045 1103
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1046 1104
 
1047
-			foreach ($temp as $tag)
1048
-				$disabled[trim($tag)] = true;
1105
+			foreach ($temp as $tag) {
1106
+							$disabled[trim($tag)] = true;
1107
+			}
1049 1108
 		}
1050 1109
 
1051
-		if (empty($modSettings['enableEmbeddedFlash']))
1052
-			$disabled['flash'] = true;
1110
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1111
+					$disabled['flash'] = true;
1112
+		}
1053 1113
 
1054 1114
 		/* The following bbc are formatted as an array, with keys as follows:
1055 1115
 
@@ -1170,8 +1230,9 @@  discard block
 block discarded – undo
1170 1230
 					$returnContext = '';
1171 1231
 
1172 1232
 					// BBC or the entire attachments feature is disabled
1173
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1174
-						return $data;
1233
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1234
+											return $data;
1235
+					}
1175 1236
 
1176 1237
 					// Save the attach ID.
1177 1238
 					$attachID = $data;
@@ -1182,8 +1243,9 @@  discard block
 block discarded – undo
1182 1243
 					$currentAttachment = parseAttachBBC($attachID);
1183 1244
 
1184 1245
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1185
-					if (is_string($currentAttachment))
1186
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1246
+					if (is_string($currentAttachment)) {
1247
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1248
+					}
1187 1249
 
1188 1250
 					if (!empty($currentAttachment['is_image']))
1189 1251
 					{
@@ -1199,15 +1261,17 @@  discard block
 block discarded – undo
1199 1261
 							$height = ' height="' . $currentAttachment['height'] . '"';
1200 1262
 						}
1201 1263
 
1202
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1203
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1204
-						else
1205
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1264
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1265
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1266
+						} else {
1267
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1268
+						}
1206 1269
 					}
1207 1270
 
1208 1271
 					// No image. Show a link.
1209
-					else
1210
-						$returnContext .= $currentAttachment['link'];
1272
+					else {
1273
+											$returnContext .= $currentAttachment['link'];
1274
+					}
1211 1275
 
1212 1276
 					// Gotta append what we just did.
1213 1277
 					$data = $returnContext;
@@ -1238,8 +1302,9 @@  discard block
 block discarded – undo
1238 1302
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1239 1303
 						{
1240 1304
 							// Do PHP code coloring?
1241
-							if ($php_parts[$php_i] != '&lt;?php')
1242
-								continue;
1305
+							if ($php_parts[$php_i] != '&lt;?php') {
1306
+															continue;
1307
+							}
1243 1308
 
1244 1309
 							$php_string = '';
1245 1310
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1255,8 +1320,9 @@  discard block
 block discarded – undo
1255 1320
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1256 1321
 
1257 1322
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1258
-						if ($context['browser']['is_opera'])
1259
-							$data .= '&nbsp;';
1323
+						if ($context['browser']['is_opera']) {
1324
+													$data .= '&nbsp;';
1325
+						}
1260 1326
 					}
1261 1327
 				},
1262 1328
 				'block_level' => true,
@@ -1275,8 +1341,9 @@  discard block
 block discarded – undo
1275 1341
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1276 1342
 						{
1277 1343
 							// Do PHP code coloring?
1278
-							if ($php_parts[$php_i] != '&lt;?php')
1279
-								continue;
1344
+							if ($php_parts[$php_i] != '&lt;?php') {
1345
+															continue;
1346
+							}
1280 1347
 
1281 1348
 							$php_string = '';
1282 1349
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1292,8 +1359,9 @@  discard block
 block discarded – undo
1292 1359
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1293 1360
 
1294 1361
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1295
-						if ($context['browser']['is_opera'])
1296
-							$data[0] .= '&nbsp;';
1362
+						if ($context['browser']['is_opera']) {
1363
+													$data[0] .= '&nbsp;';
1364
+						}
1297 1365
 					}
1298 1366
 				},
1299 1367
 				'block_level' => true,
@@ -1331,11 +1399,13 @@  discard block
 block discarded – undo
1331 1399
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1332 1400
 				'validate' => function (&$tag, &$data, $disabled)
1333 1401
 				{
1334
-					if (isset($disabled['url']))
1335
-						$tag['content'] = '$1';
1402
+					if (isset($disabled['url'])) {
1403
+											$tag['content'] = '$1';
1404
+					}
1336 1405
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1337
-					if (empty($scheme))
1338
-						$data[0] = '//' . ltrim($data[0], ':/');
1406
+					if (empty($scheme)) {
1407
+											$data[0] = '//' . ltrim($data[0], ':/');
1408
+					}
1339 1409
 				},
1340 1410
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1341 1411
 			),
@@ -1349,10 +1419,11 @@  discard block
 block discarded – undo
1349 1419
 				{
1350 1420
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1351 1421
 
1352
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1353
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1354
-					else
1355
-						$css = '';
1422
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1423
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1424
+					} else {
1425
+											$css = '';
1426
+					}
1356 1427
 
1357 1428
 					$data = $class . $css;
1358 1429
 				},
@@ -1402,14 +1473,16 @@  discard block
 block discarded – undo
1402 1473
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1403 1474
 					if ($image_proxy_enabled)
1404 1475
 					{
1405
-						if (empty($scheme))
1406
-							$data = 'http://' . ltrim($data, ':/');
1476
+						if (empty($scheme)) {
1477
+													$data = 'http://' . ltrim($data, ':/');
1478
+						}
1407 1479
 
1408
-						if ($scheme != 'https')
1409
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1480
+						if ($scheme != 'https') {
1481
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1482
+						}
1483
+					} elseif (empty($scheme)) {
1484
+											$data = '//' . ltrim($data, ':/');
1410 1485
 					}
1411
-					elseif (empty($scheme))
1412
-						$data = '//' . ltrim($data, ':/');
1413 1486
 				},
1414 1487
 				'disabled_content' => '($1)',
1415 1488
 			),
@@ -1425,14 +1498,16 @@  discard block
 block discarded – undo
1425 1498
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1426 1499
 					if ($image_proxy_enabled)
1427 1500
 					{
1428
-						if (empty($scheme))
1429
-							$data = 'http://' . ltrim($data, ':/');
1501
+						if (empty($scheme)) {
1502
+													$data = 'http://' . ltrim($data, ':/');
1503
+						}
1430 1504
 
1431
-						if ($scheme != 'https')
1432
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1505
+						if ($scheme != 'https') {
1506
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1507
+						}
1508
+					} elseif (empty($scheme)) {
1509
+											$data = '//' . ltrim($data, ':/');
1433 1510
 					}
1434
-					elseif (empty($scheme))
1435
-						$data = '//' . ltrim($data, ':/');
1436 1511
 				},
1437 1512
 				'disabled_content' => '($1)',
1438 1513
 			),
@@ -1444,8 +1519,9 @@  discard block
 block discarded – undo
1444 1519
 				{
1445 1520
 					$data = strtr($data, array('<br>' => ''));
1446 1521
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1447
-					if (empty($scheme))
1448
-						$data = '//' . ltrim($data, ':/');
1522
+					if (empty($scheme)) {
1523
+											$data = '//' . ltrim($data, ':/');
1524
+					}
1449 1525
 				},
1450 1526
 			),
1451 1527
 			array(
@@ -1456,13 +1532,14 @@  discard block
 block discarded – undo
1456 1532
 				'after' => '</a>',
1457 1533
 				'validate' => function (&$tag, &$data, $disabled)
1458 1534
 				{
1459
-					if (substr($data, 0, 1) == '#')
1460
-						$data = '#post_' . substr($data, 1);
1461
-					else
1535
+					if (substr($data, 0, 1) == '#') {
1536
+											$data = '#post_' . substr($data, 1);
1537
+					} else
1462 1538
 					{
1463 1539
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1464
-						if (empty($scheme))
1465
-							$data = '//' . ltrim($data, ':/');
1540
+						if (empty($scheme)) {
1541
+													$data = '//' . ltrim($data, ':/');
1542
+						}
1466 1543
 					}
1467 1544
 				},
1468 1545
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1540,8 +1617,9 @@  discard block
 block discarded – undo
1540 1617
 					{
1541 1618
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1542 1619
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1543
-						if ($add_begin)
1544
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1620
+						if ($add_begin) {
1621
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1622
+						}
1545 1623
 					}
1546 1624
 				},
1547 1625
 				'block_level' => false,
@@ -1672,10 +1750,11 @@  discard block
 block discarded – undo
1672 1750
 				'content' => '$1',
1673 1751
 				'validate' => function (&$tag, &$data, $disabled)
1674 1752
 				{
1675
-					if (is_numeric($data))
1676
-						$data = timeformat($data);
1677
-					else
1678
-						$tag['content'] = '[time]$1[/time]';
1753
+					if (is_numeric($data)) {
1754
+											$data = timeformat($data);
1755
+					} else {
1756
+											$tag['content'] = '[time]$1[/time]';
1757
+					}
1679 1758
 				},
1680 1759
 			),
1681 1760
 			array(
@@ -1702,8 +1781,9 @@  discard block
 block discarded – undo
1702 1781
 				{
1703 1782
 					$data = strtr($data, array('<br>' => ''));
1704 1783
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1705
-					if (empty($scheme))
1706
-						$data = '//' . ltrim($data, ':/');
1784
+					if (empty($scheme)) {
1785
+											$data = '//' . ltrim($data, ':/');
1786
+					}
1707 1787
 				},
1708 1788
 			),
1709 1789
 			array(
@@ -1715,8 +1795,9 @@  discard block
 block discarded – undo
1715 1795
 				'validate' => function (&$tag, &$data, $disabled)
1716 1796
 				{
1717 1797
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1718
-					if (empty($scheme))
1719
-						$data = '//' . ltrim($data, ':/');
1798
+					if (empty($scheme)) {
1799
+											$data = '//' . ltrim($data, ':/');
1800
+					}
1720 1801
 				},
1721 1802
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1722 1803
 				'disabled_after' => ' ($1)',
@@ -1736,8 +1817,9 @@  discard block
 block discarded – undo
1736 1817
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1737 1818
 		if ($message === false)
1738 1819
 		{
1739
-			if (isset($temp_bbc))
1740
-				$bbc_codes = $temp_bbc;
1820
+			if (isset($temp_bbc)) {
1821
+							$bbc_codes = $temp_bbc;
1822
+			}
1741 1823
 			usort($codes, function ($a, $b) {
1742 1824
 				return strcmp($a['tag'], $b['tag']);
1743 1825
 			});
@@ -1757,8 +1839,9 @@  discard block
 block discarded – undo
1757 1839
 		);
1758 1840
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1759 1841
 		{
1760
-			foreach ($itemcodes as $c => $dummy)
1761
-				$bbc_codes[$c] = array();
1842
+			foreach ($itemcodes as $c => $dummy) {
1843
+							$bbc_codes[$c] = array();
1844
+			}
1762 1845
 		}
1763 1846
 
1764 1847
 		// Shhhh!
@@ -1779,12 +1862,14 @@  discard block
 block discarded – undo
1779 1862
 		foreach ($codes as $code)
1780 1863
 		{
1781 1864
 			// Make it easier to process parameters later
1782
-			if (!empty($code['parameters']))
1783
-				ksort($code['parameters'], SORT_STRING);
1865
+			if (!empty($code['parameters'])) {
1866
+							ksort($code['parameters'], SORT_STRING);
1867
+			}
1784 1868
 
1785 1869
 			// If we are not doing every tag only do ones we are interested in.
1786
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1787
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1870
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1871
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1872
+			}
1788 1873
 		}
1789 1874
 		$codes = null;
1790 1875
 	}
@@ -1795,8 +1880,9 @@  discard block
 block discarded – undo
1795 1880
 		// It's likely this will change if the message is modified.
1796 1881
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1797 1882
 
1798
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1799
-			return $temp;
1883
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1884
+					return $temp;
1885
+		}
1800 1886
 
1801 1887
 		$cache_t = microtime();
1802 1888
 	}
@@ -1828,8 +1914,9 @@  discard block
 block discarded – undo
1828 1914
 		$disabled['flash'] = true;
1829 1915
 
1830 1916
 		// @todo Change maybe?
1831
-		if (!isset($_GET['images']))
1832
-			$disabled['img'] = true;
1917
+		if (!isset($_GET['images'])) {
1918
+					$disabled['img'] = true;
1919
+		}
1833 1920
 
1834 1921
 		// @todo Interface/setting to add more?
1835 1922
 	}
@@ -1853,8 +1940,9 @@  discard block
 block discarded – undo
1853 1940
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1854 1941
 
1855 1942
 		// Failsafe.
1856
-		if ($pos === false || $last_pos > $pos)
1857
-			$pos = strlen($message) + 1;
1943
+		if ($pos === false || $last_pos > $pos) {
1944
+					$pos = strlen($message) + 1;
1945
+		}
1858 1946
 
1859 1947
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1860 1948
 		if ($last_pos < $pos - 1)
@@ -1873,8 +1961,9 @@  discard block
 block discarded – undo
1873 1961
 
1874 1962
 				// <br> should be empty.
1875 1963
 				$empty_tags = array('br', 'hr');
1876
-				foreach ($empty_tags as $tag)
1877
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1964
+				foreach ($empty_tags as $tag) {
1965
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1966
+				}
1878 1967
 
1879 1968
 				// b, u, i, s, pre... basic tags.
1880 1969
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1883,8 +1972,9 @@  discard block
 block discarded – undo
1883 1972
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1884 1973
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1885 1974
 
1886
-					if ($diff > 0)
1887
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1975
+					if ($diff > 0) {
1976
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1977
+					}
1888 1978
 				}
1889 1979
 
1890 1980
 				// Do <img ...> - with security... action= -> action-.
@@ -1897,8 +1987,9 @@  discard block
 block discarded – undo
1897 1987
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1898 1988
 
1899 1989
 						// Remove action= from the URL - no funny business, now.
1900
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1901
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1990
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1991
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1992
+						}
1902 1993
 
1903 1994
 						// Check if the image is larger than allowed.
1904 1995
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1919,9 +2010,9 @@  discard block
 block discarded – undo
1919 2010
 
1920 2011
 							// Set the new image tag.
1921 2012
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
2013
+						} else {
2014
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1922 2015
 						}
1923
-						else
1924
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1925 2016
 					}
1926 2017
 
1927 2018
 					$data = strtr($data, $replaces);
@@ -1934,16 +2025,18 @@  discard block
 block discarded – undo
1934 2025
 				$no_autolink_area = false;
1935 2026
 				if (!empty($open_tags))
1936 2027
 				{
1937
-					foreach ($open_tags as $open_tag)
1938
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2028
+					foreach ($open_tags as $open_tag) {
2029
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1939 2030
 							$no_autolink_area = true;
2031
+					}
1940 2032
 				}
1941 2033
 
1942 2034
 				// Don't go backwards.
1943 2035
 				// @todo Don't think is the real solution....
1944 2036
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1945
-				if ($pos < $lastAutoPos)
1946
-					$no_autolink_area = true;
2037
+				if ($pos < $lastAutoPos) {
2038
+									$no_autolink_area = true;
2039
+				}
1947 2040
 				$lastAutoPos = $pos;
1948 2041
 
1949 2042
 				if (!$no_autolink_area)
@@ -2052,17 +2145,19 @@  discard block
 block discarded – undo
2052 2145
 							if ($scheme == 'mailto')
2053 2146
 							{
2054 2147
 								$email_address = str_replace('mailto:', '', $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;
2148
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2149
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2150
+								} else {
2151
+																	return $url;
2152
+								}
2059 2153
 							}
2060 2154
 
2061 2155
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2062
-							if (empty($scheme))
2063
-								$fullUrl = '//' . ltrim($url, ':/');
2064
-							else
2065
-								$fullUrl = $url;
2156
+							if (empty($scheme)) {
2157
+															$fullUrl = '//' . ltrim($url, ':/');
2158
+							} else {
2159
+															$fullUrl = $url;
2160
+							}
2066 2161
 
2067 2162
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2068 2163
 						}, $data);
@@ -2111,16 +2206,18 @@  discard block
 block discarded – undo
2111 2206
 		}
2112 2207
 
2113 2208
 		// Are we there yet?  Are we there yet?
2114
-		if ($pos >= strlen($message) - 1)
2115
-			break;
2209
+		if ($pos >= strlen($message) - 1) {
2210
+					break;
2211
+		}
2116 2212
 
2117 2213
 		$tags = strtolower($message[$pos + 1]);
2118 2214
 
2119 2215
 		if ($tags == '/' && !empty($open_tags))
2120 2216
 		{
2121 2217
 			$pos2 = strpos($message, ']', $pos + 1);
2122
-			if ($pos2 == $pos + 2)
2123
-				continue;
2218
+			if ($pos2 == $pos + 2) {
2219
+							continue;
2220
+			}
2124 2221
 
2125 2222
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2126 2223
 
@@ -2130,8 +2227,9 @@  discard block
 block discarded – undo
2130 2227
 			do
2131 2228
 			{
2132 2229
 				$tag = array_pop($open_tags);
2133
-				if (!$tag)
2134
-					break;
2230
+				if (!$tag) {
2231
+									break;
2232
+				}
2135 2233
 
2136 2234
 				if (!empty($tag['block_level']))
2137 2235
 				{
@@ -2145,10 +2243,11 @@  discard block
 block discarded – undo
2145 2243
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2146 2244
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2147 2245
 					{
2148
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2149
-							if ($temp['tag'] == $look_for)
2246
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2247
+													if ($temp['tag'] == $look_for)
2150 2248
 							{
2151 2249
 								$block_level = !empty($temp['block_level']);
2250
+						}
2152 2251
 								break;
2153 2252
 							}
2154 2253
 					}
@@ -2170,15 +2269,15 @@  discard block
 block discarded – undo
2170 2269
 			{
2171 2270
 				$open_tags = $to_close;
2172 2271
 				continue;
2173
-			}
2174
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2272
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2175 2273
 			{
2176 2274
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2177 2275
 				{
2178
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2179
-						if ($temp['tag'] == $look_for)
2276
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2277
+											if ($temp['tag'] == $look_for)
2180 2278
 						{
2181 2279
 							$block_level = !empty($temp['block_level']);
2280
+					}
2182 2281
 							break;
2183 2282
 						}
2184 2283
 				}
@@ -2186,8 +2285,9 @@  discard block
 block discarded – undo
2186 2285
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2187 2286
 				if (!$block_level)
2188 2287
 				{
2189
-					foreach ($to_close as $tag)
2190
-						array_push($open_tags, $tag);
2288
+					foreach ($to_close as $tag) {
2289
+											array_push($open_tags, $tag);
2290
+					}
2191 2291
 					continue;
2192 2292
 				}
2193 2293
 			}
@@ -2200,14 +2300,17 @@  discard block
 block discarded – undo
2200 2300
 
2201 2301
 				// See the comment at the end of the big loop - just eating whitespace ;).
2202 2302
 				$whitespace_regex = '';
2203
-				if (!empty($tag['block_level']))
2204
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2303
+				if (!empty($tag['block_level'])) {
2304
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2305
+				}
2205 2306
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2206
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2207
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2307
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2308
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2309
+				}
2208 2310
 
2209
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2210
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2311
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2312
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2313
+				}
2211 2314
 			}
2212 2315
 
2213 2316
 			if (!empty($to_close))
@@ -2220,8 +2323,9 @@  discard block
 block discarded – undo
2220 2323
 		}
2221 2324
 
2222 2325
 		// No tags for this character, so just keep going (fastest possible course.)
2223
-		if (!isset($bbc_codes[$tags]))
2224
-			continue;
2326
+		if (!isset($bbc_codes[$tags])) {
2327
+					continue;
2328
+		}
2225 2329
 
2226 2330
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2227 2331
 		$tag = null;
@@ -2230,44 +2334,52 @@  discard block
 block discarded – undo
2230 2334
 			$pt_strlen = strlen($possible['tag']);
2231 2335
 
2232 2336
 			// Not a match?
2233
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2234
-				continue;
2337
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2338
+							continue;
2339
+			}
2235 2340
 
2236 2341
 			$next_c = $message[$pos + 1 + $pt_strlen];
2237 2342
 
2238 2343
 			// A test validation?
2239
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2240
-				continue;
2344
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2345
+							continue;
2346
+			}
2241 2347
 			// Do we want parameters?
2242 2348
 			elseif (!empty($possible['parameters']))
2243 2349
 			{
2244
-				if ($next_c != ' ')
2245
-					continue;
2246
-			}
2247
-			elseif (isset($possible['type']))
2350
+				if ($next_c != ' ') {
2351
+									continue;
2352
+				}
2353
+			} elseif (isset($possible['type']))
2248 2354
 			{
2249 2355
 				// Do we need an equal sign?
2250
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2251
-					continue;
2356
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2357
+									continue;
2358
+				}
2252 2359
 				// Maybe we just want a /...
2253
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2254
-					continue;
2360
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2361
+									continue;
2362
+				}
2255 2363
 				// An immediate ]?
2256
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2257
-					continue;
2364
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2365
+									continue;
2366
+				}
2258 2367
 			}
2259 2368
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2260
-			elseif ($next_c != ']')
2261
-				continue;
2369
+			elseif ($next_c != ']') {
2370
+							continue;
2371
+			}
2262 2372
 
2263 2373
 			// Check allowed tree?
2264
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2265
-				continue;
2266
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2267
-				continue;
2374
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2375
+							continue;
2376
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2377
+							continue;
2378
+			}
2268 2379
 			// If this is in the list of disallowed child tags, don't parse it.
2269
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2270
-				continue;
2380
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2381
+							continue;
2382
+			}
2271 2383
 
2272 2384
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2273 2385
 
@@ -2279,8 +2391,9 @@  discard block
 block discarded – undo
2279 2391
 				foreach ($open_tags as $open_quote)
2280 2392
 				{
2281 2393
 					// Every parent quote this quote has flips the styling
2282
-					if ($open_quote['tag'] == 'quote')
2283
-						$quote_alt = !$quote_alt;
2394
+					if ($open_quote['tag'] == 'quote') {
2395
+											$quote_alt = !$quote_alt;
2396
+					}
2284 2397
 				}
2285 2398
 				// Add a class to the quote to style alternating blockquotes
2286 2399
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2291,8 +2404,9 @@  discard block
 block discarded – undo
2291 2404
 			{
2292 2405
 				// Build a regular expression for each parameter for the current tag.
2293 2406
 				$preg = array();
2294
-				foreach ($possible['parameters'] as $p => $info)
2295
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2407
+				foreach ($possible['parameters'] as $p => $info) {
2408
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2409
+				}
2296 2410
 
2297 2411
 				// Extract the string that potentially holds our parameters.
2298 2412
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2312,24 +2426,27 @@  discard block
 block discarded – undo
2312 2426
 
2313 2427
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2314 2428
 
2315
-					if ($match)
2316
-						$blob_counter = count($blobs) + 1;
2429
+					if ($match) {
2430
+											$blob_counter = count($blobs) + 1;
2431
+					}
2317 2432
 				}
2318 2433
 
2319 2434
 				// Didn't match our parameter list, try the next possible.
2320
-				if (!$match)
2321
-					continue;
2435
+				if (!$match) {
2436
+									continue;
2437
+				}
2322 2438
 
2323 2439
 				$params = array();
2324 2440
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2325 2441
 				{
2326 2442
 					$key = strtok(ltrim($matches[$i]), '=');
2327
-					if (isset($possible['parameters'][$key]['value']))
2328
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2329
-					elseif (isset($possible['parameters'][$key]['validate']))
2330
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2331
-					else
2332
-						$params['{' . $key . '}'] = $matches[$i + 1];
2443
+					if (isset($possible['parameters'][$key]['value'])) {
2444
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2445
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2446
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2447
+					} else {
2448
+											$params['{' . $key . '}'] = $matches[$i + 1];
2449
+					}
2333 2450
 
2334 2451
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2335 2452
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2337,23 +2454,26 @@  discard block
 block discarded – undo
2337 2454
 
2338 2455
 				foreach ($possible['parameters'] as $p => $info)
2339 2456
 				{
2340
-					if (!isset($params['{' . $p . '}']))
2341
-						$params['{' . $p . '}'] = '';
2457
+					if (!isset($params['{' . $p . '}'])) {
2458
+											$params['{' . $p . '}'] = '';
2459
+					}
2342 2460
 				}
2343 2461
 
2344 2462
 				$tag = $possible;
2345 2463
 
2346 2464
 				// Put the parameters into the string.
2347
-				if (isset($tag['before']))
2348
-					$tag['before'] = strtr($tag['before'], $params);
2349
-				if (isset($tag['after']))
2350
-					$tag['after'] = strtr($tag['after'], $params);
2351
-				if (isset($tag['content']))
2352
-					$tag['content'] = strtr($tag['content'], $params);
2465
+				if (isset($tag['before'])) {
2466
+									$tag['before'] = strtr($tag['before'], $params);
2467
+				}
2468
+				if (isset($tag['after'])) {
2469
+									$tag['after'] = strtr($tag['after'], $params);
2470
+				}
2471
+				if (isset($tag['content'])) {
2472
+									$tag['content'] = strtr($tag['content'], $params);
2473
+				}
2353 2474
 
2354 2475
 				$pos1 += strlen($given_param_string);
2355
-			}
2356
-			else
2476
+			} else
2357 2477
 			{
2358 2478
 				$tag = $possible;
2359 2479
 				$params = array();
@@ -2364,8 +2484,9 @@  discard block
 block discarded – undo
2364 2484
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2365 2485
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2366 2486
 		{
2367
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2368
-				continue;
2487
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2488
+							continue;
2489
+			}
2369 2490
 
2370 2491
 			$tag = $itemcodes[$message[$pos + 1]];
2371 2492
 
@@ -2386,9 +2507,9 @@  discard block
 block discarded – undo
2386 2507
 			{
2387 2508
 				array_pop($open_tags);
2388 2509
 				$code = '</li>';
2510
+			} else {
2511
+							$code = '';
2389 2512
 			}
2390
-			else
2391
-				$code = '';
2392 2513
 
2393 2514
 			// Now we open a new tag.
2394 2515
 			$open_tags[] = array(
@@ -2435,12 +2556,14 @@  discard block
 block discarded – undo
2435 2556
 		}
2436 2557
 
2437 2558
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2438
-		if ($tag === null)
2439
-			continue;
2559
+		if ($tag === null) {
2560
+					continue;
2561
+		}
2440 2562
 
2441 2563
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2442
-		if (isset($inside['disallow_children']))
2443
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2564
+		if (isset($inside['disallow_children'])) {
2565
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2566
+		}
2444 2567
 
2445 2568
 		// Is this tag disabled?
2446 2569
 		if (isset($disabled[$tag['tag']]))
@@ -2450,14 +2573,13 @@  discard block
 block discarded – undo
2450 2573
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2451 2574
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2452 2575
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2453
-			}
2454
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2576
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2455 2577
 			{
2456 2578
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2457 2579
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2580
+			} else {
2581
+							$tag['content'] = $tag['disabled_content'];
2458 2582
 			}
2459
-			else
2460
-				$tag['content'] = $tag['disabled_content'];
2461 2583
 		}
2462 2584
 
2463 2585
 		// we use this a lot
@@ -2467,8 +2589,9 @@  discard block
 block discarded – undo
2467 2589
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2468 2590
 		{
2469 2591
 			$n = count($open_tags) - 1;
2470
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2471
-				$n--;
2592
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2593
+							$n--;
2594
+			}
2472 2595
 
2473 2596
 			// Close all the non block level tags so this tag isn't surrounded by them.
2474 2597
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2480,12 +2603,15 @@  discard block
 block discarded – undo
2480 2603
 
2481 2604
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2482 2605
 				$whitespace_regex = '';
2483
-				if (!empty($tag['block_level']))
2484
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2485
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2486
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2487
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2488
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2606
+				if (!empty($tag['block_level'])) {
2607
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2608
+				}
2609
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2610
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2611
+				}
2612
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2613
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2614
+				}
2489 2615
 
2490 2616
 				array_pop($open_tags);
2491 2617
 			}
@@ -2503,16 +2629,19 @@  discard block
 block discarded – undo
2503 2629
 		elseif ($tag['type'] == 'unparsed_content')
2504 2630
 		{
2505 2631
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2506
-			if ($pos2 === false)
2507
-				continue;
2632
+			if ($pos2 === false) {
2633
+							continue;
2634
+			}
2508 2635
 
2509 2636
 			$data = substr($message, $pos1, $pos2 - $pos1);
2510 2637
 
2511
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2512
-				$data = substr($data, 4);
2638
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2639
+							$data = substr($data, 4);
2640
+			}
2513 2641
 
2514
-			if (isset($tag['validate']))
2515
-				$tag['validate']($tag, $data, $disabled, $params);
2642
+			if (isset($tag['validate'])) {
2643
+							$tag['validate']($tag, $data, $disabled, $params);
2644
+			}
2516 2645
 
2517 2646
 			$code = strtr($tag['content'], array('$1' => $data));
2518 2647
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2528,34 +2657,40 @@  discard block
 block discarded – undo
2528 2657
 			if (isset($tag['quoted']))
2529 2658
 			{
2530 2659
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2531
-				if ($tag['quoted'] != 'optional' && !$quoted)
2532
-					continue;
2660
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2661
+									continue;
2662
+				}
2533 2663
 
2534
-				if ($quoted)
2535
-					$pos1 += 6;
2664
+				if ($quoted) {
2665
+									$pos1 += 6;
2666
+				}
2667
+			} else {
2668
+							$quoted = false;
2536 2669
 			}
2537
-			else
2538
-				$quoted = false;
2539 2670
 
2540 2671
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2541
-			if ($pos2 === false)
2542
-				continue;
2672
+			if ($pos2 === false) {
2673
+							continue;
2674
+			}
2543 2675
 
2544 2676
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2545
-			if ($pos3 === false)
2546
-				continue;
2677
+			if ($pos3 === false) {
2678
+							continue;
2679
+			}
2547 2680
 
2548 2681
 			$data = array(
2549 2682
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2550 2683
 				substr($message, $pos1, $pos2 - $pos1)
2551 2684
 			);
2552 2685
 
2553
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2554
-				$data[0] = substr($data[0], 4);
2686
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2687
+							$data[0] = substr($data[0], 4);
2688
+			}
2555 2689
 
2556 2690
 			// Validation for my parking, please!
2557
-			if (isset($tag['validate']))
2558
-				$tag['validate']($tag, $data, $disabled, $params);
2691
+			if (isset($tag['validate'])) {
2692
+							$tag['validate']($tag, $data, $disabled, $params);
2693
+			}
2559 2694
 
2560 2695
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2561 2696
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2572,23 +2707,27 @@  discard block
 block discarded – undo
2572 2707
 		elseif ($tag['type'] == 'unparsed_commas_content')
2573 2708
 		{
2574 2709
 			$pos2 = strpos($message, ']', $pos1);
2575
-			if ($pos2 === false)
2576
-				continue;
2710
+			if ($pos2 === false) {
2711
+							continue;
2712
+			}
2577 2713
 
2578 2714
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2579
-			if ($pos3 === false)
2580
-				continue;
2715
+			if ($pos3 === false) {
2716
+							continue;
2717
+			}
2581 2718
 
2582 2719
 			// We want $1 to be the content, and the rest to be csv.
2583 2720
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2584 2721
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2585 2722
 
2586
-			if (isset($tag['validate']))
2587
-				$tag['validate']($tag, $data, $disabled, $params);
2723
+			if (isset($tag['validate'])) {
2724
+							$tag['validate']($tag, $data, $disabled, $params);
2725
+			}
2588 2726
 
2589 2727
 			$code = $tag['content'];
2590
-			foreach ($data as $k => $d)
2591
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2728
+			foreach ($data as $k => $d) {
2729
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2730
+			}
2592 2731
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2593 2732
 			$pos += strlen($code) - 1 + 2;
2594 2733
 		}
@@ -2596,24 +2735,28 @@  discard block
 block discarded – undo
2596 2735
 		elseif ($tag['type'] == 'unparsed_commas')
2597 2736
 		{
2598 2737
 			$pos2 = strpos($message, ']', $pos1);
2599
-			if ($pos2 === false)
2600
-				continue;
2738
+			if ($pos2 === false) {
2739
+							continue;
2740
+			}
2601 2741
 
2602 2742
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2603 2743
 
2604
-			if (isset($tag['validate']))
2605
-				$tag['validate']($tag, $data, $disabled, $params);
2744
+			if (isset($tag['validate'])) {
2745
+							$tag['validate']($tag, $data, $disabled, $params);
2746
+			}
2606 2747
 
2607 2748
 			// Fix after, for disabled code mainly.
2608
-			foreach ($data as $k => $d)
2609
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2749
+			foreach ($data as $k => $d) {
2750
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2751
+			}
2610 2752
 
2611 2753
 			$open_tags[] = $tag;
2612 2754
 
2613 2755
 			// Replace them out, $1, $2, $3, $4, etc.
2614 2756
 			$code = $tag['before'];
2615
-			foreach ($data as $k => $d)
2616
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2757
+			foreach ($data as $k => $d) {
2758
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2759
+			}
2617 2760
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2618 2761
 			$pos += strlen($code) - 1 + 2;
2619 2762
 		}
@@ -2624,28 +2767,33 @@  discard block
 block discarded – undo
2624 2767
 			if (isset($tag['quoted']))
2625 2768
 			{
2626 2769
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2627
-				if ($tag['quoted'] != 'optional' && !$quoted)
2628
-					continue;
2770
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2771
+									continue;
2772
+				}
2629 2773
 
2630
-				if ($quoted)
2631
-					$pos1 += 6;
2774
+				if ($quoted) {
2775
+									$pos1 += 6;
2776
+				}
2777
+			} else {
2778
+							$quoted = false;
2632 2779
 			}
2633
-			else
2634
-				$quoted = false;
2635 2780
 
2636 2781
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2637
-			if ($pos2 === false)
2638
-				continue;
2782
+			if ($pos2 === false) {
2783
+							continue;
2784
+			}
2639 2785
 
2640 2786
 			$data = substr($message, $pos1, $pos2 - $pos1);
2641 2787
 
2642 2788
 			// Validation for my parking, please!
2643
-			if (isset($tag['validate']))
2644
-				$tag['validate']($tag, $data, $disabled, $params);
2789
+			if (isset($tag['validate'])) {
2790
+							$tag['validate']($tag, $data, $disabled, $params);
2791
+			}
2645 2792
 
2646 2793
 			// For parsed content, we must recurse to avoid security problems.
2647
-			if ($tag['type'] != 'unparsed_equals')
2648
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2794
+			if ($tag['type'] != 'unparsed_equals') {
2795
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2796
+			}
2649 2797
 
2650 2798
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2651 2799
 
@@ -2657,34 +2805,40 @@  discard block
 block discarded – undo
2657 2805
 		}
2658 2806
 
2659 2807
 		// If this is block level, eat any breaks after it.
2660
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2661
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2808
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2809
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2810
+		}
2662 2811
 
2663 2812
 		// Are we trimming outside this tag?
2664
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2665
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2813
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2814
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2815
+		}
2666 2816
 	}
2667 2817
 
2668 2818
 	// Close any remaining tags.
2669
-	while ($tag = array_pop($open_tags))
2670
-		$message .= "\n" . $tag['after'] . "\n";
2819
+	while ($tag = array_pop($open_tags)) {
2820
+			$message .= "\n" . $tag['after'] . "\n";
2821
+	}
2671 2822
 
2672 2823
 	// Parse the smileys within the parts where it can be done safely.
2673 2824
 	if ($smileys === true)
2674 2825
 	{
2675 2826
 		$message_parts = explode("\n", $message);
2676
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2677
-			parsesmileys($message_parts[$i]);
2827
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2828
+					parsesmileys($message_parts[$i]);
2829
+		}
2678 2830
 
2679 2831
 		$message = implode('', $message_parts);
2680 2832
 	}
2681 2833
 
2682 2834
 	// No smileys, just get rid of the markers.
2683
-	else
2684
-		$message = strtr($message, array("\n" => ''));
2835
+	else {
2836
+			$message = strtr($message, array("\n" => ''));
2837
+	}
2685 2838
 
2686
-	if ($message !== '' && $message[0] === ' ')
2687
-		$message = '&nbsp;' . substr($message, 1);
2839
+	if ($message !== '' && $message[0] === ' ') {
2840
+			$message = '&nbsp;' . substr($message, 1);
2841
+	}
2688 2842
 
2689 2843
 	// Cleanup whitespace.
2690 2844
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2693,15 +2847,16 @@  discard block
 block discarded – undo
2693 2847
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2694 2848
 
2695 2849
 	// Cache the output if it took some time...
2696
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2697
-		cache_put_data($cache_key, $message, 240);
2850
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2851
+			cache_put_data($cache_key, $message, 240);
2852
+	}
2698 2853
 
2699 2854
 	// If this was a force parse revert if needed.
2700 2855
 	if (!empty($parse_tags))
2701 2856
 	{
2702
-		if (empty($temp_bbc))
2703
-			$bbc_codes = array();
2704
-		else
2857
+		if (empty($temp_bbc)) {
2858
+					$bbc_codes = array();
2859
+		} else
2705 2860
 		{
2706 2861
 			$bbc_codes = $temp_bbc;
2707 2862
 			unset($temp_bbc);
@@ -2728,8 +2883,9 @@  discard block
 block discarded – undo
2728 2883
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2729 2884
 
2730 2885
 	// No smiley set at all?!
2731
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2732
-		return;
2886
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2887
+			return;
2888
+	}
2733 2889
 
2734 2890
 	// If smileyPregSearch hasn't been set, do it now.
2735 2891
 	if (empty($smileyPregSearch))
@@ -2740,8 +2896,7 @@  discard block
 block discarded – undo
2740 2896
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2741 2897
 			$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');
2742 2898
 			$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'], '', '', '', '');
2743
-		}
2744
-		else
2899
+		} else
2745 2900
 		{
2746 2901
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2747 2902
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2765,9 +2920,9 @@  discard block
 block discarded – undo
2765 2920
 				$smcFunc['db_free_result']($result);
2766 2921
 
2767 2922
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2923
+			} else {
2924
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2768 2925
 			}
2769
-			else
2770
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2771 2926
 		}
2772 2927
 
2773 2928
 		// The non-breaking-space is a complex thing...
@@ -2844,35 +2999,41 @@  discard block
 block discarded – undo
2844 2999
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2845 3000
 
2846 3001
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2847
-	if (!empty($context['flush_mail']))
2848
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3002
+	if (!empty($context['flush_mail'])) {
3003
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2849 3004
 		AddMailQueue(true);
3005
+	}
2850 3006
 
2851 3007
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2852 3008
 
2853
-	if ($add)
2854
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3009
+	if ($add) {
3010
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3011
+	}
2855 3012
 
2856 3013
 	// Put the session ID in.
2857
-	if (defined('SID') && SID != '')
2858
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3014
+	if (defined('SID') && SID != '') {
3015
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3016
+	}
2859 3017
 	// Keep that debug in their for template debugging!
2860
-	elseif (isset($_GET['debug']))
2861
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3018
+	elseif (isset($_GET['debug'])) {
3019
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3020
+	}
2862 3021
 
2863 3022
 	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'])))
2864 3023
 	{
2865
-		if (defined('SID') && SID != '')
2866
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3024
+		if (defined('SID') && SID != '') {
3025
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2867 3026
 				function ($m) use ($scripturl)
2868 3027
 				{
2869 3028
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3029
+		}
2870 3030
 				}, $setLocation);
2871
-		else
2872
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3031
+		else {
3032
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2873 3033
 				function ($m) use ($scripturl)
2874 3034
 				{
2875 3035
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3036
+		}
2876 3037
 				}, $setLocation);
2877 3038
 	}
2878 3039
 
@@ -2883,8 +3044,9 @@  discard block
 block discarded – undo
2883 3044
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2884 3045
 
2885 3046
 	// Debugging.
2886
-	if (isset($db_show_debug) && $db_show_debug === true)
2887
-		$_SESSION['debug_redirect'] = $db_cache;
3047
+	if (isset($db_show_debug) && $db_show_debug === true) {
3048
+			$_SESSION['debug_redirect'] = $db_cache;
3049
+	}
2888 3050
 
2889 3051
 	obExit(false);
2890 3052
 }
@@ -2903,51 +3065,60 @@  discard block
 block discarded – undo
2903 3065
 
2904 3066
 	// Attempt to prevent a recursive loop.
2905 3067
 	++$level;
2906
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2907
-		exit;
2908
-	if ($from_fatal_error)
2909
-		$has_fatal_error = true;
3068
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3069
+			exit;
3070
+	}
3071
+	if ($from_fatal_error) {
3072
+			$has_fatal_error = true;
3073
+	}
2910 3074
 
2911 3075
 	// Clear out the stat cache.
2912 3076
 	trackStats();
2913 3077
 
2914 3078
 	// If we have mail to send, send it.
2915
-	if (!empty($context['flush_mail']))
2916
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3079
+	if (!empty($context['flush_mail'])) {
3080
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2917 3081
 		AddMailQueue(true);
3082
+	}
2918 3083
 
2919 3084
 	$do_header = $header === null ? !$header_done : $header;
2920
-	if ($do_footer === null)
2921
-		$do_footer = $do_header;
3085
+	if ($do_footer === null) {
3086
+			$do_footer = $do_header;
3087
+	}
2922 3088
 
2923 3089
 	// Has the template/header been done yet?
2924 3090
 	if ($do_header)
2925 3091
 	{
2926 3092
 		// Was the page title set last minute? Also update the HTML safe one.
2927
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2928
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3093
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3094
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3095
+		}
2929 3096
 
2930 3097
 		// Start up the session URL fixer.
2931 3098
 		ob_start('ob_sessrewrite');
2932 3099
 
2933
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2934
-			$buffers = explode(',', $settings['output_buffers']);
2935
-		elseif (!empty($settings['output_buffers']))
2936
-			$buffers = $settings['output_buffers'];
2937
-		else
2938
-			$buffers = array();
3100
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3101
+					$buffers = explode(',', $settings['output_buffers']);
3102
+		} elseif (!empty($settings['output_buffers'])) {
3103
+					$buffers = $settings['output_buffers'];
3104
+		} else {
3105
+					$buffers = array();
3106
+		}
2939 3107
 
2940
-		if (isset($modSettings['integrate_buffer']))
2941
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3108
+		if (isset($modSettings['integrate_buffer'])) {
3109
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3110
+		}
2942 3111
 
2943
-		if (!empty($buffers))
2944
-			foreach ($buffers as $function)
3112
+		if (!empty($buffers)) {
3113
+					foreach ($buffers as $function)
2945 3114
 			{
2946 3115
 				$call = call_helper($function, true);
3116
+		}
2947 3117
 
2948 3118
 				// Is it valid?
2949
-				if (!empty($call))
2950
-					ob_start($call);
3119
+				if (!empty($call)) {
3120
+									ob_start($call);
3121
+				}
2951 3122
 			}
2952 3123
 
2953 3124
 		// Display the screen in the logical order.
@@ -2959,8 +3130,9 @@  discard block
 block discarded – undo
2959 3130
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2960 3131
 
2961 3132
 		// Anything special to put out?
2962
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2963
-			echo $context['insert_after_template'];
3133
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3134
+					echo $context['insert_after_template'];
3135
+		}
2964 3136
 
2965 3137
 		// Just so we don't get caught in an endless loop of errors from the footer...
2966 3138
 		if (!$footer_done)
@@ -2969,14 +3141,16 @@  discard block
 block discarded – undo
2969 3141
 			template_footer();
2970 3142
 
2971 3143
 			// (since this is just debugging... it's okay that it's after </html>.)
2972
-			if (!isset($_REQUEST['xml']))
2973
-				displayDebug();
3144
+			if (!isset($_REQUEST['xml'])) {
3145
+							displayDebug();
3146
+			}
2974 3147
 		}
2975 3148
 	}
2976 3149
 
2977 3150
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2978
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2979
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3151
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3152
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3153
+	}
2980 3154
 
2981 3155
 	// For session check verification.... don't switch browsers...
2982 3156
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2985,9 +3159,10 @@  discard block
 block discarded – undo
2985 3159
 	call_integration_hook('integrate_exit', array($do_footer));
2986 3160
 
2987 3161
 	// Don't exit if we're coming from index.php; that will pass through normally.
2988
-	if (!$from_index)
2989
-		exit;
2990
-}
3162
+	if (!$from_index) {
3163
+			exit;
3164
+	}
3165
+	}
2991 3166
 
2992 3167
 /**
2993 3168
  * Get the size of a specified image with better error handling.
@@ -3006,8 +3181,9 @@  discard block
 block discarded – undo
3006 3181
 	$url = str_replace(' ', '%20', $url);
3007 3182
 
3008 3183
 	// Can we pull this from the cache... please please?
3009
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3010
-		return $temp;
3184
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3185
+			return $temp;
3186
+	}
3011 3187
 	$t = microtime();
3012 3188
 
3013 3189
 	// Get the host to pester...
@@ -3017,12 +3193,10 @@  discard block
 block discarded – undo
3017 3193
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3018 3194
 	{
3019 3195
 		return false;
3020
-	}
3021
-	elseif (!isset($match[1]))
3196
+	} elseif (!isset($match[1]))
3022 3197
 	{
3023 3198
 		$size = @getimagesize($url);
3024
-	}
3025
-	else
3199
+	} else
3026 3200
 	{
3027 3201
 		// Try to connect to the server... give it half a second.
3028 3202
 		$temp = 0;
@@ -3061,12 +3235,14 @@  discard block
 block discarded – undo
3061 3235
 	}
3062 3236
 
3063 3237
 	// If we didn't get it, we failed.
3064
-	if (!isset($size))
3065
-		$size = false;
3238
+	if (!isset($size)) {
3239
+			$size = false;
3240
+	}
3066 3241
 
3067 3242
 	// If this took a long time, we may never have to do it again, but then again we might...
3068
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3069
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3243
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3244
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3245
+	}
3070 3246
 
3071 3247
 	// Didn't work.
3072 3248
 	return $size;
@@ -3084,8 +3260,9 @@  discard block
 block discarded – undo
3084 3260
 
3085 3261
 	// Under SSI this function can be called more then once.  That can cause some problems.
3086 3262
 	//   So only run the function once unless we are forced to run it again.
3087
-	if ($loaded && !$forceload)
3088
-		return;
3263
+	if ($loaded && !$forceload) {
3264
+			return;
3265
+	}
3089 3266
 
3090 3267
 	$loaded = true;
3091 3268
 
@@ -3097,14 +3274,16 @@  discard block
 block discarded – undo
3097 3274
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3098 3275
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3099 3276
 	{
3100
-		if (trim($context['news_lines'][$i]) == '')
3101
-			continue;
3277
+		if (trim($context['news_lines'][$i]) == '') {
3278
+					continue;
3279
+		}
3102 3280
 
3103 3281
 		// Clean it up for presentation ;).
3104 3282
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3105 3283
 	}
3106
-	if (!empty($context['news_lines']))
3107
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3284
+	if (!empty($context['news_lines'])) {
3285
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3286
+	}
3108 3287
 
3109 3288
 	if (!$user_info['is_guest'])
3110 3289
 	{
@@ -3113,40 +3292,48 @@  discard block
 block discarded – undo
3113 3292
 		$context['user']['alerts'] = &$user_info['alerts'];
3114 3293
 
3115 3294
 		// Personal message popup...
3116
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3117
-			$context['user']['popup_messages'] = true;
3118
-		else
3119
-			$context['user']['popup_messages'] = false;
3295
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3296
+					$context['user']['popup_messages'] = true;
3297
+		} else {
3298
+					$context['user']['popup_messages'] = false;
3299
+		}
3120 3300
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3121 3301
 
3122
-		if (allowedTo('moderate_forum'))
3123
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3302
+		if (allowedTo('moderate_forum')) {
3303
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3304
+		}
3124 3305
 
3125 3306
 		$context['user']['avatar'] = array();
3126 3307
 
3127 3308
 		// Check for gravatar first since we might be forcing them...
3128 3309
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3129 3310
 		{
3130
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3131
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3132
-			else
3133
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3311
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3312
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3313
+			} else {
3314
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3315
+			}
3134 3316
 		}
3135 3317
 		// Uploaded?
3136
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3137
-			$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';
3318
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3319
+					$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';
3320
+		}
3138 3321
 		// Full URL?
3139
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3140
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3322
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3323
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3324
+		}
3141 3325
 		// Otherwise we assume it's server stored.
3142
-		elseif ($user_info['avatar']['url'] != '')
3143
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3326
+		elseif ($user_info['avatar']['url'] != '') {
3327
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3328
+		}
3144 3329
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3145
-		else
3146
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3330
+		else {
3331
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3332
+		}
3147 3333
 
3148
-		if (!empty($context['user']['avatar']))
3149
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3334
+		if (!empty($context['user']['avatar'])) {
3335
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3336
+		}
3150 3337
 
3151 3338
 		// Figure out how long they've been logged in.
3152 3339
 		$context['user']['total_time_logged_in'] = array(
@@ -3154,8 +3341,7 @@  discard block
 block discarded – undo
3154 3341
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3155 3342
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3156 3343
 		);
3157
-	}
3158
-	else
3344
+	} else
3159 3345
 	{
3160 3346
 		$context['user']['messages'] = 0;
3161 3347
 		$context['user']['unread_messages'] = 0;
@@ -3163,12 +3349,14 @@  discard block
 block discarded – undo
3163 3349
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3164 3350
 		$context['user']['popup_messages'] = false;
3165 3351
 
3166
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3167
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3352
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3353
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3354
+		}
3168 3355
 
3169 3356
 		// If we've upgraded recently, go easy on the passwords.
3170
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3171
-			$context['disable_login_hashing'] = true;
3357
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3358
+					$context['disable_login_hashing'] = true;
3359
+		}
3172 3360
 	}
3173 3361
 
3174 3362
 	// Setup the main menu items.
@@ -3181,8 +3369,8 @@  discard block
 block discarded – undo
3181 3369
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3182 3370
 
3183 3371
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3184
-	if ($context['show_pm_popup'])
3185
-		addInlineJavaScript('
3372
+	if ($context['show_pm_popup']) {
3373
+			addInlineJavaScript('
3186 3374
 		jQuery(document).ready(function($) {
3187 3375
 			new smc_Popup({
3188 3376
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3190,15 +3378,17 @@  discard block
 block discarded – undo
3190 3378
 				icon_class: \'generic_icons mail_new\'
3191 3379
 			});
3192 3380
 		});');
3381
+	}
3193 3382
 
3194 3383
 	// Add a generic "Are you sure?" confirmation message.
3195 3384
 	addInlineJavaScript('
3196 3385
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3197 3386
 
3198 3387
 	// Now add the capping code for avatars.
3199
-	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')
3200
-		addInlineCss('
3388
+	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') {
3389
+			addInlineCss('
3201 3390
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3391
+	}
3202 3392
 
3203 3393
 	// This looks weird, but it's because BoardIndex.php references the variable.
3204 3394
 	$context['common_stats']['latest_member'] = array(
@@ -3215,11 +3405,13 @@  discard block
 block discarded – undo
3215 3405
 	);
3216 3406
 	$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']);
3217 3407
 
3218
-	if (empty($settings['theme_version']))
3219
-		addJavaScriptVar('smf_scripturl', $scripturl);
3408
+	if (empty($settings['theme_version'])) {
3409
+			addJavaScriptVar('smf_scripturl', $scripturl);
3410
+	}
3220 3411
 
3221
-	if (!isset($context['page_title']))
3222
-		$context['page_title'] = '';
3412
+	if (!isset($context['page_title'])) {
3413
+			$context['page_title'] = '';
3414
+	}
3223 3415
 
3224 3416
 	// Set some specific vars.
3225 3417
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3229,21 +3421,23 @@  discard block
 block discarded – undo
3229 3421
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3230 3422
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3231 3423
 
3232
-	if (!empty($context['meta_keywords']))
3233
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3424
+	if (!empty($context['meta_keywords'])) {
3425
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3426
+	}
3234 3427
 
3235
-	if (!empty($context['canonical_url']))
3236
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3428
+	if (!empty($context['canonical_url'])) {
3429
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3430
+	}
3237 3431
 
3238
-	if (!empty($settings['og_image']))
3239
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3432
+	if (!empty($settings['og_image'])) {
3433
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3434
+	}
3240 3435
 
3241 3436
 	if (!empty($context['meta_description']))
3242 3437
 	{
3243 3438
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3244 3439
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3245
-	}
3246
-	else
3440
+	} else
3247 3441
 	{
3248 3442
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3249 3443
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3268,8 +3462,9 @@  discard block
 block discarded – undo
3268 3462
 	$memory_needed = memoryReturnBytes($needed);
3269 3463
 
3270 3464
 	// should we account for how much is currently being used?
3271
-	if ($in_use)
3272
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3465
+	if ($in_use) {
3466
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3467
+	}
3273 3468
 
3274 3469
 	// if more is needed, request it
3275 3470
 	if ($memory_current < $memory_needed)
@@ -3292,8 +3487,9 @@  discard block
 block discarded – undo
3292 3487
  */
3293 3488
 function memoryReturnBytes($val)
3294 3489
 {
3295
-	if (is_integer($val))
3296
-		return $val;
3490
+	if (is_integer($val)) {
3491
+			return $val;
3492
+	}
3297 3493
 
3298 3494
 	// Separate the number from the designator
3299 3495
 	$val = trim($val);
@@ -3329,10 +3525,11 @@  discard block
 block discarded – undo
3329 3525
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3330 3526
 
3331 3527
 		// Are we debugging the template/html content?
3332
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3333
-			header('Content-Type: application/xhtml+xml');
3334
-		elseif (!isset($_REQUEST['xml']))
3335
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3528
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3529
+					header('Content-Type: application/xhtml+xml');
3530
+		} elseif (!isset($_REQUEST['xml'])) {
3531
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3532
+		}
3336 3533
 	}
3337 3534
 
3338 3535
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3341,8 +3538,9 @@  discard block
 block discarded – undo
3341 3538
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3342 3539
 	{
3343 3540
 		$position = array_search('body', $context['template_layers']);
3344
-		if ($position === false)
3345
-			$position = array_search('main', $context['template_layers']);
3541
+		if ($position === false) {
3542
+					$position = array_search('main', $context['template_layers']);
3543
+		}
3346 3544
 
3347 3545
 		if ($position !== false)
3348 3546
 		{
@@ -3370,23 +3568,25 @@  discard block
 block discarded – undo
3370 3568
 
3371 3569
 			foreach ($securityFiles as $i => $securityFile)
3372 3570
 			{
3373
-				if (!file_exists($boarddir . '/' . $securityFile))
3374
-					unset($securityFiles[$i]);
3571
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3572
+									unset($securityFiles[$i]);
3573
+				}
3375 3574
 			}
3376 3575
 
3377 3576
 			// We are already checking so many files...just few more doesn't make any difference! :P
3378
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3379
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3380
-
3381
-			else
3382
-				$path = $modSettings['attachmentUploadDir'];
3577
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3578
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3579
+			} else {
3580
+							$path = $modSettings['attachmentUploadDir'];
3581
+			}
3383 3582
 
3384 3583
 			secureDirectory($path, true);
3385 3584
 			secureDirectory($cachedir);
3386 3585
 
3387 3586
 			// If agreement is enabled, at least the english version shall exists
3388
-			if ($modSettings['requireAgreement'])
3389
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3587
+			if ($modSettings['requireAgreement']) {
3588
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3589
+			}
3390 3590
 
3391 3591
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3392 3592
 			{
@@ -3401,18 +3601,21 @@  discard block
 block discarded – undo
3401 3601
 					echo '
3402 3602
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3403 3603
 
3404
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3405
-						echo '
3604
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3605
+											echo '
3406 3606
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3607
+					}
3407 3608
 				}
3408 3609
 
3409
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3410
-					echo '
3610
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3611
+									echo '
3411 3612
 				<strong>', $txt['cache_writable'], '</strong><br>';
3613
+				}
3412 3614
 
3413
-				if (!empty($agreement))
3414
-					echo '
3615
+				if (!empty($agreement)) {
3616
+									echo '
3415 3617
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3618
+				}
3416 3619
 
3417 3620
 				echo '
3418 3621
 			</p>
@@ -3427,16 +3630,18 @@  discard block
 block discarded – undo
3427 3630
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3428 3631
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3429 3632
 
3430
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3431
-				echo '
3633
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3634
+							echo '
3432 3635
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3636
+			}
3433 3637
 
3434
-			if (!empty($_SESSION['ban']['expire_time']))
3435
-				echo '
3638
+			if (!empty($_SESSION['ban']['expire_time'])) {
3639
+							echo '
3436 3640
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3437
-			else
3438
-				echo '
3641
+			} else {
3642
+							echo '
3439 3643
 					<div>', $txt['your_ban_expires_never'], '</div>';
3644
+			}
3440 3645
 
3441 3646
 			echo '
3442 3647
 				</div>';
@@ -3452,8 +3657,9 @@  discard block
 block discarded – undo
3452 3657
 	global $forum_copyright, $software_year, $forum_version;
3453 3658
 
3454 3659
 	// Don't display copyright for things like SSI.
3455
-	if (!isset($forum_version) || !isset($software_year))
3456
-		return;
3660
+	if (!isset($forum_version) || !isset($software_year)) {
3661
+			return;
3662
+	}
3457 3663
 
3458 3664
 	// Put in the version...
3459 3665
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3471,9 +3677,10 @@  discard block
 block discarded – undo
3471 3677
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3472 3678
 	$context['load_queries'] = $db_count;
3473 3679
 
3474
-	foreach (array_reverse($context['template_layers']) as $layer)
3475
-		loadSubTemplate($layer . '_below', true);
3476
-}
3680
+	foreach (array_reverse($context['template_layers']) as $layer) {
3681
+			loadSubTemplate($layer . '_below', true);
3682
+	}
3683
+	}
3477 3684
 
3478 3685
 /**
3479 3686
  * Output the Javascript files
@@ -3504,8 +3711,7 @@  discard block
 block discarded – undo
3504 3711
 			{
3505 3712
 				echo '
3506 3713
 		var ', $key, ';';
3507
-			}
3508
-			else
3714
+			} else
3509 3715
 			{
3510 3716
 				echo '
3511 3717
 		var ', $key, ' = ', $value, ';';
@@ -3520,26 +3726,27 @@  discard block
 block discarded – undo
3520 3726
 	foreach ($context['javascript_files'] as $id => $js_file)
3521 3727
 	{
3522 3728
 		// Last minute call! allow theme authors to disable single files.
3523
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3524
-			continue;
3729
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3730
+					continue;
3731
+		}
3525 3732
 
3526 3733
 		// By default all files don't get minimized unless the file explicitly says so!
3527 3734
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3528 3735
 		{
3529
-			if ($do_deferred && !empty($js_file['options']['defer']))
3530
-				$toMinifyDefer[] = $js_file;
3531
-
3532
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3533
-				$toMinify[] = $js_file;
3736
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3737
+							$toMinifyDefer[] = $js_file;
3738
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3739
+							$toMinify[] = $js_file;
3740
+			}
3534 3741
 
3535 3742
 			// Grab a random seed.
3536
-			if (!isset($minSeed))
3537
-				$minSeed = $js_file['options']['seed'];
3538
-		}
3539
-
3540
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3541
-			echo '
3743
+			if (!isset($minSeed)) {
3744
+							$minSeed = $js_file['options']['seed'];
3745
+			}
3746
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3747
+					echo '
3542 3748
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3749
+		}
3543 3750
 	}
3544 3751
 
3545 3752
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3547,14 +3754,14 @@  discard block
 block discarded – undo
3547 3754
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3548 3755
 
3549 3756
 		// Minify process couldn't work, print each individual files.
3550
-		if (!empty($result) && is_array($result))
3551
-			foreach ($result as $minFailedFile)
3757
+		if (!empty($result) && is_array($result)) {
3758
+					foreach ($result as $minFailedFile)
3552 3759
 				echo '
3553 3760
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3554
-
3555
-		else
3556
-			echo '
3761
+		} else {
3762
+					echo '
3557 3763
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3764
+		}
3558 3765
 	}
3559 3766
 
3560 3767
 	// Inline JavaScript - Actually useful some times!
@@ -3565,8 +3772,9 @@  discard block
 block discarded – undo
3565 3772
 			echo '
3566 3773
 <script>';
3567 3774
 
3568
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3569
-				echo $js_code;
3775
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3776
+							echo $js_code;
3777
+			}
3570 3778
 
3571 3779
 			echo '
3572 3780
 </script>';
@@ -3577,8 +3785,9 @@  discard block
 block discarded – undo
3577 3785
 			echo '
3578 3786
 	<script>';
3579 3787
 
3580
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3581
-				echo $js_code;
3788
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3789
+							echo $js_code;
3790
+			}
3582 3791
 
3583 3792
 			echo '
3584 3793
 	</script>';
@@ -3603,8 +3812,9 @@  discard block
 block discarded – undo
3603 3812
 	foreach ($context['css_files'] as $id => $file)
3604 3813
 	{
3605 3814
 		// Last minute call! allow theme authors to disable single files.
3606
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3607
-			continue;
3815
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3816
+					continue;
3817
+		}
3608 3818
 
3609 3819
 		// By default all files don't get minimized unless the file explicitly says so!
3610 3820
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3612,12 +3822,12 @@  discard block
 block discarded – undo
3612 3822
 			$toMinify[] = $file;
3613 3823
 
3614 3824
 			// Grab a random seed.
3615
-			if (!isset($minSeed))
3616
-				$minSeed = $file['options']['seed'];
3825
+			if (!isset($minSeed)) {
3826
+							$minSeed = $file['options']['seed'];
3827
+			}
3828
+		} else {
3829
+					$normal[] = $file['fileUrl'];
3617 3830
 		}
3618
-
3619
-		else
3620
-			$normal[] = $file['fileUrl'];
3621 3831
 	}
3622 3832
 
3623 3833
 	if (!empty($toMinify))
@@ -3625,28 +3835,30 @@  discard block
 block discarded – undo
3625 3835
 		$result = custMinify($toMinify, 'css');
3626 3836
 
3627 3837
 		// Minify process couldn't work, print each individual files.
3628
-		if (!empty($result) && is_array($result))
3629
-			foreach ($result as $minFailedFile)
3838
+		if (!empty($result) && is_array($result)) {
3839
+					foreach ($result as $minFailedFile)
3630 3840
 				echo '
3631 3841
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3632
-
3633
-		else
3634
-			echo '
3842
+		} else {
3843
+					echo '
3635 3844
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3845
+		}
3636 3846
 	}
3637 3847
 
3638 3848
 	// Print the rest after the minified files.
3639
-	if (!empty($normal))
3640
-		foreach ($normal as $nf)
3849
+	if (!empty($normal)) {
3850
+			foreach ($normal as $nf)
3641 3851
 			echo '
3642 3852
 	<link rel="stylesheet" href="', $nf ,'">';
3853
+	}
3643 3854
 
3644 3855
 	if ($db_show_debug === true)
3645 3856
 	{
3646 3857
 		// Try to keep only what's useful.
3647 3858
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3648
-		foreach ($context['css_files'] as $file)
3649
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3859
+		foreach ($context['css_files'] as $file) {
3860
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3861
+		}
3650 3862
 	}
3651 3863
 
3652 3864
 	if (!empty($context['css_header']))
@@ -3654,9 +3866,10 @@  discard block
 block discarded – undo
3654 3866
 		echo '
3655 3867
 	<style>';
3656 3868
 
3657
-		foreach ($context['css_header'] as $css)
3658
-			echo $css .'
3869
+		foreach ($context['css_header'] as $css) {
3870
+					echo $css .'
3659 3871
 	';
3872
+		}
3660 3873
 
3661 3874
 		echo'
3662 3875
 	</style>';
@@ -3680,15 +3893,17 @@  discard block
 block discarded – undo
3680 3893
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3681 3894
 	$data = !empty($data) ? $data : false;
3682 3895
 
3683
-	if (empty($type) || empty($data))
3684
-		return false;
3896
+	if (empty($type) || empty($data)) {
3897
+			return false;
3898
+	}
3685 3899
 
3686 3900
 	// Did we already did this?
3687 3901
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3688 3902
 
3689 3903
 	// Already done?
3690
-	if (!empty($toCache))
3691
-		return true;
3904
+	if (!empty($toCache)) {
3905
+			return true;
3906
+	}
3692 3907
 
3693 3908
 	// No namespaces, sorry!
3694 3909
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3770,8 +3985,9 @@  discard block
 block discarded – undo
3770 3985
 	global $modSettings, $smcFunc;
3771 3986
 
3772 3987
 	// Just make up a nice hash...
3773
-	if ($new)
3774
-		return sha1(md5($filename . time()) . mt_rand());
3988
+	if ($new) {
3989
+			return sha1(md5($filename . time()) . mt_rand());
3990
+	}
3775 3991
 
3776 3992
 	// Just make sure that attachment id is only a int
3777 3993
 	$attachment_id = (int) $attachment_id;
@@ -3788,23 +4004,25 @@  discard block
 block discarded – undo
3788 4004
 				'id_attach' => $attachment_id,
3789 4005
 			));
3790 4006
 
3791
-		if ($smcFunc['db_num_rows']($request) === 0)
3792
-			return false;
4007
+		if ($smcFunc['db_num_rows']($request) === 0) {
4008
+					return false;
4009
+		}
3793 4010
 
3794 4011
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3795 4012
 		$smcFunc['db_free_result']($request);
3796 4013
 	}
3797 4014
 
3798 4015
 	// Still no hash? mmm...
3799
-	if (empty($file_hash))
3800
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4016
+	if (empty($file_hash)) {
4017
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4018
+	}
3801 4019
 
3802 4020
 	// Are we using multiple directories?
3803
-	if (is_array($modSettings['attachmentUploadDir']))
3804
-		$path = $modSettings['attachmentUploadDir'][$dir];
3805
-
3806
-	else
3807
-		$path = $modSettings['attachmentUploadDir'];
4021
+	if (is_array($modSettings['attachmentUploadDir'])) {
4022
+			$path = $modSettings['attachmentUploadDir'][$dir];
4023
+	} else {
4024
+			$path = $modSettings['attachmentUploadDir'];
4025
+	}
3808 4026
 
3809 4027
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3810 4028
 }
@@ -3819,8 +4037,9 @@  discard block
 block discarded – undo
3819 4037
 function ip2range($fullip)
3820 4038
 {
3821 4039
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3822
-	if ($fullip == 'unknown')
3823
-		$fullip = '255.255.255.255';
4040
+	if ($fullip == 'unknown') {
4041
+			$fullip = '255.255.255.255';
4042
+	}
3824 4043
 
3825 4044
 	$ip_parts = explode('-', $fullip);
3826 4045
 	$ip_array = array();
@@ -3844,10 +4063,11 @@  discard block
 block discarded – undo
3844 4063
 		$ip_array['low'] = $ip_parts[0];
3845 4064
 		$ip_array['high'] = $ip_parts[1];
3846 4065
 		return $ip_array;
3847
-	}
3848
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4066
+	} elseif (count($ip_parts) == 2) {
4067
+		// if ip 22.22.*-22.22.*
3849 4068
 	{
3850 4069
 		$valid_low = isValidIP($ip_parts[0]);
4070
+	}
3851 4071
 		$valid_high = isValidIP($ip_parts[1]);
3852 4072
 		$count = 0;
3853 4073
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3862,7 +4082,9 @@  discard block
 block discarded – undo
3862 4082
 				$ip_parts[0] .= $mode . $min;
3863 4083
 				$valid_low = isValidIP($ip_parts[0]);
3864 4084
 				$count++;
3865
-				if ($count > 9) break;
4085
+				if ($count > 9) {
4086
+					break;
4087
+				}
3866 4088
 			}
3867 4089
 		}
3868 4090
 
@@ -3876,7 +4098,9 @@  discard block
 block discarded – undo
3876 4098
 				$ip_parts[1] .= $mode . $max;
3877 4099
 				$valid_high = isValidIP($ip_parts[1]);
3878 4100
 				$count++;
3879
-				if ($count > 9) break;
4101
+				if ($count > 9) {
4102
+					break;
4103
+				}
3880 4104
 			}
3881 4105
 		}
3882 4106
 
@@ -3901,46 +4125,54 @@  discard block
 block discarded – undo
3901 4125
 {
3902 4126
 	global $modSettings;
3903 4127
 
3904
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3905
-		return $host;
4128
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4129
+			return $host;
4130
+	}
3906 4131
 	$t = microtime();
3907 4132
 
3908 4133
 	// Try the Linux host command, perhaps?
3909 4134
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3910 4135
 	{
3911
-		if (!isset($modSettings['host_to_dis']))
3912
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3913
-		else
3914
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4136
+		if (!isset($modSettings['host_to_dis'])) {
4137
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4138
+		} else {
4139
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4140
+		}
3915 4141
 
3916 4142
 		// Did host say it didn't find anything?
3917
-		if (strpos($test, 'not found') !== false)
3918
-			$host = '';
4143
+		if (strpos($test, 'not found') !== false) {
4144
+					$host = '';
4145
+		}
3919 4146
 		// Invalid server option?
3920
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3921
-			updateSettings(array('host_to_dis' => 1));
4147
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4148
+					updateSettings(array('host_to_dis' => 1));
4149
+		}
3922 4150
 		// Maybe it found something, after all?
3923
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3924
-			$host = $match[1];
4151
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4152
+					$host = $match[1];
4153
+		}
3925 4154
 	}
3926 4155
 
3927 4156
 	// This is nslookup; usually only Windows, but possibly some Unix?
3928 4157
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3929 4158
 	{
3930 4159
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3931
-		if (strpos($test, 'Non-existent domain') !== false)
3932
-			$host = '';
3933
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3934
-			$host = $match[1];
4160
+		if (strpos($test, 'Non-existent domain') !== false) {
4161
+					$host = '';
4162
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4163
+					$host = $match[1];
4164
+		}
3935 4165
 	}
3936 4166
 
3937 4167
 	// This is the last try :/.
3938
-	if (!isset($host) || $host === false)
3939
-		$host = @gethostbyaddr($ip);
4168
+	if (!isset($host) || $host === false) {
4169
+			$host = @gethostbyaddr($ip);
4170
+	}
3940 4171
 
3941 4172
 	// It took a long time, so let's cache it!
3942
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3943
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4173
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4174
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4175
+	}
3944 4176
 
3945 4177
 	return $host;
3946 4178
 }
@@ -3976,20 +4208,21 @@  discard block
 block discarded – undo
3976 4208
 			{
3977 4209
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3978 4210
 				$total = 0;
3979
-				for ($i = 0; $i < $max_chars; $i++)
3980
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4211
+				for ($i = 0; $i < $max_chars; $i++) {
4212
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4213
+				}
3981 4214
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3982 4215
 			}
3983 4216
 		}
3984 4217
 		return array_unique($returned_ints);
3985
-	}
3986
-	else
4218
+	} else
3987 4219
 	{
3988 4220
 		// Trim characters before and after and add slashes for database insertion.
3989 4221
 		$returned_words = array();
3990
-		foreach ($words as $word)
3991
-			if (($word = trim($word, '-_\'')) !== '')
4222
+		foreach ($words as $word) {
4223
+					if (($word = trim($word, '-_\'')) !== '')
3992 4224
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4225
+		}
3993 4226
 
3994 4227
 		// Filter out all words that occur more than once.
3995 4228
 		return array_unique($returned_words);
@@ -4011,16 +4244,18 @@  discard block
 block discarded – undo
4011 4244
 	global $settings, $txt;
4012 4245
 
4013 4246
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4014
-	if (function_exists('template_create_button') && !$force_use)
4015
-		return template_create_button($name, $alt, $label = '', $custom = '');
4247
+	if (function_exists('template_create_button') && !$force_use) {
4248
+			return template_create_button($name, $alt, $label = '', $custom = '');
4249
+	}
4016 4250
 
4017
-	if (!$settings['use_image_buttons'])
4018
-		return $txt[$alt];
4019
-	elseif (!empty($settings['use_buttons']))
4020
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4021
-	else
4022
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4023
-}
4251
+	if (!$settings['use_image_buttons']) {
4252
+			return $txt[$alt];
4253
+	} elseif (!empty($settings['use_buttons'])) {
4254
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4255
+	} else {
4256
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4257
+	}
4258
+	}
4024 4259
 
4025 4260
 /**
4026 4261
  * Sets up all of the top menu buttons
@@ -4063,9 +4298,10 @@  discard block
 block discarded – undo
4063 4298
 	var user_menus = new smc_PopupMenu();
4064 4299
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4065 4300
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4066
-		if ($context['allow_pm'])
4067
-			addInlineJavaScript('
4301
+		if ($context['allow_pm']) {
4302
+					addInlineJavaScript('
4068 4303
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4304
+		}
4069 4305
 
4070 4306
 		if (!empty($modSettings['enable_ajax_alerts']))
4071 4307
 		{
@@ -4225,88 +4461,96 @@  discard block
 block discarded – undo
4225 4461
 
4226 4462
 		// Now we put the buttons in the context so the theme can use them.
4227 4463
 		$menu_buttons = array();
4228
-		foreach ($buttons as $act => $button)
4229
-			if (!empty($button['show']))
4464
+		foreach ($buttons as $act => $button) {
4465
+					if (!empty($button['show']))
4230 4466
 			{
4231 4467
 				$button['active_button'] = false;
4468
+		}
4232 4469
 
4233 4470
 				// This button needs some action.
4234
-				if (isset($button['action_hook']))
4235
-					$needs_action_hook = true;
4471
+				if (isset($button['action_hook'])) {
4472
+									$needs_action_hook = true;
4473
+				}
4236 4474
 
4237 4475
 				// Make sure the last button truly is the last button.
4238 4476
 				if (!empty($button['is_last']))
4239 4477
 				{
4240
-					if (isset($last_button))
4241
-						unset($menu_buttons[$last_button]['is_last']);
4478
+					if (isset($last_button)) {
4479
+											unset($menu_buttons[$last_button]['is_last']);
4480
+					}
4242 4481
 					$last_button = $act;
4243 4482
 				}
4244 4483
 
4245 4484
 				// Go through the sub buttons if there are any.
4246
-				if (!empty($button['sub_buttons']))
4247
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4485
+				if (!empty($button['sub_buttons'])) {
4486
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4248 4487
 					{
4249 4488
 						if (empty($subbutton['show']))
4250 4489
 							unset($button['sub_buttons'][$key]);
4490
+				}
4251 4491
 
4252 4492
 						// 2nd level sub buttons next...
4253 4493
 						if (!empty($subbutton['sub_buttons']))
4254 4494
 						{
4255 4495
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4256 4496
 							{
4257
-								if (empty($sub_button2['show']))
4258
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4497
+								if (empty($sub_button2['show'])) {
4498
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4499
+								}
4259 4500
 							}
4260 4501
 						}
4261 4502
 					}
4262 4503
 
4263 4504
 				// Does this button have its own icon?
4264
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4265
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4266
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4267
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4268
-				elseif (isset($button['icon']))
4269
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4270
-				else
4271
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4505
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4506
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4507
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4508
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4509
+				} elseif (isset($button['icon'])) {
4510
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4511
+				} else {
4512
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4513
+				}
4272 4514
 
4273 4515
 				$menu_buttons[$act] = $button;
4274 4516
 			}
4275 4517
 
4276
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4277
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4518
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4519
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4520
+		}
4278 4521
 	}
4279 4522
 
4280 4523
 	$context['menu_buttons'] = $menu_buttons;
4281 4524
 
4282 4525
 	// Logging out requires the session id in the url.
4283
-	if (isset($context['menu_buttons']['logout']))
4284
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4526
+	if (isset($context['menu_buttons']['logout'])) {
4527
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4528
+	}
4285 4529
 
4286 4530
 	// Figure out which action we are doing so we can set the active tab.
4287 4531
 	// Default to home.
4288 4532
 	$current_action = 'home';
4289 4533
 
4290
-	if (isset($context['menu_buttons'][$context['current_action']]))
4291
-		$current_action = $context['current_action'];
4292
-	elseif ($context['current_action'] == 'search2')
4293
-		$current_action = 'search';
4294
-	elseif ($context['current_action'] == 'theme')
4295
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4296
-	elseif ($context['current_action'] == 'register2')
4297
-		$current_action = 'register';
4298
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4299
-		$current_action = 'login';
4300
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4301
-		$current_action = 'moderate';
4534
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4535
+			$current_action = $context['current_action'];
4536
+	} elseif ($context['current_action'] == 'search2') {
4537
+			$current_action = 'search';
4538
+	} elseif ($context['current_action'] == 'theme') {
4539
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4540
+	} elseif ($context['current_action'] == 'register2') {
4541
+			$current_action = 'register';
4542
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4543
+			$current_action = 'login';
4544
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4545
+			$current_action = 'moderate';
4546
+	}
4302 4547
 
4303 4548
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4304 4549
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4305 4550
 	{
4306 4551
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4307 4552
 		$context[$current_action] = true;
4308
-	}
4309
-	elseif ($context['current_action'] == 'pm')
4553
+	} elseif ($context['current_action'] == 'pm')
4310 4554
 	{
4311 4555
 		$current_action = 'self_pm';
4312 4556
 		$context['self_pm'] = true;
@@ -4347,12 +4591,14 @@  discard block
 block discarded – undo
4347 4591
 	}
4348 4592
 
4349 4593
 	// Not all actions are simple.
4350
-	if (!empty($needs_action_hook))
4351
-		call_integration_hook('integrate_current_action', array(&$current_action));
4594
+	if (!empty($needs_action_hook)) {
4595
+			call_integration_hook('integrate_current_action', array(&$current_action));
4596
+	}
4352 4597
 
4353
-	if (isset($context['menu_buttons'][$current_action]))
4354
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4355
-}
4598
+	if (isset($context['menu_buttons'][$current_action])) {
4599
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4600
+	}
4601
+	}
4356 4602
 
4357 4603
 /**
4358 4604
  * Generate a random seed and ensure it's stored in settings.
@@ -4376,30 +4622,35 @@  discard block
 block discarded – undo
4376 4622
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4377 4623
 	global $context, $txt;
4378 4624
 
4379
-	if ($db_show_debug === true)
4380
-		$context['debug']['hooks'][] = $hook;
4625
+	if ($db_show_debug === true) {
4626
+			$context['debug']['hooks'][] = $hook;
4627
+	}
4381 4628
 
4382 4629
 	// Need to have some control.
4383
-	if (!isset($context['instances']))
4384
-		$context['instances'] = array();
4630
+	if (!isset($context['instances'])) {
4631
+			$context['instances'] = array();
4632
+	}
4385 4633
 
4386 4634
 	$results = array();
4387
-	if (empty($modSettings[$hook]))
4388
-		return $results;
4635
+	if (empty($modSettings[$hook])) {
4636
+			return $results;
4637
+	}
4389 4638
 
4390 4639
 	$functions = explode(',', $modSettings[$hook]);
4391 4640
 	// Loop through each function.
4392 4641
 	foreach ($functions as $function)
4393 4642
 	{
4394 4643
 		// Hook has been marked as "disabled". Skip it!
4395
-		if (strpos($function, '!') !== false)
4396
-			continue;
4644
+		if (strpos($function, '!') !== false) {
4645
+					continue;
4646
+		}
4397 4647
 
4398 4648
 		$call = call_helper($function, true);
4399 4649
 
4400 4650
 		// Is it valid?
4401
-		if (!empty($call))
4402
-			$results[$function] = call_user_func_array($call, $parameters);
4651
+		if (!empty($call)) {
4652
+					$results[$function] = call_user_func_array($call, $parameters);
4653
+		}
4403 4654
 
4404 4655
 		// Whatever it was suppose to call, it failed :(
4405 4656
 		elseif (!empty($function))
@@ -4415,8 +4666,9 @@  discard block
 block discarded – undo
4415 4666
 			}
4416 4667
 
4417 4668
 			// "Assume" the file resides on $boarddir somewhere...
4418
-			else
4419
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4669
+			else {
4670
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4671
+			}
4420 4672
 		}
4421 4673
 	}
4422 4674
 
@@ -4438,12 +4690,14 @@  discard block
 block discarded – undo
4438 4690
 	global $smcFunc, $modSettings;
4439 4691
 
4440 4692
 	// Any objects?
4441
-	if ($object)
4442
-		$function = $function . '#';
4693
+	if ($object) {
4694
+			$function = $function . '#';
4695
+	}
4443 4696
 
4444 4697
 	// Any files  to load?
4445
-	if (!empty($file) && is_string($file))
4446
-		$function = $file . (!empty($function) ? '|' . $function : '');
4698
+	if (!empty($file) && is_string($file)) {
4699
+			$function = $file . (!empty($function) ? '|' . $function : '');
4700
+	}
4447 4701
 
4448 4702
 	// Get the correct string.
4449 4703
 	$integration_call = $function;
@@ -4465,13 +4719,14 @@  discard block
 block discarded – undo
4465 4719
 		if (!empty($current_functions))
4466 4720
 		{
4467 4721
 			$current_functions = explode(',', $current_functions);
4468
-			if (in_array($integration_call, $current_functions))
4469
-				return;
4722
+			if (in_array($integration_call, $current_functions)) {
4723
+							return;
4724
+			}
4470 4725
 
4471 4726
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4727
+		} else {
4728
+					$permanent_functions = array($integration_call);
4472 4729
 		}
4473
-		else
4474
-			$permanent_functions = array($integration_call);
4475 4730
 
4476 4731
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4477 4732
 	}
@@ -4480,8 +4735,9 @@  discard block
 block discarded – undo
4480 4735
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4481 4736
 
4482 4737
 	// Do nothing, if it's already there.
4483
-	if (in_array($integration_call, $functions))
4484
-		return;
4738
+	if (in_array($integration_call, $functions)) {
4739
+			return;
4740
+	}
4485 4741
 
4486 4742
 	$functions[] = $integration_call;
4487 4743
 	$modSettings[$hook] = implode(',', $functions);
@@ -4504,12 +4760,14 @@  discard block
 block discarded – undo
4504 4760
 	global $smcFunc, $modSettings;
4505 4761
 
4506 4762
 	// Any objects?
4507
-	if ($object)
4508
-		$function = $function . '#';
4763
+	if ($object) {
4764
+			$function = $function . '#';
4765
+	}
4509 4766
 
4510 4767
 	// Any files  to load?
4511
-	if (!empty($file) && is_string($file))
4512
-		$function = $file . '|' . $function;
4768
+	if (!empty($file) && is_string($file)) {
4769
+			$function = $file . '|' . $function;
4770
+	}
4513 4771
 
4514 4772
 	// Get the correct string.
4515 4773
 	$integration_call = $function;
@@ -4530,16 +4788,18 @@  discard block
 block discarded – undo
4530 4788
 	{
4531 4789
 		$current_functions = explode(',', $current_functions);
4532 4790
 
4533
-		if (in_array($integration_call, $current_functions))
4534
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4791
+		if (in_array($integration_call, $current_functions)) {
4792
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4793
+		}
4535 4794
 	}
4536 4795
 
4537 4796
 	// Turn the function list into something usable.
4538 4797
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4539 4798
 
4540 4799
 	// You can only remove it if it's available.
4541
-	if (!in_array($integration_call, $functions))
4542
-		return;
4800
+	if (!in_array($integration_call, $functions)) {
4801
+			return;
4802
+	}
4543 4803
 
4544 4804
 	$functions = array_diff($functions, array($integration_call));
4545 4805
 	$modSettings[$hook] = implode(',', $functions);
@@ -4560,17 +4820,20 @@  discard block
 block discarded – undo
4560 4820
 	global $context, $smcFunc, $txt, $db_show_debug;
4561 4821
 
4562 4822
 	// Really?
4563
-	if (empty($string))
4564
-		return false;
4823
+	if (empty($string)) {
4824
+			return false;
4825
+	}
4565 4826
 
4566 4827
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4567 4828
 	// A closure? should be a callable one.
4568
-	if (is_array($string) || $string instanceof Closure)
4569
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4829
+	if (is_array($string) || $string instanceof Closure) {
4830
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4831
+	}
4570 4832
 
4571 4833
 	// No full objects, sorry! pass a method or a property instead!
4572
-	if (is_object($string))
4573
-		return false;
4834
+	if (is_object($string)) {
4835
+			return false;
4836
+	}
4574 4837
 
4575 4838
 	// Stay vitaminized my friends...
4576 4839
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4579,8 +4842,9 @@  discard block
 block discarded – undo
4579 4842
 	$string = load_file($string);
4580 4843
 
4581 4844
 	// Loaded file failed
4582
-	if (empty($string))
4583
-		return false;
4845
+	if (empty($string)) {
4846
+			return false;
4847
+	}
4584 4848
 
4585 4849
 	// Found a method.
4586 4850
 	if (strpos($string, '::') !== false)
@@ -4601,8 +4865,9 @@  discard block
 block discarded – undo
4601 4865
 				// Add another one to the list.
4602 4866
 				if ($db_show_debug === true)
4603 4867
 				{
4604
-					if (!isset($context['debug']['instances']))
4605
-						$context['debug']['instances'] = array();
4868
+					if (!isset($context['debug']['instances'])) {
4869
+											$context['debug']['instances'] = array();
4870
+					}
4606 4871
 
4607 4872
 					$context['debug']['instances'][$class] = $class;
4608 4873
 				}
@@ -4612,13 +4877,15 @@  discard block
 block discarded – undo
4612 4877
 		}
4613 4878
 
4614 4879
 		// Right then. This is a call to a static method.
4615
-		else
4616
-			$func = array($class, $method);
4880
+		else {
4881
+					$func = array($class, $method);
4882
+		}
4617 4883
 	}
4618 4884
 
4619 4885
 	// Nope! just a plain regular function.
4620
-	else
4621
-		$func = $string;
4886
+	else {
4887
+			$func = $string;
4888
+	}
4622 4889
 
4623 4890
 	// Right, we got what we need, time to do some checks.
4624 4891
 	if (!is_callable($func, false, $callable_name))
@@ -4634,17 +4901,18 @@  discard block
 block discarded – undo
4634 4901
 	else
4635 4902
 	{
4636 4903
 		// What are we gonna do about it?
4637
-		if ($return)
4638
-			return $func;
4904
+		if ($return) {
4905
+					return $func;
4906
+		}
4639 4907
 
4640 4908
 		// If this is a plain function, avoid the heat of calling call_user_func().
4641 4909
 		else
4642 4910
 		{
4643
-			if (is_array($func))
4644
-				call_user_func($func);
4645
-
4646
-			else
4647
-				$func();
4911
+			if (is_array($func)) {
4912
+							call_user_func($func);
4913
+			} else {
4914
+							$func();
4915
+			}
4648 4916
 		}
4649 4917
 	}
4650 4918
 }
@@ -4661,31 +4929,34 @@  discard block
 block discarded – undo
4661 4929
 {
4662 4930
 	global $sourcedir, $txt, $boarddir, $settings;
4663 4931
 
4664
-	if (empty($string))
4665
-		return false;
4932
+	if (empty($string)) {
4933
+			return false;
4934
+	}
4666 4935
 
4667 4936
 	if (strpos($string, '|') !== false)
4668 4937
 	{
4669 4938
 		list ($file, $string) = explode('|', $string);
4670 4939
 
4671 4940
 		// Match the wildcards to their regular vars.
4672
-		if (empty($settings['theme_dir']))
4673
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4674
-
4675
-		else
4676
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4941
+		if (empty($settings['theme_dir'])) {
4942
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4943
+		} else {
4944
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4945
+		}
4677 4946
 
4678 4947
 		// Load the file if it can be loaded.
4679
-		if (file_exists($absPath))
4680
-			require_once($absPath);
4948
+		if (file_exists($absPath)) {
4949
+					require_once($absPath);
4950
+		}
4681 4951
 
4682 4952
 		// No? try a fallback to $sourcedir
4683 4953
 		else
4684 4954
 		{
4685 4955
 			$absPath = $sourcedir .'/'. $file;
4686 4956
 
4687
-			if (file_exists($absPath))
4688
-				require_once($absPath);
4957
+			if (file_exists($absPath)) {
4958
+							require_once($absPath);
4959
+			}
4689 4960
 
4690 4961
 			// Sorry, can't do much for you at this point.
4691 4962
 			else
@@ -4712,8 +4983,9 @@  discard block
 block discarded – undo
4712 4983
 	global $user_info, $smcFunc;
4713 4984
 
4714 4985
 	// Make sure we have something to work with.
4715
-	if (empty($topic))
4716
-		return array();
4986
+	if (empty($topic)) {
4987
+			return array();
4988
+	}
4717 4989
 
4718 4990
 
4719 4991
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4736,8 +5008,9 @@  discard block
 block discarded – undo
4736 5008
 				'topic' => $topic,
4737 5009
 			)
4738 5010
 		);
4739
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4740
-			$temp[] = (int) $row['content_id'];
5011
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5012
+					$temp[] = (int) $row['content_id'];
5013
+		}
4741 5014
 
4742 5015
 		cache_put_data($cache_key, $temp, $ttl);
4743 5016
 	}
@@ -4758,8 +5031,9 @@  discard block
 block discarded – undo
4758 5031
 {
4759 5032
 	global $context;
4760 5033
 
4761
-	if (empty($string))
4762
-		return $string;
5034
+	if (empty($string)) {
5035
+			return $string;
5036
+	}
4763 5037
 
4764 5038
 	// UTF-8 occurences of MS special characters
4765 5039
 	$findchars_utf8 = array(
@@ -4800,10 +5074,11 @@  discard block
 block discarded – undo
4800 5074
 		'--',	// &mdash;
4801 5075
 	);
4802 5076
 
4803
-	if ($context['utf8'])
4804
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4805
-	else
4806
-		$string = str_replace($findchars_iso, $replacechars, $string);
5077
+	if ($context['utf8']) {
5078
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5079
+	} else {
5080
+			$string = str_replace($findchars_iso, $replacechars, $string);
5081
+	}
4807 5082
 
4808 5083
 	return $string;
4809 5084
 }
@@ -4822,49 +5097,59 @@  discard block
 block discarded – undo
4822 5097
 {
4823 5098
 	global $context;
4824 5099
 
4825
-	if (!isset($matches[2]))
4826
-		return '';
5100
+	if (!isset($matches[2])) {
5101
+			return '';
5102
+	}
4827 5103
 
4828 5104
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4829 5105
 
4830 5106
 	// remove left to right / right to left overrides
4831
-	if ($num === 0x202D || $num === 0x202E)
4832
-		return '';
5107
+	if ($num === 0x202D || $num === 0x202E) {
5108
+			return '';
5109
+	}
4833 5110
 
4834 5111
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4835
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4836
-		return '&#' . $num . ';';
5112
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5113
+			return '&#' . $num . ';';
5114
+	}
4837 5115
 
4838 5116
 	if (empty($context['utf8']))
4839 5117
 	{
4840 5118
 		// no control characters
4841
-		if ($num < 0x20)
4842
-			return '';
5119
+		if ($num < 0x20) {
5120
+					return '';
5121
+		}
4843 5122
 		// text is text
4844
-		elseif ($num < 0x80)
4845
-			return chr($num);
5123
+		elseif ($num < 0x80) {
5124
+					return chr($num);
5125
+		}
4846 5126
 		// all others get html-ised
4847
-		else
4848
-			return '&#' . $matches[2] . ';';
4849
-	}
4850
-	else
5127
+		else {
5128
+					return '&#' . $matches[2] . ';';
5129
+		}
5130
+	} else
4851 5131
 	{
4852 5132
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4853 5133
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4854
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4855
-			return '';
5134
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5135
+					return '';
5136
+		}
4856 5137
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4857
-		elseif ($num < 0x80)
4858
-			return chr($num);
5138
+		elseif ($num < 0x80) {
5139
+					return chr($num);
5140
+		}
4859 5141
 		// <0x800 (2048)
4860
-		elseif ($num < 0x800)
4861
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5142
+		elseif ($num < 0x800) {
5143
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5144
+		}
4862 5145
 		// < 0x10000 (65536)
4863
-		elseif ($num < 0x10000)
4864
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5146
+		elseif ($num < 0x10000) {
5147
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5148
+		}
4865 5149
 		// <= 0x10FFFF (1114111)
4866
-		else
4867
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5150
+		else {
5151
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5152
+		}
4868 5153
 	}
4869 5154
 }
4870 5155
 
@@ -4880,28 +5165,34 @@  discard block
 block discarded – undo
4880 5165
  */
4881 5166
 function fixchar__callback($matches)
4882 5167
 {
4883
-	if (!isset($matches[1]))
4884
-		return '';
5168
+	if (!isset($matches[1])) {
5169
+			return '';
5170
+	}
4885 5171
 
4886 5172
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4887 5173
 
4888 5174
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4889 5175
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4890
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4891
-		return '';
5176
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5177
+			return '';
5178
+	}
4892 5179
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4893
-	elseif ($num < 0x80)
4894
-		return chr($num);
5180
+	elseif ($num < 0x80) {
5181
+			return chr($num);
5182
+	}
4895 5183
 	// <0x800 (2048)
4896
-	elseif ($num < 0x800)
4897
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5184
+	elseif ($num < 0x800) {
5185
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5186
+	}
4898 5187
 	// < 0x10000 (65536)
4899
-	elseif ($num < 0x10000)
4900
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5188
+	elseif ($num < 0x10000) {
5189
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5190
+	}
4901 5191
 	// <= 0x10FFFF (1114111)
4902
-	else
4903
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4904
-}
5192
+	else {
5193
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5194
+	}
5195
+	}
4905 5196
 
4906 5197
 /**
4907 5198
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4914,17 +5205,19 @@  discard block
 block discarded – undo
4914 5205
  */
4915 5206
 function entity_fix__callback($matches)
4916 5207
 {
4917
-	if (!isset($matches[2]))
4918
-		return '';
5208
+	if (!isset($matches[2])) {
5209
+			return '';
5210
+	}
4919 5211
 
4920 5212
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4921 5213
 
4922 5214
 	// we don't allow control characters, characters out of range, byte markers, etc
4923
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4924
-		return '';
4925
-	else
4926
-		return '&#' . $num . ';';
4927
-}
5215
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5216
+			return '';
5217
+	} else {
5218
+			return '&#' . $num . ';';
5219
+	}
5220
+	}
4928 5221
 
4929 5222
 /**
4930 5223
  * Return a Gravatar URL based on
@@ -4948,18 +5241,23 @@  discard block
 block discarded – undo
4948 5241
 		$ratings = array('G', 'PG', 'R', 'X');
4949 5242
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4950 5243
 		$url_params = array();
4951
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4952
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4953
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4954
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4955
-		if (!empty($modSettings['avatar_max_width_external']))
4956
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4957
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4958
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5244
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5245
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5246
+		}
5247
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5248
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5249
+		}
5250
+		if (!empty($modSettings['avatar_max_width_external'])) {
5251
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5252
+		}
5253
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5254
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4959 5255
 				$size_string = $modSettings['avatar_max_height_external'];
5256
+		}
4960 5257
 
4961
-		if (!empty($size_string))
4962
-			$url_params[] = 's=' . $size_string;
5258
+		if (!empty($size_string)) {
5259
+					$url_params[] = 's=' . $size_string;
5260
+		}
4963 5261
 	}
4964 5262
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4965 5263
 
@@ -4978,22 +5276,26 @@  discard block
 block discarded – undo
4978 5276
 	static $timezones = null, $lastwhen = null;
4979 5277
 
4980 5278
 	// No point doing this over if we already did it once
4981
-	if (!empty($timezones) && $when == $lastwhen)
4982
-		return $timezones;
4983
-	else
4984
-		$lastwhen = $when;
5279
+	if (!empty($timezones) && $when == $lastwhen) {
5280
+			return $timezones;
5281
+	} else {
5282
+			$lastwhen = $when;
5283
+	}
4985 5284
 
4986 5285
 	// Parseable datetime string?
4987
-	if (is_int($timestamp = strtotime($when)))
4988
-		$when = $timestamp;
5286
+	if (is_int($timestamp = strtotime($when))) {
5287
+			$when = $timestamp;
5288
+	}
4989 5289
 
4990 5290
 	// A Unix timestamp?
4991
-	elseif (is_numeric($when))
4992
-		$when = intval($when);
5291
+	elseif (is_numeric($when)) {
5292
+			$when = intval($when);
5293
+	}
4993 5294
 
4994 5295
 	// Invalid value? Just get current Unix timestamp.
4995
-	else
4996
-		$when = time();
5296
+	else {
5297
+			$when = time();
5298
+	}
4997 5299
 
4998 5300
 	// We'll need these too
4999 5301
 	$date_when = date_create('@' . $when);
@@ -5057,8 +5359,9 @@  discard block
 block discarded – undo
5057 5359
 	foreach ($priority_countries as $country)
5058 5360
 	{
5059 5361
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5060
-		if (!empty($country_tzids))
5061
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5362
+		if (!empty($country_tzids)) {
5363
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5364
+		}
5062 5365
 	}
5063 5366
 
5064 5367
 	// Process the preferred timezones first, then the rest.
@@ -5068,8 +5371,9 @@  discard block
 block discarded – undo
5068 5371
 	foreach ($tzids as $tzid)
5069 5372
 	{
5070 5373
 		// We don't want UTC right now
5071
-		if ($tzid == 'UTC')
5072
-			continue;
5374
+		if ($tzid == 'UTC') {
5375
+					continue;
5376
+		}
5073 5377
 
5074 5378
 		$tz = timezone_open($tzid);
5075 5379
 
@@ -5084,12 +5388,14 @@  discard block
 block discarded – undo
5084 5388
 		$tzgeo = timezone_location_get($tz);
5085 5389
 
5086 5390
 		// Don't overwrite our preferred tzids
5087
-		if (empty($zones[$tzkey]['tzid']))
5088
-			$zones[$tzkey]['tzid'] = $tzid;
5391
+		if (empty($zones[$tzkey]['tzid'])) {
5392
+					$zones[$tzkey]['tzid'] = $tzid;
5393
+		}
5089 5394
 
5090 5395
 		// A time zone from a prioritized country?
5091
-		if (in_array($tzid, $priority_tzids))
5092
-			$priority_zones[$tzkey] = true;
5396
+		if (in_array($tzid, $priority_tzids)) {
5397
+					$priority_zones[$tzkey] = true;
5398
+		}
5093 5399
 
5094 5400
 		// Keep track of the location and offset for this tzid
5095 5401
 		$tzid_parts = explode('/', $tzid);
@@ -5111,15 +5417,17 @@  discard block
 block discarded – undo
5111 5417
 
5112 5418
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5113 5419
 
5114
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5115
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5116
-		else
5117
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5420
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5421
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5422
+		} else {
5423
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5424
+		}
5118 5425
 
5119
-		if (isset($priority_zones[$tzkey]))
5120
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5121
-		else
5122
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5426
+		if (isset($priority_zones[$tzkey])) {
5427
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5428
+		} else {
5429
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5430
+		}
5123 5431
 	}
5124 5432
 
5125 5433
 	$timezones = array_merge(
@@ -5173,9 +5481,9 @@  discard block
 block discarded – undo
5173 5481
 			'Indian/Kerguelen' => 'TFT',
5174 5482
 		);
5175 5483
 
5176
-		if (!empty($missing_tz_abbrs[$tzid]))
5177
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5178
-		else
5484
+		if (!empty($missing_tz_abbrs[$tzid])) {
5485
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5486
+		} else
5179 5487
 		{
5180 5488
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5181 5489
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5203,8 +5511,9 @@  discard block
 block discarded – undo
5203 5511
  */
5204 5512
 function inet_ptod($ip_address)
5205 5513
 {
5206
-	if (!isValidIP($ip_address))
5207
-		return $ip_address;
5514
+	if (!isValidIP($ip_address)) {
5515
+			return $ip_address;
5516
+	}
5208 5517
 
5209 5518
 	$bin = inet_pton($ip_address);
5210 5519
 	return $bin;
@@ -5216,13 +5525,15 @@  discard block
 block discarded – undo
5216 5525
  */
5217 5526
 function inet_dtop($bin)
5218 5527
 {
5219
-	if(empty($bin))
5220
-		return '';
5528
+	if(empty($bin)) {
5529
+			return '';
5530
+	}
5221 5531
 
5222 5532
 	global $db_type;
5223 5533
 
5224
-	if ($db_type == 'postgresql')
5225
-		return $bin;
5534
+	if ($db_type == 'postgresql') {
5535
+			return $bin;
5536
+	}
5226 5537
 
5227 5538
 	$ip_address = inet_ntop($bin);
5228 5539
 
@@ -5247,26 +5558,32 @@  discard block
 block discarded – undo
5247 5558
  */
5248 5559
 function _safe_serialize($value)
5249 5560
 {
5250
-	if(is_null($value))
5251
-		return 'N;';
5561
+	if(is_null($value)) {
5562
+			return 'N;';
5563
+	}
5252 5564
 
5253
-	if(is_bool($value))
5254
-		return 'b:'. (int) $value .';';
5565
+	if(is_bool($value)) {
5566
+			return 'b:'. (int) $value .';';
5567
+	}
5255 5568
 
5256
-	if(is_int($value))
5257
-		return 'i:'. $value .';';
5569
+	if(is_int($value)) {
5570
+			return 'i:'. $value .';';
5571
+	}
5258 5572
 
5259
-	if(is_float($value))
5260
-		return 'd:'. str_replace(',', '.', $value) .';';
5573
+	if(is_float($value)) {
5574
+			return 'd:'. str_replace(',', '.', $value) .';';
5575
+	}
5261 5576
 
5262
-	if(is_string($value))
5263
-		return 's:'. strlen($value) .':"'. $value .'";';
5577
+	if(is_string($value)) {
5578
+			return 's:'. strlen($value) .':"'. $value .'";';
5579
+	}
5264 5580
 
5265 5581
 	if(is_array($value))
5266 5582
 	{
5267 5583
 		$out = '';
5268
-		foreach($value as $k => $v)
5269
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5584
+		foreach($value as $k => $v) {
5585
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5586
+		}
5270 5587
 
5271 5588
 		return 'a:'. count($value) .':{'. $out .'}';
5272 5589
 	}
@@ -5292,8 +5609,9 @@  discard block
 block discarded – undo
5292 5609
 
5293 5610
 	$out = _safe_serialize($value);
5294 5611
 
5295
-	if (isset($mbIntEnc))
5296
-		mb_internal_encoding($mbIntEnc);
5612
+	if (isset($mbIntEnc)) {
5613
+			mb_internal_encoding($mbIntEnc);
5614
+	}
5297 5615
 
5298 5616
 	return $out;
5299 5617
 }
@@ -5310,8 +5628,9 @@  discard block
 block discarded – undo
5310 5628
 function _safe_unserialize($str)
5311 5629
 {
5312 5630
 	// Input  is not a string.
5313
-	if(empty($str) || !is_string($str))
5314
-		return false;
5631
+	if(empty($str) || !is_string($str)) {
5632
+			return false;
5633
+	}
5315 5634
 
5316 5635
 	$stack = array();
5317 5636
 	$expected = array();
@@ -5327,43 +5646,38 @@  discard block
 block discarded – undo
5327 5646
 	while($state != 1)
5328 5647
 	{
5329 5648
 		$type = isset($str[0]) ? $str[0] : '';
5330
-		if($type == '}')
5331
-			$str = substr($str, 1);
5332
-
5333
-		else if($type == 'N' && $str[1] == ';')
5649
+		if($type == '}') {
5650
+					$str = substr($str, 1);
5651
+		} else if($type == 'N' && $str[1] == ';')
5334 5652
 		{
5335 5653
 			$value = null;
5336 5654
 			$str = substr($str, 2);
5337
-		}
5338
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5655
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5339 5656
 		{
5340 5657
 			$value = $matches[1] == '1' ? true : false;
5341 5658
 			$str = substr($str, 4);
5342
-		}
5343
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5659
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5344 5660
 		{
5345 5661
 			$value = (int)$matches[1];
5346 5662
 			$str = $matches[2];
5347
-		}
5348
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5663
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5349 5664
 		{
5350 5665
 			$value = (float)$matches[1];
5351 5666
 			$str = $matches[3];
5352
-		}
5353
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5667
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5354 5668
 		{
5355 5669
 			$value = substr($matches[2], 0, (int)$matches[1]);
5356 5670
 			$str = substr($matches[2], (int)$matches[1] + 2);
5357
-		}
5358
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5671
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5359 5672
 		{
5360 5673
 			$expectedLength = (int)$matches[1];
5361 5674
 			$str = $matches[2];
5362 5675
 		}
5363 5676
 
5364 5677
 		// Object or unknown/malformed type.
5365
-		else
5366
-			return false;
5678
+		else {
5679
+					return false;
5680
+		}
5367 5681
 
5368 5682
 		switch($state)
5369 5683
 		{
@@ -5391,8 +5705,9 @@  discard block
 block discarded – undo
5391 5705
 				if($type == '}')
5392 5706
 				{
5393 5707
 					// Array size is less than expected.
5394
-					if(count($list) < end($expected))
5395
-						return false;
5708
+					if(count($list) < end($expected)) {
5709
+											return false;
5710
+					}
5396 5711
 
5397 5712
 					unset($list);
5398 5713
 					$list = &$stack[count($stack)-1];
@@ -5401,8 +5716,9 @@  discard block
 block discarded – undo
5401 5716
 					// Go to terminal state if we're at the end of the root array.
5402 5717
 					array_pop($expected);
5403 5718
 
5404
-					if(count($expected) == 0)
5405
-						$state = 1;
5719
+					if(count($expected) == 0) {
5720
+											$state = 1;
5721
+					}
5406 5722
 
5407 5723
 					break;
5408 5724
 				}
@@ -5410,8 +5726,9 @@  discard block
 block discarded – undo
5410 5726
 				if($type == 'i' || $type == 's')
5411 5727
 				{
5412 5728
 					// Array size exceeds expected length.
5413
-					if(count($list) >= end($expected))
5414
-						return false;
5729
+					if(count($list) >= end($expected)) {
5730
+											return false;
5731
+					}
5415 5732
 
5416 5733
 					$key = $value;
5417 5734
 					$state = 3;
@@ -5445,8 +5762,9 @@  discard block
 block discarded – undo
5445 5762
 	}
5446 5763
 
5447 5764
 	// Trailing data in input.
5448
-	if(!empty($str))
5449
-		return false;
5765
+	if(!empty($str)) {
5766
+			return false;
5767
+	}
5450 5768
 
5451 5769
 	return $data;
5452 5770
 }
@@ -5469,8 +5787,9 @@  discard block
 block discarded – undo
5469 5787
 
5470 5788
 	$out = _safe_unserialize($str);
5471 5789
 
5472
-	if (isset($mbIntEnc))
5473
-		mb_internal_encoding($mbIntEnc);
5790
+	if (isset($mbIntEnc)) {
5791
+			mb_internal_encoding($mbIntEnc);
5792
+	}
5474 5793
 
5475 5794
 	return $out;
5476 5795
 }
@@ -5485,12 +5804,14 @@  discard block
 block discarded – undo
5485 5804
 function smf_chmod($file, $value = 0)
5486 5805
 {
5487 5806
 	// No file? no checks!
5488
-	if (empty($file))
5489
-		return false;
5807
+	if (empty($file)) {
5808
+			return false;
5809
+	}
5490 5810
 
5491 5811
 	// Already writable?
5492
-	if (is_writable($file))
5493
-		return true;
5812
+	if (is_writable($file)) {
5813
+			return true;
5814
+	}
5494 5815
 
5495 5816
 	// Do we have a file or a dir?
5496 5817
 	$isDir = is_dir($file);
@@ -5506,10 +5827,9 @@  discard block
 block discarded – undo
5506 5827
 		{
5507 5828
 			$isWritable = true;
5508 5829
 			break;
5830
+		} else {
5831
+					@chmod($file, $val);
5509 5832
 		}
5510
-
5511
-		else
5512
-			@chmod($file, $val);
5513 5833
 	}
5514 5834
 
5515 5835
 	return $isWritable;
@@ -5528,8 +5848,9 @@  discard block
 block discarded – undo
5528 5848
 	global $txt;
5529 5849
 
5530 5850
 	// Come on...
5531
-	if (empty($json) || !is_string($json))
5532
-		return array();
5851
+	if (empty($json) || !is_string($json)) {
5852
+			return array();
5853
+	}
5533 5854
 
5534 5855
 	$returnArray = @json_decode($json, $returnAsArray);
5535 5856
 
@@ -5567,11 +5888,11 @@  discard block
 block discarded – undo
5567 5888
 		$jsonDebug = $jsonDebug[0];
5568 5889
 		loadLanguage('Errors');
5569 5890
 
5570
-		if (!empty($jsonDebug))
5571
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5572
-
5573
-		else
5574
-			log_error($txt['json_'. $jsonError], 'critical');
5891
+		if (!empty($jsonDebug)) {
5892
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5893
+		} else {
5894
+					log_error($txt['json_'. $jsonError], 'critical');
5895
+		}
5575 5896
 
5576 5897
 		// Everyone expects an array.
5577 5898
 		return array();
@@ -5601,8 +5922,9 @@  discard block
 block discarded – undo
5601 5922
 	global $db_show_debug, $modSettings;
5602 5923
 
5603 5924
 	// Defensive programming anyone?
5604
-	if (empty($data))
5605
-		return false;
5925
+	if (empty($data)) {
5926
+			return false;
5927
+	}
5606 5928
 
5607 5929
 	// Don't need extra stuff...
5608 5930
 	$db_show_debug = false;
@@ -5610,11 +5932,11 @@  discard block
 block discarded – undo
5610 5932
 	// Kill anything else.
5611 5933
 	ob_end_clean();
5612 5934
 
5613
-	if (!empty($modSettings['CompressedOutput']))
5614
-		@ob_start('ob_gzhandler');
5615
-
5616
-	else
5617
-		ob_start();
5935
+	if (!empty($modSettings['CompressedOutput'])) {
5936
+			@ob_start('ob_gzhandler');
5937
+	} else {
5938
+			ob_start();
5939
+	}
5618 5940
 
5619 5941
 	// Set the header.
5620 5942
 	header($type);
@@ -5646,8 +5968,9 @@  discard block
 block discarded – undo
5646 5968
 	static $done = false;
5647 5969
 
5648 5970
 	// If we don't need to do anything, don't
5649
-	if (!$update && $done)
5650
-		return;
5971
+	if (!$update && $done) {
5972
+			return;
5973
+	}
5651 5974
 
5652 5975
 	// Should we get a new copy of the official list of TLDs?
5653 5976
 	if ($update)
@@ -5656,8 +5979,9 @@  discard block
 block discarded – undo
5656 5979
 		$tlds = fetch_web_data('https://data.iana.org/TLD/tlds-alpha-by-domain.txt');
5657 5980
 
5658 5981
 		// If the Internet Assigned Numbers Authority can't be reached, the Internet is gone. We're probably running on a server hidden in a bunker deep underground to protect it from marauding bandits roaming on the surface. We don't want to waste precious electricity on pointlessly repeating background tasks, so we'll wait until the next regularly scheduled update to see if civilization has been restored.
5659
-		if ($tlds === false)
5660
-			$postapocalypticNightmare = true;
5982
+		if ($tlds === false) {
5983
+					$postapocalypticNightmare = true;
5984
+		}
5661 5985
 	}
5662 5986
 	// If we aren't updating and the regex is valid, we're done
5663 5987
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -5672,10 +5996,11 @@  discard block
 block discarded – undo
5672 5996
 		// Clean $tlds and convert it to an array
5673 5997
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5674 5998
 			$line = trim($line);
5675
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5676
-				return false;
5677
-			else
5678
-				return true;
5999
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6000
+							return false;
6001
+			} else {
6002
+							return true;
6003
+			}
5679 6004
 		});
5680 6005
 
5681 6006
 		// Convert Punycode to Unicode
@@ -5729,8 +6054,9 @@  discard block
 block discarded – undo
5729 6054
 						$idx += $digit * $w;
5730 6055
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5731 6056
 
5732
-						if ($digit < $t)
5733
-							break;
6057
+						if ($digit < $t) {
6058
+													break;
6059
+						}
5734 6060
 
5735 6061
 						$w = (int) ($w * ($base - $t));
5736 6062
 					}
@@ -5739,8 +6065,9 @@  discard block
 block discarded – undo
5739 6065
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5740 6066
 					$delta += intval($delta / ($deco_len + 1));
5741 6067
 
5742
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5743
-						$delta = intval($delta / ($base - $tmin));
6068
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
6069
+											$delta = intval($delta / ($base - $tmin));
6070
+					}
5744 6071
 
5745 6072
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5746 6073
 					$is_first = false;
@@ -5749,8 +6076,9 @@  discard block
 block discarded – undo
5749 6076
 
5750 6077
 					if ($deco_len > 0)
5751 6078
 					{
5752
-						for ($i = $deco_len; $i > $idx; $i--)
5753
-							$decoded[$i] = $decoded[($i - 1)];
6079
+						for ($i = $deco_len; $i > $idx; $i--) {
6080
+													$decoded[$i] = $decoded[($i - 1)];
6081
+						}
5754 6082
 					}
5755 6083
 					$decoded[$idx++] = $char;
5756 6084
 				}
@@ -5758,24 +6086,29 @@  discard block
 block discarded – undo
5758 6086
 				foreach ($decoded as $k => $v)
5759 6087
 				{
5760 6088
 					// 7bit are transferred literally
5761
-					if ($v < 128)
5762
-						$output .= chr($v);
6089
+					if ($v < 128) {
6090
+											$output .= chr($v);
6091
+					}
5763 6092
 
5764 6093
 					// 2 bytes
5765
-					elseif ($v < (1 << 11))
5766
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6094
+					elseif ($v < (1 << 11)) {
6095
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6096
+					}
5767 6097
 
5768 6098
 					// 3 bytes
5769
-					elseif ($v < (1 << 16))
5770
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6099
+					elseif ($v < (1 << 16)) {
6100
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6101
+					}
5771 6102
 
5772 6103
 					// 4 bytes
5773
-					elseif ($v < (1 << 21))
5774
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6104
+					elseif ($v < (1 << 21)) {
6105
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6106
+					}
5775 6107
 
5776 6108
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5777
-					else
5778
-						$output .= $safe_char;
6109
+					else {
6110
+											$output .= $safe_char;
6111
+					}
5779 6112
 				}
5780 6113
 
5781 6114
 				$output_parts[] = $output;
@@ -5869,8 +6202,7 @@  discard block
 block discarded – undo
5869 6202
 
5870 6203
 		$strlen = 'mb_strlen';
5871 6204
 		$substr = 'mb_substr';
5872
-	}
5873
-	else
6205
+	} else
5874 6206
 	{
5875 6207
 		$strlen = $smcFunc['strlen'];
5876 6208
 		$substr = $smcFunc['substr'];
@@ -5884,20 +6216,21 @@  discard block
 block discarded – undo
5884 6216
 
5885 6217
 		$first = $substr($string, 0, 1);
5886 6218
 
5887
-		if (empty($index[$first]))
5888
-			$index[$first] = array();
6219
+		if (empty($index[$first])) {
6220
+					$index[$first] = array();
6221
+		}
5889 6222
 
5890 6223
 		if ($strlen($string) > 1)
5891 6224
 		{
5892 6225
 			// Sanity check on recursion
5893
-			if ($depth > 99)
5894
-				$index[$first][$substr($string, 1)] = '';
5895
-
5896
-			else
5897
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6226
+			if ($depth > 99) {
6227
+							$index[$first][$substr($string, 1)] = '';
6228
+			} else {
6229
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6230
+			}
6231
+		} else {
6232
+					$index[$first][''] = '';
5898 6233
 		}
5899
-		else
5900
-			$index[$first][''] = '';
5901 6234
 
5902 6235
 		$depth--;
5903 6236
 		return $index;
@@ -5920,9 +6253,9 @@  discard block
 block discarded – undo
5920 6253
 			$key_regex = preg_quote($key, $delim);
5921 6254
 			$new_key = $key;
5922 6255
 
5923
-			if (empty($value))
5924
-				$sub_regex = '';
5925
-			else
6256
+			if (empty($value)) {
6257
+							$sub_regex = '';
6258
+			} else
5926 6259
 			{
5927 6260
 				$sub_regex = $index_to_regex($value, $delim);
5928 6261
 
@@ -5930,22 +6263,22 @@  discard block
 block discarded – undo
5930 6263
 				{
5931 6264
 					$new_key_array = explode('(?'.'>', $sub_regex);
5932 6265
 					$new_key .= $new_key_array[0];
6266
+				} else {
6267
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5933 6268
 				}
5934
-				else
5935
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5936 6269
 			}
5937 6270
 
5938
-			if ($depth > 1)
5939
-				$regex[$new_key] = $key_regex . $sub_regex;
5940
-			else
6271
+			if ($depth > 1) {
6272
+							$regex[$new_key] = $key_regex . $sub_regex;
6273
+			} else
5941 6274
 			{
5942 6275
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5943 6276
 				{
5944 6277
 					$regex[$new_key] = $key_regex . $sub_regex;
5945 6278
 					unset($index[$key]);
6279
+				} else {
6280
+									break;
5946 6281
 				}
5947
-				else
5948
-					break;
5949 6282
 			}
5950 6283
 		}
5951 6284
 
@@ -5954,10 +6287,11 @@  discard block
 block discarded – undo
5954 6287
 			$l1 = $strlen($k1);
5955 6288
 			$l2 = $strlen($k2);
5956 6289
 
5957
-			if ($l1 == $l2)
5958
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5959
-			else
5960
-				return $l1 > $l2 ? -1 : 1;
6290
+			if ($l1 == $l2) {
6291
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6292
+			} else {
6293
+							return $l1 > $l2 ? -1 : 1;
6294
+			}
5961 6295
 		});
5962 6296
 
5963 6297
 		$depth--;
@@ -5968,15 +6302,18 @@  discard block
 block discarded – undo
5968 6302
 	$index = array();
5969 6303
 	$regexes = array();
5970 6304
 
5971
-	foreach ($strings as $string)
5972
-		$index = $add_string_to_index($string, $index);
6305
+	foreach ($strings as $string) {
6306
+			$index = $add_string_to_index($string, $index);
6307
+	}
5973 6308
 
5974
-	while (!empty($index))
5975
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6309
+	while (!empty($index)) {
6310
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6311
+	}
5976 6312
 
5977 6313
 	// Restore PHP's internal character encoding to whatever it was originally
5978
-	if (!empty($current_encoding))
5979
-		mb_internal_encoding($current_encoding);
6314
+	if (!empty($current_encoding)) {
6315
+			mb_internal_encoding($current_encoding);
6316
+	}
5980 6317
 
5981 6318
 	return $regexes;
5982 6319
 }
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +224 added lines, -163 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
 				'max_year' => $year_high,
61 62
 			)
62 63
 		);
63
-	}
64
-	else
64
+	} else
65 65
 	{
66 66
 		$result = $smcFunc['db_query']('birthday_array', '
67 67
 			SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate
@@ -91,10 +91,11 @@  discard block
 block discarded – undo
91 91
 	$bday = array();
92 92
 	while ($row = $smcFunc['db_fetch_assoc']($result))
93 93
 	{
94
-		if ($year_low != $year_high)
95
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
-		else
97
-			$age_year = $year_low;
94
+		if ($year_low != $year_high) {
95
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
+		} else {
97
+					$age_year = $year_low;
98
+		}
98 99
 
99 100
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
100 101
 			'id' => $row['id_member'],
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 	ksort($bday);
109 110
 
110 111
 	// Set is_last, so the themes know when to stop placing separators.
111
-	foreach ($bday as $mday => $array)
112
-		$bday[$mday][count($array) - 1]['is_last'] = true;
112
+	foreach ($bday as $mday => $array) {
113
+			$bday[$mday][count($array) - 1]['is_last'] = true;
114
+	}
113 115
 
114 116
 	return $bday;
115 117
 }
@@ -133,8 +135,9 @@  discard block
 block discarded – undo
133 135
 	static $timezone_array = array();
134 136
 	require_once($sourcedir . '/Subs.php');
135 137
 	
136
-	if (empty($timezone_array['default']))
137
-		$timezone_array['default'] = timezone_open(date_default_timezone_get());
138
+	if (empty($timezone_array['default'])) {
139
+			$timezone_array['default'] = timezone_open(date_default_timezone_get());
140
+	}
138 141
 
139 142
 	$low_object = date_create($low_date);
140 143
 	$high_object = date_create($high_date);
@@ -161,8 +164,9 @@  discard block
 block discarded – undo
161 164
 	while ($row = $smcFunc['db_fetch_assoc']($result))
162 165
 	{
163 166
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
164
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
165
-			continue;
167
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
168
+					continue;
169
+		}
166 170
 
167 171
 		// Force a censor of the title - as often these are used by others.
168 172
 		censorText($row['title'], $use_permissions ? false : true);
@@ -170,12 +174,14 @@  discard block
 block discarded – undo
170 174
 		// Get the various time and date properties for this event
171 175
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
172 176
 		
173
-		if (empty($timezone_array[$tz]))
174
-			$timezone_array[$tz] = timezone_open($tz);
177
+		if (empty($timezone_array[$tz])) {
178
+					$timezone_array[$tz] = timezone_open($tz);
179
+		}
175 180
 
176 181
 		// Sanity check
177
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
178
-			continue;
182
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
183
+					continue;
184
+		}
179 185
 
180 186
 		// Get set up for the loop
181 187
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), $timezone_array[$tz]);
@@ -239,8 +245,8 @@  discard block
 block discarded – undo
239 245
 			);
240 246
 
241 247
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
242
-			if ($use_permissions)
243
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
248
+			if ($use_permissions) {
249
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
244 250
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
245 251
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
246 252
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -248,9 +254,10 @@  discard block
 block discarded – undo
248 254
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
249 255
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
250 256
 				));
257
+			}
251 258
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
252
-			else
253
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
259
+			else {
260
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
254 261
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
255 262
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
256 263
 					'can_edit' => false,
@@ -260,6 +267,7 @@  discard block
 block discarded – undo
260 267
 					'poster' => $row['id_member'],
261 268
 					'allowed_groups' => explode(',', $row['member_groups']),
262 269
 				));
270
+			}
263 271
 
264 272
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
265 273
 		}
@@ -269,8 +277,9 @@  discard block
 block discarded – undo
269 277
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
270 278
 	if ($use_permissions)
271 279
 	{
272
-		foreach ($events as $mday => $array)
273
-			$events[$mday][count($array) - 1]['is_last'] = true;
280
+		foreach ($events as $mday => $array) {
281
+					$events[$mday][count($array) - 1]['is_last'] = true;
282
+		}
274 283
 	}
275 284
 
276 285
 	ksort($events);
@@ -290,11 +299,12 @@  discard block
 block discarded – undo
290 299
 	global $smcFunc;
291 300
 
292 301
 	// Get the lowest and highest dates for "all years".
293
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
294
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
302
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
303
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
295 304
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
296
-	else
297
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
305
+	} else {
306
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
307
+	}
298 308
 
299 309
 	// Find some holidays... ;).
300 310
 	$result = $smcFunc['db_query']('', '
@@ -314,10 +324,11 @@  discard block
 block discarded – undo
314 324
 	$holidays = array();
315 325
 	while ($row = $smcFunc['db_fetch_assoc']($result))
316 326
 	{
317
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
318
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
319
-		else
320
-			$event_year = substr($low_date, 0, 4);
327
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
328
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
329
+		} else {
330
+					$event_year = substr($low_date, 0, 4);
331
+		}
321 332
 
322 333
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
323 334
 	}
@@ -343,10 +354,12 @@  discard block
 block discarded – undo
343 354
 	isAllowedTo('calendar_post');
344 355
 
345 356
 	// No board?  No topic?!?
346
-	if (empty($board))
347
-		fatal_lang_error('missing_board_id', false);
348
-	if (empty($topic))
349
-		fatal_lang_error('missing_topic_id', false);
357
+	if (empty($board)) {
358
+			fatal_lang_error('missing_board_id', false);
359
+	}
360
+	if (empty($topic)) {
361
+			fatal_lang_error('missing_topic_id', false);
362
+	}
350 363
 
351 364
 	// Administrator, Moderator, or owner.  Period.
352 365
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -364,12 +377,14 @@  discard block
 block discarded – undo
364 377
 		if ($row = $smcFunc['db_fetch_assoc']($result))
365 378
 		{
366 379
 			// Not the owner of the topic.
367
-			if ($row['id_member_started'] != $user_info['id'])
368
-				fatal_lang_error('not_your_topic', 'user');
380
+			if ($row['id_member_started'] != $user_info['id']) {
381
+							fatal_lang_error('not_your_topic', 'user');
382
+			}
369 383
 		}
370 384
 		// Topic/Board doesn't exist.....
371
-		else
372
-			fatal_lang_error('calendar_no_topic', 'general');
385
+		else {
386
+					fatal_lang_error('calendar_no_topic', 'general');
387
+		}
373 388
 		$smcFunc['db_free_result']($result);
374 389
 	}
375 390
 }
@@ -457,14 +472,16 @@  discard block
 block discarded – undo
457 472
 	if (!empty($calendarOptions['start_day']))
458 473
 	{
459 474
 		$nShift -= $calendarOptions['start_day'];
460
-		if ($nShift < 0)
461
-			$nShift = 7 + $nShift;
475
+		if ($nShift < 0) {
476
+					$nShift = 7 + $nShift;
477
+		}
462 478
 	}
463 479
 
464 480
 	// Number of rows required to fit the month.
465 481
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
466
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
467
-		$nRows++;
482
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
483
+			$nRows++;
484
+	}
468 485
 
469 486
 	// Fetch the arrays for birthdays, posted events, and holidays.
470 487
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -477,8 +494,9 @@  discard block
 block discarded – undo
477 494
 	{
478 495
 		$calendarGrid['week_days'][] = $count;
479 496
 		$count++;
480
-		if ($count == 7)
481
-			$count = 0;
497
+		if ($count == 7) {
498
+					$count = 0;
499
+		}
482 500
 	}
483 501
 
484 502
 	// Iterate through each week.
@@ -495,8 +513,9 @@  discard block
 block discarded – undo
495 513
 		{
496 514
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
497 515
 
498
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
499
-				$nDay = 0;
516
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
517
+							$nDay = 0;
518
+			}
500 519
 
501 520
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
502 521
 
@@ -514,8 +533,9 @@  discard block
 block discarded – undo
514 533
 	}
515 534
 
516 535
 	// What is the last day of the month?
517
-	if ($is_previous === true)
518
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
536
+	if ($is_previous === true) {
537
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
538
+	}
519 539
 
520 540
 	// We'll use the shift in the template.
521 541
 	$calendarGrid['shift'] = $nShift;
@@ -549,8 +569,9 @@  discard block
 block discarded – undo
549 569
 	{
550 570
 		// Here we offset accordingly to get things to the real start of a week.
551 571
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
552
-		if ($date_diff < 0)
553
-			$date_diff += 7;
572
+		if ($date_diff < 0) {
573
+					$date_diff += 7;
574
+		}
554 575
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
555 576
 		$day = (int) strftime('%d', $new_timestamp);
556 577
 		$month = (int) strftime('%m', $new_timestamp);
@@ -680,18 +701,20 @@  discard block
 block discarded – undo
680 701
 	{
681 702
 		foreach ($date_events as $event_key => $event_val)
682 703
 		{
683
-			if (in_array($event_val['id'], $temp))
684
-				unset($calendarGrid['events'][$date][$event_key]);
685
-			else
686
-				$temp[] = $event_val['id'];
704
+			if (in_array($event_val['id'], $temp)) {
705
+							unset($calendarGrid['events'][$date][$event_key]);
706
+			} else {
707
+							$temp[] = $event_val['id'];
708
+			}
687 709
 		}
688 710
 	}
689 711
 
690 712
 	// Give birthdays and holidays a friendly format, without the year
691
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
692
-		$date_format = '%b %d';
693
-	else
694
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
713
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
714
+			$date_format = '%b %d';
715
+	} else {
716
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
717
+	}
695 718
 
696 719
 	foreach (array('birthdays', 'holidays') as $type)
697 720
 	{
@@ -786,8 +809,9 @@  discard block
 block discarded – undo
786 809
 	// Holidays between now and now + days.
787 810
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
788 811
 	{
789
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
790
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
812
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
813
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
814
+		}
791 815
 	}
792 816
 
793 817
 	// Happy Birthday, guys and gals!
@@ -796,8 +820,9 @@  discard block
 block discarded – undo
796 820
 		$loop_date = strftime('%Y-%m-%d', $i);
797 821
 		if (isset($cached_data['birthdays'][$loop_date]))
798 822
 		{
799
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
800
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
823
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
824
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
825
+			}
801 826
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
802 827
 		}
803 828
 	}
@@ -809,8 +834,9 @@  discard block
 block discarded – undo
809 834
 		$loop_date = strftime('%Y-%m-%d', $i);
810 835
 
811 836
 		// No events today? Check the next day.
812
-		if (empty($cached_data['events'][$loop_date]))
813
-			continue;
837
+		if (empty($cached_data['events'][$loop_date])) {
838
+					continue;
839
+		}
814 840
 
815 841
 		// Loop through all events to add a few last-minute values.
816 842
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -823,9 +849,9 @@  discard block
 block discarded – undo
823 849
 			{
824 850
 				unset($cached_data['events'][$loop_date][$ev]);
825 851
 				continue;
852
+			} else {
853
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
826 854
 			}
827
-			else
828
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
829 855
 
830 856
 			// Might be set to true afterwards, depending on the permissions.
831 857
 			$this_event['can_edit'] = false;
@@ -833,15 +859,18 @@  discard block
 block discarded – undo
833 859
 			$this_event['date'] = $loop_date;
834 860
 		}
835 861
 
836
-		if (!empty($cached_data['events'][$loop_date]))
837
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
862
+		if (!empty($cached_data['events'][$loop_date])) {
863
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
864
+		}
838 865
 	}
839 866
 
840 867
 	// Mark the last item so that a list separator can be used in the template.
841
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
842
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
843
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
844
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
868
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
869
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
870
+	}
871
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
872
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
873
+	}
845 874
 
846 875
 	return array(
847 876
 		'data' => $return_data,
@@ -889,37 +918,46 @@  discard block
 block discarded – undo
889 918
 		if (isset($_POST['start_date']))
890 919
 		{
891 920
 			$d = date_parse($_POST['start_date']);
892
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
893
-				fatal_lang_error('invalid_date', false);
894
-			if (empty($d['year']))
895
-				fatal_lang_error('event_year_missing', false);
896
-			if (empty($d['month']))
897
-				fatal_lang_error('event_month_missing', false);
898
-		}
899
-		elseif (isset($_POST['start_datetime']))
921
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
922
+							fatal_lang_error('invalid_date', false);
923
+			}
924
+			if (empty($d['year'])) {
925
+							fatal_lang_error('event_year_missing', false);
926
+			}
927
+			if (empty($d['month'])) {
928
+							fatal_lang_error('event_month_missing', false);
929
+			}
930
+		} elseif (isset($_POST['start_datetime']))
900 931
 		{
901 932
 			$d = date_parse($_POST['start_datetime']);
902
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
903
-				fatal_lang_error('invalid_date', false);
904
-			if (empty($d['year']))
905
-				fatal_lang_error('event_year_missing', false);
906
-			if (empty($d['month']))
907
-				fatal_lang_error('event_month_missing', false);
933
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
934
+							fatal_lang_error('invalid_date', false);
935
+			}
936
+			if (empty($d['year'])) {
937
+							fatal_lang_error('event_year_missing', false);
938
+			}
939
+			if (empty($d['month'])) {
940
+							fatal_lang_error('event_month_missing', false);
941
+			}
908 942
 		}
909 943
 		// The 2.0 way
910 944
 		else
911 945
 		{
912 946
 			// No month?  No year?
913
-			if (!isset($_POST['month']))
914
-				fatal_lang_error('event_month_missing', false);
915
-			if (!isset($_POST['year']))
916
-				fatal_lang_error('event_year_missing', false);
947
+			if (!isset($_POST['month'])) {
948
+							fatal_lang_error('event_month_missing', false);
949
+			}
950
+			if (!isset($_POST['year'])) {
951
+							fatal_lang_error('event_year_missing', false);
952
+			}
917 953
 
918 954
 			// Check the month and year...
919
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
920
-				fatal_lang_error('invalid_month', false);
921
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
922
-				fatal_lang_error('invalid_year', false);
955
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
956
+							fatal_lang_error('invalid_month', false);
957
+			}
958
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
959
+							fatal_lang_error('invalid_year', false);
960
+			}
923 961
 		}
924 962
 	}
925 963
 
@@ -929,8 +967,9 @@  discard block
 block discarded – undo
929 967
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
930 968
 	if (isset($_POST['span']))
931 969
 	{
932
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
933
-			fatal_lang_error('invalid_days_numb', false);
970
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
971
+					fatal_lang_error('invalid_days_numb', false);
972
+		}
934 973
 	}
935 974
 
936 975
 	// There is no need to validate the following values if we are just deleting the event.
@@ -940,24 +979,29 @@  discard block
 block discarded – undo
940 979
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
941 980
 		{
942 981
 			// No day?
943
-			if (!isset($_POST['day']))
944
-				fatal_lang_error('event_day_missing', false);
982
+			if (!isset($_POST['day'])) {
983
+							fatal_lang_error('event_day_missing', false);
984
+			}
945 985
 
946 986
 			// Bad day?
947
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
948
-				fatal_lang_error('invalid_date', false);
987
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
988
+							fatal_lang_error('invalid_date', false);
989
+			}
949 990
 		}
950 991
 
951
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
952
-			fatal_lang_error('event_title_missing', false);
953
-		elseif (!isset($_POST['evtitle']))
954
-			$_POST['evtitle'] = $_POST['subject'];
992
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
993
+					fatal_lang_error('event_title_missing', false);
994
+		} elseif (!isset($_POST['evtitle'])) {
995
+					$_POST['evtitle'] = $_POST['subject'];
996
+		}
955 997
 
956 998
 		// No title?
957
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
958
-			fatal_lang_error('no_event_title', false);
959
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
960
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
999
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
1000
+					fatal_lang_error('no_event_title', false);
1001
+		}
1002
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
1003
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
1004
+		}
961 1005
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
962 1006
 	}
963 1007
 }
@@ -984,8 +1028,9 @@  discard block
 block discarded – undo
984 1028
 	);
985 1029
 
986 1030
 	// No results, return false.
987
-	if ($smcFunc['db_num_rows'] === 0)
988
-		return false;
1031
+	if ($smcFunc['db_num_rows'] === 0) {
1032
+			return false;
1033
+	}
989 1034
 
990 1035
 	// Grab the results and return.
991 1036
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1119,8 +1164,9 @@  discard block
 block discarded – undo
1119 1164
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1120 1165
 
1121 1166
 	$column_clauses = array();
1122
-	foreach ($event_columns as $col => $crit)
1123
-		$column_clauses[] = $col . ' = ' . $crit;
1167
+	foreach ($event_columns as $col => $crit) {
1168
+			$column_clauses[] = $col . ' = ' . $crit;
1169
+	}
1124 1170
 
1125 1171
 	$smcFunc['db_query']('', '
1126 1172
 		UPDATE {db_prefix}calendar
@@ -1205,8 +1251,9 @@  discard block
 block discarded – undo
1205 1251
 	);
1206 1252
 
1207 1253
 	// If nothing returned, we are in poo, poo.
1208
-	if ($smcFunc['db_num_rows']($request) === 0)
1209
-		return false;
1254
+	if ($smcFunc['db_num_rows']($request) === 0) {
1255
+			return false;
1256
+	}
1210 1257
 
1211 1258
 	$row = $smcFunc['db_fetch_assoc']($request);
1212 1259
 	$smcFunc['db_free_result']($request);
@@ -1214,8 +1261,9 @@  discard block
 block discarded – undo
1214 1261
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1215 1262
 
1216 1263
 	// Sanity check
1217
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1218
-		return false;
1264
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1265
+			return false;
1266
+	}
1219 1267
 
1220 1268
 	$return_value = array(
1221 1269
 		'boards' => array(),
@@ -1352,24 +1400,27 @@  discard block
 block discarded – undo
1352 1400
 
1353 1401
 	// Set $span, in case we need it
1354 1402
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1355
-	if ($span > 0)
1356
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1403
+	if ($span > 0) {
1404
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1405
+	}
1357 1406
 
1358 1407
 	// Define the timezone for this event, falling back to the default if not provided
1359
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1360
-		$tz = $eventOptions['tz'];
1361
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1362
-		$tz = $_POST['tz'];
1363
-	else
1364
-		$tz = getUserTimezone();
1408
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1409
+			$tz = $eventOptions['tz'];
1410
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1411
+			$tz = $_POST['tz'];
1412
+	} else {
1413
+			$tz = getUserTimezone();
1414
+	}
1365 1415
 
1366 1416
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1367
-	if (isset($eventOptions['allday']))
1368
-		$allday = $eventOptions['allday'];
1369
-	elseif (empty($_POST['allday']))
1370
-		$allday = false;
1371
-	else
1372
-		$allday = true;
1417
+	if (isset($eventOptions['allday'])) {
1418
+			$allday = $eventOptions['allday'];
1419
+	} elseif (empty($_POST['allday'])) {
1420
+			$allday = false;
1421
+	} else {
1422
+			$allday = true;
1423
+	}
1373 1424
 
1374 1425
 	// Input might come as individual parameters...
1375 1426
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1396,10 +1447,12 @@  discard block
 block discarded – undo
1396 1447
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1397 1448
 
1398 1449
 	// If the date and time were given in separate strings, combine them
1399
-	if (empty($start_string) && isset($start_date_string))
1400
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1401
-	if (empty($end_string) && isset($end_date_string))
1402
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1450
+	if (empty($start_string) && isset($start_date_string)) {
1451
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1452
+	}
1453
+	if (empty($end_string) && isset($end_date_string)) {
1454
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1455
+	}
1403 1456
 
1404 1457
 	// If some form of string input was given, override individually defined options with it
1405 1458
 	if (isset($start_string))
@@ -1490,10 +1543,11 @@  discard block
 block discarded – undo
1490 1543
 	if ($start_object >= $end_object)
1491 1544
 	{
1492 1545
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1493
-		if ($span > 0)
1494
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1495
-		else
1496
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1546
+		if ($span > 0) {
1547
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1548
+		} else {
1549
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1550
+		}
1497 1551
 	}
1498 1552
 
1499 1553
 	// Is $end_object too late?
@@ -1506,9 +1560,9 @@  discard block
 block discarded – undo
1506 1560
 			{
1507 1561
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1508 1562
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1563
+			} else {
1564
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1509 1565
 			}
1510
-			else
1511
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1512 1566
 		}
1513 1567
 	}
1514 1568
 
@@ -1521,8 +1575,7 @@  discard block
 block discarded – undo
1521 1575
 		$start_time = null;
1522 1576
 		$end_time = null;
1523 1577
 		$tz = null;
1524
-	}
1525
-	else
1578
+	} else
1526 1579
 	{
1527 1580
 		$start_time = date_format($start_object, 'H:i:s');
1528 1581
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1548,19 +1601,21 @@  discard block
 block discarded – undo
1548 1601
 	// First, try to create a better date format, ignoring the "time" elements.
1549 1602
 	if (empty($date_format))
1550 1603
 	{
1551
-		if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1552
-			$date_format = '%F';
1553
-		else
1554
-			$date_format = $matches[0];
1604
+		if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1605
+					$date_format = '%F';
1606
+		} else {
1607
+					$date_format = $matches[0];
1608
+		}
1555 1609
 	}
1556 1610
 
1557 1611
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1558 1612
 	if (empty($time_format))
1559 1613
 	{
1560
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1561
-			$time_format = '%k:%M';
1562
-		else
1563
-			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1614
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1615
+					$time_format = '%k:%M';
1616
+		} else {
1617
+					$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1618
+		}
1564 1619
 	}
1565 1620
 
1566 1621
 	// Should this be an all day event?
@@ -1570,11 +1625,13 @@  discard block
 block discarded – undo
1570 1625
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1571 1626
 
1572 1627
 	// We need to have a defined timezone in the steps below
1573
-	if (empty($row['timezone']))
1574
-		$row['timezone'] = getUserTimezone();
1628
+	if (empty($row['timezone'])) {
1629
+			$row['timezone'] = getUserTimezone();
1630
+	}
1575 1631
 
1576
-	if (empty($timezone_array[$row['timezone']]))
1577
-		$timezone_array[$row['timezone']] = timezone_open($row['timezone']);
1632
+	if (empty($timezone_array[$row['timezone']])) {
1633
+			$timezone_array[$row['timezone']] = timezone_open($row['timezone']);
1634
+	}
1578 1635
 
1579 1636
 	// Get most of the standard date information for the start and end datetimes
1580 1637
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1622,8 +1679,9 @@  discard block
 block discarded – undo
1622 1679
 	global $smcFunc, $context, $user_info, $modSettings, $user_settings;
1623 1680
 	static $member_cache = array();
1624 1681
 
1625
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1626
-		$id_member = $context['user']['id'];
1682
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1683
+			$id_member = $context['user']['id'];
1684
+	}
1627 1685
 
1628 1686
 	//check if the cache got the data
1629 1687
 	if (isset($id_member) && isset($member_cache[$id_member]))
@@ -1652,11 +1710,13 @@  discard block
 block discarded – undo
1652 1710
 		$smcFunc['db_free_result']($request);
1653 1711
 	}
1654 1712
 
1655
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1656
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1713
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1714
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1715
+	}
1657 1716
 
1658
-	if (isset($id_member))
1659
-		$member_cache[$id_member] = $timezone;
1717
+	if (isset($id_member)) {
1718
+			$member_cache[$id_member] = $timezone;
1719
+	}
1660 1720
 
1661 1721
 	return $timezone;
1662 1722
 }
@@ -1685,8 +1745,9 @@  discard block
 block discarded – undo
1685 1745
 		)
1686 1746
 	);
1687 1747
 	$holidays = array();
1688
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1689
-		$holidays[] = $row;
1748
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1749
+			$holidays[] = $row;
1750
+	}
1690 1751
 	$smcFunc['db_free_result']($request);
1691 1752
 
1692 1753
 	return $holidays;
Please login to merge, or discard this patch.