Completed
Pull Request — release-2.1 (#4089)
by Sebastiaan
08:14
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 3
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' => 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 = json_encode($criteria);
3835 3988
 		$actions = 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/Profile-Modify.php 2 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2183,7 +2183,7 @@  discard block
 block discarded – undo
2183 2183
  * Deletes a single or a group of alerts by ID
2184 2184
  *
2185 2185
  * @param int|array The ID of a single alert to delete or an array containing the IDs of multiple alerts. The function will convert integers into an array for better handling.
2186
- * @param bool|int $memID The user ID. Used to update the user unread alerts count.
2186
+ * @param integer $memID The user ID. Used to update the user unread alerts count.
2187 2187
  * @return void|int If the $memID param is set, returns the new amount of unread alerts.
2188 2188
  */
2189 2189
 function alert_delete($toDelete, $memID = false)
@@ -2839,7 +2839,7 @@  discard block
 block discarded – undo
2839 2839
 /**
2840 2840
  * Handles the "manage groups" section of the profile
2841 2841
  *
2842
- * @return true Always returns true
2842
+ * @return boolean Always returns true
2843 2843
  */
2844 2844
 function profileLoadGroups()
2845 2845
 {
@@ -2896,7 +2896,7 @@  discard block
 block discarded – undo
2896 2896
 /**
2897 2897
  * Load key signature context data.
2898 2898
  *
2899
- * @return true Always returns true
2899
+ * @return boolean Always returns true
2900 2900
  */
2901 2901
 function profileLoadSignatureData()
2902 2902
 {
@@ -2960,7 +2960,7 @@  discard block
 block discarded – undo
2960 2960
 /**
2961 2961
  * Load avatar context data.
2962 2962
  *
2963
- * @return true Always returns true
2963
+ * @return boolean Always returns true
2964 2964
  */
2965 2965
 function profileLoadAvatarData()
2966 2966
 {
@@ -3033,7 +3033,7 @@  discard block
 block discarded – undo
3033 3033
  * Save a members group.
3034 3034
  *
3035 3035
  * @param int &$value The ID of the (new) primary group
3036
- * @return true Always returns true
3036
+ * @return boolean Always returns true
3037 3037
  */
3038 3038
 function profileSaveGroups(&$value)
3039 3039
 {
@@ -3138,7 +3138,7 @@  discard block
 block discarded – undo
3138 3138
  * @todo argh, the avatar here. Take this out of here!
3139 3139
  *
3140 3140
  * @param string &$value What kind of avatar we're expecting. Can be 'none', 'server_stored', 'gravatar', 'external' or 'upload'
3141
- * @return bool|string False if success (or if memID is empty and password authentication failed), otherwise a string indicating what error occurred
3141
+ * @return false|string False if success (or if memID is empty and password authentication failed), otherwise a string indicating what error occurred
3142 3142
  */
3143 3143
 function profileSaveAvatarData(&$value)
3144 3144
 {
Please login to merge, or discard this patch.
Braces   +694 added lines, -518 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
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 defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '0001-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '0001-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
112
+					}
113
+				} else {
114
+									$value = '0001-01-01';
110 115
 				}
111
-				else
112
-					$value = '0001-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '0001-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '0001-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function(&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function(&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function(&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function(&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -882,9 +921,9 @@  discard block
 block discarded – undo
882 921
 	if ($context['user']['is_owner'])
883 922
 	{
884 923
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
924
+	} else {
925
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
885 926
 	}
886
-	else
887
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
888 927
 
889 928
 	// Arrays of all the changes - makes things easier.
890 929
 	$profile_bools = array();
@@ -895,22 +934,25 @@  discard block
 block discarded – undo
895 934
 		'ignore_boards',
896 935
 	);
897 936
 
898
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
899
-		$_POST['ignore_brd'] = array();
937
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
938
+			$_POST['ignore_brd'] = array();
939
+	}
900 940
 
901 941
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
902 942
 	if (isset($_POST['ignore_brd']))
903 943
 	{
904
-		if (!is_array($_POST['ignore_brd']))
905
-			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
944
+		if (!is_array($_POST['ignore_brd'])) {
945
+					$_POST['ignore_brd'] = array($_POST['ignore_brd']);
946
+		}
906 947
 
907 948
 		foreach ($_POST['ignore_brd'] as $k => $d)
908 949
 		{
909 950
 			$d = (int) $d;
910
-			if ($d != 0)
911
-				$_POST['ignore_brd'][$k] = $d;
912
-			else
913
-				unset($_POST['ignore_brd'][$k]);
951
+			if ($d != 0) {
952
+							$_POST['ignore_brd'][$k] = $d;
953
+			} else {
954
+							unset($_POST['ignore_brd'][$k]);
955
+			}
914 956
 		}
915 957
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
916 958
 		unset($_POST['ignore_brd']);
@@ -923,21 +965,26 @@  discard block
 block discarded – undo
923 965
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
924 966
 		//makeAvatarChanges($memID, $post_errors);
925 967
 
926
-		if (!empty($_REQUEST['sa']))
927
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
968
+		if (!empty($_REQUEST['sa'])) {
969
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
970
+		}
928 971
 
929
-		foreach ($profile_bools as $var)
930
-			if (isset($_POST[$var]))
972
+		foreach ($profile_bools as $var) {
973
+					if (isset($_POST[$var]))
931 974
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
932
-		foreach ($profile_ints as $var)
933
-			if (isset($_POST[$var]))
975
+		}
976
+		foreach ($profile_ints as $var) {
977
+					if (isset($_POST[$var]))
934 978
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
935
-		foreach ($profile_floats as $var)
936
-			if (isset($_POST[$var]))
979
+		}
980
+		foreach ($profile_floats as $var) {
981
+					if (isset($_POST[$var]))
937 982
 				$profile_vars[$var] = (float) $_POST[$var];
938
-		foreach ($profile_strings as $var)
939
-			if (isset($_POST[$var]))
983
+		}
984
+		foreach ($profile_strings as $var) {
985
+					if (isset($_POST[$var]))
940 986
 				$profile_vars[$var] = $_POST[$var];
987
+		}
941 988
 	}
942 989
 }
943 990
 
@@ -971,8 +1018,9 @@  discard block
 block discarded – undo
971 1018
 	);
972 1019
 
973 1020
 	// Can't change reserved vars.
974
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
975
-		fatal_lang_error('no_access', false);
1021
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1022
+			fatal_lang_error('no_access', false);
1023
+	}
976 1024
 
977 1025
 	// Don't allow any overriding of custom fields with default or non-default options.
978 1026
 	$request = $smcFunc['db_query']('', '
@@ -984,8 +1032,9 @@  discard block
 block discarded – undo
984 1032
 		)
985 1033
 	);
986 1034
 	$custom_fields = array();
987
-	while ($row = $smcFunc['db_fetch_assoc']($request))
988
-		$custom_fields[] = $row['col_name'];
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$custom_fields[] = $row['col_name'];
1037
+	}
989 1038
 	$smcFunc['db_free_result']($request);
990 1039
 
991 1040
 	// These are the theme changes...
@@ -994,33 +1043,39 @@  discard block
 block discarded – undo
994 1043
 	{
995 1044
 		foreach ($_POST['options'] as $opt => $val)
996 1045
 		{
997
-			if (in_array($opt, $custom_fields))
998
-				continue;
1046
+			if (in_array($opt, $custom_fields)) {
1047
+							continue;
1048
+			}
999 1049
 
1000 1050
 			// These need to be controlled.
1001
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1002
-				$val = max(0, min($val, 50));
1051
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1052
+							$val = max(0, min($val, 50));
1053
+			}
1003 1054
 			// We don't set this per theme anymore.
1004
-			elseif ($opt == 'allow_no_censored')
1005
-				continue;
1055
+			elseif ($opt == 'allow_no_censored') {
1056
+							continue;
1057
+			}
1006 1058
 
1007 1059
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1008 1060
 		}
1009 1061
 	}
1010 1062
 
1011 1063
 	$erase_options = array();
1012
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1013
-		foreach ($_POST['default_options'] as $opt => $val)
1064
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1065
+			foreach ($_POST['default_options'] as $opt => $val)
1014 1066
 		{
1015 1067
 			if (in_array($opt, $custom_fields))
1016 1068
 				continue;
1069
+	}
1017 1070
 
1018 1071
 			// These need to be controlled.
1019
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1020
-				$val = max(0, min($val, 50));
1072
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1073
+							$val = max(0, min($val, 50));
1074
+			}
1021 1075
 			// Only let admins and owners change the censor.
1022
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1023
-					continue;
1076
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1077
+								continue;
1078
+			}
1024 1079
 
1025 1080
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1026 1081
 			$erase_options[] = $opt;
@@ -1056,8 +1111,9 @@  discard block
 block discarded – undo
1056 1111
 
1057 1112
 		// Admins can choose any theme, even if it's not enabled...
1058 1113
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1059
-		foreach ($themes as $t)
1060
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1114
+		foreach ($themes as $t) {
1115
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1116
+		}
1061 1117
 	}
1062 1118
 }
1063 1119
 
@@ -1076,8 +1132,9 @@  discard block
 block discarded – undo
1076 1132
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1077 1133
 	{
1078 1134
 		// Make sure only integers are deleted.
1079
-		foreach ($_POST['notify_boards'] as $index => $id)
1080
-			$_POST['notify_boards'][$index] = (int) $id;
1135
+		foreach ($_POST['notify_boards'] as $index => $id) {
1136
+					$_POST['notify_boards'][$index] = (int) $id;
1137
+		}
1081 1138
 
1082 1139
 		// id_board = 0 is reserved for topic notifications.
1083 1140
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1096,8 +1153,9 @@  discard block
 block discarded – undo
1096 1153
 	// We are editing topic notifications......
1097 1154
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1098 1155
 	{
1099
-		foreach ($_POST['notify_topics'] as $index => $id)
1100
-			$_POST['notify_topics'][$index] = (int) $id;
1156
+		foreach ($_POST['notify_topics'] as $index => $id) {
1157
+					$_POST['notify_topics'][$index] = (int) $id;
1158
+		}
1101 1159
 
1102 1160
 		// Make sure there are no zeros left.
1103 1161
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1111,16 +1169,18 @@  discard block
 block discarded – undo
1111 1169
 				'selected_member' => $memID,
1112 1170
 			)
1113 1171
 		);
1114
-		foreach ($_POST['notify_topics'] as $topic)
1115
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1172
+		foreach ($_POST['notify_topics'] as $topic) {
1173
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1174
+		}
1116 1175
 	}
1117 1176
 
1118 1177
 	// We are removing topic preferences
1119 1178
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1120 1179
 	{
1121 1180
 		$prefs = array();
1122
-		foreach ($_POST['notify_topics'] as $topic)
1123
-			$prefs[] = 'topic_notify_' . $topic;
1181
+		foreach ($_POST['notify_topics'] as $topic) {
1182
+					$prefs[] = 'topic_notify_' . $topic;
1183
+		}
1124 1184
 		deleteNotifyPrefs($memID, $prefs);
1125 1185
 	}
1126 1186
 
@@ -1128,8 +1188,9 @@  discard block
 block discarded – undo
1128 1188
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1129 1189
 	{
1130 1190
 		$prefs = array();
1131
-		foreach ($_POST['notify_boards'] as $board)
1132
-			$prefs[] = 'board_notify_' . $board;
1191
+		foreach ($_POST['notify_boards'] as $board) {
1192
+					$prefs[] = 'board_notify_' . $board;
1193
+		}
1133 1194
 		deleteNotifyPrefs($memID, $prefs);
1134 1195
 	}
1135 1196
 }
@@ -1150,8 +1211,9 @@  discard block
 block discarded – undo
1150 1211
 
1151 1212
 	$errors = array();
1152 1213
 
1153
-	if ($sanitize && isset($_POST['customfield']))
1154
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1214
+	if ($sanitize && isset($_POST['customfield'])) {
1215
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1216
+	}
1155 1217
 
1156 1218
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1157 1219
 
@@ -1176,48 +1238,49 @@  discard block
 block discarded – undo
1176 1238
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1177 1239
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1178 1240
 		*/
1179
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1180
-			continue;
1241
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1242
+					continue;
1243
+		}
1181 1244
 
1182 1245
 		// Validate the user data.
1183
-		if ($row['field_type'] == 'check')
1184
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1185
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1246
+		if ($row['field_type'] == 'check') {
1247
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1248
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1186 1249
 		{
1187 1250
 			$value = $row['default_value'];
1188
-			foreach (explode(',', $row['field_options']) as $k => $v)
1189
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1251
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1252
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1190 1253
 					$value = $v;
1254
+			}
1191 1255
 		}
1192 1256
 		// Otherwise some form of text!
1193 1257
 		else
1194 1258
 		{
1195 1259
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1196
-			if ($row['field_length'])
1197
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1260
+			if ($row['field_length']) {
1261
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1262
+			}
1198 1263
 
1199 1264
 			// Any masks?
1200 1265
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
1201 1266
 			{
1202 1267
 				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1203 1268
 				{
1204
-					if ($returnErrors)
1205
-						$errors[] = 'custom_field_mail_fail';
1206
-
1207
-					else
1208
-						$value = '';
1209
-				}
1210
-				elseif ($row['mask'] == 'number')
1269
+					if ($returnErrors) {
1270
+											$errors[] = 'custom_field_mail_fail';
1271
+					} else {
1272
+											$value = '';
1273
+					}
1274
+				} elseif ($row['mask'] == 'number')
1211 1275
 				{
1212 1276
 					$value = (int) $value;
1213
-				}
1214
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1277
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1215 1278
 				{
1216
-					if ($returnErrors)
1217
-						$errors[] = 'custom_field_regex_fail';
1218
-
1219
-					else
1220
-						$value = '';
1279
+					if ($returnErrors) {
1280
+											$errors[] = 'custom_field_regex_fail';
1281
+					} else {
1282
+											$value = '';
1283
+					}
1221 1284
 				}
1222 1285
 			}
1223 1286
 		}
@@ -1243,8 +1306,9 @@  discard block
 block discarded – undo
1243 1306
 
1244 1307
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1245 1308
 
1246
-	if (!empty($hook_errors) && is_array($hook_errors))
1247
-		$errors = array_merge($errors, $hook_errors);
1309
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1310
+			$errors = array_merge($errors, $hook_errors);
1311
+	}
1248 1312
 
1249 1313
 	// Make those changes!
1250 1314
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1262,9 +1326,10 @@  discard block
 block discarded – undo
1262 1326
 		}
1263 1327
 	}
1264 1328
 
1265
-	if ($returnErrors)
1266
-		return $errors;
1267
-}
1329
+	if ($returnErrors) {
1330
+			return $errors;
1331
+	}
1332
+	}
1268 1333
 
