Completed
Push — release-2.1 ( e55abf...f15ab1 )
by
unknown
08:31
created
Sources/Display.php 1 patch
Braces   +292 added lines, -214 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -394,21 +399,25 @@  discard block
 block discarded – undo
394 399
 		);
395 400
 		while ($row = $smcFunc['db_fetch_assoc']($request))
396 401
 		{
397
-			if (empty($row['id_member']))
398
-				continue;
402
+			if (empty($row['id_member'])) {
403
+							continue;
404
+			}
399 405
 
400
-			if (!empty($row['online_color']))
401
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
402
-			else
403
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
406
+			if (!empty($row['online_color'])) {
407
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
408
+			} else {
409
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
410
+			}
404 411
 
405 412
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
406
-			if ($is_buddy)
407
-				$link = '<strong>' . $link . '</strong>';
413
+			if ($is_buddy) {
414
+							$link = '<strong>' . $link . '</strong>';
415
+			}
408 416
 
409 417
 			// Add them both to the list and to the more detailed list.
410
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
411
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
418
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
419
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
420
+			}
412 421
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
413 422
 				'id' => $row['id_member'],
414 423
 				'username' => $row['member_name'],
@@ -420,8 +429,9 @@  discard block
 block discarded – undo
420 429
 				'hidden' => empty($row['show_online']),
421 430
 			);
422 431
 
423
-			if (empty($row['show_online']))
424
-				$context['view_num_hidden']++;
432
+			if (empty($row['show_online'])) {
433
+							$context['view_num_hidden']++;
434
+			}
425 435
 		}
426 436
 
427 437
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -435,11 +445,13 @@  discard block
 block discarded – undo
435 445
 
436 446
 	// If all is set, but not allowed... just unset it.
437 447
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
438
-	if (isset($_REQUEST['all']) && !$can_show_all)
439
-		unset($_REQUEST['all']);
448
+	if (isset($_REQUEST['all']) && !$can_show_all) {
449
+			unset($_REQUEST['all']);
450
+	}
440 451
 	// Otherwise, it must be allowed... so pretend start was -1.
441
-	elseif (isset($_REQUEST['all']))
442
-		$_REQUEST['start'] = -1;
452
+	elseif (isset($_REQUEST['all'])) {
453
+			$_REQUEST['start'] = -1;
454
+	}
443 455
 
444 456
 	// Construct the page index, allowing for the .START method...
445 457
 	$context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
@@ -476,8 +488,9 @@  discard block
 block discarded – undo
476 488
 			$_REQUEST['start'] = 0;
477 489
 		}
478 490
 		// They aren't using it, but the *option* is there, at least.
479
-		else
480
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
491
+		else {
492
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
493
+		}
481 494
 	}
482 495
 
483 496
 	// Build the link tree.
@@ -493,14 +506,16 @@  discard block
 block discarded – undo
493 506
 	if (!empty($board_info['moderators']))
494 507
 	{
495 508
 		// Add a link for each moderator...
496
-		foreach ($board_info['moderators'] as $mod)
497
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
509
+		foreach ($board_info['moderators'] as $mod) {
510
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
511
+		}
498 512
 	}
499 513
 	if (!empty($board_info['moderator_groups']))
500 514
 	{
501 515
 		// Add a link for each moderator group as well...
502
-		foreach ($board_info['moderator_groups'] as $mod_group)
503
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
516
+		foreach ($board_info['moderator_groups'] as $mod_group) {
517
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
518
+		}
504 519
 	}
505 520
 
506 521
 	if (!empty($context['link_moderators']))
@@ -531,9 +546,9 @@  discard block
 block discarded – undo
531 546
 	// For quick reply we need a response prefix in the default forum language.
532 547
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
533 548
 	{
534
-		if ($language === $user_info['language'])
535
-			$context['response_prefix'] = $txt['response_prefix'];
536
-		else
549
+		if ($language === $user_info['language']) {
550
+					$context['response_prefix'] = $txt['response_prefix'];
551
+		} else
537 552
 		{
538 553
 			loadLanguage('index', $language, false);
539 554
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -565,8 +580,9 @@  discard block
 block discarded – undo
565 580
 			list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
566 581
 
567 582
 			// Sanity check
568
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
569
-				continue;
583
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
584
+							continue;
585
+			}
570 586
 
571 587
 			$linked_calendar_event = array(
572 588
 				'id' => $row['id_event'],
@@ -615,8 +631,9 @@  discard block
 block discarded – undo
615 631
 		}
616 632
 		$smcFunc['db_free_result']($request);
617 633
 
618
-		if (!empty($context['linked_calendar_events']))
619
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
634
+		if (!empty($context['linked_calendar_events'])) {
635
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
636
+		}
620 637
 	}
621 638
 
622 639
 	// Create the poll info if it exists.
@@ -679,8 +696,9 @@  discard block
 block discarded – undo
679 696
 		$smcFunc['db_free_result']($request);
680 697
 
681 698
 		// Got we multi choice?
682
-		if ($pollinfo['max_votes'] > 1)
683
-			$realtotal = $pollinfo['total'];
699
+		if ($pollinfo['max_votes'] > 1) {
700
+					$realtotal = $pollinfo['total'];
701
+		}
684 702
 
685 703
 		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
686 704
 		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
@@ -693,20 +711,21 @@  discard block
 block discarded – undo
693 711
 				foreach ($guestinfo as $i => $guestvoted)
694 712
 				{
695 713
 					$guestvoted = explode(',', $guestvoted);
696
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
697
-						break;
714
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
715
+											break;
716
+					}
698 717
 				}
699 718
 				// Has the poll been reset since guest voted?
700 719
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
701 720
 				{
702 721
 					// Remove the poll info from the cookie to allow guest to vote again
703 722
 					unset($guestinfo[$i]);
704
-					if (!empty($guestinfo))
705
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
706
-					else
707
-						unset($_COOKIE['guest_poll_vote']);
708
-				}
709
-				else
723
+					if (!empty($guestinfo)) {
724
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
725
+					} else {
726
+											unset($_COOKIE['guest_poll_vote']);
727
+					}
728
+				} else
710 729
 				{
711 730
 					// What did they vote for?
712 731
 					unset($guestvoted[0], $guestvoted[1]);
@@ -820,23 +839,29 @@  discard block
 block discarded – undo
820 839
 		// Build the poll moderation button array.
821 840
 		$context['poll_buttons'] = array();
822 841
 
823
-		if ($context['allow_return_vote'])
824
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
842
+		if ($context['allow_return_vote']) {
843
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
844
+		}
825 845
 
826
-		if ($context['show_view_results_button'])
827
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
846
+		if ($context['show_view_results_button']) {
847
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
848
+		}
828 849
 
829
-		if ($context['allow_change_vote'])
830
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
850
+		if ($context['allow_change_vote']) {
851
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
852
+		}
831 853
 
832
-		if ($context['allow_lock_poll'])
833
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
854
+		if ($context['allow_lock_poll']) {
855
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
856
+		}
834 857
 
835
-		if ($context['allow_edit_poll'])
836
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
858
+		if ($context['allow_edit_poll']) {
859
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
860
+		}
837 861
 
838
-		if ($context['can_remove_poll'])
839
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
862
+		if ($context['can_remove_poll']) {
863
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
864
+		}
840 865
 
841 866
 		// Allow mods to add additional buttons here
842 867
 		call_integration_hook('integrate_poll_buttons');
@@ -872,9 +897,9 @@  discard block
 block discarded – undo
872 897
 	{
873 898
 		$start_char = 'C';
874 899
 		$page_id = $ascending ? $context['topicinfo']['id_first_msg'] : $context['topicinfo']['id_last_msg'];
900
+	} else {
901
+			$start_char = null;
875 902
 	}
876
-	else
877
-		$start_char = null;
878 903
 
879 904
 	$limit = $context['messages_per_page'];
880 905
 
@@ -889,17 +914,17 @@  discard block
 block discarded – undo
889 914
 		{
890 915
 			$ascending_seek = true;
891 916
 			$page_operator = $ascending ? '>=' : '<=';
892
-		}
893
-		else
917
+		} else
894 918
 		{
895 919
 			$ascending_seek = false;
896 920
 			$page_operator = $ascending ? '<=' : '>=';
897 921
 		}
898 922
 
899
-		if ($start_char === 'C')
900
-			$limit_seek = $limit;
901
-		else
902
-			$limit_seek  = $limit + 1;
923
+		if ($start_char === 'C') {
924
+					$limit_seek = $limit;
925
+		} else {
926
+					$limit_seek  = $limit + 1;
927
+		}
903 928
 
904 929
 		$request = $smcFunc['db_query']('', '
905 930
 			SELECT id_msg, id_member, approved
@@ -922,21 +947,23 @@  discard block
 block discarded – undo
922 947
 		$found_msg = false;
923 948
 
924 949
 		// Fallback
925
-		if ($smcFunc['db_num_rows']($request) < 1)
926
-			unset($start_char);
927
-		else
950
+		if ($smcFunc['db_num_rows']($request) < 1) {
951
+					unset($start_char);
952
+		} else
928 953
 		{
929 954
 			while ($row = $smcFunc['db_fetch_assoc']($request))
930 955
 			{
931 956
 				// Check if the start msg is in our result
932
-				if ($row['id_msg'] == $page_id)
933
-					$found_msg = true;
957
+				if ($row['id_msg'] == $page_id) {
958
+									$found_msg = true;
959
+				}
934 960
 
935 961
 				// Skip the the start msg if we not in mode C
936 962
 				if ($start_char === 'C' || $row['id_msg'] != $page_id)
937 963
 				{
938
-					if (!empty($row['id_member']))
939
-						$all_posters[$row['id_msg']] = $row['id_member'];
964
+					if (!empty($row['id_member'])) {
965
+											$all_posters[$row['id_msg']] = $row['id_member'];
966
+					}
940 967
 
941 968
 					$messages[] = $row['id_msg'];
942 969
 				}
@@ -952,8 +979,9 @@  discard block
 block discarded – undo
952 979
 		}
953 980
 
954 981
 		// Before Page bring in the right order
955
-		if (!empty($start_char) && $start_char === 'L')
956
-			krsort($messages);
982
+		if (!empty($start_char) && $start_char === 'L') {
983
+					krsort($messages);
984
+		}
957 985
 	}
958 986
 
959 987
 	// Jump to page
@@ -989,14 +1017,16 @@  discard block
 block discarded – undo
989 1017
 
990 1018
 		while ($row = $smcFunc['db_fetch_assoc']($request))
991 1019
 		{
992
-			if (!empty($row['id_member']))
993
-				$all_posters[$row['id_msg']] = $row['id_member'];
1020
+			if (!empty($row['id_member'])) {
1021
+							$all_posters[$row['id_msg']] = $row['id_member'];
1022
+			}
994 1023
 			$messages[] = $row['id_msg'];
995 1024
 		}
996 1025
 
997 1026
 		// Sort the messages into the correct display order
998
-		if (!$ascending)
999
-			sort($messages);
1027
+		if (!$ascending) {
1028
+					sort($messages);
1029
+		}
1000 1030
 	}
1001 1031
 
1002 1032
 	// Remember the paging data for next time
@@ -1016,8 +1046,9 @@  discard block
 block discarded – undo
1016 1046
 	if (!$user_info['is_guest'] && !empty($messages))
1017 1047
 	{
1018 1048
 		$mark_at_msg = max($messages);
1019
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
1020
-			$mark_at_msg = $modSettings['maxMsgID'];
1049
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
1050
+					$mark_at_msg = $modSettings['maxMsgID'];
1051
+		}
1021 1052
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
1022 1053
 		{
1023 1054
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -1049,8 +1080,9 @@  discard block
 block discarded – undo
1049 1080
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1050 1081
 		{
1051 1082
 			// Find if this topic is marked for notification...
1052
-			if (!empty($row['id_topic']))
1053
-				$context['is_marked_notify'] = true;
1083
+			if (!empty($row['id_topic'])) {
1084
+							$context['is_marked_notify'] = true;
1085
+			}
1054 1086
 
1055 1087
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
1056 1088
 			if (!empty($row['sent']) && $do_once)
@@ -1072,8 +1104,9 @@  discard block
 block discarded – undo
1072 1104
 		}
1073 1105
 
1074 1106
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
1075
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
1076
-			$_SESSION['topicseen_cache'][$board]--;
1107
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
1108
+					$_SESSION['topicseen_cache'][$board]--;
1109
+		}
1077 1110
 		// Mark board as seen if this is the only new topic.
1078 1111
 		elseif (isset($_REQUEST['topicseen']))
1079 1112
 		{
@@ -1097,14 +1130,16 @@  discard block
 block discarded – undo
1097 1130
 			$smcFunc['db_free_result']($request);
1098 1131
 
1099 1132
 			// If there're no real new topics in this board, mark the board as seen.
1100
-			if (empty($numNewTopics))
1101
-				$_REQUEST['boardseen'] = true;
1102
-			else
1103
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1133
+			if (empty($numNewTopics)) {
1134
+							$_REQUEST['boardseen'] = true;
1135
+			} else {
1136
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1137
+			}
1104 1138
 		}
1105 1139
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
1106
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
1107
-			$_SESSION['topicseen_cache'][$board]--;
1140
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1141
+					$_SESSION['topicseen_cache'][$board]--;
1142
+		}
1108 1143
 
1109 1144
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
1110 1145
 		if (isset($_REQUEST['boardseen']))
@@ -1161,23 +1196,26 @@  discard block
 block discarded – undo
1161 1196
 			$temp = array();
1162 1197
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1163 1198
 			{
1164
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1165
-					continue;
1199
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1200
+									continue;
1201
+				}
1166 1202
 
1167 1203
 				$temp[$row['id_attach']] = $row;
1168 1204
 				$temp[$row['id_attach']]['topic'] = $topic;
1169 1205
 				$temp[$row['id_attach']]['board'] = $board;
1170 1206
 
1171
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1172
-					$context['loaded_attachments'][$row['id_msg']] = array();
1207
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1208
+									$context['loaded_attachments'][$row['id_msg']] = array();
1209
+				}
1173 1210
 			}
1174 1211
 			$smcFunc['db_free_result']($request);
1175 1212
 
1176 1213
 			// This is better than sorting it with the query...
1177 1214
 			ksort($temp);
1178 1215
 
1179
-			foreach ($temp as $row)
1180
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1216
+			foreach ($temp as $row) {
1217
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1218
+			}
1181 1219
 		}
1182 1220
 
1183 1221
 		$msg_parameters = array(
@@ -1204,21 +1242,23 @@  discard block
 block discarded – undo
1204 1242
 		);
1205 1243
 
1206 1244
 		// And the likes
1207
-		if (!empty($modSettings['enable_likes']))
1208
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1245
+		if (!empty($modSettings['enable_likes'])) {
1246
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1247
+		}
1209 1248
 
1210 1249
 		// Go to the last message if the given time is beyond the time of the last message.
1211
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1212
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1250
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1251
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1252
+		}
1213 1253
 
1214 1254
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1215 1255
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1216
-		if (empty($options['view_newest_first']))
1217
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1218
-		else
1219
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1220
-	}
1221
-	else
1256
+		if (empty($options['view_newest_first'])) {
1257
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1258
+		} else {
1259
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1260
+		}
1261
+	} else
1222 1262
 	{
1223 1263
 		$messages_request = false;
1224 1264
 		$context['first_message'] = 0;
@@ -1253,8 +1293,9 @@  discard block
 block discarded – undo
1253 1293
 		'can_restore_msg' => 'move_any',
1254 1294
 		'can_like' => 'likes_like',
1255 1295
 	);
1256
-	foreach ($common_permissions as $contextual => $perm)
1257
-		$context[$contextual] = allowedTo($perm);
1296
+	foreach ($common_permissions as $contextual => $perm) {
1297
+			$context[$contextual] = allowedTo($perm);
1298
+	}
1258 1299
 
1259 1300
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1260 1301
 	$anyown_permissions = array(
@@ -1267,8 +1308,9 @@  discard block
 block discarded – undo
1267 1308
 		'can_reply_unapproved' => 'post_unapproved_replies',
1268 1309
 		'can_view_warning' => 'profile_warning',
1269 1310
 	);
1270
-	foreach ($anyown_permissions as $contextual => $perm)
1271
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1311
+	foreach ($anyown_permissions as $contextual => $perm) {
1312
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1313
+	}
1272 1314
 
1273 1315
 	if (!$user_info['is_admin'] && $context['can_move'] && !$modSettings['topic_move_any'])
1274 1316
 	{
@@ -1314,8 +1356,9 @@  discard block
 block discarded – undo
1314 1356
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1315 1357
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1316 1358
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1317
-	if (!empty($context['drafts_save']))
1318
-		loadLanguage('Drafts');
1359
+	if (!empty($context['drafts_save'])) {
1360
+			loadLanguage('Drafts');
1361
+	}
1319 1362
 
1320 1363
 	// When was the last time this topic was replied to?  Should we warn them about it?
1321 1364
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1376,26 +1419,31 @@  discard block
 block discarded – undo
1376 1419
 	// Message icons - customized icons are off?
1377 1420
 	$context['icons'] = getMessageIcons($board);
1378 1421
 
1379
-	if (!empty($context['icons']))
1380
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1422
+	if (!empty($context['icons'])) {
1423
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1424
+	}
1381 1425
 
1382 1426
 	// Build the normal button array.
1383 1427
 	$context['normal_buttons'] = array();
1384 1428
 
1385
-	if ($context['can_reply'])
1386
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1429
+	if ($context['can_reply']) {
1430
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1431
+	}
1387 1432
 
1388
-	if ($context['can_add_poll'])
1389
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1433
+	if ($context['can_add_poll']) {
1434
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1435
+	}
1390 1436
 
1391
-	if ($context['can_mark_unread'])
1392
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1437
+	if ($context['can_mark_unread']) {
1438
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1439
+	}
1393 1440
 
1394
-	if ($context['can_print'])
1395
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1441
+	if ($context['can_print']) {
1442
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1443
+	}
1396 1444
 
1397
-	if ($context['can_set_notify'])
1398
-		$context['normal_buttons']['notify'] = array(
1445
+	if ($context['can_set_notify']) {
1446
+			$context['normal_buttons']['notify'] = array(
1399 1447
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1400 1448
 			'sub_buttons' => array(
1401 1449
 				array(
@@ -1417,38 +1465,47 @@  discard block
 block discarded – undo
1417 1465
 				),
1418 1466
 			),
1419 1467
 		);
1468
+	}
1420 1469
 
1421 1470
 	// Build the mod button array
1422 1471
 	$context['mod_buttons'] = array();
1423 1472
 
1424
-	if ($context['can_move'])
1425
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1473
+	if ($context['can_move']) {
1474
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1475
+	}
1426 1476
 
1427
-	if ($context['can_delete'])
1428
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1477
+	if ($context['can_delete']) {
1478
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1479
+	}
1429 1480
 
1430
-	if ($context['can_lock'])
1431
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1481
+	if ($context['can_lock']) {
1482
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1483
+	}
1432 1484
 
1433
-	if ($context['can_sticky'])
1434
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1485
+	if ($context['can_sticky']) {
1486
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1487
+	}
1435 1488
 
1436
-	if ($context['can_merge'])
1437
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1489
+	if ($context['can_merge']) {
1490
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1491
+	}
1438 1492
 
1439
-	if ($context['calendar_post'])
1440
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1493
+	if ($context['calendar_post']) {
1494
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1495
+	}
1441 1496
 
1442 1497
 	// Restore topic. eh?  No monkey business.
1443
-	if ($context['can_restore_topic'])
1444
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1498
+	if ($context['can_restore_topic']) {
1499
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1500
+	}
1445 1501
 
1446 1502
 	// Show a message in case a recently posted message became unapproved.
1447 1503
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1448 1504
 
1449 1505
 	// Don't want to show this forever...
1450
-	if ($context['becomesUnapproved'])
1451
-		unset($_SESSION['becomesUnapproved']);
1506
+	if ($context['becomesUnapproved']) {
1507
+			unset($_SESSION['becomesUnapproved']);
1508
+	}
1452 1509
 
1453 1510
 	// Allow adding new mod buttons easily.
1454 1511
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1457,12 +1514,14 @@  discard block
 block discarded – undo
1457 1514
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1458 1515
 
1459 1516
 	// Load the drafts js file
1460
-	if ($context['drafts_autosave'])
1461
-		loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1517
+	if ($context['drafts_autosave']) {
1518
+			loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1519
+	}
1462 1520
 
1463 1521
 	// Spellcheck
1464
-	if ($context['show_spellchecking'])
1465
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1522
+	if ($context['show_spellchecking']) {
1523
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1524
+	}
1466 1525
 
1467 1526
 	// topic.js
1468 1527
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -1496,16 +1555,19 @@  discard block
 block discarded – undo
1496 1555
 	static $counter = null;
1497 1556
 
1498 1557
 	// If the query returned false, bail.
1499
-	if ($messages_request == false)
1500
-		return false;
1558
+	if ($messages_request == false) {
1559
+			return false;
1560
+	}
1501 1561
 
1502 1562
 	// Remember which message this is.  (ie. reply #83)
1503
-	if ($counter === null || $reset)
1504
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1563
+	if ($counter === null || $reset) {
1564
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1565
+	}
1505 1566
 
1506 1567
 	// Start from the beginning...
1507
-	if ($reset)
1508
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1568
+	if ($reset) {
1569
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1570
+	}
1509 1571
 
1510 1572
 	// Attempt to get the next message.
1511 1573
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1519,19 +1581,21 @@  discard block
 block discarded – undo
1519 1581
 	if (empty($context['icon_sources']))
1520 1582
 	{
1521 1583
 		$context['icon_sources'] = array();
1522
-		foreach ($context['stable_icons'] as $icon)
1523
-			$context['icon_sources'][$icon] = 'images_url';
1584
+		foreach ($context['stable_icons'] as $icon) {
1585
+					$context['icon_sources'][$icon] = 'images_url';
1586
+		}
1524 1587
 	}
1525 1588
 
1526 1589
 	// Message Icon Management... check the images exist.
1527 1590
 	if (empty($modSettings['messageIconChecks_disable']))
1528 1591
 	{
1529 1592
 		// If the current icon isn't known, then we need to do something...
1530
-		if (!isset($context['icon_sources'][$message['icon']]))
1531
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1593
+		if (!isset($context['icon_sources'][$message['icon']])) {
1594
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1595
+		}
1596
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1597
+			$context['icon_sources'][$message['icon']] = 'images_url';
1532 1598
 	}
1533
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1534
-		$context['icon_sources'][$message['icon']] = 'images_url';
1535 1599
 
1536 1600
 	// If you're a lazy bum, you probably didn't give a subject...
1537 1601
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1556,8 +1620,7 @@  discard block
 block discarded – undo
1556 1620
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1557 1621
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1558 1622
 		$memberContext[$message['id_member']]['is_guest'] = true;
1559
-	}
1560
-	else
1623
+	} else
1561 1624
 	{
1562 1625
 		// Define this here to make things a bit more readable
1563 1626
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1580,8 +1643,9 @@  discard block
 block discarded – undo
1580 1643
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1581 1644
 
1582 1645
 	// If it's in the recycle bin we need to override whatever icon we did have.
1583
-	if (!empty($board_info['recycle']))
1584
-		$message['icon'] = 'recycled';
1646
+	if (!empty($board_info['recycle'])) {
1647
+			$message['icon'] = 'recycled';
1648
+	}
1585 1649
 
1586 1650
 	require_once($sourcedir . '/Subs-Attachments.php');
1587 1651
 
@@ -1625,32 +1689,36 @@  discard block
 block discarded – undo
1625 1689
 	}
1626 1690
 
1627 1691
 	// Are likes enable?
1628
-	if (!empty($modSettings['enable_likes']))
1629
-		$output['likes'] = array(
1692
+	if (!empty($modSettings['enable_likes'])) {
1693
+			$output['likes'] = array(
1630 1694
 			'count' => $message['likes'],
1631 1695
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1632 1696
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1633 1697
 		);
1698
+	}
1634 1699
 
1635 1700
 	// Is this user the message author?
1636 1701
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1637
-	if (!empty($output['modified']['name']))
1638
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1702
+	if (!empty($output['modified']['name'])) {
1703
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1704
+	}
1639 1705
 
1640 1706
 	// Did they give a reason for editing?
1641
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1642
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1707
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1708
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1709
+	}
1643 1710
 
1644 1711
 	// Any custom profile fields?
1645
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1646
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1712
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1713
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1647 1714
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1715
+	}
1648 1716
 
1649
-	if (empty($options['view_newest_first']))
1650
-		$counter++;
1651
-
1652
-	else
1653
-		$counter--;
1717
+	if (empty($options['view_newest_first'])) {
1718
+			$counter++;
1719
+	} else {
1720
+			$counter--;
1721
+	}
1654 1722
 
1655 1723
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1656 1724
 
@@ -1676,8 +1744,9 @@  discard block
 block discarded – undo
1676 1744
  */
1677 1745
 function approved_attach_sort($a, $b)
1678 1746
 {
1679
-	if ($a['is_approved'] == $b['is_approved'])
1680
-		return 0;
1747
+	if ($a['is_approved'] == $b['is_approved']) {
1748
+			return 0;
1749
+	}
1681 1750
 
1682 1751
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1683 1752
 }
@@ -1694,16 +1763,19 @@  discard block
 block discarded – undo
1694 1763
 
1695 1764
 	require_once($sourcedir . '/RemoveTopic.php');
1696 1765
 
1697
-	if (empty($_REQUEST['msgs']))
1698
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1766
+	if (empty($_REQUEST['msgs'])) {
1767
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1768
+	}
1699 1769
 
1700 1770
 	$messages = array();
1701
-	foreach ($_REQUEST['msgs'] as $dummy)
1702
-		$messages[] = (int) $dummy;
1771
+	foreach ($_REQUEST['msgs'] as $dummy) {
1772
+			$messages[] = (int) $dummy;
1773
+	}
1703 1774
 
1704 1775
 	// We are restoring messages. We handle this in another place.
1705
-	if (isset($_REQUEST['restore_selected']))
1706
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1776
+	if (isset($_REQUEST['restore_selected'])) {
1777
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1778
+	}
1707 1779
 	if (isset($_REQUEST['split_selection']))
1708 1780
 	{
1709 1781
 		$request = $smcFunc['db_query']('', '
@@ -1722,8 +1794,9 @@  discard block
 block discarded – undo
1722 1794
 	}
1723 1795
 
1724 1796
 	// Allowed to delete any message?
1725
-	if (allowedTo('delete_any'))
1726
-		$allowed_all = true;
1797
+	if (allowedTo('delete_any')) {
1798
+			$allowed_all = true;
1799
+	}
1727 1800
 	// Allowed to delete replies to their messages?
1728 1801
 	elseif (allowedTo('delete_replies'))
1729 1802
 	{
@@ -1740,13 +1813,14 @@  discard block
 block discarded – undo
1740 1813
 		$smcFunc['db_free_result']($request);
1741 1814
 
1742 1815
 		$allowed_all = $starter == $user_info['id'];
1816
+	} else {
1817
+			$allowed_all = false;
1743 1818
 	}
1744
-	else
1745
-		$allowed_all = false;
1746 1819
 
1747 1820
 	// Make sure they're allowed to delete their own messages, if not any.
1748
-	if (!$allowed_all)
1749
-		isAllowedTo('delete_own');
1821
+	if (!$allowed_all) {
1822
+			isAllowedTo('delete_own');
1823
+	}
1750 1824
 
1751 1825
 	// Allowed to remove which messages?
1752 1826
 	$request = $smcFunc['db_query']('', '
@@ -1766,8 +1840,9 @@  discard block
 block discarded – undo
1766 1840
 	$messages = array();
1767 1841
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1768 1842
 	{
1769
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1770
-			continue;
1843
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1844
+					continue;
1845
+		}
1771 1846
 
1772 1847
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1773 1848
 	}
@@ -1790,17 +1865,20 @@  discard block
 block discarded – undo
1790 1865
 	foreach ($messages as $message => $info)
1791 1866
 	{
1792 1867
 		// Just skip the first message - if it's not the last.
1793
-		if ($message == $first_message && $message != $last_message)
1794
-			continue;
1868
+		if ($message == $first_message && $message != $last_message) {
1869
+					continue;
1870
+		}
1795 1871
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1796
-		elseif ($message == $first_message)
1797
-			$topicGone = true;
1872
+		elseif ($message == $first_message) {
1873
+					$topicGone = true;
1874
+		}
1798 1875
 
1799 1876
 		removeMessage($message);
1800 1877
 
1801 1878
 		// Log this moderation action ;).
1802
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1803
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1879
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1880
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1881
+		}
1804 1882
 	}
1805 1883
 
1806 1884
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +229 added lines, -169 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query'					=> 'smf_db_query',
40 41
 			'db_quote'					=> 'smf_db_quote',
41 42
 			'db_insert'					=> 'smf_db_insert',
@@ -64,11 +65,13 @@  discard block
 block discarded – undo
64 65
 			'db_error_insert'			=> 'smf_db_error_insert',
65 66
 			'db_custom_order'			=> 'smf_db_custom_order',
66 67
 		);
68
+	}
67 69
 
68
-	if (!empty($db_options['persist']))
69
-		$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
70
-	else
71
-		$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
70
+	if (!empty($db_options['persist'])) {
71
+			$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
72
+	} else {
73
+			$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
74
+	}
72 75
 
73 76
 	// Something's wrong, show an error if its fatal (which we assume it is)
74 77
 	if (!$connection)
@@ -76,8 +79,7 @@  discard block
 block discarded – undo
76 79
 		if (!empty($db_options['non_fatal']))
77 80
 		{
78 81
 			return null;
79
-		}
80
-		else
82
+		} else
81 83
 		{
82 84
 			display_db_error();
83 85
 		}
@@ -128,31 +130,38 @@  discard block
 block discarded – undo
128 130
 
129 131
 	list ($values, $connection) = $db_callback;
130 132
 
131
-	if ($matches[1] === 'db_prefix')
132
-		return $db_prefix;
133
+	if ($matches[1] === 'db_prefix') {
134
+			return $db_prefix;
135
+	}
133 136
 
134
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
135
-		return $user_info[$matches[1]];
137
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
138
+			return $user_info[$matches[1]];
139
+	}
136 140
 
137
-	if ($matches[1] === 'empty')
138
-		return '\'\'';
141
+	if ($matches[1] === 'empty') {
142
+			return '\'\'';
143
+	}
139 144
 
140
-	if (!isset($matches[2]))
141
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
145
+	if (!isset($matches[2])) {
146
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
147
+	}
142 148
 
143
-	if ($matches[1] === 'literal')
144
-		return '\'' . pg_escape_string($matches[2]) . '\'';
149
+	if ($matches[1] === 'literal') {
150
+			return '\'' . pg_escape_string($matches[2]) . '\'';
151
+	}
145 152
 
146
-	if (!isset($values[$matches[2]]))
147
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
153
+	if (!isset($values[$matches[2]])) {
154
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
155
+	}
148 156
 
149 157
 	$replacement = $values[$matches[2]];
150 158
 
151 159
 	switch ($matches[1])
152 160
 	{
153 161
 		case 'int':
154
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
155
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
162
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
163
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
164
+			}
156 165
 			return (string) (int) $replacement;
157 166
 		break;
158 167
 
@@ -164,65 +173,73 @@  discard block
 block discarded – undo
164 173
 		case 'array_int':
165 174
 			if (is_array($replacement))
166 175
 			{
167
-				if (empty($replacement))
168
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
176
+				if (empty($replacement)) {
177
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
178
+				}
169 179
 
170 180
 				foreach ($replacement as $key => $value)
171 181
 				{
172
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
173
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
182
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
183
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
184
+					}
174 185
 
175 186
 					$replacement[$key] = (string) (int) $value;
176 187
 				}
177 188
 
178 189
 				return implode(', ', $replacement);
190
+			} else {
191
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179 192
 			}
180
-			else
181
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
182 193
 
183 194
 		break;
184 195
 
185 196
 		case 'array_string':
186 197
 			if (is_array($replacement))
187 198
 			{
188
-				if (empty($replacement))
189
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
199
+				if (empty($replacement)) {
200
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
201
+				}
190 202
 
191
-				foreach ($replacement as $key => $value)
192
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
203
+				foreach ($replacement as $key => $value) {
204
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
205
+				}
193 206
 
194 207
 				return implode(', ', $replacement);
208
+			} else {
209
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195 210
 			}
196
-			else
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198 211
 		break;
199 212
 
200 213
 		case 'date':
201
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
202
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
203
-			else
204
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
214
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
215
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
216
+			} else {
217
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+			}
205 219
 		break;
206 220
 
207 221
 		case 'time':
208
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
209
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
210
-			else
211
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
223
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
224
+			} else {
225
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+			}
212 227
 		break;
213 228
 
214 229
 		case 'datetime':
215
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
216
-				return 'to_timestamp('.
230
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
231
+							return 'to_timestamp('.
217 232
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
218 233
 					',\'YYYY-MM-DD HH24:MI:SS\')';
219
-			else
220
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236
+			}
221 237
 		break;
222 238
 
223 239
 		case 'float':
224
-			if (!is_numeric($replacement))
225
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240
+			if (!is_numeric($replacement)) {
241
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
242
+			}
226 243
 			return (string) (float) $replacement;
227 244
 		break;
228 245
 
@@ -235,31 +252,36 @@  discard block
 block discarded – undo
235 252
 		break;
236 253
 
237 254
 		case 'inet':
238
-			if ($replacement == 'null' || $replacement == '')
239
-				return 'null';
240
-			if (inet_pton($replacement) === false)
241
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+			if ($replacement == 'null' || $replacement == '') {
256
+							return 'null';
257
+			}
258
+			if (inet_pton($replacement) === false) {
259
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260
+			}
242 261
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
243 262
 
244 263
 		case 'array_inet':
245 264
 			if (is_array($replacement))
246 265
 			{
247
-				if (empty($replacement))
248
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+				if (empty($replacement)) {
267
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268
+				}
249 269
 
250 270
 				foreach ($replacement as $key => $value)
251 271
 				{
252
-					if ($replacement == 'null' || $replacement == '')
253
-						$replacement[$key] = 'null';
254
-					if (!isValidIP($value))
255
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272
+					if ($replacement == 'null' || $replacement == '') {
273
+											$replacement[$key] = 'null';
274
+					}
275
+					if (!isValidIP($value)) {
276
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+					}
256 278
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
257 279
 				}
258 280
 
259 281
 				return implode(', ', $replacement);
282
+			} else {
283
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260 284
 			}
261
-			else
262
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263 285
 		break;
264 286
 
265 287
 		default:
@@ -350,14 +372,16 @@  discard block
 block discarded – undo
350 372
 		),
351 373
 	);
352 374
 
353
-	if (isset($replacements[$identifier]))
354
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
375
+	if (isset($replacements[$identifier])) {
376
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
377
+	}
355 378
 
356 379
 	// Limits need to be a little different.
357 380
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
358 381
 
359
-	if (trim($db_string) == '')
360
-		return false;
382
+	if (trim($db_string) == '') {
383
+			return false;
384
+	}
361 385
 
362 386
 	// Comments that are allowed in a query are preg_removed.
363 387
 	static $allowed_comments_from = array(
@@ -377,8 +401,9 @@  discard block
 block discarded – undo
377 401
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
378 402
 	$db_replace_result = 0;
379 403
 
380
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
381
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
404
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
405
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
406
+	}
382 407
 
383 408
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
384 409
 	{
@@ -403,17 +428,18 @@  discard block
 block discarded – undo
403 428
 		while (true)
404 429
 		{
405 430
 			$pos = strpos($db_string_1, '\'', $pos + 1);
406
-			if ($pos === false)
407
-				break;
431
+			if ($pos === false) {
432
+							break;
433
+			}
408 434
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
409 435
 
410 436
 			while (true)
411 437
 			{
412 438
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
413 439
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
414
-				if ($pos1 === false)
415
-					break;
416
-				elseif ($pos2 === false || $pos2 > $pos1)
440
+				if ($pos1 === false) {
441
+									break;
442
+				} elseif ($pos2 === false || $pos2 > $pos1)
417 443
 				{
418 444
 					$pos = $pos1;
419 445
 					break;
@@ -429,16 +455,19 @@  discard block
 block discarded – undo
429 455
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
430 456
 
431 457
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
432
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
433
-			$fail = true;
458
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
459
+					$fail = true;
460
+		}
434 461
 		// Trying to change passwords, slow us down, or something?
435
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
436
-			$fail = true;
437
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
438
-			$fail = true;
462
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
463
+					$fail = true;
464
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
465
+					$fail = true;
466
+		}
439 467
 
440
-		if (!empty($fail) && function_exists('log_error'))
441
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
468
+		if (!empty($fail) && function_exists('log_error')) {
469
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
470
+		}
442 471
 	}
443 472
 
444 473
 	// Set optimize stuff
@@ -465,8 +494,9 @@  discard block
 block discarded – undo
465 494
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
466 495
 
467 496
 		// Initialize $db_cache if not already initialized.
468
-		if (!isset($db_cache))
469
-			$db_cache = array();
497
+		if (!isset($db_cache)) {
498
+					$db_cache = array();
499
+		}
470 500
 
471 501
 		if (!empty($_SESSION['debug_redirect']))
472 502
 		{
@@ -484,12 +514,14 @@  discard block
 block discarded – undo
484 514
 
485 515
 	$db_last_result = @pg_query($connection, $db_string);
486 516
 
487
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
488
-		$db_last_result = smf_db_error($db_string, $connection);
517
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
518
+			$db_last_result = smf_db_error($db_string, $connection);
519
+	}
489 520
 
490 521
 	// Debugging.
491
-	if (isset($db_show_debug) && $db_show_debug === true)
492
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
522
+	if (isset($db_show_debug) && $db_show_debug === true) {
523
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
524
+	}
493 525
 
494 526
 	return $db_last_result;
495 527
 }
@@ -506,10 +538,11 @@  discard block
 block discarded – undo
506 538
 {
507 539
 	global $db_last_result, $db_replace_result;
508 540
 
509
-	if ($db_replace_result)
510
-		return $db_replace_result;
511
-	elseif ($result === null && !$db_last_result)
512
-		return 0;
541
+	if ($db_replace_result) {
542
+			return $db_replace_result;
543
+	} elseif ($result === null && !$db_last_result) {
544
+			return 0;
545
+	}
513 546
 
514 547
 	return pg_affected_rows($result === null ? $db_last_result : $result);
515 548
 }
@@ -533,8 +566,9 @@  discard block
 block discarded – undo
533 566
 		array(
534 567
 		)
535 568
 	);
536
-	if (!$request)
537
-		return false;
569
+	if (!$request) {
570
+			return false;
571
+	}
538 572
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
539 573
 	$smcFunc['db_free_result']($request);
540 574
 
@@ -555,12 +589,13 @@  discard block
 block discarded – undo
555 589
 	// Decide which connection to use
556 590
 	$connection = $connection === null ? $db_connection : $connection;
557 591
 
558
-	if ($type == 'begin')
559
-		return @pg_query($connection, 'BEGIN');
560
-	elseif ($type == 'rollback')
561
-		return @pg_query($connection, 'ROLLBACK');
562
-	elseif ($type == 'commit')
563
-		return @pg_query($connection, 'COMMIT');
592
+	if ($type == 'begin') {
593
+			return @pg_query($connection, 'BEGIN');
594
+	} elseif ($type == 'rollback') {
595
+			return @pg_query($connection, 'ROLLBACK');
596
+	} elseif ($type == 'commit') {
597
+			return @pg_query($connection, 'COMMIT');
598
+	}
564 599
 
565 600
 	return false;
566 601
 }
@@ -588,19 +623,22 @@  discard block
 block discarded – undo
588 623
 	$query_error = @pg_last_error($connection);
589 624
 
590 625
 	// Log the error.
591
-	if (function_exists('log_error'))
592
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
626
+	if (function_exists('log_error')) {
627
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
628
+	}
593 629
 
594 630
 	// Nothing's defined yet... just die with it.
595
-	if (empty($context) || empty($txt))
596
-		die($query_error);
631
+	if (empty($context) || empty($txt)) {
632
+			die($query_error);
633
+	}
597 634
 
598 635
 	// Show an error message, if possible.
599 636
 	$context['error_title'] = $txt['database_error'];
600
-	if (allowedTo('admin_forum'))
601
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
602
-	else
603
-		$context['error_message'] = $txt['try_again'];
637
+	if (allowedTo('admin_forum')) {
638
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
639
+	} else {
640
+			$context['error_message'] = $txt['try_again'];
641
+	}
604 642
 
605 643
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
606 644
 	{
@@ -622,12 +660,14 @@  discard block
 block discarded – undo
622 660
 {
623 661
 	global $db_row_count;
624 662
 
625
-	if ($counter !== false)
626
-		return pg_fetch_row($request, $counter);
663
+	if ($counter !== false) {
664
+			return pg_fetch_row($request, $counter);
665
+	}
627 666
 
628 667
 	// Reset the row counter...
629
-	if (!isset($db_row_count[(int) $request]))
630
-		$db_row_count[(int) $request] = 0;
668
+	if (!isset($db_row_count[(int) $request])) {
669
+			$db_row_count[(int) $request] = 0;
670
+	}
631 671
 
632 672
 	// Return the right row.
633 673
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -644,12 +684,14 @@  discard block
 block discarded – undo
644 684
 {
645 685
 	global $db_row_count;
646 686
 
647
-	if ($counter !== false)
648
-		return pg_fetch_assoc($request, $counter);
687
+	if ($counter !== false) {
688
+			return pg_fetch_assoc($request, $counter);
689
+	}
649 690
 
650 691
 	// Reset the row counter...
651
-	if (!isset($db_row_count[(int) $request]))
652
-		$db_row_count[(int) $request] = 0;
692
+	if (!isset($db_row_count[(int) $request])) {
693
+			$db_row_count[(int) $request] = 0;
694
+	}
653 695
 
654 696
 	// Return the right row.
655 697
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -702,11 +744,13 @@  discard block
 block discarded – undo
702 744
 
703 745
 	$replace = '';
704 746
 
705
-	if (empty($data))
706
-		return;
747
+	if (empty($data)) {
748
+			return;
749
+	}
707 750
 
708
-	if (!is_array($data[array_rand($data)]))
709
-		$data = array($data);
751
+	if (!is_array($data[array_rand($data)])) {
752
+			$data = array($data);
753
+	}
710 754
 
711 755
 	// Replace the prefix holder with the actual prefix.
712 756
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -725,11 +769,13 @@  discard block
 block discarded – undo
725 769
 			//pg 9.5 got replace support
726 770
 			$pg_version = $smcFunc['db_get_version']();
727 771
 			// if we got a Beta Version
728
-			if (stripos($pg_version, 'beta') !== false)
729
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
772
+			if (stripos($pg_version, 'beta') !== false) {
773
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
774
+			}
730 775
 			// or RC
731
-			if (stripos($pg_version, 'rc') !== false)
732
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
776
+			if (stripos($pg_version, 'rc') !== false) {
777
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
778
+			}
733 779
 
734 780
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
735 781
 		}
@@ -748,32 +794,35 @@  discard block
 block discarded – undo
748 794
 					$key_str .= ($count_pk > 0 ? ',' : '');
749 795
 					$key_str .= $columnName;
750 796
 					$count_pk++;
751
-				}
752
-				else if ($method == 'replace') //normal field
797
+				} else if ($method == 'replace') {
798
+					//normal field
753 799
 				{
754 800
 					$col_str .= ($count > 0 ? ',' : '');
801
+				}
755 802
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
756 803
 					$count++;
757 804
 				}
758 805
 			}
759
-			if ($method == 'replace')
760
-				$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
761
-			else
762
-				$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
763
-		}
764
-		else if ($method == 'replace')
806
+			if ($method == 'replace') {
807
+							$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
808
+			} else {
809
+							$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
810
+			}
811
+		} else if ($method == 'replace')
765 812
 		{
766 813
 			foreach ($columns as $columnName => $type)
767 814
 			{
768 815
 				// Are we restricting the length?
769
-				if (strpos($type, 'string-') !== false)
770
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
771
-				else
772
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
816
+				if (strpos($type, 'string-') !== false) {
817
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
818
+				} else {
819
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
820
+				}
773 821
 
774 822
 				// A key? That's what we were looking for.
775
-				if (in_array($columnName, $keys))
776
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
823
+				if (in_array($columnName, $keys)) {
824
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
825
+				}
777 826
 				$count++;
778 827
 			}
779 828
 
@@ -809,10 +858,11 @@  discard block
 block discarded – undo
809 858
 		foreach ($columns as $columnName => $type)
810 859
 		{
811 860
 			// Are we restricting the length?
812
-			if (strpos($type, 'string-') !== false)
813
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
814
-			else
815
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
861
+			if (strpos($type, 'string-') !== false) {
862
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
863
+			} else {
864
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
865
+			}
816 866
 		}
817 867
 		$insertData = substr($insertData, 0, -2) . ')';
818 868
 
@@ -821,8 +871,9 @@  discard block
 block discarded – undo
821 871
 
822 872
 		// Here's where the variables are injected to the query.
823 873
 		$insertRows = array();
824
-		foreach ($data as $dataRow)
825
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
874
+		foreach ($data as $dataRow) {
875
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
876
+		}
826 877
 
827 878
 		// Do the insert.
828 879
 		$request = $smcFunc['db_query']('', '
@@ -839,19 +890,21 @@  discard block
 block discarded – undo
839 890
 
840 891
 		if ($with_returning && $request !== false)
841 892
 		{
842
-			if ($returnmode === 2)
843
-				$return_var = array();
893
+			if ($returnmode === 2) {
894
+							$return_var = array();
895
+			}
844 896
 
845 897
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
846 898
 			{
847
-				if (is_numeric($row[0])) // try to emulate mysql limitation
899
+				if (is_numeric($row[0])) {
900
+					// try to emulate mysql limitation
848 901
 				{
849 902
 					if ($returnmode === 1)
850 903
 						$return_var = $row[0];
851
-					elseif ($returnmode === 2)
852
-						$return_var[] = $row[0];
853
-				}
854
-				else
904
+				} elseif ($returnmode === 2) {
905
+											$return_var[] = $row[0];
906
+					}
907
+				} else
855 908
 				{
856 909
 					$with_returning = false;
857 910
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -860,9 +913,10 @@  discard block
 block discarded – undo
860 913
 		}
861 914
 	}
862 915
 
863
-	if ($with_returning && !empty($return_var))
864
-		return $return_var;
865
-}
916
+	if ($with_returning && !empty($return_var)) {
917
+			return $return_var;
918
+	}
919
+	}
866 920
 
867 921
 /**
868 922
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -899,8 +953,9 @@  discard block
 block discarded – undo
899 953
  */
900 954
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
901 955
 {
902
-	if (empty($log_message))
903
-		$log_message = $error_message;
956
+	if (empty($log_message)) {
957
+			$log_message = $error_message;
958
+	}
904 959
 
905 960
 	foreach (debug_backtrace() as $step)
906 961
 	{
@@ -919,12 +974,14 @@  discard block
 block discarded – undo
919 974
 	}
920 975
 
921 976
 	// A special case - we want the file and line numbers for debugging.
922
-	if ($error_type == 'return')
923
-		return array($file, $line);
977
+	if ($error_type == 'return') {
978
+			return array($file, $line);
979
+	}
924 980
 
925 981
 	// Is always a critical error.
926
-	if (function_exists('log_error'))
927
-		log_error($log_message, 'critical', $file, $line);
982
+	if (function_exists('log_error')) {
983
+			log_error($log_message, 'critical', $file, $line);
984
+	}
928 985
 
929 986
 	if (function_exists('fatal_error'))
930 987
 	{
@@ -932,12 +989,12 @@  discard block
 block discarded – undo
932 989
 
933 990
 		// Cannot continue...
934 991
 		exit;
992
+	} elseif ($error_type) {
993
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
994
+	} else {
995
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
996
+	}
935 997
 	}
936
-	elseif ($error_type)
937
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
938
-	else
939
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
940
-}
941 998
 
942 999
 /**
943 1000
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -954,10 +1011,11 @@  discard block
 block discarded – undo
954 1011
 		'\\' => '\\\\',
955 1012
 	);
956 1013
 
957
-	if ($translate_human_wildcards)
958
-		$replacements += array(
1014
+	if ($translate_human_wildcards) {
1015
+			$replacements += array(
959 1016
 			'*' => '%',
960 1017
 		);
1018
+	}
961 1019
 
962 1020
 	return strtr($string, $replacements);
963 1021
 }
@@ -985,11 +1043,12 @@  discard block
 block discarded – undo
985 1043
 	global  $db_prefix, $db_connection;
986 1044
 	static $pg_error_data_prep;
987 1045
 
988
-	if (empty($pg_error_data_prep))
989
-			$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
1046
+	if (empty($pg_error_data_prep)) {
1047
+				$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
990 1048
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
991 1049
 													VALUES(		$1,		$2,		$3, $4, 	$5,		$6,			$7,		$8,	$9)'
992 1050
 			);
1051
+	}
993 1052
 
994 1053
 	pg_execute($db_connection, 'smf_log_errors', $error_array);
995 1054
 }
@@ -1009,8 +1068,9 @@  discard block
 block discarded – undo
1009 1068
 	$count = count($array_values);
1010 1069
 	$then = ($desc ? ' THEN -' : ' THEN ');
1011 1070
 
1012
-	for ($i = 0; $i < $count; $i++)
1013
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1071
+	for ($i = 0; $i < $count; $i++) {
1072
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1073
+	}
1014 1074
 
1015 1075
 	$return .= 'END';
1016 1076
 	return $return;
Please login to merge, or discard this patch.
Smileys/alienine/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +277 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 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -63,9 +64,11 @@  discard block
 block discarded – undo
63 64
 			'db_error_insert'			=> 'smf_db_error_insert',
64 65
 			'db_custom_order'			=> 'smf_db_custom_order',
65 66
 		);
67
+	}
66 68
 
67
-	if (!empty($db_options['persist']))
68
-		$db_server = 'p:' . $db_server;
69
+	if (!empty($db_options['persist'])) {
70
+			$db_server = 'p:' . $db_server;
71
+	}
69 72
 
70 73
 	$connection = mysqli_init();
71 74
 
@@ -74,24 +77,27 @@  discard block
 block discarded – undo
74 77
 	$success = false;
75 78
 
76 79
 	if ($connection) {
77
-		if (!empty($db_options['port']))
78
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
79
-		else
80
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
80
+		if (!empty($db_options['port'])) {
81
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
82
+		} else {
83
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
84
+		}
81 85
 	}
82 86
 
83 87
 	// Something's wrong, show an error if its fatal (which we assume it is)
84 88
 	if ($success === false)
85 89
 	{
86
-		if (!empty($db_options['non_fatal']))
87
-			return null;
88
-		else
89
-			display_db_error();
90
+		if (!empty($db_options['non_fatal'])) {
91
+					return null;
92
+		} else {
93
+					display_db_error();
94
+		}
90 95
 	}
91 96
 
92 97
 	// Select the database, unless told not to
93
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
94
-		display_db_error();
98
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
99
+			display_db_error();
100
+	}
95 101
 
96 102
 	mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'');
97 103
 
@@ -164,34 +170,42 @@  discard block
 block discarded – undo
164 170
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 171
 
166 172
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
173
+	if (!is_object($connection)) {
174
+			display_db_error();
175
+	}
169 176
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
177
+	if ($matches[1] === 'db_prefix') {
178
+			return $db_prefix;
179
+	}
172 180
 
173
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
174
-		return $user_info[$matches[1]];
181
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
182
+			return $user_info[$matches[1]];
183
+	}
175 184
 
176
-	if ($matches[1] === 'empty')
177
-		return '\'\'';
185
+	if ($matches[1] === 'empty') {
186
+			return '\'\'';
187
+	}
178 188
 
179
-	if (!isset($matches[2]))
180
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
189
+	if (!isset($matches[2])) {
190
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
191
+	}
181 192
 
182
-	if ($matches[1] === 'literal')
183
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
193
+	if ($matches[1] === 'literal') {
194
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
195
+	}
184 196
 
185
-	if (!isset($values[$matches[2]]))
186
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
197
+	if (!isset($values[$matches[2]])) {
198
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
199
+	}
187 200
 
188 201
 	$replacement = $values[$matches[2]];
189 202
 
190 203
 	switch ($matches[1])
191 204
 	{
192 205
 		case 'int':
193
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
194
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
206
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
207
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
208
+			}
195 209
 			return (string) (int) $replacement;
196 210
 		break;
197 211
 
@@ -203,65 +217,73 @@  discard block
 block discarded – undo
203 217
 		case 'array_int':
204 218
 			if (is_array($replacement))
205 219
 			{
206
-				if (empty($replacement))
207
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				if (empty($replacement)) {
221
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+				}
208 223
 
209 224
 				foreach ($replacement as $key => $value)
210 225
 				{
211
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
212
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
227
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+					}
213 229
 
214 230
 					$replacement[$key] = (string) (int) $value;
215 231
 				}
216 232
 
217 233
 				return implode(', ', $replacement);
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218 236
 			}
219
-			else
220
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 237
 
222 238
 		break;
223 239
 
224 240
 		case 'array_string':
225 241
 			if (is_array($replacement))
226 242
 			{
227
-				if (empty($replacement))
228
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243
+				if (empty($replacement)) {
244
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+				}
229 246
 
230
-				foreach ($replacement as $key => $value)
231
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
247
+				foreach ($replacement as $key => $value) {
248
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
249
+				}
232 250
 
233 251
 				return implode(', ', $replacement);
252
+			} else {
253
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234 254
 			}
235
-			else
236
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 255
 		break;
238 256
 
239 257
 		case 'date':
240
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
241
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
242
-			else
243
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
258
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
259
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
260
+			} else {
261
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262
+			}
244 263
 		break;
245 264
 
246 265
 		case 'time':
247
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
248
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
249
-			else
250
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
267
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
268
+			} else {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
251 271
 		break;
252 272
 
253 273
 		case 'datetime':
254
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
255
-				return 'str_to_date('.
274
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
275
+							return 'str_to_date('.
256 276
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
257 277
 					',\'%Y-%m-%d %h:%i:%s\')';
258
-			else
259
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+			} else {
279
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
280
+			}
260 281
 		break;
261 282
 
262 283
 		case 'float':
263
-			if (!is_numeric($replacement))
264
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
284
+			if (!is_numeric($replacement)) {
285
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
286
+			}
265 287
 			return (string) (float) $replacement;
266 288
 		break;
267 289
 
@@ -275,32 +297,37 @@  discard block
 block discarded – undo
275 297
 		break;
276 298
 
277 299
 		case 'inet':
278
-			if ($replacement == 'null' || $replacement == '')
279
-				return 'null';
280
-			if (!isValidIP($replacement))
281
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			if ($replacement == 'null' || $replacement == '') {
301
+							return 'null';
302
+			}
303
+			if (!isValidIP($replacement)) {
304
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
305
+			}
282 306
 			//we don't use the native support of mysql > 5.6.2
283 307
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
284 308
 
285 309
 		case 'array_inet':
286 310
 			if (is_array($replacement))
287 311
 			{
288
-				if (empty($replacement))
289
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
312
+				if (empty($replacement)) {
313
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
314
+				}
290 315
 
291 316
 				foreach ($replacement as $key => $value)
292 317
 				{
293
-					if ($replacement == 'null' || $replacement == '')
294
-						$replacement[$key] = 'null';
295
-					if (!isValidIP($value))
296
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					if ($replacement == 'null' || $replacement == '') {
319
+											$replacement[$key] = 'null';
320
+					}
321
+					if (!isValidIP($value)) {
322
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
323
+					}
297 324
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
298 325
 				}
299 326
 
300 327
 				return implode(', ', $replacement);
328
+			} else {
329
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
301 330
 			}
302
-			else
303
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
304 331
 		break;
305 332
 
306 333
 		default:
@@ -376,22 +403,25 @@  discard block
 block discarded – undo
376 403
 		// Are we in SSI mode?  If so try that username and password first
377 404
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
378 405
 		{
379
-			if (empty($db_persist))
380
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
381
-			else
382
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
406
+			if (empty($db_persist)) {
407
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
408
+			} else {
409
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
410
+			}
383 411
 		}
384 412
 		// Fall back to the regular username and password if need be
385 413
 		if (!$db_connection)
386 414
 		{
387
-			if (empty($db_persist))
388
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
389
-			else
390
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
415
+			if (empty($db_persist)) {
416
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
417
+			} else {
418
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
419
+			}
391 420
 		}
392 421
 
393
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
394
-			$db_connection = false;
422
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
423
+					$db_connection = false;
424
+		}
395 425
 
396 426
 		$connection = $db_connection;
397 427
 	}
@@ -399,18 +429,20 @@  discard block
 block discarded – undo
399 429
 	// One more query....
400 430
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
401 431
 
402
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
403
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
432
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
433
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
434
+	}
404 435
 
405 436
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
406 437
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
407 438
 	{
408 439
 		// Add before LIMIT
409
-		if ($pos = strpos($db_string, 'LIMIT '))
410
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
411
-		else
412
-			// Append it.
440
+		if ($pos = strpos($db_string, 'LIMIT ')) {
441
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
442
+		} else {
443
+					// Append it.
413 444
 			$db_string .= "\n\t\t\tORDER BY null";
445
+		}
414 446
 	}
415 447
 
416 448
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -436,17 +468,18 @@  discard block
 block discarded – undo
436 468
 		while (true)
437 469
 		{
438 470
 			$pos = strpos($db_string_1, '\'', $pos + 1);
439
-			if ($pos === false)
440
-				break;
471
+			if ($pos === false) {
472
+							break;
473
+			}
441 474
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
442 475
 
443 476
 			while (true)
444 477
 			{
445 478
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
446 479
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
447
-				if ($pos1 === false)
448
-					break;
449
-				elseif ($pos2 === false || $pos2 > $pos1)
480
+				if ($pos1 === false) {
481
+									break;
482
+				} elseif ($pos2 === false || $pos2 > $pos1)
450 483
 				{
451 484
 					$pos = $pos1;
452 485
 					break;
@@ -462,16 +495,19 @@  discard block
 block discarded – undo
462 495
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
463 496
 
464 497
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
465
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
466
-			$fail = true;
498
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
499
+					$fail = true;
500
+		}
467 501
 		// Trying to change passwords, slow us down, or something?
468
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
469
-			$fail = true;
470
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
471
-			$fail = true;
502
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
503
+					$fail = true;
504
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
505
+					$fail = true;
506
+		}
472 507
 
473
-		if (!empty($fail) && function_exists('log_error'))
474
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
508
+		if (!empty($fail) && function_exists('log_error')) {
509
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
510
+		}
475 511
 	}
476 512
 
477 513
 	// Debugging.
@@ -481,8 +517,9 @@  discard block
 block discarded – undo
481 517
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
482 518
 
483 519
 		// Initialize $db_cache if not already initialized.
484
-		if (!isset($db_cache))
485
-			$db_cache = array();
520
+		if (!isset($db_cache)) {
521
+					$db_cache = array();
522
+		}
486 523
 
487 524
 		if (!empty($_SESSION['debug_redirect']))
488 525
 		{
@@ -498,17 +535,20 @@  discard block
 block discarded – undo
498 535
 		$db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start;
499 536
 	}
500 537
 
501
-	if (empty($db_unbuffered))
502
-		$ret = @mysqli_query($connection, $db_string);
503
-	else
504
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
538
+	if (empty($db_unbuffered)) {
539
+			$ret = @mysqli_query($connection, $db_string);
540
+	} else {
541
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
542
+	}
505 543
 
506
-	if ($ret === false && empty($db_values['db_error_skip']))
507
-		$ret = smf_db_error($db_string, $connection);
544
+	if ($ret === false && empty($db_values['db_error_skip'])) {
545
+			$ret = smf_db_error($db_string, $connection);
546
+	}
508 547
 
509 548
 	// Debugging.
510
-	if (isset($db_show_debug) && $db_show_debug === true)
511
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
549
+	if (isset($db_show_debug) && $db_show_debug === true) {
550
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
551
+	}
512 552
 
513 553
 	return $ret;
514 554
 }
@@ -555,12 +595,13 @@  discard block
 block discarded – undo
555 595
 	// Decide which connection to use
556 596
 	$connection = $connection === null ? $db_connection : $connection;
557 597
 
558
-	if ($type == 'begin')
559
-		return @mysqli_query($connection, 'BEGIN');
560
-	elseif ($type == 'rollback')
561
-		return @mysqli_query($connection, 'ROLLBACK');
562
-	elseif ($type == 'commit')
563
-		return @mysqli_query($connection, 'COMMIT');
598
+	if ($type == 'begin') {
599
+			return @mysqli_query($connection, 'BEGIN');
600
+	} elseif ($type == 'rollback') {
601
+			return @mysqli_query($connection, 'ROLLBACK');
602
+	} elseif ($type == 'commit') {
603
+			return @mysqli_query($connection, 'COMMIT');
604
+	}
564 605
 
565 606
 	return false;
566 607
 }
@@ -600,8 +641,9 @@  discard block
 block discarded – undo
600 641
 	//    2013: Lost connection to server during query.
601 642
 
602 643
 	// Log the error.
603
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
604
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
644
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
645
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
646
+	}
605 647
 
606 648
 	// Database error auto fixing ;).
607 649
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -610,8 +652,9 @@  discard block
 block discarded – undo
610 652
 		$old_cache = @$modSettings['cache_enable'];
611 653
 		$modSettings['cache_enable'] = '1';
612 654
 
613
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
614
-			$db_last_error = max(@$db_last_error, $temp);
655
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
656
+					$db_last_error = max(@$db_last_error, $temp);
657
+		}
615 658
 
616 659
 		if (@$db_last_error < time() - 3600 * 24 * 3)
617 660
 		{
@@ -627,8 +670,9 @@  discard block
 block discarded – undo
627 670
 					foreach ($tables as $table)
628 671
 					{
629 672
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
630
-						if (trim($table) != '')
631
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
673
+						if (trim($table) != '') {
674
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
675
+						}
632 676
 					}
633 677
 				}
634 678
 
@@ -637,8 +681,9 @@  discard block
 block discarded – undo
637 681
 			// Table crashed.  Let's try to fix it.
638 682
 			elseif ($query_errno == 1016)
639 683
 			{
640
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
641
-					$fix_tables = array('`' . $match[1] . '`');
684
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
685
+									$fix_tables = array('`' . $match[1] . '`');
686
+				}
642 687
 			}
643 688
 			// Indexes crashed.  Should be easy to fix!
644 689
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -657,13 +702,15 @@  discard block
 block discarded – undo
657 702
 
658 703
 			// Make a note of the REPAIR...
659 704
 			cache_put_data('db_last_error', time(), 600);
660
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
661
-				updateSettingsFile(array('db_last_error' => time()));
705
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
706
+							updateSettingsFile(array('db_last_error' => time()));
707
+			}
662 708
 
663 709
 			// Attempt to find and repair the broken table.
664
-			foreach ($fix_tables as $table)
665
-				$smcFunc['db_query']('', "
710
+			foreach ($fix_tables as $table) {
711
+							$smcFunc['db_query']('', "
666 712
 					REPAIR TABLE $table", false, false);
713
+			}
667 714
 
668 715
 			// And send off an email!
669 716
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -672,11 +719,12 @@  discard block
 block discarded – undo
672 719
 
673 720
 			// Try the query again...?
674 721
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
675
-			if ($ret !== false)
676
-				return $ret;
722
+			if ($ret !== false) {
723
+							return $ret;
724
+			}
725
+		} else {
726
+					$modSettings['cache_enable'] = $old_cache;
677 727
 		}
678
-		else
679
-			$modSettings['cache_enable'] = $old_cache;
680 728
 
681 729
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
682 730
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -686,22 +734,25 @@  discard block
 block discarded – undo
686 734
 				// Are we in SSI mode?  If so try that username and password first
687 735
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
688 736
 				{
689
-					if (empty($db_persist))
690
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
691
-					else
692
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
737
+					if (empty($db_persist)) {
738
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
739
+					} else {
740
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
741
+					}
693 742
 				}
694 743
 				// Fall back to the regular username and password if need be
695 744
 				if (!$db_connection)
696 745
 				{
697
-					if (empty($db_persist))
698
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
699
-					else
700
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
746
+					if (empty($db_persist)) {
747
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
748
+					} else {
749
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
750
+					}
701 751
 				}
702 752
 
703
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
704
-					$db_connection = false;
753
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
754
+									$db_connection = false;
755
+				}
705 756
 			}
706 757
 
707 758
 			if ($db_connection)
@@ -712,24 +763,27 @@  discard block
 block discarded – undo
712 763
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
713 764
 
714 765
 					$new_errno = mysqli_errno($db_connection);
715
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
716
-						break;
766
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
767
+											break;
768
+					}
717 769
 				}
718 770
 
719 771
 				// If it failed again, shucks to be you... we're not trying it over and over.
720
-				if ($ret !== false)
721
-					return $ret;
772
+				if ($ret !== false) {
773
+									return $ret;
774
+				}
722 775
 			}
723 776
 		}
724 777
 		// Are they out of space, perhaps?
725 778
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
726 779
 		{
727
-			if (!isset($txt))
728
-				$query_error .= ' - check database storage space.';
729
-			else
780
+			if (!isset($txt)) {
781
+							$query_error .= ' - check database storage space.';
782
+			} else
730 783
 			{
731
-				if (!isset($txt['mysql_error_space']))
732
-					loadLanguage('Errors');
784
+				if (!isset($txt['mysql_error_space'])) {
785
+									loadLanguage('Errors');
786
+				}
733 787
 
734 788
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
735 789
 			}
@@ -737,15 +791,17 @@  discard block
 block discarded – undo
737 791
 	}
738 792
 
739 793
 	// Nothing's defined yet... just die with it.
740
-	if (empty($context) || empty($txt))
741
-		die($query_error);
794
+	if (empty($context) || empty($txt)) {
795
+			die($query_error);
796
+	}
742 797
 
743 798
 	// Show an error message, if possible.
744 799
 	$context['error_title'] = $txt['database_error'];
745
-	if (allowedTo('admin_forum'))
746
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
747
-	else
748
-		$context['error_message'] = $txt['try_again'];
800
+	if (allowedTo('admin_forum')) {
801
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
802
+	} else {
803
+			$context['error_message'] = $txt['try_again'];
804
+	}
749 805
 
750 806
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
751 807
 	{
@@ -777,8 +833,9 @@  discard block
 block discarded – undo
777 833
 	$return_var = null;
778 834
 
779 835
 	// With nothing to insert, simply return.
780
-	if (empty($data))
781
-		return;
836
+	if (empty($data)) {
837
+			return;
838
+	}
782 839
 
783 840
 	// Replace the prefix holder with the actual prefix.
784 841
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -788,23 +845,26 @@  discard block
 block discarded – undo
788 845
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
789 846
 	{
790 847
 		$with_returning = true;
791
-		if ($returnmode == 2)
792
-			$return_var = array();
848
+		if ($returnmode == 2) {
849
+					$return_var = array();
850
+		}
793 851
 	}
794 852
 
795 853
 	// Inserting data as a single row can be done as a single array.
796
-	if (!is_array($data[array_rand($data)]))
797
-		$data = array($data);
854
+	if (!is_array($data[array_rand($data)])) {
855
+			$data = array($data);
856
+	}
798 857
 
799 858
 	// Create the mold for a single row insert.
800 859
 	$insertData = '(';
801 860
 	foreach ($columns as $columnName => $type)
802 861
 	{
803 862
 		// Are we restricting the length?
804
-		if (strpos($type, 'string-') !== false)
805
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
806
-		else
807
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
863
+		if (strpos($type, 'string-') !== false) {
864
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
865
+		} else {
866
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
867
+		}
808 868
 	}
809 869
 	$insertData = substr($insertData, 0, -2) . ')';
810 870
 
@@ -813,8 +873,9 @@  discard block
 block discarded – undo
813 873
 
814 874
 	// Here's where the variables are injected to the query.
815 875
 	$insertRows = array();
816
-	foreach ($data as $dataRow)
817
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
876
+	foreach ($data as $dataRow) {
877
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
878
+	}
818 879
 
819 880
 	// Determine the method of insertion.
820 881
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -833,8 +894,7 @@  discard block
 block discarded – undo
833 894
 			),
834 895
 			$connection
835 896
 		);
836
-	}
837
-	else //special way for ignore method with returning
897
+	} else //special way for ignore method with returning
838 898
 	{
839 899
 		$count = count($insertRows);
840 900
 		$ai = 0;
@@ -854,19 +914,21 @@  discard block
 block discarded – undo
854 914
 			);
855 915
 			$new_id = $smcFunc['db_insert_id']();
856 916
 
857
-			if ($last_id != $new_id) //the inserted value was new
917
+			if ($last_id != $new_id) {
918
+				//the inserted value was new
858 919
 			{
859 920
 				$ai = $new_id;
860 921
 			}
861
-			else	// the inserted value already exists we need to find the pk
922
+			} else	// the inserted value already exists we need to find the pk
862 923
 			{
863 924
 				$where_string = '';
864 925
 				$count2 = count($indexed_columns);
865 926
 				for ($x = 0; $x < $count2; $x++)
866 927
 				{
867 928
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
868
-					if (($x + 1) < $count2)
869
-						$where_string += ' AND ';
929
+					if (($x + 1) < $count2) {
930
+											$where_string += ' AND ';
931
+					}
870 932
 				}
871 933
 
872 934
 				$request = $smcFunc['db_query']('','
@@ -882,25 +944,27 @@  discard block
 block discarded – undo
882 944
 				}
883 945
 			}
884 946
 
885
-			if ($returnmode == 1)
886
-				$return_var = $ai;
887
-			else if ($returnmode == 2)
888
-				$return_var[] = $ai;
947
+			if ($returnmode == 1) {
948
+							$return_var = $ai;
949
+			} else if ($returnmode == 2) {
950
+							$return_var[] = $ai;
951
+			}
889 952
 		}
890 953
 	}
891 954
 
892 955
 
893 956
 	if ($with_returning)
894 957
 	{
895
-		if ($returnmode == 1 && empty($return_var))
896
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
897
-		else if ($returnmode == 2 && empty($return_var))
958
+		if ($returnmode == 1 && empty($return_var)) {
959
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
960
+		} else if ($returnmode == 2 && empty($return_var))
898 961
 		{
899 962
 			$return_var = array();
900 963
 			$count = count($insertRows);
901 964
 			$start = smf_db_insert_id($table, $keys[0]);
902
-			for ($i = 0; $i < $count; $i++ )
903
-				$return_var[] = $start + $i;
965
+			for ($i = 0; $i < $count; $i++ ) {
966
+							$return_var[] = $start + $i;
967
+			}
904 968
 		}
905 969
 		return $return_var;
906 970
 	}
@@ -918,8 +982,9 @@  discard block
 block discarded – undo
918 982
  */
919 983
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
920 984
 {
921
-	if (empty($log_message))
922
-		$log_message = $error_message;
985
+	if (empty($log_message)) {
986
+			$log_message = $error_message;
987
+	}
923 988
 
924 989
 	foreach (debug_backtrace() as $step)
925 990
 	{
@@ -938,12 +1003,14 @@  discard block
 block discarded – undo
938 1003
 	}
939 1004
 
940 1005
 	// A special case - we want the file and line numbers for debugging.
941
-	if ($error_type == 'return')
942
-		return array($file, $line);
1006
+	if ($error_type == 'return') {
1007
+			return array($file, $line);
1008
+	}
943 1009
 
944 1010
 	// Is always a critical error.
945
-	if (function_exists('log_error'))
946
-		log_error($log_message, 'critical', $file, $line);
1011
+	if (function_exists('log_error')) {
1012
+			log_error($log_message, 'critical', $file, $line);
1013
+	}
947 1014
 
948 1015
 	if (function_exists('fatal_error'))
949 1016
 	{
@@ -951,12 +1018,12 @@  discard block
 block discarded – undo
951 1018
 
952 1019
 		// Cannot continue...
953 1020
 		exit;
1021
+	} elseif ($error_type) {
1022
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
1023
+	} else {
1024
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
1025
+	}
954 1026
 	}
955
-	elseif ($error_type)
956
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
957
-	else
958
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
959
-}
960 1027
 
961 1028
 /**
962 1029
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -973,10 +1040,11 @@  discard block
 block discarded – undo
973 1040
 		'\\' => '\\\\',
974 1041
 	);
975 1042
 
976
-	if ($translate_human_wildcards)
977
-		$replacements += array(
1043
+	if ($translate_human_wildcards) {
1044
+			$replacements += array(
978 1045
 			'*' => '%',
979 1046
 		);
1047
+	}
980 1048
 
981 1049
 	return strtr($string, $replacements);
982 1050
 }
@@ -990,8 +1058,9 @@  discard block
 block discarded – undo
990 1058
  */
991 1059
 function smf_is_resource($result)
992 1060
 {
993
-	if ($result instanceof mysqli_result)
994
-		return true;
1061
+	if ($result instanceof mysqli_result) {
1062
+			return true;
1063
+	}
995 1064
 
996 1065
 	return false;
997 1066
 }
@@ -1019,16 +1088,18 @@  discard block
 block discarded – undo
1019 1088
 	global  $db_prefix, $db_connection;
1020 1089
 	static $mysql_error_data_prep;
1021 1090
 
1022
-	if (empty($mysql_error_data_prep))
1023
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1091
+	if (empty($mysql_error_data_prep)) {
1092
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
1024 1093
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
1025 1094
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?)'
1026 1095
 			);
1096
+	}
1027 1097
 
1028
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
1029
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
1030
-	else
1031
-		$error_array[2] = null;
1098
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1099
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1100
+	} else {
1101
+			$error_array[2] = null;
1102
+	}
1032 1103
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi',
1033 1104
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
1034 1105
 		$error_array[7], $error_array[8]);
@@ -1050,8 +1121,9 @@  discard block
 block discarded – undo
1050 1121
 	$count = count($array_values);
1051 1122
 	$then = ($desc ? ' THEN -' : ' THEN ');
1052 1123
 
1053
-	for ($i = 0; $i < $count; $i++)
1054
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1124
+	for ($i = 0; $i < $count; $i++) {
1125
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1126
+	}
1055 1127
 
1056 1128
 	$return .= 'END';
1057 1129
 	return $return;
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 1 patch
Braces   +24 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 	<strong>
29 29
 		', $context['error_title'], '
30 30
 	</strong><br>
31 31
 	<div ', $context['error_code'], 'class="padding">
32 32
 		', $context['error_message'], '
33 33
 	</div>';
34
-	else
34
+	} else
35 35
 	{
36 36
 		echo '
37 37
 	<div id="fatal_error">
@@ -85,21 +85,23 @@  discard block
 block discarded – undo
85 85
 
86 86
 	$error_types = array();
87 87
 
88
-	foreach ($context['error_types'] as $type => $details)
89
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
88
+	foreach ($context['error_types'] as $type => $details) {
89
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
90
+	}
90 91
 
91 92
 	echo '
92 93
 						', implode(' | ', $error_types), '
93 94
 					</td>
94 95
 				</tr>';
95 96
 
96
-	if ($context['has_filter'])
97
-		echo '
97
+	if ($context['has_filter']) {
98
+			echo '
98 99
 				<tr>
99 100
 					<td colspan="3" class="windowbg">
100 101
 						<strong>', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], ' [<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
101 102
 					</td>
102 103
 				</tr>';
104
+	}
103 105
 
104 106
 	echo '
105 107
 				<tr>
@@ -110,11 +112,12 @@  discard block
 block discarded – undo
110 112
 				</tr>';
111 113
 
112 114
 	// No errors, then show a message
113
-	if (count($context['errors']) == 0)
114
-		echo '
115
+	if (count($context['errors']) == 0) {
116
+			echo '
115 117
 				<tr class="windowbg">
116 118
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
117 119
 				</tr>';
120
+	}
118 121
 
119 122
 	// We have some errors, must be some mods installed :P
120 123
 	foreach ($context['errors'] as $error)
@@ -128,16 +131,18 @@  discard block
 block discarded – undo
128 131
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
129 132
 							', $error['time'], '<br>';
130 133
 
131
-		if (!empty($error['member']['ip']))
132
-			echo '
134
+		if (!empty($error['member']['ip'])) {
135
+					echo '
133 136
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a>
134 137
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>';
138
+		}
135 139
 		
136
-		if ($error['member']['session'] != '')
137
-			echo '
140
+		if ($error['member']['session'] != '') {
141
+					echo '
138 142
 							<br>
139 143
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 						</div>
@@ -152,12 +157,13 @@  discard block
 block discarded – undo
152 157
 							<a href="', $error['url']['html'], '">', $error['url']['html'], '</a>
153 158
 ';
154 159
 
155
-		if (!empty($error['file']))
156
-			echo '
160
+		if (!empty($error['file'])) {
161
+					echo '
157 162
 							<div>
158 163
 								<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '">'
159 164
 				. '					<span class="generic_icons filter"></span></a> ', $error['file']['link'], ' (', $txt['line'], ' ', $error['file']['line'], ')
160 165
 							</div>';
166
+		}
161 167
 
162 168
 		echo '
163 169
 						</div>
@@ -186,9 +192,10 @@  discard block
 block discarded – undo
186 192
 				</div>
187 193
 			</div>';
188 194
 
189
-	if ($context['sort_direction'] == 'down')
190
-		echo '
195
+	if ($context['sort_direction'] == 'down') {
196
+			echo '
191 197
 			<input type="hidden" name="desc" value="1">';
198
+	}
192 199
 
193 200
 	echo '
194 201
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
Please login to merge, or discard this patch.
Themes/default/Profile.template.php 1 patch
Braces   +508 added lines, -392 removed lines patch added patch discarded remove patch
@@ -18,23 +18,25 @@  discard block
 block discarded – undo
18 18
 	global $context;
19 19
 
20 20
 	// Prevent Chrome from auto completing fields when viewing/editing other members profiles
21
-	if (isBrowser('is_chrome') && !$context['user']['is_owner'])
22
-		echo '
21
+	if (isBrowser('is_chrome') && !$context['user']['is_owner']) {
22
+			echo '
23 23
 			<script>
24 24
 				disableAutoComplete();
25 25
 			</script>';
26
+	}
26 27
 
27 28
 	// If an error occurred while trying to save previously, give the user a clue!
28 29
 	echo '
29 30
 			', template_error_message();
30 31
 
31 32
 	// If the profile was update successfully, let the user know this.
32
-	if (!empty($context['profile_updated']))
33
-		echo '
33
+	if (!empty($context['profile_updated'])) {
34
+			echo '
34 35
 			<div class="infobox">
35 36
 				', $context['profile_updated'], '
36 37
 			</div>';
37
-}
38
+	}
39
+	}
38 40
 
39 41
 /**
40 42
  * Template for any HTML needed below the profile (closing off divs/tables, etc.)
@@ -99,19 +101,19 @@  discard block
 block discarded – undo
99 101
 		</div>
100 102
 		<div class="alerts_unread">';
101 103
 
102
-	if (empty($context['unread_alerts']))
103
-		template_alerts_all_read();
104
-
105
-	else
104
+	if (empty($context['unread_alerts'])) {
105
+			template_alerts_all_read();
106
+	} else
106 107
 	{
107
-		foreach ($context['unread_alerts'] as $id_alert => $details)
108
-			echo '
108
+		foreach ($context['unread_alerts'] as $id_alert => $details) {
109
+					echo '
109 110
 			<div class="unread">
110 111
 				', !empty($details['sender']) ? $details['sender']['avatar']['image'] : '', '
111 112
 				<div class="details">
112 113
 					', !empty($details['icon']) ? $details['icon'] : '', '<span>', $details['text'], '</span> - ', $details['time'], '
113 114
 				</div>
114 115
 			</div>';
116
+		}
115 117
 	}
116 118
 
117 119
 	echo '
@@ -161,10 +163,11 @@  discard block
 block discarded – undo
161 163
 			<div class="custom_fields_above_name">
162 164
 				<ul>';
163 165
 
164
-		foreach ($context['print_custom_fields']['above_member'] as $field)
165
-			if (!empty($field['output_html']))
166
+		foreach ($context['print_custom_fields']['above_member'] as $field) {
167
+					if (!empty($field['output_html']))
166 168
 				echo '
167 169
 					<li>', $field['output_html'], '</li>';
170
+		}
168 171
 
169 172
 		echo '
170 173
 				</ul>
@@ -176,20 +179,22 @@  discard block
 block discarded – undo
176 179
 			<div class="username clear">
177 180
 				<h4>';
178 181
 
179
-	if (!empty($context['print_custom_fields']['before_member']))
180
-		foreach ($context['print_custom_fields']['before_member'] as $field)
182
+	if (!empty($context['print_custom_fields']['before_member'])) {
183
+			foreach ($context['print_custom_fields']['before_member'] as $field)
181 184
 			if (!empty($field['output_html']))
182 185
 				echo '
183 186
 					<span>', $field['output_html'], '</span>';
187
+	}
184 188
 
185 189
 	echo '
186 190
 					', $context['member']['name'];
187 191
 
188
-	if (!empty($context['print_custom_fields']['after_member']))
189
-		foreach ($context['print_custom_fields']['after_member'] as $field)
192
+	if (!empty($context['print_custom_fields']['after_member'])) {
193
+			foreach ($context['print_custom_fields']['after_member'] as $field)
190 194
 			if (!empty($field['output_html']))
191 195
 				echo '
192 196
 					<span>', $field['output_html'], '</span>';
197
+	}
193 198
 
194 199
 
195 200
 	echo '
@@ -205,10 +210,11 @@  discard block
 block discarded – undo
205 210
 			<div class="custom_fields_below_avatar">
206 211
 				<ul>';
207 212
 
208
-		foreach ($context['print_custom_fields']['below_avatar'] as $field)
209
-			if (!empty($field['output_html']))
213
+		foreach ($context['print_custom_fields']['below_avatar'] as $field) {
214
+					if (!empty($field['output_html']))
210 215
 				echo '
211 216
 					<li>', $field['output_html'], '</li>';
217
+		}
212 218
 
213 219
 		echo '
214 220
 				</ul>
@@ -220,22 +226,25 @@  discard block
 block discarded – undo
220 226
 			<ul class="clear">';
221 227
 
222 228
 	// Email is only visible if it's your profile or you have the moderate_forum permission
223
-	if ($context['member']['show_email'])
224
-		echo '
229
+	if ($context['member']['show_email']) {
230
+			echo '
225 231
 				<li><a href="mailto:', $context['member']['email'], '" title="', $context['member']['email'], '" rel="nofollow"><span class="generic_icons mail" title="' . $txt['email'] . '"></span></a></li>';
232
+	}
226 233
 
227 234
 	// Don't show an icon if they haven't specified a website.
228
-	if ($context['member']['website']['url'] !== '' && !isset($context['disabled_fields']['website']))
229
-		echo '
235
+	if ($context['member']['website']['url'] !== '' && !isset($context['disabled_fields']['website'])) {
236
+			echo '
230 237
 				<li><a href="', $context['member']['website']['url'], '" title="' . $context['member']['website']['title'] . '" target="_blank" rel="noopener">', ($settings['use_image_buttons'] ? '<span class="generic_icons www" title="' . $context['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
238
+	}
231 239
 
232 240
 	// Are there any custom profile fields as icons?
233 241
 	if (!empty($context['print_custom_fields']['icons']))
234 242
 	{
235
-		foreach ($context['print_custom_fields']['icons'] as $field)
236
-			if (!empty($field['output_html']))
243
+		foreach ($context['print_custom_fields']['icons'] as $field) {
244
+					if (!empty($field['output_html']))
237 245
 				echo '
238 246
 				<li class="custom_field">', $field['output_html'], '</li>';
247
+		}
239 248
 	}
240 249
 
241 250
 	echo '
@@ -244,24 +253,27 @@  discard block
 block discarded – undo
244 253
 				', $context['can_send_pm'] ? '<a href="' . $context['member']['online']['href'] . '" title="' . $context['member']['online']['text'] . '" rel="nofollow">' : '', $settings['use_image_buttons'] ? '<span class="' . ($context['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $context['member']['online']['text'] . '"></span>' : $context['member']['online']['label'], $context['can_send_pm'] ? '</a>' : '', $settings['use_image_buttons'] ? '<span class="smalltext"> ' . $context['member']['online']['label'] . '</span>' : '';
245 254
 
246 255
 	// Can they add this member as a buddy?
247
-	if (!empty($context['can_have_buddy']) && !$context['user']['is_owner'])
248
-		echo '
256
+	if (!empty($context['can_have_buddy']) && !$context['user']['is_owner']) {
257
+			echo '
249 258
 				<br>
250 259
 				<a href="', $scripturl, '?action=buddy;u=', $context['id_member'], ';', $context['session_var'], '=', $context['session_id'], '">[', $txt['buddy_' . ($context['member']['is_buddy'] ? 'remove' : 'add')], ']</a>';
260
+	}
251 261
 
252 262
 	echo '
253 263
 			</span>';
254 264
 
255
-	if (!$context['user']['is_owner'] && $context['can_send_pm'])
256
-		echo '
265
+	if (!$context['user']['is_owner'] && $context['can_send_pm']) {
266
+			echo '
257 267
 			<a href="', $scripturl, '?action=pm;sa=send;u=', $context['id_member'], '" class="infolinks">', $txt['profile_sendpm_short'], '</a>';
268
+	}
258 269
 
259 270
 	echo '
260 271
 			<a href="', $scripturl, '?action=profile;area=showposts;u=', $context['id_member'], '" class="infolinks">', $txt['showPosts'], '</a>';
261 272
 
262
-	if ($context['user']['is_owner'] && !empty($modSettings['drafts_post_enabled']))
263
-		echo '
273
+	if ($context['user']['is_owner'] && !empty($modSettings['drafts_post_enabled'])) {
274
+			echo '
264 275
 			<a href="', $scripturl, '?action=profile;area=showdrafts;u=', $context['id_member'], '" class="infolinks">', $txt['drafts_show'], '</a>';
276
+	}
265 277
 
266 278
 	echo '
267 279
 			<a href="', $scripturl, '?action=profile;area=statistics;u=', $context['id_member'], '" class="infolinks">', $txt['statPanel'], '</a>';
@@ -273,10 +285,11 @@  discard block
 block discarded – undo
273 285
 			<div class="custom_fields_bottom">
274 286
 				<ul class="nolist">';
275 287
 
276
-		foreach ($context['print_custom_fields']['bottom_poster'] as $field)
277
-			if (!empty($field['output_html']))
288
+		foreach ($context['print_custom_fields']['bottom_poster'] as $field) {
289
+					if (!empty($field['output_html']))
278 290
 				echo '
279 291
 					<li>', $field['output_html'], '</li>';
292
+		}
280 293
 
281 294
 		echo '
282 295
 				</ul>
@@ -289,30 +302,35 @@  discard block
 block discarded – undo
289 302
 		<div id="detailedinfo">
290 303
 			<dl class="settings">';
291 304
 
292
-	if ($context['user']['is_owner'] || $context['user']['is_admin'])
293
-		echo '
305
+	if ($context['user']['is_owner'] || $context['user']['is_admin']) {
306
+			echo '
294 307
 				<dt>', $txt['username'], ': </dt>
295 308
 				<dd>', $context['member']['username'], '</dd>';
309
+	}
296 310
 
297
-	if (!isset($context['disabled_fields']['posts']))
298
-		echo '
311
+	if (!isset($context['disabled_fields']['posts'])) {
312
+			echo '
299 313
 				<dt>', $txt['profile_posts'], ': </dt>
300 314
 				<dd>', $context['member']['posts'], ' (', $context['member']['posts_per_day'], ' ', $txt['posts_per_day'], ')</dd>';
315
+	}
301 316
 
302
-	if ($context['member']['show_email'])
303
-		echo '
317
+	if ($context['member']['show_email']) {
318
+			echo '
304 319
 				<dt>', $txt['email'], ': </dt>
305 320
 				<dd><a href="mailto:', $context['member']['email'], '">', $context['member']['email'], '</a></dd>';
321
+	}
306 322
 
307
-	if (!empty($modSettings['titlesEnable']) && !empty($context['member']['title']))
308
-		echo '
323
+	if (!empty($modSettings['titlesEnable']) && !empty($context['member']['title'])) {
324
+			echo '
309 325
 				<dt>', $txt['custom_title'], ': </dt>
310 326
 				<dd>', $context['member']['title'], '</dd>';
327
+	}
311 328
 
312
-	if (!empty($context['member']['blurb']))
313
-		echo '
329
+	if (!empty($context['member']['blurb'])) {
330
+			echo '
314 331
 				<dt>', $txt['personal_text'], ': </dt>
315 332
 				<dd>', $context['member']['blurb'], '</dd>';
333
+	}
316 334
 
317 335
 	echo '
318 336
 				<dt>', $txt['age'], ':</dt>
@@ -326,19 +344,21 @@  discard block
 block discarded – undo
326 344
 	{
327 345
 		$fields = array();
328 346
 
329
-		foreach ($context['print_custom_fields']['standard'] as $field)
330
-			if (!empty($field['output_html']))
347
+		foreach ($context['print_custom_fields']['standard'] as $field) {
348
+					if (!empty($field['output_html']))
331 349
 				$fields[] = $field;
350
+		}
332 351
 
333 352
 		if (count($fields) > 0)
334 353
 		{
335 354
 			echo '
336 355
 			<dl class="settings">';
337 356
 
338
-			foreach ($fields as $field)
339
-				echo '
357
+			foreach ($fields as $field) {
358
+							echo '
340 359
 				<dt>', $field['name'], ':</dt>
341 360
 				<dd>', $field['output_html'], '</dd>';
361
+			}
342 362
 
343 363
 			echo '
344 364
 			</dl>';
@@ -358,9 +378,10 @@  discard block
 block discarded – undo
358 378
 					<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=', ($context['can_issue_warning'] && !$context['user']['is_owner'] ? 'issuewarning' : 'viewwarning'), '">', $context['member']['warning'], '%</a>';
359 379
 
360 380
 		// Can we provide information on what this means?
361
-		if (!empty($context['warning_status']))
362
-			echo '
381
+		if (!empty($context['warning_status'])) {
382
+					echo '
363 383
 					<span class="smalltext">(', $context['warning_status'], ')</span>';
384
+		}
364 385
 
365 386
 		echo '
366 387
 				</dd>';
@@ -371,11 +392,12 @@  discard block
 block discarded – undo
371 392
 	{
372 393
 
373 394
 		// If the person looking at the summary has permission, and the account isn't activated, give the viewer the ability to do it themselves.
374
-		if (!empty($context['activate_message']))
375
-			echo '
395
+		if (!empty($context['activate_message'])) {
396
+					echo '
376 397
 				<dt class="clear">
377 398
 					<span class="alert">', $context['activate_message'], '</span> (<a href="', $context['activate_link'], '"', ($context['activate_type'] == 4 ? ' class="you_sure" data-confirm="' . $txt['profileConfirm'] . '"' : ''), '>', $context['activate_link_text'], '</a>)
378 399
 				</dt>';
400
+		}
379 401
 
380 402
 		// If the current member is banned, show a message and possibly a link to the ban.
381 403
 		if (!empty($context['member']['bans']))
@@ -387,10 +409,11 @@  discard block
 block discarded – undo
387 409
 				<dt class="clear" id="ban_info" style="display: none;">
388 410
 					<strong>', $txt['user_banned_by_following'], ':</strong>';
389 411
 
390
-			foreach ($context['member']['bans'] as $ban)
391
-				echo '
412
+			foreach ($context['member']['bans'] as $ban) {
413
+							echo '
392 414
 					<br>
393 415
 					<span class="smalltext">', $ban['explanation'], '</span>';
416
+			}
394 417
 
395 418
 			echo '
396 419
 				</dt>';
@@ -404,30 +427,34 @@  discard block
 block discarded – undo
404 427
 	// If the person looking is allowed, they can check the members IP address and hostname.
405 428
 	if ($context['can_see_ip'])
406 429
 	{
407
-		if (!empty($context['member']['ip']))
408
-		echo '
430
+		if (!empty($context['member']['ip'])) {
431
+				echo '
409 432
 				<dt>', $txt['ip'], ': </dt>
410 433
 				<dd><a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['member']['ip'], ';u=', $context['member']['id'], '">', $context['member']['ip'], '</a></dd>';
434
+		}
411 435
 
412
-		if (empty($modSettings['disableHostnameLookup']) && !empty($context['member']['ip']))
413
-			echo '
436
+		if (empty($modSettings['disableHostnameLookup']) && !empty($context['member']['ip'])) {
437
+					echo '
414 438
 				<dt>', $txt['hostname'], ': </dt>
415 439
 				<dd>', $context['member']['hostname'], '</dd>';
440
+		}
416 441
 	}
417 442
 
418 443
 	echo '
419 444
 				<dt>', $txt['local_time'], ':</dt>
420 445
 				<dd>', $context['member']['local_time'], '</dd>';
421 446
 
422
-	if (!empty($modSettings['userLanguage']) && !empty($context['member']['language']))
423
-		echo '
447
+	if (!empty($modSettings['userLanguage']) && !empty($context['member']['language'])) {
448
+			echo '
424 449
 				<dt>', $txt['language'], ':</dt>
425 450
 				<dd>', $context['member']['language'], '</dd>';
451
+	}
426 452
 
427
-	if ($context['member']['show_last_login'])
428
-		echo '
453
+	if ($context['member']['show_last_login']) {
454
+			echo '
429 455
 				<dt>', $txt['lastLoggedIn'], ': </dt>
430 456
 				<dd>', $context['member']['last_login'], (!empty($context['member']['is_hidden']) ? ' (' . $txt['hidden'] . ')' : ''), '</dd>';
457
+	}
431 458
 
432 459
 	echo '
433 460
 			</dl>';
@@ -439,10 +466,11 @@  discard block
 block discarded – undo
439 466
 			<div class="custom_fields_above_signature">
440 467
 				<ul class="nolist">';
441 468
 
442
-		foreach ($context['print_custom_fields']['above_signature'] as $field)
443
-			if (!empty($field['output_html']))
469
+		foreach ($context['print_custom_fields']['above_signature'] as $field) {
470
+					if (!empty($field['output_html']))
444 471
 				echo '
445 472
 					<li>', $field['output_html'], '</li>';
473
+		}
446 474
 
447 475
 		echo '
448 476
 				</ul>
@@ -450,12 +478,13 @@  discard block
 block discarded – undo
450 478
 	}
451 479
 
452 480
 	// Show the users signature.
453
-	if ($context['signature_enabled'] && !empty($context['member']['signature']))
454
-		echo '
481
+	if ($context['signature_enabled'] && !empty($context['member']['signature'])) {
482
+			echo '
455 483
 			<div class="signature">
456 484
 				<h5>', $txt['signature'], ':</h5>
457 485
 				', $context['member']['signature'], '
458 486
 			</div>';
487
+	}
459 488
 
460 489
 	// Are there any custom profile fields for below the signature?
461 490
 	if (!empty($context['print_custom_fields']['below_signature']))
@@ -464,10 +493,11 @@  discard block
 block discarded – undo
464 493
 			<div class="custom_fields_below_signature">
465 494
 				<ul class="nolist">';
466 495
 
467
-		foreach ($context['print_custom_fields']['below_signature'] as $field)
468
-			if (!empty($field['output_html']))
496
+		foreach ($context['print_custom_fields']['below_signature'] as $field) {
497
+					if (!empty($field['output_html']))
469 498
 				echo '
470 499
 					<li>', $field['output_html'], '</li>';
500
+		}
471 501
 
472 502
 		echo '
473 503
 				</ul>
@@ -513,62 +543,70 @@  discard block
 block discarded – undo
513 543
 			</div>
514 544
 			<div class="list_posts">';
515 545
 
516
-			if (!$post['approved'])
517
-				echo '
546
+			if (!$post['approved']) {
547
+							echo '
518 548
 				<div class="approve_post">
519 549
 					<em>', $txt['post_awaiting_approval'], '</em>
520 550
 				</div>';
551
+			}
521 552
 
522 553
 			echo '
523 554
 				', $post['body'], '
524 555
 			</div>';
525 556
 
526
-			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
527
-				echo '
557
+			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
558
+							echo '
528 559
 			<div class="floatright">
529 560
 				<ul class="quickbuttons">';
561
+			}
530 562
 
531 563
 			// If they *can* reply?
532
-			if ($post['can_reply'])
533
-				echo '
564
+			if ($post['can_reply']) {
565
+							echo '
534 566
 					<li><a href="', $scripturl, '?action=post;topic=', $post['topic'], '.', $post['start'], '"><span class="generic_icons reply_button"></span>', $txt['reply'], '</a></li>';
567
+			}
535 568
 
536 569
 			// If they *can* quote?
537
-			if ($post['can_quote'])
538
-				echo '
570
+			if ($post['can_quote']) {
571
+							echo '
539 572
 					<li><a href="', $scripturl . '?action=post;topic=', $post['topic'], '.', $post['start'], ';quote=', $post['id'], '"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>';
573
+			}
540 574
 
541 575
 			// How about... even... remove it entirely?!
542
-			if ($post['can_delete'])
543
-				echo '
576
+			if ($post['can_delete']) {
577
+							echo '
544 578
 					<li><a href="', $scripturl, '?action=deletemsg;msg=', $post['id'], ';topic=', $post['topic'], ';profile;u=', $context['member']['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
579
+			}
545 580
 
546
-			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
547
-				echo '
581
+			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
582
+							echo '
548 583
 				</ul>
549 584
 			</div><!-- .floatright -->';
585
+			}
550 586
 
551 587
 			echo '
552 588
 		</div><!-- $post[css_class] -->';
553 589
 		}
590
+	} else {
591
+			template_show_list('attachments');
554 592
 	}
555
-	else
556
-		template_show_list('attachments');
557 593
 
558 594
 	// No posts? Just end with a informative message.
559
-	if ((isset($context['attachments']) && empty($context['attachments'])) || (!isset($context['attachments']) && empty($context['posts'])))
560
-		echo '
595
+	if ((isset($context['attachments']) && empty($context['attachments'])) || (!isset($context['attachments']) && empty($context['posts']))) {
596
+			echo '
561 597
 		<div class="windowbg2">
562 598
 			', isset($context['attachments']) ? $txt['show_attachments_none'] : ($context['is_topics'] ? $txt['show_topics_none'] : $txt['show_posts_none']), '
563 599
 		</div>';
600
+	}
564 601
 
565 602
 	// Show more page numbers.
566
-	if (!empty($context['page_index']))
567
-		echo '
603
+	if (!empty($context['page_index'])) {
604
+			echo '
568 605
 		<div class="pagesection">
569 606
 			<div class="pagelinks">', $context['page_index'], '</div>
570 607
 		</div>';
571
-}
608
+	}
609
+	}
572 610
 
573 611
 /**
574 612
  * Template for showing alerts within the alerts popup
@@ -578,11 +616,12 @@  discard block
 block discarded – undo
578 616
 	global $context, $txt, $scripturl;
579 617
 
580 618
 	// Do we have an update message?
581
-	if (!empty($context['update_message']))
582
-		echo '
619
+	if (!empty($context['update_message'])) {
620
+			echo '
583 621
 		<div class="infobox">
584 622
 			', $context['update_message'], '.
585 623
 		</div>';
624
+	}
586 625
 
587 626
 	echo '
588 627
 		<div class="cat_bar">
@@ -591,13 +630,12 @@  discard block
 block discarded – undo
591 630
 			</h3>
592 631
 		</div>';
593 632
 
594
-	if (empty($context['alerts']))
595
-		echo '
633
+	if (empty($context['alerts'])) {
634
+			echo '
596 635
 		<div class="information">
597 636
 			', $txt['alerts_none'], '
598 637
 		</div>';
599
-
600
-	else
638
+	} else
601 639
 	{
602 640
 		// Start the form.
603 641
 		echo '
@@ -659,12 +697,12 @@  discard block
 block discarded – undo
659 697
 		</div>' : '';
660 698
 
661 699
 	// No drafts? Just show an informative message.
662
-	if (empty($context['drafts']))
663
-		echo '
700
+	if (empty($context['drafts'])) {
701
+			echo '
664 702
 		<div class="windowbg2 centertext">
665 703
 			', $txt['draft_none'], '
666 704
 		</div>';
667
-	else
705
+	} else
668 706
 	{
669 707
 		// For every draft to be displayed, give it its own div, and show the important details of the draft.
670 708
 		foreach ($context['drafts'] as $draft)
@@ -676,13 +714,15 @@  discard block
 block discarded – undo
676 714
 				<h5>
677 715
 					<strong><a href="', $scripturl, '?board=', $draft['board']['id'], '.0">', $draft['board']['name'], '</a> / ', $draft['topic']['link'], '</strong> &nbsp; &nbsp;';
678 716
 
679
-			if (!empty($draft['sticky']))
680
-				echo '
717
+			if (!empty($draft['sticky'])) {
718
+							echo '
681 719
 					<span class="generic_icons sticky" title="', $txt['sticky_topic'], '"></span>';
720
+			}
682 721
 
683
-			if (!empty($draft['locked']))
684
-				echo '
722
+			if (!empty($draft['locked'])) {
723
+							echo '
685 724
 					<span class="generic_icons lock" title="', $txt['locked_topic'], '"></span>';
725
+			}
686 726
 
687 727
 			echo '
688 728
 				</h5>
@@ -715,13 +755,13 @@  discard block
 block discarded – undo
715 755
 {
716 756
 	global $context, $scripturl, $txt;
717 757
 
718
-	if (!empty($context['saved_successful']))
719
-		echo '
758
+	if (!empty($context['saved_successful'])) {
759
+			echo '
720 760
 	<div class="infobox">', $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $context['member']['name']), '</div>';
721
-
722
-	elseif (!empty($context['saved_failed']))
723
-		echo '
761
+	} elseif (!empty($context['saved_failed'])) {
762
+			echo '
724 763
 	<div class="errorbox">', $context['saved_failed'], '</div>';
764
+	}
725 765
 
726 766
 	echo '
727 767
 	<div id="edit_buddies">
@@ -736,14 +776,16 @@  discard block
 block discarded – undo
736 776
 					<th scope="col" class="quarter_table">', $txt['name'], '</th>
737 777
 					<th scope="col">', $txt['status'], '</th>';
738 778
 
739
-	if (allowedTo('moderate_forum'))
740
-		echo '
779
+	if (allowedTo('moderate_forum')) {
780
+			echo '
741 781
 					<th scope="col">', $txt['email'], '</th>';
782
+	}
742 783
 
743
-	if (!empty($context['custom_pf']))
744
-		foreach ($context['custom_pf'] as $column)
784
+	if (!empty($context['custom_pf'])) {
785
+			foreach ($context['custom_pf'] as $column)
745 786
 				echo '
746 787
 					<th scope="col">', $column['label'], '</th>';
788
+	}
747 789
 
748 790
 	echo '
749 791
 					<th scope="col">', $txt['remove'], '</th>
@@ -752,13 +794,14 @@  discard block
 block discarded – undo
752 794
 			<tbody>';
753 795
 
754 796
 	// If they don't have any buddies don't list them!
755
-	if (empty($context['buddies']))
756
-		echo '
797
+	if (empty($context['buddies'])) {
798
+			echo '
757 799
 				<tr class="windowbg">
758 800
 					<td colspan="', allowedTo('moderate_forum') ? '10' : '9', '">
759 801
 						<strong>', $txt['no_buddies'], '</strong>
760 802
 					</td>
761 803
 				</tr>';
804
+	}
762 805
 
763 806
 		// Now loop through each buddy showing info on each.
764 807
 	else
@@ -772,17 +815,19 @@  discard block
 block discarded – undo
772 815
 						<a href="', $buddy['online']['href'], '"><span class="' . ($buddy['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $buddy['online']['text'] . '"></span></a>
773 816
 					</td>';
774 817
 
775
-			if ($buddy['show_email'])
776
-				echo '
818
+			if ($buddy['show_email']) {
819
+							echo '
777 820
 					<td>
778 821
 						<a href="mailto:' . $buddy['email'] . '" rel="nofollow"><span class="generic_icons mail icon" title="' . $txt['email'] . ' ' . $buddy['name'] . '"></span></a>
779 822
 					</td>';
823
+			}
780 824
 
781 825
 			// Show the custom profile fields for this user.
782
-			if (!empty($context['custom_pf']))
783
-				foreach ($context['custom_pf'] as $key => $column)
826
+			if (!empty($context['custom_pf'])) {
827
+							foreach ($context['custom_pf'] as $key => $column)
784 828
 					echo '
785 829
 					<td class="lefttext">', $buddy['options'][$key], '</td>';
830
+			}
786 831
 
787 832
 			echo '
788 833
 					<td>
@@ -815,9 +860,10 @@  discard block
 block discarded – undo
815 860
 			</dl>
816 861
 		</div>';
817 862
 
818
-	if (!empty($context['token_check']))
819
-		echo '
863
+	if (!empty($context['token_check'])) {
864
+			echo '
820 865
 		<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
866
+	}
821 867
 
822 868
 	echo '
823 869
 		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -843,13 +889,13 @@  discard block
 block discarded – undo
843 889
 {
844 890
 	global $context, $scripturl, $txt;
845 891
 
846
-	if (!empty($context['saved_successful']))
847
-		echo '
892
+	if (!empty($context['saved_successful'])) {
893
+			echo '
848 894
 	<div class="infobox">', $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $context['member']['name']), '</div>';
849
-
850
-	elseif (!empty($context['saved_failed']))
851
-		echo '
895
+	} elseif (!empty($context['saved_failed'])) {
896
+			echo '
852 897
 	<div class="errorbox">', $context['saved_failed'], '</div>';
898
+	}
853 899
 
854 900
 	echo '
855 901
 	<div id="edit_buddies">
@@ -864,9 +910,10 @@  discard block
 block discarded – undo
864 910
 					<th scope="col" class="quarter_table">', $txt['name'], '</th>
865 911
 					<th scope="col">', $txt['status'], '</th>';
866 912
 
867
-	if (allowedTo('moderate_forum'))
868
-		echo '
913
+	if (allowedTo('moderate_forum')) {
914
+			echo '
869 915
 					<th scope="col">', $txt['email'], '</th>';
916
+	}
870 917
 
871 918
 	echo '
872 919
 					<th scope="col">', $txt['ignore_remove'], '</th>
@@ -875,13 +922,14 @@  discard block
 block discarded – undo
875 922
 			<tbody>';
876 923
 
877 924
 	// If they don't have anyone on their ignore list, don't list it!
878
-	if (empty($context['ignore_list']))
879
-		echo '
925
+	if (empty($context['ignore_list'])) {
926
+			echo '
880 927
 				<tr class="windowbg">
881 928
 					<td colspan="', allowedTo('moderate_forum') ? '4' : '3', '">
882 929
 						<strong>', $txt['no_ignore'], '</strong>
883 930
 					</td>
884 931
 				</tr>';
932
+	}
885 933
 
886 934
 	// Now loop through each buddy showing info on each.
887 935
 	foreach ($context['ignore_list'] as $member)
@@ -893,11 +941,12 @@  discard block
 block discarded – undo
893 941
 						<a href="', $member['online']['href'], '"><span class="' . ($member['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $member['online']['text'] . '"></span></a>
894 942
 					</td>';
895 943
 
896
-		if ($member['show_email'])
897
-			echo '
944
+		if ($member['show_email']) {
945
+					echo '
898 946
 					<td>
899 947
 						<a href="mailto:' . $member['email'] . '" rel="nofollow"><span class="generic_icons mail icon" title="' . $txt['email'] . ' ' . $member['name'] . '"></span></a>
900 948
 					</td>';
949
+		}
901 950
 		echo '
902 951
 					<td>
903 952
 						<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons delete" title="', $txt['ignore_remove'], '"></span></a>
@@ -927,9 +976,10 @@  discard block
 block discarded – undo
927 976
 			</dl>
928 977
 		</div>';
929 978
 
930
-	if (!empty($context['token_check']))
931
-		echo '
979
+	if (!empty($context['token_check'])) {
980
+			echo '
932 981
 		<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
982
+	}
933 983
 
934 984
 	echo '
935 985
 		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -975,9 +1025,10 @@  discard block
 block discarded – undo
975 1025
 					<a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip'], ';u=', $context['member']['id'], '">', $context['last_ip'], '</a>';
976 1026
 
977 1027
 	// Second address detected?
978
-	if (!empty($context['last_ip2']))
979
-		echo '
1028
+	if (!empty($context['last_ip2'])) {
1029
+			echo '
980 1030
 					, <a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip2'], ';u=', $context['member']['id'], '">', $context['last_ip2'], '</a>';
1031
+	}
981 1032
 
982 1033
 	echo '
983 1034
 				</dd>';
@@ -1043,9 +1094,10 @@  discard block
 block discarded – undo
1043 1094
 		</div>
1044 1095
 		<div class="windowbg2 noup">';
1045 1096
 
1046
-		foreach ($context['whois_servers'] as $server)
1047
-			echo '
1097
+		foreach ($context['whois_servers'] as $server) {
1098
+					echo '
1048 1099
 			<a href="', $server['url'], '" target="_blank" rel="noopener"', isset($context['auto_whois_server']) && $context['auto_whois_server']['name'] == $server['name'] ? ' style="font-weight: bold;"' : '', '>', $server['name'], '</a><br>';
1100
+		}
1049 1101
 		echo '
1050 1102
 		</div>
1051 1103
 		<br>';
@@ -1057,13 +1109,12 @@  discard block
 block discarded – undo
1057 1109
 			<h3 class="catbg">', $txt['members_from_ip'], ' ', $context['ip'], '</h3>
1058 1110
 		</div>';
1059 1111
 
1060
-	if (empty($context['ips']))
1061
-		echo '
1112
+	if (empty($context['ips'])) {
1113
+			echo '
1062 1114
 		<p class="windowbg2 description">
1063 1115
 			<em>', $txt['no_members_from_ip'], '</em>
1064 1116
 		</p>';
1065
-
1066
-	else
1117
+	} else
1067 1118
 	{
1068 1119
 		echo '
1069 1120
 		<table class="table_grid">
@@ -1076,12 +1127,13 @@  discard block
 block discarded – undo
1076 1127
 			<tbody>';
1077 1128
 
1078 1129
 		// Loop through each of the members and display them.
1079
-		foreach ($context['ips'] as $ip => $memberlist)
1080
-			echo '
1130
+		foreach ($context['ips'] as $ip => $memberlist) {
1131
+					echo '
1081 1132
 				<tr class="windowbg">
1082 1133
 					<td><a href="', $context['base_url'], ';searchip=', $ip, '">', $ip, '</a></td>
1083 1134
 					<td>', implode(', ', $memberlist), '</td>
1084 1135
 				</tr>';
1136
+		}
1085 1137
 
1086 1138
 		echo '
1087 1139
 			</tbody>
@@ -1123,11 +1175,10 @@  discard block
 block discarded – undo
1123 1175
 			</h3>
1124 1176
 		</div>';
1125 1177
 
1126
-	if ($context['member']['has_all_permissions'])
1127
-		echo '
1178
+	if ($context['member']['has_all_permissions']) {
1179
+			echo '
1128 1180
 		<div class="information">', $txt['showPermissions_all'], '</div>';
1129
-
1130
-	else
1181
+	} else
1131 1182
 	{
1132 1183
 		echo '
1133 1184
 		<div class="information">',$txt['showPermissions_help'], '</div>
@@ -1142,9 +1193,10 @@  discard block
 block discarded – undo
1142 1193
 			<div class="windowbg smalltext">
1143 1194
 				', $txt['showPermissions_restricted_boards_desc'], ':<br>';
1144 1195
 
1145
-			foreach ($context['no_access_boards'] as $no_access_board)
1146
-				echo '
1196
+			foreach ($context['no_access_boards'] as $no_access_board) {
1197
+							echo '
1147 1198
 				<a href="', $scripturl, '?board=', $no_access_board['id'], '.0">', $no_access_board['name'], '</a>', $no_access_board['is_last'] ? '' : ', ';
1199
+			}
1148 1200
 			echo '
1149 1201
 			</div>';
1150 1202
 		}
@@ -1176,12 +1228,13 @@  discard block
 block discarded – undo
1176 1228
 							</td>
1177 1229
 							<td class="smalltext">';
1178 1230
 
1179
-				if ($permission['is_denied'])
1180
-					echo '
1231
+				if ($permission['is_denied']) {
1232
+									echo '
1181 1233
 								<span class="alert">', $txt['showPermissions_denied'], ': ', implode(', ', $permission['groups']['denied']), '</span>';
1182
-				else
1183
-					echo '
1234
+				} else {
1235
+									echo '
1184 1236
 								', $txt['showPermissions_given'], ': ', implode(', ', $permission['groups']['allowed']);
1237
+				}
1185 1238
 
1186 1239
 				echo '
1187 1240
 							</td>
@@ -1192,10 +1245,10 @@  discard block
 block discarded – undo
1192 1245
 				</table>
1193 1246
 			</div><!-- .tborder -->
1194 1247
 			<br>';
1195
-		}
1196
-		else
1197
-			echo '
1248
+		} else {
1249
+					echo '
1198 1250
 			<p class="windowbg2">', $txt['showPermissions_none_general'], '</p>';
1251
+		}
1199 1252
 
1200 1253
 		// Board permission section.
1201 1254
 		echo '
@@ -1206,14 +1259,16 @@  discard block
 block discarded – undo
1206 1259
 						<select name="board" onchange="if (this.options[this.selectedIndex].value) this.form.submit();">
1207 1260
 							<option value="0"', $context['board'] == 0 ? ' selected' : '', '>', $txt['showPermissions_global'], '</option>';
1208 1261
 
1209
-		if (!empty($context['boards']))
1210
-			echo '
1262
+		if (!empty($context['boards'])) {
1263
+					echo '
1211 1264
 							<option value="" disabled>---------------------------</option>';
1265
+		}
1212 1266
 
1213 1267
 		// Fill the box with any local permission boards.
1214
-		foreach ($context['boards'] as $board)
1215
-			echo '
1268
+		foreach ($context['boards'] as $board) {
1269
+					echo '
1216 1270
 							<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['name'], ' (', $board['profile_name'], ')</option>';
1271
+		}
1217 1272
 
1218 1273
 		echo '
1219 1274
 						</select>
@@ -1242,13 +1297,13 @@  discard block
 block discarded – undo
1242 1297
 						</td>
1243 1298
 						<td class="smalltext">';
1244 1299
 
1245
-				if ($permission['is_denied'])
1246
-					echo '
1300
+				if ($permission['is_denied']) {
1301
+									echo '
1247 1302
 							<span class="alert">', $txt['showPermissions_denied'], ': ', implode(', ', $permission['groups']['denied']), '</span>';
1248
-
1249
-				else
1250
-					echo '
1303
+				} else {
1304
+									echo '
1251 1305
 							', $txt['showPermissions_given'], ': ', implode(', ', $permission['groups']['allowed']);
1306
+				}
1252 1307
 
1253 1308
 				echo '
1254 1309
 						</td>
@@ -1257,10 +1312,10 @@  discard block
 block discarded – undo
1257 1312
 			echo '
1258 1313
 				</tbody>
1259 1314
 			</table>';
1260
-		}
1261
-		else
1262
-			echo '
1315
+		} else {
1316
+					echo '
1263 1317
 			<p class="windowbg2">', $txt['showPermissions_none_board'], '</p>';
1318
+		}
1264 1319
 	echo '
1265 1320
 		</div><!-- #permissions -->';
1266 1321
 	}
@@ -1301,9 +1356,10 @@  discard block
 block discarded – undo
1301 1356
 			</div>';
1302 1357
 
1303 1358
 	// If they haven't post at all, don't draw the graph.
1304
-	if (empty($context['posts_by_time']))
1305
-		echo '
1359
+	if (empty($context['posts_by_time'])) {
1360
+			echo '
1306 1361
 			<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1362
+	}
1307 1363
 
1308 1364
 	// Otherwise do!
1309 1365
 	else
@@ -1312,8 +1368,8 @@  discard block
 block discarded – undo
1312 1368
 			<ul class="activity_stats flow_hidden">';
1313 1369
 
1314 1370
 		// The labels.
1315
-		foreach ($context['posts_by_time'] as $time_of_day)
1316
-			echo '
1371
+		foreach ($context['posts_by_time'] as $time_of_day) {
1372
+					echo '
1317 1373
 				<li', $time_of_day['is_last'] ? ' class="last"' : '', '>
1318 1374
 					<div class="bar" style="padding-top: ', ((int) (100 - $time_of_day['relative_percent'])), 'px;" title="', sprintf($txt['statPanel_activityTime_posts'], $time_of_day['posts'], $time_of_day['posts_percent']), '">
1319 1375
 						<div style="height: ', (int) $time_of_day['relative_percent'], 'px;">
@@ -1322,6 +1378,7 @@  discard block
 block discarded – undo
1322 1378
 					</div>
1323 1379
 					<span class="stats_hour">', $time_of_day['hour_format'], '</span>
1324 1380
 				</li>';
1381
+		}
1325 1382
 
1326 1383
 		echo '
1327 1384
 			</ul>';
@@ -1340,11 +1397,10 @@  discard block
 block discarded – undo
1340 1397
 					</h3>
1341 1398
 				</div>';
1342 1399
 
1343
-	if (empty($context['popular_boards']))
1344
-		echo '
1400
+	if (empty($context['popular_boards'])) {
1401
+			echo '
1345 1402
 				<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1346
-
1347
-	else
1403
+	} else
1348 1404
 	{
1349 1405
 		echo '
1350 1406
 				<dl class="stats">';
@@ -1374,10 +1430,10 @@  discard block
 block discarded – undo
1374 1430
 					</h3>
1375 1431
 				</div>';
1376 1432
 
1377
-	if (empty($context['board_activity']))
1378
-		echo '
1433
+	if (empty($context['board_activity'])) {
1434
+			echo '
1379 1435
 				<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1380
-	else
1436
+	} else
1381 1437
 	{
1382 1438
 		echo '
1383 1439
 				<dl class="stats">';
@@ -1428,90 +1484,97 @@  discard block
 block discarded – undo
1428 1484
 				<h3 class="catbg profile_hd">';
1429 1485
 
1430 1486
 		// Don't say "Profile" if this isn't the profile...
1431
-		if (!empty($context['profile_header_text']))
1432
-			echo '
1487
+		if (!empty($context['profile_header_text'])) {
1488
+					echo '
1433 1489
 					', $context['profile_header_text'];
1434
-		else
1435
-			echo '
1490
+		} else {
1491
+					echo '
1436 1492
 					', $txt['profile'];
1493
+		}
1437 1494
 
1438 1495
 		echo '
1439 1496
 				</h3>
1440 1497
 			</div>';
1441 1498
 
1442 1499
 	// Have we some description?
1443
-	if ($context['page_desc'])
1444
-		echo '
1500
+	if ($context['page_desc']) {
1501
+			echo '
1445 1502
 			<p class="information">', $context['page_desc'], '</p>';
1503
+	}
1446 1504
 
1447 1505
 	echo '
1448 1506
 			<div class="roundframe">';
1449 1507
 
1450 1508
 	// Any bits at the start?
1451
-	if (!empty($context['profile_prehtml']))
1452
-		echo '
1509
+	if (!empty($context['profile_prehtml'])) {
1510
+			echo '
1453 1511
 				<div>', $context['profile_prehtml'], '</div>';
1512
+	}
1454 1513
 
1455
-	if (!empty($context['profile_fields']))
1456
-		echo '
1514
+	if (!empty($context['profile_fields'])) {
1515
+			echo '
1457 1516
 				<dl class="settings">';
1517
+	}
1458 1518
 
1459 1519
 	// Start the big old loop 'of love.
1460 1520
 	$lastItem = 'hr';
1461 1521
 	foreach ($context['profile_fields'] as $key => $field)
1462 1522
 	{
1463 1523
 		// We add a little hack to be sure we never get more than one hr in a row!
1464
-		if ($lastItem == 'hr' && $field['type'] == 'hr')
1465
-			continue;
1524
+		if ($lastItem == 'hr' && $field['type'] == 'hr') {
1525
+					continue;
1526
+		}
1466 1527
 
1467 1528
 		$lastItem = $field['type'];
1468
-		if ($field['type'] == 'hr')
1469
-			echo '
1529
+		if ($field['type'] == 'hr') {
1530
+					echo '
1470 1531
 				</dl>
1471 1532
 				<hr>
1472 1533
 				<dl class="settings">';
1473
-
1474
-		elseif ($field['type'] == 'callback')
1534
+		} elseif ($field['type'] == 'callback')
1475 1535
 		{
1476 1536
 			if (isset($field['callback_func']) && function_exists('template_profile_' . $field['callback_func']))
1477 1537
 			{
1478 1538
 				$callback_func = 'template_profile_' . $field['callback_func'];
1479 1539
 				$callback_func();
1480 1540
 			}
1481
-		}
1482
-		else
1541
+		} else
1483 1542
 		{
1484 1543
 			echo '
1485 1544
 					<dt>
1486 1545
 						<strong', !empty($field['is_error']) ? ' class="error"' : '', '>', $field['type'] !== 'label' ? '<label for="' . $key . '">' : '', $field['label'], $field['type'] !== 'label' ? '</label>' : '', '</strong>';
1487 1546
 
1488 1547
 			// Does it have any subtext to show?
1489
-			if (!empty($field['subtext']))
1490
-				echo '
1548
+			if (!empty($field['subtext'])) {
1549
+							echo '
1491 1550
 						<br>
1492 1551
 						<span class="smalltext">', $field['subtext'], '</span>';
1552
+			}
1493 1553
 
1494 1554
 			echo '
1495 1555
 					</dt>
1496 1556
 					<dd>';
1497 1557
 
1498 1558
 			// Want to put something infront of the box?
1499
-			if (!empty($field['preinput']))
1500
-				echo '
1559
+			if (!empty($field['preinput'])) {
1560
+							echo '
1501 1561
 						', $field['preinput'];
1562
+			}
1502 1563
 
1503 1564
 			// What type of data are we showing?
1504
-			if ($field['type'] == 'label')
1505
-				echo '
1565
+			if ($field['type'] == 'label') {
1566
+							echo '
1506 1567
 						', $field['value'];
1568
+			}
1507 1569
 
1508 1570
 			// Maybe it's a text box - very likely!
1509 1571
 			elseif (in_array($field['type'], array('int', 'float', 'text', 'password', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'number', 'time', 'url')))
1510 1572
 			{
1511
-				if ($field['type'] == 'int' || $field['type'] == 'float')
1512
-					$type = 'number';
1513
-				else
1514
-					$type = $field['type'];
1573
+				if ($field['type'] == 'int' || $field['type'] == 'float') {
1574
+									$type = 'number';
1575
+				} else {
1576
+									$type = $field['type'];
1577
+				}
1515 1578
 				$step = $field['type'] == 'float' ? ' step="0.1"' : '';
1516 1579
 
1517 1580
 
@@ -1519,10 +1582,11 @@  discard block
 block discarded – undo
1519 1582
 						<input type="', $type, '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" ', $field['input_attr'], ' ', $step, '>';
1520 1583
 			}
1521 1584
 			// You "checking" me out? ;)
1522
-			elseif ($field['type'] == 'check')
1523
-				echo '
1585
+			elseif ($field['type'] == 'check') {
1586
+							echo '
1524 1587
 						<input type="hidden" name="', $key, '" value="0">
1525 1588
 						<input type="checkbox" name="', $key, '" id="', $key, '"', !empty($field['value']) ? ' checked' : '', ' value="1" ', $field['input_attr'], '>';
1589
+			}
1526 1590
 
1527 1591
 			// Always fun - select boxes!
1528 1592
 			elseif ($field['type'] == 'select')
@@ -1533,14 +1597,16 @@  discard block
 block discarded – undo
1533 1597
 				if (isset($field['options']))
1534 1598
 				{
1535 1599
 					// Is this some code to generate the options?
1536
-					if (!is_array($field['options']))
1537
-						$field['options'] = $field['options']();
1600
+					if (!is_array($field['options'])) {
1601
+											$field['options'] = $field['options']();
1602
+					}
1538 1603
 
1539 1604
 					// Assuming we now have some!
1540
-					if (is_array($field['options']))
1541
-						foreach ($field['options'] as $value => $name)
1605
+					if (is_array($field['options'])) {
1606
+											foreach ($field['options'] as $value => $name)
1542 1607
 							echo '
1543 1608
 							<option value="', $value, '"', $value == $field['value'] ? ' selected' : '', '>', $name, '</option>';
1609
+					}
1544 1610
 				}
1545 1611
 
1546 1612
 				echo '
@@ -1548,31 +1614,34 @@  discard block
 block discarded – undo
1548 1614
 			}
1549 1615
 
1550 1616
 			// Something to end with?
1551
-			if (!empty($field['postinput']))
1552
-				echo '
1617
+			if (!empty($field['postinput'])) {
1618
+							echo '
1553 1619
 						', $field['postinput'];
1620
+			}
1554 1621
 
1555 1622
 			echo '
1556 1623
 					</dd>';
1557 1624
 		}
1558 1625
 	}
1559 1626
 
1560
-	if (!empty($context['profile_fields']))
1561
-		echo '
1627
+	if (!empty($context['profile_fields'])) {
1628
+			echo '
1562 1629
 				</dl>';
1630
+	}
1563 1631
 
1564 1632
 	// Are there any custom profile fields - if so print them!
1565 1633
 	if (!empty($context['custom_fields']))
1566 1634
 	{
1567
-		if ($lastItem != 'hr')
1568
-			echo '
1635
+		if ($lastItem != 'hr') {
1636
+					echo '
1569 1637
 				<hr>';
1638
+		}
1570 1639
 
1571 1640
 		echo '
1572 1641
 				<dl class="settings">';
1573 1642
 
1574
-		foreach ($context['custom_fields'] as $field)
1575
-			echo '
1643
+		foreach ($context['custom_fields'] as $field) {
1644
+					echo '
1576 1645
 					<dt>
1577 1646
 						<strong>', $field['name'], ': </strong><br>
1578 1647
 						<span class="smalltext">', $field['desc'], '</span>
@@ -1580,6 +1649,7 @@  discard block
 block discarded – undo
1580 1649
 					<dd>
1581 1650
 						', $field['input_html'], '
1582 1651
 					</dd>';
1652
+		}
1583 1653
 
1584 1654
 		echo '
1585 1655
 				</dl>';
@@ -1587,13 +1657,14 @@  discard block
 block discarded – undo
1587 1657
 	}
1588 1658
 
1589 1659
 	// Any closing HTML?
1590
-	if (!empty($context['profile_posthtml']))
1591
-		echo '
1660
+	if (!empty($context['profile_posthtml'])) {
1661
+			echo '
1592 1662
 				<div>', $context['profile_posthtml'], '</div>';
1663
+	}
1593 1664
 
1594 1665
 	// Only show the password box if it's actually needed.
1595
-	if ($context['require_password'])
1596
-		echo '
1666
+	if ($context['require_password']) {
1667
+			echo '
1597 1668
 				<dl class="settings">
1598 1669
 					<dt>
1599 1670
 						<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '><label for="oldpasswrd">', $txt['current_password'], ': </label></strong><br>
@@ -1603,18 +1674,21 @@  discard block
 block discarded – undo
1603 1674
 						<input type="password" name="oldpasswrd" id="oldpasswrd" size="20">
1604 1675
 					</dd>
1605 1676
 				</dl>';
1677
+	}
1606 1678
 
1607 1679
 	// The button shouldn't say "Change profile" unless we're changing the profile...
1608
-	if (!empty($context['submit_button_text']))
1609
-		echo '
1680
+	if (!empty($context['submit_button_text'])) {
1681
+			echo '
1610 1682
 				<input type="submit" name="save" value="', $context['submit_button_text'], '" class="button floatright">';
1611
-	else
1612
-		echo '
1683
+	} else {
1684
+			echo '
1613 1685
 				<input type="submit" name="save" value="', $txt['change_profile'], '" class="button floatright">';
1686
+	}
1614 1687
 
1615
-	if (!empty($context['token_check']))
1616
-		echo '
1688
+	if (!empty($context['token_check'])) {
1689
+			echo '
1617 1690
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
1691
+	}
1618 1692
 
1619 1693
 	echo '
1620 1694
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -1624,10 +1698,11 @@  discard block
 block discarded – undo
1624 1698
 		</form>';
1625 1699
 
1626 1700
 	// Any final spellchecking stuff?
1627
-	if (!empty($context['show_spellchecking']))
1628
-		echo '
1701
+	if (!empty($context['show_spellchecking'])) {
1702
+			echo '
1629 1703
 		<form name="spell_form" id="spell_form" method="post" accept-charset="', $context['character_set'], '" target="spellWindow" action="', $scripturl, '?action=spellcheck"><input type="hidden" name="spellstring" value=""></form>';
1630
-}
1704
+	}
1705
+	}
1631 1706
 
1632 1707
 /**
1633 1708
  * Personal Message settings.
@@ -1664,10 +1739,11 @@  discard block
 block discarded – undo
1664 1739
 						<select name="pm_receive_from" id="pm_receive_from">
1665 1740
 							<option value="0"', empty($context['receive_from']) || (empty($modSettings['enable_buddylist']) && $context['receive_from'] < 3) ? ' selected' : '', '>', $txt['pm_receive_from_everyone'], '</option>';
1666 1741
 
1667
-	if (!empty($modSettings['enable_buddylist']))
1668
-		echo '
1742
+	if (!empty($modSettings['enable_buddylist'])) {
1743
+			echo '
1669 1744
 							<option value="1"', !empty($context['receive_from']) && $context['receive_from'] == 1 ? ' selected' : '', '>', $txt['pm_receive_from_ignore'], '</option>
1670 1745
 							<option value="2"', !empty($context['receive_from']) && $context['receive_from'] == 2 ? ' selected' : '', '>', $txt['pm_receive_from_buddies'], '</option>';
1746
+	}
1671 1747
 
1672 1748
 	echo '
1673 1749
 							<option value="3"', !empty($context['receive_from']) && $context['receive_from'] > 2 ? ' selected' : '', '>', $txt['pm_receive_from_admins'], '</option>
@@ -1710,11 +1786,12 @@  discard block
 block discarded – undo
1710 1786
 		if (empty($setting) || !is_array($setting))
1711 1787
 		{
1712 1788
 			// Insert a separator (unless this is the first item in the list)
1713
-			if ($i !== $first_option_key)
1714
-				echo '
1789
+			if ($i !== $first_option_key) {
1790
+							echo '
1715 1791
 				</dl>
1716 1792
 				<hr>
1717 1793
 				<dl class="settings">';
1794
+			}
1718 1795
 
1719 1796
 			// Should we give a name to this section?
1720 1797
 			if (is_string($setting) && !empty($setting))
@@ -1723,69 +1800,67 @@  discard block
 block discarded – undo
1723 1800
 				echo '
1724 1801
 					<dt><strong>' . $setting . '</strong></dt>
1725 1802
 					<dd></dd>';
1803
+			} else {
1804
+							$titled_section = false;
1726 1805
 			}
1727
-			else
1728
-				$titled_section = false;
1729 1806
 
1730 1807
 			continue;
1731 1808
 		}
1732 1809
 
1733 1810
 		// Is this disabled?
1734
-		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled']))
1735
-			continue;
1736
-
1737
-		elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
1738
-			continue;
1739
-
1740
-		elseif ($setting['id'] == 'show_no_censored' && empty($modSettings['allow_no_censored']))
1741
-			continue;
1742
-
1743
-		elseif ($setting['id'] == 'posts_apply_ignore_list' && empty($modSettings['enable_buddylist']))
1744
-			continue;
1745
-
1746
-		elseif ($setting['id'] == 'wysiwyg_default' && !empty($modSettings['disable_wysiwyg']))
1747
-			continue;
1748
-
1749
-		elseif ($setting['id'] == 'drafts_autosave_enabled' && (empty($modSettings['drafts_autosave_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled']))))
1750
-			continue;
1751
-
1752
-		elseif ($setting['id'] == 'drafts_show_saved_enabled' && (empty($modSettings['drafts_show_saved_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled']))))
1753
-			continue;
1811
+		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled'])) {
1812
+					continue;
1813
+		} elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) {
1814
+					continue;
1815
+		} elseif ($setting['id'] == 'show_no_censored' && empty($modSettings['allow_no_censored'])) {
1816
+					continue;
1817
+		} elseif ($setting['id'] == 'posts_apply_ignore_list' && empty($modSettings['enable_buddylist'])) {
1818
+					continue;
1819
+		} elseif ($setting['id'] == 'wysiwyg_default' && !empty($modSettings['disable_wysiwyg'])) {
1820
+					continue;
1821
+		} elseif ($setting['id'] == 'drafts_autosave_enabled' && (empty($modSettings['drafts_autosave_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled'])))) {
1822
+					continue;
1823
+		} elseif ($setting['id'] == 'drafts_show_saved_enabled' && (empty($modSettings['drafts_show_saved_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled'])))) {
1824
+					continue;
1825
+		}
1754 1826
 
1755 1827
 		// Some of these may not be set...  Set to defaults here
1756 1828
 		$opts = array('topics_per_page', 'messages_per_page', 'display_quick_mod');
1757
-		if (in_array($setting['id'], $opts) && !isset($context['member']['options'][$setting['id']]))
1758
-			$context['member']['options'][$setting['id']] = 0;
1759
-
1760
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
1761
-			$setting['type'] = 'checkbox';
1762
-
1763
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
1764
-			$setting['type'] = 'number';
1829
+		if (in_array($setting['id'], $opts) && !isset($context['member']['options'][$setting['id']])) {
1830
+					$context['member']['options'][$setting['id']] = 0;
1831
+		}
1765 1832
 
1766
-		elseif ($setting['type'] == 'string')
1767
-			$setting['type'] = 'text';
1833
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
1834
+					$setting['type'] = 'checkbox';
1835
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
1836
+					$setting['type'] = 'number';
1837
+		} elseif ($setting['type'] == 'string') {
1838
+					$setting['type'] = 'text';
1839
+		}
1768 1840
 
1769
-		if (isset($setting['options']))
1770
-			$setting['type'] = 'list';
1841
+		if (isset($setting['options'])) {
1842
+					$setting['type'] = 'list';
1843
+		}
1771 1844
 
1772 1845
 		echo '
1773 1846
 					<dt>
1774 1847
 						<label for="', $setting['id'], '">', !$titled_section ? '<strong>' : '', $setting['label'], !$titled_section ? '</strong>' : '', '</label>';
1775 1848
 
1776
-		if (isset($setting['description']))
1777
-			echo '
1849
+		if (isset($setting['description'])) {
1850
+					echo '
1778 1851
 						<br>
1779 1852
 						<span class="smalltext">', $setting['description'], '</span>';
1853
+		}
1780 1854
 		echo '
1781 1855
 					</dt>
1782 1856
 					<dd>';
1783 1857
 
1784 1858
 		// Display checkbox options
1785
-		if ($setting['type'] == 'checkbox')
1786
-			echo '
1859
+		if ($setting['type'] == 'checkbox') {
1860
+					echo '
1787 1861
 						<input type="hidden" name="default_options[' . $setting['id'] . ']" value="0">
1788 1862
 						<input type="checkbox" name="default_options[', $setting['id'], ']" id="', $setting['id'], '"', !empty($context['member']['options'][$setting['id']]) ? ' checked' : '', ' value="1">';
1863
+		}
1789 1864
 
1790 1865
 		// How about selection lists, we all love them
1791 1866
 		elseif ($setting['type'] == 'list')
@@ -1793,9 +1868,10 @@  discard block
 block discarded – undo
1793 1868
 			echo '
1794 1869
 						<select name="default_options[', $setting['id'], ']" id="', $setting['id'], '"', '>';
1795 1870
 
1796
-			foreach ($setting['options'] as $value => $label)
1797
-				echo '
1871
+			foreach ($setting['options'] as $value => $label) {
1872
+							echo '
1798 1873
 							<option value="', $value, '"', $value == $context['member']['options'][$setting['id']] ? ' selected' : '', '>', $label, '</option>';
1874
+			}
1799 1875
 
1800 1876
 			echo '
1801 1877
 						</select>';
@@ -1811,14 +1887,13 @@  discard block
 block discarded – undo
1811 1887
 
1812 1888
 				echo '
1813 1889
 						<input type="number"', $min . $max . $step;
1814
-			}
1815
-			elseif (isset($setting['type']) && $setting['type'] == 'url')
1816
-				echo'
1890
+			} elseif (isset($setting['type']) && $setting['type'] == 'url') {
1891
+							echo'
1817 1892
 						<input type="url"';
1818
-
1819
-			else
1820
-				echo '
1893
+			} else {
1894
+							echo '
1821 1895
 						<input type="text"';
1896
+			}
1822 1897
 
1823 1898
 			echo ' name="default_options[', $setting['id'], ']" id="', $setting['id'], '" value="', isset($context['member']['options'][$setting['id']]) ? $context['member']['options'][$setting['id']] : $setting['value'], '"', $setting['type'] == 'number' ? ' size="5"' : '', '>';
1824 1899
 		}
@@ -1855,8 +1930,8 @@  discard block
 block discarded – undo
1855 1930
 				<dl class="settings">';
1856 1931
 
1857 1932
 	// Allow notification on announcements to be disabled?
1858
-	if (!empty($modSettings['allow_disableAnnounce']))
1859
-		echo '
1933
+	if (!empty($modSettings['allow_disableAnnounce'])) {
1934
+			echo '
1860 1935
 					<dt>
1861 1936
 						<label for="notify_announcements">', $txt['notify_important_email'], '</label>
1862 1937
 					</dt>
@@ -1864,15 +1939,17 @@  discard block
 block discarded – undo
1864 1939
 						<input type="hidden" name="notify_announcements" value="0">
1865 1940
 						<input type="checkbox" id="notify_announcements" name="notify_announcements" value="1"', !empty($context['member']['notify_announcements']) ? ' checked' : '', '>
1866 1941
 					</dd>';
1942
+	}
1867 1943
 
1868
-	if (!empty($modSettings['enable_ajax_alerts']))
1869
-		echo '
1944
+	if (!empty($modSettings['enable_ajax_alerts'])) {
1945
+			echo '
1870 1946
 					<dt>
1871 1947
 						<label for="notify_send_body">', $txt['notify_alert_timeout'], '</label>
1872 1948
 					</dt>
1873 1949
 					<dd>
1874 1950
 						<input type="number" size="4" id="notify_alert_timeout" name="opt_alert_timeout" min="0" value="', $context['member']['alert_timeout'], '">
1875 1951
 					</dd>';
1952
+	}
1876 1953
 
1877 1954
 	echo '
1878 1955
 				</dl>
@@ -1904,9 +1981,10 @@  discard block
 block discarded – undo
1904 1981
 
1905 1982
 				$label = $txt['alert_opt_' . $opts[1]];
1906 1983
 				$label_pos = isset($opts['label']) ? $opts['label'] : '';
1907
-				if ($label_pos == 'before')
1908
-					echo '
1984
+				if ($label_pos == 'before') {
1985
+									echo '
1909 1986
 						<label for="opt_', $opts[1], '">', $label, '</label>';
1987
+				}
1910 1988
 
1911 1989
 				$this_value = isset($context['alert_prefs'][$opts[1]]) ? $context['alert_prefs'][$opts[1]] : 0;
1912 1990
 				switch ($opts[0])
@@ -1920,17 +1998,19 @@  discard block
 block discarded – undo
1920 1998
 						echo '
1921 1999
 						<select name="opt_', $opts[1], '" id="opt_', $opts[1], '">';
1922 2000
 
1923
-						foreach ($opts['opts'] as $k => $v)
1924
-							echo '
2001
+						foreach ($opts['opts'] as $k => $v) {
2002
+													echo '
1925 2003
 							<option value="', $k, '"', $this_value == $k ? ' selected' : '', '>', $v, '</option>';
2004
+						}
1926 2005
 						echo '
1927 2006
 						</select>';
1928 2007
 						break;
1929 2008
 				}
1930 2009
 
1931
-				if ($label_pos == 'after')
1932
-					echo '
2010
+				if ($label_pos == 'after') {
2011
+									echo '
1933 2012
 						<label for="opt_', $opts[1], '">', $label, '</label>';
2013
+				}
1934 2014
 
1935 2015
 				echo '
1936 2016
 					</td>
@@ -2047,11 +2127,12 @@  discard block
 block discarded – undo
2047 2127
 			<p class="information">', $txt['groupMembership_info'], '</p>';
2048 2128
 
2049 2129
 	// Do we have an update message?
2050
-	if (!empty($context['update_message']))
2051
-		echo '
2130
+	if (!empty($context['update_message'])) {
2131
+			echo '
2052 2132
 			<div class="infobox">
2053 2133
 				', $context['update_message'], '.
2054 2134
 			</div>';
2135
+	}
2055 2136
 
2056 2137
 	echo '
2057 2138
 			<div id="groups">';
@@ -2073,8 +2154,7 @@  discard block
 block discarded – undo
2073 2154
 						</div>
2074 2155
 					</div>
2075 2156
 				</div><!-- .groupmembership -->';
2076
-	}
2077
-	else
2157
+	} else
2078 2158
 	{
2079 2159
 		echo '
2080 2160
 				<div class="title_bar">
@@ -2086,27 +2166,30 @@  discard block
 block discarded – undo
2086 2166
 			echo '
2087 2167
 				<div class="windowbg" id="primdiv_', $group['id'], '">';
2088 2168
 
2089
-				if ($context['can_edit_primary'])
2090
-					echo '
2169
+				if ($context['can_edit_primary']) {
2170
+									echo '
2091 2171
 					<input type="radio" name="primary" id="primary_', $group['id'], '" value="', $group['id'], '"', $group['is_primary'] ? ' checked' : '', ' onclick="highlightSelected(\'primdiv_' . $group['id'] . '\');"', $group['can_be_primary'] ? '' : ' disabled', '>';
2172
+				}
2092 2173
 
2093 2174
 				echo '
2094 2175
 					<label for="primary_', $group['id'], '"><strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br><span class="smalltext">' . $group['desc'] . '</span>' : ''), '</label>';
2095 2176
 
2096 2177
 				// Can they leave their group?
2097
-				if ($group['can_leave'])
2098
-					echo '
2178
+				if ($group['can_leave']) {
2179
+									echo '
2099 2180
 					<a href="' . $scripturl . '?action=profile;save;u=' . $context['id_member'] . ';area=groupmembership;' . $context['session_var'] . '=' . $context['session_id'] . ';gid=' . $group['id'] . ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '">' . $txt['leave_group'] . '</a>';
2181
+				}
2100 2182
 
2101 2183
 				echo '
2102 2184
 				</div><!-- .windowbg -->';
2103 2185
 		}
2104 2186
 
2105
-		if ($context['can_edit_primary'])
2106
-			echo '
2187
+		if ($context['can_edit_primary']) {
2188
+					echo '
2107 2189
 				<div class="padding righttext">
2108 2190
 					<input type="submit" value="', $txt['make_primary'], '" class="button">
2109 2191
 				</div>';
2192
+		}
2110 2193
 
2111 2194
 		// Any groups they can join?
2112 2195
 		if (!empty($context['groups']['available']))
@@ -2122,17 +2205,16 @@  discard block
 block discarded – undo
2122 2205
 				<div class="windowbg">
2123 2206
 					<strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br><span class="smalltext">' . $group['desc'] . '</span>' : ''), '';
2124 2207
 
2125
-				if ($group['type'] == 3)
2126
-					echo '
2208
+				if ($group['type'] == 3) {
2209
+									echo '
2127 2210
 					<a href="', $scripturl, '?action=profile;save;u=', $context['id_member'], ';area=groupmembership;', $context['session_var'], '=', $context['session_id'], ';gid=', $group['id'], ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '" class="button floatright">', $txt['join_group'], '</a>';
2128
-
2129
-				elseif ($group['type'] == 2 && $group['pending'])
2130
-					echo '
2211
+				} elseif ($group['type'] == 2 && $group['pending']) {
2212
+									echo '
2131 2213
 					<span class="floatright">', $txt['approval_pending'], '</span>';
2132
-
2133
-				elseif ($group['type'] == 2)
2134
-					echo '
2214
+				} elseif ($group['type'] == 2) {
2215
+									echo '
2135 2216
 					<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=groupmembership;request=', $group['id'], '" class="button floatright">', $txt['request_group'], '</a>';
2217
+				}
2136 2218
 
2137 2219
 				echo '
2138 2220
 				</div><!-- .windowbg -->';
@@ -2155,9 +2237,10 @@  discard block
 block discarded – undo
2155 2237
 
2156 2238
 						prevDiv.className = "windowbg";
2157 2239
 					}';
2158
-		if (isset($context['groups']['member'][$context['primary_group']]))
2159
-			echo '
2240
+		if (isset($context['groups']['member'][$context['primary_group']])) {
2241
+					echo '
2160 2242
 					highlightSelected("primdiv_' . $context['primary_group'] . '");';
2243
+		}
2161 2244
 
2162 2245
 		echo '
2163 2246
 				</script>';
@@ -2166,9 +2249,10 @@  discard block
 block discarded – undo
2166 2249
 	echo '
2167 2250
 			</div><!-- #groups -->';
2168 2251
 
2169
-	if (!empty($context['token_check']))
2170
-		echo '
2252
+	if (!empty($context['token_check'])) {
2253
+			echo '
2171 2254
 			<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2255
+	}
2172 2256
 
2173 2257
 	echo '
2174 2258
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2216,14 +2300,15 @@  discard block
 block discarded – undo
2216 2300
 
2217 2301
 		foreach ($category['boards'] as $board)
2218 2302
 		{
2219
-			if ($i == $limit)
2220
-				echo '
2303
+			if ($i == $limit) {
2304
+							echo '
2221 2305
 						</ul>
2222 2306
 					</li>
2223 2307
 				</ul>
2224 2308
 				<ul class="ignoreboards floatright">
2225 2309
 					<li class="category">
2226 2310
 						<ul>';
2311
+			}
2227 2312
 
2228 2313
 			echo '
2229 2314
 							<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
@@ -2269,10 +2354,11 @@  discard block
 block discarded – undo
2269 2354
 
2270 2355
 	// Work out the starting color.
2271 2356
 	$context['current_color'] = $context['colors'][0];
2272
-	foreach ($context['colors'] as $limit => $color)
2273
-		if ($context['member']['warning'] >= $limit)
2357
+	foreach ($context['colors'] as $limit => $color) {
2358
+			if ($context['member']['warning'] >= $limit)
2274 2359
 			$context['current_color'] = $color;
2275
-}
2360
+	}
2361
+	}
2276 2362
 
2277 2363
 // Show all warnings of a user?
2278 2364
 function template_viewWarning()
@@ -2311,14 +2397,15 @@  discard block
 block discarded – undo
2311 2397
 				</dd>';
2312 2398
 
2313 2399
 	// There's some impact of this?
2314
-	if (!empty($context['level_effects'][$context['current_level']]))
2315
-		echo '
2400
+	if (!empty($context['level_effects'][$context['current_level']])) {
2401
+			echo '
2316 2402
 				<dt>
2317 2403
 					<strong>', $txt['profile_viewwarning_impact'], ':</strong>
2318 2404
 				</dt>
2319 2405
 				<dd>
2320 2406
 					', $context['level_effects'][$context['current_level']], '
2321 2407
 				</dd>';
2408
+	}
2322 2409
 
2323 2410
 	echo '
2324 2411
 			</dl>
@@ -2356,10 +2443,11 @@  discard block
 block discarded – undo
2356 2443
 
2357 2444
 			// Otherwise see what we can do...';
2358 2445
 
2359
-	foreach ($context['notification_templates'] as $k => $type)
2360
-		echo '
2446
+	foreach ($context['notification_templates'] as $k => $type) {
2447
+			echo '
2361 2448
 			if (index == ', $k, ')
2362 2449
 				document.getElementById(\'warn_body\').value = "', strtr($type['body'], array('"' => "'", "\n" => '\\n', "\r" => '')), '";';
2450
+	}
2363 2451
 
2364 2452
 	echo '
2365 2453
 		}
@@ -2369,10 +2457,11 @@  discard block
 block discarded – undo
2369 2457
 			// Also set the right effect.
2370 2458
 			effectText = "";';
2371 2459
 
2372
-	foreach ($context['level_effects'] as $limit => $text)
2373
-		echo '
2460
+	foreach ($context['level_effects'] as $limit => $text) {
2461
+			echo '
2374 2462
 			if (slideAmount >= ', $limit, ')
2375 2463
 				effectText = "', $text, '";';
2464
+	}
2376 2465
 
2377 2466
 	echo '
2378 2467
 			setInnerHTML(document.getElementById(\'cur_level_div\'), slideAmount + \'% (\' + effectText + \')\');
@@ -2387,32 +2476,35 @@  discard block
 block discarded – undo
2387 2476
 			</h3>
2388 2477
 		</div>';
2389 2478
 
2390
-	if (!$context['user']['is_owner'])
2391
-		echo '
2479
+	if (!$context['user']['is_owner']) {
2480
+			echo '
2392 2481
 		<p class="information">', $txt['profile_warning_desc'], '</p>';
2482
+	}
2393 2483
 
2394 2484
 	echo '
2395 2485
 		<div class="windowbg">
2396 2486
 			<dl class="settings">';
2397 2487
 
2398
-	if (!$context['user']['is_owner'])
2399
-		echo '
2488
+	if (!$context['user']['is_owner']) {
2489
+			echo '
2400 2490
 				<dt>
2401 2491
 					<strong>', $txt['profile_warning_name'], ':</strong>
2402 2492
 				</dt>
2403 2493
 				<dd>
2404 2494
 					<strong>', $context['member']['name'], '</strong>
2405 2495
 				</dd>';
2496
+	}
2406 2497
 
2407 2498
 	echo '
2408 2499
 				<dt>
2409 2500
 					<strong>', $txt['profile_warning_level'], ':</strong>';
2410 2501
 
2411 2502
 	// Is there only so much they can apply?
2412
-	if ($context['warning_limit'])
2413
-		echo '
2503
+	if ($context['warning_limit']) {
2504
+			echo '
2414 2505
 					<br>
2415 2506
 					<span class="smalltext">', sprintf($txt['profile_warning_limit_attribute'], $context['warning_limit']), '</span>';
2507
+	}
2416 2508
 
2417 2509
 	echo '
2418 2510
 				</dt>
@@ -2467,9 +2559,10 @@  discard block
 block discarded – undo
2467 2559
 						<option value="-1">', $txt['profile_warning_notify_template'], '</option>
2468 2560
 						<option value="-1" disabled>------------------------------</option>';
2469 2561
 
2470
-		foreach ($context['notification_templates'] as $id_template => $template)
2471
-			echo '
2562
+		foreach ($context['notification_templates'] as $id_template => $template) {
2563
+					echo '
2472 2564
 						<option value="', $id_template, '">', $template['title'], '</option>';
2565
+		}
2473 2566
 
2474 2567
 		echo '
2475 2568
 					</select>
@@ -2482,9 +2575,10 @@  discard block
 block discarded – undo
2482 2575
 			</dl>
2483 2576
 			<div class="righttext">';
2484 2577
 
2485
-	if (!empty($context['token_check']))
2486
-		echo '
2578
+	if (!empty($context['token_check'])) {
2579
+			echo '
2487 2580
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2581
+	}
2488 2582
 
2489 2583
 	echo '
2490 2584
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2500,8 +2594,8 @@  discard block
 block discarded – undo
2500 2594
 	echo '
2501 2595
 	<script>';
2502 2596
 
2503
-	if (!$context['user']['is_owner'])
2504
-		echo '
2597
+	if (!$context['user']['is_owner']) {
2598
+			echo '
2505 2599
 		modifyWarnNotify();
2506 2600
 		$(document).ready(function() {
2507 2601
 			$("#preview_button").click(function() {
@@ -2540,6 +2634,7 @@  discard block
 block discarded – undo
2540 2634
 			});
2541 2635
 			return false;
2542 2636
 		}';
2637
+	}
2543 2638
 
2544 2639
 	echo '
2545 2640
 	</script>';
@@ -2562,17 +2657,19 @@  discard block
 block discarded – undo
2562 2657
 			</div>';
2563 2658
 
2564 2659
 	// If deleting another account give them a lovely info box.
2565
-	if (!$context['user']['is_owner'])
2566
-		echo '
2660
+	if (!$context['user']['is_owner']) {
2661
+			echo '
2567 2662
 			<p class="information">', $txt['deleteAccount_desc'], '</p>';
2663
+	}
2568 2664
 
2569 2665
 	echo '
2570 2666
 			<div class="windowbg2">';
2571 2667
 
2572 2668
 	// If they are deleting their account AND the admin needs to approve it - give them another piece of info ;)
2573
-	if ($context['needs_approval'])
2574
-		echo '
2669
+	if ($context['needs_approval']) {
2670
+			echo '
2575 2671
 				<div class="errorbox">', $txt['deleteAccount_approval'], '</div>';
2672
+	}
2576 2673
 
2577 2674
 	// If the user is deleting their own account warn them first - and require a password!
2578 2675
 	if ($context['user']['is_owner'])
@@ -2584,9 +2681,10 @@  discard block
 block discarded – undo
2584 2681
 					<input type="password" name="oldpasswrd" size="20">
2585 2682
 					<input type="submit" value="', $txt['yes'], '" class="button">';
2586 2683
 
2587
-		if (!empty($context['token_check']))
2588
-			echo '
2684
+		if (!empty($context['token_check'])) {
2685
+					echo '
2589 2686
 					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2687
+		}
2590 2688
 
2591 2689
 		echo '
2592 2690
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2616,10 +2714,11 @@  discard block
 block discarded – undo
2616 2714
 						<option value="topics">', $txt['deleteAccount_topics'], '</option>
2617 2715
 					</select>';
2618 2716
 
2619
-			if ($context['show_perma_delete'])
2620
-				echo '
2717
+			if ($context['show_perma_delete']) {
2718
+							echo '
2621 2719
 					<br>
2622 2720
 					<label for="perma_delete"><input type="checkbox" name="perma_delete" id="perma_delete" value="1">', $txt['deleteAccount_permanent'], ':</label>';
2721
+			}
2623 2722
 
2624 2723
 			echo '
2625 2724
 				</div>';
@@ -2632,9 +2731,10 @@  discard block
 block discarded – undo
2632 2731
 				<div>
2633 2732
 					<input type="submit" value="', $txt['delete'], '" class="button">';
2634 2733
 
2635
-		if (!empty($context['token_check']))
2636
-			echo '
2734
+		if (!empty($context['token_check'])) {
2735
+					echo '
2637 2736
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2737
+		}
2638 2738
 
2639 2739
 		echo '
2640 2740
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2660,8 +2760,8 @@  discard block
 block discarded – undo
2660 2760
 					<hr>';
2661 2761
 
2662 2762
 	// Only show the password box if it's actually needed.
2663
-	if ($context['require_password'])
2664
-		echo '
2763
+	if ($context['require_password']) {
2764
+			echo '
2665 2765
 					<dl class="settings">
2666 2766
 						<dt>
2667 2767
 							<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '>', $txt['current_password'], ': </strong><br>
@@ -2671,13 +2771,15 @@  discard block
 block discarded – undo
2671 2771
 							<input type="password" name="oldpasswrd" size="20">
2672 2772
 						</dd>
2673 2773
 					</dl>';
2774
+	}
2674 2775
 
2675 2776
 	echo '
2676 2777
 					<div class="righttext">';
2677 2778
 
2678
-	if (!empty($context['token_check']))
2679
-		echo '
2779
+	if (!empty($context['token_check'])) {
2780
+			echo '
2680 2781
 						<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2782
+	}
2681 2783
 
2682 2784
 	echo '
2683 2785
 						<input type="submit" value="', $txt['change_profile'], '" class="button">
@@ -2704,9 +2806,10 @@  discard block
 block discarded – undo
2704 2806
 			<ul id="list_errors">';
2705 2807
 
2706 2808
 		// Cycle through each error and display an error message.
2707
-		foreach ($context['post_errors'] as $error)
2708
-			echo '
2809
+		foreach ($context['post_errors'] as $error) {
2810
+					echo '
2709 2811
 				<li>', isset($txt['profile_error_' . $error]) ? $txt['profile_error_' . $error] : $error, '</li>';
2812
+		}
2710 2813
 
2711 2814
 		echo '
2712 2815
 			</ul>';
@@ -2732,12 +2835,13 @@  discard block
 block discarded – undo
2732 2835
 								<select name="id_group" ', ($context['user']['is_owner'] && $context['member']['group_id'] == 1 ? 'onchange="if (this.value != 1 &amp;&amp; !confirm(\'' . $txt['deadmin_confirm'] . '\')) this.value = 1;"' : ''), '>';
2733 2836
 
2734 2837
 	// Fill the select box with all primary member groups that can be assigned to a member.
2735
-	foreach ($context['member_groups'] as $member_group)
2736
-		if (!empty($member_group['can_be_primary']))
2838
+	foreach ($context['member_groups'] as $member_group) {
2839
+			if (!empty($member_group['can_be_primary']))
2737 2840
 			echo '
2738 2841
 									<option value="', $member_group['id'], '"', $member_group['is_primary'] ? ' selected' : '', '>
2739 2842
 										', $member_group['name'], '
2740 2843
 									</option>';
2844
+	}
2741 2845
 
2742 2846
 	echo '
2743 2847
 								</select>
@@ -2750,10 +2854,11 @@  discard block
 block discarded – undo
2750 2854
 									<input type="hidden" name="additional_groups[]" value="0">';
2751 2855
 
2752 2856
 	// For each membergroup show a checkbox so members can be assigned to more than one group.
2753
-	foreach ($context['member_groups'] as $member_group)
2754
-		if ($member_group['can_be_additional'])
2857
+	foreach ($context['member_groups'] as $member_group) {
2858
+			if ($member_group['can_be_additional'])
2755 2859
 			echo '
2756 2860
 									<label for="additional_groups-', $member_group['id'], '"><input type="checkbox" name="additional_groups[]" value="', $member_group['id'], '" id="additional_groups-', $member_group['id'], '"', $member_group['is_additional'] ? ' checked' : '', '> ', $member_group['name'], '</label><br>';
2861
+	}
2757 2862
 
2758 2863
 	echo '
2759 2864
 								</span>
@@ -2813,9 +2918,10 @@  discard block
 block discarded – undo
2813 2918
 								<span class="smalltext">', $txt['sig_info'], '</span><br>
2814 2919
 								<br>';
2815 2920
 
2816
-	if ($context['show_spellchecking'])
2817
-		echo '
2921
+	if ($context['show_spellchecking']) {
2922
+			echo '
2818 2923
 								<input type="button" value="', $txt['spell_check'], '" onclick="spellCheck(\'creator\', \'signature\');" class="button">';
2924
+	}
2819 2925
 
2820 2926
 	echo '
2821 2927
 							</dt>
@@ -2823,17 +2929,20 @@  discard block
 block discarded – undo
2823 2929
 								<textarea class="editor" onkeyup="calcCharLeft();" id="signature" name="signature" rows="5" cols="50">', $context['member']['signature'], '</textarea><br>';
2824 2930
 
2825 2931
 	// If there is a limit at all!
2826
-	if (!empty($context['signature_limits']['max_length']))
2827
-		echo '
2932
+	if (!empty($context['signature_limits']['max_length'])) {
2933
+			echo '
2828 2934
 								<span class="smalltext">', sprintf($txt['max_sig_characters'], $context['signature_limits']['max_length']), ' <span id="signatureLeft">', $context['signature_limits']['max_length'], '</span></span><br>';
2935
+	}
2829 2936
 
2830
-	if (!empty($context['show_preview_button']))
2831
-		echo '
2937
+	if (!empty($context['show_preview_button'])) {
2938
+			echo '
2832 2939
 								<input type="button" name="preview_signature" id="preview_button" value="', $txt['preview_signature'], '" class="button floatright">';
2940
+	}
2833 2941
 
2834
-	if ($context['signature_warning'])
2835
-		echo '
2942
+	if ($context['signature_warning']) {
2943
+			echo '
2836 2944
 								<span class="smalltext">', $context['signature_warning'], '</span>';
2945
+	}
2837 2946
 
2838 2947
 	// Some javascript used to count how many characters have been used so far in the signature.
2839 2948
 	echo '
@@ -2878,9 +2987,10 @@  discard block
 block discarded – undo
2878 2987
 										<select name="cat" id="cat" size="10" onchange="changeSel(\'\');" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'server_stored\');">';
2879 2988
 
2880 2989
 		// This lists all the file categories.
2881
-		foreach ($context['avatars'] as $avatar)
2882
-			echo '
2990
+		foreach ($context['avatars'] as $avatar) {
2991
+					echo '
2883 2992
 											<option value="', $avatar['filename'] . ($avatar['is_dir'] ? '/' : ''), '"', ($avatar['checked'] ? ' selected' : ''), '>', $avatar['name'], '</option>';
2993
+		}
2884 2994
 
2885 2995
 		echo '
2886 2996
 										</select>
@@ -2912,20 +3022,22 @@  discard block
 block discarded – undo
2912 3022
 	}
2913 3023
 
2914 3024
 	// If the user can link to an off server avatar, show them a box to input the address.
2915
-	if (!empty($context['member']['avatar']['allow_external']))
2916
-		echo '
3025
+	if (!empty($context['member']['avatar']['allow_external'])) {
3026
+			echo '
2917 3027
 								<div id="avatar_external">
2918 3028
 									<div class="smalltext">', $txt['avatar_by_url'], '</div>', !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_download_and_resize' ? template_max_size('external') : '', '
2919 3029
 									<input type="text" name="userpicpersonal" size="45" value="', ((stristr($context['member']['avatar']['external'], 'http://') || stristr($context['member']['avatar']['external'], 'https://')) ? $context['member']['avatar']['external'] : 'http://'), '" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'external\');" onchange="if (typeof(previewExternalAvatar) != \'undefined\') previewExternalAvatar(this.value);">
2920 3030
 								</div>';
3031
+	}
2921 3032
 
2922 3033
 	// If the user is able to upload avatars to the server show them an upload box.
2923
-	if (!empty($context['member']['avatar']['allow_upload']))
2924
-		echo '
3034
+	if (!empty($context['member']['avatar']['allow_upload'])) {
3035
+			echo '
2925 3036
 								<div id="avatar_upload">
2926 3037
 									<input type="file" size="44" name="attachment" id="avatar_upload_box" value="" onchange="readfromUpload(this)"  onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'upload\');" accept="image/gif, image/jpeg, image/jpg, image/png">', template_max_size('upload'), '
2927 3038
 									', (!empty($context['member']['avatar']['id_attach']) ? '<br><img src="' . $context['member']['avatar']['href'] . (strpos($context['member']['avatar']['href'], '?') === false ? '?' : '&amp;') . 'time=' . time() . '" alt="" id="attached_image"><input type="hidden" name="id_attach" value="' . $context['member']['avatar']['id_attach'] . '">' : ''), '
2928 3039
 								</div>';
3040
+	}
2929 3041
 
2930 3042
 	// if the user is able to use Gravatar avatars show then the image preview
2931 3043
 	if (!empty($context['member']['avatar']['allow_gravatar']))
@@ -2934,16 +3046,17 @@  discard block
 block discarded – undo
2934 3046
 								<div id="avatar_gravatar">
2935 3047
 									<img src="' . $context['member']['avatar']['href'] . '" alt="">';
2936 3048
 
2937
-		if (empty($modSettings['gravatarAllowExtraEmail']))
2938
-			echo '
3049
+		if (empty($modSettings['gravatarAllowExtraEmail'])) {
3050
+					echo '
2939 3051
 									<div class="smalltext">', $txt['gravatar_noAlternateEmail'], '</div>';
2940
-		else
3052
+		} else
2941 3053
 		{
2942 3054
 			// Depending on other stuff, the stored value here might have some odd things in it from other areas.
2943
-			if ($context['member']['avatar']['external'] == $context['member']['email'])
2944
-				$textbox_value = '';
2945
-			else
2946
-				$textbox_value = $context['member']['avatar']['external'];
3055
+			if ($context['member']['avatar']['external'] == $context['member']['email']) {
3056
+							$textbox_value = '';
3057
+			} else {
3058
+							$textbox_value = $context['member']['avatar']['external'];
3059
+			}
2947 3060
 
2948 3061
 			echo '
2949 3062
 									<div class="smalltext">', $txt['gravatar_alternateEmail'], '</div>
@@ -3015,8 +3128,9 @@  discard block
 block discarded – undo
3015 3128
 	$h = !empty($modSettings['avatar_max_height_' . $type]) ? comma_format($modSettings['avatar_max_height_' . $type]) : 0;
3016 3129
 
3017 3130
 	$suffix = (!empty($w) ? 'w' : '') . (!empty($h) ? 'h' : '');
3018
-	if (empty($suffix))
3019
-		return;
3131
+	if (empty($suffix)) {
3132
+			return;
3133
+	}
3020 3134
 
3021 3135
 	echo '
3022 3136
 								<div class="smalltext">', sprintf($txt['avatar_max_size_' . $suffix], $w, $h), '</div>';
@@ -3041,9 +3155,10 @@  discard block
 block discarded – undo
3041 3155
 								<select name="easyformat" id="easyformat" onchange="document.forms.creator.time_format.value = this.options[this.selectedIndex].value;">';
3042 3156
 
3043 3157
 	// Help the user by showing a list of common time formats.
3044
-	foreach ($context['easy_timeformats'] as $time_format)
3045
-		echo '
3158
+	foreach ($context['easy_timeformats'] as $time_format) {
3159
+			echo '
3046 3160
 									<option value="', $time_format['format'], '"', $time_format['format'] == $context['member']['time_format'] ? ' selected' : '', '>', $time_format['title'], '</option>';
3161
+	}
3047 3162
 
3048 3163
 	echo '
3049 3164
 								</select>
@@ -3081,9 +3196,10 @@  discard block
 block discarded – undo
3081 3196
 							<dd>
3082 3197
 								<select name="smiley_set" id="smiley_set" onchange="document.getElementById(\'smileypr\').src = this.selectedIndex == 0 ? \'', $settings['images_url'], '/blank.png\' : \'', $modSettings['smileys_url'], '/\' + (this.selectedIndex != 1 ? this.options[this.selectedIndex].value : \'', !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'], '\') + \'/smiley.png\';">';
3083 3198
 
3084
-	foreach ($context['smiley_sets'] as $set)
3085
-		echo '
3199
+	foreach ($context['smiley_sets'] as $set) {
3200
+			echo '
3086 3201
 									<option value="', $set['id'], '"', $set['selected'] ? ' selected' : '', '>', $set['name'], '</option>';
3202
+	}
3087 3203
 
3088 3204
 	echo '
3089 3205
 								</select>
@@ -3135,10 +3251,11 @@  discard block
 block discarded – undo
3135 3251
 										<img src="', $context['tfa_qr_url'], '" alt="">
3136 3252
 									</div>';
3137 3253
 
3138
-	if (!empty($context['from_ajax']))
3139
-		echo '
3254
+	if (!empty($context['from_ajax'])) {
3255
+			echo '
3140 3256
 					<br>
3141 3257
 					<a href="javascript:self.close();"></a>';
3258
+	}
3142 3259
 
3143 3260
 	echo '
3144 3261
 				</div>
@@ -3178,17 +3295,16 @@  discard block
 block discarded – undo
3178 3295
 							</dt>
3179 3296
 							<dd>';
3180 3297
 
3181
-	if (!$context['tfa_enabled'] && $context['user']['is_owner'])
3182
-		echo '
3298
+	if (!$context['tfa_enabled'] && $context['user']['is_owner']) {
3299
+			echo '
3183 3300
 								<a href="', !empty($modSettings['force_ssl']) ? strtr($scripturl, array('http://' => 'https://')) : $scripturl, '?action=profile;area=tfasetup" id="enable_tfa">', $txt['tfa_profile_enable'], '</a>';
3184
-
3185
-	elseif (!$context['tfa_enabled'])
3186
-		echo '
3301
+	} elseif (!$context['tfa_enabled']) {
3302
+			echo '
3187 3303
 								', $txt['tfa_profile_disabled'];
3188
-
3189
-	else
3190
-		echo '
3304
+	} else {
3305
+			echo '
3191 3306
 								', sprintf($txt['tfa_profile_enabled'], $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=tfasetup;disable');
3307
+	}
3192 3308
 
3193 3309
 	echo '
3194 3310
 							</dd>';
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 1 patch
Braces   +703 added lines, -527 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This 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 = '1004-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '1004-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
112
+					}
113
+				} else {
114
+									$value = '1004-01-01';
110 115
 				}
111
-				else
112
-					$value = '1004-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]) : '1004-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '1004-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,26 +1238,29 @@  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 1260
 
1197
-			if ($row['field_length'])
1198
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1261
+			if ($row['field_length']) {
1262
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1263
+			}
1199 1264
 
1200 1265
 			// Any masks?
1201 1266
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
@@ -1204,36 +1269,34 @@  discard block
 block discarded – undo
1204 1269
 				$valueReference = un_htmlspecialchars($value);
1205 1270
 
1206 1271
 				// Try and avoid some checks. '0' could be a valid non-empty value.
1207
-				if (empty($value) && !is_numeric($value))
1208
-					$value = '';
1272
+				if (empty($value) && !is_numeric($value)) {
1273
+									$value = '';
1274
+				}
1209 1275
 
1210 1276
 				if ($row['mask'] == 'nohtml' && ($valueReference != strip_tags($valueReference) || $value != filter_var($value, FILTER_SANITIZE_STRING) || preg_match('/<(.+?)[\s]*\/?[\s]*>/si', $valueReference)))
1211 1277
 				{
1212
-					if ($returnErrors)
1213
-						$errors[] = 'custom_field_nohtml_fail';
1214
-
1215
-					else
1216
-						$value = '';
1217
-				}
1218
-				elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1278
+					if ($returnErrors) {
1279
+											$errors[] = 'custom_field_nohtml_fail';
1280
+					} else {
1281
+											$value = '';
1282
+					}
1283
+				} elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1219 1284
 				{
1220
-					if ($returnErrors)
1221
-						$errors[] = 'custom_field_mail_fail';
1222
-
1223
-					else
1224
-						$value = '';
1225
-				}
1226
-				elseif ($row['mask'] == 'number')
1285
+					if ($returnErrors) {
1286
+											$errors[] = 'custom_field_mail_fail';
1287
+					} else {
1288
+											$value = '';
1289
+					}
1290
+				} elseif ($row['mask'] == 'number')
1227 1291
 				{
1228 1292
 					$value = (int) $value;
1229
-				}
1230
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1293
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1231 1294
 				{
1232
-					if ($returnErrors)
1233
-						$errors[] = 'custom_field_regex_fail';
1234
-
1235
-					else
1236
-						$value = '';
1295
+					if ($returnErrors) {
1296
+											$errors[] = 'custom_field_regex_fail';
1297
+					} else {
1298
+											$value = '';
1299
+					}
1237 1300
 				}
1238 1301
 
1239 1302
 				unset($valueReference);
@@ -1261,8 +1324,9 @@  discard block
 block discarded – undo
1261 1324
 
1262 1325
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1263 1326
 
1264
-	if (!empty($hook_errors) && is_array($hook_errors))
1265
-		$errors = array_merge($errors, $hook_errors);
1327
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1328
+			$errors = array_merge($errors, $hook_errors);
1329
+	}
1266 1330
 
1267 1331
 	// Make those changes!
1268 1332
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1280,9 +1344,10 @@  discard block
 block discarded – undo
1280 1344
 		}
1281 1345
 	}
1282 1346
 
1283
-	if ($returnErrors)
1284
-		return $errors;
1285
-}
1347
+	if ($returnErrors) {
1348
+			return $errors;
1349
+	}
1350
+	}
1286 1351
 
1287 1352
 /**
1288 1353
  * Show all the users buddies, as well as a add/delete interface.
@@ -1294,8 +1359,9 @@  discard block
 block discarded – undo
1294 1359
 	global $context, $txt, $modSettings;
1295 1360
 
1296 1361
 	// Do a quick check to ensure people aren't getting here illegally!
1297
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1298
-		fatal_lang_error('no_access', false);
1362
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1363
+			fatal_lang_error('no_access', false);
1364
+	}
1299 1365
 
1300 1366
 	// Can we email the user direct?
1301 1367
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1325,9 +1391,10 @@  discard block
 block discarded – undo
1325 1391
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1326 1392
 	$call = call_helper($subActions[$context['list_area']][0], true);
1327 1393
 
1328
-	if (!empty($call))
1329
-		call_user_func($call, $memID);
1330
-}
1394
+	if (!empty($call)) {
1395
+			call_user_func($call, $memID);
1396
+	}
1397
+	}
1331 1398
 
1332 1399
 /**
1333 1400
  * Show all the users buddies, as well as a add/delete interface.
@@ -1341,9 +1408,10 @@  discard block
 block discarded – undo
1341 1408
 
1342 1409
 	// For making changes!
1343 1410
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1344
-	foreach ($buddiesArray as $k => $dummy)
1345
-		if ($dummy == '')
1411
+	foreach ($buddiesArray as $k => $dummy) {
1412
+			if ($dummy == '')
1346 1413
 			unset($buddiesArray[$k]);
1414
+	}
1347 1415
 
1348 1416
 	// Removing a buddy?
1349 1417
 	if (isset($_GET['remove']))
@@ -1355,10 +1423,11 @@  discard block
 block discarded – undo
1355 1423
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1356 1424
 
1357 1425
 		// Heh, I'm lazy, do it the easy way...
1358
-		foreach ($buddiesArray as $key => $buddy)
1359
-			if ($buddy == (int) $_GET['remove'])
1426
+		foreach ($buddiesArray as $key => $buddy) {
1427
+					if ($buddy == (int) $_GET['remove'])
1360 1428
 			{
1361 1429
 				unset($buddiesArray[$key]);
1430
+		}
1362 1431
 				$_SESSION['prf-save'] = true;
1363 1432
 			}
1364 1433
 
@@ -1368,8 +1437,7 @@  discard block
 block discarded – undo
1368 1437
 
1369 1438
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1370 1439
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1371
-	}
1372
-	elseif (isset($_POST['new_buddy']))
1440
+	} elseif (isset($_POST['new_buddy']))
1373 1441
 	{
1374 1442
 		checkSession();
1375 1443
 
@@ -1382,8 +1450,9 @@  discard block
 block discarded – undo
1382 1450
 		{
1383 1451
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1384 1452
 
1385
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1386
-				unset($new_buddies[$k]);
1453
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1454
+							unset($new_buddies[$k]);
1455
+			}
1387 1456
 		}
1388 1457
 
1389 1458
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1403,16 +1472,18 @@  discard block
 block discarded – undo
1403 1472
 				)
1404 1473
 			);
1405 1474
 
1406
-			if ($smcFunc['db_num_rows']($request) != 0)
1407
-				$_SESSION['prf-save'] = true;
1475
+			if ($smcFunc['db_num_rows']($request) != 0) {
1476
+							$_SESSION['prf-save'] = true;
1477
+			}
1408 1478
 
1409 1479
 			// Add the new member to the buddies array.
1410 1480
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1411 1481
 			{
1412
-				if (in_array($row['id_member'], $buddiesArray))
1413
-					continue;
1414
-				else
1415
-					$buddiesArray[] = (int) $row['id_member'];
1482
+				if (in_array($row['id_member'], $buddiesArray)) {
1483
+									continue;
1484
+				} else {
1485
+									$buddiesArray[] = (int) $row['id_member'];
1486
+				}
1416 1487
 			}
1417 1488
 			$smcFunc['db_free_result']($request);
1418 1489
 
@@ -1442,18 +1513,20 @@  discard block
 block discarded – undo
1442 1513
 
1443 1514
 	$context['custom_pf'] = array();
1444 1515
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1445
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1446
-		if (!isset($disabled_fields[$row['col_name']]))
1516
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1517
+			if (!isset($disabled_fields[$row['col_name']]))
1447 1518
 			$context['custom_pf'][$row['col_name']] = array(
1448 1519
 				'label' => $row['field_name'],
1449 1520
 				'type' => $row['field_type'],
1450 1521
 				'bbc' => !empty($row['bbc']),
1451 1522
 				'enclose' => $row['enclose'],
1452 1523
 			);
1524
+	}
1453 1525
 
1454 1526
 	// Gotta disable the gender option.
1455
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None')
1456
-		unset($context['custom_pf']['cust_gender']);
1527
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None') {
1528
+			unset($context['custom_pf']['cust_gender']);
1529
+	}
1457 1530
 
1458 1531
 	$smcFunc['db_free_result']($request);
1459 1532
 
@@ -1470,8 +1543,9 @@  discard block
 block discarded – undo
1470 1543
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1471 1544
 			)
1472 1545
 		);
1473
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1474
-			$buddies[] = $row['id_member'];
1546
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1547
+					$buddies[] = $row['id_member'];
1548
+		}
1475 1549
 		$smcFunc['db_free_result']($result);
1476 1550
 	}
1477 1551
 
@@ -1499,30 +1573,32 @@  discard block
 block discarded – undo
1499 1573
 					continue;
1500 1574
 				}
1501 1575
 
1502
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1503
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1504
-
1505
-				elseif ($column['type'] == 'check')
1506
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1576
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1577
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1578
+				} elseif ($column['type'] == 'check') {
1579
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1580
+				}
1507 1581
 
1508 1582
 				// Enclosing the user input within some other text?
1509
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1510
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1583
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1584
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1511 1585
 						'{SCRIPTURL}' => $scripturl,
1512 1586
 						'{IMAGES_URL}' => $settings['images_url'],
1513 1587
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1514 1588
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1515 1589
 					));
1590
+				}
1516 1591
 			}
1517 1592
 		}
1518 1593
 	}
1519 1594
 
1520 1595
 	if (isset($_SESSION['prf-save']))
1521 1596
 	{
1522
-		if ($_SESSION['prf-save'] === true)
1523
-			$context['saved_successful'] = true;
1524
-		else
1525
-			$context['saved_failed'] = $_SESSION['prf-save'];
1597
+		if ($_SESSION['prf-save'] === true) {
1598
+					$context['saved_successful'] = true;
1599
+		} else {
1600
+					$context['saved_failed'] = $_SESSION['prf-save'];
1601
+		}
1526 1602
 
1527 1603
 		unset($_SESSION['prf-save']);
1528 1604
 	}
@@ -1542,9 +1618,10 @@  discard block
 block discarded – undo
1542 1618
 
1543 1619
 	// For making changes!
1544 1620
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1545
-	foreach ($ignoreArray as $k => $dummy)
1546
-		if ($dummy == '')
1621
+	foreach ($ignoreArray as $k => $dummy) {
1622
+			if ($dummy == '')
1547 1623
 			unset($ignoreArray[$k]);
1624
+	}
1548 1625
 
1549 1626
 	// Removing a member from the ignore list?
1550 1627
 	if (isset($_GET['remove']))
@@ -1554,10 +1631,11 @@  discard block
 block discarded – undo
1554 1631
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1555 1632
 
1556 1633
 		// Heh, I'm lazy, do it the easy way...
1557
-		foreach ($ignoreArray as $key => $id_remove)
1558
-			if ($id_remove == (int) $_GET['remove'])
1634
+		foreach ($ignoreArray as $key => $id_remove) {
1635
+					if ($id_remove == (int) $_GET['remove'])
1559 1636
 			{
1560 1637
 				unset($ignoreArray[$key]);
1638
+		}
1561 1639
 				$_SESSION['prf-save'] = true;
1562 1640
 			}
1563 1641
 
@@ -1567,8 +1645,7 @@  discard block
 block discarded – undo
1567 1645
 
1568 1646
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1569 1647
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1570
-	}
1571
-	elseif (isset($_POST['new_ignore']))
1648
+	} elseif (isset($_POST['new_ignore']))
1572 1649
 	{
1573 1650
 		checkSession();
1574 1651
 		// Prepare the string for extraction...
@@ -1580,8 +1657,9 @@  discard block
 block discarded – undo
1580 1657
 		{
1581 1658
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1582 1659
 
1583
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1584
-				unset($new_entries[$k]);
1660
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1661
+							unset($new_entries[$k]);
1662
+			}
1585 1663
 		}
1586 1664
 
1587 1665
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1599,16 +1677,18 @@  discard block
 block discarded – undo
1599 1677
 				)
1600 1678
 			);
1601 1679
 
1602
-			if ($smcFunc['db_num_rows']($request) != 0)
1603
-				$_SESSION['prf-save'] = true;
1680
+			if ($smcFunc['db_num_rows']($request) != 0) {
1681
+							$_SESSION['prf-save'] = true;
1682
+			}
1604 1683
 
1605 1684
 			// Add the new member to the buddies array.
1606 1685
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1607 1686
 			{
1608
-				if (in_array($row['id_member'], $ignoreArray))
1609
-					continue;
1610
-				else
1611
-					$ignoreArray[] = (int) $row['id_member'];
1687
+				if (in_array($row['id_member'], $ignoreArray)) {
1688
+									continue;
1689
+				} else {
1690
+									$ignoreArray[] = (int) $row['id_member'];
1691
+				}
1612 1692
 			}
1613 1693
 			$smcFunc['db_free_result']($request);
1614 1694
 
@@ -1637,8 +1717,9 @@  discard block
 block discarded – undo
1637 1717
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1638 1718
 			)
1639 1719
 		);
1640
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1641
-			$ignored[] = $row['id_member'];
1720
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1721
+					$ignored[] = $row['id_member'];
1722
+		}
1642 1723
 		$smcFunc['db_free_result']($result);
1643 1724
 	}
1644 1725
 
@@ -1657,10 +1738,11 @@  discard block
 block discarded – undo
1657 1738
 
1658 1739
 	if (isset($_SESSION['prf-save']))
1659 1740
 	{
1660
-		if ($_SESSION['prf-save'] === true)
1661
-			$context['saved_successful'] = true;
1662
-		else
1663
-			$context['saved_failed'] = $_SESSION['prf-save'];
1741
+		if ($_SESSION['prf-save'] === true) {
1742
+					$context['saved_successful'] = true;
1743
+		} else {
1744
+					$context['saved_failed'] = $_SESSION['prf-save'];
1745
+		}
1664 1746
 
1665 1747
 		unset($_SESSION['prf-save']);
1666 1748
 	}
@@ -1676,8 +1758,9 @@  discard block
 block discarded – undo
1676 1758
 	global $context, $txt;
1677 1759
 
1678 1760
 	loadThemeOptions($memID);
1679
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1680
-		loadCustomFields($memID, 'account');
1761
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1762
+			loadCustomFields($memID, 'account');
1763
+	}
1681 1764
 
1682 1765
 	$context['sub_template'] = 'edit_options';
1683 1766
 	$context['page_desc'] = $txt['account_info'];
@@ -1704,8 +1787,9 @@  discard block
 block discarded – undo
1704 1787
 	global $context, $txt;
1705 1788
 
1706 1789
 	loadThemeOptions($memID);
1707
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1708
-		loadCustomFields($memID, 'forumprofile');
1790
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1791
+			loadCustomFields($memID, 'forumprofile');
1792
+	}
1709 1793
 
1710 1794
 	$context['sub_template'] = 'edit_options';
1711 1795
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1738,18 +1822,21 @@  discard block
 block discarded – undo
1738 1822
 	$dirs = array();
1739 1823
 	$files = array();
1740 1824
 
1741
-	if (!$dir)
1742
-		return array();
1825
+	if (!$dir) {
1826
+			return array();
1827
+	}
1743 1828
 
1744 1829
 	while ($line = $dir->read())
1745 1830
 	{
1746
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1747
-			continue;
1831
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1832
+					continue;
1833
+		}
1748 1834
 
1749
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1750
-			$dirs[] = $line;
1751
-		else
1752
-			$files[] = $line;
1835
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1836
+					$dirs[] = $line;
1837
+		} else {
1838
+					$files[] = $line;
1839
+		}
1753 1840
 	}
1754 1841
 	$dir->close();
1755 1842
 
@@ -1770,14 +1857,15 @@  discard block
 block discarded – undo
1770 1857
 	foreach ($dirs as $line)
1771 1858
 	{
1772 1859
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1773
-		if (!empty($tmp))
1774
-			$result[] = array(
1860
+		if (!empty($tmp)) {
1861
+					$result[] = array(
1775 1862
 				'filename' => $smcFunc['htmlspecialchars']($line),
1776 1863
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1777 1864
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1778 1865
 				'is_dir' => true,
1779 1866
 				'files' => $tmp
1780 1867
 		);
1868
+		}
1781 1869
 		unset($tmp);
1782 1870
 	}
1783 1871
 
@@ -1787,8 +1875,9 @@  discard block
 block discarded – undo
1787 1875
 		$extension = substr(strrchr($line, '.'), 1);
1788 1876
 
1789 1877
 		// Make sure it is an image.
1790
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1791
-			continue;
1878
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1879
+					continue;
1880
+		}
1792 1881
 
1793 1882
 		$result[] = array(
1794 1883
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1796,8 +1885,9 @@  discard block
 block discarded – undo
1796 1885
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1797 1886
 			'is_dir' => false
1798 1887
 		);
1799
-		if ($level == 1)
1800
-			$context['avatar_list'][] = $directory . '/' . $line;
1888
+		if ($level == 1) {
1889
+					$context['avatar_list'][] = $directory . '/' . $line;
1890
+		}
1801 1891
 	}
1802 1892
 
1803 1893
 	return $result;
@@ -1819,8 +1909,9 @@  discard block
 block discarded – undo
1819 1909
 	call_integration_hook('integrate_theme_options');
1820 1910
 
1821 1911
 	loadThemeOptions($memID);
1822
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1823
-		loadCustomFields($memID, 'theme');
1912
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1913
+			loadCustomFields($memID, 'theme');
1914
+	}
1824 1915
 
1825 1916
 	$context['sub_template'] = 'edit_options';
1826 1917
 	$context['page_desc'] = $txt['theme_info'];
@@ -1874,16 +1965,19 @@  discard block
 block discarded – undo
1874 1965
 {
1875 1966
 	global $txt, $context, $modSettings, $smcFunc, $sourcedir;
1876 1967
 
1877
-	if (!isset($context['token_check']))
1878
-		$context['token_check'] = 'profile-nt' . $memID;
1968
+	if (!isset($context['token_check'])) {
1969
+			$context['token_check'] = 'profile-nt' . $memID;
1970
+	}
1879 1971
 
1880 1972
 	is_not_guest();
1881
-	if (!$context['user']['is_owner'])
1882
-		isAllowedTo('profile_extra_any');
1973
+	if (!$context['user']['is_owner']) {
1974
+			isAllowedTo('profile_extra_any');
1975
+	}
1883 1976
 
1884 1977
 	// Set the post action if we're coming from the profile...
1885
-	if (!isset($context['action']))
1886
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1978
+	if (!isset($context['action'])) {
1979
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1980
+	}
1887 1981
 
1888 1982
 	// What options are set
1889 1983
 	loadThemeOptions($memID);
@@ -1970,28 +2064,34 @@  discard block
 block discarded – undo
1970 2064
 	);
1971 2065
 
1972 2066
 	// There are certain things that are disabled at the group level.
1973
-	if (empty($modSettings['cal_enabled']))
1974
-		unset($alert_types['calendar']);
2067
+	if (empty($modSettings['cal_enabled'])) {
2068
+			unset($alert_types['calendar']);
2069
+	}
1975 2070
 
1976 2071
 	// Disable paid subscriptions at group level if they're disabled
1977
-	if (empty($modSettings['paid_enabled']))
1978
-		unset($alert_types['paidsubs']);
2072
+	if (empty($modSettings['paid_enabled'])) {
2073
+			unset($alert_types['paidsubs']);
2074
+	}
1979 2075
 
1980 2076
 	// Disable membergroup requests at group level if they're disabled
1981
-	if (empty($modSettings['show_group_membership']))
1982
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2077
+	if (empty($modSettings['show_group_membership'])) {
2078
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2079
+	}
1983 2080
 
1984 2081
 	// Disable mentions if they're disabled
1985
-	if (empty($modSettings['enable_mentions']))
1986
-		unset($alert_types['msg']['msg_mention']);
2082
+	if (empty($modSettings['enable_mentions'])) {
2083
+			unset($alert_types['msg']['msg_mention']);
2084
+	}
1987 2085
 
1988 2086
 	// Disable likes if they're disabled
1989
-	if (empty($modSettings['enable_likes']))
1990
-		unset($alert_types['msg']['msg_like']);
2087
+	if (empty($modSettings['enable_likes'])) {
2088
+			unset($alert_types['msg']['msg_like']);
2089
+	}
1991 2090
 
1992 2091
 	// Disable buddy requests if they're disabled
1993
-	if (empty($modSettings['enable_buddylist']))
1994
-		unset($alert_types['members']['buddy_request']);
2092
+	if (empty($modSettings['enable_buddylist'])) {
2093
+			unset($alert_types['members']['buddy_request']);
2094
+	}
1995 2095
 
1996 2096
 	// Now, now, we could pass this through global but we should really get into the habit of
1997 2097
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -2019,15 +2119,17 @@  discard block
 block discarded – undo
2019 2119
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
2020 2120
 		}
2021 2121
 
2022
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2023
-			unset($alert_types['members']['request_group']);
2122
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2123
+					unset($alert_types['members']['request_group']);
2124
+		}
2024 2125
 
2025 2126
 		foreach ($alert_types as $group => $items)
2026 2127
 		{
2027 2128
 			foreach ($items as $alert_key => $alert_value)
2028 2129
 			{
2029
-				if (!isset($alert_value['permission']))
2030
-					continue;
2130
+				if (!isset($alert_value['permission'])) {
2131
+									continue;
2132
+				}
2031 2133
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2032 2134
 				{
2033 2135
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2035,12 +2137,14 @@  discard block
 block discarded – undo
2035 2137
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2036 2138
 				}
2037 2139
 
2038
-				if (!$perms_cache[$alert_value['permission']['name']])
2039
-					unset ($alert_types[$group][$alert_key]);
2140
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2141
+									unset ($alert_types[$group][$alert_key]);
2142
+				}
2040 2143
 			}
2041 2144
 
2042
-			if (empty($alert_types[$group]))
2043
-				unset ($alert_types[$group]);
2145
+			if (empty($alert_types[$group])) {
2146
+							unset ($alert_types[$group]);
2147
+			}
2044 2148
 		}
2045 2149
 	}
2046 2150
 
@@ -2072,9 +2176,9 @@  discard block
 block discarded – undo
2072 2176
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2073 2177
 						break;
2074 2178
 					case 'select':
2075
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2076
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2077
-						else
2179
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2180
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2181
+						} else
2078 2182
 						{
2079 2183
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2080 2184
 							$keys = array_keys($this_option['opts']);
@@ -2094,23 +2198,28 @@  discard block
 block discarded – undo
2094 2198
 				$this_value = 0;
2095 2199
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2096 2200
 				{
2097
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2098
-						$this_value |= $bitvalue;
2201
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2202
+											$this_value |= $bitvalue;
2203
+					}
2204
+				}
2205
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2206
+									$update_prefs[$item_key] = $this_value;
2099 2207
 				}
2100
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2101
-					$update_prefs[$item_key] = $this_value;
2102 2208
 			}
2103 2209
 		}
2104 2210
 
2105
-		if (!empty($_POST['opt_alert_timeout']))
2106
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2211
+		if (!empty($_POST['opt_alert_timeout'])) {
2212
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2213
+		}
2107 2214
 
2108
-		if (!empty($_POST['notify_announcements']))
2109
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2215
+		if (!empty($_POST['notify_announcements'])) {
2216
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2217
+		}
2110 2218
 
2111 2219
 		setNotifyPrefs((int) $memID, $update_prefs);
2112
-		foreach ($update_prefs as $pref => $value)
2113
-			$context['alert_prefs'][$pref] = $value;
2220
+		foreach ($update_prefs as $pref => $value) {
2221
+					$context['alert_prefs'][$pref] = $value;
2222
+		}
2114 2223
 
2115 2224
 		makeNotificationChanges($memID);
2116 2225
 
@@ -2140,8 +2249,9 @@  discard block
 block discarded – undo
2140 2249
 
2141 2250
 	// Now we're all set up.
2142 2251
 	is_not_guest();
2143
-	if (!$context['user']['is_owner'])
2144
-		fatal_error('no_access');
2252
+	if (!$context['user']['is_owner']) {
2253
+			fatal_error('no_access');
2254
+	}
2145 2255
 
2146 2256
 	checkSession('get');
2147 2257
 
@@ -2173,8 +2283,9 @@  discard block
 block discarded – undo
2173 2283
 {
2174 2284
 	global $smcFunc;
2175 2285
 
2176
-	if (empty($toMark) || empty($memID))
2177
-		return false;
2286
+	if (empty($toMark) || empty($memID)) {
2287
+			return false;
2288
+	}
2178 2289
 
2179 2290
 	$toMark = (array) $toMark;
2180 2291
 
@@ -2208,8 +2319,9 @@  discard block
 block discarded – undo
2208 2319
 {
2209 2320
 	global $smcFunc;
2210 2321
 
2211
-	if (empty($toDelete))
2212
-		return false;
2322
+	if (empty($toDelete)) {
2323
+			return false;
2324
+	}
2213 2325
 
2214 2326
 	$toDelete = (array) $toDelete;
2215 2327
 
@@ -2244,8 +2356,9 @@  discard block
 block discarded – undo
2244 2356
 {
2245 2357
 	global $smcFunc;
2246 2358
 
2247
-	if (empty($memID))
2248
-		return false;
2359
+	if (empty($memID)) {
2360
+			return false;
2361
+	}
2249 2362
 
2250 2363
 	$request = $smcFunc['db_query']('', '
2251 2364
 		SELECT id_alert
@@ -2322,8 +2435,9 @@  discard block
 block discarded – undo
2322 2435
 					{
2323 2436
 						$link = $topic['link'];
2324 2437
 
2325
-						if ($topic['new'])
2326
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2438
+						if ($topic['new']) {
2439
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2440
+						}
2327 2441
 
2328 2442
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2329 2443
 
@@ -2474,8 +2588,9 @@  discard block
 block discarded – undo
2474 2588
 					{
2475 2589
 						$link = $board['link'];
2476 2590
 
2477
-						if ($board['new'])
2478
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2591
+						if ($board['new']) {
2592
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2593
+						}
2479 2594
 
2480 2595
 						return $link;
2481 2596
 					},
@@ -2675,8 +2790,8 @@  discard block
 block discarded – undo
2675 2790
 		)
2676 2791
 	);
2677 2792
 	$notification_boards = array();
2678
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2679
-		$notification_boards[] = array(
2793
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2794
+			$notification_boards[] = array(
2680 2795
 			'id' => $row['id_board'],
2681 2796
 			'name' => $row['name'],
2682 2797
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2684,6 +2799,7 @@  discard block
 block discarded – undo
2684 2799
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2685 2800
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2686 2801
 		);
2802
+	}
2687 2803
 	$smcFunc['db_free_result']($request);
2688 2804
 
2689 2805
 	return $notification_boards;
@@ -2698,17 +2814,18 @@  discard block
 block discarded – undo
2698 2814
 {
2699 2815
 	global $context, $options, $cur_profile, $smcFunc;
2700 2816
 
2701
-	if (isset($_POST['default_options']))
2702
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2817
+	if (isset($_POST['default_options'])) {
2818
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2819
+	}
2703 2820
 
2704 2821
 	if ($context['user']['is_owner'])
2705 2822
 	{
2706 2823
 		$context['member']['options'] = $options;
2707
-		if (isset($_POST['options']) && is_array($_POST['options']))
2708
-			foreach ($_POST['options'] as $k => $v)
2824
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2825
+					foreach ($_POST['options'] as $k => $v)
2709 2826
 				$context['member']['options'][$k] = $v;
2710
-	}
2711
-	else
2827
+		}
2828
+	} else
2712 2829
 	{
2713 2830
 		$request = $smcFunc['db_query']('', '
2714 2831
 			SELECT id_member, variable, value
@@ -2729,8 +2846,9 @@  discard block
 block discarded – undo
2729 2846
 				continue;
2730 2847
 			}
2731 2848
 
2732
-			if (isset($_POST['options'][$row['variable']]))
2733
-				$row['value'] = $_POST['options'][$row['variable']];
2849
+			if (isset($_POST['options'][$row['variable']])) {
2850
+							$row['value'] = $_POST['options'][$row['variable']];
2851
+			}
2734 2852
 			$context['member']['options'][$row['variable']] = $row['value'];
2735 2853
 		}
2736 2854
 		$smcFunc['db_free_result']($request);
@@ -2738,8 +2856,9 @@  discard block
 block discarded – undo
2738 2856
 		// Load up the default theme options for any missing.
2739 2857
 		foreach ($temp as $k => $v)
2740 2858
 		{
2741
-			if (!isset($context['member']['options'][$k]))
2742
-				$context['member']['options'][$k] = $v;
2859
+			if (!isset($context['member']['options'][$k])) {
2860
+							$context['member']['options'][$k] = $v;
2861
+			}
2743 2862
 		}
2744 2863
 	}
2745 2864
 }
@@ -2754,8 +2873,9 @@  discard block
 block discarded – undo
2754 2873
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2755 2874
 
2756 2875
 	// Have the admins enabled this option?
2757
-	if (empty($modSettings['allow_ignore_boards']))
2758
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2876
+	if (empty($modSettings['allow_ignore_boards'])) {
2877
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2878
+	}
2759 2879
 
2760 2880
 	// Find all the boards this user is allowed to see.
2761 2881
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2775,12 +2895,13 @@  discard block
 block discarded – undo
2775 2895
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2776 2896
 	{
2777 2897
 		// This category hasn't been set up yet..
2778
-		if (!isset($context['categories'][$row['id_cat']]))
2779
-			$context['categories'][$row['id_cat']] = array(
2898
+		if (!isset($context['categories'][$row['id_cat']])) {
2899
+					$context['categories'][$row['id_cat']] = array(
2780 2900
 				'id' => $row['id_cat'],
2781 2901
 				'name' => $row['cat_name'],
2782 2902
 				'boards' => array()
2783 2903
 			);
2904
+		}
2784 2905
 
2785 2906
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2786 2907
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2810,18 +2931,20 @@  discard block
 block discarded – undo
2810 2931
 	}
2811 2932
 
2812 2933
 	$max_boards = ceil(count($temp_boards) / 2);
2813
-	if ($max_boards == 1)
2814
-		$max_boards = 2;
2934
+	if ($max_boards == 1) {
2935
+			$max_boards = 2;
2936
+	}
2815 2937
 
2816 2938
 	// Now, alternate them so they can be shown left and right ;).
2817 2939
 	$context['board_columns'] = array();
2818 2940
 	for ($i = 0; $i < $max_boards; $i++)
2819 2941
 	{
2820 2942
 		$context['board_columns'][] = $temp_boards[$i];
2821
-		if (isset($temp_boards[$i + $max_boards]))
2822
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2823
-		else
2824
-			$context['board_columns'][] = array();
2943
+		if (isset($temp_boards[$i + $max_boards])) {
2944
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2945
+		} else {
2946
+					$context['board_columns'][] = array();
2947
+		}
2825 2948
 	}
2826 2949
 
2827 2950
 	loadThemeOptions($memID);
@@ -2890,8 +3013,9 @@  discard block
 block discarded – undo
2890 3013
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2891 3014
 	{
2892 3015
 		// We should skip the administrator group if they don't have the admin_forum permission!
2893
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2894
-			continue;
3016
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
3017
+					continue;
3018
+		}
2895 3019
 
2896 3020
 		$context['member_groups'][$row['id_group']] = array(
2897 3021
 			'id' => $row['id_group'],
@@ -2937,16 +3061,17 @@  discard block
 block discarded – undo
2937 3061
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2938 3062
 	// Warning message for signature image limits?
2939 3063
 	$context['signature_warning'] = '';
2940
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2941
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2942
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2943
-		$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']);
3064
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3065
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3066
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3067
+			$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']);
3068
+	}
2944 3069
 
2945 3070
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2946 3071
 
2947
-	if (empty($context['do_preview']))
2948
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2949
-	else
3072
+	if (empty($context['do_preview'])) {
3073
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3074
+	} else
2950 3075
 	{
2951 3076
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2952 3077
 		$validation = profileValidateSignature($signature);
@@ -2956,8 +3081,9 @@  discard block
 block discarded – undo
2956 3081
 			$context['post_errors'] = array();
2957 3082
 		}
2958 3083
 		$context['post_errors'][] = 'signature_not_yet_saved';
2959
-		if ($validation !== true && $validation !== false)
2960
-			$context['post_errors'][] = $validation;
3084
+		if ($validation !== true && $validation !== false) {
3085
+					$context['post_errors'][] = $validation;
3086
+		}
2961 3087
 
2962 3088
 		censorText($context['member']['signature']);
2963 3089
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2967,8 +3093,9 @@  discard block
 block discarded – undo
2967 3093
 	}
2968 3094
 
2969 3095
 	// Load the spell checker?
2970
-	if ($context['show_spellchecking'])
2971
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3096
+	if ($context['show_spellchecking']) {
3097
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3098
+	}
2972 3099
 
2973 3100
 	return true;
2974 3101
 }
@@ -3002,8 +3129,7 @@  discard block
 block discarded – undo
3002 3129
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
3003 3130
 		);
3004 3131
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
3005
-	}
3006
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3132
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3007 3133
 	{
3008 3134
 		$context['member']['avatar'] += array(
3009 3135
 			'choice' => 'upload',
@@ -3013,33 +3139,34 @@  discard block
 block discarded – undo
3013 3139
 		$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'];
3014 3140
 	}
3015 3141
 	// Use "avatar_original" here so we show what the user entered even if the image proxy is enabled
3016
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
3017
-		$context['member']['avatar'] += array(
3142
+	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3143
+			$context['member']['avatar'] += array(
3018 3144
 			'choice' => 'external',
3019 3145
 			'server_pic' => 'blank.png',
3020 3146
 			'external' => $cur_profile['avatar_original']
3021 3147
 		);
3022
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3023
-		$context['member']['avatar'] += array(
3148
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3149
+			$context['member']['avatar'] += array(
3024 3150
 			'choice' => 'server_stored',
3025 3151
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3026 3152
 			'external' => 'http://'
3027 3153
 		);
3028
-	else
3029
-		$context['member']['avatar'] += array(
3154
+	} else {
3155
+			$context['member']['avatar'] += array(
3030 3156
 			'choice' => 'none',
3031 3157
 			'server_pic' => 'blank.png',
3032 3158
 			'external' => 'http://'
3033 3159
 		);
3160
+	}
3034 3161
 
3035 3162
 	// Get a list of all the avatars.
3036 3163
 	if ($context['member']['avatar']['allow_server_stored'])
3037 3164
 	{
3038 3165
 		$context['avatar_list'] = array();
3039 3166
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3167
+	} else {
3168
+			$context['avatars'] = array();
3040 3169
 	}
3041
-	else
3042
-		$context['avatars'] = array();
3043 3170
 
3044 3171
 	// Second level selected avatar...
3045 3172
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3068,19 +3195,22 @@  discard block
 block discarded – undo
3068 3195
 			)
3069 3196
 		);
3070 3197
 		$protected_groups = array(1);
3071
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3072
-			$protected_groups[] = $row['id_group'];
3198
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3199
+					$protected_groups[] = $row['id_group'];
3200
+		}
3073 3201
 		$smcFunc['db_free_result']($request);
3074 3202
 
3075 3203
 		$protected_groups = array_unique($protected_groups);
3076 3204
 	}
3077 3205
 
3078 3206
 	// The account page allows the change of your id_group - but not to a protected group!
3079
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3080
-		$value = (int) $value;
3207
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3208
+			$value = (int) $value;
3209
+	}
3081 3210
 	// ... otherwise it's the old group sir.
3082
-	else
3083
-		$value = $old_profile['id_group'];
3211
+	else {
3212
+			$value = $old_profile['id_group'];
3213
+	}
3084 3214
 
3085 3215
 	// Find the additional membergroups (if any)
3086 3216
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3089,16 +3219,18 @@  discard block
 block discarded – undo
3089 3219
 		foreach ($_POST['additional_groups'] as $group_id)
3090 3220
 		{
3091 3221
 			$group_id = (int) $group_id;
3092
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3093
-				$additional_groups[] = $group_id;
3222
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3223
+							$additional_groups[] = $group_id;
3224
+			}
3094 3225
 		}
3095 3226
 
3096 3227
 		// Put the protected groups back in there if you don't have permission to take them away.
3097 3228
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3098 3229
 		foreach ($old_additional_groups as $group_id)
3099 3230
 		{
3100
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3101
-				$additional_groups[] = $group_id;
3231
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3232
+							$additional_groups[] = $group_id;
3233
+			}
3102 3234
 		}
3103 3235
 
3104 3236
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3130,18 +3262,20 @@  discard block
 block discarded – undo
3130 3262
 			list ($another) = $smcFunc['db_fetch_row']($request);
3131 3263
 			$smcFunc['db_free_result']($request);
3132 3264
 
3133
-			if (empty($another))
3134
-				fatal_lang_error('at_least_one_admin', 'critical');
3265
+			if (empty($another)) {
3266
+							fatal_lang_error('at_least_one_admin', 'critical');
3267
+			}
3135 3268
 		}
3136 3269
 	}
3137 3270
 
3138 3271
 	// If we are changing group status, update permission cache as necessary.
3139 3272
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3140 3273
 	{
3141
-		if ($context['user']['is_owner'])
3142
-			$_SESSION['mc']['time'] = 0;
3143
-		else
3144
-			updateSettings(array('settings_updated' => time()));
3274
+		if ($context['user']['is_owner']) {
3275
+					$_SESSION['mc']['time'] = 0;
3276
+		} else {
3277
+					updateSettings(array('settings_updated' => time()));
3278
+		}
3145 3279
 	}
3146 3280
 
3147 3281
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3162,8 +3296,9 @@  discard block
 block discarded – undo
3162 3296
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3163 3297
 
3164 3298
 	$memID = $context['id_member'];
3165
-	if (empty($memID) && !empty($context['password_auth_failed']))
3166
-		return false;
3299
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3300
+			return false;
3301
+	}
3167 3302
 
3168 3303
 	require_once($sourcedir . '/ManageAttachments.php');
3169 3304
 
@@ -3174,8 +3309,9 @@  discard block
 block discarded – undo
3174 3309
 	$downloadedExternalAvatar = false;
3175 3310
 	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']))
3176 3311
 	{
3177
-		if (!is_writable($uploadDir))
3178
-			fatal_lang_error('attachments_no_write', 'critical');
3312
+		if (!is_writable($uploadDir)) {
3313
+					fatal_lang_error('attachments_no_write', 'critical');
3314
+		}
3179 3315
 
3180 3316
 		require_once($sourcedir . '/Subs-Package.php');
3181 3317
 
@@ -3219,19 +3355,18 @@  discard block
 block discarded – undo
3219 3355
 
3220 3356
 		// Get rid of their old avatar. (if uploaded.)
3221 3357
 		removeAttachments(array('id_member' => $memID));
3222
-	}
3223
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3358
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3224 3359
 	{
3225 3360
 		// 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.
3226
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3227
-			$profile_vars['avatar'] = 'gravatar://';
3228
-		else
3229
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3361
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3362
+					$profile_vars['avatar'] = 'gravatar://';
3363
+		} else {
3364
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3365
+		}
3230 3366
 
3231 3367
 		// Get rid of their old avatar. (if uploaded.)
3232 3368
 		removeAttachments(array('id_member' => $memID));
3233
-	}
3234
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3369
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3235 3370
 	{
3236 3371
 		// We need these clean...
3237 3372
 		$cur_profile['id_attach'] = 0;
@@ -3243,11 +3378,13 @@  discard block
 block discarded – undo
3243 3378
 
3244 3379
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3245 3380
 
3246
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3247
-			$profile_vars['avatar'] = '';
3381
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3382
+					$profile_vars['avatar'] = '';
3383
+		}
3248 3384
 		// Trying to make us do something we'll regret?
3249
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3250
-			return 'bad_avatar_invalid_url';
3385
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3386
+					return 'bad_avatar_invalid_url';
3387
+		}
3251 3388
 		// Should we check dimensions?
3252 3389
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3253 3390
 		{
@@ -3257,9 +3394,9 @@  discard block
 block discarded – undo
3257 3394
 			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']))))
3258 3395
 			{
3259 3396
 				// Houston, we have a problem. The avatar is too large!!
3260
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3261
-					return 'bad_avatar_too_large';
3262
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3397
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3398
+									return 'bad_avatar_too_large';
3399
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3263 3400
 				{
3264 3401
 					// @todo remove this if appropriate
3265 3402
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3269,26 +3406,27 @@  discard block
 block discarded – undo
3269 3406
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3270 3407
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3271 3408
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3409
+					} else {
3410
+											return 'bad_avatar';
3272 3411
 					}
3273
-					else
3274
-						return 'bad_avatar';
3275 3412
 				}
3276 3413
 			}
3277 3414
 		}
3278
-	}
3279
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3415
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3280 3416
 	{
3281 3417
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3282 3418
 		{
3283 3419
 			// Get the dimensions of the image.
3284 3420
 			if (!$downloadedExternalAvatar)
3285 3421
 			{
3286
-				if (!is_writable($uploadDir))
3287
-					fatal_lang_error('attachments_no_write', 'critical');
3422
+				if (!is_writable($uploadDir)) {
3423
+									fatal_lang_error('attachments_no_write', 'critical');
3424
+				}
3288 3425
 
3289 3426
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3290
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3291
-					fatal_lang_error('attach_timeout', 'critical');
3427
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3428
+									fatal_lang_error('attach_timeout', 'critical');
3429
+				}
3292 3430
 
3293 3431
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3294 3432
 			}
@@ -3401,17 +3539,19 @@  discard block
 block discarded – undo
3401 3539
 			$profile_vars['avatar'] = '';
3402 3540
 
3403 3541
 			// Delete any temporary file.
3404
-			if (file_exists($_FILES['attachment']['tmp_name']))
3405
-				@unlink($_FILES['attachment']['tmp_name']);
3542
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3543
+							@unlink($_FILES['attachment']['tmp_name']);
3544
+			}
3406 3545
 		}
3407 3546
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3408
-		else
3547
+		else {
3548
+					$profile_vars['avatar'] = '';
3549
+		}
3550
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3551
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3552
+	} else {
3409 3553
 			$profile_vars['avatar'] = '';
3410 3554
 	}
3411
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3412
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3413
-	else
3414
-		$profile_vars['avatar'] = '';
3415 3555
 
3416 3556
 	// Setup the profile variables so it shows things right on display!
3417 3557
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3459,9 +3599,9 @@  discard block
 block discarded – undo
3459 3599
 		$smiley_parsed = $unparsed_signature;
3460 3600
 		parsesmileys($smiley_parsed);
3461 3601
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3462
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3463
-			return 'signature_allow_smileys';
3464
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3602
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3603
+					return 'signature_allow_smileys';
3604
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3465 3605
 		{
3466 3606
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3467 3607
 			return 'signature_max_smileys';
@@ -3474,14 +3614,15 @@  discard block
 block discarded – undo
3474 3614
 			{
3475 3615
 				$limit_broke = 0;
3476 3616
 				// Attempt to allow all sizes of abuse, so to speak.
3477
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3478
-					$limit_broke = $sig_limits[7] . 'px';
3479
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3480
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3481
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3482
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3483
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3484
-					$limit_broke = 'large';
3617
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3618
+									$limit_broke = $sig_limits[7] . 'px';
3619
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3620
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3621
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3622
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3623
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3624
+									$limit_broke = 'large';
3625
+				}
3485 3626
 
3486 3627
 				if ($limit_broke)
3487 3628
 				{
@@ -3523,24 +3664,26 @@  discard block
 block discarded – undo
3523 3664
 					$width = -1; $height = -1;
3524 3665
 
3525 3666
 					// Does it have predefined restraints? Width first.
3526
-					if ($matches[6][$key])
3527
-						$matches[2][$key] = $matches[6][$key];
3667
+					if ($matches[6][$key]) {
3668
+											$matches[2][$key] = $matches[6][$key];
3669
+					}
3528 3670
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3529 3671
 					{
3530 3672
 						$width = $sig_limits[5];
3531 3673
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3674
+					} elseif ($matches[2][$key]) {
3675
+											$width = $matches[2][$key];
3532 3676
 					}
3533
-					elseif ($matches[2][$key])
3534
-						$width = $matches[2][$key];
3535 3677
 					// ... and height.
3536 3678
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3537 3679
 					{
3538 3680
 						$height = $sig_limits[6];
3539
-						if ($width != -1)
3540
-							$width = $width * ($height / $matches[4][$key]);
3681
+						if ($width != -1) {
3682
+													$width = $width * ($height / $matches[4][$key]);
3683
+						}
3684
+					} elseif ($matches[4][$key]) {
3685
+											$height = $matches[4][$key];
3541 3686
 					}
3542
-					elseif ($matches[4][$key])
3543
-						$height = $matches[4][$key];
3544 3687
 
3545 3688
 					// If the dimensions are still not fixed - we need to check the actual image.
3546 3689
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3558,21 +3701,24 @@  discard block
 block discarded – undo
3558 3701
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3559 3702
 							{
3560 3703
 								$height = $sig_limits[6];
3561
-								if ($width == -1)
3562
-									$width = $sizes[0];
3704
+								if ($width == -1) {
3705
+																	$width = $sizes[0];
3706
+								}
3563 3707
 								$width = $width * ($height / $sizes[1]);
3708
+							} elseif ($width != -1) {
3709
+															$height = $sizes[1];
3564 3710
 							}
3565
-							elseif ($width != -1)
3566
-								$height = $sizes[1];
3567 3711
 						}
3568 3712
 					}
3569 3713
 
3570 3714
 					// Did we come up with some changes? If so remake the string.
3571
-					if ($width != -1 || $height != -1)
3572
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3715
+					if ($width != -1 || $height != -1) {
3716
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3717
+					}
3718
+				}
3719
+				if (!empty($replaces)) {
3720
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3573 3721
 				}
3574
-				if (!empty($replaces))
3575
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3576 3722
 			}
3577 3723
 		}
3578 3724
 
@@ -3616,10 +3762,12 @@  discard block
 block discarded – undo
3616 3762
 	$email = strtr($email, array('&#039;' => '\''));
3617 3763
 
3618 3764
 	// Check the name and email for validity.
3619
-	if (trim($email) == '')
3620
-		return 'no_email';
3621
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3622
-		return 'bad_email';
3765
+	if (trim($email) == '') {
3766
+			return 'no_email';
3767
+	}
3768
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3769
+			return 'bad_email';
3770
+	}
3623 3771
 
3624 3772
 	// Email addresses should be and stay unique.
3625 3773
 	$request = $smcFunc['db_query']('', '
@@ -3634,8 +3782,9 @@  discard block
 block discarded – undo
3634 3782
 		)
3635 3783
 	);
3636 3784
 
3637
-	if ($smcFunc['db_num_rows']($request) > 0)
3638
-		return 'email_taken';
3785
+	if ($smcFunc['db_num_rows']($request) > 0) {
3786
+			return 'email_taken';
3787
+	}
3639 3788
 	$smcFunc['db_free_result']($request);
3640 3789
 
3641 3790
 	return true;
@@ -3648,8 +3797,9 @@  discard block
 block discarded – undo
3648 3797
 {
3649 3798
 	global $modSettings, $context, $cur_profile;
3650 3799
 
3651
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3652
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3800
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3801
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3802
+	}
3653 3803
 
3654 3804
 	loadUserSettings();
3655 3805
 	writeLog();
@@ -3665,8 +3815,9 @@  discard block
 block discarded – undo
3665 3815
 	require_once($sourcedir . '/Subs-Post.php');
3666 3816
 
3667 3817
 	// Shouldn't happen but just in case.
3668
-	if (empty($profile_vars['email_address']))
3669
-		return;
3818
+	if (empty($profile_vars['email_address'])) {
3819
+			return;
3820
+	}
3670 3821
 
3671 3822
 	$replacements = array(
3672 3823
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3689,8 +3840,9 @@  discard block
 block discarded – undo
3689 3840
 	$_SESSION['log_time'] = 0;
3690 3841
 	$_SESSION['login_' . $cookiename] = $smcFunc['json_encode'](array(0, '', 0));
3691 3842
 
3692
-	if (isset($_COOKIE[$cookiename]))
3693
-		$_COOKIE[$cookiename] = '';
3843
+	if (isset($_COOKIE[$cookiename])) {
3844
+			$_COOKIE[$cookiename] = '';
3845
+	}
3694 3846
 
3695 3847
 	loadUserSettings();
3696 3848
 
@@ -3723,11 +3875,13 @@  discard block
 block discarded – undo
3723 3875
 	$groups[] = $curMember['id_group'];
3724 3876
 
3725 3877
 	// Ensure the query doesn't croak!
3726
-	if (empty($groups))
3727
-		$groups = array(0);
3878
+	if (empty($groups)) {
3879
+			$groups = array(0);
3880
+	}
3728 3881
 	// Just to be sure...
3729
-	foreach ($groups as $k => $v)
3730
-		$groups[$k] = (int) $v;
3882
+	foreach ($groups as $k => $v) {
3883
+			$groups[$k] = (int) $v;
3884
+	}
3731 3885
 
3732 3886
 	// Get all the membergroups they can join.
3733 3887
 	$request = $smcFunc['db_query']('', '
@@ -3757,12 +3911,14 @@  discard block
 block discarded – undo
3757 3911
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3758 3912
 	{
3759 3913
 		// Can they edit their primary group?
3760
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3761
-			$context['can_edit_primary'] = true;
3914
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3915
+					$context['can_edit_primary'] = true;
3916
+		}
3762 3917
 
3763 3918
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3764
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3765
-			continue;
3919
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3920
+					continue;
3921
+		}
3766 3922
 
3767 3923
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3768 3924
 			'id' => $row['id_group'],
@@ -3791,13 +3947,15 @@  discard block
 block discarded – undo
3791 3947
 	);
3792 3948
 
3793 3949
 	// No changing primary one unless you have enough groups!
3794
-	if (count($context['groups']['member']) < 2)
3795
-		$context['can_edit_primary'] = false;
3950
+	if (count($context['groups']['member']) < 2) {
3951
+			$context['can_edit_primary'] = false;
3952
+	}
3796 3953
 
3797 3954
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3798
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3799
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3800
-}
3955
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3956
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3957
+	}
3958
+	}
3801 3959
 
3802 3960
 /**
3803 3961
  * This function actually makes all the group changes
@@ -3812,10 +3970,12 @@  discard block
 block discarded – undo
3812 3970
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3813 3971
 
3814 3972
 	// Let's be extra cautious...
3815
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3816
-		isAllowedTo('manage_membergroups');
3817
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3818
-		fatal_lang_error('no_access', false);
3973
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3974
+			isAllowedTo('manage_membergroups');
3975
+	}
3976
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3977
+			fatal_lang_error('no_access', false);
3978
+	}
3819 3979
 
3820 3980
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3821 3981
 
@@ -3834,8 +3994,9 @@  discard block
 block discarded – undo
3834 3994
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3835 3995
 
3836 3996
 	// Sanity check!!
3837
-	if ($group_id == 1)
3838
-		isAllowedTo('admin_forum');
3997
+	if ($group_id == 1) {
3998
+			isAllowedTo('admin_forum');
3999
+	}
3839 4000
 	// Protected groups too!
3840 4001
 	else
3841 4002
 	{
@@ -3852,8 +4013,9 @@  discard block
 block discarded – undo
3852 4013
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3853 4014
 		$smcFunc['db_free_result']($request);
3854 4015
 
3855
-		if ($is_protected == 1)
3856
-			isAllowedTo('admin_forum');
4016
+		if ($is_protected == 1) {
4017
+					isAllowedTo('admin_forum');
4018
+		}
3857 4019
 	}
3858 4020
 
3859 4021
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3875,36 +4037,43 @@  discard block
 block discarded – undo
3875 4037
 			$group_name = $row['group_name'];
3876 4038
 
3877 4039
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3878
-			if ($changeType == 'request' && $row['group_type'] != 2)
3879
-				fatal_lang_error('no_access', false);
4040
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4041
+							fatal_lang_error('no_access', false);
4042
+			}
3880 4043
 			// What about leaving a requestable group we are not a member of?
3881
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3882
-				fatal_lang_error('no_access', false);
3883
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3884
-				fatal_lang_error('no_access', false);
4044
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4045
+							fatal_lang_error('no_access', false);
4046
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4047
+							fatal_lang_error('no_access', false);
4048
+			}
3885 4049
 
3886 4050
 			// We can't change the primary group if this is hidden!
3887
-			if ($row['hidden'] == 2)
3888
-				$canChangePrimary = false;
4051
+			if ($row['hidden'] == 2) {
4052
+							$canChangePrimary = false;
4053
+			}
3889 4054
 		}
3890 4055
 
3891 4056
 		// If this is their old primary, can we change it?
3892
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3893
-			$canChangePrimary = 1;
4057
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4058
+					$canChangePrimary = 1;
4059
+		}
3894 4060
 
3895 4061
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3896
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3897
-			$canChangePrimary = false;
4062
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4063
+					$canChangePrimary = false;
4064
+		}
3898 4065
 
3899 4066
 		// If this is the one we are acting on, can we even act?
3900
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3901
-			$canChangePrimary = false;
4067
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4068
+					$canChangePrimary = false;
4069
+		}
3902 4070
 	}
3903 4071
 	$smcFunc['db_free_result']($request);
3904 4072
 
3905 4073
 	// Didn't find the target?
3906
-	if (!$foundTarget)
3907
-		fatal_lang_error('no_access', false);
4074
+	if (!$foundTarget) {
4075
+			fatal_lang_error('no_access', false);
4076
+	}
3908 4077
 
3909 4078
 	// Final security check, don't allow users to promote themselves to admin.
3910 4079
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3924,8 +4093,9 @@  discard block
 block discarded – undo
3924 4093
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3925 4094
 		$smcFunc['db_free_result']($request);
3926 4095
 
3927
-		if ($disallow)
3928
-			isAllowedTo('admin_forum');
4096
+		if ($disallow) {
4097
+					isAllowedTo('admin_forum');
4098
+		}
3929 4099
 	}
3930 4100
 
3931 4101
 	// If we're requesting, add the note then return.
@@ -3943,8 +4113,9 @@  discard block
 block discarded – undo
3943 4113
 				'status_open' => 0,
3944 4114
 			)
3945 4115
 		);
3946
-		if ($smcFunc['db_num_rows']($request) != 0)
3947
-			fatal_lang_error('profile_error_already_requested_group');
4116
+		if ($smcFunc['db_num_rows']($request) != 0) {
4117
+					fatal_lang_error('profile_error_already_requested_group');
4118
+		}
3948 4119
 		$smcFunc['db_free_result']($request);
3949 4120
 
3950 4121
 		// Log the request.
@@ -3978,10 +4149,11 @@  discard block
 block discarded – undo
3978 4149
 		// Are we leaving?
3979 4150
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3980 4151
 		{
3981
-			if ($old_profile['id_group'] == $group_id)
3982
-				$newPrimary = 0;
3983
-			else
3984
-				unset($addGroups[$group_id]);
4152
+			if ($old_profile['id_group'] == $group_id) {
4153
+							$newPrimary = 0;
4154
+			} else {
4155
+							unset($addGroups[$group_id]);
4156
+			}
3985 4157
 		}
3986 4158
 		// ... if not, must be joining.
3987 4159
 		else
@@ -3989,36 +4161,42 @@  discard block
 block discarded – undo
3989 4161
 			// Can we change the primary, and do we want to?
3990 4162
 			if ($canChangePrimary)
3991 4163
 			{
3992
-				if ($old_profile['id_group'] != 0)
3993
-					$addGroups[$old_profile['id_group']] = -1;
4164
+				if ($old_profile['id_group'] != 0) {
4165
+									$addGroups[$old_profile['id_group']] = -1;
4166
+				}
3994 4167
 				$newPrimary = $group_id;
3995 4168
 			}
3996 4169
 			// Otherwise it's an additional group...
3997
-			else
3998
-				$addGroups[$group_id] = -1;
4170
+			else {
4171
+							$addGroups[$group_id] = -1;
4172
+			}
3999 4173
 		}
4000 4174
 	}
4001 4175
 	// Finally, we must be setting the primary.
4002 4176
 	elseif ($canChangePrimary)
4003 4177
 	{
4004
-		if ($old_profile['id_group'] != 0)
4005
-			$addGroups[$old_profile['id_group']] = -1;
4006
-		if (isset($addGroups[$group_id]))
4007
-			unset($addGroups[$group_id]);
4178
+		if ($old_profile['id_group'] != 0) {
4179
+					$addGroups[$old_profile['id_group']] = -1;
4180
+		}
4181
+		if (isset($addGroups[$group_id])) {
4182
+					unset($addGroups[$group_id]);
4183
+		}
4008 4184
 		$newPrimary = $group_id;
4009 4185
 	}
4010 4186
 
4011 4187
 	// Finally, we can make the changes!
4012
-	foreach ($addGroups as $id => $dummy)
4013
-		if (empty($id))
4188
+	foreach ($addGroups as $id => $dummy) {
4189
+			if (empty($id))
4014 4190
 			unset($addGroups[$id]);
4191
+	}
4015 4192
 	$addGroups = implode(',', array_flip($addGroups));
4016 4193
 
4017 4194
 	// Ensure that we don't cache permissions if the group is changing.
4018
-	if ($context['user']['is_owner'])
4019
-		$_SESSION['mc']['time'] = 0;
4020
-	else
4021
-		updateSettings(array('settings_updated' => time()));
4195
+	if ($context['user']['is_owner']) {
4196
+			$_SESSION['mc']['time'] = 0;
4197
+	} else {
4198
+			updateSettings(array('settings_updated' => time()));
4199
+	}
4022 4200
 
4023 4201
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4024 4202
 
@@ -4041,8 +4219,9 @@  discard block
 block discarded – undo
4041 4219
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4042 4220
 	{
4043 4221
 		// Check to ensure we're forcing SSL for authentication
4044
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
4045
-			fatal_lang_error('login_ssl_required');
4222
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
4223
+					fatal_lang_error('login_ssl_required');
4224
+		}
4046 4225
 
4047 4226
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4048 4227
 		// we do not want too much AJAX to confuse them.
@@ -4079,8 +4258,7 @@  discard block
 block discarded – undo
4079 4258
 				$context['sub_template'] = 'tfasetup_backup';
4080 4259
 
4081 4260
 				return;
4082
-			}
4083
-			else
4261
+			} else
4084 4262
 			{
4085 4263
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4086 4264
 				$context['tfa_error'] = !$valid_code;
@@ -4088,8 +4266,7 @@  discard block
 block discarded – undo
4088 4266
 				$context['tfa_pass_value'] = $_POST['passwd'];
4089 4267
 				$context['tfa_value'] = $_POST['tfa_code'];
4090 4268
 			}
4091
-		}
4092
-		else
4269
+		} else
4093 4270
 		{
4094 4271
 			$totp = new \TOTP\Auth();
4095 4272
 			$secret = $totp->generateCode();
@@ -4099,17 +4276,16 @@  discard block
 block discarded – undo
4099 4276
 		}
4100 4277
 
4101 4278
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4102
-	}
4103
-	elseif (isset($_REQUEST['disable']))
4279
+	} elseif (isset($_REQUEST['disable']))
4104 4280
 	{
4105 4281
 		updateMemberData($memID, array(
4106 4282
 			'tfa_secret' => '',
4107 4283
 			'tfa_backup' => '',
4108 4284
 		));
4109 4285
 		redirectexit('action=profile;area=account;u=' . $memID);
4286
+	} else {
4287
+			redirectexit('action=profile;area=account;u=' . $memID);
4288
+	}
4110 4289
 	}
4111
-	else
4112
-		redirectexit('action=profile;area=account;u=' . $memID);
4113
-}
4114 4290
 
4115 4291
 ?>
4116 4292
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Themes.php 1 patch
Braces   +348 added lines, -271 removed lines patch added patch discarded remove patch
@@ -30,8 +30,9 @@  discard block
 block discarded – undo
30 30
  * @version 2.1 Beta 4
31 31
  */
32 32
 
33
-if (!defined('SMF'))
33
+if (!defined('SMF')) {
34 34
 	die('No direct access...');
35
+}
35 36
 
36 37
 /**
37 38
  * Subaction handler - manages the action and delegates control to the proper
@@ -103,12 +104,12 @@  discard block
 block discarded – undo
103 104
 	cache_put_data('minimized_css', null);
104 105
 
105 106
 	// Follow the sa or just go to administration.
106
-	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']]))
107
-		call_helper($subActions[$_GET['sa']]);
108
-
109
-	else
110
-		call_helper($subActions['admin']);
111
-}
107
+	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) {
108
+			call_helper($subActions[$_GET['sa']]);
109
+	} else {
110
+			call_helper($subActions['admin']);
111
+	}
112
+	}
112 113
 
113 114
 /**
114 115
  * This function allows administration of themes and their settings,
@@ -130,15 +131,16 @@  discard block
 block discarded – undo
130 131
 		checkSession();
131 132
 		validateToken('admin-tm');
132 133
 
133
-		if (isset($_POST['options']['known_themes']))
134
-			foreach ($_POST['options']['known_themes'] as $key => $id)
134
+		if (isset($_POST['options']['known_themes'])) {
135
+					foreach ($_POST['options']['known_themes'] as $key => $id)
135 136
 				$_POST['options']['known_themes'][$key] = (int) $id;
137
+		} else {
138
+					fatal_lang_error('themes_none_selectable', false);
139
+		}
136 140
 
137
-		else
138
-			fatal_lang_error('themes_none_selectable', false);
139
-
140
-		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes']))
141
-			fatal_lang_error('themes_default_selectable', false);
141
+		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) {
142
+					fatal_lang_error('themes_default_selectable', false);
143
+		}
142 144
 
143 145
 		// Commit the new settings.
144 146
 		updateSettings(array(
@@ -146,8 +148,9 @@  discard block
 block discarded – undo
146 148
 			'theme_guests' => $_POST['options']['theme_guests'],
147 149
 			'knownThemes' => implode(',', $_POST['options']['known_themes']),
148 150
 		));
149
-		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes']))
150
-			updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
151
+		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) {
152
+					updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
153
+		}
151 154
 
152 155
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=admin');
153 156
 	}
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	// Look for a non existent theme directory. (ie theme87.)
167 170
 	$theme_dir = $boarddir . '/Themes/theme';
168 171
 	$i = 1;
169
-	while (file_exists($theme_dir . $i))
170
-		$i++;
172
+	while (file_exists($theme_dir . $i)) {
173
+			$i++;
174
+	}
171 175
 
172 176
 	$context['new_theme_name'] = 'theme' . $i;
173 177
 
@@ -189,8 +193,9 @@  discard block
 block discarded – undo
189 193
 	loadLanguage('Admin');
190 194
 	isAllowedTo('admin_forum');
191 195
 
192
-	if (isset($_REQUEST['th']))
193
-		return SetThemeSettings();
196
+	if (isset($_REQUEST['th'])) {
197
+			return SetThemeSettings();
198
+	}
194 199
 
195 200
 	if (isset($_POST['save']))
196 201
 	{
@@ -274,12 +279,13 @@  discard block
 block discarded – undo
274 279
 		$context['themes'] = array();
275 280
 		while ($row = $smcFunc['db_fetch_assoc']($request))
276 281
 		{
277
-			if (!isset($context['themes'][$row['id_theme']]))
278
-				$context['themes'][$row['id_theme']] = array(
282
+			if (!isset($context['themes'][$row['id_theme']])) {
283
+							$context['themes'][$row['id_theme']] = array(
279 284
 					'id' => $row['id_theme'],
280 285
 					'num_default_options' => 0,
281 286
 					'num_members' => 0,
282 287
 				);
288
+			}
283 289
 			$context['themes'][$row['id_theme']][$row['variable']] = $row['value'];
284 290
 		}
285 291
 		$smcFunc['db_free_result']($request);
@@ -293,8 +299,9 @@  discard block
 block discarded – undo
293 299
 				'guest_member' => -1,
294 300
 			)
295 301
 		);
296
-		while ($row = $smcFunc['db_fetch_assoc']($request))
297
-			$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
302
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
303
+					$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
304
+		}
298 305
 		$smcFunc['db_free_result']($request);
299 306
 
300 307
 		// Need to make sure we don't do custom fields.
@@ -305,8 +312,9 @@  discard block
 block discarded – undo
305 312
 			)
306 313
 		);
307 314
 		$customFields = array();
308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
309
-			$customFields[] = $row['col_name'];
315
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
316
+					$customFields[] = $row['col_name'];
317
+		}
310 318
 		$smcFunc['db_free_result']($request);
311 319
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
312 320
 
@@ -321,14 +329,16 @@  discard block
 block discarded – undo
321 329
 				'custom_fields' => empty($customFields) ? array() : $customFields,
322 330
 			)
323 331
 		);
324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
325
-			$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
332
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
333
+					$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
334
+		}
326 335
 		$smcFunc['db_free_result']($request);
327 336
 
328 337
 		// There has to be a Settings template!
329
-		foreach ($context['themes'] as $k => $v)
330
-			if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
338
+		foreach ($context['themes'] as $k => $v) {
339
+					if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
331 340
 				unset($context['themes'][$k]);
341
+		}
332 342
 
333 343
 		loadTemplate('Themes');
334 344
 		$context['sub_template'] = 'reset_list';
@@ -343,16 +353,19 @@  discard block
 block discarded – undo
343 353
 		checkSession();
344 354
 		validateToken('admin-sto');
345 355
 
346
-		if (empty($_POST['options']))
347
-			$_POST['options'] = array();
348
-		if (empty($_POST['default_options']))
349
-			$_POST['default_options'] = array();
356
+		if (empty($_POST['options'])) {
357
+					$_POST['options'] = array();
358
+		}
359
+		if (empty($_POST['default_options'])) {
360
+					$_POST['default_options'] = array();
361
+		}
350 362
 
351 363
 		// Set up the sql query.
352 364
 		$setValues = array();
353 365
 
354
-		foreach ($_POST['options'] as $opt => $val)
355
-			$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
366
+		foreach ($_POST['options'] as $opt => $val) {
367
+					$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
368
+		}
356 369
 
357 370
 		$old_settings = array();
358 371
 		foreach ($_POST['default_options'] as $opt => $val)
@@ -366,8 +379,8 @@  discard block
 block discarded – undo
366 379
 		if (!empty($setValues))
367 380
 		{
368 381
 			// Are there options in non-default themes set that should be cleared?
369
-			if (!empty($old_settings))
370
-				$smcFunc['db_query']('', '
382
+			if (!empty($old_settings)) {
383
+							$smcFunc['db_query']('', '
371 384
 					DELETE FROM {db_prefix}themes
372 385
 					WHERE id_theme != {int:default_theme}
373 386
 						AND id_member = {int:guest_member}
@@ -378,6 +391,7 @@  discard block
 block discarded – undo
378 391
 						'old_settings' => $old_settings,
379 392
 					)
380 393
 				);
394
+			}
381 395
 
382 396
 			$smcFunc['db_insert']('replace',
383 397
 				'{db_prefix}themes',
@@ -391,8 +405,7 @@  discard block
 block discarded – undo
391 405
 		cache_put_data('theme_settings-1', null, 90);
392 406
 
393 407
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
394
-	}
395
-	elseif (isset($_POST['submit']) && $_POST['who'] == 1)
408
+	} elseif (isset($_POST['submit']) && $_POST['who'] == 1)
396 409
 	{
397 410
 		checkSession();
398 411
 		validateToken('admin-sto');
@@ -405,9 +418,9 @@  discard block
 block discarded – undo
405 418
 		$old_settings = array();
406 419
 		foreach ($_POST['default_options'] as $opt => $val)
407 420
 		{
408
-			if ($_POST['default_options_master'][$opt] == 0)
409
-				continue;
410
-			elseif ($_POST['default_options_master'][$opt] == 1)
421
+			if ($_POST['default_options_master'][$opt] == 0) {
422
+							continue;
423
+			} elseif ($_POST['default_options_master'][$opt] == 1)
411 424
 			{
412 425
 				// Delete then insert for ease of database compatibility!
413 426
 				$smcFunc['db_query']('substring', '
@@ -433,8 +446,7 @@  discard block
 block discarded – undo
433 446
 				);
434 447
 
435 448
 				$old_settings[] = $opt;
436
-			}
437
-			elseif ($_POST['default_options_master'][$opt] == 2)
449
+			} elseif ($_POST['default_options_master'][$opt] == 2)
438 450
 			{
439 451
 				$smcFunc['db_query']('', '
440 452
 					DELETE FROM {db_prefix}themes
@@ -449,8 +461,8 @@  discard block
 block discarded – undo
449 461
 		}
450 462
 
451 463
 		// Delete options from other themes.
452
-		if (!empty($old_settings))
453
-			$smcFunc['db_query']('', '
464
+		if (!empty($old_settings)) {
465
+					$smcFunc['db_query']('', '
454 466
 				DELETE FROM {db_prefix}themes
455 467
 				WHERE id_theme != {int:default_theme}
456 468
 					AND id_member > {int:no_member}
@@ -461,12 +473,13 @@  discard block
 block discarded – undo
461 473
 					'old_settings' => $old_settings,
462 474
 				)
463 475
 			);
476
+		}
464 477
 
465 478
 		foreach ($_POST['options'] as $opt => $val)
466 479
 		{
467
-			if ($_POST['options_master'][$opt] == 0)
468
-				continue;
469
-			elseif ($_POST['options_master'][$opt] == 1)
480
+			if ($_POST['options_master'][$opt] == 0) {
481
+							continue;
482
+			} elseif ($_POST['options_master'][$opt] == 1)
470 483
 			{
471 484
 				// Delete then insert for ease of database compatibility - again!
472 485
 				$smcFunc['db_query']('substring', '
@@ -491,8 +504,7 @@  discard block
 block discarded – undo
491 504
 						'value' => (is_array($val) ? implode(',', $val) : $val),
492 505
 					)
493 506
 				);
494
-			}
495
-			elseif ($_POST['options_master'][$opt] == 2)
507
+			} elseif ($_POST['options_master'][$opt] == 2)
496 508
 			{
497 509
 				$smcFunc['db_query']('', '
498 510
 					DELETE FROM {db_prefix}themes
@@ -509,8 +521,7 @@  discard block
 block discarded – undo
509 521
 		}
510 522
 
511 523
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
512
-	}
513
-	elseif (!empty($_GET['who']) && $_GET['who'] == 2)
524
+	} elseif (!empty($_GET['who']) && $_GET['who'] == 2)
514 525
 	{
515 526
 		checkSession('get');
516 527
 		validateToken('admin-stor', 'request');
@@ -525,8 +536,9 @@  discard block
 block discarded – undo
525 536
 				)
526 537
 			);
527 538
 			$customFields = array();
528
-			while ($row = $smcFunc['db_fetch_assoc']($request))
529
-				$customFields[] = $row['col_name'];
539
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
540
+							$customFields[] = $row['col_name'];
541
+			}
530 542
 			$smcFunc['db_free_result']($request);
531 543
 		}
532 544
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
@@ -581,13 +593,13 @@  discard block
 block discarded – undo
581 593
 			)
582 594
 		);
583 595
 		$context['theme_options'] = array();
584
-		while ($row = $smcFunc['db_fetch_assoc']($request))
585
-			$context['theme_options'][$row['variable']] = $row['value'];
596
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
597
+					$context['theme_options'][$row['variable']] = $row['value'];
598
+		}
586 599
 		$smcFunc['db_free_result']($request);
587 600
 
588 601
 		$context['theme_options_reset'] = false;
589
-	}
590
-	else
602
+	} else
591 603
 	{
592 604
 		$context['theme_options'] = array();
593 605
 		$context['theme_options_reset'] = true;
@@ -596,30 +608,32 @@  discard block
 block discarded – undo
596 608
 	foreach ($context['options'] as $i => $setting)
597 609
 	{
598 610
 		// Just skip separators
599
-		if (!is_array($setting))
600
-			continue;
611
+		if (!is_array($setting)) {
612
+					continue;
613
+		}
601 614
 
602 615
 		// Is this disabled?
603 616
 		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled']))
604 617
 		{
605 618
 			unset($context['options'][$i]);
606 619
 			continue;
607
-		}
608
-		elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
620
+		} elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
609 621
 		{
610 622
 			unset($context['options'][$i]);
611 623
 			continue;
612 624
 		}
613 625
 
614
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
615
-			$context['options'][$i]['type'] = 'checkbox';
616
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
617
-			$context['options'][$i]['type'] = 'number';
618
-		elseif ($setting['type'] == 'string')
619
-			$context['options'][$i]['type'] = 'text';
626
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
627
+					$context['options'][$i]['type'] = 'checkbox';
628
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
629
+					$context['options'][$i]['type'] = 'number';
630
+		} elseif ($setting['type'] == 'string') {
631
+					$context['options'][$i]['type'] = 'text';
632
+		}
620 633
 
621
-		if (isset($setting['options']))
622
-			$context['options'][$i]['type'] = 'list';
634
+		if (isset($setting['options'])) {
635
+					$context['options'][$i]['type'] = 'list';
636
+		}
623 637
 
624 638
 		$context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']];
625 639
 	}
@@ -644,8 +658,9 @@  discard block
 block discarded – undo
644 658
 {
645 659
 	global $txt, $context, $settings, $modSettings, $smcFunc;
646 660
 
647
-	if (empty($_GET['th']) && empty($_GET['id']))
648
-		return ThemeAdmin();
661
+	if (empty($_GET['th']) && empty($_GET['id'])) {
662
+			return ThemeAdmin();
663
+	}
649 664
 
650 665
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
651 666
 
@@ -656,8 +671,9 @@  discard block
 block discarded – undo
656 671
 	isAllowedTo('admin_forum');
657 672
 
658 673
 	// Validate inputs/user.
659
-	if (empty($_GET['th']))
660
-		fatal_lang_error('no_theme', false);
674
+	if (empty($_GET['th'])) {
675
+			fatal_lang_error('no_theme', false);
676
+	}
661 677
 
662 678
 	// Fetch the smiley sets...
663 679
 	$sets = explode(',', 'none,' . $modSettings['smiley_sets_known']);
@@ -665,8 +681,9 @@  discard block
 block discarded – undo
665 681
 	$context['smiley_sets'] = array(
666 682
 		'' => $txt['smileys_no_default']
667 683
 	);
668
-	foreach ($sets as $i => $set)
669
-		$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
684
+	foreach ($sets as $i => $set) {
685
+			$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
686
+	}
670 687
 
671 688
 	$old_id = $settings['theme_id'];
672 689
 	$old_settings = $settings;
@@ -691,8 +708,9 @@  discard block
 block discarded – undo
691 708
 	if (file_exists($settings['theme_dir'] . '/index.template.php'))
692 709
 	{
693 710
 		$file_contents = implode('', file($settings['theme_dir'] . '/index.template.php'));
694
-		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches))
695
-				eval('global $settings;' . $matches[0]);
711
+		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) {
712
+						eval('global $settings;' . $matches[0]);
713
+		}
696 714
 	}
697 715
 
698 716
 	// Let mods hook into the theme settings.
@@ -704,37 +722,45 @@  discard block
 block discarded – undo
704 722
 		checkSession();
705 723
 		validateToken('admin-sts');
706 724
 
707
-		if (empty($_POST['options']))
708
-			$_POST['options'] = array();
709
-		if (empty($_POST['default_options']))
710
-			$_POST['default_options'] = array();
725
+		if (empty($_POST['options'])) {
726
+					$_POST['options'] = array();
727
+		}
728
+		if (empty($_POST['default_options'])) {
729
+					$_POST['default_options'] = array();
730
+		}
711 731
 
712 732
 		// Make sure items are cast correctly.
713 733
 		foreach ($context['theme_settings'] as $item)
714 734
 		{
715 735
 			// Disregard this item if this is just a separator.
716
-			if (!is_array($item))
717
-				continue;
736
+			if (!is_array($item)) {
737
+							continue;
738
+			}
718 739
 
719 740
 			foreach (array('options', 'default_options') as $option)
720 741
 			{
721
-				if (!isset($_POST[$option][$item['id']]))
722
-					continue;
742
+				if (!isset($_POST[$option][$item['id']])) {
743
+									continue;
744
+				}
723 745
 				// Checkbox.
724
-				elseif (empty($item['type']))
725
-					$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
746
+				elseif (empty($item['type'])) {
747
+									$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
748
+				}
726 749
 				// Number
727
-				elseif ($item['type'] == 'number')
728
-					$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
750
+				elseif ($item['type'] == 'number') {
751
+									$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
752
+				}
729 753
 			}
730 754
 		}
731 755
 
732 756
 		// Set up the sql query.
733 757
 		$inserts = array();
734
-		foreach ($_POST['options'] as $opt => $val)
735
-			$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
736
-		foreach ($_POST['default_options'] as $opt => $val)
737
-			$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
758
+		foreach ($_POST['options'] as $opt => $val) {
759
+					$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
760
+		}
761
+		foreach ($_POST['default_options'] as $opt => $val) {
762
+					$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
763
+		}
738 764
 		// If we're actually inserting something..
739 765
 		if (!empty($inserts))
740 766
 		{
@@ -760,8 +786,9 @@  discard block
 block discarded – undo
760 786
 
761 787
 	foreach ($settings as $setting => $dummy)
762 788
 	{
763
-		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs')))
764
-			$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
789
+		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) {
790
+					$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
791
+		}
765 792
 	}
766 793
 
767 794
 	$context['settings'] = $context['theme_settings'];
@@ -770,18 +797,21 @@  discard block
 block discarded – undo
770 797
 	foreach ($context['settings'] as $i => $setting)
771 798
 	{
772 799
 		// Separators are dummies, so leave them alone.
773
-		if (!is_array($setting))
774
-			continue;
800
+		if (!is_array($setting)) {
801
+					continue;
802
+		}
775 803
 
776
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
777
-			$context['settings'][$i]['type'] = 'checkbox';
778
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
779
-			$context['settings'][$i]['type'] = 'number';
780
-		elseif ($setting['type'] == 'string')
781
-			$context['settings'][$i]['type'] = 'text';
804
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
805
+					$context['settings'][$i]['type'] = 'checkbox';
806
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
807
+					$context['settings'][$i]['type'] = 'number';
808
+		} elseif ($setting['type'] == 'string') {
809
+					$context['settings'][$i]['type'] = 'text';
810
+		}
782 811
 
783
-		if (isset($setting['options']))
784
-			$context['settings'][$i]['type'] = 'list';
812
+		if (isset($setting['options'])) {
813
+					$context['settings'][$i]['type'] = 'list';
814
+		}
785 815
 
786 816
 		$context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']];
787 817
 	}
@@ -834,8 +864,9 @@  discard block
 block discarded – undo
834 864
 	$themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
835 865
 
836 866
 	// You can't delete the default theme!
837
-	if ($themeID == 1)
838
-		fatal_lang_error('no_access', false);
867
+	if ($themeID == 1) {
868
+			fatal_lang_error('no_access', false);
869
+	}
839 870
 
840 871
 	$theme_info = get_single_theme($themeID);
841 872
 
@@ -843,8 +874,9 @@  discard block
 block discarded – undo
843 874
 	remove_theme($themeID);
844 875
 
845 876
 	// And remove all its files and folders too.
846
-	if (!empty($theme_info) && !empty($theme_info['theme_dir']))
847
-		remove_dir($theme_info['theme_dir']);
877
+	if (!empty($theme_info) && !empty($theme_info['theme_dir'])) {
878
+			remove_dir($theme_info['theme_dir']);
879
+	}
848 880
 
849 881
 	// Go back to the list page.
850 882
 	redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id'] . ';done=removing');
@@ -869,12 +901,14 @@  discard block
 block discarded – undo
869 901
 	$enableThemes = explode(',', $modSettings['enableThemes']);
870 902
 
871 903
 	// Are we disabling it?
872
-	if (isset($_GET['disabled']))
873
-		$enableThemes = array_diff($enableThemes, array($themeID));
904
+	if (isset($_GET['disabled'])) {
905
+			$enableThemes = array_diff($enableThemes, array($themeID));
906
+	}
874 907
 
875 908
 	// Nope? then enable it!
876
-	else
877
-		$enableThemes[] = (string) $themeID;
909
+	else {
910
+			$enableThemes[] = (string) $themeID;
911
+	}
878 912
 
879 913
 	// Update the setting.
880 914
 	$enableThemes = strtr(implode(',', $enableThemes), array(',,' => ','));
@@ -909,18 +943,21 @@  discard block
 block discarded – undo
909 943
 
910 944
 	$_SESSION['id_theme'] = 0;
911 945
 
912
-	if (isset($_GET['id']))
913
-		$_GET['th'] = $_GET['id'];
946
+	if (isset($_GET['id'])) {
947
+			$_GET['th'] = $_GET['id'];
948
+	}
914 949
 
915 950
 	// Saving a variant cause JS doesn't work - pretend it did ;)
916 951
 	if (isset($_POST['save']))
917 952
 	{
918 953
 		// Which theme?
919
-		foreach ($_POST['save'] as $k => $v)
920
-			$_GET['th'] = (int) $k;
954
+		foreach ($_POST['save'] as $k => $v) {
955
+					$_GET['th'] = (int) $k;
956
+		}
921 957
 
922
-		if (isset($_POST['vrt'][$k]))
923
-			$_GET['vrt'] = $_POST['vrt'][$k];
958
+		if (isset($_POST['vrt'][$k])) {
959
+					$_GET['vrt'] = $_POST['vrt'][$k];
960
+		}
924 961
 	}
925 962
 
926 963
 	// Have we made a decision, or are we just browsing?
@@ -998,8 +1035,9 @@  discard block
 block discarded – undo
998 1035
 		else
999 1036
 		{
1000 1037
 			// The forum's default theme is always 0 and we
1001
-			if (isset($_GET['th']) && $_GET['th'] == 0)
1002
-					$_GET['th'] = $modSettings['theme_guests'];
1038
+			if (isset($_GET['th']) && $_GET['th'] == 0) {
1039
+								$_GET['th'] = $modSettings['theme_guests'];
1040
+			}
1003 1041
 
1004 1042
 			updateMemberData((int) $_REQUEST['u'], array('id_theme' => (int) $_GET['th']));
1005 1043
 
@@ -1013,8 +1051,9 @@  discard block
 block discarded – undo
1013 1051
 				);
1014 1052
 				cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90);
1015 1053
 
1016
-				if ($user_info['id'] == $_REQUEST['u'])
1017
-					$_SESSION['id_variant'] = 0;
1054
+				if ($user_info['id'] == $_REQUEST['u']) {
1055
+									$_SESSION['id_variant'] = 0;
1056
+				}
1018 1057
 			}
1019 1058
 
1020 1059
 			redirectexit('action=profile;u=' . (int) $_REQUEST['u'] . ';area=theme');
@@ -1083,12 +1122,13 @@  discard block
 block discarded – undo
1083 1122
 		);
1084 1123
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1085 1124
 		{
1086
-			if (!isset($context['available_themes'][$row['id_theme']]))
1087
-				$context['available_themes'][$row['id_theme']] = array(
1125
+			if (!isset($context['available_themes'][$row['id_theme']])) {
1126
+							$context['available_themes'][$row['id_theme']] = array(
1088 1127
 					'id' => $row['id_theme'],
1089 1128
 					'selected' => $context['current_theme'] == $row['id_theme'],
1090 1129
 					'num_users' => 0
1091 1130
 				);
1131
+			}
1092 1132
 			$context['available_themes'][$row['id_theme']][$row['variable']] = $row['value'];
1093 1133
 		}
1094 1134
 		$smcFunc['db_free_result']($request);
@@ -1101,9 +1141,9 @@  discard block
 block discarded – undo
1101 1141
 			'num_users' => 0
1102 1142
 		);
1103 1143
 		$guest_theme = 0;
1144
+	} else {
1145
+			$guest_theme = $modSettings['theme_guests'];
1104 1146
 	}
1105
-	else
1106
-		$guest_theme = $modSettings['theme_guests'];
1107 1147
 
1108 1148
 	$request = $smcFunc['db_query']('', '
1109 1149
 		SELECT id_theme, COUNT(*) AS the_count
@@ -1116,15 +1156,17 @@  discard block
 block discarded – undo
1116 1156
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1117 1157
 	{
1118 1158
 		// Figure out which theme it is they are REALLY using.
1119
-		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes'])))
1120
-			$row['id_theme'] = $guest_theme;
1121
-		elseif (empty($modSettings['theme_allow']))
1122
-			$row['id_theme'] = $guest_theme;
1159
+		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) {
1160
+					$row['id_theme'] = $guest_theme;
1161
+		} elseif (empty($modSettings['theme_allow'])) {
1162
+					$row['id_theme'] = $guest_theme;
1163
+		}
1123 1164
 
1124
-		if (isset($context['available_themes'][$row['id_theme']]))
1125
-			$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1126
-		else
1127
-			$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1165
+		if (isset($context['available_themes'][$row['id_theme']])) {
1166
+					$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1167
+		} else {
1168
+					$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1169
+		}
1128 1170
 	}
1129 1171
 	$smcFunc['db_free_result']($request);
1130 1172
 
@@ -1143,8 +1185,9 @@  discard block
 block discarded – undo
1143 1185
 				'id_member' => isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? array(-1, $context['current_member']) : array(-1),
1144 1186
 			)
1145 1187
 		);
1146
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1147
-			$variant_preferences[$row['id_theme']] = $row['value'];
1188
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1189
+					$variant_preferences[$row['id_theme']] = $row['value'];
1190
+		}
1148 1191
 		$smcFunc['db_free_result']($request);
1149 1192
 	}
1150 1193
 
@@ -1155,17 +1198,18 @@  discard block
 block discarded – undo
1155 1198
 	foreach ($context['available_themes'] as $id_theme => $theme_data)
1156 1199
 	{
1157 1200
 		// Don't try to load the forum or board default theme's data... it doesn't have any!
1158
-		if ($id_theme == 0)
1159
-			continue;
1201
+		if ($id_theme == 0) {
1202
+					continue;
1203
+		}
1160 1204
 
1161 1205
 		// The thumbnail needs the correct path.
1162 1206
 		$settings['images_url'] = &$theme_data['images_url'];
1163 1207
 
1164
-		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
1165
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1166
-		elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'))
1167
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1168
-		else
1208
+		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) {
1209
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1210
+		} elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) {
1211
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1212
+		} else
1169 1213
 		{
1170 1214
 			$txt['theme_thumbnail_href'] = $theme_data['images_url'] . '/thumbnail.png';
1171 1215
 			$txt['theme_description'] = '';
@@ -1190,15 +1234,17 @@  discard block
 block discarded – undo
1190 1234
 					loadLanguage('Settings');
1191 1235
 
1192 1236
 					$context['available_themes'][$id_theme]['variants'] = array();
1193
-					foreach ($settings['theme_variants'] as $variant)
1194
-						$context['available_themes'][$id_theme]['variants'][$variant] = array(
1237
+					foreach ($settings['theme_variants'] as $variant) {
1238
+											$context['available_themes'][$id_theme]['variants'][$variant] = array(
1195 1239
 							'label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant,
1196 1240
 							'thumbnail' => !file_exists($theme_data['theme_dir'] . '/images/thumbnail.png') || file_exists($theme_data['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $theme_data['images_url'] . '/thumbnail_' . $variant . '.png' : ($theme_data['images_url'] . '/thumbnail.png'),
1197 1241
 						);
1242
+					}
1198 1243
 
1199 1244
 					$context['available_themes'][$id_theme]['selected_variant'] = isset($_GET['vrt']) ? $_GET['vrt'] : (!empty($variant_preferences[$id_theme]) ? $variant_preferences[$id_theme] : (!empty($settings['default_variant']) ? $settings['default_variant'] : $settings['theme_variants'][0]));
1200
-					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail']))
1201
-						$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1245
+					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) {
1246
+											$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1247
+					}
1202 1248
 
1203 1249
 					$context['available_themes'][$id_theme]['thumbnail_href'] = $context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'];
1204 1250
 					// Allow themes to override the text.
@@ -1214,8 +1260,9 @@  discard block
 block discarded – undo
1214 1260
 	// As long as we're not doing the default theme...
1215 1261
 	if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0)
1216 1262
 	{
1217
-		if ($guest_theme != 0)
1218
-			$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1263
+		if ($guest_theme != 0) {
1264
+					$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1265
+		}
1219 1266
 
1220 1267
 		$context['available_themes'][0]['id'] = 0;
1221 1268
 		$context['available_themes'][0]['name'] = $txt['theme_forum_default'];
@@ -1264,14 +1311,16 @@  discard block
 block discarded – undo
1264 1311
 		$action = $smcFunc['htmlspecialchars'](trim($_GET['do']));
1265 1312
 
1266 1313
 		// Got any info from the specific form?
1267
-		if (!isset($_POST['save_' . $action]))
1268
-			fatal_lang_error('theme_install_no_action', false);
1314
+		if (!isset($_POST['save_' . $action])) {
1315
+					fatal_lang_error('theme_install_no_action', false);
1316
+		}
1269 1317
 
1270 1318
 		validateToken('admin-t-' . $action);
1271 1319
 
1272 1320
 		// Hopefully the themes directory is writable, or we might have a problem.
1273
-		if (!is_writable($themedir))
1274
-			fatal_lang_error('theme_install_write_error', 'critical');
1321
+		if (!is_writable($themedir)) {
1322
+					fatal_lang_error('theme_install_write_error', 'critical');
1323
+		}
1275 1324
 
1276 1325
 		// Call the function and handle the result.
1277 1326
 		$result = $subActions[$action]();
@@ -1286,9 +1335,10 @@  discard block
 block discarded – undo
1286 1335
 	}
1287 1336
 
1288 1337
 	// Nope, show a nice error.
1289
-	else
1290
-		fatal_lang_error('theme_install_no_action', false);
1291
-}
1338
+	else {
1339
+			fatal_lang_error('theme_install_no_action', false);
1340
+	}
1341
+	}
1292 1342
 
1293 1343
 /**
1294 1344
  * Installs a theme from a theme package.
@@ -1304,8 +1354,9 @@  discard block
 block discarded – undo
1304 1354
 	$dirtemp = $themedir . '/temp';
1305 1355
 
1306 1356
 	// Make sure the temp dir doesn't already exist
1307
-	if (file_exists($dirtemp))
1308
-		remove_dir($dirtemp);
1357
+	if (file_exists($dirtemp)) {
1358
+			remove_dir($dirtemp);
1359
+	}
1309 1360
 
1310 1361
 	// Create the temp dir.
1311 1362
 	mkdir($dirtemp, 0777);
@@ -1317,17 +1368,20 @@  discard block
 block discarded – undo
1317 1368
 		smf_chmod($dirtemp, '0755');
1318 1369
 
1319 1370
 		// How about now?
1320
-		if (!is_writable($dirtemp))
1321
-			fatal_lang_error('theme_install_write_error', 'critical');
1371
+		if (!is_writable($dirtemp)) {
1372
+					fatal_lang_error('theme_install_write_error', 'critical');
1373
+		}
1322 1374
 	}
1323 1375
 
1324 1376
 	// This happens when the admin session is gone and the user has to login again.
1325
-	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz']))
1326
-		redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1377
+	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) {
1378
+			redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1379
+	}
1327 1380
 
1328 1381
 	// Another error check layer, something went wrong with the upload.
1329
-	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0)
1330
-		fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1382
+	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) {
1383
+			fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1384
+	}
1331 1385
 
1332 1386
 	// Get the theme's name.
1333 1387
 	$name = pathinfo($_FILES['theme_gz']['name'], PATHINFO_FILENAME);
@@ -1358,11 +1412,10 @@  discard block
 block discarded – undo
1358 1412
 
1359 1413
 		// return all the info.
1360 1414
 		return $context['to_install'];
1415
+	} else {
1416
+			fatal_lang_error('theme_install_error_title', false);
1417
+	}
1361 1418
 	}
1362
-
1363
-	else
1364
-		fatal_lang_error('theme_install_error_title', false);
1365
-}
1366 1419
 
1367 1420
 /**
1368 1421
  * Makes a copy from the default theme, assigns a name for it and installs it.
@@ -1376,15 +1429,17 @@  discard block
 block discarded – undo
1376 1429
 	global $forum_version;
1377 1430
 
1378 1431
 	// There's gotta be something to work with.
1379
-	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy']))
1380
-		fatal_lang_error('theme_install_error_title', false);
1432
+	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) {
1433
+			fatal_lang_error('theme_install_error_title', false);
1434
+	}
1381 1435
 
1382 1436
 	// Get a cleaner version.
1383 1437
 	$name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']);
1384 1438
 
1385 1439
 	// Is there a theme already named like this?
1386
-	if (file_exists($themedir . '/' . $name))
1387
-		fatal_lang_error('theme_install_already_dir', false);
1440
+	if (file_exists($themedir . '/' . $name)) {
1441
+			fatal_lang_error('theme_install_already_dir', false);
1442
+	}
1388 1443
 
1389 1444
 	// This is a brand new theme so set all possible values.
1390 1445
 	$context['to_install'] = array(
@@ -1404,8 +1459,9 @@  discard block
 block discarded – undo
1404 1459
 
1405 1460
 	// Buy some time.
1406 1461
 	@set_time_limit(600);
1407
-	if (function_exists('apache_reset_timeout'))
1408
-		@apache_reset_timeout();
1462
+	if (function_exists('apache_reset_timeout')) {
1463
+			@apache_reset_timeout();
1464
+	}
1409 1465
 
1410 1466
 	// Create subdirectories for css and javascript files.
1411 1467
 	mkdir($context['to_install']['theme_dir'] . '/css', 0777);
@@ -1441,12 +1497,13 @@  discard block
 block discarded – undo
1441 1497
 
1442 1498
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1443 1499
 	{
1444
-		if ($row['variable'] == 'theme_templates')
1445
-			$theme_templates = $row['value'];
1446
-		elseif ($row['variable'] == 'theme_layers')
1447
-			$theme_layers = $row['value'];
1448
-		else
1449
-			continue;
1500
+		if ($row['variable'] == 'theme_templates') {
1501
+					$theme_templates = $row['value'];
1502
+		} elseif ($row['variable'] == 'theme_layers') {
1503
+					$theme_layers = $row['value'];
1504
+		} else {
1505
+					continue;
1506
+		}
1450 1507
 	}
1451 1508
 
1452 1509
 	$smcFunc['db_free_result']($request);
@@ -1505,12 +1562,14 @@  discard block
 block discarded – undo
1505 1562
 	global $themedir, $themeurl, $context;
1506 1563
 
1507 1564
 	// Cannot use the theme dir as a theme dir.
1508
-	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir))
1509
-		fatal_lang_error('theme_install_invalid_dir', false);
1565
+	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) {
1566
+			fatal_lang_error('theme_install_invalid_dir', false);
1567
+	}
1510 1568
 
1511 1569
 	// Check is there is "something" on the dir.
1512
-	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml'))
1513
-		fatal_lang_error('theme_install_error', false);
1570
+	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) {
1571
+			fatal_lang_error('theme_install_error', false);
1572
+	}
1514 1573
 
1515 1574
 	$name = basename($_REQUEST['theme_dir']);
1516 1575
 	$name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);
@@ -1554,24 +1613,27 @@  discard block
 block discarded – undo
1554 1613
 	}
1555 1614
 
1556 1615
 	// Any special layers?
1557
-	if (isset($settings['catch_action']['layers']))
1558
-		$context['template_layers'] = $settings['catch_action']['layers'];
1616
+	if (isset($settings['catch_action']['layers'])) {
1617
+			$context['template_layers'] = $settings['catch_action']['layers'];
1618
+	}
1559 1619
 
1560 1620
 	// Any function to call?
1561 1621
 	if (isset($settings['catch_action']['function']))
1562 1622
 	{
1563 1623
 		$hook = $settings['catch_action']['function'];
1564 1624
 
1565
-		if (!isset($settings['catch_action']['filename']))
1566
-			$settings['catch_action']['filename'] = '';
1625
+		if (!isset($settings['catch_action']['filename'])) {
1626
+					$settings['catch_action']['filename'] = '';
1627
+		}
1567 1628
 
1568 1629
 		add_integration_function('integrate_wrap_action', $hook, false, $settings['catch_action']['filename'], false);
1569 1630
 		call_integration_hook('integrate_wrap_action');
1570 1631
 	}
1571 1632
 	// And finally, the main sub template ;).
1572
-	if (isset($settings['catch_action']['sub_template']))
1573
-		$context['sub_template'] = $settings['catch_action']['sub_template'];
1574
-}
1633
+	if (isset($settings['catch_action']['sub_template'])) {
1634
+			$context['sub_template'] = $settings['catch_action']['sub_template'];
1635
+	}
1636
+	}
1575 1637
 
1576 1638
 /**
1577 1639
  * Set an option via javascript.
@@ -1590,12 +1652,14 @@  discard block
 block discarded – undo
1590 1652
 	checkSession('get');
1591 1653
 
1592 1654
 	// This good-for-nothing pixel is being used to keep the session alive.
1593
-	if (empty($_GET['var']) || !isset($_GET['val']))
1594
-		redirectexit($settings['images_url'] . '/blank.png');
1655
+	if (empty($_GET['var']) || !isset($_GET['val'])) {
1656
+			redirectexit($settings['images_url'] . '/blank.png');
1657
+	}
1595 1658
 
1596 1659
 	// Sorry, guests can't go any further than this.
1597
-	if ($user_info['is_guest'] || $user_info['id'] == 0)
1598
-		obExit(false);
1660
+	if ($user_info['is_guest'] || $user_info['id'] == 0) {
1661
+			obExit(false);
1662
+	}
1599 1663
 
1600 1664
 	$reservedVars = array(
1601 1665
 		'actual_theme_url',
@@ -1618,8 +1682,9 @@  discard block
 block discarded – undo
1618 1682
 	);
1619 1683
 
1620 1684
 	// Can't change reserved vars.
1621
-	if (in_array(strtolower($_GET['var']), $reservedVars))
1622
-		redirectexit($settings['images_url'] . '/blank.png');
1685
+	if (in_array(strtolower($_GET['var']), $reservedVars)) {
1686
+			redirectexit($settings['images_url'] . '/blank.png');
1687
+	}
1623 1688
 
1624 1689
 	// Use a specific theme?
1625 1690
 	if (isset($_GET['th']) || isset($_GET['id']))
@@ -1635,8 +1700,9 @@  discard block
 block discarded – undo
1635 1700
 	{
1636 1701
 		$options['admin_preferences'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array();
1637 1702
 		// New thingy...
1638
-		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5)
1639
-			$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1703
+		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) {
1704
+					$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1705
+		}
1640 1706
 
1641 1707
 		// Change the value to be something nice,
1642 1708
 		$_GET['val'] = $smcFunc['json_encode']($options['admin_preferences']);
@@ -1666,8 +1732,9 @@  discard block
 block discarded – undo
1666 1732
 	global $context, $scripturl, $boarddir, $smcFunc, $txt;
1667 1733
 
1668 1734
 	// @todo Should this be removed?
1669
-	if (isset($_REQUEST['preview']))
1670
-		die('die() with fire');
1735
+	if (isset($_REQUEST['preview'])) {
1736
+			die('die() with fire');
1737
+	}
1671 1738
 
1672 1739
 	isAllowedTo('admin_forum');
1673 1740
 	loadTemplate('Themes');
@@ -1681,11 +1748,11 @@  discard block
 block discarded – undo
1681 1748
 		foreach ($context['themes'] as $key => $theme)
1682 1749
 		{
1683 1750
 			// There has to be a Settings template!
1684
-			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css'))
1685
-				unset($context['themes'][$key]);
1686
-
1687
-			else
1688
-				$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1751
+			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) {
1752
+							unset($context['themes'][$key]);
1753
+			} else {
1754
+							$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1755
+			}
1689 1756
 		}
1690 1757
 
1691 1758
 		$context['sub_template'] = 'edit_list';
@@ -1700,22 +1767,24 @@  discard block
 block discarded – undo
1700 1767
 	$context['theme_id'] = $currentTheme['id'];
1701 1768
 	$context['browse_title'] = sprintf($txt['themeadmin_browsing_theme'], $currentTheme['name']);
1702 1769
 
1703
-	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css'))
1704
-		fatal_lang_error('theme_edit_missing', false);
1770
+	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) {
1771
+			fatal_lang_error('theme_edit_missing', false);
1772
+	}
1705 1773
 
1706 1774
 	if (!isset($_REQUEST['filename']))
1707 1775
 	{
1708 1776
 		if (isset($_GET['directory']))
1709 1777
 		{
1710
-			if (substr($_GET['directory'], 0, 1) == '.')
1711
-				$_GET['directory'] = '';
1712
-			else
1778
+			if (substr($_GET['directory'], 0, 1) == '.') {
1779
+							$_GET['directory'] = '';
1780
+			} else
1713 1781
 			{
1714 1782
 				$_GET['directory'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_GET['directory']);
1715 1783
 
1716 1784
 				$temp = realpath($currentTheme['theme_dir'] . '/' . $_GET['directory']);
1717
-				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1718
-					$_GET['directory'] = '';
1785
+				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1786
+									$_GET['directory'] = '';
1787
+				}
1719 1788
 			}
1720 1789
 		}
1721 1790
 
@@ -1734,37 +1803,39 @@  discard block
 block discarded – undo
1734 1803
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $temp,
1735 1804
 				'size' => '',
1736 1805
 			));
1806
+		} else {
1807
+					$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1737 1808
 		}
1738
-		else
1739
-			$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1740 1809
 
1741 1810
 		$context['sub_template'] = 'edit_browse';
1742 1811
 
1743 1812
 		return;
1744
-	}
1745
-	else
1813
+	} else
1746 1814
 	{
1747
-		if (substr($_REQUEST['filename'], 0, 1) == '.')
1748
-			$_REQUEST['filename'] = '';
1749
-		else
1815
+		if (substr($_REQUEST['filename'], 0, 1) == '.') {
1816
+					$_REQUEST['filename'] = '';
1817
+		} else
1750 1818
 		{
1751 1819
 			$_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']);
1752 1820
 
1753 1821
 			$temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1754
-			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1755
-				$_REQUEST['filename'] = '';
1822
+			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1823
+							$_REQUEST['filename'] = '';
1824
+			}
1756 1825
 		}
1757 1826
 
1758
-		if (empty($_REQUEST['filename']))
1759
-			fatal_lang_error('theme_edit_missing', false);
1827
+		if (empty($_REQUEST['filename'])) {
1828
+					fatal_lang_error('theme_edit_missing', false);
1829
+		}
1760 1830
 	}
1761 1831
 
1762 1832
 	if (isset($_POST['save']))
1763 1833
 	{
1764 1834
 		if (checkSession('post', '', false) == '' && validateToken('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true)
1765 1835
 		{
1766
-			if (is_array($_POST['entire_file']))
1767
-				$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1836
+			if (is_array($_POST['entire_file'])) {
1837
+							$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1838
+			}
1768 1839
 
1769 1840
 			$_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', '   ' => "\t")));
1770 1841
 
@@ -1776,10 +1847,11 @@  discard block
 block discarded – undo
1776 1847
 				fclose($fp);
1777 1848
 
1778 1849
 				$error = @file_get_contents($currentTheme['theme_url'] . '/tmp_' . session_id() . '.php');
1779
-				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0)
1780
-					$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1781
-				else
1782
-					unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1850
+				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) {
1851
+									$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1852
+				} else {
1853
+									unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1854
+				}
1783 1855
 			}
1784 1856
 
1785 1857
 			if (!isset($error_file))
@@ -1800,10 +1872,11 @@  discard block
 block discarded – undo
1800 1872
 			$context['sub_template'] = 'edit_file';
1801 1873
 
1802 1874
 			// Recycle the submitted data.
1803
-			if (is_array($_POST['entire_file']))
1804
-				$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1805
-			else
1806
-				$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1875
+			if (is_array($_POST['entire_file'])) {
1876
+							$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1877
+			} else {
1878
+							$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1879
+			}
1807 1880
 
1808 1881
 			$context['edit_filename'] = $smcFunc['htmlspecialchars']($_POST['filename']);
1809 1882
 
@@ -1826,17 +1899,17 @@  discard block
 block discarded – undo
1826 1899
 		$context['sub_template'] = 'edit_style';
1827 1900
 
1828 1901
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(file_get_contents($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']), array("\t" => '   ')));
1829
-	}
1830
-	elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1902
+	} elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1831 1903
 	{
1832 1904
 		$context['sub_template'] = 'edit_template';
1833 1905
 
1834
-		if (!isset($error_file))
1835
-			$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1836
-		else
1906
+		if (!isset($error_file)) {
1907
+					$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1908
+		} else
1837 1909
 		{
1838
-			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0)
1839
-				$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1910
+			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) {
1911
+							$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1912
+			}
1840 1913
 			$file_data = file($error_file);
1841 1914
 			unlink($error_file);
1842 1915
 		}
@@ -1850,8 +1923,9 @@  discard block
 block discarded – undo
1850 1923
 				// Try to format the functions a little nicer...
1851 1924
 				$context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n";
1852 1925
 
1853
-				if (empty($context['file_parts'][$j]['lines']))
1854
-					unset($context['file_parts'][$j]);
1926
+				if (empty($context['file_parts'][$j]['lines'])) {
1927
+									unset($context['file_parts'][$j]);
1928
+				}
1855 1929
 				$context['file_parts'][++$j] = array('lines' => 0, 'line' => $i + 1, 'data' => '');
1856 1930
 			}
1857 1931
 
@@ -1860,8 +1934,7 @@  discard block
 block discarded – undo
1860 1934
 		}
1861 1935
 
1862 1936
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(implode('', $file_data), array("\t" => '   ')));
1863
-	}
1864
-	else
1937
+	} else
1865 1938
 	{
1866 1939
 		$context['sub_template'] = 'edit_file';
1867 1940
 
@@ -1887,8 +1960,9 @@  discard block
 block discarded – undo
1887 1960
 
1888 1961
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
1889 1962
 
1890
-	if (empty($_GET['th']))
1891
-		fatal_lang_error('theme_install_invalid_id');
1963
+	if (empty($_GET['th'])) {
1964
+			fatal_lang_error('theme_install_invalid_id');
1965
+	}
1892 1966
 
1893 1967
 	// Get the theme info.
1894 1968
 	$theme = get_single_theme($_GET['th']);
@@ -1896,25 +1970,24 @@  discard block
 block discarded – undo
1896 1970
 
1897 1971
 	if (isset($_REQUEST['template']) && preg_match('~[\./\\\\:\0]~', $_REQUEST['template']) == 0)
1898 1972
 	{
1899
-		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'))
1900
-			$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1901
-
1902
-		else
1903
-			fatal_lang_error('no_access', false);
1973
+		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) {
1974
+					$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1975
+		} else {
1976
+					fatal_lang_error('no_access', false);
1977
+		}
1904 1978
 
1905 1979
 		$fp = fopen($theme['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w');
1906 1980
 		fwrite($fp, file_get_contents($filename));
1907 1981
 		fclose($fp);
1908 1982
 
1909 1983
 		redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy');
1910
-	}
1911
-	elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1984
+	} elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1912 1985
 	{
1913
-		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'))
1914
-			$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1915
-
1916
-		else
1917
-			fatal_lang_error('no_access', false);
1986
+		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) {
1987
+					$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1988
+		} else {
1989
+					fatal_lang_error('no_access', false);
1990
+		}
1918 1991
 
1919 1992
 		$fp = fopen($theme['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w');
1920 1993
 		fwrite($fp, file_get_contents($filename));
@@ -1929,16 +2002,18 @@  discard block
 block discarded – undo
1929 2002
 	$dir = dir($settings['default_theme_dir']);
1930 2003
 	while ($entry = $dir->read())
1931 2004
 	{
1932
-		if (substr($entry, -13) == '.template.php')
1933
-			$templates[] = substr($entry, 0, -13);
2005
+		if (substr($entry, -13) == '.template.php') {
2006
+					$templates[] = substr($entry, 0, -13);
2007
+		}
1934 2008
 	}
1935 2009
 	$dir->close();
1936 2010
 
1937 2011
 	$dir = dir($settings['default_theme_dir'] . '/languages');
1938 2012
 	while ($entry = $dir->read())
1939 2013
 	{
1940
-		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches))
1941
-			$lang_files[] = $matches[1];
2014
+		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) {
2015
+					$lang_files[] = $matches[1];
2016
+		}
1942 2017
 	}
1943 2018
 	$dir->close();
1944 2019
 
@@ -1946,21 +2021,23 @@  discard block
 block discarded – undo
1946 2021
 	natcasesort($lang_files);
1947 2022
 
1948 2023
 	$context['available_templates'] = array();
1949
-	foreach ($templates as $template)
1950
-		$context['available_templates'][$template] = array(
2024
+	foreach ($templates as $template) {
2025
+			$context['available_templates'][$template] = array(
1951 2026
 			'filename' => $template . '.template.php',
1952 2027
 			'value' => $template,
1953 2028
 			'already_exists' => false,
1954 2029
 			'can_copy' => is_writable($theme['theme_dir']),
1955 2030
 		);
2031
+	}
1956 2032
 	$context['available_language_files'] = array();
1957
-	foreach ($lang_files as $file)
1958
-		$context['available_language_files'][$file] = array(
2033
+	foreach ($lang_files as $file) {
2034
+			$context['available_language_files'][$file] = array(
1959 2035
 			'filename' => $file . '.php',
1960 2036
 			'value' => $file,
1961 2037
 			'already_exists' => false,
1962 2038
 			'can_copy' => file_exists($theme['theme_dir'] . '/languages') ? is_writable($theme['theme_dir'] . '/languages') : is_writable($theme['theme_dir']),
1963 2039
 		);
2040
+	}
1964 2041
 
1965 2042
 	$dir = dir($theme['theme_dir']);
1966 2043
 	while ($entry = $dir->read())
Please login to merge, or discard this patch.
Sources/Post.php 1 patch
Braces   +674 added lines, -521 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -58,12 +61,14 @@  discard block
 block discarded – undo
58 61
 	{
59 62
 		// Get ids of all the boards they can post in.
60 63
 		$post_permissions = array('post_new');
61
-		if ($modSettings['postmod_active'])
62
-			$post_permissions[] = 'post_unapproved_topics';
64
+		if ($modSettings['postmod_active']) {
65
+					$post_permissions[] = 'post_unapproved_topics';
66
+		}
63 67
 
64 68
 		$boards = boardsAllowedTo($post_permissions);
65
-		if (empty($boards))
66
-			fatal_lang_error('cannot_post_new', false);
69
+		if (empty($boards)) {
70
+					fatal_lang_error('cannot_post_new', false);
71
+		}
67 72
 
68 73
 		// Get a list of boards for the select menu
69 74
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -76,8 +81,9 @@  discard block
 block discarded – undo
76 81
 		$board_list = getBoardList($boardListOptions);
77 82
 	}
78 83
 	// Let's keep things simple for ourselves below
79
-	else
80
-		$boards = array($board);
84
+	else {
85
+			$boards = array($board);
86
+	}
81 87
 
82 88
 	require_once($sourcedir . '/Subs-Post.php');
83 89
 
@@ -100,10 +106,11 @@  discard block
 block discarded – undo
100 106
 			array(
101 107
 				'msg' => (int) $_REQUEST['msg'],
102 108
 		));
103
-		if ($smcFunc['db_num_rows']($request) != 1)
104
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
105
-		else
106
-			list ($topic) = $smcFunc['db_fetch_row']($request);
109
+		if ($smcFunc['db_num_rows']($request) != 1) {
110
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
111
+		} else {
112
+					list ($topic) = $smcFunc['db_fetch_row']($request);
113
+		}
107 114
 		$smcFunc['db_free_result']($request);
108 115
 	}
109 116
 
@@ -130,33 +137,36 @@  discard block
 block discarded – undo
130 137
 		$smcFunc['db_free_result']($request);
131 138
 
132 139
 		// If this topic already has a poll, they sure can't add another.
133
-		if (isset($_REQUEST['poll']) && $pollID > 0)
134
-			unset($_REQUEST['poll']);
140
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
141
+					unset($_REQUEST['poll']);
142
+		}
135 143
 
136 144
 		if (empty($_REQUEST['msg']))
137 145
 		{
138
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
139
-				is_not_guest();
146
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
147
+							is_not_guest();
148
+			}
140 149
 
141 150
 			// By default the reply will be approved...
142 151
 			$context['becomes_approved'] = true;
143 152
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
144 153
 			{
145
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
146
-					$context['becomes_approved'] = false;
147
-				else
148
-					isAllowedTo('post_reply_any');
149
-			}
150
-			elseif (!allowedTo('post_reply_any'))
154
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
155
+									$context['becomes_approved'] = false;
156
+				} else {
157
+									isAllowedTo('post_reply_any');
158
+				}
159
+			} elseif (!allowedTo('post_reply_any'))
151 160
 			{
152
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
153
-					$context['becomes_approved'] = false;
154
-				else
155
-					isAllowedTo('post_reply_own');
161
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
162
+									$context['becomes_approved'] = false;
163
+				} else {
164
+									isAllowedTo('post_reply_own');
165
+				}
156 166
 			}
167
+		} else {
168
+					$context['becomes_approved'] = true;
157 169
 		}
158
-		else
159
-			$context['becomes_approved'] = true;
160 170
 
161 171
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
162 172
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -171,17 +181,18 @@  discard block
 block discarded – undo
171 181
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
172 182
 
173 183
 		// Check whether this is a really old post being bumped...
174
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
175
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
176
-	}
177
-	else
184
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
185
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
186
+		}
187
+	} else
178 188
 	{
179 189
 		// @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu
180 190
 		$context['becomes_approved'] = true;
181
-		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true))
182
-			$context['becomes_approved'] = false;
183
-		else
184
-			isAllowedTo('post_new', $boards, true);
191
+		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) {
192
+					$context['becomes_approved'] = false;
193
+		} else {
194
+					isAllowedTo('post_new', $boards, true);
195
+		}
185 196
 
186 197
 		$locked = 0;
187 198
 		$context['already_locked'] = 0;
@@ -211,27 +222,32 @@  discard block
 block discarded – undo
211 222
 	if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached']))
212 223
 	{
213 224
 		require_once($sourcedir . '/ManageAttachments.php');
214
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
215
-			removeAttachments(array('id_attach' => $attachID));
225
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
226
+					removeAttachments(array('id_attach' => $attachID));
227
+		}
216 228
 
217 229
 		unset($_SESSION['already_attached']);
218 230
 	}
219 231
 
220 232
 	// Don't allow a post if it's locked and you aren't all powerful.
221
-	if ($locked && !allowedTo('moderate_board'))
222
-		fatal_lang_error('topic_locked', false);
233
+	if ($locked && !allowedTo('moderate_board')) {
234
+			fatal_lang_error('topic_locked', false);
235
+	}
223 236
 	// Check the users permissions - is the user allowed to add or post a poll?
224 237
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
225 238
 	{
226 239
 		// New topic, new poll.
227
-		if (empty($topic))
228
-			isAllowedTo('poll_post');
240
+		if (empty($topic)) {
241
+					isAllowedTo('poll_post');
242
+		}
229 243
 		// This is an old topic - but it is yours!  Can you add to it?
230
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
231
-			isAllowedTo('poll_add_own');
244
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
245
+					isAllowedTo('poll_add_own');
246
+		}
232 247
 		// If you're not the owner, can you add to any poll?
233
-		else
234
-			isAllowedTo('poll_add_any');
248
+		else {
249
+					isAllowedTo('poll_add_any');
250
+		}
235 251
 
236 252
 		if (!empty($board))
237 253
 		{
@@ -240,8 +256,9 @@  discard block
 block discarded – undo
240 256
 			$guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']);
241 257
 		}
242 258
 		// No board, so we'll have to check this again in Post2
243
-		else
244
-			$guest_vote_enabled = true;
259
+		else {
260
+					$guest_vote_enabled = true;
261
+		}
245 262
 
246 263
 		// Set up the poll options.
247 264
 		$context['poll_options'] = array(
@@ -267,8 +284,9 @@  discard block
 block discarded – undo
267 284
 	if ($context['make_event'])
268 285
 	{
269 286
 		// They might want to pick a board.
270
-		if (!isset($context['current_board']))
271
-			$context['current_board'] = 0;
287
+		if (!isset($context['current_board'])) {
288
+					$context['current_board'] = 0;
289
+		}
272 290
 
273 291
 		// Start loading up the event info.
274 292
 		$context['event'] = array();
@@ -282,10 +300,11 @@  discard block
 block discarded – undo
282 300
 		isAllowedTo('calendar_post');
283 301
 
284 302
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
285
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
286
-			$time_string = '%k:%M';
287
-		else
288
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
303
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
304
+					$time_string = '%k:%M';
305
+		} else {
306
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
307
+		}
289 308
 
290 309
 		$js_time_string = str_replace(
291 310
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -307,8 +326,7 @@  discard block
 block discarded – undo
307 326
 			require_once($sourcedir . '/Subs-Calendar.php');
308 327
 			$eventProperties = getEventProperties($context['event']['id']);
309 328
 			$context['event'] = array_merge($context['event'], $eventProperties);
310
-		}
311
-		else
329
+		} else
312 330
 		{
313 331
 			// Get the current event information.
314 332
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -316,10 +334,12 @@  discard block
 block discarded – undo
316 334
 			$context['event'] = array_merge($context['event'], $eventProperties);
317 335
 
318 336
 			// Make sure the year and month are in the valid range.
319
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
320
-				fatal_lang_error('invalid_month', false);
321
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
322
-				fatal_lang_error('invalid_year', false);
337
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
338
+							fatal_lang_error('invalid_month', false);
339
+			}
340
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
341
+							fatal_lang_error('invalid_year', false);
342
+			}
323 343
 
324 344
 			$context['event']['categories'] = $board_list;
325 345
 		}
@@ -430,10 +450,11 @@  discard block
 block discarded – undo
430 450
 
431 451
 			if (!empty($context['new_replies']))
432 452
 			{
433
-				if ($context['new_replies'] == 1)
434
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
435
-				else
436
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
453
+				if ($context['new_replies'] == 1) {
454
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
455
+				} else {
456
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
457
+				}
437 458
 
438 459
 				$post_errors[] = 'new_replies';
439 460
 
@@ -445,9 +466,9 @@  discard block
 block discarded – undo
445 466
 	// Get a response prefix (like 'Re:') in the default forum language.
446 467
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
447 468
 	{
448
-		if ($language === $user_info['language'])
449
-			$context['response_prefix'] = $txt['response_prefix'];
450
-		else
469
+		if ($language === $user_info['language']) {
470
+					$context['response_prefix'] = $txt['response_prefix'];
471
+		} else
451 472
 		{
452 473
 			loadLanguage('index', $language, false);
453 474
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -460,23 +481,26 @@  discard block
 block discarded – undo
460 481
 	// Do we have a body, but an error happened.
461 482
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
462 483
 	{
463
-		if (isset($_REQUEST['quickReply']))
464
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
484
+		if (isset($_REQUEST['quickReply'])) {
485
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
486
+		}
465 487
 
466 488
 		// Validate inputs.
467 489
 		if (empty($context['post_error']))
468 490
 		{
469 491
 			// This means they didn't click Post and get an error.
470 492
 			$really_previewing = true;
471
-		}
472
-		else
493
+		} else
473 494
 		{
474
-			if (!isset($_REQUEST['subject']))
475
-				$_REQUEST['subject'] = '';
476
-			if (!isset($_REQUEST['message']))
477
-				$_REQUEST['message'] = '';
478
-			if (!isset($_REQUEST['icon']))
479
-				$_REQUEST['icon'] = 'xx';
495
+			if (!isset($_REQUEST['subject'])) {
496
+							$_REQUEST['subject'] = '';
497
+			}
498
+			if (!isset($_REQUEST['message'])) {
499
+							$_REQUEST['message'] = '';
500
+			}
501
+			if (!isset($_REQUEST['icon'])) {
502
+							$_REQUEST['icon'] = 'xx';
503
+			}
480 504
 
481 505
 			// They are previewing if they asked to preview (i.e. came from quick reply).
482 506
 			$really_previewing = !empty($_POST['preview']);
@@ -492,8 +516,9 @@  discard block
 block discarded – undo
492 516
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
493 517
 
494 518
 		// Make sure the subject isn't too long - taking into account special characters.
495
-		if ($smcFunc['strlen']($form_subject) > 100)
496
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
519
+		if ($smcFunc['strlen']($form_subject) > 100) {
520
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
521
+		}
497 522
 
498 523
 		if (isset($_REQUEST['poll']))
499 524
 		{
@@ -505,8 +530,9 @@  discard block
 block discarded – undo
505 530
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
506 531
 			foreach ($_POST['options'] as $option)
507 532
 			{
508
-				if (trim($option) == '')
509
-					continue;
533
+				if (trim($option) == '') {
534
+									continue;
535
+				}
510 536
 
511 537
 				$context['choices'][] = array(
512 538
 					'id' => $choice_id++,
@@ -568,13 +594,14 @@  discard block
 block discarded – undo
568 594
 				$context['preview_subject'] = $form_subject;
569 595
 
570 596
 				censorText($context['preview_subject']);
597
+			} else {
598
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
571 599
 			}
572
-			else
573
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
574 600
 
575 601
 			// Protect any CDATA blocks.
576
-			if (isset($_REQUEST['xml']))
577
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
602
+			if (isset($_REQUEST['xml'])) {
603
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
604
+			}
578 605
 		}
579 606
 
580 607
 		// Set up the checkboxes.
@@ -613,29 +640,32 @@  discard block
 block discarded – undo
613 640
 			);
614 641
 			// The message they were trying to edit was most likely deleted.
615 642
 			// @todo Change this error message?
616
-			if ($smcFunc['db_num_rows']($request) == 0)
617
-				fatal_lang_error('no_board', false);
643
+			if ($smcFunc['db_num_rows']($request) == 0) {
644
+							fatal_lang_error('no_board', false);
645
+			}
618 646
 			$row = $smcFunc['db_fetch_assoc']($request);
619 647
 
620 648
 			$attachment_stuff = array($row);
621
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
622
-				$attachment_stuff[] = $row2;
649
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
650
+							$attachment_stuff[] = $row2;
651
+			}
623 652
 			$smcFunc['db_free_result']($request);
624 653
 
625 654
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
626 655
 			{
627 656
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
628
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
629
-					fatal_lang_error('modify_post_time_passed', false);
630
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
631
-					isAllowedTo('modify_replies');
632
-				else
633
-					isAllowedTo('modify_own');
657
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
658
+									fatal_lang_error('modify_post_time_passed', false);
659
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
660
+									isAllowedTo('modify_replies');
661
+				} else {
662
+									isAllowedTo('modify_own');
663
+				}
664
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
665
+							isAllowedTo('modify_replies');
666
+			} else {
667
+							isAllowedTo('modify_any');
634 668
 			}
635
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
636
-				isAllowedTo('modify_replies');
637
-			else
638
-				isAllowedTo('modify_any');
639 669
 
640 670
 			if ($context['can_announce'] && !empty($row['id_action']))
641 671
 			{
@@ -659,8 +689,9 @@  discard block
 block discarded – undo
659 689
 
660 690
 				while ($row = $smcFunc['db_fetch_assoc']($request))
661 691
 				{
662
-					if ($row['filesize'] <= 0)
663
-						continue;
692
+					if ($row['filesize'] <= 0) {
693
+											continue;
694
+					}
664 695
 					$context['current_attachments'][$row['id_attach']] = array(
665 696
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
666 697
 						'size' => $row['filesize'],
@@ -730,29 +761,32 @@  discard block
 block discarded – undo
730 761
 			)
731 762
 		);
732 763
 		// The message they were trying to edit was most likely deleted.
733
-		if ($smcFunc['db_num_rows']($request) == 0)
734
-			fatal_lang_error('no_message', false);
764
+		if ($smcFunc['db_num_rows']($request) == 0) {
765
+					fatal_lang_error('no_message', false);
766
+		}
735 767
 		$row = $smcFunc['db_fetch_assoc']($request);
736 768
 
737 769
 		$attachment_stuff = array($row);
738
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
739
-			$attachment_stuff[] = $row2;
770
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
771
+					$attachment_stuff[] = $row2;
772
+		}
740 773
 		$smcFunc['db_free_result']($request);
741 774
 
742 775
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
743 776
 		{
744 777
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
745
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
746
-				fatal_lang_error('modify_post_time_passed', false);
747
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
748
-				isAllowedTo('modify_replies');
749
-			else
750
-				isAllowedTo('modify_own');
778
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
779
+							fatal_lang_error('modify_post_time_passed', false);
780
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
781
+							isAllowedTo('modify_replies');
782
+			} else {
783
+							isAllowedTo('modify_own');
784
+			}
785
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
786
+					isAllowedTo('modify_replies');
787
+		} else {
788
+					isAllowedTo('modify_any');
751 789
 		}
752
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
753
-			isAllowedTo('modify_replies');
754
-		else
755
-			isAllowedTo('modify_any');
756 790
 
757 791
 		if ($context['can_announce'] && !empty($row['id_action']))
758 792
 		{
@@ -779,15 +813,17 @@  discard block
 block discarded – undo
779 813
 		$context['icon'] = $row['icon'];
780 814
 
781 815
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
782
-		if (!$row['approved'] && !$context['show_approval'])
783
-			$context['show_approval'] = allowedTo('approve_posts');
816
+		if (!$row['approved'] && !$context['show_approval']) {
817
+					$context['show_approval'] = allowedTo('approve_posts');
818
+		}
784 819
 
785 820
 		// Sort the attachments so they are in the order saved
786 821
 		$temp = array();
787 822
 		foreach ($attachment_stuff as $attachment)
788 823
 		{
789
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
790
-				$temp[$attachment['id_attach']] = $attachment;
824
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
825
+							$temp[$attachment['id_attach']] = $attachment;
826
+			}
791 827
 
792 828
 		}
793 829
 		ksort($temp);
@@ -849,14 +885,16 @@  discard block
 block discarded – undo
849 885
 					'is_approved' => 1,
850 886
 				)
851 887
 			);
852
-			if ($smcFunc['db_num_rows']($request) == 0)
853
-				fatal_lang_error('quoted_post_deleted', false);
888
+			if ($smcFunc['db_num_rows']($request) == 0) {
889
+							fatal_lang_error('quoted_post_deleted', false);
890
+			}
854 891
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
855 892
 			$smcFunc['db_free_result']($request);
856 893
 
857 894
 			// Add 'Re: ' to the front of the quoted subject.
858
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
859
-				$form_subject = $context['response_prefix'] . $form_subject;
895
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
896
+							$form_subject = $context['response_prefix'] . $form_subject;
897
+			}
860 898
 
861 899
 			// Censor the message and subject.
862 900
 			censorText($form_message);
@@ -869,10 +907,11 @@  discard block
 block discarded – undo
869 907
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
870 908
 				{
871 909
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
872
-					if ($i % 4 == 0)
873
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
910
+					if ($i % 4 == 0) {
911
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
874 912
 						{
875 913
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
914
+					}
876 915
 						}, $parts[$i]);
877 916
 				}
878 917
 				$form_message = implode('', $parts);
@@ -881,8 +920,9 @@  discard block
 block discarded – undo
881 920
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
882 921
 
883 922
 			// Remove any nested quotes, if necessary.
884
-			if (!empty($modSettings['removeNestedQuotes']))
885
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
923
+			if (!empty($modSettings['removeNestedQuotes'])) {
924
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
925
+			}
886 926
 
887 927
 			// Add a quote string on the front and end.
888 928
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -894,15 +934,15 @@  discard block
 block discarded – undo
894 934
 			$form_subject = $first_subject;
895 935
 
896 936
 			// Add 'Re: ' to the front of the subject.
897
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
898
-				$form_subject = $context['response_prefix'] . $form_subject;
937
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
938
+							$form_subject = $context['response_prefix'] . $form_subject;
939
+			}
899 940
 
900 941
 			// Censor the subject.
901 942
 			censorText($form_subject);
902 943
 
903 944
 			$form_message = '';
904
-		}
905
-		else
945
+		} else
906 946
 		{
907 947
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
908 948
 			$form_message = '';
@@ -921,13 +961,15 @@  discard block
 block discarded – undo
921 961
 		if (isset($_REQUEST['msg']))
922 962
 		{
923 963
 			$context['attachments']['quantity'] = count($context['current_attachments']);
924
-			foreach ($context['current_attachments'] as $attachment)
925
-				$context['attachments']['total_size'] += $attachment['size'];
964
+			foreach ($context['current_attachments'] as $attachment) {
965
+							$context['attachments']['total_size'] += $attachment['size'];
966
+			}
926 967
 		}
927 968
 
928 969
 		// A bit of house keeping first.
929
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
930
-			unset($_SESSION['temp_attachments']);
970
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
971
+					unset($_SESSION['temp_attachments']);
972
+		}
931 973
 
932 974
 		if (!empty($_SESSION['temp_attachments']))
933 975
 		{
@@ -936,9 +978,10 @@  discard block
 block discarded – undo
936 978
 			{
937 979
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
938 980
 				{
939
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
940
-						if (file_exists($attachment['tmp_name']))
981
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
982
+											if (file_exists($attachment['tmp_name']))
941 983
 							unlink($attachment['tmp_name']);
984
+					}
942 985
 				}
943 986
 				$post_errors[] = 'temp_attachments_gone';
944 987
 				$_SESSION['temp_attachments'] = array();
@@ -952,8 +995,9 @@  discard block
 block discarded – undo
952 995
 					// See if any files still exist before showing the warning message and the files attached.
953 996
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
954 997
 					{
955
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
956
-							continue;
998
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
999
+													continue;
1000
+						}
957 1001
 
958 1002
 						if (file_exists($attachment['tmp_name']))
959 1003
 						{
@@ -963,20 +1007,21 @@  discard block
 block discarded – undo
963 1007
 							break;
964 1008
 						}
965 1009
 					}
966
-				}
967
-				else
1010
+				} else
968 1011
 				{
969 1012
 					// Since, they don't belong here. Let's inform the user that they exist..
970
-					if (!empty($topic))
971
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
972
-					else
973
-						$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1013
+					if (!empty($topic)) {
1014
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
1015
+					} else {
1016
+											$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1017
+					}
974 1018
 
975 1019
 					// Compile a list of the files to show the user.
976 1020
 					$file_list = array();
977
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
978
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1021
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1022
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
979 1023
 							$file_list[] = $attachment['name'];
1024
+					}
980 1025
 
981 1026
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
982 1027
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -988,8 +1033,7 @@  discard block
 block discarded – undo
988 1033
 
989 1034
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
990 1035
 						$context['ignore_temp_attachments'] = true;
991
-					}
992
-					else
1036
+					} else
993 1037
 					{
994 1038
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
995 1039
 						$context['ignore_temp_attachments'] = true;
@@ -997,16 +1041,19 @@  discard block
 block discarded – undo
997 1041
 				}
998 1042
 			}
999 1043
 
1000
-			if (!empty($context['we_are_history']))
1001
-				$post_errors[] = $context['we_are_history'];
1044
+			if (!empty($context['we_are_history'])) {
1045
+							$post_errors[] = $context['we_are_history'];
1046
+			}
1002 1047
 
1003 1048
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1004 1049
 			{
1005
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
1006
-					break;
1050
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1051
+									break;
1052
+				}
1007 1053
 
1008
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1009
-					continue;
1054
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1055
+									continue;
1056
+				}
1010 1057
 
1011 1058
 				if ($attachID == 'initial_error')
1012 1059
 				{
@@ -1021,15 +1068,17 @@  discard block
 block discarded – undo
1021 1068
 				{
1022 1069
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1023 1070
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1024
-					foreach ($attachment['errors'] as $error)
1025
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1071
+					foreach ($attachment['errors'] as $error) {
1072
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1073
+					}
1026 1074
 					$txt['error_attach_errors'] .= '</div>';
1027 1075
 					$post_errors[] = 'attach_errors';
1028 1076
 
1029 1077
 					// Take out the trash.
1030 1078
 					unset($_SESSION['temp_attachments'][$attachID]);
1031
-					if (file_exists($attachment['tmp_name']))
1032
-						unlink($attachment['tmp_name']);
1079
+					if (file_exists($attachment['tmp_name'])) {
1080
+											unlink($attachment['tmp_name']);
1081
+					}
1033 1082
 					continue;
1034 1083
 				}
1035 1084
 
@@ -1042,8 +1091,9 @@  discard block
 block discarded – undo
1042 1091
 
1043 1092
 				$context['attachments']['quantity']++;
1044 1093
 				$context['attachments']['total_size'] += $attachment['size'];
1045
-				if (!isset($context['files_in_session_warning']))
1046
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1094
+				if (!isset($context['files_in_session_warning'])) {
1095
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1096
+				}
1047 1097
 
1048 1098
 				$context['current_attachments'][$attachID] = array(
1049 1099
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1071,8 +1121,9 @@  discard block
 block discarded – undo
1071 1121
 	}
1072 1122
 
1073 1123
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1074
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1075
-		$post_errors[] = 'need_qr_verification';
1124
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1125
+			$post_errors[] = 'need_qr_verification';
1126
+	}
1076 1127
 
1077 1128
 	/*
1078 1129
 	 * There are two error types: serious and minor. Serious errors
@@ -1089,52 +1140,56 @@  discard block
 block discarded – undo
1089 1140
 	{
1090 1141
 		loadLanguage('Errors');
1091 1142
 		$context['error_type'] = 'minor';
1092
-		foreach ($post_errors as $post_error)
1093
-			if (is_array($post_error))
1143
+		foreach ($post_errors as $post_error) {
1144
+					if (is_array($post_error))
1094 1145
 			{
1095 1146
 				$post_error_id = $post_error[0];
1147
+		}
1096 1148
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1097 1149
 
1098 1150
 				// If it's not a minor error flag it as such.
1099
-				if (!in_array($post_error_id, $minor_errors))
1100
-					$context['error_type'] = 'serious';
1101
-			}
1102
-			else
1151
+				if (!in_array($post_error_id, $minor_errors)) {
1152
+									$context['error_type'] = 'serious';
1153
+				}
1154
+			} else
1103 1155
 			{
1104 1156
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1105 1157
 
1106 1158
 				// If it's not a minor error flag it as such.
1107
-				if (!in_array($post_error, $minor_errors))
1108
-					$context['error_type'] = 'serious';
1159
+				if (!in_array($post_error, $minor_errors)) {
1160
+									$context['error_type'] = 'serious';
1161
+				}
1109 1162
 			}
1110 1163
 	}
1111 1164
 
1112 1165
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1113
-	if (isset($_REQUEST['poll']))
1114
-		$context['page_title'] = $txt['new_poll'];
1115
-	elseif ($context['make_event'])
1116
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1117
-	elseif (isset($_REQUEST['msg']))
1118
-		$context['page_title'] = $txt['modify_msg'];
1119
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1120
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1121
-	elseif (empty($topic))
1122
-		$context['page_title'] = $txt['start_new_topic'];
1123
-	else
1124
-		$context['page_title'] = $txt['post_reply'];
1166
+	if (isset($_REQUEST['poll'])) {
1167
+			$context['page_title'] = $txt['new_poll'];
1168
+	} elseif ($context['make_event']) {
1169
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1170
+	} elseif (isset($_REQUEST['msg'])) {
1171
+			$context['page_title'] = $txt['modify_msg'];
1172
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1173
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1174
+	} elseif (empty($topic)) {
1175
+			$context['page_title'] = $txt['start_new_topic'];
1176
+	} else {
1177
+			$context['page_title'] = $txt['post_reply'];
1178
+	}
1125 1179
 
1126 1180
 	// Build the link tree.
1127
-	if (empty($topic))
1128
-		$context['linktree'][] = array(
1181
+	if (empty($topic)) {
1182
+			$context['linktree'][] = array(
1129 1183
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1130 1184
 		);
1131
-	else
1132
-		$context['linktree'][] = array(
1185
+	} else {
1186
+			$context['linktree'][] = array(
1133 1187
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1134 1188
 			'name' => $form_subject,
1135 1189
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1136 1190
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1137 1191
 		);
1192
+	}
1138 1193
 
1139 1194
 	$context['subject'] = addcslashes($form_subject, '"');
1140 1195
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1178,8 +1233,9 @@  discard block
 block discarded – undo
1178 1233
 	// Message icons - customized icons are off?
1179 1234
 	$context['icons'] = getMessageIcons(!empty($board) ? $board : 0);
1180 1235
 
1181
-	if (!empty($context['icons']))
1182
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1236
+	if (!empty($context['icons'])) {
1237
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1238
+	}
1183 1239
 
1184 1240
 	// Are we starting a poll? if set the poll icon as selected if its available
1185 1241
 	if (isset($_REQUEST['poll']))
@@ -1199,8 +1255,9 @@  discard block
 block discarded – undo
1199 1255
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1200 1256
 	{
1201 1257
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1202
-		if ($context['icons'][$i]['selected'])
1203
-			$context['icon_url'] = $context['icons'][$i]['url'];
1258
+		if ($context['icons'][$i]['selected']) {
1259
+					$context['icon_url'] = $context['icons'][$i]['url'];
1260
+		}
1204 1261
 	}
1205 1262
 	if (empty($context['icon_url']))
1206 1263
 	{
@@ -1214,8 +1271,9 @@  discard block
 block discarded – undo
1214 1271
 		));
1215 1272
 	}
1216 1273
 
1217
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1218
-		getTopic();
1274
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1275
+			getTopic();
1276
+	}
1219 1277
 
1220 1278
 	// If the user can post attachments prepare the warning labels.
1221 1279
 	if ($context['can_post_attachment'])
@@ -1226,12 +1284,13 @@  discard block
 block discarded – undo
1226 1284
 		$context['attachment_restrictions'] = array();
1227 1285
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1228 1286
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1229
-		foreach ($attachmentRestrictionTypes as $type)
1230
-			if (!empty($modSettings[$type]))
1287
+		foreach ($attachmentRestrictionTypes as $type) {
1288
+					if (!empty($modSettings[$type]))
1231 1289
 			{
1232 1290
 				// Show the max number of attachments if not 0.
1233 1291
 				if ($type == 'attachmentNumPerPostLimit')
1234 1292
 					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1293
+		}
1235 1294
 			}
1236 1295
 	}
1237 1296
 
@@ -1265,8 +1324,8 @@  discard block
 block discarded – undo
1265 1324
 
1266 1325
 	if (!empty($context['current_attachments']))
1267 1326
 	{
1268
-		foreach ($context['current_attachments'] as $key => $mock)
1269
-			addInlineJavaScript('
1327
+		foreach ($context['current_attachments'] as $key => $mock) {
1328
+					addInlineJavaScript('
1270 1329
 	current_attachments.push({
1271 1330
 		name: '. JavaScriptEscape($mock['name']) . ',
1272 1331
 		size: '. $mock['size'] . ',
@@ -1275,6 +1334,7 @@  discard block
 block discarded – undo
1275 1334
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1276 1335
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1277 1336
 	});', true);
1337
+		}
1278 1338
 	}
1279 1339
 
1280 1340
 	// File Upload.
@@ -1349,9 +1409,10 @@  discard block
 block discarded – undo
1349 1409
 			$context['posting_fields']['board']['dd'] .= '
1350 1410
 							<optgroup label="' . $category['name'] . '">';
1351 1411
 
1352
-			foreach ($category['boards'] as $brd)
1353
-				$context['posting_fields']['board']['dd'] .= '
1412
+			foreach ($category['boards'] as $brd) {
1413
+							$context['posting_fields']['board']['dd'] .= '
1354 1414
 								<option value="' . $brd['id'] . '"' . ($brd['selected'] ? ' selected' : '') . '>' . ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=&gt;' : '') . ' ' . $brd['name'] . '</option>';
1415
+			}
1355 1416
 
1356 1417
 			$context['posting_fields']['board']['dd'] .= '
1357 1418
 							</optgroup>';
@@ -1382,8 +1443,9 @@  discard block
 block discarded – undo
1382 1443
 
1383 1444
 
1384 1445
 	// Finally, load the template.
1385
-	if (!isset($_REQUEST['xml']))
1386
-		loadTemplate('Post');
1446
+	if (!isset($_REQUEST['xml'])) {
1447
+			loadTemplate('Post');
1448
+	}
1387 1449
 
1388 1450
 	call_integration_hook('integrate_post_end');
1389 1451
 }
@@ -1404,13 +1466,14 @@  discard block
 block discarded – undo
1404 1466
 	// Sneaking off, are we?
1405 1467
 	if (empty($_POST) && empty($topic))
1406 1468
 	{
1407
-		if (empty($_SERVER['CONTENT_LENGTH']))
1408
-			redirectexit('action=post;board=' . $board . '.0');
1409
-		else
1410
-			fatal_lang_error('post_upload_error', false);
1469
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1470
+					redirectexit('action=post;board=' . $board . '.0');
1471
+		} else {
1472
+					fatal_lang_error('post_upload_error', false);
1473
+		}
1474
+	} elseif (empty($_POST) && !empty($topic)) {
1475
+			redirectexit('action=post;topic=' . $topic . '.0');
1411 1476
 	}
1412
-	elseif (empty($_POST) && !empty($topic))
1413
-		redirectexit('action=post;topic=' . $topic . '.0');
1414 1477
 
1415 1478
 	// No need!
1416 1479
 	$context['robot_no_index'] = true;
@@ -1422,8 +1485,9 @@  discard block
 block discarded – undo
1422 1485
 	$post_errors = array();
1423 1486
 
1424 1487
 	// If the session has timed out, let the user re-submit their form.
1425
-	if (checkSession('post', '', false) != '')
1426
-		$post_errors[] = 'session_timeout';
1488
+	if (checkSession('post', '', false) != '') {
1489
+			$post_errors[] = 'session_timeout';
1490
+	}
1427 1491
 
1428 1492
 	// Wrong verification code?
1429 1493
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1433,33 +1497,38 @@  discard block
 block discarded – undo
1433 1497
 			'id' => 'post',
1434 1498
 		);
1435 1499
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1436
-		if (is_array($context['require_verification']))
1437
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1500
+		if (is_array($context['require_verification'])) {
1501
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1502
+		}
1438 1503
 	}
1439 1504
 
1440 1505
 	require_once($sourcedir . '/Subs-Post.php');
1441 1506
 	loadLanguage('Post');
1442 1507
 
1443 1508
 	// Drafts enabled and needed?
1444
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1445
-		require_once($sourcedir . '/Drafts.php');
1509
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1510
+			require_once($sourcedir . '/Drafts.php');
1511
+	}
1446 1512
 
1447 1513
 	// First check to see if they are trying to delete any current attachments.
1448 1514
 	if (isset($_POST['attach_del']))
1449 1515
 	{
1450 1516
 		$keep_temp = array();
1451 1517
 		$keep_ids = array();
1452
-		foreach ($_POST['attach_del'] as $dummy)
1453
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1518
+		foreach ($_POST['attach_del'] as $dummy) {
1519
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1454 1520
 				$keep_temp[] = $dummy;
1455
-			else
1456
-				$keep_ids[] = (int) $dummy;
1521
+		}
1522
+			else {
1523
+							$keep_ids[] = (int) $dummy;
1524
+			}
1457 1525
 
1458
-		if (isset($_SESSION['temp_attachments']))
1459
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1526
+		if (isset($_SESSION['temp_attachments'])) {
1527
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1460 1528
 			{
1461 1529
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1462 1530
 					continue;
1531
+		}
1463 1532
 
1464 1533
 				unset($_SESSION['temp_attachments'][$attachID]);
1465 1534
 				unlink($attachment['tmp_name']);
@@ -1491,8 +1560,9 @@  discard block
 block discarded – undo
1491 1560
 	{
1492 1561
 		require_once($sourcedir . '/ManageAttachments.php');
1493 1562
 
1494
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
1495
-			removeAttachments(array('id_attach' => $attachID));
1563
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
1564
+					removeAttachments(array('id_attach' => $attachID));
1565
+		}
1496 1566
 
1497 1567
 		unset($_SESSION['already_attached']);
1498 1568
 
@@ -1515,12 +1585,14 @@  discard block
 block discarded – undo
1515 1585
 		$smcFunc['db_free_result']($request);
1516 1586
 
1517 1587
 		// Though the topic should be there, it might have vanished.
1518
-		if (!is_array($topic_info))
1519
-			fatal_lang_error('topic_doesnt_exist', 404);
1588
+		if (!is_array($topic_info)) {
1589
+					fatal_lang_error('topic_doesnt_exist', 404);
1590
+		}
1520 1591
 
1521 1592
 		// Did this topic suddenly move? Just checking...
1522
-		if ($topic_info['id_board'] != $board)
1523
-			fatal_lang_error('not_a_topic');
1593
+		if ($topic_info['id_board'] != $board) {
1594
+					fatal_lang_error('not_a_topic');
1595
+		}
1524 1596
 
1525 1597
 		// Do the permissions and approval stuff...
1526 1598
 		$becomesApproved = true;
@@ -1543,49 +1615,50 @@  discard block
 block discarded – undo
1543 1615
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1544 1616
 	{
1545 1617
 		// Don't allow a post if it's locked.
1546
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1547
-			fatal_lang_error('topic_locked', false);
1618
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1619
+					fatal_lang_error('topic_locked', false);
1620
+		}
1548 1621
 
1549 1622
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1550
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1551
-			unset($_REQUEST['poll']);
1552
-
1553
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1554
-		{
1555
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1556
-				$becomesApproved = false;
1557
-
1558
-			else
1559
-				isAllowedTo('post_reply_any');
1560
-		}
1561
-		elseif (!allowedTo('post_reply_any'))
1623
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1624
+					unset($_REQUEST['poll']);
1625
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1626
+		{
1627
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1628
+							$becomesApproved = false;
1629
+			} else {
1630
+							isAllowedTo('post_reply_any');
1631
+			}
1632
+		} elseif (!allowedTo('post_reply_any'))
1562 1633
 		{
1563
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1564
-				$becomesApproved = false;
1565
-
1566
-			else
1567
-				isAllowedTo('post_reply_own');
1634
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1635
+							$becomesApproved = false;
1636
+			} else {
1637
+							isAllowedTo('post_reply_own');
1638
+			}
1568 1639
 		}
1569 1640
 
1570 1641
 		if (isset($_POST['lock']))
1571 1642
 		{
1572 1643
 			// Nothing is changed to the lock.
1573
-			if (empty($topic_info['locked']) == empty($_POST['lock']))
1574
-				unset($_POST['lock']);
1644
+			if (empty($topic_info['locked']) == empty($_POST['lock'])) {
1645
+							unset($_POST['lock']);
1646
+			}
1575 1647
 
1576 1648
 			// You're have no permission to lock this topic.
1577
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1578
-				unset($_POST['lock']);
1649
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1650
+							unset($_POST['lock']);
1651
+			}
1579 1652
 
1580 1653
 			// You are allowed to (un)lock your own topic only.
1581 1654
 			elseif (!allowedTo('lock_any'))
1582 1655
 			{
1583 1656
 				// You cannot override a moderator lock.
1584
-				if ($topic_info['locked'] == 1)
1585
-					unset($_POST['lock']);
1586
-
1587
-				else
1588
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1657
+				if ($topic_info['locked'] == 1) {
1658
+									unset($_POST['lock']);
1659
+				} else {
1660
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1661
+				}
1589 1662
 			}
1590 1663
 			// Hail mighty moderator, (un)lock this topic immediately.
1591 1664
 			else
@@ -1593,19 +1666,21 @@  discard block
 block discarded – undo
1593 1666
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1594 1667
 
1595 1668
 				// Did someone (un)lock this while you were posting?
1596
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1597
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1669
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1670
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1671
+				}
1598 1672
 			}
1599 1673
 		}
1600 1674
 
1601 1675
 		// So you wanna (un)sticky this...let's see.
1602
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1603
-			unset($_POST['sticky']);
1604
-		elseif (isset($_POST['sticky']))
1676
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1677
+					unset($_POST['sticky']);
1678
+		} elseif (isset($_POST['sticky']))
1605 1679
 		{
1606 1680
 			// Did someone (un)sticky this while you were posting?
1607
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1608
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1681
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1682
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1683
+			}
1609 1684
 		}
1610 1685
 
1611 1686
 		// If drafts are enabled, then pass this off
@@ -1632,26 +1707,31 @@  discard block
 block discarded – undo
1632 1707
 
1633 1708
 		// Do like, the permissions, for safety and stuff...
1634 1709
 		$becomesApproved = true;
1635
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1636
-			$becomesApproved = false;
1637
-		else
1638
-			isAllowedTo('post_new');
1710
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1711
+					$becomesApproved = false;
1712
+		} else {
1713
+					isAllowedTo('post_new');
1714
+		}
1639 1715
 
1640 1716
 		if (isset($_POST['lock']))
1641 1717
 		{
1642 1718
 			// New topics are by default not locked.
1643
-			if (empty($_POST['lock']))
1644
-				unset($_POST['lock']);
1719
+			if (empty($_POST['lock'])) {
1720
+							unset($_POST['lock']);
1721
+			}
1645 1722
 			// Besides, you need permission.
1646
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1647
-				unset($_POST['lock']);
1723
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1724
+							unset($_POST['lock']);
1725
+			}
1648 1726
 			// A moderator-lock (1) can override a user-lock (2).
1649
-			else
1650
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1727
+			else {
1728
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1729
+			}
1651 1730
 		}
1652 1731
 
1653
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1654
-			unset($_POST['sticky']);
1732
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1733
+					unset($_POST['sticky']);
1734
+		}
1655 1735
 
1656 1736
 		// Saving your new topic as a draft first?
1657 1737
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1676,31 +1756,37 @@  discard block
 block discarded – undo
1676 1756
 				'id_msg' => $_REQUEST['msg'],
1677 1757
 			)
1678 1758
 		);
1679
-		if ($smcFunc['db_num_rows']($request) == 0)
1680
-			fatal_lang_error('cant_find_messages', false);
1759
+		if ($smcFunc['db_num_rows']($request) == 0) {
1760
+					fatal_lang_error('cant_find_messages', false);
1761
+		}
1681 1762
 		$row = $smcFunc['db_fetch_assoc']($request);
1682 1763
 		$smcFunc['db_free_result']($request);
1683 1764
 
1684
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1685
-			fatal_lang_error('topic_locked', false);
1765
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1766
+					fatal_lang_error('topic_locked', false);
1767
+		}
1686 1768
 
1687 1769
 		if (isset($_POST['lock']))
1688 1770
 		{
1689 1771
 			// Nothing changes to the lock status.
1690
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1691
-				unset($_POST['lock']);
1772
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1773
+							unset($_POST['lock']);
1774
+			}
1692 1775
 			// You're simply not allowed to (un)lock this.
1693
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1694
-				unset($_POST['lock']);
1776
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1777
+							unset($_POST['lock']);
1778
+			}
1695 1779
 			// You're only allowed to lock your own topics.
1696 1780
 			elseif (!allowedTo('lock_any'))
1697 1781
 			{
1698 1782
 				// You're not allowed to break a moderator's lock.
1699
-				if ($topic_info['locked'] == 1)
1700
-					unset($_POST['lock']);
1783
+				if ($topic_info['locked'] == 1) {
1784
+									unset($_POST['lock']);
1785
+				}
1701 1786
 				// Lock it with a soft lock or unlock it.
1702
-				else
1703
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1787
+				else {
1788
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1789
+				}
1704 1790
 			}
1705 1791
 			// You must be the moderator.
1706 1792
 			else
@@ -1708,44 +1794,46 @@  discard block
 block discarded – undo
1708 1794
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1709 1795
 
1710 1796
 				// Did someone (un)lock this while you were posting?
1711
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1712
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1797
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1798
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1799
+				}
1713 1800
 			}
1714 1801
 		}
1715 1802
 
1716 1803
 		// Change the sticky status of this topic?
1717
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1718
-			unset($_POST['sticky']);
1719
-		elseif (isset($_POST['sticky']))
1804
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1805
+					unset($_POST['sticky']);
1806
+		} elseif (isset($_POST['sticky']))
1720 1807
 		{
1721 1808
 			// Did someone (un)sticky this while you were posting?
1722
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1723
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1809
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1810
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1811
+			}
1724 1812
 		}
1725 1813
 
1726 1814
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1727 1815
 		{
1728
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1729
-				fatal_lang_error('modify_post_time_passed', false);
1730
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1731
-				isAllowedTo('modify_replies');
1732
-			else
1733
-				isAllowedTo('modify_own');
1734
-		}
1735
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1816
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1817
+							fatal_lang_error('modify_post_time_passed', false);
1818
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1819
+							isAllowedTo('modify_replies');
1820
+			} else {
1821
+							isAllowedTo('modify_own');
1822
+			}
1823
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1736 1824
 		{
1737 1825
 			isAllowedTo('modify_replies');
1738 1826
 
1739 1827
 			// If you're modifying a reply, I say it better be logged...
1740 1828
 			$moderationAction = true;
1741
-		}
1742
-		else
1829
+		} else
1743 1830
 		{
1744 1831
 			isAllowedTo('modify_any');
1745 1832
 
1746 1833
 			// Log it, assuming you're not modifying your own post.
1747
-			if ($row['id_member'] != $user_info['id'])
1748
-				$moderationAction = true;
1834
+			if ($row['id_member'] != $user_info['id']) {
1835
+							$moderationAction = true;
1836
+			}
1749 1837
 		}
1750 1838
 
1751 1839
 		// If drafts are enabled, then lets send this off to save
@@ -1784,20 +1872,24 @@  discard block
 block discarded – undo
1784 1872
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1785 1873
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1786 1874
 
1787
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1788
-			$post_errors[] = 'no_name';
1789
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1790
-			$post_errors[] = 'long_name';
1875
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1876
+					$post_errors[] = 'no_name';
1877
+		}
1878
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1879
+					$post_errors[] = 'long_name';
1880
+		}
1791 1881
 
1792 1882
 		if (empty($modSettings['guest_post_no_email']))
1793 1883
 		{
1794 1884
 			// Only check if they changed it!
1795 1885
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1796 1886
 			{
1797
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1798
-					$post_errors[] = 'no_email';
1799
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1800
-					$post_errors[] = 'bad_email';
1887
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1888
+									$post_errors[] = 'no_email';
1889
+				}
1890
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1891
+									$post_errors[] = 'bad_email';
1892
+				}
1801 1893
 			}
1802 1894
 
1803 1895
 			// Now make sure this email address is not banned from posting.
@@ -1813,75 +1905,89 @@  discard block
 block discarded – undo
1813 1905
 	}
1814 1906
 
1815 1907
 	// Coming from the quickReply?
1816
-	if (isset($_POST['quickReply']))
1817
-		$_POST['message'] = $_POST['quickReply'];
1908
+	if (isset($_POST['quickReply'])) {
1909
+			$_POST['message'] = $_POST['quickReply'];
1910
+	}
1818 1911
 
1819 1912
 	// Check the subject and message.
1820
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1821
-		$post_errors[] = 'no_subject';
1822
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1823
-		$post_errors[] = 'no_message';
1824
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1825
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1826
-	else
1913
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1914
+			$post_errors[] = 'no_subject';
1915
+	}
1916
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1917
+			$post_errors[] = 'no_message';
1918
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1919
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1920
+	} else
1827 1921
 	{
1828 1922
 		// Prepare the message a bit for some additional testing.
1829 1923
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1830 1924
 
1831 1925
 		// Preparse code. (Zef)
1832
-		if ($user_info['is_guest'])
1833
-			$user_info['name'] = $_POST['guestname'];
1926
+		if ($user_info['is_guest']) {
1927
+					$user_info['name'] = $_POST['guestname'];
1928
+		}
1834 1929
 		preparsecode($_POST['message']);
1835 1930
 
1836 1931
 		// Let's see if there's still some content left without the tags.
1837
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1838
-			$post_errors[] = 'no_message';
1932
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1933
+					$post_errors[] = 'no_message';
1934
+		}
1935
+	}
1936
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1937
+			$post_errors[] = 'no_event';
1839 1938
 	}
1840
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1841
-		$post_errors[] = 'no_event';
1842 1939
 	// You are not!
1843
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1844
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1940
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1941
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1942
+	}
1845 1943
 
1846 1944
 	// Validate the poll...
1847 1945
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1848 1946
 	{
1849
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1850
-			fatal_lang_error('no_access', false);
1947
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1948
+					fatal_lang_error('no_access', false);
1949
+		}
1851 1950
 
1852 1951
 		// This is a new topic... so it's a new poll.
1853
-		if (empty($topic))
1854
-			isAllowedTo('poll_post');
1952
+		if (empty($topic)) {
1953
+					isAllowedTo('poll_post');
1954
+		}
1855 1955
 		// Can you add to your own topics?
1856
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1857
-			isAllowedTo('poll_add_own');
1956
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1957
+					isAllowedTo('poll_add_own');
1958
+		}
1858 1959
 		// Can you add polls to any topic, then?
1859
-		else
1860
-			isAllowedTo('poll_add_any');
1960
+		else {
1961
+					isAllowedTo('poll_add_any');
1962
+		}
1861 1963
 
1862
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1863
-			$post_errors[] = 'no_question';
1964
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1965
+					$post_errors[] = 'no_question';
1966
+		}
1864 1967
 
1865 1968
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1866 1969
 
1867 1970
 		// Get rid of empty ones.
1868
-		foreach ($_POST['options'] as $k => $option)
1869
-			if ($option == '')
1971
+		foreach ($_POST['options'] as $k => $option) {
1972
+					if ($option == '')
1870 1973
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1974
+		}
1871 1975
 
1872 1976
 		// What are you going to vote between with one choice?!?
1873
-		if (count($_POST['options']) < 2)
1874
-			$post_errors[] = 'poll_few';
1875
-		elseif (count($_POST['options']) > 256)
1876
-			$post_errors[] = 'poll_many';
1977
+		if (count($_POST['options']) < 2) {
1978
+					$post_errors[] = 'poll_few';
1979
+		} elseif (count($_POST['options']) > 256) {
1980
+					$post_errors[] = 'poll_many';
1981
+		}
1877 1982
 	}
1878 1983
 
1879 1984
 	if ($posterIsGuest)
1880 1985
 	{
1881 1986
 		// If user is a guest, make sure the chosen name isn't taken.
1882 1987
 		require_once($sourcedir . '/Subs-Members.php');
1883
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1884
-			$post_errors[] = 'bad_name';
1988
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
1989
+					$post_errors[] = 'bad_name';
1990
+		}
1885 1991
 	}
1886 1992
 	// If the user isn't a guest, get his or her name and email.
1887 1993
 	elseif (!isset($_REQUEST['msg']))
@@ -1912,8 +2018,9 @@  discard block
 block discarded – undo
1912 2018
 	}
1913 2019
 
1914 2020
 	// Make sure the user isn't spamming the board.
1915
-	if (!isset($_REQUEST['msg']))
1916
-		spamProtection('post');
2021
+	if (!isset($_REQUEST['msg'])) {
2022
+			spamProtection('post');
2023
+	}
1917 2024
 
1918 2025
 	// At about this point, we're posting and that's that.
1919 2026
 	ignore_user_abort(true);
@@ -1926,32 +2033,36 @@  discard block
 block discarded – undo
1926 2033
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1927 2034
 
1928 2035
 	// At this point, we want to make sure the subject isn't too long.
1929
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1930
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2036
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
2037
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2038
+	}
1931 2039
 
1932 2040
 	// Same with the "why did you edit this" text.
1933
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1934
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2041
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2042
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2043
+	}
1935 2044
 
1936 2045
 	// Make the poll...
1937 2046
 	if (isset($_REQUEST['poll']))
1938 2047
 	{
1939 2048
 		// Make sure that the user has not entered a ridiculous number of options..
1940
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1941
-			$_POST['poll_max_votes'] = 1;
1942
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1943
-			$_POST['poll_max_votes'] = count($_POST['options']);
1944
-		else
1945
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2049
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
2050
+					$_POST['poll_max_votes'] = 1;
2051
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
2052
+					$_POST['poll_max_votes'] = count($_POST['options']);
2053
+		} else {
2054
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2055
+		}
1946 2056
 
1947 2057
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1948 2058
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1949 2059
 
1950 2060
 		// Just set it to zero if it's not there..
1951
-		if (!isset($_POST['poll_hide']))
1952
-			$_POST['poll_hide'] = 0;
1953
-		else
1954
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2061
+		if (!isset($_POST['poll_hide'])) {
2062
+					$_POST['poll_hide'] = 0;
2063
+		} else {
2064
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2065
+		}
1955 2066
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1956 2067
 
1957 2068
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1960,16 +2071,19 @@  discard block
 block discarded – undo
1960 2071
 		{
1961 2072
 			require_once($sourcedir . '/Subs-Members.php');
1962 2073
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1963
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1964
-				$_POST['poll_guest_vote'] = 0;
2074
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2075
+							$_POST['poll_guest_vote'] = 0;
2076
+			}
1965 2077
 		}
1966 2078
 
1967 2079
 		// If the user tries to set the poll too far in advance, don't let them.
1968
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1969
-			fatal_lang_error('poll_range_error', false);
2080
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2081
+					fatal_lang_error('poll_range_error', false);
2082
+		}
1970 2083
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1971
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1972
-			$_POST['poll_hide'] = 1;
2084
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2085
+					$_POST['poll_hide'] = 1;
2086
+		}
1973 2087
 
1974 2088
 		// Clean up the question and answers.
1975 2089
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1983,13 +2097,15 @@  discard block
 block discarded – undo
1983 2097
 	{
1984 2098
 		$attachIDs = array();
1985 2099
 		$attach_errors = array();
1986
-		if (!empty($context['we_are_history']))
1987
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2100
+		if (!empty($context['we_are_history'])) {
2101
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2102
+		}
1988 2103
 
1989 2104
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
1990 2105
 		{
1991
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1992
-				continue;
2106
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2107
+							continue;
2108
+			}
1993 2109
 
1994 2110
 			// If there was an initial error just show that message.
1995 2111
 			if ($attachID == 'initial_error')
@@ -2018,12 +2134,13 @@  discard block
 block discarded – undo
2018 2134
 				if (createAttachment($attachmentOptions))
2019 2135
 				{
2020 2136
 					$attachIDs[] = $attachmentOptions['id'];
2021
-					if (!empty($attachmentOptions['thumb']))
2022
-						$attachIDs[] = $attachmentOptions['thumb'];
2137
+					if (!empty($attachmentOptions['thumb'])) {
2138
+											$attachIDs[] = $attachmentOptions['thumb'];
2139
+					}
2023 2140
 				}
2141
+			} else {
2142
+							$attach_errors[] = '<dt>&nbsp;</dt>';
2024 2143
 			}
2025
-			else
2026
-				$attach_errors[] = '<dt>&nbsp;</dt>';
2027 2144
 
2028 2145
 			if (!empty($attachmentOptions['errors']))
2029 2146
 			{
@@ -2035,14 +2152,16 @@  discard block
 block discarded – undo
2035 2152
 					if (!is_array($error))
2036 2153
 					{
2037 2154
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
2038
-						if (in_array($error, $log_these))
2039
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2155
+						if (in_array($error, $log_these)) {
2156
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2157
+						}
2158
+					} else {
2159
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2040 2160
 					}
2041
-					else
2042
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2043 2161
 				}
2044
-				if (file_exists($attachment['tmp_name']))
2045
-					unlink($attachment['tmp_name']);
2162
+				if (file_exists($attachment['tmp_name'])) {
2163
+									unlink($attachment['tmp_name']);
2164
+				}
2046 2165
 			}
2047 2166
 		}
2048 2167
 		unset($_SESSION['temp_attachments']);
@@ -2083,24 +2202,24 @@  discard block
 block discarded – undo
2083 2202
 		);
2084 2203
 
2085 2204
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2205
+	} else {
2206
+			$id_poll = 0;
2086 2207
 	}
2087
-	else
2088
-		$id_poll = 0;
2089 2208
 
2090 2209
 	// Creating a new topic?
2091 2210
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2092 2211
 
2093 2212
 	// Check the icon.
2094
-	if (!isset($_POST['icon']))
2095
-		$_POST['icon'] = 'xx';
2096
-
2097
-	else
2213
+	if (!isset($_POST['icon'])) {
2214
+			$_POST['icon'] = 'xx';
2215
+	} else
2098 2216
 	{
2099 2217
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2100 2218
 
2101 2219
 		// Need to figure it out if this is a valid icon name.
2102
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2103
-			$_POST['icon'] = 'xx';
2220
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2221
+					$_POST['icon'] = 'xx';
2222
+		}
2104 2223
 	}
2105 2224
 
2106 2225
 	// Collect all parameters for the creation or modification of a post.
@@ -2141,8 +2260,9 @@  discard block
 block discarded – undo
2141 2260
 		}
2142 2261
 
2143 2262
 		// This will save some time...
2144
-		if (empty($approve_has_changed))
2145
-			unset($msgOptions['approved']);
2263
+		if (empty($approve_has_changed)) {
2264
+					unset($msgOptions['approved']);
2265
+		}
2146 2266
 
2147 2267
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2148 2268
 	}
@@ -2151,8 +2271,9 @@  discard block
 block discarded – undo
2151 2271
 	{
2152 2272
 		createPost($msgOptions, $topicOptions, $posterOptions);
2153 2273
 
2154
-		if (isset($topicOptions['id']))
2155
-			$topic = $topicOptions['id'];
2274
+		if (isset($topicOptions['id'])) {
2275
+					$topic = $topicOptions['id'];
2276
+		}
2156 2277
 	}
2157 2278
 
2158 2279
 	// Are there attachments already uploaded and waiting to be assigned?
@@ -2164,8 +2285,9 @@  discard block
 block discarded – undo
2164 2285
 	}
2165 2286
 
2166 2287
 	// If we had a draft for this, its time to remove it since it was just posted
2167
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2168
-		DeleteDraft($_POST['id_draft']);
2288
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2289
+			DeleteDraft($_POST['id_draft']);
2290
+	}
2169 2291
 
2170 2292
 	// Editing or posting an event?
2171 2293
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2184,8 +2306,7 @@  discard block
 block discarded – undo
2184 2306
 			'member' => $user_info['id'],
2185 2307
 		);
2186 2308
 		insertEvent($eventOptions);
2187
-	}
2188
-	elseif (isset($_POST['calendar']))
2309
+	} elseif (isset($_POST['calendar']))
2189 2310
 	{
2190 2311
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2191 2312
 
@@ -2213,14 +2334,15 @@  discard block
 block discarded – undo
2213 2334
 		}
2214 2335
 
2215 2336
 		// Delete it?
2216
-		if (isset($_REQUEST['deleteevent']))
2217
-			$smcFunc['db_query']('', '
2337
+		if (isset($_REQUEST['deleteevent'])) {
2338
+					$smcFunc['db_query']('', '
2218 2339
 				DELETE FROM {db_prefix}calendar
2219 2340
 				WHERE id_event = {int:id_event}',
2220 2341
 				array(
2221 2342
 					'id_event' => $_REQUEST['eventid'],
2222 2343
 				)
2223 2344
 			);
2345
+		}
2224 2346
 		// ... or just update it?
2225 2347
 		else
2226 2348
 		{
@@ -2262,9 +2384,8 @@  discard block
 block discarded – undo
2262 2384
 			array($user_info['id'], $topic, 0),
2263 2385
 			array('id_member', 'id_topic', 'id_board')
2264 2386
 		);
2265
-	}
2266
-	elseif (!$newTopic)
2267
-		$smcFunc['db_query']('', '
2387
+	} elseif (!$newTopic) {
2388
+			$smcFunc['db_query']('', '
2268 2389
 			DELETE FROM {db_prefix}log_notify
2269 2390
 			WHERE id_member = {int:current_member}
2270 2391
 				AND id_topic = {int:current_topic}',
@@ -2273,16 +2394,20 @@  discard block
 block discarded – undo
2273 2394
 				'current_topic' => $topic,
2274 2395
 			)
2275 2396
 		);
2397
+	}
2276 2398
 
2277 2399
 	// Log an act of moderation - modifying.
2278
-	if (!empty($moderationAction))
2279
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2400
+	if (!empty($moderationAction)) {
2401
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2402
+	}
2280 2403
 
2281
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2282
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2404
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2405
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2406
+	}
2283 2407
 
2284
-	if (isset($_POST['sticky']))
2285
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2408
+	if (isset($_POST['sticky'])) {
2409
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2410
+	}
2286 2411
 
2287 2412
 	// Returning to the topic?
2288 2413
 	if (!empty($_REQUEST['goback']))
@@ -2301,26 +2426,31 @@  discard block
 block discarded – undo
2301 2426
 		);
2302 2427
 	}
2303 2428
 
2304
-	if ($board_info['num_topics'] == 0)
2305
-		cache_put_data('board-' . $board, null, 120);
2429
+	if ($board_info['num_topics'] == 0) {
2430
+			cache_put_data('board-' . $board, null, 120);
2431
+	}
2306 2432
 
2307 2433
 	call_integration_hook('integrate_post2_end');
2308 2434
 
2309
-	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic'))
2310
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2435
+	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) {
2436
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2437
+	}
2311 2438
 
2312
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2313
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2439
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2440
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2441
+	}
2314 2442
 
2315 2443
 	// Return to post if the mod is on.
2316
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2317
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2318
-	elseif (!empty($_REQUEST['goback']))
2319
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2444
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2445
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2446
+	} elseif (!empty($_REQUEST['goback'])) {
2447
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2448
+	}
2320 2449
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2321
-	else
2322
-		redirectexit('board=' . $board . '.0');
2323
-}
2450
+	else {
2451
+			redirectexit('board=' . $board . '.0');
2452
+	}
2453
+	}
2324 2454
 
2325 2455
 /**
2326 2456
  * Handle the announce topic function (action=announce).
@@ -2338,8 +2468,9 @@  discard block
 block discarded – undo
2338 2468
 
2339 2469
 	validateSession();
2340 2470
 
2341
-	if (empty($topic))
2342
-		fatal_lang_error('topic_gone', false);
2471
+	if (empty($topic)) {
2472
+			fatal_lang_error('topic_gone', false);
2473
+	}
2343 2474
 
2344 2475
 	loadLanguage('Post');
2345 2476
 	loadTemplate('Post');
@@ -2366,8 +2497,9 @@  discard block
 block discarded – undo
2366 2497
 	global $txt, $context, $topic, $board_info, $smcFunc;
2367 2498
 
2368 2499
 	$groups = array_merge($board_info['groups'], array(1));
2369
-	foreach ($groups as $id => $group)
2370
-		$groups[$id] = (int) $group;
2500
+	foreach ($groups as $id => $group) {
2501
+			$groups[$id] = (int) $group;
2502
+	}
2371 2503
 
2372 2504
 	$context['groups'] = array();
2373 2505
 	if (in_array(0, $groups))
@@ -2410,8 +2542,9 @@  discard block
 block discarded – undo
2410 2542
 			'group_list' => $groups,
2411 2543
 		)
2412 2544
 	);
2413
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2414
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2545
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2546
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2547
+	}
2415 2548
 	$smcFunc['db_free_result']($request);
2416 2549
 
2417 2550
 	// Get the subject of the topic we're about to announce.
@@ -2453,16 +2586,19 @@  discard block
 block discarded – undo
2453 2586
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2454 2587
 	$groups = array_merge($board_info['groups'], array(1));
2455 2588
 
2456
-	if (isset($_POST['membergroups']))
2457
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2589
+	if (isset($_POST['membergroups'])) {
2590
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2591
+	}
2458 2592
 
2459 2593
 	// Check whether at least one membergroup was selected.
2460
-	if (empty($_POST['who']))
2461
-		fatal_lang_error('no_membergroup_selected');
2594
+	if (empty($_POST['who'])) {
2595
+			fatal_lang_error('no_membergroup_selected');
2596
+	}
2462 2597
 
2463 2598
 	// Make sure all membergroups are integers and can access the board of the announcement.
2464
-	foreach ($_POST['who'] as $id => $mg)
2465
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2599
+	foreach ($_POST['who'] as $id => $mg) {
2600
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2601
+	}
2466 2602
 
2467 2603
 	// Get the topic subject and censor it.
2468 2604
 	$request = $smcFunc['db_query']('', '
@@ -2508,12 +2644,13 @@  discard block
 block discarded – undo
2508 2644
 	if ($smcFunc['db_num_rows']($request) == 0)
2509 2645
 	{
2510 2646
 		logAction('announce_topic', array('topic' => $topic), 'user');
2511
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2512
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2513
-		elseif (!empty($_REQUEST['goback']))
2514
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2515
-		else
2516
-			redirectexit('board=' . $board . '.0');
2647
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2648
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2649
+		} elseif (!empty($_REQUEST['goback'])) {
2650
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2651
+		} else {
2652
+					redirectexit('board=' . $board . '.0');
2653
+		}
2517 2654
 	}
2518 2655
 
2519 2656
 	$announcements = array();
@@ -2532,8 +2669,9 @@  discard block
 block discarded – undo
2532 2669
 	foreach ($rows as $row)
2533 2670
 	{
2534 2671
 		// Force them to have it?
2535
-		if (empty($prefs[$row['id_member']]['announcements']))
2536
-			continue;
2672
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2673
+					continue;
2674
+		}
2537 2675
 
2538 2676
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2539 2677
 
@@ -2561,8 +2699,9 @@  discard block
 block discarded – undo
2561 2699
 	}
2562 2700
 
2563 2701
 	// For each language send a different mail - low priority...
2564
-	foreach ($announcements as $lang => $mail)
2565
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2702
+	foreach ($announcements as $lang => $mail) {
2703
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2704
+	}
2566 2705
 
2567 2706
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2568 2707
 
@@ -2572,9 +2711,10 @@  discard block
 block discarded – undo
2572 2711
 	$context['sub_template'] = 'announcement_send';
2573 2712
 
2574 2713
 	// Go back to the correct language for the user ;).
2575
-	if (!empty($modSettings['userLanguage']))
2576
-		loadLanguage('Post');
2577
-}
2714
+	if (!empty($modSettings['userLanguage'])) {
2715
+			loadLanguage('Post');
2716
+	}
2717
+	}
2578 2718
 
2579 2719
 /**
2580 2720
  * Get the topic for display purposes.
@@ -2587,12 +2727,13 @@  discard block
 block discarded – undo
2587 2727
 {
2588 2728
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2589 2729
 
2590
-	if (isset($_REQUEST['xml']))
2591
-		$limit = '
2730
+	if (isset($_REQUEST['xml'])) {
2731
+			$limit = '
2592 2732
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2593
-	else
2594
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2733
+	} else {
2734
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2595 2735
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2736
+	}
2596 2737
 
2597 2738
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2598 2739
 	$request = $smcFunc['db_query']('', '
@@ -2630,8 +2771,9 @@  discard block
 block discarded – undo
2630 2771
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2631 2772
 		);
2632 2773
 
2633
-		if (!empty($context['new_replies']))
2634
-			$context['new_replies']--;
2774
+		if (!empty($context['new_replies'])) {
2775
+					$context['new_replies']--;
2776
+		}
2635 2777
 	}
2636 2778
 	$smcFunc['db_free_result']($request);
2637 2779
 }
@@ -2648,8 +2790,9 @@  discard block
 block discarded – undo
2648 2790
 	global $sourcedir, $smcFunc;
2649 2791
 
2650 2792
 	loadLanguage('Post');
2651
-	if (!isset($_REQUEST['xml']))
2652
-		loadTemplate('Post');
2793
+	if (!isset($_REQUEST['xml'])) {
2794
+			loadTemplate('Post');
2795
+	}
2653 2796
 
2654 2797
 	include_once($sourcedir . '/Subs-Post.php');
2655 2798
 
@@ -2680,8 +2823,9 @@  discard block
 block discarded – undo
2680 2823
 	$smcFunc['db_free_result']($request);
2681 2824
 
2682 2825
 	$context['sub_template'] = 'quotefast';
2683
-	if (!empty($row))
2684
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2826
+	if (!empty($row)) {
2827
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2828
+	}
2685 2829
 
2686 2830
 	if (!empty($can_view_post))
2687 2831
 	{
@@ -2714,8 +2858,9 @@  discard block
 block discarded – undo
2714 2858
 		}
2715 2859
 
2716 2860
 		// Remove any nested quotes.
2717
-		if (!empty($modSettings['removeNestedQuotes']))
2718
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2861
+		if (!empty($modSettings['removeNestedQuotes'])) {
2862
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2863
+		}
2719 2864
 
2720 2865
 		$lb = "\n";
2721 2866
 
@@ -2741,14 +2886,14 @@  discard block
 block discarded – undo
2741 2886
 				'time' => '',
2742 2887
 			),
2743 2888
 		);
2744
-	}
2745
-	else
2746
-		$context['quote'] = array(
2889
+	} else {
2890
+			$context['quote'] = array(
2747 2891
 			'xml' => '',
2748 2892
 			'mozilla' => '',
2749 2893
 			'text' => '',
2750 2894
 		);
2751
-}
2895
+	}
2896
+	}
2752 2897
 
2753 2898
 /**
2754 2899
  * Used to edit the body or subject of a message inline
@@ -2760,8 +2905,9 @@  discard block
 block discarded – undo
2760 2905
 	global $user_info, $context, $smcFunc, $language, $board_info;
2761 2906
 
2762 2907
 	// We have to have a topic!
2763
-	if (empty($topic))
2764
-		obExit(false);
2908
+	if (empty($topic)) {
2909
+			obExit(false);
2910
+	}
2765 2911
 
2766 2912
 	checkSession('get');
2767 2913
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2787,31 +2933,35 @@  discard block
 block discarded – undo
2787 2933
 			'guest_id' => 0,
2788 2934
 		)
2789 2935
 	);
2790
-	if ($smcFunc['db_num_rows']($request) == 0)
2791
-		fatal_lang_error('no_board', false);
2936
+	if ($smcFunc['db_num_rows']($request) == 0) {
2937
+			fatal_lang_error('no_board', false);
2938
+	}
2792 2939
 	$row = $smcFunc['db_fetch_assoc']($request);
2793 2940
 	$smcFunc['db_free_result']($request);
2794 2941
 
2795 2942
 	// Change either body or subject requires permissions to modify messages.
2796 2943
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2797 2944
 	{
2798
-		if (!empty($row['locked']))
2799
-			isAllowedTo('moderate_board');
2945
+		if (!empty($row['locked'])) {
2946
+					isAllowedTo('moderate_board');
2947
+		}
2800 2948
 
2801 2949
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2802 2950
 		{
2803
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2804
-				fatal_lang_error('modify_post_time_passed', false);
2805
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2806
-				isAllowedTo('modify_replies');
2807
-			else
2808
-				isAllowedTo('modify_own');
2951
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2952
+							fatal_lang_error('modify_post_time_passed', false);
2953
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2954
+							isAllowedTo('modify_replies');
2955
+			} else {
2956
+							isAllowedTo('modify_own');
2957
+			}
2809 2958
 		}
2810 2959
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2811
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2812
-			isAllowedTo('modify_replies');
2813
-		else
2814
-			isAllowedTo('modify_any');
2960
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2961
+					isAllowedTo('modify_replies');
2962
+		} else {
2963
+					isAllowedTo('modify_any');
2964
+		}
2815 2965
 
2816 2966
 		// Only log this action if it wasn't your message.
2817 2967
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2823,10 +2973,10 @@  discard block
 block discarded – undo
2823 2973
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2824 2974
 
2825 2975
 		// Maximum number of characters.
2826
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2827
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2828
-	}
2829
-	elseif (isset($_POST['subject']))
2976
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2977
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2978
+		}
2979
+	} elseif (isset($_POST['subject']))
2830 2980
 	{
2831 2981
 		$post_errors[] = 'no_subject';
2832 2982
 		unset($_POST['subject']);
@@ -2838,13 +2988,11 @@  discard block
 block discarded – undo
2838 2988
 		{
2839 2989
 			$post_errors[] = 'no_message';
2840 2990
 			unset($_POST['message']);
2841
-		}
2842
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2991
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2843 2992
 		{
2844 2993
 			$post_errors[] = 'long_message';
2845 2994
 			unset($_POST['message']);
2846
-		}
2847
-		else
2995
+		} else
2848 2996
 		{
2849 2997
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2850 2998
 
@@ -2860,31 +3008,34 @@  discard block
 block discarded – undo
2860 3008
 
2861 3009
 	if (isset($_POST['lock']))
2862 3010
 	{
2863
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2864
-			unset($_POST['lock']);
2865
-		elseif (!allowedTo('lock_any'))
3011
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
3012
+					unset($_POST['lock']);
3013
+		} elseif (!allowedTo('lock_any'))
2866 3014
 		{
2867
-			if ($row['locked'] == 1)
2868
-				unset($_POST['lock']);
2869
-			else
2870
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3015
+			if ($row['locked'] == 1) {
3016
+							unset($_POST['lock']);
3017
+			} else {
3018
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3019
+			}
3020
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
3021
+					unset($_POST['lock']);
3022
+		} else {
3023
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2871 3024
 		}
2872
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2873
-			unset($_POST['lock']);
2874
-		else
2875
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2876 3025
 	}
2877 3026
 
2878
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2879
-		unset($_POST['sticky']);
3027
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
3028
+			unset($_POST['sticky']);
3029
+	}
2880 3030
 
2881 3031
 	if (isset($_POST['modify_reason']))
2882 3032
 	{
2883 3033
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2884 3034
 
2885 3035
 		// Maximum number of characters.
2886
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2887
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3036
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
3037
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3038
+		}
2888 3039
 	}
2889 3040
 
2890 3041
 	if (empty($post_errors))
@@ -2921,8 +3072,9 @@  discard block
 block discarded – undo
2921 3072
 			}
2922 3073
 		}
2923 3074
 		// If nothing was changed there's no need to add an entry to the moderation log.
2924
-		else
2925
-			$moderationAction = false;
3075
+		else {
3076
+					$moderationAction = false;
3077
+		}
2926 3078
 
2927 3079
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2928 3080
 
@@ -2940,9 +3092,9 @@  discard block
 block discarded – undo
2940 3092
 			// Get the proper (default language) response prefix first.
2941 3093
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2942 3094
 			{
2943
-				if ($language === $user_info['language'])
2944
-					$context['response_prefix'] = $txt['response_prefix'];
2945
-				else
3095
+				if ($language === $user_info['language']) {
3096
+									$context['response_prefix'] = $txt['response_prefix'];
3097
+				} else
2946 3098
 				{
2947 3099
 					loadLanguage('index', $language, false);
2948 3100
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2964,8 +3116,9 @@  discard block
 block discarded – undo
2964 3116
 			);
2965 3117
 		}
2966 3118
 
2967
-		if (!empty($moderationAction))
2968
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3119
+		if (!empty($moderationAction)) {
3120
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3121
+		}
2969 3122
 	}
2970 3123
 
2971 3124
 	if (isset($_REQUEST['xml']))
@@ -3006,8 +3159,7 @@  discard block
 block discarded – undo
3006 3159
 			);
3007 3160
 
3008 3161
 			censorText($context['message']['subject']);
3009
-		}
3010
-		else
3162
+		} else
3011 3163
 		{
3012 3164
 			$context['message'] = array(
3013 3165
 				'id' => $row['id_msg'],
@@ -3019,15 +3171,16 @@  discard block
 block discarded – undo
3019 3171
 			loadLanguage('Errors');
3020 3172
 			foreach ($post_errors as $post_error)
3021 3173
 			{
3022
-				if ($post_error == 'long_message')
3023
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3024
-				else
3025
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3174
+				if ($post_error == 'long_message') {
3175
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3176
+				} else {
3177
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3178
+				}
3026 3179
 			}
3027 3180
 		}
3181
+	} else {
3182
+			obExit(false);
3183
+	}
3028 3184
 	}
3029
-	else
3030
-		obExit(false);
3031
-}
3032 3185
 
3033 3186
 ?>
3034 3187
\ No newline at end of file
Please login to merge, or discard this patch.