1269 1334
 /**
1270 1335
  * Show all the users buddies, as well as a add/delete interface.
@@ -1276,8 +1341,9 @@  discard block
 block discarded – undo
1276 1341
 	global $context, $txt, $modSettings;
1277 1342
 
1278 1343
 	// Do a quick check to ensure people aren't getting here illegally!
1279
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1280
-		fatal_lang_error('no_access', false);
1344
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1345
+			fatal_lang_error('no_access', false);
1346
+	}
1281 1347
 
1282 1348
 	// Can we email the user direct?
1283 1349
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1307,9 +1373,10 @@  discard block
 block discarded – undo
1307 1373
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1308 1374
 	$call = call_helper($subActions[$context['list_area']][0], true);
1309 1375
 
1310
-	if (!empty($call))
1311
-		call_user_func($call, $memID);
1312
-}
1376
+	if (!empty($call)) {
1377
+			call_user_func($call, $memID);
1378
+	}
1379
+	}
1313 1380
 
1314 1381
 /**
1315 1382
  * Show all the users buddies, as well as a add/delete interface.
@@ -1323,9 +1390,10 @@  discard block
 block discarded – undo
1323 1390
 
1324 1391
 	// For making changes!
1325 1392
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1326
-	foreach ($buddiesArray as $k => $dummy)
1327
-		if ($dummy == '')
1393
+	foreach ($buddiesArray as $k => $dummy) {
1394
+			if ($dummy == '')
1328 1395
 			unset($buddiesArray[$k]);
1396
+	}
1329 1397
 
1330 1398
 	// Removing a buddy?
1331 1399
 	if (isset($_GET['remove']))
@@ -1337,10 +1405,11 @@  discard block
 block discarded – undo
1337 1405
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1338 1406
 
1339 1407
 		// Heh, I'm lazy, do it the easy way...
1340
-		foreach ($buddiesArray as $key => $buddy)
1341
-			if ($buddy == (int) $_GET['remove'])
1408
+		foreach ($buddiesArray as $key => $buddy) {
1409
+					if ($buddy == (int) $_GET['remove'])
1342 1410
 			{
1343 1411
 				unset($buddiesArray[$key]);
1412
+		}
1344 1413
 				$_SESSION['prf-save'] = true;
1345 1414
 			}
1346 1415
 
@@ -1350,8 +1419,7 @@  discard block
 block discarded – undo
1350 1419
 
1351 1420
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1352 1421
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1353
-	}
1354
-	elseif (isset($_POST['new_buddy']))
1422
+	} elseif (isset($_POST['new_buddy']))
1355 1423
 	{
1356 1424
 		checkSession();
1357 1425
 
@@ -1364,8 +1432,9 @@  discard block
 block discarded – undo
1364 1432
 		{
1365 1433
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1366 1434
 
1367
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1368
-				unset($new_buddies[$k]);
1435
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1436
+							unset($new_buddies[$k]);
1437
+			}
1369 1438
 		}
1370 1439
 
1371 1440
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1385,16 +1454,18 @@  discard block
 block discarded – undo
1385 1454
 				)
1386 1455
 			);
1387 1456
 
1388
-			if ($smcFunc['db_num_rows']($request) != 0)
1389
-				$_SESSION['prf-save'] = true;
1457
+			if ($smcFunc['db_num_rows']($request) != 0) {
1458
+							$_SESSION['prf-save'] = true;
1459
+			}
1390 1460
 
1391 1461
 			// Add the new member to the buddies array.
1392 1462
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1393 1463
 			{
1394
-				if (in_array($row['id_member'], $buddiesArray))
1395
-					continue;
1396
-				else
1397
-					$buddiesArray[] = (int) $row['id_member'];
1464
+				if (in_array($row['id_member'], $buddiesArray)) {
1465
+									continue;
1466
+				} else {
1467
+									$buddiesArray[] = (int) $row['id_member'];
1468
+				}
1398 1469
 			}
1399 1470
 			$smcFunc['db_free_result']($request);
1400 1471
 
@@ -1424,18 +1495,20 @@  discard block
 block discarded – undo
1424 1495
 
1425 1496
 	$context['custom_pf'] = array();
1426 1497
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1427
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1428
-		if (!isset($disabled_fields[$row['col_name']]))
1498
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1499
+			if (!isset($disabled_fields[$row['col_name']]))
1429 1500
 			$context['custom_pf'][$row['col_name']] = array(
1430 1501
 				'label' => $row['field_name'],
1431 1502
 				'type' => $row['field_type'],
1432 1503
 				'bbc' => !empty($row['bbc']),
1433 1504
 				'enclose' => $row['enclose'],
1434 1505
 			);
1506
+	}
1435 1507
 
1436 1508
 	// Gotta disable the gender option.
1437
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled')
1438
-		unset($context['custom_pf']['cust_gender']);
1509
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') {
1510
+			unset($context['custom_pf']['cust_gender']);
1511
+	}
1439 1512
 
1440 1513
 	$smcFunc['db_free_result']($request);
1441 1514
 
@@ -1452,8 +1525,9 @@  discard block
 block discarded – undo
1452 1525
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1453 1526
 			)
1454 1527
 		);
1455
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1456
-			$buddies[] = $row['id_member'];
1528
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1529
+					$buddies[] = $row['id_member'];
1530
+		}
1457 1531
 		$smcFunc['db_free_result']($result);
1458 1532
 	}
1459 1533
 
@@ -1481,30 +1555,32 @@  discard block
 block discarded – undo
1481 1555
 					continue;
1482 1556
 				}
1483 1557
 
1484
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1485
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1486
-
1487
-				elseif ($column['type'] == 'check')
1488
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1558
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1559
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1560
+				} elseif ($column['type'] == 'check') {
1561
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1562
+				}
1489 1563
 
1490 1564
 				// Enclosing the user input within some other text?
1491
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1492
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1565
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1566
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1493 1567
 						'{SCRIPTURL}' => $scripturl,
1494 1568
 						'{IMAGES_URL}' => $settings['images_url'],
1495 1569
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1496 1570
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1497 1571
 					));
1572
+				}
1498 1573
 			}
1499 1574
 		}
1500 1575
 	}
1501 1576
 
1502 1577
 	if (isset($_SESSION['prf-save']))
1503 1578
 	{
1504
-		if ($_SESSION['prf-save'] === true)
1505
-			$context['saved_successful'] = true;
1506
-		else
1507
-			$context['saved_failed'] = $_SESSION['prf-save'];
1579
+		if ($_SESSION['prf-save'] === true) {
1580
+					$context['saved_successful'] = true;
1581
+		} else {
1582
+					$context['saved_failed'] = $_SESSION['prf-save'];
1583
+		}
1508 1584
 
1509 1585
 		unset($_SESSION['prf-save']);
1510 1586
 	}
@@ -1524,9 +1600,10 @@  discard block
 block discarded – undo
1524 1600
 
1525 1601
 	// For making changes!
1526 1602
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1527
-	foreach ($ignoreArray as $k => $dummy)
1528
-		if ($dummy == '')
1603
+	foreach ($ignoreArray as $k => $dummy) {
1604
+			if ($dummy == '')
1529 1605
 			unset($ignoreArray[$k]);
1606
+	}
1530 1607
 
1531 1608
 	// Removing a member from the ignore list?
1532 1609
 	if (isset($_GET['remove']))
@@ -1536,10 +1613,11 @@  discard block
 block discarded – undo
1536 1613
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1537 1614
 
1538 1615
 		// Heh, I'm lazy, do it the easy way...
1539
-		foreach ($ignoreArray as $key => $id_remove)
1540
-			if ($id_remove == (int) $_GET['remove'])
1616
+		foreach ($ignoreArray as $key => $id_remove) {
1617
+					if ($id_remove == (int) $_GET['remove'])
1541 1618
 			{
1542 1619
 				unset($ignoreArray[$key]);
1620
+		}
1543 1621
 				$_SESSION['prf-save'] = true;
1544 1622
 			}
1545 1623
 
@@ -1549,8 +1627,7 @@  discard block
 block discarded – undo
1549 1627
 
1550 1628
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1551 1629
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1552
-	}
1553
-	elseif (isset($_POST['new_ignore']))
1630
+	} elseif (isset($_POST['new_ignore']))
1554 1631
 	{
1555 1632
 		checkSession();
1556 1633
 		// Prepare the string for extraction...
@@ -1562,8 +1639,9 @@  discard block
 block discarded – undo
1562 1639
 		{
1563 1640
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1564 1641
 
1565
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1566
-				unset($new_entries[$k]);
1642
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1643
+							unset($new_entries[$k]);
1644
+			}
1567 1645
 		}
1568 1646
 
1569 1647
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1581,16 +1659,18 @@  discard block
 block discarded – undo
1581 1659
 				)
1582 1660
 			);
1583 1661
 
1584
-			if ($smcFunc['db_num_rows']($request) != 0)
1585
-				$_SESSION['prf-save'] = true;
1662
+			if ($smcFunc['db_num_rows']($request) != 0) {
1663
+							$_SESSION['prf-save'] = true;
1664
+			}
1586 1665
 
1587 1666
 			// Add the new member to the buddies array.
1588 1667
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1589 1668
 			{
1590
-				if (in_array($row['id_member'], $ignoreArray))
1591
-					continue;
1592
-				else
1593
-					$ignoreArray[] = (int) $row['id_member'];
1669
+				if (in_array($row['id_member'], $ignoreArray)) {
1670
+									continue;
1671
+				} else {
1672
+									$ignoreArray[] = (int) $row['id_member'];
1673
+				}
1594 1674
 			}
1595 1675
 			$smcFunc['db_free_result']($request);
1596 1676
 
@@ -1619,8 +1699,9 @@  discard block
 block discarded – undo
1619 1699
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1620 1700
 			)
1621 1701
 		);
1622
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1623
-			$ignored[] = $row['id_member'];
1702
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1703
+					$ignored[] = $row['id_member'];
1704
+		}
1624 1705
 		$smcFunc['db_free_result']($result);
1625 1706
 	}
1626 1707
 
@@ -1639,10 +1720,11 @@  discard block
 block discarded – undo
1639 1720
 
1640 1721
 	if (isset($_SESSION['prf-save']))
1641 1722
 	{
1642
-		if ($_SESSION['prf-save'] === true)
1643
-			$context['saved_successful'] = true;
1644
-		else
1645
-			$context['saved_failed'] = $_SESSION['prf-save'];
1723
+		if ($_SESSION['prf-save'] === true) {
1724
+					$context['saved_successful'] = true;
1725
+		} else {
1726
+					$context['saved_failed'] = $_SESSION['prf-save'];
1727
+		}
1646 1728
 
1647 1729
 		unset($_SESSION['prf-save']);
1648 1730
 	}
@@ -1658,8 +1740,9 @@  discard block
 block discarded – undo
1658 1740
 	global $context, $txt;
1659 1741
 
1660 1742
 	loadThemeOptions($memID);
1661
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1662
-		loadCustomFields($memID, 'account');
1743
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1744
+			loadCustomFields($memID, 'account');
1745
+	}
1663 1746
 
1664 1747
 	$context['sub_template'] = 'edit_options';
1665 1748
 	$context['page_desc'] = $txt['account_info'];
@@ -1686,8 +1769,9 @@  discard block
 block discarded – undo
1686 1769
 	global $context, $txt;
1687 1770
 
1688 1771
 	loadThemeOptions($memID);
1689
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1690
-		loadCustomFields($memID, 'forumprofile');
1772
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1773
+			loadCustomFields($memID, 'forumprofile');
1774
+	}
1691 1775
 
1692 1776
 	$context['sub_template'] = 'edit_options';
1693 1777
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1720,18 +1804,21 @@  discard block
 block discarded – undo
1720 1804
 	$dirs = array();
1721 1805
 	$files = array();
1722 1806
 
1723
-	if (!$dir)
1724
-		return array();
1807
+	if (!$dir) {
1808
+			return array();
1809
+	}
1725 1810
 
1726 1811
 	while ($line = $dir->read())
1727 1812
 	{
1728
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1729
-			continue;
1813
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1814
+					continue;
1815
+		}
1730 1816
 
1731
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1732
-			$dirs[] = $line;
1733
-		else
1734
-			$files[] = $line;
1817
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1818
+					$dirs[] = $line;
1819
+		} else {
1820
+					$files[] = $line;
1821
+		}
1735 1822
 	}
1736 1823
 	$dir->close();
1737 1824
 
@@ -1752,14 +1839,15 @@  discard block
 block discarded – undo
1752 1839
 	foreach ($dirs as $line)
1753 1840
 	{
1754 1841
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1755
-		if (!empty($tmp))
1756
-			$result[] = array(
1842
+		if (!empty($tmp)) {
1843
+					$result[] = array(
1757 1844
 				'filename' => $smcFunc['htmlspecialchars']($line),
1758 1845
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1759 1846
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1760 1847
 				'is_dir' => true,
1761 1848
 				'files' => $tmp
1762 1849
 		);
1850
+		}
1763 1851
 		unset($tmp);
1764 1852
 	}
1765 1853
 
@@ -1769,8 +1857,9 @@  discard block
 block discarded – undo
1769 1857
 		$extension = substr(strrchr($line, '.'), 1);
1770 1858
 
1771 1859
 		// Make sure it is an image.
1772
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1773
-			continue;
1860
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1861
+					continue;
1862
+		}
1774 1863
 
1775 1864
 		$result[] = array(
1776 1865
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1778,8 +1867,9 @@  discard block
 block discarded – undo
1778 1867
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1779 1868
 			'is_dir' => false
1780 1869
 		);
1781
-		if ($level == 1)
1782
-			$context['avatar_list'][] = $directory . '/' . $line;
1870
+		if ($level == 1) {
1871
+					$context['avatar_list'][] = $directory . '/' . $line;
1872
+		}
1783 1873
 	}
1784 1874
 
1785 1875
 	return $result;
@@ -1798,8 +1888,9 @@  discard block
 block discarded – undo
1798 1888
 	loadSubTemplate('options');
1799 1889
 
1800 1890
 	loadThemeOptions($memID);
1801
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1802
-		loadCustomFields($memID, 'theme');
1891
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1892
+			loadCustomFields($memID, 'theme');
1893
+	}
1803 1894
 
1804 1895
 	$context['sub_template'] = 'edit_options';
1805 1896
 	$context['page_desc'] = $txt['theme_info'];
@@ -1853,16 +1944,19 @@  discard block
 block discarded – undo
1853 1944
 {
1854 1945
 	global $txt, $user_profile, $context, $modSettings, $smcFunc, $sourcedir;
1855 1946
 
1856
-	if (!isset($context['token_check']))
1857
-		$context['token_check'] = 'profile-nt' . $memID;
1947
+	if (!isset($context['token_check'])) {
1948
+			$context['token_check'] = 'profile-nt' . $memID;
1949
+	}
1858 1950
 
1859 1951
 	is_not_guest();
1860
-	if (!$context['user']['is_owner'])
1861
-		isAllowedTo('profile_extra_any');
1952
+	if (!$context['user']['is_owner']) {
1953
+			isAllowedTo('profile_extra_any');
1954
+	}
1862 1955
 
1863 1956
 	// Set the post action if we're coming from the profile...
1864
-	if (!isset($context['action']))
1865
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1957
+	if (!isset($context['action'])) {
1958
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1959
+	}
1866 1960
 
1867 1961
 	// What options are set
1868 1962
 	loadThemeOptions($memID);
@@ -1949,28 +2043,34 @@  discard block
 block discarded – undo
1949 2043
 	);
1950 2044
 
1951 2045
 	// There are certain things that are disabled at the group level.
1952
-	if (empty($modSettings['cal_enabled']))
1953
-		unset($alert_types['calendar']);
2046
+	if (empty($modSettings['cal_enabled'])) {
2047
+			unset($alert_types['calendar']);
2048
+	}
1954 2049
 
1955 2050
 	// Disable paid subscriptions at group level if they're disabled
1956
-	if (empty($modSettings['paid_enabled']))
1957
-		unset($alert_types['paidsubs']);
2051
+	if (empty($modSettings['paid_enabled'])) {
2052
+			unset($alert_types['paidsubs']);
2053
+	}
1958 2054
 
1959 2055
 	// Disable membergroup requests at group level if they're disabled
1960
-	if (empty($modSettings['show_group_membership']))
1961
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2056
+	if (empty($modSettings['show_group_membership'])) {
2057
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2058
+	}
1962 2059
 
1963 2060
 	// Disable mentions if they're disabled
1964
-	if (empty($modSettings['enable_mentions']))
1965
-		unset($alert_types['msg']['msg_mention']);
2061
+	if (empty($modSettings['enable_mentions'])) {
2062
+			unset($alert_types['msg']['msg_mention']);
2063
+	}
1966 2064
 
1967 2065
 	// Disable likes if they're disabled
1968
-	if (empty($modSettings['enable_likes']))
1969
-		unset($alert_types['msg']['msg_like']);
2066
+	if (empty($modSettings['enable_likes'])) {
2067
+			unset($alert_types['msg']['msg_like']);
2068
+	}
1970 2069
 
1971 2070
 	// Disable buddy requests if they're disabled
1972
-	if (empty($modSettings['enable_buddylist']))
1973
-		unset($alert_types['members']['buddy_request']);
2071
+	if (empty($modSettings['enable_buddylist'])) {
2072
+			unset($alert_types['members']['buddy_request']);
2073
+	}
1974 2074
 
1975 2075
 	// Now, now, we could pass this through global but we should really get into the habit of
1976 2076
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -1998,15 +2098,17 @@  discard block
 block discarded – undo
1998 2098
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
1999 2099
 		}
2000 2100
 
2001
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2002
-			unset($alert_types['members']['request_group']);
2101
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2102
+					unset($alert_types['members']['request_group']);
2103
+		}
2003 2104
 
2004 2105
 		foreach ($alert_types as $group => $items)
2005 2106
 		{
2006 2107
 			foreach ($items as $alert_key => $alert_value)
2007 2108
 			{
2008
-				if (!isset($alert_value['permission']))
2009
-					continue;
2109
+				if (!isset($alert_value['permission'])) {
2110
+									continue;
2111
+				}
2010 2112
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2011 2113
 				{
2012 2114
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2014,12 +2116,14 @@  discard block
 block discarded – undo
2014 2116
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2015 2117
 				}
2016 2118
 
2017
-				if (!$perms_cache[$alert_value['permission']['name']])
2018
-					unset ($alert_types[$group][$alert_key]);
2119
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2120
+									unset ($alert_types[$group][$alert_key]);
2121
+				}
2019 2122
 			}
2020 2123
 
2021
-			if (empty($alert_types[$group]))
2022
-				unset ($alert_types[$group]);
2124
+			if (empty($alert_types[$group])) {
2125
+							unset ($alert_types[$group]);
2126
+			}
2023 2127
 		}
2024 2128
 	}
2025 2129
 
@@ -2051,9 +2155,9 @@  discard block
 block discarded – undo
2051 2155
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2052 2156
 						break;
2053 2157
 					case 'select':
2054
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2055
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2056
-						else
2158
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2159
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2160
+						} else
2057 2161
 						{
2058 2162
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2059 2163
 							$keys = array_keys($this_option['opts']);
@@ -2073,23 +2177,28 @@  discard block
 block discarded – undo
2073 2177
 				$this_value = 0;
2074 2178
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2075 2179
 				{
2076
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2077
-						$this_value |= $bitvalue;
2180
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2181
+											$this_value |= $bitvalue;
2182
+					}
2183
+				}
2184
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2185
+									$update_prefs[$item_key] = $this_value;
2078 2186
 				}
2079
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2080
-					$update_prefs[$item_key] = $this_value;
2081 2187
 			}
2082 2188
 		}
2083 2189
 
2084
-		if (!empty($_POST['opt_alert_timeout']))
2085
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2190
+		if (!empty($_POST['opt_alert_timeout'])) {
2191
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2192
+		}
2086 2193
 
2087
-		if (!empty($_POST['notify_announcements']))
2088
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2194
+		if (!empty($_POST['notify_announcements'])) {
2195
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2196
+		}
2089 2197
 
2090 2198
 		setNotifyPrefs((int) $memID, $update_prefs);
2091
-		foreach ($update_prefs as $pref => $value)
2092
-			$context['alert_prefs'][$pref] = $value;
2199
+		foreach ($update_prefs as $pref => $value) {
2200
+					$context['alert_prefs'][$pref] = $value;
2201
+		}
2093 2202
 
2094 2203
 		makeNotificationChanges($memID);
2095 2204
 
@@ -2119,8 +2228,9 @@  discard block
 block discarded – undo
2119 2228
 
2120 2229
 	// Now we're all set up.
2121 2230
 	is_not_guest();
2122
-	if (!$context['user']['is_owner'])
2123
-		fatal_error('no_access');
2231
+	if (!$context['user']['is_owner']) {
2232
+			fatal_error('no_access');
2233
+	}
2124 2234
 
2125 2235
 	checkSession('get');
2126 2236
 
@@ -2152,8 +2262,9 @@  discard block
 block discarded – undo
2152 2262
 {
2153 2263
 	global $smcFunc;
2154 2264
 
2155
-	if (empty($toMark) || empty($memID))
2156
-		return false;
2265
+	if (empty($toMark) || empty($memID)) {
2266
+			return false;
2267
+	}
2157 2268
 
2158 2269
 	$toMark = (array) $toMark;
2159 2270
 
@@ -2187,8 +2298,9 @@  discard block
 block discarded – undo
2187 2298
 {
2188 2299
 	global $smcFunc;
2189 2300
 
2190
-	if (empty($toDelete))
2191
-		return false;
2301
+	if (empty($toDelete)) {
2302
+			return false;
2303
+	}
2192 2304
 
2193 2305
 	$toDelete = (array) $toDelete;
2194 2306
 
@@ -2223,8 +2335,9 @@  discard block
 block discarded – undo
2223 2335
 {
2224 2336
 	global $smcFunc;
2225 2337
 
2226
-	if (empty($memID))
2227
-		return false;
2338
+	if (empty($memID)) {
2339
+			return false;
2340
+	}
2228 2341
 
2229 2342
 	$request = $smcFunc['db_query']('', '
2230 2343
 		SELECT id_alert
@@ -2301,8 +2414,9 @@  discard block
 block discarded – undo
2301 2414
 					{
2302 2415
 						$link = $topic['link'];
2303 2416
 
2304
-						if ($topic['new'])
2305
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2417
+						if ($topic['new']) {
2418
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2419
+						}
2306 2420
 
2307 2421
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2308 2422
 
@@ -2453,8 +2567,9 @@  discard block
 block discarded – undo
2453 2567
 					{
2454 2568
 						$link = $board['link'];
2455 2569
 
2456
-						if ($board['new'])
2457
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2570
+						if ($board['new']) {
2571
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2572
+						}
2458 2573
 
2459 2574
 						return $link;
2460 2575
 					},
@@ -2654,8 +2769,8 @@  discard block
 block discarded – undo
2654 2769
 		)
2655 2770
 	);
2656 2771
 	$notification_boards = array();
2657
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2658
-		$notification_boards[] = array(
2772
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2773
+			$notification_boards[] = array(
2659 2774
 			'id' => $row['id_board'],
2660 2775
 			'name' => $row['name'],
2661 2776
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2663,6 +2778,7 @@  discard block
 block discarded – undo
2663 2778
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2664 2779
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2665 2780
 		);
2781
+	}
2666 2782
 	$smcFunc['db_free_result']($request);
2667 2783
 
2668 2784
 	return $notification_boards;
@@ -2677,17 +2793,18 @@  discard block
 block discarded – undo
2677 2793
 {
2678 2794
 	global $context, $options, $cur_profile, $smcFunc;
2679 2795
 
2680
-	if (isset($_POST['default_options']))
2681
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2796
+	if (isset($_POST['default_options'])) {
2797
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2798
+	}
2682 2799
 
2683 2800
 	if ($context['user']['is_owner'])
2684 2801
 	{
2685 2802
 		$context['member']['options'] = $options;
2686
-		if (isset($_POST['options']) && is_array($_POST['options']))
2687
-			foreach ($_POST['options'] as $k => $v)
2803
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2804
+					foreach ($_POST['options'] as $k => $v)
2688 2805
 				$context['member']['options'][$k] = $v;
2689
-	}
2690
-	else
2806
+		}
2807
+	} else
2691 2808
 	{
2692 2809
 		$request = $smcFunc['db_query']('', '
2693 2810
 			SELECT id_member, variable, value
@@ -2708,8 +2825,9 @@  discard block
 block discarded – undo
2708 2825
 				continue;
2709 2826
 			}
2710 2827
 
2711
-			if (isset($_POST['options'][$row['variable']]))
2712
-				$row['value'] = $_POST['options'][$row['variable']];
2828
+			if (isset($_POST['options'][$row['variable']])) {
2829
+							$row['value'] = $_POST['options'][$row['variable']];
2830
+			}
2713 2831
 			$context['member']['options'][$row['variable']] = $row['value'];
2714 2832
 		}
2715 2833
 		$smcFunc['db_free_result']($request);
@@ -2717,8 +2835,9 @@  discard block
 block discarded – undo
2717 2835
 		// Load up the default theme options for any missing.
2718 2836
 		foreach ($temp as $k => $v)
2719 2837
 		{
2720
-			if (!isset($context['member']['options'][$k]))
2721
-				$context['member']['options'][$k] = $v;
2838
+			if (!isset($context['member']['options'][$k])) {
2839
+							$context['member']['options'][$k] = $v;
2840
+			}
2722 2841
 		}
2723 2842
 	}
2724 2843
 }
@@ -2733,8 +2852,9 @@  discard block
 block discarded – undo
2733 2852
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2734 2853
 
2735 2854
 	// Have the admins enabled this option?
2736
-	if (empty($modSettings['allow_ignore_boards']))
2737
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2855
+	if (empty($modSettings['allow_ignore_boards'])) {
2856
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2857
+	}
2738 2858
 
2739 2859
 	// Find all the boards this user is allowed to see.
2740 2860
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2754,12 +2874,13 @@  discard block
 block discarded – undo
2754 2874
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2755 2875
 	{
2756 2876
 		// This category hasn't been set up yet..
2757
-		if (!isset($context['categories'][$row['id_cat']]))
2758
-			$context['categories'][$row['id_cat']] = array(
2877
+		if (!isset($context['categories'][$row['id_cat']])) {
2878
+					$context['categories'][$row['id_cat']] = array(
2759 2879
 				'id' => $row['id_cat'],
2760 2880
 				'name' => $row['cat_name'],
2761 2881
 				'boards' => array()
2762 2882
 			);
2883
+		}
2763 2884
 
2764 2885
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2765 2886
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2789,18 +2910,20 @@  discard block
 block discarded – undo
2789 2910
 	}
2790 2911
 
2791 2912
 	$max_boards = ceil(count($temp_boards) / 2);
2792
-	if ($max_boards == 1)
2793
-		$max_boards = 2;
2913
+	if ($max_boards == 1) {
2914
+			$max_boards = 2;
2915
+	}
2794 2916
 
2795 2917
 	// Now, alternate them so they can be shown left and right ;).
2796 2918
 	$context['board_columns'] = array();
2797 2919
 	for ($i = 0; $i < $max_boards; $i++)
2798 2920
 	{
2799 2921
 		$context['board_columns'][] = $temp_boards[$i];
2800
-		if (isset($temp_boards[$i + $max_boards]))
2801
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2802
-		else
2803
-			$context['board_columns'][] = array();
2922
+		if (isset($temp_boards[$i + $max_boards])) {
2923
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2924
+		} else {
2925
+					$context['board_columns'][] = array();
2926
+		}
2804 2927
 	}
2805 2928
 
2806 2929
 	loadThemeOptions($memID);
@@ -2869,8 +2992,9 @@  discard block
 block discarded – undo
2869 2992
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2870 2993
 	{
2871 2994
 		// We should skip the administrator group if they don't have the admin_forum permission!
2872
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2873
-			continue;
2995
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
2996
+					continue;
2997
+		}
2874 2998
 
2875 2999
 		$context['member_groups'][$row['id_group']] = array(
2876 3000
 			'id' => $row['id_group'],
@@ -2916,16 +3040,17 @@  discard block
 block discarded – undo
2916 3040
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2917 3041
 	// Warning message for signature image limits?
2918 3042
 	$context['signature_warning'] = '';
2919
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2920
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2921
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2922
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3043
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3044
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3045
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3046
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3047
+	}
2923 3048
 
2924 3049
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2925 3050
 
2926
-	if (empty($context['do_preview']))
2927
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2928
-	else
3051
+	if (empty($context['do_preview'])) {
3052
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3053
+	} else
2929 3054
 	{
2930 3055
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2931 3056
 		$validation = profileValidateSignature($signature);
@@ -2935,8 +3060,9 @@  discard block
 block discarded – undo
2935 3060
 			$context['post_errors'] = array();
2936 3061
 		}
2937 3062
 		$context['post_errors'][] = 'signature_not_yet_saved';
2938
-		if ($validation !== true && $validation !== false)
2939
-			$context['post_errors'][] = $validation;
3063
+		if ($validation !== true && $validation !== false) {
3064
+					$context['post_errors'][] = $validation;
3065
+		}
2940 3066
 
2941 3067
 		censorText($context['member']['signature']);
2942 3068
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2946,8 +3072,9 @@  discard block
 block discarded – undo
2946 3072
 	}
2947 3073
 
2948 3074
 	// Load the spell checker?
2949
-	if ($context['show_spellchecking'])
2950
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3075
+	if ($context['show_spellchecking']) {
3076
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3077
+	}
2951 3078
 
2952 3079
 	return true;
2953 3080
 }
@@ -2981,8 +3108,7 @@  discard block
 block discarded – undo
2981 3108
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
2982 3109
 		);
2983 3110
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
2984
-	}
2985
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3111
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
2986 3112
 	{
2987 3113
 		$context['member']['avatar'] += array(
2988 3114
 			'choice' => 'upload',
@@ -2992,33 +3118,34 @@  discard block
 block discarded – undo
2992 3118
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
2993 3119
 	}
2994 3120
 	// Use "avatar_original" here so we show what the user entered even if the image proxy is enabled
2995
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
2996
-		$context['member']['avatar'] += array(
3121
+	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3122
+			$context['member']['avatar'] += array(
2997 3123
 			'choice' => 'external',
2998 3124
 			'server_pic' => 'blank.png',
2999 3125
 			'external' => $cur_profile['avatar_original']
3000 3126
 		);
3001
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3002
-		$context['member']['avatar'] += array(
3127
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3128
+			$context['member']['avatar'] += array(
3003 3129
 			'choice' => 'server_stored',
3004 3130
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3005 3131
 			'external' => 'http://'
3006 3132
 		);
3007
-	else
3008
-		$context['member']['avatar'] += array(
3133
+	} else {
3134
+			$context['member']['avatar'] += array(
3009 3135
 			'choice' => 'none',
3010 3136
 			'server_pic' => 'blank.png',
3011 3137
 			'external' => 'http://'
3012 3138
 		);
3139
+	}
3013 3140
 
3014 3141
 	// Get a list of all the avatars.
3015 3142
 	if ($context['member']['avatar']['allow_server_stored'])
3016 3143
 	{
3017 3144
 		$context['avatar_list'] = array();
3018 3145
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3146
+	} else {
3147
+			$context['avatars'] = array();
3019 3148
 	}
3020
-	else
3021
-		$context['avatars'] = array();
3022 3149
 
3023 3150
 	// Second level selected avatar...
3024 3151
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3047,19 +3174,22 @@  discard block
 block discarded – undo
3047 3174
 			)
3048 3175
 		);
3049 3176
 		$protected_groups = array(1);
3050
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3051
-			$protected_groups[] = $row['id_group'];
3177
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3178
+					$protected_groups[] = $row['id_group'];
3179
+		}
3052 3180
 		$smcFunc['db_free_result']($request);
3053 3181
 
3054 3182
 		$protected_groups = array_unique($protected_groups);
3055 3183
 	}
3056 3184
 
3057 3185
 	// The account page allows the change of your id_group - but not to a protected group!
3058
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3059
-		$value = (int) $value;
3186
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3187
+			$value = (int) $value;
3188
+	}
3060 3189
 	// ... otherwise it's the old group sir.
3061
-	else
3062
-		$value = $old_profile['id_group'];
3190
+	else {
3191
+			$value = $old_profile['id_group'];
3192
+	}
3063 3193
 
3064 3194
 	// Find the additional membergroups (if any)
3065 3195
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3068,16 +3198,18 @@  discard block
 block discarded – undo
3068 3198
 		foreach ($_POST['additional_groups'] as $group_id)
3069 3199
 		{
3070 3200
 			$group_id = (int) $group_id;
3071
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3072
-				$additional_groups[] = $group_id;
3201
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3202
+							$additional_groups[] = $group_id;
3203
+			}
3073 3204
 		}
3074 3205
 
3075 3206
 		// Put the protected groups back in there if you don't have permission to take them away.
3076 3207
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3077 3208
 		foreach ($old_additional_groups as $group_id)
3078 3209
 		{
3079
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3080
-				$additional_groups[] = $group_id;
3210
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3211
+							$additional_groups[] = $group_id;
3212
+			}
3081 3213
 		}
3082 3214
 
3083 3215
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3109,18 +3241,20 @@  discard block
 block discarded – undo
3109 3241
 			list ($another) = $smcFunc['db_fetch_row']($request);
3110 3242
 			$smcFunc['db_free_result']($request);
3111 3243
 
3112
-			if (empty($another))
3113
-				fatal_lang_error('at_least_one_admin', 'critical');
3244
+			if (empty($another)) {
3245
+							fatal_lang_error('at_least_one_admin', 'critical');
3246
+			}
3114 3247
 		}
3115 3248
 	}
3116 3249
 
3117 3250
 	// If we are changing group status, update permission cache as necessary.
3118 3251
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3119 3252
 	{
3120
-		if ($context['user']['is_owner'])
3121
-			$_SESSION['mc']['time'] = 0;
3122
-		else
3123
-			updateSettings(array('settings_updated' => time()));
3253
+		if ($context['user']['is_owner']) {
3254
+					$_SESSION['mc']['time'] = 0;
3255
+		} else {
3256
+					updateSettings(array('settings_updated' => time()));
3257
+		}
3124 3258
 	}
3125 3259
 
3126 3260
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3141,8 +3275,9 @@  discard block
 block discarded – undo
3141 3275
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3142 3276
 
3143 3277
 	$memID = $context['id_member'];
3144
-	if (empty($memID) && !empty($context['password_auth_failed']))
3145
-		return false;
3278
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3279
+			return false;
3280
+	}
3146 3281
 
3147 3282
 	require_once($sourcedir . '/ManageAttachments.php');
3148 3283
 
@@ -3153,8 +3288,9 @@  discard block
 block discarded – undo
3153 3288
 	$downloadedExternalAvatar = false;
3154 3289
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3155 3290
 	{
3156
-		if (!is_writable($uploadDir))
3157
-			fatal_lang_error('attachments_no_write', 'critical');
3291
+		if (!is_writable($uploadDir)) {
3292
+					fatal_lang_error('attachments_no_write', 'critical');
3293
+		}
3158 3294
 
3159 3295
 		require_once($sourcedir . '/Subs-Package.php');
3160 3296
 
@@ -3198,19 +3334,18 @@  discard block
 block discarded – undo
3198 3334
 
3199 3335
 		// Get rid of their old avatar. (if uploaded.)
3200 3336
 		removeAttachments(array('id_member' => $memID));
3201
-	}
3202
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3337
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3203 3338
 	{
3204 3339
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3205
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3206
-			$profile_vars['avatar'] = 'gravatar://';
3207
-		else
3208
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3340
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3341
+					$profile_vars['avatar'] = 'gravatar://';
3342
+		} else {
3343
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3344
+		}
3209 3345
 
3210 3346
 		// Get rid of their old avatar. (if uploaded.)
3211 3347
 		removeAttachments(array('id_member' => $memID));
3212
-	}
3213
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3348
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3214 3349
 	{
3215 3350
 		// We need these clean...
3216 3351
 		$cur_profile['id_attach'] = 0;
@@ -3222,11 +3357,13 @@  discard block
 block discarded – undo
3222 3357
 
3223 3358
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3224 3359
 
3225
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3226
-			$profile_vars['avatar'] = '';
3360
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3361
+					$profile_vars['avatar'] = '';
3362
+		}
3227 3363
 		// Trying to make us do something we'll regret?
3228
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3229
-			return 'bad_avatar_invalid_url';
3364
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3365
+					return 'bad_avatar_invalid_url';
3366
+		}
3230 3367
 		// Should we check dimensions?
3231 3368
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3232 3369
 		{
@@ -3236,9 +3373,9 @@  discard block
 block discarded – undo
3236 3373
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3237 3374
 			{
3238 3375
 				// Houston, we have a problem. The avatar is too large!!
3239
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3240
-					return 'bad_avatar_too_large';
3241
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3376
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3377
+									return 'bad_avatar_too_large';
3378
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3242 3379
 				{
3243 3380
 					// @todo remove this if appropriate
3244 3381
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3248,26 +3385,27 @@  discard block
 block discarded – undo
3248 3385
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3249 3386
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3250 3387
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3388
+					} else {
3389
+											return 'bad_avatar';
3251 3390
 					}
3252
-					else
3253
-						return 'bad_avatar';
3254 3391
 				}
3255 3392
 			}
3256 3393
 		}
3257
-	}
3258
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3394
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3259 3395
 	{
3260 3396
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3261 3397
 		{
3262 3398
 			// Get the dimensions of the image.
3263 3399
 			if (!$downloadedExternalAvatar)
3264 3400
 			{
3265
-				if (!is_writable($uploadDir))
3266
-					fatal_lang_error('attachments_no_write', 'critical');
3401
+				if (!is_writable($uploadDir)) {
3402
+									fatal_lang_error('attachments_no_write', 'critical');
3403
+				}
3267 3404
 
3268 3405
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3269
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3270
-					fatal_lang_error('attach_timeout', 'critical');
3406
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3407
+									fatal_lang_error('attach_timeout', 'critical');
3408
+				}
3271 3409
 
3272 3410
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3273 3411
 			}
@@ -3380,17 +3518,19 @@  discard block
 block discarded – undo
3380 3518
 			$profile_vars['avatar'] = '';
3381 3519
 
3382 3520
 			// Delete any temporary file.
3383
-			if (file_exists($_FILES['attachment']['tmp_name']))
3384
-				@unlink($_FILES['attachment']['tmp_name']);
3521
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3522
+							@unlink($_FILES['attachment']['tmp_name']);
3523
+			}
3385 3524
 		}
3386 3525
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3387
-		else
3526
+		else {
3527
+					$profile_vars['avatar'] = '';
3528
+		}
3529
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3530
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3531
+	} else {
3388 3532
 			$profile_vars['avatar'] = '';
3389 3533
 	}
3390
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3391
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3392
-	else
3393
-		$profile_vars['avatar'] = '';
3394 3534
 
3395 3535
 	// Setup the profile variables so it shows things right on display!
3396 3536
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3438,9 +3578,9 @@  discard block
 block discarded – undo
3438 3578
 		$smiley_parsed = $unparsed_signature;
3439 3579
 		parsesmileys($smiley_parsed);
3440 3580
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3441
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3442
-			return 'signature_allow_smileys';
3443
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3581
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3582
+					return 'signature_allow_smileys';
3583
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3444 3584
 		{
3445 3585
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3446 3586
 			return 'signature_max_smileys';
@@ -3453,14 +3593,15 @@  discard block
 block discarded – undo
3453 3593
 			{
3454 3594
 				$limit_broke = 0;
3455 3595
 				// Attempt to allow all sizes of abuse, so to speak.
3456
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3457
-					$limit_broke = $sig_limits[7] . 'px';
3458
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3459
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3460
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3461
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3462
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3463
-					$limit_broke = 'large';
3596
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3597
+									$limit_broke = $sig_limits[7] . 'px';
3598
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3599
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3600
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3601
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3602
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3603
+									$limit_broke = 'large';
3604
+				}
3464 3605
 
3465 3606
 				if ($limit_broke)
3466 3607
 				{
@@ -3502,24 +3643,26 @@  discard block
 block discarded – undo
3502 3643
 					$width = -1; $height = -1;
3503 3644
 
3504 3645
 					// Does it have predefined restraints? Width first.
3505
-					if ($matches[6][$key])
3506
-						$matches[2][$key] = $matches[6][$key];
3646
+					if ($matches[6][$key]) {
3647
+											$matches[2][$key] = $matches[6][$key];
3648
+					}
3507 3649
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3508 3650
 					{
3509 3651
 						$width = $sig_limits[5];
3510 3652
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3653
+					} elseif ($matches[2][$key]) {
3654
+											$width = $matches[2][$key];
3511 3655
 					}
3512
-					elseif ($matches[2][$key])
3513
-						$width = $matches[2][$key];
3514 3656
 					// ... and height.
3515 3657
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3516 3658
 					{
3517 3659
 						$height = $sig_limits[6];
3518
-						if ($width != -1)
3519
-							$width = $width * ($height / $matches[4][$key]);
3660
+						if ($width != -1) {
3661
+													$width = $width * ($height / $matches[4][$key]);
3662
+						}
3663
+					} elseif ($matches[4][$key]) {
3664
+											$height = $matches[4][$key];
3520 3665
 					}
3521
-					elseif ($matches[4][$key])
3522
-						$height = $matches[4][$key];
3523 3666
 
3524 3667
 					// If the dimensions are still not fixed - we need to check the actual image.
3525 3668
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3537,21 +3680,24 @@  discard block
 block discarded – undo
3537 3680
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3538 3681
 							{
3539 3682
 								$height = $sig_limits[6];
3540
-								if ($width == -1)
3541
-									$width = $sizes[0];
3683
+								if ($width == -1) {
3684
+																	$width = $sizes[0];
3685
+								}
3542 3686
 								$width = $width * ($height / $sizes[1]);
3687
+							} elseif ($width != -1) {
3688
+															$height = $sizes[1];
3543 3689
 							}
3544
-							elseif ($width != -1)
3545
-								$height = $sizes[1];
3546 3690
 						}
3547 3691
 					}
3548 3692
 
3549 3693
 					// Did we come up with some changes? If so remake the string.
3550
-					if ($width != -1 || $height != -1)
3551
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3694
+					if ($width != -1 || $height != -1) {
3695
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3696
+					}
3697
+				}
3698
+				if (!empty($replaces)) {
3699
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3552 3700
 				}
3553
-				if (!empty($replaces))
3554
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3555 3701
 			}
3556 3702
 		}
3557 3703
 
@@ -3595,10 +3741,12 @@  discard block
 block discarded – undo
3595 3741
 	$email = strtr($email, array('&#039;' => '\''));
3596 3742
 
3597 3743
 	// Check the name and email for validity.
3598
-	if (trim($email) == '')
3599
-		return 'no_email';
3600
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3601
-		return 'bad_email';
3744
+	if (trim($email) == '') {
3745
+			return 'no_email';
3746
+	}
3747
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3748
+			return 'bad_email';
3749
+	}
3602 3750
 
3603 3751
 	// Email addresses should be and stay unique.
3604 3752
 	$request = $smcFunc['db_query']('', '
@@ -3613,8 +3761,9 @@  discard block
 block discarded – undo
3613 3761
 		)
3614 3762
 	);
3615 3763
 
3616
-	if ($smcFunc['db_num_rows']($request) > 0)
3617
-		return 'email_taken';
3764
+	if ($smcFunc['db_num_rows']($request) > 0) {
3765
+			return 'email_taken';
3766
+	}
3618 3767
 	$smcFunc['db_free_result']($request);
3619 3768
 
3620 3769
 	return true;
@@ -3627,8 +3776,9 @@  discard block
 block discarded – undo
3627 3776
 {
3628 3777
 	global $modSettings, $context, $cur_profile;
3629 3778
 
3630
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3631
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3779
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3780
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3781
+	}
3632 3782
 
3633 3783
 	loadUserSettings();
3634 3784
 	writeLog();
@@ -3644,8 +3794,9 @@  discard block
 block discarded – undo
3644 3794
 	require_once($sourcedir . '/Subs-Post.php');
3645 3795
 
3646 3796
 	// Shouldn't happen but just in case.
3647
-	if (empty($profile_vars['email_address']))
3648
-		return;
3797
+	if (empty($profile_vars['email_address'])) {
3798
+			return;
3799
+	}
3649 3800
 
3650 3801
 	$replacements = array(
3651 3802
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3668,8 +3819,9 @@  discard block
 block discarded – undo
3668 3819
 	$_SESSION['log_time'] = 0;
3669 3820
 	$_SESSION['login_' . $cookiename] = json_encode(array(0, '', 0));
3670 3821
 
3671
-	if (isset($_COOKIE[$cookiename]))
3672
-		$_COOKIE[$cookiename] = '';
3822
+	if (isset($_COOKIE[$cookiename])) {
3823
+			$_COOKIE[$cookiename] = '';
3824
+	}
3673 3825
 
3674 3826
 	loadUserSettings();
3675 3827
 
@@ -3702,11 +3854,13 @@  discard block
 block discarded – undo
3702 3854
 	$groups[] = $curMember['id_group'];
3703 3855
 
3704 3856
 	// Ensure the query doesn't croak!
3705
-	if (empty($groups))
3706
-		$groups = array(0);
3857
+	if (empty($groups)) {
3858
+			$groups = array(0);
3859
+	}
3707 3860
 	// Just to be sure...
3708
-	foreach ($groups as $k => $v)
3709
-		$groups[$k] = (int) $v;
3861
+	foreach ($groups as $k => $v) {
3862
+			$groups[$k] = (int) $v;
3863
+	}
3710 3864
 
3711 3865
 	// Get all the membergroups they can join.
3712 3866
 	$request = $smcFunc['db_query']('', '
@@ -3736,12 +3890,14 @@  discard block
 block discarded – undo
3736 3890
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3737 3891
 	{
3738 3892
 		// Can they edit their primary group?
3739
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3740
-			$context['can_edit_primary'] = true;
3893
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3894
+					$context['can_edit_primary'] = true;
3895
+		}
3741 3896
 
3742 3897
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3743
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3744
-			continue;
3898
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3899
+					continue;
3900
+		}
3745 3901
 
3746 3902
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3747 3903
 			'id' => $row['id_group'],
@@ -3770,13 +3926,15 @@  discard block
 block discarded – undo
3770 3926
 	);
3771 3927
 
3772 3928
 	// No changing primary one unless you have enough groups!
3773
-	if (count($context['groups']['member']) < 2)
3774
-		$context['can_edit_primary'] = false;
3929
+	if (count($context['groups']['member']) < 2) {
3930
+			$context['can_edit_primary'] = false;
3931
+	}
3775 3932
 
3776 3933
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3777
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3778
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3779
-}
3934
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3935
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3936
+	}
3937
+	}
3780 3938
 
3781 3939
 /**
3782 3940
  * This function actually makes all the group changes
@@ -3791,10 +3949,12 @@  discard block
 block discarded – undo
3791 3949
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3792 3950
 
3793 3951
 	// Let's be extra cautious...
3794
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3795
-		isAllowedTo('manage_membergroups');
3796
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3797
-		fatal_lang_error('no_access', false);
3952
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3953
+			isAllowedTo('manage_membergroups');
3954
+	}
3955
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3956
+			fatal_lang_error('no_access', false);
3957
+	}
3798 3958
 
3799 3959
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3800 3960
 
@@ -3813,8 +3973,9 @@  discard block
 block discarded – undo
3813 3973
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3814 3974
 
3815 3975
 	// Sanity check!!
3816
-	if ($group_id == 1)
3817
-		isAllowedTo('admin_forum');
3976
+	if ($group_id == 1) {
3977
+			isAllowedTo('admin_forum');
3978
+	}
3818 3979
 	// Protected groups too!
3819 3980
 	else
3820 3981
 	{
@@ -3831,8 +3992,9 @@  discard block
 block discarded – undo
3831 3992
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3832 3993
 		$smcFunc['db_free_result']($request);
3833 3994
 
3834
-		if ($is_protected == 1)
3835
-			isAllowedTo('admin_forum');
3995
+		if ($is_protected == 1) {
3996
+					isAllowedTo('admin_forum');
3997
+		}
3836 3998
 	}
3837 3999
 
3838 4000
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3854,36 +4016,43 @@  discard block
 block discarded – undo
3854 4016
 			$group_name = $row['group_name'];
3855 4017
 
3856 4018
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3857
-			if ($changeType == 'request' && $row['group_type'] != 2)
3858
-				fatal_lang_error('no_access', false);
4019
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4020
+							fatal_lang_error('no_access', false);
4021
+			}
3859 4022
 			// What about leaving a requestable group we are not a member of?
3860
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3861
-				fatal_lang_error('no_access', false);
3862
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3863
-				fatal_lang_error('no_access', false);
4023
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4024
+							fatal_lang_error('no_access', false);
4025
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4026
+							fatal_lang_error('no_access', false);
4027
+			}
3864 4028
 
3865 4029
 			// We can't change the primary group if this is hidden!
3866
-			if ($row['hidden'] == 2)
3867
-				$canChangePrimary = false;
4030
+			if ($row['hidden'] == 2) {
4031
+							$canChangePrimary = false;
4032
+			}
3868 4033
 		}
3869 4034
 
3870 4035
 		// If this is their old primary, can we change it?
3871
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3872
-			$canChangePrimary = 1;
4036
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4037
+					$canChangePrimary = 1;
4038
+		}
3873 4039
 
3874 4040
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3875
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3876
-			$canChangePrimary = false;
4041
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4042
+					$canChangePrimary = false;
4043
+		}
3877 4044
 
3878 4045
 		// If this is the one we are acting on, can we even act?
3879
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3880
-			$canChangePrimary = false;
4046
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4047
+					$canChangePrimary = false;
4048
+		}
3881 4049
 	}
3882 4050
 	$smcFunc['db_free_result']($request);
3883 4051
 
3884 4052
 	// Didn't find the target?
3885
-	if (!$foundTarget)
3886
-		fatal_lang_error('no_access', false);
4053
+	if (!$foundTarget) {
4054
+			fatal_lang_error('no_access', false);
4055
+	}
3887 4056
 
3888 4057
 	// Final security check, don't allow users to promote themselves to admin.
3889 4058
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3903,8 +4072,9 @@  discard block
 block discarded – undo
3903 4072
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3904 4073
 		$smcFunc['db_free_result']($request);
3905 4074
 
3906
-		if ($disallow)
3907
-			isAllowedTo('admin_forum');
4075
+		if ($disallow) {
4076
+					isAllowedTo('admin_forum');
4077
+		}
3908 4078
 	}
3909 4079
 
3910 4080
 	// If we're requesting, add the note then return.
@@ -3922,8 +4092,9 @@  discard block
 block discarded – undo
3922 4092
 				'status_open' => 0,
3923 4093
 			)
3924 4094
 		);
3925
-		if ($smcFunc['db_num_rows']($request) != 0)
3926
-			fatal_lang_error('profile_error_already_requested_group');
4095
+		if ($smcFunc['db_num_rows']($request) != 0) {
4096
+					fatal_lang_error('profile_error_already_requested_group');
4097
+		}
3927 4098
 		$smcFunc['db_free_result']($request);
3928 4099
 
3929 4100
 		// Log the request.
@@ -3957,10 +4128,11 @@  discard block
 block discarded – undo
3957 4128
 		// Are we leaving?
3958 4129
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3959 4130
 		{
3960
-			if ($old_profile['id_group'] == $group_id)
3961
-				$newPrimary = 0;
3962
-			else
3963
-				unset($addGroups[$group_id]);
4131
+			if ($old_profile['id_group'] == $group_id) {
4132
+							$newPrimary = 0;
4133
+			} else {
4134
+							unset($addGroups[$group_id]);
4135
+			}
3964 4136
 		}
3965 4137
 		// ... if not, must be joining.
3966 4138
 		else
@@ -3968,36 +4140,42 @@  discard block
 block discarded – undo
3968 4140
 			// Can we change the primary, and do we want to?
3969 4141
 			if ($canChangePrimary)
3970 4142
 			{
3971
-				if ($old_profile['id_group'] != 0)
3972
-					$addGroups[$old_profile['id_group']] = -1;
4143
+				if ($old_profile['id_group'] != 0) {
4144
+									$addGroups[$old_profile['id_group']] = -1;
4145
+				}
3973 4146
 				$newPrimary = $group_id;
3974 4147
 			}
3975 4148
 			// Otherwise it's an additional group...
3976
-			else
3977
-				$addGroups[$group_id] = -1;
4149
+			else {
4150
+							$addGroups[$group_id] = -1;
4151
+			}
3978 4152
 		}
3979 4153
 	}
3980 4154
 	// Finally, we must be setting the primary.
3981 4155
 	elseif ($canChangePrimary)
3982 4156
 	{
3983
-		if ($old_profile['id_group'] != 0)
3984
-			$addGroups[$old_profile['id_group']] = -1;
3985
-		if (isset($addGroups[$group_id]))
3986
-			unset($addGroups[$group_id]);
4157
+		if ($old_profile['id_group'] != 0) {
4158
+					$addGroups[$old_profile['id_group']] = -1;
4159
+		}
4160
+		if (isset($addGroups[$group_id])) {
4161
+					unset($addGroups[$group_id]);
4162
+		}
3987 4163
 		$newPrimary = $group_id;
3988 4164
 	}
3989 4165
 
3990 4166
 	// Finally, we can make the changes!
3991
-	foreach ($addGroups as $id => $dummy)
3992
-		if (empty($id))
4167
+	foreach ($addGroups as $id => $dummy) {
4168
+			if (empty($id))
3993 4169
 			unset($addGroups[$id]);
4170
+	}
3994 4171
 	$addGroups = implode(',', array_flip($addGroups));
3995 4172
 
3996 4173
 	// Ensure that we don't cache permissions if the group is changing.
3997
-	if ($context['user']['is_owner'])
3998
-		$_SESSION['mc']['time'] = 0;
3999
-	else
4000
-		updateSettings(array('settings_updated' => time()));
4174
+	if ($context['user']['is_owner']) {
4175
+			$_SESSION['mc']['time'] = 0;
4176
+	} else {
4177
+			updateSettings(array('settings_updated' => time()));
4178
+	}
4001 4179
 
4002 4180
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4003 4181
 
@@ -4020,8 +4198,9 @@  discard block
 block discarded – undo
4020 4198
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4021 4199
 	{
4022 4200
 		// Check to ensure we're forcing SSL for authentication
4023
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
4024
-			fatal_lang_error('login_ssl_required');
4201
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
4202
+					fatal_lang_error('login_ssl_required');
4203
+		}
4025 4204
 
4026 4205
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4027 4206
 		// we do not want too much AJAX to confuse them.
@@ -4058,8 +4237,7 @@  discard block
 block discarded – undo
4058 4237
 				$context['sub_template'] = 'tfasetup_backup';
4059 4238
 
4060 4239
 				return;
4061
-			}
4062
-			else
4240
+			} else
4063 4241
 			{
4064 4242
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4065 4243
 				$context['tfa_error'] = !$valid_code;
@@ -4067,8 +4245,7 @@  discard block
 block discarded – undo
4067 4245
 				$context['tfa_pass_value'] = $_POST['passwd'];
4068 4246
 				$context['tfa_value'] = $_POST['tfa_code'];
4069 4247
 			}
4070
-		}
4071
-		else
4248
+		} else
4072 4249
 		{
4073 4250
 			$totp = new \TOTP\Auth();
4074 4251
 			$secret = $totp->generateCode();
@@ -4078,17 +4255,16 @@  discard block
 block discarded – undo
4078 4255
 		}
4079 4256
 
4080 4257
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4081
-	}
4082
-	elseif (isset($_REQUEST['disable']))
4258
+	} elseif (isset($_REQUEST['disable']))
4083 4259
 	{
4084 4260
 		updateMemberData($memID, array(
4085 4261
 			'tfa_secret' => '',
4086 4262
 			'tfa_backup' => '',
4087 4263
 		));
4088 4264
 		redirectexit('action=profile;area=account;u=' . $memID);
4265
+	} else {
4266
+			redirectexit('action=profile;area=account;u=' . $memID);
4267
+	}
4089 4268
 	}
4090
-	else
4091
-		redirectexit('action=profile;area=account;u=' . $memID);
4092
-}
4093 4269
 
4094 4270
 ?>
4095 4271
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Profile-View.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2605,7 +2605,7 @@
 block discarded – undo
2605 2605
  * @param int $start Which item to start with (for pagination purposes)
2606 2606
  * @param int $items_per_page How many items to show on each page
2607 2607
  * @param string $sort A string indicating how to sort the results
2608
- * @param int $memID The ID of the member
2608
+ * @param string $memID The ID of the member
2609 2609
  * @return array An array of information about the user's group requests
2610 2610
  */
2611 2611
 function list_getGroupRequests($start, $items_per_page, $sort, $memID)
Please login to merge, or discard this patch.
Braces   +297 added lines, -216 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * View a summary.
@@ -23,8 +24,9 @@  discard block
 block discarded – undo
23 24
 	global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
24 25
 
25 26
 	// Attempt to load the member's profile data.
26
-	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
27
-		fatal_lang_error('not_a_user', false, 404);
27
+	if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
28
+			fatal_lang_error('not_a_user', false, 404);
29
+	}
28 30
 
29 31
 	// Set up the stuff and load the user.
30 32
 	$context += array(
@@ -49,19 +51,21 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// See if they have broken any warning levels...
51 53
 	list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
52
-	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
53
-		$context['warning_status'] = $txt['profile_warning_is_muted'];
54
-	elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
55
-		$context['warning_status'] = $txt['profile_warning_is_moderation'];
56
-	elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
57
-		$context['warning_status'] = $txt['profile_warning_is_watch'];
54
+	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
55
+			$context['warning_status'] = $txt['profile_warning_is_muted'];
56
+	} elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
57
+			$context['warning_status'] = $txt['profile_warning_is_moderation'];
58
+	} elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
59
+			$context['warning_status'] = $txt['profile_warning_is_watch'];
60
+	}
58 61
 
59 62
 	// They haven't even been registered for a full day!?
60 63
 	$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
61
-	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
62
-		$context['member']['posts_per_day'] = $txt['not_applicable'];
63
-	else
64
-		$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
64
+	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
65
+			$context['member']['posts_per_day'] = $txt['not_applicable'];
66
+	} else {
67
+			$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
68
+	}
65 69
 
66 70
 	// Set the age...
67 71
 	if (empty($context['member']['birth_date']))
@@ -70,8 +74,7 @@  discard block
 block discarded – undo
70 74
 			'age' => $txt['not_applicable'],
71 75
 			'today_is_birthday' => false
72 76
 		);
73
-	}
74
-	else
77
+	} else
75 78
 	{
76 79
 		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
77 80
 		$datearray = getdate(forum_time());
@@ -84,15 +87,16 @@  discard block
 block discarded – undo
84 87
 	if (allowedTo('moderate_forum'))
85 88
 	{
86 89
 		// Make sure it's a valid ip address; otherwise, don't bother...
87
-		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
88
-			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
89
-		else
90
-			$context['member']['hostname'] = '';
90
+		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
91
+					$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
92
+		} else {
93
+					$context['member']['hostname'] = '';
94
+		}
91 95
 
92 96
 		$context['can_see_ip'] = true;
97
+	} else {
98
+			$context['can_see_ip'] = false;
93 99
 	}
94
-	else
95
-		$context['can_see_ip'] = false;
96 100
 
97 101
 	// Are they hidden?
98 102
 	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
@@ -103,8 +107,9 @@  discard block
 block discarded – undo
103 107
 		include_once($sourcedir . '/Who.php');
104 108
 		$action = determineActions($user_profile[$memID]['url']);
105 109
 
106
-		if ($action !== false)
107
-			$context['member']['action'] = $action;
110
+		if ($action !== false) {
111
+					$context['member']['action'] = $action;
112
+		}
108 113
 	}
109 114
 
110 115
 	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
@@ -167,13 +172,15 @@  discard block
 block discarded – undo
167 172
 		{
168 173
 			// Work out what restrictions we actually have.
169 174
 			$ban_restrictions = array();
170
-			foreach (array('access', 'register', 'login', 'post') as $type)
171
-				if ($row['cannot_' . $type])
175
+			foreach (array('access', 'register', 'login', 'post') as $type) {
176
+							if ($row['cannot_' . $type])
172 177
 					$ban_restrictions[] = $txt['ban_type_' . $type];
178
+			}
173 179
 
174 180
 			// No actual ban in place?
175
-			if (empty($ban_restrictions))
176
-				continue;
181
+			if (empty($ban_restrictions)) {
182
+							continue;
183
+			}
177 184
 
178 185
 			// Prepare the link for context.
179 186
 			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
@@ -196,9 +203,10 @@  discard block
 block discarded – undo
196 203
 	$context['print_custom_fields'] = array();
197 204
 
198 205
 	// Any custom profile fields?
199
-	if (!empty($context['custom_fields']))
200
-		foreach ($context['custom_fields'] as $custom)
206
+	if (!empty($context['custom_fields'])) {
207
+			foreach ($context['custom_fields'] as $custom)
201 208
 			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
209
+	}
202 210
 
203 211
 }
204 212
 
@@ -242,14 +250,16 @@  discard block
 block discarded – undo
242 250
 		$row['extra'] = !empty($row['extra']) ? smf_json_decode($row['extra'], true) : array();
243 251
 		$alerts[$id_alert] = $row;
244 252
 
245
-		if (!empty($row['sender_id']))
246
-			$senders[] = $row['sender_id'];
253
+		if (!empty($row['sender_id'])) {
254
+					$senders[] = $row['sender_id'];
255
+		}
247 256
 	}
248 257
 	$smcFunc['db_free_result']($request);
249 258
 
250 259
 	$senders = loadMemberData($senders);
251
-	foreach ($senders as $member)
252
-		loadMemberContext($member);
260
+	foreach ($senders as $member) {
261
+			loadMemberContext($member);
262
+	}
253 263
 
254 264
 	// Now go through and actually make with the text.
255 265
 	loadLanguage('Alerts');
@@ -263,12 +273,15 @@  discard block
 block discarded – undo
263 273
 	$msgs = array();
264 274
 	foreach ($alerts as $id_alert => $alert)
265 275
 	{
266
-		if (isset($alert['extra']['board']))
267
-			$boards[$alert['extra']['board']] = $txt['board_na'];
268
-		if (isset($alert['extra']['topic']))
269
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
270
-		if ($alert['content_type'] == 'msg')
271
-			$msgs[$alert['content_id']] = $txt['topic_na'];
276
+		if (isset($alert['extra']['board'])) {
277
+					$boards[$alert['extra']['board']] = $txt['board_na'];
278
+		}
279
+		if (isset($alert['extra']['topic'])) {
280
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
281
+		}
282
+		if ($alert['content_type'] == 'msg') {
283
+					$msgs[$alert['content_id']] = $txt['topic_na'];
284
+		}
272 285
 	}
273 286
 
274 287
 	// Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up.
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 				'boards' => array_keys($boards),
284 297
 			)
285 298
 		);
286
-		while ($row = $smcFunc['db_fetch_assoc']($request))
287
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
299
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
300
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
301
+		}
288 302
 	}
289 303
 	if (!empty($topics))
290 304
 	{
@@ -299,8 +313,9 @@  discard block
 block discarded – undo
299 313
 				'topics' => array_keys($topics),
300 314
 			)
301 315
 		);
302
-		while ($row = $smcFunc['db_fetch_assoc']($request))
303
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
316
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
317
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
318
+		}
304 319
 	}
305 320
 	if (!empty($msgs))
306 321
 	{
@@ -315,26 +330,33 @@  discard block
 block discarded – undo
315 330
 				'msgs' => array_keys($msgs),
316 331
 			)
317 332
 		);
318
-		while ($row = $smcFunc['db_fetch_assoc']($request))
319
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
333
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
334
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
335
+		}
320 336
 	}
321 337
 
322 338
 	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
323 339
 	foreach ($alerts as $id_alert => $alert)
324 340
 	{
325
-		if (!empty($alert['text']))
326
-			continue;
327
-		if (isset($alert['extra']['board']))
328
-			$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
329
-		if (isset($alert['extra']['topic']))
330
-			$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
331
-		if ($alert['content_type'] == 'msg')
332
-			$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
333
-		if ($alert['content_type'] == 'profile')
334
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
335
-
336
-		if (!empty($memberContext[$alert['sender_id']]))
337
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
341
+		if (!empty($alert['text'])) {
342
+					continue;
343
+		}
344
+		if (isset($alert['extra']['board'])) {
345
+					$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
346
+		}
347
+		if (isset($alert['extra']['topic'])) {
348
+					$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
349
+		}
350
+		if ($alert['content_type'] == 'msg') {
351
+					$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
352
+		}
353
+		if ($alert['content_type'] == 'profile') {
354
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
355
+		}
356
+
357
+		if (!empty($memberContext[$alert['sender_id']])) {
358
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
359
+		}
338 360
 
339 361
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
340 362
 		if (isset($txt[$string]))
@@ -422,11 +444,11 @@  discard block
 block discarded – undo
422 444
 		checkSession('request');
423 445
 
424 446
 		// Call it!
425
-		if ($action == 'remove')
426
-			alert_delete($toMark, $memID);
427
-
428
-		else
429
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
447
+		if ($action == 'remove') {
448
+					alert_delete($toMark, $memID);
449
+		} else {
450
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
451
+		}
430 452
 
431 453
 		// Set a nice update message.
432 454
 		$_SESSION['update_message'] = true;
@@ -476,23 +498,27 @@  discard block
 block discarded – undo
476 498
 	);
477 499
 
478 500
 	// Set the page title
479
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
480
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
481
-	else
482
-		$context['page_title'] = $txt['showPosts'];
501
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
502
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
503
+	} else {
504
+			$context['page_title'] = $txt['showPosts'];
505
+	}
483 506
 
484 507
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
485 508
 
486 509
 	// Is the load average too high to allow searching just now?
487
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
488
-		fatal_lang_error('loadavg_show_posts_disabled', false);
510
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
511
+			fatal_lang_error('loadavg_show_posts_disabled', false);
512
+	}
489 513
 
490 514
 	// If we're specifically dealing with attachments use that function!
491
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
492
-		return showAttachments($memID);
515
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
516
+			return showAttachments($memID);
517
+	}
493 518
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
494
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
495
-		return showUnwatched($memID);
519
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
520
+			return showUnwatched($memID);
521
+	}
496 522
 
497 523
 	// Are we just viewing topics?
498 524
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -515,27 +541,30 @@  discard block
 block discarded – undo
515 541
 		$smcFunc['db_free_result']($request);
516 542
 
517 543
 		// Trying to remove a message that doesn't exist.
518
-		if (empty($info))
519
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
544
+		if (empty($info)) {
545
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
546
+		}
520 547
 
521 548
 		// We can be lazy, since removeMessage() will check the permissions for us.
522 549
 		require_once($sourcedir . '/RemoveTopic.php');
523 550
 		removeMessage((int) $_GET['delete']);
524 551
 
525 552
 		// Add it to the mod log.
526
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
527
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
553
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
554
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
555
+		}
528 556
 
529 557
 		// Back to... where we are now ;).
530 558
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
531 559
 	}
532 560
 
533 561
 	// Default to 10.
534
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
535
-		$_REQUEST['viewscount'] = '10';
562
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
563
+			$_REQUEST['viewscount'] = '10';
564
+	}
536 565
 
537
-	if ($context['is_topics'])
538
-		$request = $smcFunc['db_query']('', '
566
+	if ($context['is_topics']) {
567
+			$request = $smcFunc['db_query']('', '
539 568
 			SELECT COUNT(*)
540 569
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
541 570
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -548,8 +577,8 @@  discard block
 block discarded – undo
548 577
 				'board' => $board,
549 578
 			)
550 579
 		);
551
-	else
552
-		$request = $smcFunc['db_query']('', '
580
+	} else {
581
+			$request = $smcFunc['db_query']('', '
553 582
 			SELECT COUNT(*)
554 583
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
555 584
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -562,6 +591,7 @@  discard block
 block discarded – undo
562 591
 				'board' => $board,
563 592
 			)
564 593
 		);
594
+	}
565 595
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
566 596
 	$smcFunc['db_free_result']($request);
567 597
 
@@ -582,10 +612,11 @@  discard block
 block discarded – undo
582 612
 
583 613
 	$range_limit = '';
584 614
 
585
-	if ($context['is_topics'])
586
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
587
-	else
588
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
615
+	if ($context['is_topics']) {
616
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
617
+	} else {
618
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
619
+	}
589 620
 
590 621
 	$maxIndex = $maxPerPage;
591 622
 
@@ -611,9 +642,9 @@  discard block
 block discarded – undo
611 642
 		{
612 643
 			$margin *= 5;
613 644
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
645
+		} else {
646
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
614 647
 		}
615
-		else
616
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
617 648
 	}
618 649
 
619 650
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -645,8 +676,7 @@  discard block
 block discarded – undo
645 676
 					'max' => $maxIndex,
646 677
 				)
647 678
 			);
648
-		}
649
-		else
679
+		} else
650 680
 		{
651 681
 			$request = $smcFunc['db_query']('', '
652 682
 				SELECT
@@ -675,8 +705,9 @@  discard block
 block discarded – undo
675 705
 		}
676 706
 
677 707
 		// Make sure we quit this loop.
678
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
679
-			break;
708
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) {
709
+					break;
710
+		}
680 711
 		$looped = true;
681 712
 		$range_limit = '';
682 713
 	}
@@ -720,19 +751,21 @@  discard block
 block discarded – undo
720 751
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
721 752
 		);
722 753
 
723
-		if ($user_info['id'] == $row['id_member_started'])
724
-			$board_ids['own'][$row['id_board']][] = $counter;
754
+		if ($user_info['id'] == $row['id_member_started']) {
755
+					$board_ids['own'][$row['id_board']][] = $counter;
756
+		}
725 757
 		$board_ids['any'][$row['id_board']][] = $counter;
726 758
 	}
727 759
 	$smcFunc['db_free_result']($request);
728 760
 
729 761
 	// All posts were retrieved in reverse order, get them right again.
730
-	if ($reverse)
731
-		$context['posts'] = array_reverse($context['posts'], true);
762
+	if ($reverse) {
763
+			$context['posts'] = array_reverse($context['posts'], true);
764
+	}
732 765
 
733 766
 	// These are all the permissions that are different from board to board..
734
-	if ($context['is_topics'])
735
-		$permissions = array(
767
+	if ($context['is_topics']) {
768
+			$permissions = array(
736 769
 			'own' => array(
737 770
 				'post_reply_own' => 'can_reply',
738 771
 			),
@@ -740,8 +773,8 @@  discard block
 block discarded – undo
740 773
 				'post_reply_any' => 'can_reply',
741 774
 			)
742 775
 		);
743
-	else
744
-		$permissions = array(
776
+	} else {
777
+			$permissions = array(
745 778
 			'own' => array(
746 779
 				'post_reply_own' => 'can_reply',
747 780
 				'delete_own' => 'can_delete',
@@ -751,6 +784,7 @@  discard block
 block discarded – undo
751 784
 				'delete_any' => 'can_delete',
752 785
 			)
753 786
 		);
787
+	}
754 788
 
755 789
 	// For every permission in the own/any lists...
756 790
 	foreach ($permissions as $type => $list)
@@ -761,19 +795,22 @@  discard block
 block discarded – undo
761 795
 			$boards = boardsAllowedTo($permission);
762 796
 
763 797
 			// Hmm, they can do it on all boards, can they?
764
-			if (!empty($boards) && $boards[0] == 0)
765
-				$boards = array_keys($board_ids[$type]);
798
+			if (!empty($boards) && $boards[0] == 0) {
799
+							$boards = array_keys($board_ids[$type]);
800
+			}
766 801
 
767 802
 			// Now go through each board they can do the permission on.
768 803
 			foreach ($boards as $board_id)
769 804
 			{
770 805
 				// There aren't any posts displayed from this board.
771
-				if (!isset($board_ids[$type][$board_id]))
772
-					continue;
806
+				if (!isset($board_ids[$type][$board_id])) {
807
+									continue;
808
+				}
773 809
 
774 810
 				// Set the permission to true ;).
775
-				foreach ($board_ids[$type][$board_id] as $counter)
776
-					$context['posts'][$counter][$allowed] = true;
811
+				foreach ($board_ids[$type][$board_id] as $counter) {
812
+									$context['posts'][$counter][$allowed] = true;
813
+				}
777 814
 			}
778 815
 		}
779 816
 	}
@@ -804,8 +841,9 @@  discard block
 block discarded – undo
804 841
 	$boardsAllowed = boardsAllowedTo('view_attachments');
805 842
 
806 843
 	// Make sure we can't actually see anything...
807
-	if (empty($boardsAllowed))
808
-		$boardsAllowed = array(-1);
844
+	if (empty($boardsAllowed)) {
845
+			$boardsAllowed = array(-1);
846
+	}
809 847
 
810 848
 	require_once($sourcedir . '/Subs-List.php');
811 849
 
@@ -956,8 +994,8 @@  discard block
 block discarded – undo
956 994
 		)
957 995
 	);
958 996
 	$attachments = array();
959
-	while ($row = $smcFunc['db_fetch_assoc']($request))
960
-		$attachments[] = array(
997
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
998
+			$attachments[] = array(
961 999
 			'id' => $row['id_attach'],
962 1000
 			'filename' => $row['filename'],
963 1001
 			'downloads' => $row['downloads'],
@@ -969,6 +1007,7 @@  discard block
 block discarded – undo
969 1007
 			'board_name' => $row['name'],
970 1008
 			'approved' => $row['approved'],
971 1009
 		);
1010
+	}
972 1011
 
973 1012
 	$smcFunc['db_free_result']($request);
974 1013
 
@@ -1023,8 +1062,9 @@  discard block
 block discarded – undo
1023 1062
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1024 1063
 
1025 1064
 	// Only the owner can see the list (if the function is enabled of course)
1026
-	if ($user_info['id'] != $memID)
1027
-		return;
1065
+	if ($user_info['id'] != $memID) {
1066
+			return;
1067
+	}
1028 1068
 
1029 1069
 	require_once($sourcedir . '/Subs-List.php');
1030 1070
 
@@ -1170,8 +1210,9 @@  discard block
 block discarded – undo
1170 1210
 	);
1171 1211
 
1172 1212
 	$topics = array();
1173
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1174
-		$topics[] = $row['id_topic'];
1213
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1214
+			$topics[] = $row['id_topic'];
1215
+	}
1175 1216
 
1176 1217
 	$smcFunc['db_free_result']($request);
1177 1218
 
@@ -1191,8 +1232,9 @@  discard block
 block discarded – undo
1191 1232
 				'topics' => $topics,
1192 1233
 			)
1193 1234
 		);
1194
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1195
-			$topicsInfo[] = $row;
1235
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1236
+					$topicsInfo[] = $row;
1237
+		}
1196 1238
 		$smcFunc['db_free_result']($request);
1197 1239
 	}
1198 1240
 
@@ -1240,8 +1282,9 @@  discard block
 block discarded – undo
1240 1282
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1241 1283
 
1242 1284
 	// Is the load average too high to allow searching just now?
1243
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1244
-		fatal_lang_error('loadavg_userstats_disabled', false);
1285
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1286
+			fatal_lang_error('loadavg_userstats_disabled', false);
1287
+	}
1245 1288
 
1246 1289
 	// General user statistics.
1247 1290
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1399,11 +1442,13 @@  discard block
 block discarded – undo
1399 1442
 	}
1400 1443
 	$smcFunc['db_free_result']($result);
1401 1444
 
1402
-	if ($maxPosts > 0)
1403
-		for ($hour = 0; $hour < 24; $hour++)
1445
+	if ($maxPosts > 0) {
1446
+			for ($hour = 0;
1447
+	}
1448
+	$hour < 24; $hour++)
1404 1449
 		{
1405
-			if (!isset($context['posts_by_time'][$hour]))
1406
-				$context['posts_by_time'][$hour] = array(
1450
+			if (!isset($context['posts_by_time'][$hour])) {
1451
+							$context['posts_by_time'][$hour] = array(
1407 1452
 					'hour' => $hour,
1408 1453
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1409 1454
 					'posts' => 0,
@@ -1411,7 +1456,7 @@  discard block
 block discarded – undo
1411 1456
 					'relative_percent' => 0,
1412 1457
 					'is_last' => $hour == 23,
1413 1458
 				);
1414
-			else
1459
+			} else
1415 1460
 			{
1416 1461
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1417 1462
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1444,8 +1489,9 @@  discard block
 block discarded – undo
1444 1489
 
1445 1490
 	foreach ($subActions as $sa => $action)
1446 1491
 	{
1447
-		if (!allowedTo($action[2]))
1448
-			unset($subActions[$sa]);
1492
+		if (!allowedTo($action[2])) {
1493
+					unset($subActions[$sa]);
1494
+		}
1449 1495
 	}
1450 1496
 
1451 1497
 	// Create the tabs for the template.
@@ -1463,15 +1509,18 @@  discard block
 block discarded – undo
1463 1509
 	);
1464 1510
 
1465 1511
 	// Moderation must be on to track edits.
1466
-	if (empty($modSettings['userlog_enabled']))
1467
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1512
+	if (empty($modSettings['userlog_enabled'])) {
1513
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1514
+	}
1468 1515
 
1469 1516
 	// Group requests must be active to show it...
1470
-	if (empty($modSettings['show_group_membership']))
1471
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1517
+	if (empty($modSettings['show_group_membership'])) {
1518
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1519
+	}
1472 1520
 
1473
-	if (empty($subActions))
1474
-		fatal_lang_error('no_access', false);
1521
+	if (empty($subActions)) {
1522
+			fatal_lang_error('no_access', false);
1523
+	}
1475 1524
 
1476 1525
 	$keys = array_keys($subActions);
1477 1526
 	$default = array_shift($keys);
@@ -1484,9 +1533,10 @@  discard block
 block discarded – undo
1484 1533
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1485 1534
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1486 1535
 
1487
-	if (!empty($call))
1488
-		call_user_func($call, $memID);
1489
-}
1536
+	if (!empty($call)) {
1537
+			call_user_func($call, $memID);
1538
+	}
1539
+	}
1490 1540
 
1491 1541
 /**
1492 1542
  * Handles tracking a user's activity
@@ -1502,8 +1552,9 @@  discard block
 block discarded – undo
1502 1552
 	isAllowedTo('moderate_forum');
1503 1553
 
1504 1554
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1505
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1506
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1555
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1556
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1557
+	}
1507 1558
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1508 1559
 
1509 1560
 	// Set the options for the list component.
@@ -1669,8 +1720,9 @@  discard block
 block discarded – undo
1669 1720
 			)
1670 1721
 		);
1671 1722
 		$message_members = array();
1672
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1673
-			$message_members[] = $row['id_member'];
1723
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1724
+					$message_members[] = $row['id_member'];
1725
+		}
1674 1726
 		$smcFunc['db_free_result']($request);
1675 1727
 
1676 1728
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1685,8 +1737,9 @@  discard block
 block discarded – undo
1685 1737
 					'ip_list' => $ips,
1686 1738
 				)
1687 1739
 			);
1688
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1689
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1740
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1741
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1742
+			}
1690 1743
 			$smcFunc['db_free_result']($request);
1691 1744
 		}
1692 1745
 
@@ -1700,8 +1753,9 @@  discard block
 block discarded – undo
1700 1753
 				'ip_list' => $ips,
1701 1754
 			)
1702 1755
 		);
1703
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1704
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1756
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1757
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1758
+		}
1705 1759
 		$smcFunc['db_free_result']($request);
1706 1760
 	}
1707 1761
 }
@@ -1761,8 +1815,8 @@  discard block
 block discarded – undo
1761 1815
 		))
1762 1816
 	);
1763 1817
 	$error_messages = array();
1764
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1765
-		$error_messages[] = array(
1818
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1819
+			$error_messages[] = array(
1766 1820
 			'ip' => inet_dtop($row['ip']),
1767 1821
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1768 1822
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1770,6 +1824,7 @@  discard block
 block discarded – undo
1770 1824
 			'time' => timeformat($row['log_time']),
1771 1825
 			'timestamp' => forum_time(true, $row['log_time']),
1772 1826
 		);
1827
+	}
1773 1828
 	$smcFunc['db_free_result']($request);
1774 1829
 
1775 1830
 	return $error_messages;
@@ -1832,8 +1887,8 @@  discard block
 block discarded – undo
1832 1887
 		))
1833 1888
 	);
1834 1889
 	$messages = array();
1835
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1836
-		$messages[] = array(
1890
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1891
+			$messages[] = array(
1837 1892
 			'ip' => inet_dtop($row['poster_ip']),
1838 1893
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1839 1894
 			'board' => array(
@@ -1846,6 +1901,7 @@  discard block
 block discarded – undo
1846 1901
 			'time' => timeformat($row['poster_time']),
1847 1902
 			'timestamp' => forum_time(true, $row['poster_time'])
1848 1903
 		);
1904
+	}
1849 1905
 	$smcFunc['db_free_result']($request);
1850 1906
 
1851 1907
 	return $messages;
@@ -1872,19 +1928,20 @@  discard block
 block discarded – undo
1872 1928
 		$context['sub_template'] = 'trackIP';
1873 1929
 		$context['page_title'] = $txt['profile'];
1874 1930
 		$context['base_url'] = $scripturl . '?action=trackip';
1875
-	}
1876
-	else
1931
+	} else
1877 1932
 	{
1878 1933
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1879 1934
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1880 1935
 	}
1881 1936
 
1882 1937
 	// Searching?
1883
-	if (isset($_REQUEST['searchip']))
1884
-		$context['ip'] = trim($_REQUEST['searchip']);
1938
+	if (isset($_REQUEST['searchip'])) {
1939
+			$context['ip'] = trim($_REQUEST['searchip']);
1940
+	}
1885 1941
 
1886
-	if (isValidIP($context['ip']) === false)
1887
-		fatal_lang_error('invalid_tracking_ip', false);
1942
+	if (isValidIP($context['ip']) === false) {
1943
+			fatal_lang_error('invalid_tracking_ip', false);
1944
+	}
1888 1945
 
1889 1946
 	//mysql didn't support like search with varbinary
1890 1947
 	//$ip_var = str_replace('*', '%', $context['ip']);
@@ -1892,8 +1949,9 @@  discard block
 block discarded – undo
1892 1949
 	$ip_var = $context['ip'];
1893 1950
 	$ip_string = '= {inet:ip_address}';
1894 1951
 
1895
-	if (empty($context['tracking_area']))
1896
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1952
+	if (empty($context['tracking_area'])) {
1953
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1954
+	}
1897 1955
 
1898 1956
 	$request = $smcFunc['db_query']('', '
1899 1957
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1904,8 +1962,9 @@  discard block
 block discarded – undo
1904 1962
 		)
1905 1963
 	);
1906 1964
 	$context['ips'] = array();
1907
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1908
-		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1965
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1966
+			$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1967
+	}
1909 1968
 	$smcFunc['db_free_result']($request);
1910 1969
 
1911 1970
 	ksort($context['ips']);
@@ -2134,8 +2193,9 @@  discard block
 block discarded – undo
2134 2193
 		foreach ($context['whois_servers'] as $whois)
2135 2194
 		{
2136 2195
 			// Strip off the "decimal point" and anything following...
2137
-			if (in_array((int) $context['ip'], $whois['range']))
2138
-				$context['auto_whois_server'] = $whois;
2196
+			if (in_array((int) $context['ip'], $whois['range'])) {
2197
+							$context['auto_whois_server'] = $whois;
2198
+			}
2139 2199
 		}
2140 2200
 	}
2141 2201
 }
@@ -2152,10 +2212,11 @@  discard block
 block discarded – undo
2152 2212
 	// Gonna want this for the list.
2153 2213
 	require_once($sourcedir . '/Subs-List.php');
2154 2214
 
2155
-	if ($memID == 0)
2156
-		$context['base_url'] = $scripturl . '?action=trackip';
2157
-	else
2158
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2215
+	if ($memID == 0) {
2216
+			$context['base_url'] = $scripturl . '?action=trackip';
2217
+	} else {
2218
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2219
+	}
2159 2220
 
2160 2221
 	// Start with the user messages.
2161 2222
 	$listOptions = array(
@@ -2265,12 +2326,13 @@  discard block
 block discarded – undo
2265 2326
 		)
2266 2327
 	);
2267 2328
 	$logins = array();
2268
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2269
-		$logins[] = array(
2329
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2330
+			$logins[] = array(
2270 2331
 			'time' => timeformat($row['time']),
2271 2332
 			'ip' => inet_dtop($row['ip']),
2272 2333
 			'ip2' => inet_dtop($row['ip2']),
2273 2334
 		);
2335
+	}
2274 2336
 	$smcFunc['db_free_result']($request);
2275 2337
 
2276 2338
 	return $logins;
@@ -2295,11 +2357,12 @@  discard block
 block discarded – undo
2295 2357
 		)
2296 2358
 	);
2297 2359
 	$context['custom_field_titles'] = array();
2298
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2299
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2360
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2361
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2300 2362
 			'title' => $row['field_name'],
2301 2363
 			'parse_bbc' => $row['bbc'],
2302 2364
 		);
2365
+	}
2303 2366
 	$smcFunc['db_free_result']($request);
2304 2367
 
2305 2368
 	// Set the options for the error lists.
@@ -2438,19 +2501,22 @@  discard block
 block discarded – undo
2438 2501
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2439 2502
 	{
2440 2503
 		$extra = smf_json_decode($row['extra'], true);
2441
-		if (!empty($extra['applicator']))
2442
-			$members[] = $extra['applicator'];
2504
+		if (!empty($extra['applicator'])) {
2505
+					$members[] = $extra['applicator'];
2506
+		}
2443 2507
 
2444 2508
 		// Work out what the name of the action is.
2445
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2446
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2447
-		elseif (isset($txt[$row['action']]))
2448
-			$action_text = $txt[$row['action']];
2509
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2510
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2511
+		} elseif (isset($txt[$row['action']])) {
2512
+					$action_text = $txt[$row['action']];
2513
+		}
2449 2514
 		// Custom field?
2450
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2451
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2452
-		else
2453
-			$action_text = $row['action'];
2515
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2516
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2517
+		} else {
2518
+					$action_text = $row['action'];
2519
+		}
2454 2520
 
2455 2521
 		// Parse BBC?
2456 2522
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2482,13 +2548,15 @@  discard block
 block discarded – undo
2482 2548
 			)
2483 2549
 		);
2484 2550
 		$members = array();
2485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2486
-			$members[$row['id_member']] = $row['real_name'];
2551
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2552
+					$members[$row['id_member']] = $row['real_name'];
2553
+		}
2487 2554
 		$smcFunc['db_free_result']($request);
2488 2555
 
2489
-		foreach ($edits as $key => $value)
2490
-			if (isset($members[$value['id_member']]))
2556
+		foreach ($edits as $key => $value) {
2557
+					if (isset($members[$value['id_member']]))
2491 2558
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2559
+		}
2492 2560
 	}
2493 2561
 
2494 2562
 	return $edits;
@@ -2689,10 +2757,11 @@  discard block
 block discarded – undo
2689 2757
 	$context['board'] = $board;
2690 2758
 
2691 2759
 	// Determine which groups this user is in.
2692
-	if (empty($user_profile[$memID]['additional_groups']))
2693
-		$curGroups = array();
2694
-	else
2695
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2760
+	if (empty($user_profile[$memID]['additional_groups'])) {
2761
+			$curGroups = array();
2762
+	} else {
2763
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2764
+	}
2696 2765
 	$curGroups[] = $user_profile[$memID]['id_group'];
2697 2766
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2698 2767
 
@@ -2712,28 +2781,30 @@  discard block
 block discarded – undo
2712 2781
 	$context['no_access_boards'] = array();
2713 2782
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2714 2783
 	{
2715
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2716
-			$context['no_access_boards'][] = array(
2784
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2785
+					$context['no_access_boards'][] = array(
2717 2786
 				'id' => $row['id_board'],
2718 2787
 				'name' => $row['name'],
2719 2788
 				'is_last' => false,
2720 2789
 			);
2721
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2722
-			$context['boards'][$row['id_board']] = array(
2790
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2791
+					$context['boards'][$row['id_board']] = array(
2723 2792
 				'id' => $row['id_board'],
2724 2793
 				'name' => $row['name'],
2725 2794
 				'selected' => $board == $row['id_board'],
2726 2795
 				'profile' => $row['id_profile'],
2727 2796
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2728 2797
 			);
2798
+		}
2729 2799
 	}
2730 2800
 	$smcFunc['db_free_result']($request);
2731 2801
 
2732 2802
 	require_once($sourcedir . '/Subs-Boards.php');
2733 2803
 	sortBoards($context['boards']);
2734 2804
 
2735
-	if (!empty($context['no_access_boards']))
2736
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2805
+	if (!empty($context['no_access_boards'])) {
2806
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2807
+	}
2737 2808
 
2738 2809
 	$context['member']['permissions'] = array(
2739 2810
 		'general' => array(),
@@ -2742,8 +2813,9 @@  discard block
 block discarded – undo
2742 2813
 
2743 2814
 	// If you're an admin we know you can do everything, we might as well leave.
2744 2815
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2745
-	if ($context['member']['has_all_permissions'])
2746
-		return;
2816
+	if ($context['member']['has_all_permissions']) {
2817
+			return;
2818
+	}
2747 2819
 
2748 2820
 	$denied = array();
2749 2821
 
@@ -2762,21 +2834,24 @@  discard block
 block discarded – undo
2762 2834
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2763 2835
 	{
2764 2836
 		// We don't know about this permission, it doesn't exist :P.
2765
-		if (!isset($txt['permissionname_' . $row['permission']]))
2766
-			continue;
2837
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2838
+					continue;
2839
+		}
2767 2840
 
2768
-		if (empty($row['add_deny']))
2769
-			$denied[] = $row['permission'];
2841
+		if (empty($row['add_deny'])) {
2842
+					$denied[] = $row['permission'];
2843
+		}
2770 2844
 
2771 2845
 		// Permissions that end with _own or _any consist of two parts.
2772
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2773
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2774
-		else
2775
-			$name = $txt['permissionname_' . $row['permission']];
2846
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2847
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2848
+		} else {
2849
+					$name = $txt['permissionname_' . $row['permission']];
2850
+		}
2776 2851
 
2777 2852
 		// Add this permission if it doesn't exist yet.
2778
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2779
-			$context['member']['permissions']['general'][$row['permission']] = array(
2853
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2854
+					$context['member']['permissions']['general'][$row['permission']] = array(
2780 2855
 				'id' => $row['permission'],
2781 2856
 				'groups' => array(
2782 2857
 					'allowed' => array(),
@@ -2786,6 +2861,7 @@  discard block
 block discarded – undo
2786 2861
 				'is_denied' => false,
2787 2862
 				'is_global' => true,
2788 2863
 			);
2864
+		}
2789 2865
 
2790 2866
 		// Add the membergroup to either the denied or the allowed groups.
2791 2867
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2819,18 +2895,20 @@  discard block
 block discarded – undo
2819 2895
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2820 2896
 	{
2821 2897
 		// We don't know about this permission, it doesn't exist :P.
2822
-		if (!isset($txt['permissionname_' . $row['permission']]))
2823
-			continue;
2898
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2899
+					continue;
2900
+		}
2824 2901
 
2825 2902
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2826
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2827
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2828
-		else
2829
-			$name = $txt['permissionname_' . $row['permission']];
2903
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2904
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2905
+		} else {
2906
+					$name = $txt['permissionname_' . $row['permission']];
2907
+		}
2830 2908
 
2831 2909
 		// Create the structure for this permission.
2832
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2833
-			$context['member']['permissions']['board'][$row['permission']] = array(
2910
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2911
+					$context['member']['permissions']['board'][$row['permission']] = array(
2834 2912
 				'id' => $row['permission'],
2835 2913
 				'groups' => array(
2836 2914
 					'allowed' => array(),
@@ -2840,6 +2918,7 @@  discard block
 block discarded – undo
2840 2918
 				'is_denied' => false,
2841 2919
 				'is_global' => empty($board),
2842 2920
 			);
2921
+		}
2843 2922
 
2844 2923
 		$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
2845 2924
 
@@ -2858,8 +2937,9 @@  discard block
 block discarded – undo
2858 2937
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2859 2938
 
2860 2939
 	// Firstly, can we actually even be here?
2861
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2862
-		fatal_lang_error('no_access', false);
2940
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2941
+			fatal_lang_error('no_access', false);
2942
+	}
2863 2943
 
2864 2944
 	// Make sure things which are disabled stay disabled.
2865 2945
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2946,9 +3026,10 @@  discard block
 block discarded – undo
2946 3026
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2947 3027
 	);
2948 3028
 	$context['current_level'] = 0;
2949
-	foreach ($context['level_effects'] as $limit => $dummy)
2950
-		if ($context['member']['warning'] >= $limit)
3029
+	foreach ($context['level_effects'] as $limit => $dummy) {
3030
+			if ($context['member']['warning'] >= $limit)
2951 3031
 			$context['current_level'] = $limit;
2952
-}
3032
+	}
3033
+	}
2953 3034
 
2954 3035
 ?>
2955 3036
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/QueryString.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@
 block discarded – undo
325 325
  * Validates a IPv6 address. returns true if it is ipv6.
326 326
  *
327 327
  * @param string $ip The ip address to be validated
328
- * @return boolean Whether the specified IP is a valid IPv6 address
328
+ * @return false|string Whether the specified IP is a valid IPv6 address
329 329
  */
330 330
 function isValidIPv6($ip)
331 331
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -426,8 +426,8 @@
 block discarded – undo
426 426
 */
427 427
 function matchIPtoCIDR($ip_address, $cidr_address)
428 428
 {
429
-    list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
430
-    return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
429
+	list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
430
+	return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
431 431
 }
432 432
 
433 433
 /**
Please login to merge, or discard this patch.
Braces   +184 added lines, -130 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off.
@@ -44,22 +45,26 @@  discard block
 block discarded – undo
44 45
 	unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']);
45 46
 
46 47
 	// These keys shouldn't be set...ever.
47
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
48
-		die('Invalid request variable.');
48
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
49
+			die('Invalid request variable.');
50
+	}
49 51
 
50 52
 	// Same goes for numeric keys.
51
-	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key)
52
-		if (is_numeric($key))
53
+	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) {
54
+			if (is_numeric($key))
53 55
 			die('Numeric request keys are invalid.');
56
+	}
54 57
 
55 58
 	// Numeric keys in cookies are less of a problem. Just unset those.
56
-	foreach ($_COOKIE as $key => $value)
57
-		if (is_numeric($key))
59
+	foreach ($_COOKIE as $key => $value) {
60
+			if (is_numeric($key))
58 61
 			unset($_COOKIE[$key]);
62
+	}
59 63
 
60 64
 	// Get the correct query string.  It may be in an environment variable...
61
-	if (!isset($_SERVER['QUERY_STRING']))
62
-		$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
65
+	if (!isset($_SERVER['QUERY_STRING'])) {
66
+			$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
67
+	}
63 68
 
64 69
 	// It seems that sticking a URL after the query string is mighty common, well, it's evil - don't.
65 70
 	if (strpos($_SERVER['QUERY_STRING'], 'http') === 0)
@@ -83,13 +88,14 @@  discard block
 block discarded – undo
83 88
 		parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET);
84 89
 
85 90
 		// Magic quotes still applies with parse_str - so clean it up.
86
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
87
-			$_GET = $removeMagicQuoteFunction($_GET);
88
-	}
89
-	elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
91
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
92
+					$_GET = $removeMagicQuoteFunction($_GET);
93
+		}
94
+	} elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
90 95
 	{
91
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
92
-			$_GET = $removeMagicQuoteFunction($_GET);
96
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
97
+					$_GET = $removeMagicQuoteFunction($_GET);
98
+		}
93 99
 
94 100
 		// Search engines will send action=profile%3Bu=1, which confuses PHP.
95 101
 		foreach ($_GET as $k => $v)
@@ -102,8 +108,9 @@  discard block
 block discarded – undo
102 108
 				for ($i = 1, $n = count($temp); $i < $n; $i++)
103 109
 				{
104 110
 					@list ($key, $val) = @explode('=', $temp[$i], 2);
105
-					if (!isset($_GET[$key]))
106
-						$_GET[$key] = $val;
111
+					if (!isset($_GET[$key])) {
112
+											$_GET[$key] = $val;
113
+					}
107 114
 				}
108 115
 			}
109 116
 
@@ -120,18 +127,20 @@  discard block
 block discarded – undo
120 127
 	if (!empty($_SERVER['REQUEST_URI']))
121 128
 	{
122 129
 		// Remove the .html, assuming there is one.
123
-		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm')
124
-			$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
125
-		else
126
-			$request = $_SERVER['REQUEST_URI'];
130
+		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') {
131
+					$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
132
+		} else {
133
+					$request = $_SERVER['REQUEST_URI'];
134
+		}
127 135
 
128 136
 		// @todo smflib.
129 137
 		// Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET.
130 138
 		if (strpos($request, basename($scripturl) . '/') !== false)
131 139
 		{
132 140
 			parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp);
133
-			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
134
-				$temp = $removeMagicQuoteFunction($temp);
141
+			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
142
+							$temp = $removeMagicQuoteFunction($temp);
143
+			}
135 144
 			$_GET += $temp;
136 145
 		}
137 146
 	}
@@ -142,9 +151,10 @@  discard block
 block discarded – undo
142 151
 		$_ENV = $removeMagicQuoteFunction($_ENV);
143 152
 		$_POST = $removeMagicQuoteFunction($_POST);
144 153
 		$_COOKIE = $removeMagicQuoteFunction($_COOKIE);
145
-		foreach ($_FILES as $k => $dummy)
146
-			if (isset($_FILES[$k]['name']))
154
+		foreach ($_FILES as $k => $dummy) {
155
+					if (isset($_FILES[$k]['name']))
147 156
 				$_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']);
157
+		}
148 158
 	}
149 159
 
150 160
 	// Add entities to GET.  This is kinda like the slashes on everything else.
@@ -160,11 +170,13 @@  discard block
 block discarded – undo
160 170
 		$_REQUEST['board'] = (string) $_REQUEST['board'];
161 171
 
162 172
 		// If there's a slash in it, we've got a start value! (old, compatible links.)
163
-		if (strpos($_REQUEST['board'], '/') !== false)
164
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
173
+		if (strpos($_REQUEST['board'], '/') !== false) {
174
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
175
+		}
165 176
 		// Same idea, but dots.  This is the currently used format - ?board=1.0...
166
-		elseif (strpos($_REQUEST['board'], '.') !== false)
167
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
177
+		elseif (strpos($_REQUEST['board'], '.') !== false) {
178
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
179
+		}
168 180
 		// Now make absolutely sure it's a number.
169 181
 		$board = (int) $_REQUEST['board'];
170 182
 		$_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
@@ -173,12 +185,14 @@  discard block
 block discarded – undo
173 185
 		$_GET['board'] = $board;
174 186
 	}
175 187
 	// Well, $board is going to be a number no matter what.
176
-	else
177
-		$board = 0;
188
+	else {
189
+			$board = 0;
190
+	}
178 191
 
179 192
 	// If there's a threadid, it's probably an old YaBB SE link.  Flow with it.
180
-	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic']))
181
-		$_REQUEST['topic'] = $_REQUEST['threadid'];
193
+	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) {
194
+			$_REQUEST['topic'] = $_REQUEST['threadid'];
195
+	}
182 196
 
183 197
 	// We've got topic!
184 198
 	if (isset($_REQUEST['topic']))
@@ -187,29 +201,34 @@  discard block
 block discarded – undo
187 201
 		$_REQUEST['topic'] = (string) $_REQUEST['topic'];
188 202
 
189 203
 		// Slash means old, beta style, formatting.  That's okay though, the link should still work.
190
-		if (strpos($_REQUEST['topic'], '/') !== false)
191
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
204
+		if (strpos($_REQUEST['topic'], '/') !== false) {
205
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
206
+		}
192 207
 		// Dots are useful and fun ;).  This is ?topic=1.15.
193
-		elseif (strpos($_REQUEST['topic'], '.') !== false)
194
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
208
+		elseif (strpos($_REQUEST['topic'], '.') !== false) {
209
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
210
+		}
195 211
 
196 212
 		$topic = (int) $_REQUEST['topic'];
197 213
 
198 214
 		// Now make sure the online log gets the right number.
199 215
 		$_GET['topic'] = $topic;
216
+	} else {
217
+			$topic = 0;
200 218
 	}
201
-	else
202
-		$topic = 0;
203 219
 
204 220
 	// There should be a $_REQUEST['start'], some at least.  If you need to default to other than 0, use $_GET['start'].
205
-	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647)
206
-		$_REQUEST['start'] = 0;
221
+	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) {
222
+			$_REQUEST['start'] = 0;
223
+	}
207 224
 
208 225
 	// The action needs to be a string and not an array or anything else
209
-	if (isset($_REQUEST['action']))
210
-		$_REQUEST['action'] = (string) $_REQUEST['action'];
211
-	if (isset($_GET['action']))
212
-		$_GET['action'] = (string) $_GET['action'];
226
+	if (isset($_REQUEST['action'])) {
227
+			$_REQUEST['action'] = (string) $_REQUEST['action'];
228
+	}
229
+	if (isset($_GET['action'])) {
230
+			$_GET['action'] = (string) $_GET['action'];
231
+	}
213 232
 
214 233
 	// Some mail providers like to encode semicolons in activation URLs...
215 234
 	if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b')
@@ -235,29 +254,33 @@  discard block
 block discarded – undo
235 254
 	$_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR'];
236 255
 
237 256
 	// If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do.
238
-	if (!isset($modSettings['proxy_ip_header']))
239
-		$modSettings['proxy_ip_header'] = 'autodetect';
257
+	if (!isset($modSettings['proxy_ip_header'])) {
258
+			$modSettings['proxy_ip_header'] = 'autodetect';
259
+	}
240 260
 
241 261
 	// Which headers are we going to check for Reverse Proxy IP headers?
242
-	if ($modSettings['proxy_ip_header'] == 'disabled')
243
-		$reverseIPheaders = array();
244
-	elseif ($modSettings['proxy_ip_header'] == 'autodetect')
245
-		$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
246
-	else
247
-		$reverseIPheaders = array($modSettings['proxy_ip_header']);
262
+	if ($modSettings['proxy_ip_header'] == 'disabled') {
263
+			$reverseIPheaders = array();
264
+	} elseif ($modSettings['proxy_ip_header'] == 'autodetect') {
265
+			$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
266
+	} else {
267
+			$reverseIPheaders = array($modSettings['proxy_ip_header']);
268
+	}
248 269
 
249 270
 	// Find the user's IP address. (but don't let it give you 'unknown'!)
250 271
 	foreach ($reverseIPheaders as $proxyIPheader)
251 272
 	{
252 273
 		// Ignore if this is not set.
253
-		if (!isset($_SERVER[$proxyIPheader]))
254
-			continue;
274
+		if (!isset($_SERVER[$proxyIPheader])) {
275
+					continue;
276
+		}
255 277
 
256 278
 		if (!empty($modSettings['proxy_ip_servers']))
257 279
 		{
258
-			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy)
259
-				if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
280
+			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) {
281
+							if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
260 282
 					continue;
283
+			}
261 284
 		}
262 285
 
263 286
 		// If there are commas, get the last one.. probably.
@@ -277,8 +300,9 @@  discard block
 block discarded – undo
277 300
 
278 301
 						// Just incase we have a legacy IPv4 address.
279 302
 						// @ TODO: Convert to IPv6.
280
-						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
281
-							continue;
303
+						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
304
+													continue;
305
+						}
282 306
 					}
283 307
 
284 308
 					continue;
@@ -290,36 +314,40 @@  discard block
 block discarded – undo
290 314
 			}
291 315
 		}
292 316
 		// Otherwise just use the only one.
293
-		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0)
294
-			$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
295
-		elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
317
+		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) {
318
+					$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
319
+		} elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
296 320
 		{
297 321
 			$_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]);
298 322
 
299 323
 			// Just incase we have a legacy IPv4 address.
300 324
 			// @ TODO: Convert to IPv6.
301
-			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
302
-				continue;
325
+			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
326
+							continue;
327
+			}
303 328
 		}
304 329
 	}
305 330
 
306 331
 	// Make sure we know the URL of the current request.
307
-	if (empty($_SERVER['REQUEST_URI']))
308
-		$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
309
-	elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
310
-		$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
311
-	else
312
-		$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
332
+	if (empty($_SERVER['REQUEST_URI'])) {
333
+			$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
334
+	} elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) {
335
+			$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
336
+	} else {
337
+			$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
338
+	}
313 339
 
314 340
 	// And make sure HTTP_USER_AGENT is set.
315 341
 	$_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : '';
316 342
 
317 343
 	// Some final checking.
318
-	if (!isValidIP($_SERVER['BAN_CHECK_IP']))
319
-		$_SERVER['BAN_CHECK_IP'] = '';
320
-	if ($_SERVER['REMOTE_ADDR'] == 'unknown')
321
-		$_SERVER['REMOTE_ADDR'] = '';
322
-}
344
+	if (!isValidIP($_SERVER['BAN_CHECK_IP'])) {
345
+			$_SERVER['BAN_CHECK_IP'] = '';
346
+	}
347
+	if ($_SERVER['REMOTE_ADDR'] == 'unknown') {
348
+			$_SERVER['REMOTE_ADDR'] = '';
349
+	}
350
+	}
323 351
 
324 352
 /**
325 353
  * Validates a IPv6 address. returns true if it is ipv6.
@@ -330,8 +358,9 @@  discard block
 block discarded – undo
330 358
 function isValidIPv6($ip)
331 359
 {
332 360
 	//looking for :
333
-	if (strpos($ip, ':') === false)
334
-		return false;
361
+	if (strpos($ip, ':') === false) {
362
+			return false;
363
+	}
335 364
 
336 365
 	//check valid address
337 366
 	return inet_pton($ip);
@@ -348,15 +377,17 @@  discard block
 block discarded – undo
348 377
 	static $expanded = array();
349 378
 
350 379
 	// Check if we have done this already.
351
-	if (isset($expanded[$ip]))
352
-		return $expanded[$ip];
380
+	if (isset($expanded[$ip])) {
381
+			return $expanded[$ip];
382
+	}
353 383
 
354 384
 	// Expand the IP out.
355 385
 	$expanded_ip = explode(':', expandIPv6($ip));
356 386
 
357 387
 	$new_ip = array();
358
-	foreach ($expanded_ip as $int)
359
-		$new_ip[] = hexdec($int);
388
+	foreach ($expanded_ip as $int) {
389
+			$new_ip[] = hexdec($int);
390
+	}
360 391
 
361 392
 	// Save this incase of repeated use.
362 393
 	$expanded[$ip] = $new_ip;
@@ -376,8 +407,9 @@  discard block
 block discarded – undo
376 407
 	static $converted = array();
377 408
 
378 409
 	// Check if we have done this already.
379
-	if (isset($converted[$addr]))
380
-		return $converted[$addr];
410
+	if (isset($converted[$addr])) {
411
+			return $converted[$addr];
412
+	}
381 413
 
382 414
 	// Check if there are segments missing, insert if necessary.
383 415
 	if (strpos($addr, '::') !== false)
@@ -387,18 +419,20 @@  discard block
 block discarded – undo
387 419
 		$part[1] = explode(':', $part[1]);
388 420
 		$missing = array();
389 421
 
390
-		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
391
-			array_push($missing, '0000');
422
+		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
423
+					array_push($missing, '0000');
424
+		}
392 425
 
393 426
 		$part = array_merge($part[0], $missing, $part[1]);
427
+	} else {
428
+			$part = explode(':', $addr);
394 429
 	}
395
-	else
396
-		$part = explode(':', $addr);
397 430
 
398 431
 	// Pad each segment until it has 4 digits.
399
-	foreach ($part as &$p)
400
-		while (strlen($p) < 4)
432
+	foreach ($part as &$p) {
433
+			while (strlen($p) < 4)
401 434
 			$p = '0' . $p;
435
+	}
402 436
 
403 437
 	unset($p);
404 438
 
@@ -409,11 +443,12 @@  discard block
 block discarded – undo
409 443
 	$converted[$addr] = $result;
410 444
 
411 445
 	// Quick check to make sure the length is as expected.
412
-	if (!$strict_check || strlen($result) == 39)
413
-		return $result;
414
-	else
415
-		return false;
416
-}
446
+	if (!$strict_check || strlen($result) == 39) {
447
+			return $result;
448
+	} else {
449
+			return false;
450
+	}
451
+	}
417 452
 
418 453
 
419 454
 /**
@@ -444,15 +479,17 @@  discard block
 block discarded – undo
444 479
 {
445 480
 	global $smcFunc;
446 481
 
447
-	if (!is_array($var))
448
-		return $smcFunc['db_escape_string']($var);
482
+	if (!is_array($var)) {
483
+			return $smcFunc['db_escape_string']($var);
484
+	}
449 485
 
450 486
 	// Reindex the array with slashes.
451 487
 	$new_var = array();
452 488
 
453 489
 	// Add slashes to every element, even the indexes!
454
-	foreach ($var as $k => $v)
455
-		$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
490
+	foreach ($var as $k => $v) {
491
+			$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
492
+	}
456 493
 
457 494
 	return $new_var;
458 495
 }
@@ -472,12 +509,14 @@  discard block
 block discarded – undo
472 509
 {
473 510
 	global $smcFunc;
474 511
 
475
-	if (!is_array($var))
476
-		return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
512
+	if (!is_array($var)) {
513
+			return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
514
+	}
477 515
 
478 516
 	// Add the htmlspecialchars to every element.
479
-	foreach ($var as $k => $v)
480
-		$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
517
+	foreach ($var as $k => $v) {
518
+			$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
519
+	}
481 520
 
482 521
 	return $var;
483 522
 }
@@ -495,15 +534,17 @@  discard block
 block discarded – undo
495 534
  */
496 535
 function urldecode__recursive($var, $level = 0)
497 536
 {
498
-	if (!is_array($var))
499
-		return urldecode($var);
537
+	if (!is_array($var)) {
538
+			return urldecode($var);
539
+	}
500 540
 
501 541
 	// Reindex the array...
502 542
 	$new_var = array();
503 543
 
504 544
 	// Add the htmlspecialchars to every element.
505
-	foreach ($var as $k => $v)
506
-		$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
545
+	foreach ($var as $k => $v) {
546
+			$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
547
+	}
507 548
 
508 549
 	return $new_var;
509 550
 }
@@ -521,15 +562,17 @@  discard block
 block discarded – undo
521 562
 {
522 563
 	global $smcFunc;
523 564
 
524
-	if (!is_array($var))
525
-		return $smcFunc['db_unescape_string']($var);
565
+	if (!is_array($var)) {
566
+			return $smcFunc['db_unescape_string']($var);
567
+	}
526 568
 
527 569
 	// Reindex the array without slashes, this time.
528 570
 	$new_var = array();
529 571
 
530 572
 	// Strip the slashes from every element.
531
-	foreach ($var as $k => $v)
532
-		$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
573
+	foreach ($var as $k => $v) {
574
+			$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
575
+	}
533 576
 
534 577
 	return $new_var;
535 578
 }
@@ -547,15 +590,17 @@  discard block
 block discarded – undo
547 590
  */
548 591
 function stripslashes__recursive($var, $level = 0)
549 592
 {
550
-	if (!is_array($var))
551
-		return stripslashes($var);
593
+	if (!is_array($var)) {
594
+			return stripslashes($var);
595
+	}
552 596
 
553 597
 	// Reindex the array without slashes, this time.
554 598
 	$new_var = array();
555 599
 
556 600
 	// Strip the slashes from every element.
557
-	foreach ($var as $k => $v)
558
-		$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
601
+	foreach ($var as $k => $v) {
602
+			$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
603
+	}
559 604
 
560 605
 	return $new_var;
561 606
 }
@@ -576,12 +621,14 @@  discard block
 block discarded – undo
576 621
 	global $smcFunc;
577 622
 
578 623
 	// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
579
-	if (!is_array($var))
580
-		return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
624
+	if (!is_array($var)) {
625
+			return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
626
+	}
581 627
 
582 628
 	// Go through all the elements and remove the whitespace.
583
-	foreach ($var as $k => $v)
584
-		$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
629
+	foreach ($var as $k => $v) {
630
+			$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
631
+	}
585 632
 
586 633
 	return $var;
587 634
 }
@@ -646,30 +693,37 @@  discard block
 block discarded – undo
646 693
 	global $scripturl, $modSettings, $context;
647 694
 
648 695
 	// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
649
-	if ($scripturl == '' || !defined('SID'))
650
-		return $buffer;
696
+	if ($scripturl == '' || !defined('SID')) {
697
+			return $buffer;
698
+	}
651 699
 
652 700
 	// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
653 701
 	// @todo smflib
654
-	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot'))
655
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
702
+	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) {
703
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
704
+	}
656 705
 	// Debugging templates, are we?
657
-	elseif (isset($_GET['debug']))
658
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
706
+	elseif (isset($_GET['debug'])) {
707
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
708
+	}
659 709
 
660 710
 	// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
661 711
 	if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed']))
662 712
 	{
663 713
 		// Let's do something special for session ids!
664
-		if (defined('SID') && SID != '')
665
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
714
+		if (defined('SID') && SID != '') {
715
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
666 716
 			{
667
-				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
717
+				global $scripturl;
718
+		}
719
+		return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
668 720
 			}, $buffer);
669
-		else
670
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
721
+		else {
722
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
671 723
 			{
672
-				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
724
+				global $scripturl;
725
+		}
726
+		return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
673 727
 			}, $buffer);
674 728
 	}
675 729
 
Please login to merge, or discard this patch.
Sources/RemoveTopic.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1491,7 +1491,7 @@
 block discarded – undo
1491 1491
 
1492 1492
 /**
1493 1493
  * Try to determine if the topic has already been deleted by another user.
1494
- * @return bool False if it can't be deleted (recycling not enabled or no recycling board set), true if we've confirmed it can be deleted. Dies with an error if it's already been deleted.
1494
+ * @return boolean|null False if it can't be deleted (recycling not enabled or no recycling board set), true if we've confirmed it can be deleted. Dies with an error if it's already been deleted.
1495 1495
  */
1496 1496
 function removeDeleteConcurrence()
1497 1497
 {
Please login to merge, or discard this patch.
Braces   +267 added lines, -200 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /*	The contents of this file handle the deletion of topics, posts, and related
21 22
 	paraphernalia.  It has the following functions:
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Post.php');
38 39
 
39 40
 	// Trying to fool us around, are we?
40
-	if (empty($topic))
41
-		redirectexit();
41
+	if (empty($topic)) {
42
+			redirectexit();
43
+	}
42 44
 
43 45
 	removeDeleteConcurrence();
44 46
 
@@ -55,20 +57,23 @@  discard block
 block discarded – undo
55 57
 	list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request);
56 58
 	$smcFunc['db_free_result']($request);
57 59
 
58
-	if ($starter == $user_info['id'] && !allowedTo('remove_any'))
59
-		isAllowedTo('remove_own');
60
-	else
61
-		isAllowedTo('remove_any');
60
+	if ($starter == $user_info['id'] && !allowedTo('remove_any')) {
61
+			isAllowedTo('remove_own');
62
+	} else {
63
+			isAllowedTo('remove_any');
64
+	}
62 65
 
63 66
 	// Can they see the topic?
64
-	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id'])
65
-		isAllowedTo('approve_posts');
67
+	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) {
68
+			isAllowedTo('approve_posts');
69
+	}
66 70
 
67 71
 	// Ok, we got that far, but is it locked?
68 72
 	if ($locked)
69 73
 	{
70
-		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any')))
71
-			fatal_lang_error('cannot_remove_locked', 'user');
74
+		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) {
75
+					fatal_lang_error('cannot_remove_locked', 'user');
76
+		}
72 77
 	}
73 78
 
74 79
 	// Notify people that this topic has been removed.
@@ -77,8 +82,9 @@  discard block
 block discarded – undo
77 82
 	removeTopics($topic);
78 83
 
79 84
 	// Note, only log topic ID in native form if it's not gone forever.
80
-	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id']))
81
-		logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
85
+	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) {
86
+			logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
87
+	}
82 88
 
83 89
 	redirectexit('board=' . $board . '.0');
84 90
 }
@@ -96,8 +102,9 @@  discard block
 block discarded – undo
96 102
 	$_REQUEST['msg'] = (int) $_REQUEST['msg'];
97 103
 
98 104
 	// Is $topic set?
99
-	if (empty($topic) && isset($_REQUEST['topic']))
100
-		$topic = (int) $_REQUEST['topic'];
105
+	if (empty($topic) && isset($_REQUEST['topic'])) {
106
+			$topic = (int) $_REQUEST['topic'];
107
+	}
101 108
 
102 109
 	removeDeleteConcurrence();
103 110
 
@@ -116,44 +123,48 @@  discard block
 block discarded – undo
116 123
 	$smcFunc['db_free_result']($request);
117 124
 
118 125
 	// Verify they can see this!
119
-	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id'])
120
-		isAllowedTo('approve_posts');
126
+	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) {
127
+			isAllowedTo('approve_posts');
128
+	}
121 129
 
122 130
 	if ($poster == $user_info['id'])
123 131
 	{
124 132
 		if (!allowedTo('delete_own'))
125 133
 		{
126
-			if ($starter == $user_info['id'] && !allowedTo('delete_any'))
127
-				isAllowedTo('delete_replies');
128
-			elseif (!allowedTo('delete_any'))
129
-				isAllowedTo('delete_own');
134
+			if ($starter == $user_info['id'] && !allowedTo('delete_any')) {
135
+							isAllowedTo('delete_replies');
136
+			} elseif (!allowedTo('delete_any')) {
137
+							isAllowedTo('delete_own');
138
+			}
139
+		} elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) {
140
+					fatal_lang_error('modify_post_time_passed', false);
130 141
 		}
131
-		elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time())
132
-			fatal_lang_error('modify_post_time_passed', false);
142
+	} elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) {
143
+			isAllowedTo('delete_replies');
144
+	} else {
145
+			isAllowedTo('delete_any');
133 146
 	}
134
-	elseif ($starter == $user_info['id'] && !allowedTo('delete_any'))
135
-		isAllowedTo('delete_replies');
136
-	else
137
-		isAllowedTo('delete_any');
138 147
 
139 148
 	// If the full topic was removed go back to the board.
140 149
 	$full_topic = removeMessage($_REQUEST['msg']);
141 150
 
142
-	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id']))
143
-		logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
151
+	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) {
152
+			logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
153
+	}
144 154
 
145 155
 	// We want to redirect back to recent action.
146
-	if (isset($_REQUEST['modcenter']))
147
-		redirectexit('action=moderate;area=reportedposts;done');
148
-	elseif (isset($_REQUEST['recent']))
149
-		redirectexit('action=recent');
150
-	elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u']))
151
-		redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
152
-	elseif ($full_topic)
153
-		redirectexit('board=' . $board . '.0');
154
-	else
155
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
156
-}
156
+	if (isset($_REQUEST['modcenter'])) {
157
+			redirectexit('action=moderate;area=reportedposts;done');
158
+	} elseif (isset($_REQUEST['recent'])) {
159
+			redirectexit('action=recent');
160
+	} elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) {
161
+			redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
162
+	} elseif ($full_topic) {
163
+			redirectexit('board=' . $board . '.0');
164
+	} else {
165
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
166
+	}
167
+	}
157 168
 
158 169
 /**
159 170
  * So long as you are sure... all old posts will be gone.
@@ -167,8 +178,9 @@  discard block
 block discarded – undo
167 178
 	checkSession('post', 'admin');
168 179
 
169 180
 	// No boards at all?  Forget it then :/.
170
-	if (empty($_POST['boards']))
171
-		redirectexit('action=admin;area=maintain;sa=topics');
181
+	if (empty($_POST['boards'])) {
182
+			redirectexit('action=admin;area=maintain;sa=topics');
183
+	}
172 184
 
173 185
 	// This should exist, but we can make sure.
174 186
 	$_POST['delete_type'] = isset($_POST['delete_type']) ? $_POST['delete_type'] : 'nothing';
@@ -222,8 +234,9 @@  discard block
 block discarded – undo
222 234
 		$condition_params
223 235
 	);
224 236
 	$topics = array();
225
-	while ($row = $smcFunc['db_fetch_assoc']($request))
226
-		$topics[] = $row['id_topic'];
237
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
238
+			$topics[] = $row['id_topic'];
239
+	}
227 240
 	$smcFunc['db_free_result']($request);
228 241
 
229 242
 	removeTopics($topics, false, true);
@@ -247,11 +260,13 @@  discard block
 block discarded – undo
247 260
 	global $sourcedir, $modSettings, $smcFunc;
248 261
 
249 262
 	// Nothing to do?
250
-	if (empty($topics))
251
-		return;
263
+	if (empty($topics)) {
264
+			return;
265
+	}
252 266
 	// Only a single topic.
253
-	if (is_numeric($topics))
254
-		$topics = array($topics);
267
+	if (is_numeric($topics)) {
268
+			$topics = array($topics);
269
+	}
255 270
 
256 271
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
257 272
 
@@ -276,8 +291,9 @@  discard block
 block discarded – undo
276 291
 		);
277 292
 		if ($smcFunc['db_num_rows']($requestMembers) > 0)
278 293
 		{
279
-			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers))
280
-				updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
294
+			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) {
295
+							updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
296
+			}
281 297
 		}
282 298
 		$smcFunc['db_free_result']($requestMembers);
283 299
 	}
@@ -303,8 +319,9 @@  discard block
 block discarded – undo
303 319
 			$recycleTopics = array();
304 320
 			while ($row = $smcFunc['db_fetch_assoc']($request))
305 321
 			{
306
-				if (function_exists('apache_reset_timeout'))
307
-					@apache_reset_timeout();
322
+				if (function_exists('apache_reset_timeout')) {
323
+									@apache_reset_timeout();
324
+				}
308 325
 
309 326
 				$recycleTopics[] = $row['id_topic'];
310 327
 
@@ -346,20 +363,22 @@  discard block
 block discarded – undo
346 363
 
347 364
 			// Topics that were recycled don't need to be deleted, so subtract them.
348 365
 			$topics = array_diff($topics, $recycleTopics);
366
+		} else {
367
+					$smcFunc['db_free_result']($request);
349 368
 		}
350
-		else
351
-			$smcFunc['db_free_result']($request);
352 369
 	}
353 370
 
354 371
 	// Still topics left to delete?
355
-	if (empty($topics))
356
-		return;
372
+	if (empty($topics)) {
373
+			return;
374
+	}
357 375
 
358 376
 	// Callback for search APIs to do their thing
359 377
 	require_once($sourcedir . '/Search.php');
360 378
 	$searchAPI = findSearchAPI();
361
-	if ($searchAPI->supportsMethod('topicsRemoved'))
362
-		$searchAPI->topicsRemoved($topics);
379
+	if ($searchAPI->supportsMethod('topicsRemoved')) {
380
+			$searchAPI->topicsRemoved($topics);
381
+	}
363 382
 
364 383
 	$adjustBoards = array();
365 384
 
@@ -391,10 +410,11 @@  discard block
 block discarded – undo
391 410
 		$adjustBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
392 411
 
393 412
 		// Add the topics to the right type.
394
-		if ($row['approved'])
395
-			$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
396
-		else
397
-			$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
413
+		if ($row['approved']) {
414
+					$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
415
+		} else {
416
+					$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
417
+		}
398 418
 	}
399 419
 	$smcFunc['db_free_result']($request);
400 420
 
@@ -403,8 +423,9 @@  discard block
 block discarded – undo
403 423
 		// Decrease the posts/topics...
404 424
 		foreach ($adjustBoards as $stats)
405 425
 		{
406
-			if (function_exists('apache_reset_timeout'))
407
-				@apache_reset_timeout();
426
+			if (function_exists('apache_reset_timeout')) {
427
+							@apache_reset_timeout();
428
+			}
408 429
 
409 430
 			$smcFunc['db_query']('', '
410 431
 				UPDATE {db_prefix}boards
@@ -438,8 +459,9 @@  discard block
 block discarded – undo
438 459
 		)
439 460
 	);
440 461
 	$polls = array();
441
-	while ($row = $smcFunc['db_fetch_assoc']($request))
442
-		$polls[] = $row['id_poll'];
462
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
463
+			$polls[] = $row['id_poll'];
464
+	}
443 465
 	$smcFunc['db_free_result']($request);
444 466
 
445 467
 	if (!empty($polls))
@@ -492,8 +514,9 @@  discard block
 block discarded – undo
492 514
 		);
493 515
 		while ($row = $smcFunc['db_fetch_assoc']($request))
494 516
 		{
495
-			if (function_exists('apache_reset_timeout'))
496
-				@apache_reset_timeout();
517
+			if (function_exists('apache_reset_timeout')) {
518
+							@apache_reset_timeout();
519
+			}
497 520
 
498 521
 			$words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true));
499 522
 			$messages[] = $row['id_msg'];
@@ -501,8 +524,8 @@  discard block
 block discarded – undo
501 524
 		$smcFunc['db_free_result']($request);
502 525
 		$words = array_unique($words);
503 526
 
504
-		if (!empty($words) && !empty($messages))
505
-			$smcFunc['db_query']('', '
527
+		if (!empty($words) && !empty($messages)) {
528
+					$smcFunc['db_query']('', '
506 529
 				DELETE FROM {db_prefix}log_search_words
507 530
 				WHERE id_word IN ({array_int:word_list})
508 531
 					AND id_msg IN ({array_int:message_list})',
@@ -511,6 +534,7 @@  discard block
 block discarded – undo
511 534
 					'message_list' => $messages,
512 535
 				)
513 536
 			);
537
+		}
514 538
 	}
515 539
 
516 540
 	// Delete anything related to the topic.
@@ -569,8 +593,9 @@  discard block
 block discarded – undo
569 593
 
570 594
 	require_once($sourcedir . '/Subs-Post.php');
571 595
 	$updates = array();
572
-	foreach ($adjustBoards as $stats)
573
-		$updates[] = $stats['id_board'];
596
+	foreach ($adjustBoards as $stats) {
597
+			$updates[] = $stats['id_board'];
598
+	}
574 599
 	updateLastMessages($updates);
575 600
 }
576 601
 
@@ -587,8 +612,9 @@  discard block
 block discarded – undo
587 612
 {
588 613
 	global $board, $sourcedir, $modSettings, $user_info, $smcFunc;
589 614
 
590
-	if (empty($message) || !is_numeric($message))
591
-		return false;
615
+	if (empty($message) || !is_numeric($message)) {
616
+			return false;
617
+	}
592 618
 
593 619
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
594 620
 
@@ -607,8 +633,9 @@  discard block
 block discarded – undo
607 633
 			'id_msg' => $message,
608 634
 		)
609 635
 	);
610
-	if ($smcFunc['db_num_rows']($request) == 0)
611
-		return false;
636
+	if ($smcFunc['db_num_rows']($request) == 0) {
637
+			return false;
638
+	}
612 639
 	$row = $smcFunc['db_fetch_assoc']($request);
613 640
 	$smcFunc['db_free_result']($request);
614 641
 
@@ -629,54 +656,57 @@  discard block
 block discarded – undo
629 656
 				{
630 657
 					if ($row['id_member_poster'] == $user_info['id'])
631 658
 					{
632
-						if (!$delete_replies)
633
-							fatal_lang_error('cannot_delete_replies', 'permission');
659
+						if (!$delete_replies) {
660
+													fatal_lang_error('cannot_delete_replies', 'permission');
661
+						}
662
+					} else {
663
+											fatal_lang_error('cannot_delete_own', 'permission');
634 664
 					}
635
-					else
636
-						fatal_lang_error('cannot_delete_own', 'permission');
665
+				} elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
666
+									fatal_lang_error('modify_post_time_passed', false);
637 667
 				}
638
-				elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
639
-					fatal_lang_error('modify_post_time_passed', false);
640
-			}
641
-			elseif ($row['id_member_poster'] == $user_info['id'])
668
+			} elseif ($row['id_member_poster'] == $user_info['id'])
642 669
 			{
643
-				if (!$delete_replies)
644
-					fatal_lang_error('cannot_delete_replies', 'permission');
670
+				if (!$delete_replies) {
671
+									fatal_lang_error('cannot_delete_replies', 'permission');
672
+				}
673
+			} else {
674
+							fatal_lang_error('cannot_delete_any', 'permission');
645 675
 			}
646
-			else
647
-				fatal_lang_error('cannot_delete_any', 'permission');
648 676
 		}
649 677
 
650 678
 		// Can't delete an unapproved message, if you can't see it!
651 679
 		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any)))
652 680
 		{
653 681
 			$approve_posts = boardsAllowedTo('approve_posts');
654
-			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts))
655
-				return false;
682
+			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) {
683
+							return false;
684
+			}
656 685
 		}
657
-	}
658
-	else
686
+	} else
659 687
 	{
660 688
 		// Check permissions to delete this message.
661 689
 		if ($row['id_member'] == $user_info['id'])
662 690
 		{
663 691
 			if (!allowedTo('delete_own'))
664 692
 			{
665
-				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
666
-					isAllowedTo('delete_replies');
667
-				elseif (!allowedTo('delete_any'))
668
-					isAllowedTo('delete_own');
693
+				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
694
+									isAllowedTo('delete_replies');
695
+				} elseif (!allowedTo('delete_any')) {
696
+									isAllowedTo('delete_own');
697
+				}
698
+			} elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
699
+							fatal_lang_error('modify_post_time_passed', false);
669 700
 			}
670
-			elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
671
-				fatal_lang_error('modify_post_time_passed', false);
701
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
702
+					isAllowedTo('delete_replies');
703
+		} else {
704
+					isAllowedTo('delete_any');
672 705
 		}
673
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
674
-			isAllowedTo('delete_replies');
675
-		else
676
-			isAllowedTo('delete_any');
677 706
 
678
-		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own'))
679
-			isAllowedTo('approve_posts');
707
+		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) {
708
+					isAllowedTo('approve_posts');
709
+		}
680 710
 	}
681 711
 
682 712
 	// Delete the *whole* topic, but only if the topic consists of one message.
@@ -692,31 +722,34 @@  discard block
 block discarded – undo
692 722
 				$remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own);
693 723
 			}
694 724
 
695
-			if ($row['id_member'] != $user_info['id'] && !$remove_any)
696
-				fatal_lang_error('cannot_remove_any', 'permission');
697
-			elseif (!$remove_any && !$remove_own)
698
-				fatal_lang_error('cannot_remove_own', 'permission');
699
-		}
700
-		else
725
+			if ($row['id_member'] != $user_info['id'] && !$remove_any) {
726
+							fatal_lang_error('cannot_remove_any', 'permission');
727
+			} elseif (!$remove_any && !$remove_own) {
728
+							fatal_lang_error('cannot_remove_own', 'permission');
729
+			}
730
+		} else
701 731
 		{
702 732
 			// Check permissions to delete a whole topic.
703
-			if ($row['id_member'] != $user_info['id'])
704
-				isAllowedTo('remove_any');
705
-			elseif (!allowedTo('remove_any'))
706
-				isAllowedTo('remove_own');
733
+			if ($row['id_member'] != $user_info['id']) {
734
+							isAllowedTo('remove_any');
735
+			} elseif (!allowedTo('remove_any')) {
736
+							isAllowedTo('remove_own');
737
+			}
707 738
 		}
708 739
 
709 740
 		// ...if there is only one post.
710
-		if (!empty($row['num_replies']))
711
-			fatal_lang_error('delFirstPost', false);
741
+		if (!empty($row['num_replies'])) {
742
+					fatal_lang_error('delFirstPost', false);
743
+		}
712 744
 
713 745
 		removeTopics($row['id_topic']);
714 746
 		return true;
715 747
 	}
716 748
 
717 749
 	// Deleting a recycled message can not lower anyone's post count.
718
-	if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
719
-		$decreasePostCount = false;
750
+	if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
751
+			$decreasePostCount = false;
752
+	}
720 753
 
721 754
 	// This is the last post, update the last post on the board.
722 755
 	if ($row['id_last_msg'] == $message)
@@ -755,8 +788,8 @@  discard block
 block discarded – undo
755 788
 		);
756 789
 	}
757 790
 	// Only decrease post counts.
758
-	else
759
-		$smcFunc['db_query']('', '
791
+	else {
792
+			$smcFunc['db_query']('', '
760 793
 			UPDATE {db_prefix}topics
761 794
 			SET ' . ($row['approved'] ? '
762 795
 				num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : '
@@ -768,6 +801,7 @@  discard block
 block discarded – undo
768 801
 				'id_topic' => $row['id_topic'],
769 802
 			)
770 803
 		);
804
+	}
771 805
 
772 806
 	// Default recycle to false.
773 807
 	$recycle = false;
@@ -787,8 +821,9 @@  discard block
 block discarded – undo
787 821
 				'recycle_board' => $modSettings['recycle_board'],
788 822
 			)
789 823
 		);
790
-		if ($smcFunc['db_num_rows']($request) == 0)
791
-			fatal_lang_error('recycle_no_valid_board');
824
+		if ($smcFunc['db_num_rows']($request) == 0) {
825
+					fatal_lang_error('recycle_no_valid_board');
826
+		}
792 827
 		list ($isRead, $last_board_msg) = $smcFunc['db_fetch_row']($request);
793 828
 		$smcFunc['db_free_result']($request);
794 829
 
@@ -807,8 +842,8 @@  discard block
 block discarded – undo
807 842
 		$smcFunc['db_free_result']($request);
808 843
 
809 844
 		// Insert a new topic in the recycle board if $id_recycle_topic is empty.
810
-		if (empty($id_recycle_topic))
811
-			$id_topic = $smcFunc['db_insert']('',
845
+		if (empty($id_recycle_topic)) {
846
+					$id_topic = $smcFunc['db_insert']('',
812 847
 				'{db_prefix}topics',
813 848
 				array(
814 849
 					'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int',
@@ -821,6 +856,7 @@  discard block
 block discarded – undo
821 856
 				array('id_topic'),
822 857
 				1
823 858
 			);
859
+		}
824 860
 
825 861
 		// Capture the ID of the new topic...
826 862
 		$topicID = empty($id_recycle_topic) ? $id_topic : $id_recycle_topic;
@@ -858,22 +894,24 @@  discard block
 block discarded – undo
858 894
 			);
859 895
 
860 896
 			// Mark recycled topic as read.
861
-			if (!$user_info['is_guest'])
862
-				$smcFunc['db_insert']('replace',
897
+			if (!$user_info['is_guest']) {
898
+							$smcFunc['db_insert']('replace',
863 899
 					'{db_prefix}log_topics',
864 900
 					array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'),
865 901
 					array($topicID, $user_info['id'], $modSettings['maxMsgID'], 0),
866 902
 					array('id_topic', 'id_member')
867 903
 				);
904
+			}
868 905
 
869 906
 			// Mark recycle board as seen, if it was marked as seen before.
870
-			if (!empty($isRead) && !$user_info['is_guest'])
871
-				$smcFunc['db_insert']('replace',
907
+			if (!empty($isRead) && !$user_info['is_guest']) {
908
+							$smcFunc['db_insert']('replace',
872 909
 					'{db_prefix}log_boards',
873 910
 					array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
874 911
 					array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']),
875 912
 					array('id_board', 'id_member')
876 913
 				);
914
+			}
877 915
 
878 916
 			// Add one topic and post to the recycle bin board.
879 917
 			$smcFunc['db_query']('', '
@@ -891,8 +929,8 @@  discard block
 block discarded – undo
891 929
 			);
892 930
 
893 931
 			// Lets increase the num_replies, and the first/last message ID as appropriate.
894
-			if (!empty($id_recycle_topic))
895
-				$smcFunc['db_query']('', '
932
+			if (!empty($id_recycle_topic)) {
933
+							$smcFunc['db_query']('', '
896 934
 					UPDATE {db_prefix}topics
897 935
 					SET num_replies = num_replies + 1' .
898 936
 						($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') .
@@ -903,6 +941,7 @@  discard block
 block discarded – undo
903 941
 						'id_merged_msg' => $message,
904 942
 					)
905 943
 				);
944
+			}
906 945
 
907 946
 			// Make sure this message isn't getting deleted later on.
908 947
 			$recycle = true;
@@ -912,8 +951,8 @@  discard block
 block discarded – undo
912 951
 		}
913 952
 
914 953
 		// If it wasn't approved don't keep it in the queue.
915
-		if (!$row['approved'])
916
-			$smcFunc['db_query']('', '
954
+		if (!$row['approved']) {
955
+					$smcFunc['db_query']('', '
917 956
 				DELETE FROM {db_prefix}approval_queue
918 957
 				WHERE id_msg = {int:id_msg}
919 958
 					AND id_attach = {int:id_attach}',
@@ -922,6 +961,7 @@  discard block
 block discarded – undo
922 961
 					'id_attach' => 0,
923 962
 				)
924 963
 			);
964
+		}
925 965
 	}
926 966
 
927 967
 	$smcFunc['db_query']('', '
@@ -939,8 +979,9 @@  discard block
 block discarded – undo
939 979
 
940 980
 	// If the poster was registered and the board this message was on incremented
941 981
 	// the member's posts when it was posted, decrease his or her post count.
942
-	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved'])
943
-		updateMemberData($row['id_member'], array('posts' => '-'));
982
+	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) {
983
+			updateMemberData($row['id_member'], array('posts' => '-'));
984
+	}
944 985
 
945 986
 	// Only remove posts if they're not recycled.
946 987
 	if (!$recycle)
@@ -948,8 +989,9 @@  discard block
 block discarded – undo
948 989
 		// Callback for search APIs to do their thing
949 990
 		require_once($sourcedir . '/Search.php');
950 991
 		$searchAPI = findSearchAPI();
951
-		if ($searchAPI->supportsMethod('postRemoved'))
952
-			$searchAPI->postRemoved($message);
992
+		if ($searchAPI->supportsMethod('postRemoved')) {
993
+					$searchAPI->postRemoved($message);
994
+		}
953 995
 
954 996
 		// Remove the message!
955 997
 		$smcFunc['db_query']('', '
@@ -964,8 +1006,8 @@  discard block
 block discarded – undo
964 1006
 		{
965 1007
 			$customIndexSettings = smf_json_decode($modSettings['search_custom_index_config'], true);
966 1008
 			$words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true);
967
-			if (!empty($words))
968
-				$smcFunc['db_query']('', '
1009
+			if (!empty($words)) {
1010
+							$smcFunc['db_query']('', '
969 1011
 					DELETE FROM {db_prefix}log_search_words
970 1012
 					WHERE id_word IN ({array_int:word_list})
971 1013
 						AND id_msg = {int:id_msg}',
@@ -974,6 +1016,7 @@  discard block
 block discarded – undo
974 1016
 						'id_msg' => $message,
975 1017
 					)
976 1018
 				);
1019
+			}
977 1020
 		}
978 1021
 
979 1022
 		// Delete attachment(s) if they exist.
@@ -997,10 +1040,11 @@  discard block
 block discarded – undo
997 1040
 
998 1041
 	// And now to update the last message of each board we messed with.
999 1042
 	require_once($sourcedir . '/Subs-Post.php');
1000
-	if ($recycle)
1001
-		updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1002
-	else
1003
-		updateLastMessages($row['id_board']);
1043
+	if ($recycle) {
1044
+			updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1045
+	} else {
1046
+			updateLastMessages($row['id_board']);
1047
+	}
1004 1048
 
1005 1049
 	// Close any moderation reports for this message.
1006 1050
 	$smcFunc['db_query']('', '
@@ -1033,8 +1077,9 @@  discard block
 block discarded – undo
1033 1077
 	checkSession('get');
1034 1078
 
1035 1079
 	// Is recycled board enabled?
1036
-	if (empty($modSettings['recycle_enable']))
1037
-		fatal_lang_error('restored_disabled', 'critical');
1080
+	if (empty($modSettings['recycle_enable'])) {
1081
+			fatal_lang_error('restored_disabled', 'critical');
1082
+	}
1038 1083
 
1039 1084
 	// Can we be in here?
1040 1085
 	isAllowedTo('move_any', $modSettings['recycle_board']);
@@ -1049,8 +1094,9 @@  discard block
 block discarded – undo
1049 1094
 	if (!empty($_REQUEST['msgs']))
1050 1095
 	{
1051 1096
 		$msgs = explode(',', $_REQUEST['msgs']);
1052
-		foreach ($msgs as $k => $msg)
1053
-			$msgs[$k] = (int) $msg;
1097
+		foreach ($msgs as $k => $msg) {
1098
+					$msgs[$k] = (int) $msg;
1099
+		}
1054 1100
 
1055 1101
 		// Get the id_previous_board and id_previous_topic.
1056 1102
 		$request = $smcFunc['db_query']('', '
@@ -1084,8 +1130,8 @@  discard block
 block discarded – undo
1084 1130
 			}
1085 1131
 
1086 1132
 			$previous_topics[] = $row['id_previous_topic'];
1087
-			if (empty($actioned_messages[$row['id_previous_topic']]))
1088
-				$actioned_messages[$row['id_previous_topic']] = array(
1133
+			if (empty($actioned_messages[$row['id_previous_topic']])) {
1134
+							$actioned_messages[$row['id_previous_topic']] = array(
1089 1135
 					'msgs' => array(),
1090 1136
 					'count_posts' => $row['count_posts'],
1091 1137
 					'subject' => $row['subject'],
@@ -1095,17 +1141,20 @@  discard block
 block discarded – undo
1095 1141
 					'current_board' => $row['id_board'],
1096 1142
 					'members' => array(),
1097 1143
 				);
1144
+			}
1098 1145
 
1099 1146
 			$actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject'];
1100
-			if ($row['id_member'])
1101
-				$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1147
+			if ($row['id_member']) {
1148
+							$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1149
+			}
1102 1150
 		}
1103 1151
 		$smcFunc['db_free_result']($request);
1104 1152
 
1105 1153
 		// Check for topics we are going to fully restore.
1106
-		foreach ($actioned_messages as $topic => $data)
1107
-			if (in_array($topic, $topics_to_restore))
1154
+		foreach ($actioned_messages as $topic => $data) {
1155
+					if (in_array($topic, $topics_to_restore))
1108 1156
 				unset($actioned_messages[$topic]);
1157
+		}
1109 1158
 
1110 1159
 		// Load any previous topics to check they exist.
1111 1160
 		if (!empty($previous_topics))
@@ -1120,11 +1169,12 @@  discard block
 block discarded – undo
1120 1169
 				)
1121 1170
 			);
1122 1171
 			$previous_topics = array();
1123
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1124
-				$previous_topics[$row['id_topic']] = array(
1172
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1173
+							$previous_topics[$row['id_topic']] = array(
1125 1174
 					'board' => $row['id_board'],
1126 1175
 					'subject' => $row['subject'],
1127 1176
 				);
1177
+			}
1128 1178
 			$smcFunc['db_free_result']($request);
1129 1179
 		}
1130 1180
 
@@ -1146,11 +1196,11 @@  discard block
 block discarded – undo
1146 1196
 				// Log em.
1147 1197
 				logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board']));
1148 1198
 				$messages = array_merge(array_keys($data['msgs']), $messages);
1149
-			}
1150
-			else
1199
+			} else
1151 1200
 			{
1152
-				foreach ($data['msgs'] as $msg)
1153
-					$unfound_messages[$msg['id']] = $msg['subject'];
1201
+				foreach ($data['msgs'] as $msg) {
1202
+									$unfound_messages[$msg['id']] = $msg['subject'];
1203
+				}
1154 1204
 			}
1155 1205
 		}
1156 1206
 	}
@@ -1159,8 +1209,9 @@  discard block
 block discarded – undo
1159 1209
 	if (!empty($_REQUEST['topics']))
1160 1210
 	{
1161 1211
 		$topics = explode(',', $_REQUEST['topics']);
1162
-		foreach ($topics as $id)
1163
-			$topics_to_restore[] = (int) $id;
1212
+		foreach ($topics as $id) {
1213
+					$topics_to_restore[] = (int) $id;
1214
+		}
1164 1215
 	}
1165 1216
 
1166 1217
 	if (!empty($topics_to_restore))
@@ -1214,8 +1265,9 @@  discard block
 block discarded – undo
1214 1265
 					)
1215 1266
 				);
1216 1267
 
1217
-				while ($member = $smcFunc['db_fetch_assoc']($request2))
1218
-					updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1268
+				while ($member = $smcFunc['db_fetch_assoc']($request2)) {
1269
+									updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1270
+				}
1219 1271
 				$smcFunc['db_free_result']($request2);
1220 1272
 			}
1221 1273
 
@@ -1226,8 +1278,9 @@  discard block
 block discarded – undo
1226 1278
 	}
1227 1279
 
1228 1280
 	// Didn't find some things?
1229
-	if (!empty($unfound_messages))
1230
-		fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1281
+	if (!empty($unfound_messages)) {
1282
+			fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1283
+	}
1231 1284
 
1232 1285
 	// Just send them to the index if they get here.
1233 1286
 	redirectexit();
@@ -1247,12 +1300,14 @@  discard block
 block discarded – undo
1247 1300
 	//!!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient.
1248 1301
 
1249 1302
 	// Is it an array?
1250
-	if (!is_array($msgs))
1251
-		$msgs = array($msgs);
1303
+	if (!is_array($msgs)) {
1304
+			$msgs = array($msgs);
1305
+	}
1252 1306
 
1253 1307
 	// Lets make sure they are int.
1254
-	foreach ($msgs as $key => $msg)
1255
-		$msgs[$key] = (int) $msg;
1308
+	foreach ($msgs as $key => $msg) {
1309
+			$msgs[$key] = (int) $msg;
1310
+	}
1256 1311
 
1257 1312
 	// Get the source information.
1258 1313
 	$request = $smcFunc['db_query']('', '
@@ -1295,8 +1350,9 @@  discard block
 block discarded – undo
1295 1350
 			)
1296 1351
 		);
1297 1352
 
1298
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1299
-			updateMemberData($row['id_member'], array('posts' => '+'));
1353
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1354
+					updateMemberData($row['id_member'], array('posts' => '+'));
1355
+		}
1300 1356
 	}
1301 1357
 
1302 1358
 	// Time to move the messages.
@@ -1332,13 +1388,15 @@  discard block
 block discarded – undo
1332 1388
 	);
1333 1389
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1334 1390
 	{
1335
-		if ($row['id_first_msg'] < $target_topic_data['id_first_msg'])
1336
-			$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1391
+		if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) {
1392
+					$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1393
+		}
1337 1394
 		$target_topic_data['id_last_msg'] = $row['id_last_msg'];
1338
-		if (!$row['approved'])
1339
-			$target_topic_data['unapproved_posts'] = $row['message_count'];
1340
-		else
1341
-			$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1395
+		if (!$row['approved']) {
1396
+					$target_topic_data['unapproved_posts'] = $row['message_count'];
1397
+		} else {
1398
+					$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1399
+		}
1342 1400
 	}
1343 1401
 	$smcFunc['db_free_result']($request);
1344 1402
 
@@ -1397,13 +1455,15 @@  discard block
 block discarded – undo
1397 1455
 		);
1398 1456
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1399 1457
 		{
1400
-			if ($row['id_first_msg'] < $source_topic_data['id_first_msg'])
1401
-				$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1458
+			if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) {
1459
+							$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1460
+			}
1402 1461
 			$source_topic_data['id_last_msg'] = $row['id_last_msg'];
1403
-			if (!$row['approved'])
1404
-				$source_topic_data['unapproved_posts'] = $row['message_count'];
1405
-			else
1406
-				$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1462
+			if (!$row['approved']) {
1463
+							$source_topic_data['unapproved_posts'] = $row['message_count'];
1464
+			} else {
1465
+							$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1466
+			}
1407 1467
 		}
1408 1468
 		$smcFunc['db_free_result']($request);
1409 1469
 
@@ -1467,10 +1527,12 @@  discard block
 block discarded – undo
1467 1527
 
1468 1528
 	// Subject cache?
1469 1529
 	$cache_updates = array();
1470
-	if ($target_first_msg != $target_topic_data['id_first_msg'])
1471
-		$cache_updates[] = $target_topic_data['id_first_msg'];
1472
-	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg'])
1473
-		$cache_updates[] = $source_topic_data['id_first_msg'];
1530
+	if ($target_first_msg != $target_topic_data['id_first_msg']) {
1531
+			$cache_updates[] = $target_topic_data['id_first_msg'];
1532
+	}
1533
+	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) {
1534
+			$cache_updates[] = $source_topic_data['id_first_msg'];
1535
+	}
1474 1536
 
1475 1537
 	if (!empty($cache_updates))
1476 1538
 	{
@@ -1482,8 +1544,9 @@  discard block
 block discarded – undo
1482 1544
 				'first_messages' => $cache_updates,
1483 1545
 			)
1484 1546
 		);
1485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1486
-			updateStats('subject', $row['id_topic'], $row['subject']);
1547
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1548
+					updateStats('subject', $row['id_topic'], $row['subject']);
1549
+		}
1487 1550
 		$smcFunc['db_free_result']($request);
1488 1551
 	}
1489 1552
 
@@ -1499,22 +1562,26 @@  discard block
 block discarded – undo
1499 1562
 	global $modSettings, $board, $scripturl, $context;
1500 1563
 
1501 1564
 	// No recycle no need to go further
1502
-	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board']))
1503
-		return false;
1565
+	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) {
1566
+			return false;
1567
+	}
1504 1568
 
1505 1569
 	// If it's confirmed go on and delete (from recycle)
1506
-	if (isset($_GET['confirm_delete']))
1507
-		return true;
1570
+	if (isset($_GET['confirm_delete'])) {
1571
+			return true;
1572
+	}
1508 1573
 
1509
-	if (empty($board))
1510
-		return false;
1574
+	if (empty($board)) {
1575
+			return false;
1576
+	}
1511 1577
 
1512
-	if ($modSettings['recycle_board'] != $board)
1513
-		return true;
1514
-	elseif (isset($_REQUEST['msg']))
1515
-		$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1516
-	else
1517
-		$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1578
+	if ($modSettings['recycle_board'] != $board) {
1579
+			return true;
1580
+	} elseif (isset($_REQUEST['msg'])) {
1581
+			$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1582
+	} else {
1583
+			$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1584
+	}
1518 1585
 
1519 1586
 	fatal_lang_error('post_already_deleted', false, array($confirm_url));
1520 1587
 }
Please login to merge, or discard this patch.
Sources/Reports.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1013,7 +1013,7 @@
 block discarded – undo
1013 1013
  * @param string $title The title of the separator
1014 1014
  * @param null|string $custom_table The ID of the custom table
1015 1015
  *
1016
- * @return void|bool Returns false if there are no tables
1016
+ * @return null|false Returns false if there are no tables
1017 1017
  */
1018 1018
 function addSeparator($title = '', $custom_table = null)
1019 1019
 {
Please login to merge, or discard this patch.
Braces   +199 added lines, -148 removed lines patch added patch discarded remove patch
@@ -21,8 +21,9 @@  discard block
 block discarded – undo
21 21
  * @version 2.1 Beta 3
22 22
  */
23 23
 
24
-if (!defined('SMF'))
24
+if (!defined('SMF')) {
25 25
 	die('No direct access...');
26
+}
26 27
 
27 28
 /**
28 29
  * Handling function for generating reports.
@@ -69,14 +70,15 @@  discard block
 block discarded – undo
69 70
 	);
70 71
 
71 72
 	$is_first = 0;
72
-	foreach ($context['report_types'] as $k => $temp)
73
-		$context['report_types'][$k] = array(
73
+	foreach ($context['report_types'] as $k => $temp) {
74
+			$context['report_types'][$k] = array(
74 75
 			'id' => $k,
75 76
 			'title' => isset($txt['gr_type_' . $k]) ? $txt['gr_type_' . $k] : $k,
76 77
 			'description' => isset($txt['gr_type_desc_' . $k]) ? $txt['gr_type_desc_' . $k] : null,
77 78
 			'function' => $temp,
78 79
 			'is_first' => $is_first++ == 0,
79 80
 		);
81
+	}
80 82
 
81 83
 	// If they haven't chosen a report type which is valid, send them off to the report type chooser!
82 84
 	if (empty($_REQUEST['rt']) || !isset($context['report_types'][$_REQUEST['rt']]))
@@ -102,8 +104,9 @@  discard block
 block discarded – undo
102 104
 		$context['sub_template'] = $_REQUEST['st'];
103 105
 
104 106
 		// Are we disabling the other layers - print friendly for example?
105
-		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null)
106
-			$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
107
+		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null) {
108
+					$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
109
+		}
107 110
 	}
108 111
 
109 112
 	// Make the page title more descriptive.
@@ -151,8 +154,9 @@  discard block
 block discarded – undo
151 154
 		)
152 155
 	);
153 156
 	$moderators = array();
154
-	while ($row = $smcFunc['db_fetch_assoc']($request))
155
-		$moderators[$row['id_board']][] = $row['real_name'];
157
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
158
+			$moderators[$row['id_board']][] = $row['real_name'];
159
+	}
156 160
 	$smcFunc['db_free_result']($request);
157 161
 
158 162
 	// Get every moderator gruop.
@@ -164,8 +168,9 @@  discard block
 block discarded – undo
164 168
 		)
165 169
 	);
166 170
 	$moderator_groups = array();
167
-	while ($row = $smcFunc['db_fetch_assoc']($request))
168
-		$moderator_groups[$row['id_board']][] = $row['group_name'];
171
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
172
+			$moderator_groups[$row['id_board']][] = $row['group_name'];
173
+	}
169 174
 	$smcFunc['db_free_result']($request);
170 175
 
171 176
 	// Get all the possible membergroups!
@@ -176,8 +181,9 @@  discard block
 block discarded – undo
176 181
 		)
177 182
 	);
178 183
 	$groups = array(-1 => $txt['guest_title'], 0 => $txt['full_member']);
179
-	while ($row = $smcFunc['db_fetch_assoc']($request))
180
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
184
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
186
+	}
181 187
 	$smcFunc['db_free_result']($request);
182 188
 
183 189
 	// All the fields we'll show.
@@ -195,8 +201,9 @@  discard block
 block discarded – undo
195 201
 		'moderator_groups' => $txt['board_moderator_groups'],
196 202
 		'groups' => $txt['board_groups'],
197 203
 	);
198
-	if (!empty($modSettings['deny_boards_access']))
199
-		$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
204
+	if (!empty($modSettings['deny_boards_access'])) {
205
+			$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
206
+	}
200 207
 
201 208
 	// Do it in columns, it's just easier.
202 209
 	setKeys('cols');
@@ -222,8 +229,9 @@  discard block
 block discarded – undo
222 229
 		newTable($row['name'], '', 'left', 'auto', 'left', 200, 'left');
223 230
 
224 231
 		$this_boardSettings = $boardSettings;
225
-		if (empty($row['redirect']))
226
-			unset($this_boardSettings['redirect']);
232
+		if (empty($row['redirect'])) {
233
+					unset($this_boardSettings['redirect']);
234
+		}
227 235
 
228 236
 		// First off, add in the side key.
229 237
 		addData($this_boardSettings);
@@ -250,10 +258,11 @@  discard block
 block discarded – undo
250 258
 		$allowedGroups = explode(',', $row['member_groups']);
251 259
 		foreach ($allowedGroups as $key => $group)
252 260
 		{
253
-			if (isset($groups[$group]))
254
-				$allowedGroups[$key] = $groups[$group];
255
-			else
256
-				unset($allowedGroups[$key]);
261
+			if (isset($groups[$group])) {
262
+							$allowedGroups[$key] = $groups[$group];
263
+			} else {
264
+							unset($allowedGroups[$key]);
265
+			}
257 266
 		}
258 267
 		$boardData['groups'] = implode(', ', $allowedGroups);
259 268
 		if (!empty($modSettings['deny_boards_access']))
@@ -261,16 +270,18 @@  discard block
 block discarded – undo
261 270
 			$disallowedGroups = explode(',', $row['deny_member_groups']);
262 271
 			foreach ($disallowedGroups as $key => $group)
263 272
 			{
264
-				if (isset($groups[$group]))
265
-					$disallowedGroups[$key] = $groups[$group];
266
-				else
267
-					unset($disallowedGroups[$key]);
273
+				if (isset($groups[$group])) {
274
+									$disallowedGroups[$key] = $groups[$group];
275
+				} else {
276
+									unset($disallowedGroups[$key]);
277
+				}
268 278
 			}
269 279
 			$boardData['disallowed_groups'] = implode(', ', $disallowedGroups);
270 280
 		}
271 281
 
272
-		if (empty($row['redirect']))
273
-			unset ($boardData['redirect']);
282
+		if (empty($row['redirect'])) {
283
+					unset ($boardData['redirect']);
284
+		}
274 285
 
275 286
 		// Next add the main data.
276 287
 		addData($boardData);
@@ -295,27 +306,31 @@  discard block
 block discarded – undo
295 306
 
296 307
 	if (isset($_REQUEST['boards']))
297 308
 	{
298
-		if (!is_array($_REQUEST['boards']))
299
-			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
300
-		foreach ($_REQUEST['boards'] as $k => $dummy)
301
-			$_REQUEST['boards'][$k] = (int) $dummy;
309
+		if (!is_array($_REQUEST['boards'])) {
310
+					$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
311
+		}
312
+		foreach ($_REQUEST['boards'] as $k => $dummy) {
313
+					$_REQUEST['boards'][$k] = (int) $dummy;
314
+		}
302 315
 
303 316
 		$board_clause = 'id_board IN ({array_int:boards})';
317
+	} else {
318
+			$board_clause = '1=1';
304 319
 	}
305
-	else
306
-		$board_clause = '1=1';
307 320
 
308 321
 	if (isset($_REQUEST['groups']))
309 322
 	{
310
-		if (!is_array($_REQUEST['groups']))
311
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
312
-		foreach ($_REQUEST['groups'] as $k => $dummy)
313
-			$_REQUEST['groups'][$k] = (int) $dummy;
323
+		if (!is_array($_REQUEST['groups'])) {
324
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
325
+		}
326
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
327
+					$_REQUEST['groups'][$k] = (int) $dummy;
328
+		}
314 329
 
315 330
 		$group_clause = 'id_group IN ({array_int:groups})';
331
+	} else {
332
+			$group_clause = '1=1';
316 333
 	}
317
-	else
318
-		$group_clause = '1=1';
319 334
 
320 335
 	// Fetch all the board names.
321 336
 	$request = $smcFunc['db_query']('', '
@@ -369,12 +384,14 @@  discard block
 block discarded – undo
369 384
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
370 385
 		)
371 386
 	);
372
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
373
-		$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
374
-	else
375
-		$member_groups = array('col' => '');
376
-	while ($row = $smcFunc['db_fetch_assoc']($request))
377
-		$member_groups[$row['id_group']] = $row['group_name'];
387
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
388
+			$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
389
+	} else {
390
+			$member_groups = array('col' => '');
391
+	}
392
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
393
+			$member_groups[$row['id_group']] = $row['group_name'];
394
+	}
378 395
 	$smcFunc['db_free_result']($request);
379 396
 
380 397
 	// Make sure that every group is represented - plus in rows!
@@ -411,12 +428,14 @@  discard block
 block discarded – undo
411 428
 	);
412 429
 	while ($row = $smcFunc['db_fetch_assoc']($request))
413 430
 	{
414
-		if (in_array($row['permission'], $disabled_permissions))
415
-			continue;
431
+		if (in_array($row['permission'], $disabled_permissions)) {
432
+					continue;
433
+		}
416 434
 
417
-		foreach ($boards as $id => $board)
418
-			if ($board['profile'] == $row['id_profile'])
435
+		foreach ($boards as $id => $board) {
436
+					if ($board['profile'] == $row['id_profile'])
419 437
 				$board_permissions[$id][$row['id_group']][$row['permission']] = $row['add_deny'];
438
+		}
420 439
 
421 440
 		// Make sure we get every permission.
422 441
 		if (!isset($permissions[$row['permission']]))
@@ -454,8 +473,9 @@  discard block
 block discarded – undo
454 473
 			foreach ($member_groups as $id_group => $name)
455 474
 			{
456 475
 				// Don't overwrite the key column!
457
-				if ($id_group === 'col')
458
-					continue;
476
+				if ($id_group === 'col') {
477
+									continue;
478
+				}
459 479
 
460 480
 				$group_permissions = isset($groups[$id_group]) ? $groups[$id_group] : array();
461 481
 
@@ -477,16 +497,18 @@  discard block
 block discarded – undo
477 497
 				}
478 498
 
479 499
 				// Now actually make the data for the group look right.
480
-				if (empty($curData[$id_group]))
481
-					$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
482
-				elseif ($curData[$id_group] == 1)
483
-					$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
484
-				else
485
-					$curData[$id_group] = 'x';
500
+				if (empty($curData[$id_group])) {
501
+									$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
502
+				} elseif ($curData[$id_group] == 1) {
503
+									$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
504
+				} else {
505
+									$curData[$id_group] = 'x';
506
+				}
486 507
 
487 508
 				// Embolden those permissions different from global (makes it a lot easier!)
488
-				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM])
489
-					$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
509
+				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM]) {
510
+									$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
511
+				}
490 512
 			}
491 513
 
492 514
 			// Now add the data for this permission.
@@ -516,15 +538,17 @@  discard block
 block discarded – undo
516 538
 	);
517 539
 	while ($row = $smcFunc['db_fetch_assoc']($request))
518 540
 	{
519
-		if (trim($row['member_groups']) == '')
520
-			$groups = array(1);
521
-		else
522
-			$groups = array_merge(array(1), explode(',', $row['member_groups']));
541
+		if (trim($row['member_groups']) == '') {
542
+					$groups = array(1);
543
+		} else {
544
+					$groups = array_merge(array(1), explode(',', $row['member_groups']));
545
+		}
523 546
 
524
-		if (trim($row['deny_member_groups']) == '')
525
-			$denyGroups = array();
526
-		else
527
-			$denyGroups = explode(',', $row['deny_member_groups']);
547
+		if (trim($row['deny_member_groups']) == '') {
548
+					$denyGroups = array();
549
+		} else {
550
+					$denyGroups = explode(',', $row['deny_member_groups']);
551
+		}
528 552
 
529 553
 		$boards[$row['id_board']] = array(
530 554
 			'id' => $row['id_board'],
@@ -548,8 +572,9 @@  discard block
 block discarded – undo
548 572
 	);
549 573
 
550 574
 	// Add on the boards!
551
-	foreach ($boards as $board)
552
-		$mgSettings['board_' . $board['id']] = $board['name'];
575
+	foreach ($boards as $board) {
576
+			$mgSettings['board_' . $board['id']] = $board['name'];
577
+	}
553 578
 
554 579
 	// Add all the membergroup settings, plus we'll be adding in columns!
555 580
 	setKeys('cols', $mgSettings);
@@ -594,8 +619,9 @@  discard block
 block discarded – undo
594 619
 			'icons' => ''
595 620
 		),
596 621
 	);
597
-	while ($row = $smcFunc['db_fetch_assoc']($request))
598
-		$rows[] = $row;
622
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
623
+			$rows[] = $row;
624
+	}
599 625
 	$smcFunc['db_free_result']($request);
600 626
 
601 627
 	foreach ($rows as $row)
@@ -611,8 +637,9 @@  discard block
 block discarded – undo
611 637
 		);
612 638
 
613 639
 		// Board permissions.
614
-		foreach ($boards as $board)
615
-			$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
640
+		foreach ($boards as $board) {
641
+					$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
642
+		}
616 643
 
617 644
 		addData($group);
618 645
 	}
@@ -632,16 +659,18 @@  discard block
 block discarded – undo
632 659
 
633 660
 	if (isset($_REQUEST['groups']))
634 661
 	{
635
-		if (!is_array($_REQUEST['groups']))
636
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
637
-		foreach ($_REQUEST['groups'] as $k => $dummy)
638
-			$_REQUEST['groups'][$k] = (int) $dummy;
662
+		if (!is_array($_REQUEST['groups'])) {
663
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
664
+		}
665
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
666
+					$_REQUEST['groups'][$k] = (int) $dummy;
667
+		}
639 668
 		$_REQUEST['groups'] = array_diff($_REQUEST['groups'], array(3));
640 669
 
641 670
 		$clause = 'id_group IN ({array_int:groups})';
671
+	} else {
672
+			$clause = 'id_group != {int:moderator_group}';
642 673
 	}
643
-	else
644
-		$clause = 'id_group != {int:moderator_group}';
645 674
 
646 675
 	// Get all the possible membergroups, except admin!
647 676
 	$request = $smcFunc['db_query']('', '
@@ -659,12 +688,14 @@  discard block
 block discarded – undo
659 688
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
660 689
 		)
661 690
 	);
662
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
663
-		$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
664
-	else
665
-		$groups = array('col' => '');
666
-	while ($row = $smcFunc['db_fetch_assoc']($request))
667
-		$groups[$row['id_group']] = $row['group_name'];
691
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
692
+			$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
693
+	} else {
694
+			$groups = array('col' => '');
695
+	}
696
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
697
+			$groups[$row['id_group']] = $row['group_name'];
698
+	}
668 699
 	$smcFunc['db_free_result']($request);
669 700
 
670 701
 	// Make sure that every group is represented!
@@ -688,8 +719,9 @@  discard block
 block discarded – undo
688 719
 		$disabled_permissions[] = 'calendar_edit_own';
689 720
 		$disabled_permissions[] = 'calendar_edit_any';
690 721
 	}
691
-	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0)
692
-		$disabled_permissions[] = 'issue_warning';
722
+	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0) {
723
+			$disabled_permissions[] = 'issue_warning';
724
+	}
693 725
 
694 726
 	call_integration_hook('integrate_reports_groupperm', array(&$disabled_permissions));
695 727
 
@@ -710,15 +742,17 @@  discard block
 block discarded – undo
710 742
 	$curData = array();
711 743
 	while ($row = $smcFunc['db_fetch_assoc']($request))
712 744
 	{
713
-		if (in_array($row['permission'], $disabled_permissions))
714
-			continue;
745
+		if (in_array($row['permission'], $disabled_permissions)) {
746
+					continue;
747
+		}
715 748
 
716 749
 		// If this is a new permission flush the last row.
717 750
 		if ($row['permission'] != $lastPermission)
718 751
 		{
719 752
 			// Send the data!
720
-			if ($lastPermission !== null)
721
-				addData($curData);
753
+			if ($lastPermission !== null) {
754
+							addData($curData);
755
+			}
722 756
 
723 757
 			// Add the permission name in the left column.
724 758
 			$curData = array('col' => isset($txt['group_perms_name_' . $row['permission']]) ? $txt['group_perms_name_' . $row['permission']] : $row['permission']);
@@ -727,10 +761,11 @@  discard block
 block discarded – undo
727 761
 		}
728 762
 
729 763
 		// Good stuff - add the permission to the list!
730
-		if ($row['add_deny'])
731
-			$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
732
-		else
733
-			$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
764
+		if ($row['add_deny']) {
765
+					$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
766
+		} else {
767
+					$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
768
+		}
734 769
 	}
735 770
 	$smcFunc['db_free_result']($request);
736 771
 
@@ -760,8 +795,9 @@  discard block
 block discarded – undo
760 795
 		)
761 796
 	);
762 797
 	$boards = array();
763
-	while ($row = $smcFunc['db_fetch_assoc']($request))
764
-		$boards[$row['id_board']] = $row['name'];
798
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
799
+			$boards[$row['id_board']] = $row['name'];
800
+	}
765 801
 	$smcFunc['db_free_result']($request);
766 802
 
767 803
 	// Get every moderator.
@@ -793,12 +829,14 @@  discard block
 block discarded – undo
793 829
 	while ($row = $smcFunc['db_fetch_assoc']($request))
794 830
 	{
795 831
 		// Either we don't have them as a moderator at all or at least not as a moderator of this board
796
-		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']]))
797
-			$moderators[$row['id_member']][] = $row['id_board'];
832
+		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']])) {
833
+					$moderators[$row['id_member']][] = $row['id_board'];
834
+		}
798 835
 
799 836
 		// We don't have them listed as a moderator yet
800
-		if (!array_key_exists($row['id_member'], $local_mods))
801
-			$local_mods[$row['id_member']] = $row['id_member'];
837
+		if (!array_key_exists($row['id_member'], $local_mods)) {
838
+					$local_mods[$row['id_member']] = $row['id_member'];
839
+		}
802 840
 	}
803 841
 
804 842
 	// Get a list of global moderators (i.e. members with moderation powers).
@@ -811,8 +849,9 @@  discard block
 block discarded – undo
811 849
 	$allStaff = array_unique($allStaff);
812 850
 
813 851
 	// This is a bit of a cop out - but we're protecting their forum, really!
814
-	if (count($allStaff) > 300)
815
-		fatal_lang_error('report_error_too_many_staff');
852
+	if (count($allStaff) > 300) {
853
+			fatal_lang_error('report_error_too_many_staff');
854
+	}
816 855
 
817 856
 	// Get all the possible membergroups!
818 857
 	$request = $smcFunc['db_query']('', '
@@ -822,8 +861,9 @@  discard block
 block discarded – undo
822 861
 		)
823 862
 	);
824 863
 	$groups = array(0 => $txt['full_member']);
825
-	while ($row = $smcFunc['db_fetch_assoc']($request))
826
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
864
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
865
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
866
+	}
827 867
 	$smcFunc['db_free_result']($request);
828 868
 
829 869
 	// All the fields we'll show.
@@ -864,19 +904,20 @@  discard block
 block discarded – undo
864 904
 		);
865 905
 
866 906
 		// What do they moderate?
867
-		if (in_array($row['id_member'], $global_mods))
868
-			$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
869
-		elseif (isset($moderators[$row['id_member']]))
907
+		if (in_array($row['id_member'], $global_mods)) {
908
+					$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
909
+		} elseif (isset($moderators[$row['id_member']]))
870 910
 		{
871 911
 			// Get the names
872
-			foreach ($moderators[$row['id_member']] as $board)
873
-				if (isset($boards[$board]))
912
+			foreach ($moderators[$row['id_member']] as $board) {
913
+							if (isset($boards[$board]))
874 914
 					$staffData['moderates'][] = $boards[$board];
915
+			}
875 916
 
876 917
 			$staffData['moderates'] = implode(', ', $staffData['moderates']);
918
+		} else {
919
+					$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
877 920
 		}
878
-		else
879
-			$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
880 921
 
881 922
 		// Next add the main data.
882 923
 		addData($staffData);
@@ -904,8 +945,9 @@  discard block
 block discarded – undo
904 945
 	global $context;
905 946
 
906 947
 	// Set the table count if needed.
907
-	if (empty($context['table_count']))
908
-		$context['table_count'] = 0;
948
+	if (empty($context['table_count'])) {
949
+			$context['table_count'] = 0;
950
+	}
909 951
 
910 952
 	// Create the table!
911 953
 	$context['tables'][$context['table_count']] = array(
@@ -955,16 +997,18 @@  discard block
 block discarded – undo
955 997
 	global $context;
956 998
 
957 999
 	// No tables? Create one even though we are probably already in a bad state!
958
-	if (empty($context['table_count']))
959
-		newTable();
1000
+	if (empty($context['table_count'])) {
1001
+			newTable();
1002
+	}
960 1003
 
961 1004
 	// Specific table?
962
-	if ($custom_table !== null && !isset($context['tables'][$custom_table]))
963
-		return false;
964
-	elseif ($custom_table !== null)
965
-		$table = $custom_table;
966
-	else
967
-		$table = $context['current_table'];
1005
+	if ($custom_table !== null && !isset($context['tables'][$custom_table])) {
1006
+			return false;
1007
+	} elseif ($custom_table !== null) {
1008
+			$table = $custom_table;
1009
+	} else {
1010
+			$table = $context['current_table'];
1011
+	}
968 1012
 
969 1013
 	// If we have keys, sanitise the data...
970 1014
 	if (!empty($context['keys']))
@@ -976,11 +1020,11 @@  discard block
 block discarded – undo
976 1020
 				'v' => empty($inc_data[$key]) ? $context['tables'][$table]['default_value'] : $inc_data[$key],
977 1021
 			);
978 1022
 			// Special "hack" the adding separators when doing data by column.
979
-			if (substr($key, 0, 5) == '#sep#')
980
-				$data[$key]['separator'] = true;
1023
+			if (substr($key, 0, 5) == '#sep#') {
1024
+							$data[$key]['separator'] = true;
1025
+			}
981 1026
 		}
982
-	}
983
-	else
1027
+	} else
984 1028
 	{
985 1029
 		$data = $inc_data;
986 1030
 		foreach ($data as $key => $value)
@@ -988,8 +1032,9 @@  discard block
 block discarded – undo
988 1032
 			$data[$key] = array(
989 1033
 				'v' => $value,
990 1034
 			);
991
-			if (substr($key, 0, 5) == '#sep#')
992
-				$data[$key]['separator'] = true;
1035
+			if (substr($key, 0, 5) == '#sep#') {
1036
+							$data[$key]['separator'] = true;
1037
+			}
993 1038
 		}
994 1039
 	}
995 1040
 
@@ -1002,8 +1047,9 @@  discard block
 block discarded – undo
1002 1047
 	// Otherwise, tricky!
1003 1048
 	else
1004 1049
 	{
1005
-		foreach ($data as $key => $item)
1006
-			$context['tables'][$table]['data'][$key][] = $item;
1050
+		foreach ($data as $key => $item) {
1051
+					$context['tables'][$table]['data'][$key][] = $item;
1052
+		}
1007 1053
 	}
1008 1054
 }
1009 1055
 
@@ -1020,16 +1066,18 @@  discard block
 block discarded – undo
1020 1066
 	global $context;
1021 1067
 
1022 1068
 	// No tables - return?
1023
-	if (empty($context['table_count']))
1024
-		return;
1069
+	if (empty($context['table_count'])) {
1070
+			return;
1071
+	}
1025 1072
 
1026 1073
 	// Specific table?
1027
-	if ($custom_table !== null && !isset($context['tables'][$table]))
1028
-		return false;
1029
-	elseif ($custom_table !== null)
1030
-		$table = $custom_table;
1031
-	else
1032
-		$table = $context['current_table'];
1074
+	if ($custom_table !== null && !isset($context['tables'][$table])) {
1075
+			return false;
1076
+	} elseif ($custom_table !== null) {
1077
+			$table = $custom_table;
1078
+	} else {
1079
+			$table = $context['current_table'];
1080
+	}
1033 1081
 
1034 1082
 	// Plumb in the separator
1035 1083
 	$context['tables'][$table]['data'][] = array(0 => array(
@@ -1050,8 +1098,9 @@  discard block
 block discarded – undo
1050 1098
 {
1051 1099
 	global $context;
1052 1100
 
1053
-	if (empty($context['tables']))
1054
-		return;
1101
+	if (empty($context['tables'])) {
1102
+			return;
1103
+	}
1055 1104
 
1056 1105
 	// Loop through each table counting up some basic values, to help with the templating.
1057 1106
 	foreach ($context['tables'] as $id => $table)
@@ -1062,12 +1111,13 @@  discard block
 block discarded – undo
1062 1111
 		$context['tables'][$id]['column_count'] = count($curElement);
1063 1112
 
1064 1113
 		// Work out the rough width - for templates like the print template. Without this we might get funny tables.
1065
-		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto')
1066
-			$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1067
-		elseif ($table['width']['normal'] != 'auto')
1068
-			$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1069
-		else
1070
-			$context['tables'][$id]['max_width'] = 'auto';
1114
+		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto') {
1115
+					$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1116
+		} elseif ($table['width']['normal'] != 'auto') {
1117
+					$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1118
+		} else {
1119
+					$context['tables'][$id]['max_width'] = 'auto';
1120
+		}
1071 1121
 	}
1072 1122
 }
1073 1123
 
@@ -1092,10 +1142,11 @@  discard block
 block discarded – undo
1092 1142
 	global $context;
1093 1143
 
1094 1144
 	// Do we want to use the keys of the keys as the keys? :P
1095
-	if ($reverse)
1096
-		$context['keys'] = array_flip($keys);
1097
-	else
1098
-		$context['keys'] = $keys;
1145
+	if ($reverse) {
1146
+			$context['keys'] = array_flip($keys);
1147
+	} else {
1148
+			$context['keys'] = $keys;
1149
+	}
1099 1150
 
1100 1151
 	// Rows or columns?
1101 1152
 	$context['key_method'] = $method == 'rows' ? 'rows' : 'cols';
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -807,7 +807,7 @@
 block discarded – undo
807 807
 /**
808 808
  * Send a group of emails from the mail queue.
809 809
  *
810
- * @param bool|int $number The number to send each loop through or false to use the standard limits
810
+ * @param integer $number The number to send each loop through or false to use the standard limits
811 811
  * @param bool $override_limit Whether to bypass the limit
812 812
  * @param bool $force_send Whether to forcibly send the messages now (useful when using cron jobs)
813 813
  * @return bool Whether things were sent
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -384,7 +384,7 @@
 block discarded – undo
384 384
 	clean_cache();
385 385
 
386 386
 	// If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level.
387
-	list (, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
387
+	list (,, $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
388 388
 	if ($modSettings['warning_decrement'])
389 389
 	{
390 390
 		// Find every member who has a warning level...
Please login to merge, or discard this patch.
Braces   +282 added lines, -205 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc, $modSettings;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -452,16 +477,17 @@  discard block
 block discarded – undo
452 477
 
453 478
 	// Check the database version - for some buggy MySQL version.
454 479
 	$server_version = $smcFunc['db_server_info']();
455
-	if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
456
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
457
-	elseif (!empty($modSettings['db_mysql_group_by_fix']))
458
-		$smcFunc['db_query']('', '
480
+	if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
481
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
482
+	} elseif (!empty($modSettings['db_mysql_group_by_fix'])) {
483
+			$smcFunc['db_query']('', '
459 484
 			DELETE FROM {db_prefix}settings
460 485
 			WHERE variable = {string:mysql_fix}',
461 486
 			array(
462 487
 				'mysql_fix' => 'db_mysql_group_by_fix',
463 488
 			)
464 489
 		);
490
+	}
465 491
 
466 492
 	// Clean up some old login history information.
467 493
 	$smcFunc['db_query']('', '
@@ -519,15 +545,17 @@  discard block
 block discarded – undo
519 545
 
520 546
 		// Store this useful data!
521 547
 		$boards[$row['id_board']] = $row['id_board'];
522
-		if ($row['id_topic'])
523
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
524
-		else
525
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
548
+		if ($row['id_topic']) {
549
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
550
+		} else {
551
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
552
+		}
526 553
 	}
527 554
 	$smcFunc['db_free_result']($request);
528 555
 
529
-	if (empty($boards))
530
-		return true;
556
+	if (empty($boards)) {
557
+			return true;
558
+	}
531 559
 
532 560
 	// Just get the board names.
533 561
 	$request = $smcFunc['db_query']('', '
@@ -539,12 +567,14 @@  discard block
 block discarded – undo
539 567
 		)
540 568
 	);
541 569
 	$boards = array();
542
-	while ($row = $smcFunc['db_fetch_assoc']($request))
543
-		$boards[$row['id_board']] = $row['name'];
570
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
571
+			$boards[$row['id_board']] = $row['name'];
572
+	}
544 573
 	$smcFunc['db_free_result']($request);
545 574
 
546
-	if (empty($boards))
547
-		return true;
575
+	if (empty($boards)) {
576
+			return true;
577
+	}
548 578
 
549 579
 	// Get the actual topics...
550 580
 	$request = $smcFunc['db_query']('', '
@@ -564,52 +594,57 @@  discard block
 block discarded – undo
564 594
 	$types = array();
565 595
 	while ($row = $smcFunc['db_fetch_assoc']($request))
566 596
 	{
567
-		if (!isset($types[$row['note_type']][$row['id_board']]))
568
-			$types[$row['note_type']][$row['id_board']] = array(
597
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
598
+					$types[$row['note_type']][$row['id_board']] = array(
569 599
 				'lines' => array(),
570 600
 				'name' => $row['board_name'],
571 601
 				'id' => $row['id_board'],
572 602
 			);
603
+		}
573 604
 
574 605
 		if ($row['note_type'] == 'reply')
575 606
 		{
576
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
577
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
578
-			else
579
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
607
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
608
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
609
+			} else {
610
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
580 611
 					'id' => $row['id_topic'],
581 612
 					'subject' => un_htmlspecialchars($row['subject']),
582 613
 					'count' => 1,
583 614
 				);
584
-		}
585
-		elseif ($row['note_type'] == 'topic')
615
+			}
616
+		} elseif ($row['note_type'] == 'topic')
586 617
 		{
587
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
588
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
618
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
619
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
589 620
 					'id' => $row['id_topic'],
590 621
 					'subject' => un_htmlspecialchars($row['subject']),
591 622
 				);
592
-		}
593
-		else
623
+			}
624
+		} else
594 625
 		{
595
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
596
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
626
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
627
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
597 628
 					'id' => $row['id_topic'],
598 629
 					'subject' => un_htmlspecialchars($row['subject']),
599 630
 					'starter' => $row['id_member_started'],
600 631
 				);
632
+			}
601 633
 		}
602 634
 
603 635
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
604
-		if (!empty($notify['topics'][$row['id_topic']]))
605
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
606
-		if (!empty($notify['boards'][$row['id_board']]))
607
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
636
+		if (!empty($notify['topics'][$row['id_topic']])) {
637
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
638
+		}
639
+		if (!empty($notify['boards'][$row['id_board']])) {
640
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
641
+		}
608 642
 	}
609 643
 	$smcFunc['db_free_result']($request);
610 644
 
611
-	if (empty($types))
612
-		return true;
645
+	if (empty($types)) {
646
+			return true;
647
+	}
613 648
 
614 649
 	// Let's load all the languages into a cache thingy.
615 650
 	$langtxt = array();
@@ -650,8 +685,9 @@  discard block
 block discarded – undo
650 685
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
651 686
 
652 687
 		// Did they not elect to choose this?
653
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
654
-			continue;
688
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
689
+					continue;
690
+		}
655 691
 
656 692
 		// Right character set!
657 693
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -667,39 +703,43 @@  discard block
 block discarded – undo
667 703
 		if (isset($types['topic']))
668 704
 		{
669 705
 			$titled = false;
670
-			foreach ($types['topic'] as $id => $board)
671
-				foreach ($board['lines'] as $topic)
706
+			foreach ($types['topic'] as $id => $board) {
707
+							foreach ($board['lines'] as $topic)
672 708
 					if (in_array($mid, $topic['members']))
673 709
 					{
674 710
 						if (!$titled)
675 711
 						{
676 712
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
713
+			}
677 714
 							$titled = true;
678 715
 						}
679 716
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
680 717
 					}
681
-			if ($titled)
682
-				$email['body'] .= "\n";
718
+			if ($titled) {
719
+							$email['body'] .= "\n";
720
+			}
683 721
 		}
684 722
 
685 723
 		// What about replies?
686 724
 		if (isset($types['reply']))
687 725
 		{
688 726
 			$titled = false;
689
-			foreach ($types['reply'] as $id => $board)
690
-				foreach ($board['lines'] as $topic)
727
+			foreach ($types['reply'] as $id => $board) {
728
+							foreach ($board['lines'] as $topic)
691 729
 					if (in_array($mid, $topic['members']))
692 730
 					{
693 731
 						if (!$titled)
694 732
 						{
695 733
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
734
+			}
696 735
 							$titled = true;
697 736
 						}
698 737
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
699 738
 					}
700 739
 
701
-			if ($titled)
702
-				$email['body'] .= "\n";
740
+			if ($titled) {
741
+							$email['body'] .= "\n";
742
+			}
703 743
 		}
704 744
 
705 745
 		// Finally, moderation actions!
@@ -708,24 +748,27 @@  discard block
 block discarded – undo
708 748
 			$titled = false;
709 749
 			foreach ($types as $note_type => $type)
710 750
 			{
711
-				if ($note_type == 'topic' || $note_type == 'reply')
712
-					continue;
751
+				if ($note_type == 'topic' || $note_type == 'reply') {
752
+									continue;
753
+				}
713 754
 
714
-				foreach ($type as $id => $board)
715
-					foreach ($board['lines'] as $topic)
755
+				foreach ($type as $id => $board) {
756
+									foreach ($board['lines'] as $topic)
716 757
 						if (in_array($mid, $topic['members']))
717 758
 						{
718 759
 							if (!$titled)
719 760
 							{
720 761
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
762
+				}
721 763
 								$titled = true;
722 764
 							}
723 765
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
724 766
 						}
725 767
 			}
726 768
 		}
727
-		if ($titled)
728
-			$email['body'] .= "\n";
769
+		if ($titled) {
770
+					$email['body'] .= "\n";
771
+		}
729 772
 
730 773
 		// Then just say our goodbyes!
731 774
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -753,8 +796,7 @@  discard block
 block discarded – undo
753 796
 				'not_daily' => 0,
754 797
 			)
755 798
 		);
756
-	}
757
-	else
799
+	} else
758 800
 	{
759 801
 		// Clear any only weekly ones, and stop us from sending daily again.
760 802
 		$smcFunc['db_query']('', '
@@ -816,16 +858,19 @@  discard block
 block discarded – undo
816 858
 	global $modSettings, $smcFunc, $sourcedir;
817 859
 
818 860
 	// Are we intending another script to be sending out the queue?
819
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
820
-		return false;
861
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
862
+			return false;
863
+	}
821 864
 
822 865
 	// By default send 5 at once.
823
-	if (!$number)
824
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
866
+	if (!$number) {
867
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
868
+	}
825 869
 
826 870
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
827
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
828
-		return false;
871
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
872
+			return false;
873
+	}
829 874
 
830 875
 	// By default move the next sending on by 10 seconds, and require an affected row.
831 876
 	if (!$override_limit)
@@ -842,8 +887,9 @@  discard block
 block discarded – undo
842 887
 				'last_send' => $modSettings['mail_next_send'],
843 888
 			)
844 889
 		);
845
-		if ($smcFunc['db_affected_rows']() == 0)
846
-			return false;
890
+		if ($smcFunc['db_affected_rows']() == 0) {
891
+					return false;
892
+		}
847 893
 		$modSettings['mail_next_send'] = time() + $delay;
848 894
 	}
849 895
 
@@ -864,8 +910,9 @@  discard block
 block discarded – undo
864 910
 			$mn += $number;
865 911
 		}
866 912
 		// No more I'm afraid, return!
867
-		else
868
-			return false;
913
+		else {
914
+					return false;
915
+		}
869 916
 
870 917
 		// Reflect that we're about to send some, do it now to be safe.
871 918
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -900,14 +947,15 @@  discard block
 block discarded – undo
900 947
 	$smcFunc['db_free_result']($request);
901 948
 
902 949
 	// Delete, delete, delete!!!
903
-	if (!empty($ids))
904
-		$smcFunc['db_query']('', '
950
+	if (!empty($ids)) {
951
+			$smcFunc['db_query']('', '
905 952
 			DELETE FROM {db_prefix}mail_queue
906 953
 			WHERE id_mail IN ({array_int:mail_list})',
907 954
 			array(
908 955
 				'mail_list' => $ids,
909 956
 			)
910 957
 		);
958
+	}
911 959
 
912 960
 	// Don't believe we have any left?
913 961
 	if (count($ids) < $number)
@@ -925,11 +973,13 @@  discard block
 block discarded – undo
925 973
 		);
926 974
 	}
927 975
 
928
-	if (empty($ids))
929
-		return false;
976
+	if (empty($ids)) {
977
+			return false;
978
+	}
930 979
 
931
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
932
-		require_once($sourcedir . '/Subs-Post.php');
980
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
981
+			require_once($sourcedir . '/Subs-Post.php');
982
+	}
933 983
 
934 984
 	// Send each email, yea!
935 985
 	$failed_emails = array();
@@ -949,15 +999,17 @@  discard block
 block discarded – undo
949 999
 
950 1000
 			// Try to stop a timeout, this would be bad...
951 1001
 			@set_time_limit(300);
952
-			if (function_exists('apache_reset_timeout'))
953
-				@apache_reset_timeout();
1002
+			if (function_exists('apache_reset_timeout')) {
1003
+							@apache_reset_timeout();
1004
+			}
1005
+		} else {
1006
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
954 1007
 		}
955
-		else
956
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
957 1008
 
958 1009
 		// Hopefully it sent?
959
-		if (!$result)
960
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1010
+		if (!$result) {
1011
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1012
+		}
961 1013
 	}
962 1014
 
963 1015
 	// Any emails that didn't send?
@@ -972,8 +1024,8 @@  discard block
 block discarded – undo
972 1024
 		);
973 1025
 
974 1026
 		// If we have failed to many times, tell mail to wait a bit and try again.
975
-		if ($modSettings['mail_failed_attempts'] > 5)
976
-			$smcFunc['db_query']('', '
1027
+		if ($modSettings['mail_failed_attempts'] > 5) {
1028
+					$smcFunc['db_query']('', '
977 1029
 				UPDATE {db_prefix}settings
978 1030
 				SET value = {string:next_mail_send}
979 1031
 				WHERE variable = {literal:mail_next_send}
@@ -982,6 +1034,7 @@  discard block
 block discarded – undo
982 1034
 					'next_mail_send' => time() + 60,
983 1035
 					'last_send' => $modSettings['mail_next_send'],
984 1036
 			));
1037
+		}
985 1038
 
986 1039
 		// Add our email back to the queue, manually.
987 1040
 		$smcFunc['db_insert']('insert',
@@ -994,8 +1047,8 @@  discard block
 block discarded – undo
994 1047
 		return false;
995 1048
 	}
996 1049
 	// We where unable to send the email, clear our failed attempts.
997
-	elseif (!empty($modSettings['mail_failed_attempts']))
998
-		$smcFunc['db_query']('', '
1050
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1051
+			$smcFunc['db_query']('', '
999 1052
 			UPDATE {db_prefix}settings
1000 1053
 			SET value = {string:zero}
1001 1054
 			WHERE variable = {string:mail_failed_attempts}',
@@ -1003,6 +1056,7 @@  discard block
 block discarded – undo
1003 1056
 				'zero' => '0',
1004 1057
 				'mail_failed_attempts' => 'mail_failed_attempts',
1005 1058
 		));
1059
+	}
1006 1060
 
1007 1061
 	// Had something to send...
1008 1062
 	return true;
@@ -1019,16 +1073,18 @@  discard block
 block discarded – undo
1019 1073
 	global $modSettings, $smcFunc;
1020 1074
 
1021 1075
 	$task_query = '';
1022
-	if (!is_array($tasks))
1023
-		$tasks = array($tasks);
1076
+	if (!is_array($tasks)) {
1077
+			$tasks = array($tasks);
1078
+	}
1024 1079
 
1025 1080
 	// Actually have something passed?
1026 1081
 	if (!empty($tasks))
1027 1082
 	{
1028
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1029
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1030
-		else
1031
-			$task_query = ' AND task IN ({array_string:tasks})';
1083
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1084
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1085
+		} else {
1086
+					$task_query = ' AND task IN ({array_string:tasks})';
1087
+		}
1032 1088
 	}
1033 1089
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1034 1090
 
@@ -1049,20 +1105,22 @@  discard block
 block discarded – undo
1049 1105
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1050 1106
 
1051 1107
 		// Only bother moving the task if it's out of place or we're forcing it!
1052
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1053
-			$tasks[$row['id_task']] = $next_time;
1054
-		else
1055
-			$next_time = $row['next_time'];
1108
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1109
+					$tasks[$row['id_task']] = $next_time;
1110
+		} else {
1111
+					$next_time = $row['next_time'];
1112
+		}
1056 1113
 
1057 1114
 		// If this is sooner than the current next task, make this the next task.
1058
-		if ($next_time < $nextTaskTime)
1059
-			$nextTaskTime = $next_time;
1115
+		if ($next_time < $nextTaskTime) {
1116
+					$nextTaskTime = $next_time;
1117
+		}
1060 1118
 	}
1061 1119
 	$smcFunc['db_free_result']($request);
1062 1120
 
1063 1121
 	// Now make the changes!
1064
-	foreach ($tasks as $id => $time)
1065
-		$smcFunc['db_query']('', '
1122
+	foreach ($tasks as $id => $time) {
1123
+			$smcFunc['db_query']('', '
1066 1124
 			UPDATE {db_prefix}scheduled_tasks
1067 1125
 			SET next_time = {int:next_time}
1068 1126
 			WHERE id_task = {int:id_task}',
@@ -1071,11 +1129,13 @@  discard block
 block discarded – undo
1071 1129
 				'id_task' => $id,
1072 1130
 			)
1073 1131
 		);
1132
+	}
1074 1133
 
1075 1134
 	// If the next task is now different update.
1076
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1077
-		updateSettings(array('next_task_time' => $nextTaskTime));
1078
-}
1135
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1136
+			updateSettings(array('next_task_time' => $nextTaskTime));
1137
+	}
1138
+	}
1079 1139
 
1080 1140
 /**
1081 1141
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1088,8 +1148,9 @@  discard block
 block discarded – undo
1088 1148
 function next_time($regularity, $unit, $offset)
1089 1149
 {
1090 1150
 	// Just in case!
1091
-	if ($regularity == 0)
1092
-		$regularity = 2;
1151
+	if ($regularity == 0) {
1152
+			$regularity = 2;
1153
+	}
1093 1154
 
1094 1155
 	$curMin = date('i', time());
1095 1156
 
@@ -1099,15 +1160,16 @@  discard block
 block discarded – undo
1099 1160
 		$off = date('i', $offset);
1100 1161
 
1101 1162
 		// If it's now just pretend it ain't,
1102
-		if ($off == $curMin)
1103
-			$next_time = time() + $regularity;
1104
-		else
1163
+		if ($off == $curMin) {
1164
+					$next_time = time() + $regularity;
1165
+		} else
1105 1166
 		{
1106 1167
 			// Make sure that the offset is always in the past.
1107 1168
 			$off = $off > $curMin ? $off - 60 : $off;
1108 1169
 
1109
-			while ($off <= $curMin)
1110
-				$off += $regularity;
1170
+			while ($off <= $curMin) {
1171
+							$off += $regularity;
1172
+			}
1111 1173
 
1112 1174
 			// Now we know when the time should be!
1113 1175
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1127,11 +1189,13 @@  discard block
 block discarded – undo
1127 1189
 		// Default we'll jump in hours.
1128 1190
 		$applyOffset = 3600;
1129 1191
 		// 24 hours = 1 day.
1130
-		if ($unit == 'd')
1131
-			$applyOffset = 86400;
1192
+		if ($unit == 'd') {
1193
+					$applyOffset = 86400;
1194
+		}
1132 1195
 		// Otherwise a week.
1133
-		if ($unit == 'w')
1134
-			$applyOffset = 604800;
1196
+		if ($unit == 'w') {
1197
+					$applyOffset = 604800;
1198
+		}
1135 1199
 
1136 1200
 		$applyOffset *= $regularity;
1137 1201
 
@@ -1168,8 +1232,9 @@  discard block
 block discarded – undo
1168 1232
 		$settings[$row['variable']] = $row['value'];
1169 1233
 
1170 1234
 		// Is this the default theme?
1171
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1172
-			$settings['default_' . $row['variable']] = $row['value'];
1235
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1236
+					$settings['default_' . $row['variable']] = $row['value'];
1237
+		}
1173 1238
 	}
1174 1239
 	$smcFunc['db_free_result']($result);
1175 1240
 
@@ -1179,12 +1244,14 @@  discard block
 block discarded – undo
1179 1244
 		$settings['template_dirs'] = array($settings['theme_dir']);
1180 1245
 
1181 1246
 		// Based on theme (if there is one).
1182
-		if (!empty($settings['base_theme_dir']))
1183
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1247
+		if (!empty($settings['base_theme_dir'])) {
1248
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1249
+		}
1184 1250
 
1185 1251
 		// Lastly the default theme.
1186
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1187
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1252
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1253
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1254
+		}
1188 1255
 	}
1189 1256
 
1190 1257
 	// Assume we want this.
@@ -1330,8 +1397,9 @@  discard block
 block discarded – undo
1330 1397
 	// Ok should we prune the logs?
1331 1398
 	if (!empty($modSettings['pruningOptions']))
1332 1399
 	{
1333
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1334
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1400
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1401
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1402
+		}
1335 1403
 
1336 1404
 		if (!empty($modSettings['pruneErrorLog']))
1337 1405
 		{
@@ -1397,8 +1465,9 @@  discard block
 block discarded – undo
1397 1465
 				)
1398 1466
 			);
1399 1467
 
1400
-			while ($row = $smcFunc['db_fetch_row']($result))
1401
-				$reports[] = $row[0];
1468
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1469
+							$reports[] = $row[0];
1470
+			}
1402 1471
 
1403 1472
 			$smcFunc['db_free_result']($result);
1404 1473
 
@@ -1560,8 +1629,9 @@  discard block
 block discarded – undo
1560 1629
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1561 1630
 
1562 1631
 		// Send the actual email.
1563
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1564
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1632
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1633
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1634
+		}
1565 1635
 
1566 1636
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1567 1637
 		{
@@ -1584,18 +1654,19 @@  discard block
 block discarded – undo
1584 1654
 	}
1585 1655
 
1586 1656
 	// Insert the alerts if any
1587
-	if (!empty($alert_rows))
1588
-		$smcFunc['db_insert']('',
1657
+	if (!empty($alert_rows)) {
1658
+			$smcFunc['db_insert']('',
1589 1659
 			'{db_prefix}user_alerts',
1590 1660
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1591 1661
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1592 1662
 			$alert_rows,
1593 1663
 			array()
1594 1664
 		);
1665
+	}
1595 1666
 
1596 1667
 	// Mark the reminder as sent.
1597
-	if (!empty($subs_reminded))
1598
-		$smcFunc['db_query']('', '
1668
+	if (!empty($subs_reminded)) {
1669
+			$smcFunc['db_query']('', '
1599 1670
 			UPDATE {db_prefix}log_subscribed
1600 1671
 			SET reminder_sent = {int:reminder_sent}
1601 1672
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1604,6 +1675,7 @@  discard block
 block discarded – undo
1604 1675
 				'reminder_sent' => 1,
1605 1676
 			)
1606 1677
 		);
1678
+	}
1607 1679
 
1608 1680
 	return true;
1609 1681
 }
@@ -1619,13 +1691,13 @@  discard block
 block discarded – undo
1619 1691
 	// We need to know where this thing is going.
1620 1692
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1621 1693
 	{
1622
-		if (!is_array($modSettings['attachmentUploadDir']))
1623
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1694
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1695
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1696
+		}
1624 1697
 
1625 1698
 		// Just use the current path for temp files.
1626 1699
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1627
-	}
1628
-	else
1700
+	} else
1629 1701
 	{
1630 1702
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1631 1703
 	}
@@ -1644,14 +1716,16 @@  discard block
 block discarded – undo
1644 1716
 
1645 1717
 		while ($file = readdir($dir))
1646 1718
 		{
1647
-			if ($file == '.' || $file == '..')
1648
-				continue;
1719
+			if ($file == '.' || $file == '..') {
1720
+							continue;
1721
+			}
1649 1722
 
1650 1723
 			if (strpos($file, 'post_tmp_') !== false)
1651 1724
 			{
1652 1725
 				// Temp file is more than 5 hours old!
1653
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1654
-					@unlink($attach_dir . '/' . $file);
1726
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1727
+									@unlink($attach_dir . '/' . $file);
1728
+				}
1655 1729
 			}
1656 1730
 		}
1657 1731
 		closedir($dir);
@@ -1684,8 +1758,9 @@  discard block
 block discarded – undo
1684 1758
 		)
1685 1759
 	);
1686 1760
 
1687
-	while ($row = $smcFunc['db_fetch_row']($request))
1688
-		$topics[] = $row[0];
1761
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1762
+			$topics[] = $row[0];
1763
+	}
1689 1764
 	$smcFunc['db_free_result']($request);
1690 1765
 
1691 1766
 	// Zap, your gone
@@ -1705,8 +1780,9 @@  discard block
 block discarded – undo
1705 1780
 {
1706 1781
 	global $smcFunc, $sourcedir, $modSettings;
1707 1782
 
1708
-	if (empty($modSettings['drafts_keep_days']))
1709
-		return true;
1783
+	if (empty($modSettings['drafts_keep_days'])) {
1784
+			return true;
1785
+	}
1710 1786
 
1711 1787
 	// init
1712 1788
 	$drafts = array();
@@ -1724,8 +1800,9 @@  discard block
 block discarded – undo
1724 1800
 		)
1725 1801
 	);
1726 1802
 
1727
-	while ($row = $smcFunc['db_fetch_row']($request))
1728
-		$drafts[] = (int) $row[0];
1803
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1804
+			$drafts[] = (int) $row[0];
1805
+	}
1729 1806
 	$smcFunc['db_free_result']($request);
1730 1807
 
1731 1808
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/Subs-Admin.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
 
19 19
 /**
20 20
  * Get a list of versions that are currently installed on the server.
21
- * @param array $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server'
21
+ * @param string[] $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server'
22 22
  * @return array An array of versions (keys are same as what was in $checkFor, values are the versions)
23 23
  */
24 24
 function getServerVersions($checkFor)
Please login to merge, or discard this patch.
Braces   +124 added lines, -89 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get a list of versions that are currently installed on the server.
@@ -45,8 +46,7 @@  discard block
 block discarded – undo
45 46
 			$temp2 = $temp->getVersion();
46 47
 			$im_version = $temp2['versionString'];
47 48
 			$extension_version = 'Imagick ' . phpversion('Imagick');
48
-		}
49
-		else
49
+		} else
50 50
 		{
51 51
 			$im_version = MagickGetVersionString();
52 52
 			$extension_version = 'MagickWand ' . phpversion('MagickWand');
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	if (in_array('db_server', $checkFor))
62 62
 	{
63 63
 		db_extend();
64
-		if (!isset($db_connection) || $db_connection === false)
65
-			trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
-		else
64
+		if (!isset($db_connection) || $db_connection === false) {
65
+					trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
+		} else
67 67
 		{
68 68
 			$versions['db_engine'] = array('title' => sprintf($txt['support_versions_db_engine'], $smcFunc['db_title']), 'version' => '');
69 69
 			$versions['db_engine']['version'] = $smcFunc['db_get_engine']();
@@ -74,24 +74,31 @@  discard block
 block discarded – undo
74 74
 	}
75 75
 
76 76
 	// If we're using memcache we need the server info.
77
-	if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '')
78
-		get_memcached_server();
77
+	if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
78
+			get_memcached_server();
79
+	}
79 80
 
80 81
 	// Check to see if we have any accelerators installed...
81
-	if (in_array('phpa', $checkFor) && isset($_PHPA))
82
-		$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
83
-	if (in_array('apc', $checkFor) && extension_loaded('apc'))
84
-		$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
85
-	if (in_array('memcache', $checkFor) && function_exists('memcache_set'))
86
-		$versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached));
87
-	if (in_array('xcache', $checkFor) && function_exists('xcache_set'))
88
-		$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
82
+	if (in_array('phpa', $checkFor) && isset($_PHPA)) {
83
+			$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
84
+	}
85
+	if (in_array('apc', $checkFor) && extension_loaded('apc')) {
86
+			$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
87
+	}
88
+	if (in_array('memcache', $checkFor) && function_exists('memcache_set')) {
89
+			$versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached));
90
+	}
91
+	if (in_array('xcache', $checkFor) && function_exists('xcache_set')) {
92
+			$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
93
+	}
89 94
 
90
-	if (in_array('php', $checkFor))
91
-		$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
95
+	if (in_array('php', $checkFor)) {
96
+			$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
97
+	}
92 98
 
93
-	if (in_array('server', $checkFor))
94
-		$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
99
+	if (in_array('server', $checkFor)) {
100
+			$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
101
+	}
95 102
 
96 103
 	return $versions;
97 104
 }
@@ -131,11 +138,13 @@  discard block
 block discarded – undo
131 138
 		fclose($fp);
132 139
 
133 140
 		// The comment looks rougly like... that.
134
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
135
-			$version_info['file_versions']['SSI.php'] = $match[1];
141
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
142
+					$version_info['file_versions']['SSI.php'] = $match[1];
143
+		}
136 144
 		// Not found!  This is bad.
137
-		else
138
-			$version_info['file_versions']['SSI.php'] = '??';
145
+		else {
146
+					$version_info['file_versions']['SSI.php'] = '??';
147
+		}
139 148
 	}
140 149
 
141 150
 	// Do the paid subscriptions handler?
@@ -146,11 +155,13 @@  discard block
 block discarded – undo
146 155
 		fclose($fp);
147 156
 
148 157
 		// Found it?
149
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
150
-			$version_info['file_versions']['subscriptions.php'] = $match[1];
158
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
159
+					$version_info['file_versions']['subscriptions.php'] = $match[1];
160
+		}
151 161
 		// If we haven't how do we all get paid?
152
-		else
153
-			$version_info['file_versions']['subscriptions.php'] = '??';
162
+		else {
163
+					$version_info['file_versions']['subscriptions.php'] = '??';
164
+		}
154 165
 	}
155 166
 
156 167
 	// Load all the files in the Sources directory, except this file and the redirect.
@@ -165,11 +176,13 @@  discard block
 block discarded – undo
165 176
 			fclose($fp);
166 177
 
167 178
 			// Look for the version comment in the file header.
168
-			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
169
-				$version_info['file_versions'][$entry] = $match[1];
179
+			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
180
+							$version_info['file_versions'][$entry] = $match[1];
181
+			}
170 182
 			// It wasn't found, but the file was... show a '??'.
171
-			else
172
-				$version_info['file_versions'][$entry] = '??';
183
+			else {
184
+							$version_info['file_versions'][$entry] = '??';
185
+			}
173 186
 		}
174 187
 	}
175 188
 	$sources_dir->close();
@@ -188,11 +201,13 @@  discard block
 block discarded – undo
188 201
 				fclose($fp);
189 202
 
190 203
 				// Look for the version comment in the file header.
191
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
192
-					$version_info['tasks_versions'][$entry] = $match[1];
204
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
205
+									$version_info['tasks_versions'][$entry] = $match[1];
206
+				}
193 207
 				// It wasn't found, but the file was... show a '??'.
194
-				else
195
-					$version_info['tasks_versions'][$entry] = '??';
208
+				else {
209
+									$version_info['tasks_versions'][$entry] = '??';
210
+				}
196 211
 			}
197 212
 		}
198 213
 		$tasks_dir->close();
@@ -200,8 +215,9 @@  discard block
 block discarded – undo
200 215
 
201 216
 	// Load all the files in the default template directory - and the current theme if applicable.
202 217
 	$directories = array('default_template_versions' => $settings['default_theme_dir']);
203
-	if ($settings['theme_id'] != 1)
204
-		$directories += array('template_versions' => $settings['theme_dir']);
218
+	if ($settings['theme_id'] != 1) {
219
+			$directories += array('template_versions' => $settings['theme_dir']);
220
+	}
205 221
 
206 222
 	foreach ($directories as $type => $dirname)
207 223
 	{
@@ -216,11 +232,13 @@  discard block
 block discarded – undo
216 232
 				fclose($fp);
217 233
 
218 234
 				// Look for the version comment in the file header.
219
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
220
-					$version_info[$type][$entry] = $match[1];
235
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
236
+									$version_info[$type][$entry] = $match[1];
237
+				}
221 238
 				// It wasn't found, but the file was... show a '??'.
222
-				else
223
-					$version_info[$type][$entry] = '??';
239
+				else {
240
+									$version_info[$type][$entry] = '??';
241
+				}
224 242
 			}
225 243
 		}
226 244
 		$this_dir->close();
@@ -241,11 +259,13 @@  discard block
 block discarded – undo
241 259
 			list ($name, $language) = explode('.', $entry);
242 260
 
243 261
 			// Look for the version comment in the file header.
244
-			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1)
245
-				$version_info['default_language_versions'][$language][$name] = $match[1];
262
+			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) {
263
+							$version_info['default_language_versions'][$language][$name] = $match[1];
264
+			}
246 265
 			// It wasn't found, but the file was... show a '??'.
247
-			else
248
-				$version_info['default_language_versions'][$language][$name] = '??';
266
+			else {
267
+							$version_info['default_language_versions'][$language][$name] = '??';
268
+			}
249 269
 		}
250 270
 	}
251 271
 	$this_dir->close();
@@ -260,8 +280,9 @@  discard block
 block discarded – undo
260 280
 		ksort($version_info['tasks_versions']);
261 281
 
262 282
 		// For languages sort each language too.
263
-		foreach ($version_info['default_language_versions'] as $language => $dummy)
264
-			ksort($version_info['default_language_versions'][$language]);
283
+		foreach ($version_info['default_language_versions'] as $language => $dummy) {
284
+					ksort($version_info['default_language_versions'][$language]);
285
+		}
265 286
 	}
266 287
 	return $version_info;
267 288
 }
@@ -303,27 +324,31 @@  discard block
 block discarded – undo
303 324
 	$settingsArray = trim(file_get_contents($boarddir . '/Settings.php'));
304 325
 
305 326
 	// Break it up based on \r or \n, and then clean out extra characters.
306
-	if (strpos($settingsArray, "\n") !== false)
307
-		$settingsArray = explode("\n", $settingsArray);
308
-	elseif (strpos($settingsArray, "\r") !== false)
309
-		$settingsArray = explode("\r", $settingsArray);
310
-	else
311
-		return;
327
+	if (strpos($settingsArray, "\n") !== false) {
328
+			$settingsArray = explode("\n", $settingsArray);
329
+	} elseif (strpos($settingsArray, "\r") !== false) {
330
+			$settingsArray = explode("\r", $settingsArray);
331
+	} else {
332
+			return;
333
+	}
312 334
 
313 335
 	// Presumably, the file has to have stuff in it for this function to be called :P.
314
-	if (count($settingsArray) < 10)
315
-		return;
336
+	if (count($settingsArray) < 10) {
337
+			return;
338
+	}
316 339
 
317 340
 	// remove any /r's that made there way in here
318
-	foreach ($settingsArray as $k => $dummy)
319
-		$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
341
+	foreach ($settingsArray as $k => $dummy) {
342
+			$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
343
+	}
320 344
 
321 345
 	// go line by line and see whats changing
322 346
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
323 347
 	{
324 348
 		// Don't trim or bother with it if it's not a variable.
325
-		if (substr($settingsArray[$i], 0, 1) != '$')
326
-			continue;
349
+		if (substr($settingsArray[$i], 0, 1) != '$') {
350
+					continue;
351
+		}
327 352
 
328 353
 		$settingsArray[$i] = trim($settingsArray[$i]) . "\n";
329 354
 
@@ -335,8 +360,7 @@  discard block
 block discarded – undo
335 360
 			{
336 361
 				updateDbLastError($val);
337 362
 				unset($config_vars[$var]);
338
-			}
339
-			elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
363
+			} elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
340 364
 			{
341 365
 				$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
342 366
 				$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n";
@@ -347,34 +371,39 @@  discard block
 block discarded – undo
347 371
 		}
348 372
 
349 373
 		// End of the file ... maybe
350
-		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>')
351
-			$end = $i;
374
+		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') {
375
+					$end = $i;
376
+		}
352 377
 	}
353 378
 
354 379
 	// This should never happen, but apparently it is happening.
355
-	if (empty($end) || $end < 10)
356
-		$end = count($settingsArray) - 1;
380
+	if (empty($end) || $end < 10) {
381
+			$end = count($settingsArray) - 1;
382
+	}
357 383
 
358 384
 	// Still more variables to go?  Then lets add them at the end.
359 385
 	if (!empty($config_vars))
360 386
 	{
361
-		if (trim($settingsArray[$end]) == '?' . '>')
362
-			$settingsArray[$end++] = '';
363
-		else
364
-			$end++;
387
+		if (trim($settingsArray[$end]) == '?' . '>') {
388
+					$settingsArray[$end++] = '';
389
+		} else {
390
+					$end++;
391
+		}
365 392
 
366 393
 		// Add in any newly defined vars that were passed
367
-		foreach ($config_vars as $var => $val)
368
-			$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
394
+		foreach ($config_vars as $var => $val) {
395
+					$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
396
+		}
369 397
 
370 398
 		$settingsArray[$end] = '?' . '>';
399
+	} else {
400
+			$settingsArray[$end] = trim($settingsArray[$end]);
371 401
 	}
372
-	else
373
-		$settingsArray[$end] = trim($settingsArray[$end]);
374 402
 
375 403
 	// Sanity error checking: the file needs to be at least 12 lines.
376
-	if (count($settingsArray) < 12)
377
-		return;
404
+	if (count($settingsArray) < 12) {
405
+			return;
406
+	}
378 407
 
379 408
 	// Try to avoid a few pitfalls:
380 409
 	//  - like a possible race condition,
@@ -382,8 +411,9 @@  discard block
 block discarded – undo
382 411
 	//
383 412
 	// Check before you act: if cache is enabled, we can do a simple write test
384 413
 	// to validate that we even write things on this filesystem.
385
-	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
386
-		$cachedir = $boarddir . '/cache';
414
+	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
415
+			$cachedir = $boarddir . '/cache';
416
+	}
387 417
 
388 418
 	$test_fp = @fopen($cachedir . '/settings_update.tmp', "w+");
389 419
 	if ($test_fp)
@@ -419,16 +449,18 @@  discard block
 block discarded – undo
419 449
 			// Well this is not good at all, lets see if we can save this
420 450
 			$context['settings_message'] = 'settings_error';
421 451
 
422
-			if (file_exists($boarddir . '/Settings_bak.php'))
423
-				@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
452
+			if (file_exists($boarddir . '/Settings_bak.php')) {
453
+							@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
454
+			}
424 455
 		}
425 456
 	}
426 457
 
427 458
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
428 459
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
429
-	if (function_exists('opcache_invalidate'))
430
-		opcache_invalidate($boarddir . '/Settings.php', true);
431
-}
460
+	if (function_exists('opcache_invalidate')) {
461
+			opcache_invalidate($boarddir . '/Settings.php', true);
462
+	}
463
+	}
432 464
 
433 465
 /**
434 466
  * Saves the time of the last db error for the error log
@@ -454,8 +486,9 @@  discard block
 block discarded – undo
454 486
 	global $options, $context, $smcFunc, $settings, $user_info;
455 487
 
456 488
 	// This must exist!
457
-	if (!isset($context['admin_preferences']))
458
-		return false;
489
+	if (!isset($context['admin_preferences'])) {
490
+			return false;
491
+	}
459 492
 
460 493
 	// This is what we'll be saving.
461 494
 	$options['admin_preferences'] = json_encode($context['admin_preferences']);
@@ -519,8 +552,9 @@  discard block
 block discarded – undo
519 552
 	$emails_sent = array();
520 553
 	while ($row = $smcFunc['db_fetch_assoc']($request))
521 554
 	{
522
-		if (empty($prefs[$row['id_member']]['announcements']))
523
-			continue;
555
+		if (empty($prefs[$row['id_member']]['announcements'])) {
556
+					continue;
557
+		}
524 558
 
525 559
 		// Stick their particulars in the replacement data.
526 560
 		$replacements['IDMEMBER'] = $row['id_member'];
@@ -539,11 +573,12 @@  discard block
 block discarded – undo
539 573
 	$smcFunc['db_free_result']($request);
540 574
 
541 575
 	// Any additional users we must email this to?
542
-	if (!empty($additional_recipients))
543
-		foreach ($additional_recipients as $recipient)
576
+	if (!empty($additional_recipients)) {
577
+			foreach ($additional_recipients as $recipient)
544 578
 		{
545 579
 			if (in_array($recipient['email'], $emails_sent))
546 580
 				continue;
581
+	}
547 582
 
548 583
 			$replacements['IDMEMBER'] = $recipient['id'];
549 584
 			$replacements['REALNAME'] = $recipient['name'];
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@
 block discarded – undo
150 150
  *
151 151
  * @param bool $local Whether we want local cookies
152 152
  * @param bool $global Whether we want global cookies
153
- * @return array An array to set the cookie on with domain and path in it, in that order
153
+ * @return string An array to set the cookie on with domain and path in it, in that order
154 154
  */
155 155
 function url_parts($local, $global)
156 156
 {
Please login to merge, or discard this patch.
Braces   +160 added lines, -115 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -43,8 +44,9 @@  discard block
 block discarded – undo
43 44
 		$array = smf_json_decode($_COOKIE[$cookiename], true);
44 45
 
45 46
 		// Legacy format
46
-		if (is_null($array))
47
-			$array = safe_unserialize($_COOKIE[$cookiename]);
47
+		if (is_null($array)) {
48
+					$array = safe_unserialize($_COOKIE[$cookiename]);
49
+		}
48 50
 
49 51
 		// Out with the old, in with the new!
50 52
 		if (isset($array[3]) && $array[3] != $cookie_state)
@@ -62,8 +64,9 @@  discard block
 block discarded – undo
62 64
 	smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
63 65
 
64 66
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
65
-	if (empty($id) && !empty($modSettings['globalCookies']))
66
-		smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
67
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
68
+			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
69
+	}
67 70
 
68 71
 	// Any alias URLs?  This is mainly for use with frames, etc.
69 72
 	if (!empty($modSettings['forum_alias_urls']))
@@ -79,8 +82,9 @@  discard block
 block discarded – undo
79 82
 
80 83
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
81 84
 
82
-			if ($cookie_url[0] == '')
83
-				$cookie_url[0] = strtok($alias, '/');
85
+			if ($cookie_url[0] == '') {
86
+							$cookie_url[0] = strtok($alias, '/');
87
+			}
84 88
 
85 89
 			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
86 90
 		}
@@ -126,8 +130,9 @@  discard block
 block discarded – undo
126 130
 	$identifier = $cookiename . '_tfa';
127 131
 	$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
128 132
 
129
-	if ($preserve)
130
-		$cookie_length = 81600 * 30;
133
+	if ($preserve) {
134
+			$cookie_length = 81600 * 30;
135
+	}
131 136
 
132 137
 	// Get the data and path to set it on.
133 138
 	$data = json_encode(empty($id) ? array(0, '', 0, $cookie_state, false) : array($id, $secret, time() + $cookie_length, $cookie_state, $preserve));
@@ -137,8 +142,9 @@  discard block
 block discarded – undo
137 142
 	smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
138 143
 
139 144
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
140
-	if (empty($id) && !empty($modSettings['globalCookies']))
141
-		smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
145
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
146
+			smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
147
+	}
142 148
 
143 149
 	$_COOKIE[$identifier] = $data;
144 150
 }
@@ -160,23 +166,28 @@  discard block
 block discarded – undo
160 166
 	$parsed_url = parse_url($boardurl);
161 167
 
162 168
 	// Is local cookies off?
163
-	if (empty($parsed_url['path']) || !$local)
164
-		$parsed_url['path'] = '';
169
+	if (empty($parsed_url['path']) || !$local) {
170
+			$parsed_url['path'] = '';
171
+	}
165 172
 
166
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
167
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
173
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
174
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
175
+	}
168 176
 
169 177
 	// Globalize cookies across domains (filter out IP-addresses)?
170
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
171
-		$parsed_url['host'] = '.' . $parts[1];
178
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
179
+			$parsed_url['host'] = '.' . $parts[1];
180
+	}
172 181
 
173 182
 	// We shouldn't use a host at all if both options are off.
174
-	elseif (!$local && !$global)
175
-		$parsed_url['host'] = '';
183
+	elseif (!$local && !$global) {
184
+			$parsed_url['host'] = '';
185
+	}
176 186
 
177 187
 	// The host also shouldn't be set if there aren't any dots in it.
178
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
179
-		$parsed_url['host'] = '';
188
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
189
+			$parsed_url['host'] = '';
190
+	}
180 191
 
181 192
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
182 193
 }
@@ -195,8 +206,9 @@  discard block
 block discarded – undo
195 206
 	createToken('login');
196 207
 
197 208
 	// Never redirect to an attachment
198
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
199
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
209
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
210
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
211
+	}
200 212
 
201 213
 	$context['sub_template'] = 'kick_guest';
202 214
 	$context['page_title'] = $txt['login'];
@@ -251,10 +263,12 @@  discard block
 block discarded – undo
251 263
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
252 264
 		log_error($txt['security_wrong'], 'critical');
253 265
 
254
-		if (isset($_POST[$type . '_hash_pass']))
255
-			unset($_POST[$type . '_hash_pass']);
256
-		if (isset($_POST[$type . '_pass']))
257
-			unset($_POST[$type . '_pass']);
266
+		if (isset($_POST[$type . '_hash_pass'])) {
267
+					unset($_POST[$type . '_hash_pass']);
268
+		}
269
+		if (isset($_POST[$type . '_pass'])) {
270
+					unset($_POST[$type . '_pass']);
271
+		}
258 272
 
259 273
 		$context['incorrect_password'] = true;
260 274
 	}
@@ -267,15 +281,17 @@  discard block
 block discarded – undo
267 281
 
268 282
 	// Now go through $_POST.  Make sure the session hash is sent.
269 283
 	$_POST[$context['session_var']] = $context['session_id'];
270
-	foreach ($_POST as $k => $v)
271
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
284
+	foreach ($_POST as $k => $v) {
285
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
286
+	}
272 287
 
273 288
 	// Now we'll use the admin_login sub template of the Login template.
274 289
 	$context['sub_template'] = 'admin_login';
275 290
 
276 291
 	// And title the page something like "Login".
277
-	if (!isset($context['page_title']))
278
-		$context['page_title'] = $txt['login'];
292
+	if (!isset($context['page_title'])) {
293
+			$context['page_title'] = $txt['login'];
294
+	}
279 295
 
280 296
 	// The type of action.
281 297
 	$context['sessionCheckType'] = $type;
@@ -298,14 +314,15 @@  discard block
 block discarded – undo
298 314
 {
299 315
 	global $smcFunc;
300 316
 
301
-	if (!is_array($v))
302
-		return '
317
+	if (!is_array($v)) {
318
+			return '
303 319
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
304
-	else
320
+	} else
305 321
 	{
306 322
 		$ret = '';
307
-		foreach ($v as $k2 => $v2)
308
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
323
+		foreach ($v as $k2 => $v2) {
324
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
325
+		}
309 326
 
310 327
 		return $ret;
311 328
 	}
@@ -332,18 +349,20 @@  discard block
 block discarded – undo
332 349
 		foreach ($get as $k => $v)
333 350
 		{
334 351
 			// Only if it's not already in the $scripturl!
335
-			if (!isset($temp[$k]))
336
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
352
+			if (!isset($temp[$k])) {
353
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
354
+			}
337 355
 			// If it changed, put it out there, but with an ampersand.
338
-			elseif ($temp[$k] != $get[$k])
339
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
356
+			elseif ($temp[$k] != $get[$k]) {
357
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
358
+			}
340 359
 		}
341
-	}
342
-	else
360
+	} else
343 361
 	{
344 362
 		// Add up all the data from $_GET into get_data.
345
-		foreach ($get as $k => $v)
346
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
363
+		foreach ($get as $k => $v) {
364
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
365
+		}
347 366
 	}
348 367
 
349 368
 	$query_string = substr($query_string, 0, -1);
@@ -366,8 +385,9 @@  discard block
 block discarded – undo
366 385
 	global $scripturl, $user_info, $smcFunc;
367 386
 
368 387
 	// If it's not already an array, make it one.
369
-	if (!is_array($names))
370
-		$names = explode(',', $names);
388
+	if (!is_array($names)) {
389
+			$names = explode(',', $names);
390
+	}
371 391
 
372 392
 	$maybe_email = false;
373 393
 	foreach ($names as $i => $name)
@@ -378,10 +398,11 @@  discard block
 block discarded – undo
378 398
 		$maybe_email |= strpos($name, '@') !== false;
379 399
 
380 400
 		// Make it so standard wildcards will work. (* and ?)
381
-		if ($use_wildcards)
382
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
383
-		else
384
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
401
+		if ($use_wildcards) {
402
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
403
+		} else {
404
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
405
+		}
385 406
 	}
386 407
 
387 408
 	// What are we using to compare?
@@ -391,11 +412,12 @@  discard block
 block discarded – undo
391 412
 	$results = array();
392 413
 
393 414
 	// This ensures you can't search someones email address if you can't see it.
394
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
395
-		$email_condition = '
415
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
416
+			$email_condition = '
396 417
 			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
397
-	else
398
-		$email_condition = '';
418
+	} else {
419
+			$email_condition = '';
420
+	}
399 421
 
400 422
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
401 423
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -453,10 +475,11 @@  discard block
 block discarded – undo
453 475
 	$context['template_layers'] = array();
454 476
 	$context['sub_template'] = 'find_members';
455 477
 
456
-	if (isset($_REQUEST['search']))
457
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
458
-	else
459
-		$_REQUEST['start'] = 0;
478
+	if (isset($_REQUEST['search'])) {
479
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
480
+	} else {
481
+			$_REQUEST['start'] = 0;
482
+	}
460 483
 
461 484
 	// Allow the user to pass the input to be added to to the box.
462 485
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -497,10 +520,10 @@  discard block
 block discarded – undo
497 520
 		);
498 521
 
499 522
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
523
+	} else {
524
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
525
+	}
500 526
 	}
501
-	else
502
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
503
-}
504 527
 
505 528
 /**
506 529
  * Outputs each member name on its own line.
@@ -516,8 +539,9 @@  discard block
 block discarded – undo
516 539
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
517 540
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
518 541
 
519
-	if (function_exists('iconv'))
520
-		header('Content-Type: text/plain; charset=UTF-8');
542
+	if (function_exists('iconv')) {
543
+			header('Content-Type: text/plain; charset=UTF-8');
544
+	}
521 545
 
522 546
 	$request = $smcFunc['db_query']('', '
523 547
 		SELECT real_name
@@ -537,14 +561,16 @@  discard block
 block discarded – undo
537 561
 		if (function_exists('iconv'))
538 562
 		{
539 563
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
540
-			if ($utf8)
541
-				$row['real_name'] = $utf8;
564
+			if ($utf8) {
565
+							$row['real_name'] = $utf8;
566
+			}
542 567
 		}
543 568
 
544 569
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
545 570
 
546
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
547
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
571
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
572
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
573
+		}
548 574
 
549 575
 		echo $row['real_name'], "\n";
550 576
 	}
@@ -601,9 +627,9 @@  discard block
 block discarded – undo
601 627
 
602 628
 		// Update the database...
603 629
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
630
+	} else {
631
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
604 632
 	}
605
-	else
606
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
607 633
 
608 634
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
609 635
 
@@ -634,31 +660,37 @@  discard block
 block discarded – undo
634 660
 	$errors = array();
635 661
 
636 662
 	// Don't use too long a name.
637
-	if ($smcFunc['strlen']($username) > 25)
638
-		$errors[] = array('lang', 'error_long_name');
663
+	if ($smcFunc['strlen']($username) > 25) {
664
+			$errors[] = array('lang', 'error_long_name');
665
+	}
639 666
 
640 667
 	// No name?!  How can you register with no name?
641
-	if ($username == '')
642
-		$errors[] = array('lang', 'need_username');
668
+	if ($username == '') {
669
+			$errors[] = array('lang', 'need_username');
670
+	}
643 671
 
644 672
 	// Only these characters are permitted.
645
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
646
-		$errors[] = array('lang', 'error_invalid_characters_username');
673
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
674
+			$errors[] = array('lang', 'error_invalid_characters_username');
675
+	}
647 676
 
648
-	if (stristr($username, $txt['guest_title']) !== false)
649
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
677
+	if (stristr($username, $txt['guest_title']) !== false) {
678
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
679
+	}
650 680
 
651 681
 	if ($check_reserved_name)
652 682
 	{
653 683
 		require_once($sourcedir . '/Subs-Members.php');
654
-		if (isReservedName($username, $memID, false))
655
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
684
+		if (isReservedName($username, $memID, false)) {
685
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
686
+		}
656 687
 	}
657 688
 
658
-	if ($return_error)
659
-		return $errors;
660
-	elseif (empty($errors))
661
-		return null;
689
+	if ($return_error) {
690
+			return $errors;
691
+	} elseif (empty($errors)) {
692
+			return null;
693
+	}
662 694
 
663 695
 	loadLanguage('Errors');
664 696
 	$error = $errors[0];
@@ -684,22 +716,26 @@  discard block
 block discarded – undo
684 716
 	global $modSettings, $smcFunc;
685 717
 
686 718
 	// Perform basic requirements first.
687
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
688
-		return 'short';
719
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
720
+			return 'short';
721
+	}
689 722
 
690 723
 	// Is this enough?
691
-	if (empty($modSettings['password_strength']))
692
-		return null;
724
+	if (empty($modSettings['password_strength'])) {
725
+			return null;
726
+	}
693 727
 
694 728
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
695
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
696
-		return 'restricted_words';
697
-	elseif ($smcFunc['strpos']($password, $username) !== false)
698
-		return 'restricted_words';
729
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
730
+			return 'restricted_words';
731
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
732
+			return 'restricted_words';
733
+	}
699 734
 
700 735
 	// If just medium, we're done.
701
-	if ($modSettings['password_strength'] == 1)
702
-		return null;
736
+	if ($modSettings['password_strength'] == 1) {
737
+			return null;
738
+	}
703 739
 
704 740
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
705 741
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -731,14 +767,16 @@  discard block
 block discarded – undo
731 767
 			)
732 768
 		);
733 769
 		$groups = array();
734
-		while ($row = $smcFunc['db_fetch_assoc']($request))
735
-			$groups[] = $row['id_group'];
770
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
771
+					$groups[] = $row['id_group'];
772
+		}
736 773
 		$smcFunc['db_free_result']($request);
737 774
 
738
-		if (empty($groups))
739
-			$group_query = '0=1';
740
-		else
741
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
775
+		if (empty($groups)) {
776
+					$group_query = '0=1';
777
+		} else {
778
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
779
+		}
742 780
 	}
743 781
 
744 782
 	// Then, same again, just the boards this time!
@@ -748,10 +786,11 @@  discard block
 block discarded – undo
748 786
 	{
749 787
 		$boards = boardsAllowedTo('moderate_board', true);
750 788
 
751
-		if (empty($boards))
752
-			$board_query = '0=1';
753
-		else
754
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
789
+		if (empty($boards)) {
790
+					$board_query = '0=1';
791
+		} else {
792
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
793
+		}
755 794
 	}
756 795
 
757 796
 	// What boards are they the moderator of?
@@ -766,8 +805,9 @@  discard block
 block discarded – undo
766 805
 				'current_member' => $user_info['id'],
767 806
 			)
768 807
 		);
769
-		while ($row = $smcFunc['db_fetch_assoc']($request))
770
-			$boards_mod[] = $row['id_board'];
808
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
809
+					$boards_mod[] = $row['id_board'];
810
+		}
771 811
 		$smcFunc['db_free_result']($request);
772 812
 
773 813
 		// Can any of the groups they're in moderate any of the boards?
@@ -779,8 +819,9 @@  discard block
 block discarded – undo
779 819
 				'groups' => $user_info['groups'],
780 820
 			)
781 821
 		);
782
-		while ($row = $smcFunc['db_fetch_assoc']($request))
783
-			$boards_mod[] = $row['id_board'];
822
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
823
+					$boards_mod[] = $row['id_board'];
824
+		}
784 825
 		$smcFunc['db_free_result']($request);
785 826
 
786 827
 		// Just in case we've got duplicates here...
@@ -825,10 +866,12 @@  discard block
 block discarded – undo
825 866
 	global $modSettings;
826 867
 
827 868
 	// In case a customization wants to override the default settings
828
-	if ($httponly === null)
829
-		$httponly = !empty($modSettings['httponlyCookies']);
830
-	if ($secure === null)
831
-		$secure = !empty($modSettings['secureCookies']);
869
+	if ($httponly === null) {
870
+			$httponly = !empty($modSettings['httponlyCookies']);
871
+	}
872
+	if ($secure === null) {
873
+			$secure = !empty($modSettings['secureCookies']);
874
+	}
832 875
 
833 876
 	// Intercept cookie?
834 877
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -848,8 +891,9 @@  discard block
 block discarded – undo
848 891
 function hash_password($username, $password, $cost = null)
849 892
 {
850 893
 	global $sourcedir, $smcFunc, $modSettings;
851
-	if (!function_exists('password_hash'))
852
-		require_once($sourcedir . '/Subs-Password.php');
894
+	if (!function_exists('password_hash')) {
895
+			require_once($sourcedir . '/Subs-Password.php');
896
+	}
853 897
 
854 898
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
855 899
 
@@ -881,8 +925,9 @@  discard block
 block discarded – undo
881 925
 function hash_verify_password($username, $password, $hash)
882 926
 {
883 927
 	global $sourcedir, $smcFunc;
884
-	if (!function_exists('password_verify'))
885
-		require_once($sourcedir . '/Subs-Password.php');
928
+	if (!function_exists('password_verify')) {
929
+			require_once($sourcedir . '/Subs-Password.php');
930
+	}
886 931
 
887 932
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
888 933
 }
Please login to merge, or discard this patch.