Completed
Pull Request — release-2.1 (#4090)
by Rick
10:32 queued 01:58
created
Sources/Display.php 1 patch
Braces   +333 added lines, -249 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * 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.
@@ -689,20 +706,21 @@  discard block
 block discarded – undo
689 706
 				foreach ($guestinfo as $i => $guestvoted)
690 707
 				{
691 708
 					$guestvoted = explode(',', $guestvoted);
692
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
693
-						break;
709
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
710
+											break;
711
+					}
694 712
 				}
695 713
 				// Has the poll been reset since guest voted?
696 714
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
697 715
 				{
698 716
 					// Remove the poll info from the cookie to allow guest to vote again
699 717
 					unset($guestinfo[$i]);
700
-					if (!empty($guestinfo))
701
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
702
-					else
703
-						unset($_COOKIE['guest_poll_vote']);
704
-				}
705
-				else
718
+					if (!empty($guestinfo)) {
719
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
720
+					} else {
721
+											unset($_COOKIE['guest_poll_vote']);
722
+					}
723
+				} else
706 724
 				{
707 725
 					// What did they vote for?
708 726
 					unset($guestvoted[0], $guestvoted[1]);
@@ -816,23 +834,29 @@  discard block
 block discarded – undo
816 834
 		// Build the poll moderation button array.
817 835
 		$context['poll_buttons'] = array();
818 836
 
819
-		if ($context['allow_return_vote'])
820
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
837
+		if ($context['allow_return_vote']) {
838
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
839
+		}
821 840
 
822
-		if ($context['show_view_results_button'])
823
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
841
+		if ($context['show_view_results_button']) {
842
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
843
+		}
824 844
 
825
-		if ($context['allow_change_vote'])
826
-			$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']);
845
+		if ($context['allow_change_vote']) {
846
+					$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']);
847
+		}
827 848
 
828
-		if ($context['allow_lock_poll'])
829
-			$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']);
849
+		if ($context['allow_lock_poll']) {
850
+					$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']);
851
+		}
830 852
 
831
-		if ($context['allow_edit_poll'])
832
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
853
+		if ($context['allow_edit_poll']) {
854
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
855
+		}
833 856
 
834
-		if ($context['can_remove_poll'])
835
-			$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']);
857
+		if ($context['can_remove_poll']) {
858
+					$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']);
859
+		}
836 860
 
837 861
 		// Allow mods to add additional buttons here
838 862
 		call_integration_hook('integrate_poll_buttons');
@@ -873,8 +897,9 @@  discard block
 block discarded – undo
873 897
 	$all_posters = array();
874 898
 	while ($row = $smcFunc['db_fetch_assoc']($request))
875 899
 	{
876
-		if (!empty($row['id_member']))
877
-			$all_posters[$row['id_msg']] = $row['id_member'];
900
+		if (!empty($row['id_member'])) {
901
+					$all_posters[$row['id_msg']] = $row['id_member'];
902
+		}
878 903
 		$messages[] = $row['id_msg'];
879 904
 	}
880 905
 	$smcFunc['db_free_result']($request);
@@ -886,8 +911,9 @@  discard block
 block discarded – undo
886 911
 	if (!$user_info['is_guest'] && !empty($messages))
887 912
 	{
888 913
 		$mark_at_msg = max($messages);
889
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
890
-			$mark_at_msg = $modSettings['maxMsgID'];
914
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
915
+					$mark_at_msg = $modSettings['maxMsgID'];
916
+		}
891 917
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
892 918
 		{
893 919
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -919,8 +945,9 @@  discard block
 block discarded – undo
919 945
 		while ($row = $smcFunc['db_fetch_assoc']($request))
920 946
 		{
921 947
 			// Find if this topic is marked for notification...
922
-			if (!empty($row['id_topic']))
923
-				$context['is_marked_notify'] = true;
948
+			if (!empty($row['id_topic'])) {
949
+							$context['is_marked_notify'] = true;
950
+			}
924 951
 
925 952
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
926 953
 			if (!empty($row['sent']) && $do_once)
@@ -942,8 +969,9 @@  discard block
 block discarded – undo
942 969
 		}
943 970
 
944 971
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
945
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
946
-			$_SESSION['topicseen_cache'][$board]--;
972
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
973
+					$_SESSION['topicseen_cache'][$board]--;
974
+		}
947 975
 		// Mark board as seen if this is the only new topic.
948 976
 		elseif (isset($_REQUEST['topicseen']))
949 977
 		{
@@ -967,14 +995,16 @@  discard block
 block discarded – undo
967 995
 			$smcFunc['db_free_result']($request);
968 996
 
969 997
 			// If there're no real new topics in this board, mark the board as seen.
970
-			if (empty($numNewTopics))
971
-				$_REQUEST['boardseen'] = true;
972
-			else
973
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
998
+			if (empty($numNewTopics)) {
999
+							$_REQUEST['boardseen'] = true;
1000
+			} else {
1001
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1002
+			}
974 1003
 		}
975 1004
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
976
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
977
-			$_SESSION['topicseen_cache'][$board]--;
1005
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1006
+					$_SESSION['topicseen_cache'][$board]--;
1007
+		}
978 1008
 
979 1009
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
980 1010
 		if (isset($_REQUEST['boardseen']))
@@ -1031,23 +1061,26 @@  discard block
 block discarded – undo
1031 1061
 			$temp = array();
1032 1062
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1033 1063
 			{
1034
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1035
-					continue;
1064
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1065
+									continue;
1066
+				}
1036 1067
 
1037 1068
 				$temp[$row['id_attach']] = $row;
1038 1069
 				$temp[$row['id_attach']]['topic'] = $topic;
1039 1070
 				$temp[$row['id_attach']]['board'] = $board;
1040 1071
 
1041
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1042
-					$context['loaded_attachments'][$row['id_msg']] = array();
1072
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1073
+									$context['loaded_attachments'][$row['id_msg']] = array();
1074
+				}
1043 1075
 			}
1044 1076
 			$smcFunc['db_free_result']($request);
1045 1077
 
1046 1078
 			// This is better than sorting it with the query...
1047 1079
 			ksort($temp);
1048 1080
 
1049
-			foreach ($temp as $row)
1050
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1081
+			foreach ($temp as $row) {
1082
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1083
+			}
1051 1084
 		}
1052 1085
 
1053 1086
 		$msg_parameters = array(
@@ -1074,21 +1107,23 @@  discard block
 block discarded – undo
1074 1107
 		);
1075 1108
 
1076 1109
 		// And the likes
1077
-		if (!empty($modSettings['enable_likes']))
1078
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1110
+		if (!empty($modSettings['enable_likes'])) {
1111
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1112
+		}
1079 1113
 
1080 1114
 		// Go to the last message if the given time is beyond the time of the last message.
1081
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1082
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1115
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1116
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1117
+		}
1083 1118
 
1084 1119
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1085 1120
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1086
-		if (empty($options['view_newest_first']))
1087
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1088
-		else
1089
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1090
-	}
1091
-	else
1121
+		if (empty($options['view_newest_first'])) {
1122
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1123
+		} else {
1124
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1125
+		}
1126
+	} else
1092 1127
 	{
1093 1128
 		$messages_request = false;
1094 1129
 		$context['first_message'] = 0;
@@ -1124,8 +1159,9 @@  discard block
 block discarded – undo
1124 1159
 		'can_see_likes' => 'likes_view',
1125 1160
 		'can_like' => 'likes_like',
1126 1161
 	);
1127
-	foreach ($common_permissions as $contextual => $perm)
1128
-		$context[$contextual] = allowedTo($perm);
1162
+	foreach ($common_permissions as $contextual => $perm) {
1163
+			$context[$contextual] = allowedTo($perm);
1164
+	}
1129 1165
 
1130 1166
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1131 1167
 	$anyown_permissions = array(
@@ -1138,8 +1174,9 @@  discard block
 block discarded – undo
1138 1174
 		'can_reply_unapproved' => 'post_unapproved_replies',
1139 1175
 		'can_view_warning' => 'profile_warning',
1140 1176
 	);
1141
-	foreach ($anyown_permissions as $contextual => $perm)
1142
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1177
+	foreach ($anyown_permissions as $contextual => $perm) {
1178
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1179
+	}
1143 1180
 
1144 1181
 	if (!$user_info['is_admin'] && !$modSettings['topic_move_any'])
1145 1182
 	{
@@ -1185,8 +1222,9 @@  discard block
 block discarded – undo
1185 1222
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1186 1223
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1187 1224
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1188
-	if (!empty($context['drafts_save']))
1189
-		loadLanguage('Drafts');
1225
+	if (!empty($context['drafts_save'])) {
1226
+			loadLanguage('Drafts');
1227
+	}
1190 1228
 
1191 1229
 	// When was the last time this topic was replied to?  Should we warn them about it?
1192 1230
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1247,26 +1285,31 @@  discard block
 block discarded – undo
1247 1285
 	// Message icons - customized icons are off?
1248 1286
 	$context['icons'] = getMessageIcons($board);
1249 1287
 
1250
-	if (!empty($context['icons']))
1251
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1288
+	if (!empty($context['icons'])) {
1289
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1290
+	}
1252 1291
 
1253 1292
 	// Build the normal button array.
1254 1293
 	$context['normal_buttons'] = array();
1255 1294
 
1256
-	if ($context['can_reply'])
1257
-		$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);
1295
+	if ($context['can_reply']) {
1296
+			$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);
1297
+	}
1258 1298
 
1259
-	if ($context['can_add_poll'])
1260
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1299
+	if ($context['can_add_poll']) {
1300
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1301
+	}
1261 1302
 
1262
-	if ($context['can_mark_unread'])
1263
-		$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']);
1303
+	if ($context['can_mark_unread']) {
1304
+			$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']);
1305
+	}
1264 1306
 
1265
-	if ($context['can_print'])
1266
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1307
+	if ($context['can_print']) {
1308
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1309
+	}
1267 1310
 
1268
-	if ($context['can_set_notify'])
1269
-		$context['normal_buttons']['notify'] = array(
1311
+	if ($context['can_set_notify']) {
1312
+			$context['normal_buttons']['notify'] = array(
1270 1313
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1271 1314
 			'sub_buttons' => array(
1272 1315
 				array(
@@ -1288,38 +1331,47 @@  discard block
 block discarded – undo
1288 1331
 				),
1289 1332
 			),
1290 1333
 		);
1334
+	}
1291 1335
 
1292 1336
 	// Build the mod button array
1293 1337
 	$context['mod_buttons'] = array();
1294 1338
 
1295
-	if ($context['can_move'])
1296
-		$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');
1339
+	if ($context['can_move']) {
1340
+			$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');
1341
+	}
1297 1342
 
1298
-	if ($context['can_delete'])
1299
-		$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']);
1343
+	if ($context['can_delete']) {
1344
+			$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']);
1345
+	}
1300 1346
 
1301
-	if ($context['can_lock'])
1302
-		$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']);
1347
+	if ($context['can_lock']) {
1348
+			$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']);
1349
+	}
1303 1350
 
1304
-	if ($context['can_sticky'])
1305
-		$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']);
1351
+	if ($context['can_sticky']) {
1352
+			$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']);
1353
+	}
1306 1354
 
1307
-	if ($context['can_merge'])
1308
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1355
+	if ($context['can_merge']) {
1356
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1357
+	}
1309 1358
 
1310
-	if ($context['calendar_post'])
1311
-		$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');
1359
+	if ($context['calendar_post']) {
1360
+			$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');
1361
+	}
1312 1362
 
1313 1363
 	// Restore topic. eh?  No monkey business.
1314
-	if ($context['can_restore_topic'])
1315
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1364
+	if ($context['can_restore_topic']) {
1365
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1366
+	}
1316 1367
 
1317 1368
 	// Show a message in case a recently posted message became unapproved.
1318 1369
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1319 1370
 
1320 1371
 	// Don't want to show this forever...
1321
-	if ($context['becomesUnapproved'])
1322
-		unset($_SESSION['becomesUnapproved']);
1372
+	if ($context['becomesUnapproved']) {
1373
+			unset($_SESSION['becomesUnapproved']);
1374
+	}
1323 1375
 
1324 1376
 	// Allow adding new mod buttons easily.
1325 1377
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1328,12 +1380,14 @@  discard block
 block discarded – undo
1328 1380
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1329 1381
 
1330 1382
 	// Load the drafts js file
1331
-	if ($context['drafts_autosave'])
1332
-		loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1383
+	if ($context['drafts_autosave']) {
1384
+			loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1385
+	}
1333 1386
 
1334 1387
 	// Spellcheck
1335
-	if ($context['show_spellchecking'])
1336
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1388
+	if ($context['show_spellchecking']) {
1389
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1390
+	}
1337 1391
 
1338 1392
 	// topic.js
1339 1393
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -1367,16 +1421,19 @@  discard block
 block discarded – undo
1367 1421
 	static $counter = null;
1368 1422
 
1369 1423
 	// If the query returned false, bail.
1370
-	if ($messages_request == false)
1371
-		return false;
1424
+	if ($messages_request == false) {
1425
+			return false;
1426
+	}
1372 1427
 
1373 1428
 	// Remember which message this is.  (ie. reply #83)
1374
-	if ($counter === null || $reset)
1375
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1429
+	if ($counter === null || $reset) {
1430
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1431
+	}
1376 1432
 
1377 1433
 	// Start from the beginning...
1378
-	if ($reset)
1379
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1434
+	if ($reset) {
1435
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1436
+	}
1380 1437
 
1381 1438
 	// Attempt to get the next message.
1382 1439
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1390,19 +1447,21 @@  discard block
 block discarded – undo
1390 1447
 	if (empty($context['icon_sources']))
1391 1448
 	{
1392 1449
 		$context['icon_sources'] = array();
1393
-		foreach ($context['stable_icons'] as $icon)
1394
-			$context['icon_sources'][$icon] = 'images_url';
1450
+		foreach ($context['stable_icons'] as $icon) {
1451
+					$context['icon_sources'][$icon] = 'images_url';
1452
+		}
1395 1453
 	}
1396 1454
 
1397 1455
 	// Message Icon Management... check the images exist.
1398 1456
 	if (empty($modSettings['messageIconChecks_disable']))
1399 1457
 	{
1400 1458
 		// If the current icon isn't known, then we need to do something...
1401
-		if (!isset($context['icon_sources'][$message['icon']]))
1402
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1459
+		if (!isset($context['icon_sources'][$message['icon']])) {
1460
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1461
+		}
1462
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1463
+			$context['icon_sources'][$message['icon']] = 'images_url';
1403 1464
 	}
1404
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1405
-		$context['icon_sources'][$message['icon']] = 'images_url';
1406 1465
 
1407 1466
 	// If you're a lazy bum, you probably didn't give a subject...
1408 1467
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1427,8 +1486,7 @@  discard block
 block discarded – undo
1427 1486
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1428 1487
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1429 1488
 		$memberContext[$message['id_member']]['is_guest'] = true;
1430
-	}
1431
-	else
1489
+	} else
1432 1490
 	{
1433 1491
 		// Define this here to make things a bit more readable
1434 1492
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1451,8 +1509,9 @@  discard block
 block discarded – undo
1451 1509
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1452 1510
 
1453 1511
 	// If it's in the recycle bin we need to override whatever icon we did have.
1454
-	if (!empty($board_info['recycle']))
1455
-		$message['icon'] = 'recycled';
1512
+	if (!empty($board_info['recycle'])) {
1513
+			$message['icon'] = 'recycled';
1514
+	}
1456 1515
 
1457 1516
 	require_once($sourcedir . '/Subs-Attachments.php');
1458 1517
 
@@ -1496,32 +1555,36 @@  discard block
 block discarded – undo
1496 1555
 	}
1497 1556
 
1498 1557
 	// Are likes enable?
1499
-	if (!empty($modSettings['enable_likes']))
1500
-		$output['likes'] = array(
1558
+	if (!empty($modSettings['enable_likes'])) {
1559
+			$output['likes'] = array(
1501 1560
 			'count' => $message['likes'],
1502 1561
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1503 1562
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1504 1563
 		);
1564
+	}
1505 1565
 
1506 1566
 	// Is this user the message author?
1507 1567
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1508
-	if (!empty($output['modified']['name']))
1509
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1568
+	if (!empty($output['modified']['name'])) {
1569
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1570
+	}
1510 1571
 
1511 1572
 	// Did they give a reason for editing?
1512
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1513
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1573
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1574
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1575
+	}
1514 1576
 
1515 1577
 	// Any custom profile fields?
1516
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1517
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1578
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1579
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1518 1580
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1581
+	}
1519 1582
 
1520
-	if (empty($options['view_newest_first']))
1521
-		$counter++;
1522
-
1523
-	else
1524
-		$counter--;
1583
+	if (empty($options['view_newest_first'])) {
1584
+			$counter++;
1585
+	} else {
1586
+			$counter--;
1587
+	}
1525 1588
 
1526 1589
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1527 1590
 
@@ -1547,21 +1610,23 @@  discard block
 block discarded – undo
1547 1610
 	$context['no_last_modified'] = true;
1548 1611
 
1549 1612
 	// Prevent a preview image from being displayed twice.
1550
-	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview'))
1551
-		return;
1613
+	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) {
1614
+			return;
1615
+	}
1552 1616
 
1553 1617
 	// Make sure some attachment was requested!
1554
-	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id']))
1555
-		fatal_lang_error('no_access', false);
1618
+	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) {
1619
+			fatal_lang_error('no_access', false);
1620
+	}
1556 1621
 
1557 1622
 	$_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id'];
1558 1623
 
1559 1624
 	// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
1560 1625
 	$attachRequest = null;
1561 1626
 	call_integration_hook('integrate_download_request', array(&$attachRequest));
1562
-	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
1563
-		$request = $attachRequest;
1564
-	else
1627
+	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
1628
+			$request = $attachRequest;
1629
+	} else
1565 1630
 	{
1566 1631
 		// This checks only the current board for $board/$topic's permissions.
1567 1632
 		isAllowedTo('view_attachments');
@@ -1582,19 +1647,21 @@  discard block
 block discarded – undo
1582 1647
 		);
1583 1648
 	}
1584 1649
 
1585
-	if ($smcFunc['db_num_rows']($request) == 0)
1586
-		fatal_lang_error('no_access', false);
1650
+	if ($smcFunc['db_num_rows']($request) == 0) {
1651
+			fatal_lang_error('no_access', false);
1652
+	}
1587 1653
 
1588 1654
 	list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request);
1589 1655
 	$smcFunc['db_free_result']($request);
1590 1656
 
1591 1657
 	// If it isn't yet approved, do they have permission to view it?
1592
-	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3))
1593
-		isAllowedTo('approve_posts');
1658
+	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) {
1659
+			isAllowedTo('approve_posts');
1660
+	}
1594 1661
 
1595 1662
 	// Update the download counter (unless it's a thumbnail).
1596
-	if ($attachment_type != 3)
1597
-		$smcFunc['db_query']('attach_download_increase', '
1663
+	if ($attachment_type != 3) {
1664
+			$smcFunc['db_query']('attach_download_increase', '
1598 1665
 			UPDATE LOW_PRIORITY {db_prefix}attachments
1599 1666
 			SET downloads = downloads + 1
1600 1667
 			WHERE id_attach = {int:id_attach}',
@@ -1602,15 +1669,15 @@  discard block
 block discarded – undo
1602 1669
 				'id_attach' => $id_attach,
1603 1670
 			)
1604 1671
 		);
1672
+	}
1605 1673
 
1606 1674
 	$filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash);
1607 1675
 
1608 1676
 	// This is done to clear any output that was made before now.
1609 1677
 	ob_end_clean();
1610
-	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java')))
1611
-		@ob_start('ob_gzhandler');
1612
-
1613
-	else
1678
+	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) {
1679
+			@ob_start('ob_gzhandler');
1680
+	} else
1614 1681
 	{
1615 1682
 		ob_start();
1616 1683
 		header('Content-Encoding: none');
@@ -1653,8 +1720,9 @@  discard block
 block discarded – undo
1653 1720
 	// Send the attachment headers.
1654 1721
 	header('Pragma: ');
1655 1722
 
1656
-	if (!isBrowser('gecko'))
1657
-		header('Content-Transfer-Encoding: binary');
1723
+	if (!isBrowser('gecko')) {
1724
+			header('Content-Transfer-Encoding: binary');
1725
+	}
1658 1726
 
1659 1727
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
1660 1728
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT');
@@ -1663,18 +1731,19 @@  discard block
 block discarded – undo
1663 1731
 	header('ETag: ' . $eTag);
1664 1732
 
1665 1733
 	// Make sure the mime type warrants an inline display.
1666
-	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0)
1667
-		unset($_REQUEST['image']);
1734
+	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) {
1735
+			unset($_REQUEST['image']);
1736
+	}
1668 1737
 
1669 1738
 	// Does this have a mime type?
1670
-	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
1671
-		header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1672
-
1673
-	else
1739
+	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
1740
+			header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1741
+	} else
1674 1742
 	{
1675 1743
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
1676
-		if (isset($_REQUEST['image']))
1677
-			unset($_REQUEST['image']);
1744
+		if (isset($_REQUEST['image'])) {
1745
+					unset($_REQUEST['image']);
1746
+		}
1678 1747
 	}
1679 1748
 
1680 1749
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -1682,23 +1751,22 @@  discard block
 block discarded – undo
1682 1751
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
1683 1752
 
1684 1753
 	// Different browsers like different standards...
1685
-	if (isBrowser('firefox'))
1686
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1687
-
1688
-	elseif (isBrowser('opera'))
1689
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1690
-
1691
-	elseif (isBrowser('ie'))
1692
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1693
-
1694
-	else
1695
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1754
+	if (isBrowser('firefox')) {
1755
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1756
+	} elseif (isBrowser('opera')) {
1757
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1758
+	} elseif (isBrowser('ie')) {
1759
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1760
+	} else {
1761
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1762
+	}
1696 1763
 
1697 1764
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
1698
-	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
1699
-		header('Cache-Control: no-cache');
1700
-	else
1701
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1765
+	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
1766
+			header('Cache-Control: no-cache');
1767
+	} else {
1768
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1769
+	}
1702 1770
 
1703 1771
 	header('Content-Length: ' . filesize($filename));
1704 1772
 
@@ -1708,20 +1776,23 @@  discard block
 block discarded – undo
1708 1776
 	// Recode line endings for text files, if enabled.
1709 1777
 	if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml')))
1710 1778
 	{
1711
-		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
1712
-			$callback = function($buffer)
1779
+		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) {
1780
+					$callback = function($buffer)
1713 1781
 			{
1714 1782
 				return preg_replace('~[\r]?\n~', "\r\n", $buffer);
1783
+		}
1715 1784
 			};
1716
-		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
1717
-			$callback = function($buffer)
1785
+		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) {
1786
+					$callback = function($buffer)
1718 1787
 			{
1719 1788
 				return preg_replace('~[\r]?\n~', "\r", $buffer);
1789
+		}
1720 1790
 			};
1721
-		else
1722
-			$callback = function($buffer)
1791
+		else {
1792
+					$callback = function($buffer)
1723 1793
 			{
1724 1794
 				return preg_replace('~[\r]?\n~', "\n", $buffer);
1795
+		}
1725 1796
 			};
1726 1797
 	}
1727 1798
 
@@ -1729,23 +1800,26 @@  discard block
 block discarded – undo
1729 1800
 	if (filesize($filename) > 4194304)
1730 1801
 	{
1731 1802
 		// Forcibly end any output buffering going on.
1732
-		while (@ob_get_level() > 0)
1733
-			@ob_end_clean();
1803
+		while (@ob_get_level() > 0) {
1804
+					@ob_end_clean();
1805
+		}
1734 1806
 
1735 1807
 		$fp = fopen($filename, 'rb');
1736 1808
 		while (!feof($fp))
1737 1809
 		{
1738
-			if (isset($callback))
1739
-				echo $callback(fread($fp, 8192));
1740
-			else
1741
-				echo fread($fp, 8192);
1810
+			if (isset($callback)) {
1811
+							echo $callback(fread($fp, 8192));
1812
+			} else {
1813
+							echo fread($fp, 8192);
1814
+			}
1742 1815
 			flush();
1743 1816
 		}
1744 1817
 		fclose($fp);
1745 1818
 	}
1746 1819
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
1747
-	elseif (isset($callback) || @readfile($filename) === null)
1748
-		echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1820
+	elseif (isset($callback) || @readfile($filename) === null) {
1821
+			echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1822
+	}
1749 1823
 
1750 1824
 	obExit(false);
1751 1825
 }
@@ -1758,8 +1832,9 @@  discard block
 block discarded – undo
1758 1832
  */
1759 1833
 function approved_attach_sort($a, $b)
1760 1834
 {
1761
-	if ($a['is_approved'] == $b['is_approved'])
1762
-		return 0;
1835
+	if ($a['is_approved'] == $b['is_approved']) {
1836
+			return 0;
1837
+	}
1763 1838
 
1764 1839
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1765 1840
 }
@@ -1776,16 +1851,19 @@  discard block
 block discarded – undo
1776 1851
 
1777 1852
 	require_once($sourcedir . '/RemoveTopic.php');
1778 1853
 
1779
-	if (empty($_REQUEST['msgs']))
1780
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1854
+	if (empty($_REQUEST['msgs'])) {
1855
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1856
+	}
1781 1857
 
1782 1858
 	$messages = array();
1783
-	foreach ($_REQUEST['msgs'] as $dummy)
1784
-		$messages[] = (int) $dummy;
1859
+	foreach ($_REQUEST['msgs'] as $dummy) {
1860
+			$messages[] = (int) $dummy;
1861
+	}
1785 1862
 
1786 1863
 	// We are restoring messages. We handle this in another place.
1787
-	if (isset($_REQUEST['restore_selected']))
1788
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1864
+	if (isset($_REQUEST['restore_selected'])) {
1865
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1866
+	}
1789 1867
 	if (isset($_REQUEST['split_selection']))
1790 1868
 	{
1791 1869
 		$request = $smcFunc['db_query']('', '
@@ -1804,8 +1882,9 @@  discard block
 block discarded – undo
1804 1882
 	}
1805 1883
 
1806 1884
 	// Allowed to delete any message?
1807
-	if (allowedTo('delete_any'))
1808
-		$allowed_all = true;
1885
+	if (allowedTo('delete_any')) {
1886
+			$allowed_all = true;
1887
+	}
1809 1888
 	// Allowed to delete replies to their messages?
1810 1889
 	elseif (allowedTo('delete_replies'))
1811 1890
 	{
@@ -1822,13 +1901,14 @@  discard block
 block discarded – undo
1822 1901
 		$smcFunc['db_free_result']($request);
1823 1902
 
1824 1903
 		$allowed_all = $starter == $user_info['id'];
1904
+	} else {
1905
+			$allowed_all = false;
1825 1906
 	}
1826
-	else
1827
-		$allowed_all = false;
1828 1907
 
1829 1908
 	// Make sure they're allowed to delete their own messages, if not any.
1830
-	if (!$allowed_all)
1831
-		isAllowedTo('delete_own');
1909
+	if (!$allowed_all) {
1910
+			isAllowedTo('delete_own');
1911
+	}
1832 1912
 
1833 1913
 	// Allowed to remove which messages?
1834 1914
 	$request = $smcFunc['db_query']('', '
@@ -1848,8 +1928,9 @@  discard block
 block discarded – undo
1848 1928
 	$messages = array();
1849 1929
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1850 1930
 	{
1851
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1852
-			continue;
1931
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1932
+					continue;
1933
+		}
1853 1934
 
1854 1935
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1855 1936
 	}
@@ -1872,17 +1953,20 @@  discard block
 block discarded – undo
1872 1953
 	foreach ($messages as $message => $info)
1873 1954
 	{
1874 1955
 		// Just skip the first message - if it's not the last.
1875
-		if ($message == $first_message && $message != $last_message)
1876
-			continue;
1956
+		if ($message == $first_message && $message != $last_message) {
1957
+					continue;
1958
+		}
1877 1959
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1878
-		elseif ($message == $first_message)
1879
-			$topicGone = true;
1960
+		elseif ($message == $first_message) {
1961
+					$topicGone = true;
1962
+		}
1880 1963
 
1881 1964
 		removeMessage($message);
1882 1965
 
1883 1966
 		// Log this moderation action ;).
1884
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1885
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1967
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1968
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1969
+		}
1886 1970
 	}
1887 1971
 
1888 1972
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Sources/CacheAPI-zend.php 1 patch
Braces   +15 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * Our Cache API class
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 	{
28 29
 		$supported = function_exists('zend_shm_cache_fetch') || function_exists('output_cache_get');
29 30
 
30
-		if ($test)
31
-			return $supported;
31
+		if ($test) {
32
+					return $supported;
33
+		}
32 34
 		return parent::isSupported() && $supported;
33 35
 	}
34 36
 
@@ -40,10 +42,11 @@  discard block
 block discarded – undo
40 42
 		$key = $this->prefix . strtr($key, ':/', '-_');
41 43
 
42 44
 		// Zend's pricey stuff.
43
-		if (function_exists('zend_shm_cache_fetch'))
44
-			return zend_shm_cache_fetch('SMF::' . $key);
45
-		elseif (function_exists('output_cache_get'))
46
-			return output_cache_get($key, $ttl);
45
+		if (function_exists('zend_shm_cache_fetch')) {
46
+					return zend_shm_cache_fetch('SMF::' . $key);
47
+		} elseif (function_exists('output_cache_get')) {
48
+					return output_cache_get($key, $ttl);
49
+		}
47 50
 	}
48 51
 
49 52
 	/**
@@ -53,10 +56,11 @@  discard block
 block discarded – undo
53 56
 	{
54 57
 		$key = $this->prefix . strtr($key, ':/', '-_');
55 58
 
56
-		if (function_exists('zend_shm_cache_store'))
57
-			return zend_shm_cache_store('SMF::' . $key, $value, $ttl);
58
-		elseif (function_exists('output_cache_put'))
59
-			return output_cache_put($key, $value);
59
+		if (function_exists('zend_shm_cache_store')) {
60
+					return zend_shm_cache_store('SMF::' . $key, $value, $ttl);
61
+		} elseif (function_exists('output_cache_put')) {
62
+					return output_cache_put($key, $value);
63
+		}
60 64
 	}
61 65
 
62 66
 	/**
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 1 patch
Braces   +282 added lines, -205 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -452,16 +477,17 @@  discard block
 block discarded – undo
452 477
 
453 478
 	// Check the database version - for some buggy MySQL version.
454 479
 	$server_version = $smcFunc['db_server_info']();
455
-	if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
456
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
457
-	elseif (!empty($modSettings['db_mysql_group_by_fix']))
458
-		$smcFunc['db_query']('', '
480
+	if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
481
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
482
+	} elseif (!empty($modSettings['db_mysql_group_by_fix'])) {
483
+			$smcFunc['db_query']('', '
459 484
 			DELETE FROM {db_prefix}settings
460 485
 			WHERE variable = {string:mysql_fix}',
461 486
 			array(
462 487
 				'mysql_fix' => 'db_mysql_group_by_fix',
463 488
 			)
464 489
 		);
490
+	}
465 491
 
466 492
 	// Clean up some old login history information.
467 493
 	$smcFunc['db_query']('', '
@@ -519,15 +545,17 @@  discard block
 block discarded – undo
519 545
 
520 546
 		// Store this useful data!
521 547
 		$boards[$row['id_board']] = $row['id_board'];
522
-		if ($row['id_topic'])
523
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
524
-		else
525
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
548
+		if ($row['id_topic']) {
549
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
550
+		} else {
551
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
552
+		}
526 553
 	}
527 554
 	$smcFunc['db_free_result']($request);
528 555
 
529
-	if (empty($boards))
530
-		return true;
556
+	if (empty($boards)) {
557
+			return true;
558
+	}
531 559
 
532 560
 	// Just get the board names.
533 561
 	$request = $smcFunc['db_query']('', '
@@ -539,12 +567,14 @@  discard block
 block discarded – undo
539 567
 		)
540 568
 	);
541 569
 	$boards = array();
542
-	while ($row = $smcFunc['db_fetch_assoc']($request))
543
-		$boards[$row['id_board']] = $row['name'];
570
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
571
+			$boards[$row['id_board']] = $row['name'];
572
+	}
544 573
 	$smcFunc['db_free_result']($request);
545 574
 
546
-	if (empty($boards))
547
-		return true;
575
+	if (empty($boards)) {
576
+			return true;
577
+	}
548 578
 
549 579
 	// Get the actual topics...
550 580
 	$request = $smcFunc['db_query']('', '
@@ -564,52 +594,57 @@  discard block
 block discarded – undo
564 594
 	$types = array();
565 595
 	while ($row = $smcFunc['db_fetch_assoc']($request))
566 596
 	{
567
-		if (!isset($types[$row['note_type']][$row['id_board']]))
568
-			$types[$row['note_type']][$row['id_board']] = array(
597
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
598
+					$types[$row['note_type']][$row['id_board']] = array(
569 599
 				'lines' => array(),
570 600
 				'name' => $row['board_name'],
571 601
 				'id' => $row['id_board'],
572 602
 			);
603
+		}
573 604
 
574 605
 		if ($row['note_type'] == 'reply')
575 606
 		{
576
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
577
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
578
-			else
579
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
607
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
608
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
609
+			} else {
610
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
580 611
 					'id' => $row['id_topic'],
581 612
 					'subject' => un_htmlspecialchars($row['subject']),
582 613
 					'count' => 1,
583 614
 				);
584
-		}
585
-		elseif ($row['note_type'] == 'topic')
615
+			}
616
+		} elseif ($row['note_type'] == 'topic')
586 617
 		{
587
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
588
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
618
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
619
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
589 620
 					'id' => $row['id_topic'],
590 621
 					'subject' => un_htmlspecialchars($row['subject']),
591 622
 				);
592
-		}
593
-		else
623
+			}
624
+		} else
594 625
 		{
595
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
596
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
626
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
627
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
597 628
 					'id' => $row['id_topic'],
598 629
 					'subject' => un_htmlspecialchars($row['subject']),
599 630
 					'starter' => $row['id_member_started'],
600 631
 				);
632
+			}
601 633
 		}
602 634
 
603 635
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
604
-		if (!empty($notify['topics'][$row['id_topic']]))
605
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
606
-		if (!empty($notify['boards'][$row['id_board']]))
607
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
636
+		if (!empty($notify['topics'][$row['id_topic']])) {
637
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
638
+		}
639
+		if (!empty($notify['boards'][$row['id_board']])) {
640
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
641
+		}
608 642
 	}
609 643
 	$smcFunc['db_free_result']($request);
610 644
 
611
-	if (empty($types))
612
-		return true;
645
+	if (empty($types)) {
646
+			return true;
647
+	}
613 648
 
614 649
 	// Let's load all the languages into a cache thingy.
615 650
 	$langtxt = array();
@@ -650,8 +685,9 @@  discard block
 block discarded – undo
650 685
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
651 686
 
652 687
 		// Did they not elect to choose this?
653
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
654
-			continue;
688
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
689
+					continue;
690
+		}
655 691
 
656 692
 		// Right character set!
657 693
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -667,39 +703,43 @@  discard block
 block discarded – undo
667 703
 		if (isset($types['topic']))
668 704
 		{
669 705
 			$titled = false;
670
-			foreach ($types['topic'] as $id => $board)
671
-				foreach ($board['lines'] as $topic)
706
+			foreach ($types['topic'] as $id => $board) {
707
+							foreach ($board['lines'] as $topic)
672 708
 					if (in_array($mid, $topic['members']))
673 709
 					{
674 710
 						if (!$titled)
675 711
 						{
676 712
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
713
+			}
677 714
 							$titled = true;
678 715
 						}
679 716
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
680 717
 					}
681
-			if ($titled)
682
-				$email['body'] .= "\n";
718
+			if ($titled) {
719
+							$email['body'] .= "\n";
720
+			}
683 721
 		}
684 722
 
685 723
 		// What about replies?
686 724
 		if (isset($types['reply']))
687 725
 		{
688 726
 			$titled = false;
689
-			foreach ($types['reply'] as $id => $board)
690
-				foreach ($board['lines'] as $topic)
727
+			foreach ($types['reply'] as $id => $board) {
728
+							foreach ($board['lines'] as $topic)
691 729
 					if (in_array($mid, $topic['members']))
692 730
 					{
693 731
 						if (!$titled)
694 732
 						{
695 733
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
734
+			}
696 735
 							$titled = true;
697 736
 						}
698 737
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
699 738
 					}
700 739
 
701
-			if ($titled)
702
-				$email['body'] .= "\n";
740
+			if ($titled) {
741
+							$email['body'] .= "\n";
742
+			}
703 743
 		}
704 744
 
705 745
 		// Finally, moderation actions!
@@ -708,24 +748,27 @@  discard block
 block discarded – undo
708 748
 			$titled = false;
709 749
 			foreach ($types as $note_type => $type)
710 750
 			{
711
-				if ($note_type == 'topic' || $note_type == 'reply')
712
-					continue;
751
+				if ($note_type == 'topic' || $note_type == 'reply') {
752
+									continue;
753
+				}
713 754
 
714
-				foreach ($type as $id => $board)
715
-					foreach ($board['lines'] as $topic)
755
+				foreach ($type as $id => $board) {
756
+									foreach ($board['lines'] as $topic)
716 757
 						if (in_array($mid, $topic['members']))
717 758
 						{
718 759
 							if (!$titled)
719 760
 							{
720 761
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
762
+				}
721 763
 								$titled = true;
722 764
 							}
723 765
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
724 766
 						}
725 767
 			}
726 768
 		}
727
-		if ($titled)
728
-			$email['body'] .= "\n";
769
+		if ($titled) {
770
+					$email['body'] .= "\n";
771
+		}
729 772
 
730 773
 		// Then just say our goodbyes!
731 774
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -753,8 +796,7 @@  discard block
 block discarded – undo
753 796
 				'not_daily' => 0,
754 797
 			)
755 798
 		);
756
-	}
757
-	else
799
+	} else
758 800
 	{
759 801
 		// Clear any only weekly ones, and stop us from sending daily again.
760 802
 		$smcFunc['db_query']('', '
@@ -816,16 +858,19 @@  discard block
 block discarded – undo
816 858
 	global $modSettings, $smcFunc, $sourcedir;
817 859
 
818 860
 	// Are we intending another script to be sending out the queue?
819
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
820
-		return false;
861
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
862
+			return false;
863
+	}
821 864
 
822 865
 	// By default send 5 at once.
823
-	if (!$number)
824
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
866
+	if (!$number) {
867
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
868
+	}
825 869
 
826 870
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
827
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
828
-		return false;
871
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
872
+			return false;
873
+	}
829 874
 
830 875
 	// By default move the next sending on by 10 seconds, and require an affected row.
831 876
 	if (!$override_limit)
@@ -842,8 +887,9 @@  discard block
 block discarded – undo
842 887
 				'last_send' => $modSettings['mail_next_send'],
843 888
 			)
844 889
 		);
845
-		if ($smcFunc['db_affected_rows']() == 0)
846
-			return false;
890
+		if ($smcFunc['db_affected_rows']() == 0) {
891
+					return false;
892
+		}
847 893
 		$modSettings['mail_next_send'] = time() + $delay;
848 894
 	}
849 895
 
@@ -864,8 +910,9 @@  discard block
 block discarded – undo
864 910
 			$mn += $number;
865 911
 		}
866 912
 		// No more I'm afraid, return!
867
-		else
868
-			return false;
913
+		else {
914
+					return false;
915
+		}
869 916
 
870 917
 		// Reflect that we're about to send some, do it now to be safe.
871 918
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -900,14 +947,15 @@  discard block
 block discarded – undo
900 947
 	$smcFunc['db_free_result']($request);
901 948
 
902 949
 	// Delete, delete, delete!!!
903
-	if (!empty($ids))
904
-		$smcFunc['db_query']('', '
950
+	if (!empty($ids)) {
951
+			$smcFunc['db_query']('', '
905 952
 			DELETE FROM {db_prefix}mail_queue
906 953
 			WHERE id_mail IN ({array_int:mail_list})',
907 954
 			array(
908 955
 				'mail_list' => $ids,
909 956
 			)
910 957
 		);
958
+	}
911 959
 
912 960
 	// Don't believe we have any left?
913 961
 	if (count($ids) < $number)
@@ -925,11 +973,13 @@  discard block
 block discarded – undo
925 973
 		);
926 974
 	}
927 975
 
928
-	if (empty($ids))
929
-		return false;
976
+	if (empty($ids)) {
977
+			return false;
978
+	}
930 979
 
931
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
932
-		require_once($sourcedir . '/Subs-Post.php');
980
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
981
+			require_once($sourcedir . '/Subs-Post.php');
982
+	}
933 983
 
934 984
 	// Send each email, yea!
935 985
 	$failed_emails = array();
@@ -949,15 +999,17 @@  discard block
 block discarded – undo
949 999
 
950 1000
 			// Try to stop a timeout, this would be bad...
951 1001
 			@set_time_limit(300);
952
-			if (function_exists('apache_reset_timeout'))
953
-				@apache_reset_timeout();
1002
+			if (function_exists('apache_reset_timeout')) {
1003
+							@apache_reset_timeout();
1004
+			}
1005
+		} else {
1006
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
954 1007
 		}
955
-		else
956
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
957 1008
 
958 1009
 		// Hopefully it sent?
959
-		if (!$result)
960
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1010
+		if (!$result) {
1011
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1012
+		}
961 1013
 	}
962 1014
 
963 1015
 	// Any emails that didn't send?
@@ -972,8 +1024,8 @@  discard block
 block discarded – undo
972 1024
 		);
973 1025
 
974 1026
 		// If we have failed to many times, tell mail to wait a bit and try again.
975
-		if ($modSettings['mail_failed_attempts'] > 5)
976
-			$smcFunc['db_query']('', '
1027
+		if ($modSettings['mail_failed_attempts'] > 5) {
1028
+					$smcFunc['db_query']('', '
977 1029
 				UPDATE {db_prefix}settings
978 1030
 				SET value = {string:next_mail_send}
979 1031
 				WHERE variable = {literal:mail_next_send}
@@ -982,6 +1034,7 @@  discard block
 block discarded – undo
982 1034
 					'next_mail_send' => time() + 60,
983 1035
 					'last_send' => $modSettings['mail_next_send'],
984 1036
 			));
1037
+		}
985 1038
 
986 1039
 		// Add our email back to the queue, manually.
987 1040
 		$smcFunc['db_insert']('insert',
@@ -994,8 +1047,8 @@  discard block
 block discarded – undo
994 1047
 		return false;
995 1048
 	}
996 1049
 	// We where unable to send the email, clear our failed attempts.
997
-	elseif (!empty($modSettings['mail_failed_attempts']))
998
-		$smcFunc['db_query']('', '
1050
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1051
+			$smcFunc['db_query']('', '
999 1052
 			UPDATE {db_prefix}settings
1000 1053
 			SET value = {string:zero}
1001 1054
 			WHERE variable = {string:mail_failed_attempts}',
@@ -1003,6 +1056,7 @@  discard block
 block discarded – undo
1003 1056
 				'zero' => '0',
1004 1057
 				'mail_failed_attempts' => 'mail_failed_attempts',
1005 1058
 		));
1059
+	}
1006 1060
 
1007 1061
 	// Had something to send...
1008 1062
 	return true;
@@ -1019,16 +1073,18 @@  discard block
 block discarded – undo
1019 1073
 	global $modSettings, $smcFunc;
1020 1074
 
1021 1075
 	$task_query = '';
1022
-	if (!is_array($tasks))
1023
-		$tasks = array($tasks);
1076
+	if (!is_array($tasks)) {
1077
+			$tasks = array($tasks);
1078
+	}
1024 1079
 
1025 1080
 	// Actually have something passed?
1026 1081
 	if (!empty($tasks))
1027 1082
 	{
1028
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1029
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1030
-		else
1031
-			$task_query = ' AND task IN ({array_string:tasks})';
1083
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1084
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1085
+		} else {
1086
+					$task_query = ' AND task IN ({array_string:tasks})';
1087
+		}
1032 1088
 	}
1033 1089
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1034 1090
 
@@ -1049,20 +1105,22 @@  discard block
 block discarded – undo
1049 1105
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1050 1106
 
1051 1107
 		// Only bother moving the task if it's out of place or we're forcing it!
1052
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1053
-			$tasks[$row['id_task']] = $next_time;
1054
-		else
1055
-			$next_time = $row['next_time'];
1108
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1109
+					$tasks[$row['id_task']] = $next_time;
1110
+		} else {
1111
+					$next_time = $row['next_time'];
1112
+		}
1056 1113
 
1057 1114
 		// If this is sooner than the current next task, make this the next task.
1058
-		if ($next_time < $nextTaskTime)
1059
-			$nextTaskTime = $next_time;
1115
+		if ($next_time < $nextTaskTime) {
1116
+					$nextTaskTime = $next_time;
1117
+		}
1060 1118
 	}
1061 1119
 	$smcFunc['db_free_result']($request);
1062 1120
 
1063 1121
 	// Now make the changes!
1064
-	foreach ($tasks as $id => $time)
1065
-		$smcFunc['db_query']('', '
1122
+	foreach ($tasks as $id => $time) {
1123
+			$smcFunc['db_query']('', '
1066 1124
 			UPDATE {db_prefix}scheduled_tasks
1067 1125
 			SET next_time = {int:next_time}
1068 1126
 			WHERE id_task = {int:id_task}',
@@ -1071,11 +1129,13 @@  discard block
 block discarded – undo
1071 1129
 				'id_task' => $id,
1072 1130
 			)
1073 1131
 		);
1132
+	}
1074 1133
 
1075 1134
 	// If the next task is now different update.
1076
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1077
-		updateSettings(array('next_task_time' => $nextTaskTime));
1078
-}
1135
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1136
+			updateSettings(array('next_task_time' => $nextTaskTime));
1137
+	}
1138
+	}
1079 1139
 
1080 1140
 /**
1081 1141
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1088,8 +1148,9 @@  discard block
 block discarded – undo
1088 1148
 function next_time($regularity, $unit, $offset)
1089 1149
 {
1090 1150
 	// Just in case!
1091
-	if ($regularity == 0)
1092
-		$regularity = 2;
1151
+	if ($regularity == 0) {
1152
+			$regularity = 2;
1153
+	}
1093 1154
 
1094 1155
 	$curMin = date('i', time());
1095 1156
 
@@ -1099,15 +1160,16 @@  discard block
 block discarded – undo
1099 1160
 		$off = date('i', $offset);
1100 1161
 
1101 1162
 		// If it's now just pretend it ain't,
1102
-		if ($off == $curMin)
1103
-			$next_time = time() + $regularity;
1104
-		else
1163
+		if ($off == $curMin) {
1164
+					$next_time = time() + $regularity;
1165
+		} else
1105 1166
 		{
1106 1167
 			// Make sure that the offset is always in the past.
1107 1168
 			$off = $off > $curMin ? $off - 60 : $off;
1108 1169
 
1109
-			while ($off <= $curMin)
1110
-				$off += $regularity;
1170
+			while ($off <= $curMin) {
1171
+							$off += $regularity;
1172
+			}
1111 1173
 
1112 1174
 			// Now we know when the time should be!
1113 1175
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1127,11 +1189,13 @@  discard block
 block discarded – undo
1127 1189
 		// Default we'll jump in hours.
1128 1190
 		$applyOffset = 3600;
1129 1191
 		// 24 hours = 1 day.
1130
-		if ($unit == 'd')
1131
-			$applyOffset = 86400;
1192
+		if ($unit == 'd') {
1193
+					$applyOffset = 86400;
1194
+		}
1132 1195
 		// Otherwise a week.
1133
-		if ($unit == 'w')
1134
-			$applyOffset = 604800;
1196
+		if ($unit == 'w') {
1197
+					$applyOffset = 604800;
1198
+		}
1135 1199
 
1136 1200
 		$applyOffset *= $regularity;
1137 1201
 
@@ -1168,8 +1232,9 @@  discard block
 block discarded – undo
1168 1232
 		$settings[$row['variable']] = $row['value'];
1169 1233
 
1170 1234
 		// Is this the default theme?
1171
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1172
-			$settings['default_' . $row['variable']] = $row['value'];
1235
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1236
+					$settings['default_' . $row['variable']] = $row['value'];
1237
+		}
1173 1238
 	}
1174 1239
 	$smcFunc['db_free_result']($result);
1175 1240
 
@@ -1179,12 +1244,14 @@  discard block
 block discarded – undo
1179 1244
 		$settings['template_dirs'] = array($settings['theme_dir']);
1180 1245
 
1181 1246
 		// Based on theme (if there is one).
1182
-		if (!empty($settings['base_theme_dir']))
1183
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1247
+		if (!empty($settings['base_theme_dir'])) {
1248
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1249
+		}
1184 1250
 
1185 1251
 		// Lastly the default theme.
1186
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1187
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1252
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1253
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1254
+		}
1188 1255
 	}
1189 1256
 
1190 1257
 	// Assume we want this.
@@ -1330,8 +1397,9 @@  discard block
 block discarded – undo
1330 1397
 	// Ok should we prune the logs?
1331 1398
 	if (!empty($modSettings['pruningOptions']))
1332 1399
 	{
1333
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1334
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1400
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1401
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1402
+		}
1335 1403
 
1336 1404
 		if (!empty($modSettings['pruneErrorLog']))
1337 1405
 		{
@@ -1397,8 +1465,9 @@  discard block
 block discarded – undo
1397 1465
 				)
1398 1466
 			);
1399 1467
 
1400
-			while ($row = $smcFunc['db_fetch_row']($result))
1401
-				$reports[] = $row[0];
1468
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1469
+							$reports[] = $row[0];
1470
+			}
1402 1471
 
1403 1472
 			$smcFunc['db_free_result']($result);
1404 1473
 
@@ -1560,8 +1629,9 @@  discard block
 block discarded – undo
1560 1629
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1561 1630
 
1562 1631
 		// Send the actual email.
1563
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1564
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1632
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1633
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1634
+		}
1565 1635
 
1566 1636
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1567 1637
 		{
@@ -1584,18 +1654,19 @@  discard block
 block discarded – undo
1584 1654
 	}
1585 1655
 
1586 1656
 	// Insert the alerts if any
1587
-	if (!empty($alert_rows))
1588
-		$smcFunc['db_insert']('',
1657
+	if (!empty($alert_rows)) {
1658
+			$smcFunc['db_insert']('',
1589 1659
 			'{db_prefix}user_alerts',
1590 1660
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1591 1661
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1592 1662
 			$alert_rows,
1593 1663
 			array()
1594 1664
 		);
1665
+	}
1595 1666
 
1596 1667
 	// Mark the reminder as sent.
1597
-	if (!empty($subs_reminded))
1598
-		$smcFunc['db_query']('', '
1668
+	if (!empty($subs_reminded)) {
1669
+			$smcFunc['db_query']('', '
1599 1670
 			UPDATE {db_prefix}log_subscribed
1600 1671
 			SET reminder_sent = {int:reminder_sent}
1601 1672
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1604,6 +1675,7 @@  discard block
 block discarded – undo
1604 1675
 				'reminder_sent' => 1,
1605 1676
 			)
1606 1677
 		);
1678
+	}
1607 1679
 
1608 1680
 	return true;
1609 1681
 }
@@ -1619,13 +1691,13 @@  discard block
 block discarded – undo
1619 1691
 	// We need to know where this thing is going.
1620 1692
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1621 1693
 	{
1622
-		if (!is_array($modSettings['attachmentUploadDir']))
1623
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1694
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1695
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1696
+		}
1624 1697
 
1625 1698
 		// Just use the current path for temp files.
1626 1699
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1627
-	}
1628
-	else
1700
+	} else
1629 1701
 	{
1630 1702
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1631 1703
 	}
@@ -1644,14 +1716,16 @@  discard block
 block discarded – undo
1644 1716
 
1645 1717
 		while ($file = readdir($dir))
1646 1718
 		{
1647
-			if ($file == '.' || $file == '..')
1648
-				continue;
1719
+			if ($file == '.' || $file == '..') {
1720
+							continue;
1721
+			}
1649 1722
 
1650 1723
 			if (strpos($file, 'post_tmp_') !== false)
1651 1724
 			{
1652 1725
 				// Temp file is more than 5 hours old!
1653
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1654
-					@unlink($attach_dir . '/' . $file);
1726
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1727
+									@unlink($attach_dir . '/' . $file);
1728
+				}
1655 1729
 			}
1656 1730
 		}
1657 1731
 		closedir($dir);
@@ -1684,8 +1758,9 @@  discard block
 block discarded – undo
1684 1758
 		)
1685 1759
 	);
1686 1760
 
1687
-	while ($row = $smcFunc['db_fetch_row']($request))
1688
-		$topics[] = $row[0];
1761
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1762
+			$topics[] = $row[0];
1763
+	}
1689 1764
 	$smcFunc['db_free_result']($request);
1690 1765
 
1691 1766
 	// Zap, your gone
@@ -1705,8 +1780,9 @@  discard block
 block discarded – undo
1705 1780
 {
1706 1781
 	global $smcFunc, $sourcedir, $modSettings;
1707 1782
 
1708
-	if (empty($modSettings['drafts_keep_days']))
1709
-		return true;
1783
+	if (empty($modSettings['drafts_keep_days'])) {
1784
+			return true;
1785
+	}
1710 1786
 
1711 1787
 	// init
1712 1788
 	$drafts = array();
@@ -1724,8 +1800,9 @@  discard block
 block discarded – undo
1724 1800
 		)
1725 1801
 	);
1726 1802
 
1727
-	while ($row = $smcFunc['db_fetch_row']($request))
1728
-		$drafts[] = (int) $row[0];
1803
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1804
+			$drafts[] = (int) $row[0];
1805
+	}
1729 1806
 	$smcFunc['db_free_result']($request);
1730 1807
 
1731 1808
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +297 added lines, -224 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -54,21 +57,25 @@  discard block
 block discarded – undo
54 57
 
55 58
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
56 59
 	{
57
-			if (!is_array($modSettings['attachment_basedirectories']))
58
-				$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
60
+			if (!is_array($modSettings['attachment_basedirectories'])) {
61
+							$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
62
+			}
59 63
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
64
+	} else {
65
+			$base_dir = 0;
60 66
 	}
61
-	else
62
-		$base_dir = 0;
63 67
 
64 68
 	if ($modSettings['automanage_attachments'] == 1)
65 69
 	{
66
-		if (!isset($modSettings['last_attachments_directory']))
67
-			$modSettings['last_attachments_directory'] = array();
68
-		if (!is_array($modSettings['last_attachments_directory']))
69
-			$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
70
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
71
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
70
+		if (!isset($modSettings['last_attachments_directory'])) {
71
+					$modSettings['last_attachments_directory'] = array();
72
+		}
73
+		if (!is_array($modSettings['last_attachments_directory'])) {
74
+					$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
75
+		}
76
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
77
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
78
+		}
72 79
 	}
73 80
 
74 81
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -97,12 +104,14 @@  discard block
 block discarded – undo
97 104
 			$updir = '';
98 105
 	}
99 106
 
100
-	if (!is_array($modSettings['attachmentUploadDir']))
101
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
102
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
103
-		$outputCreation = automanage_attachments_create_directory($updir);
104
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
105
-		$outputCreation = true;
107
+	if (!is_array($modSettings['attachmentUploadDir'])) {
108
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
109
+	}
110
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
111
+			$outputCreation = automanage_attachments_create_directory($updir);
112
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
113
+			$outputCreation = true;
114
+	}
106 115
 
107 116
 	if ($outputCreation)
108 117
 	{
@@ -139,8 +148,9 @@  discard block
 block discarded – undo
139 148
 		$count = count($tree);
140 149
 
141 150
 		$directory = attachments_init_dir($tree, $count);
142
-		if ($directory === false)
143
-			return false;
151
+		if ($directory === false) {
152
+					return false;
153
+		}
144 154
 	}
145 155
 
146 156
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -168,8 +178,9 @@  discard block
 block discarded – undo
168 178
 	}
169 179
 
170 180
 	// Everything seems fine...let's create the .htaccess
171
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
172
-		secureDirectory($updir, true);
181
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
182
+			secureDirectory($updir, true);
183
+	}
173 184
 
174 185
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
175 186
 	$updir = rtrim($updir, $sep);
@@ -201,8 +212,9 @@  discard block
 block discarded – undo
201 212
 {
202 213
 	global $modSettings, $boarddir;
203 214
 
204
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
205
-		return;
215
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
216
+			return;
217
+	}
206 218
 
207 219
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
208 220
 	// Just to be sure: I don't want directory separators at the end
@@ -214,13 +226,14 @@  discard block
 block discarded – undo
214 226
 	{
215 227
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
216 228
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
229
+	} else {
230
+			$base_dir = 0;
217 231
 	}
218
-	else
219
-		$base_dir = 0;
220 232
 
221 233
 	// Get the last attachment directory for that base directory
222
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
223
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
234
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
235
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
236
+	}
224 237
 	// And increment it.
225 238
 	$modSettings['last_attachments_directory'][$base_dir]++;
226 239
 
@@ -235,10 +248,10 @@  discard block
 block discarded – undo
235 248
 		$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
236 249
 
237 250
 		return true;
251
+	} else {
252
+			return false;
253
+	}
238 254
 	}
239
-	else
240
-		return false;
241
-}
242 255
 
243 256
 /**
244 257
  * Split a path into a list of all directories and subdirectories
@@ -256,12 +269,13 @@  discard block
 block discarded – undo
256 269
 			* in Windows we need to explode for both \ and /
257 270
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
258 271
 	*/
259
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
260
-		$tree = preg_split('#[\\\/]#', $directory);
261
-	else
272
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
273
+			$tree = preg_split('#[\\\/]#', $directory);
274
+	} else
262 275
 	{
263
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
264
-			return false;
276
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
277
+					return false;
278
+		}
265 279
 
266 280
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
267 281
 	}
@@ -285,10 +299,11 @@  discard block
 block discarded – undo
285 299
 		 //Better be sure that the first part of the path is actually a drive letter...
286 300
 		 //...even if, I should check this in the admin page...isn't it?
287 301
 		 //...NHAAA Let's leave space for users' complains! :P
288
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
289
-			$directory = array_shift($tree);
290
-		else
291
-			return false;
302
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
303
+					$directory = array_shift($tree);
304
+		} else {
305
+					return false;
306
+		}
292 307
 
293 308
 		$count--;
294 309
 	}
@@ -303,18 +318,20 @@  discard block
 block discarded – undo
303 318
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
304 319
 
305 320
 	// Make sure we're uploading to the right place.
306
-	if (!empty($modSettings['automanage_attachments']))
307
-		automanage_attachments_check_directory();
321
+	if (!empty($modSettings['automanage_attachments'])) {
322
+			automanage_attachments_check_directory();
323
+	}
308 324
 
309
-	if (!is_array($modSettings['attachmentUploadDir']))
310
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
325
+	if (!is_array($modSettings['attachmentUploadDir'])) {
326
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
327
+	}
311 328
 
312 329
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
313 330
 
314 331
 	// Is the attachments folder actualy there?
315
-	if (!empty($context['dir_creation_error']))
316
-		$initial_error = $context['dir_creation_error'];
317
-	elseif (!is_dir($context['attach_dir']))
332
+	if (!empty($context['dir_creation_error'])) {
333
+			$initial_error = $context['dir_creation_error'];
334
+	} elseif (!is_dir($context['attach_dir']))
318 335
 	{
319 336
 		$initial_error = 'attach_folder_warning';
320 337
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -337,12 +354,12 @@  discard block
 block discarded – undo
337 354
 			);
338 355
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
339 356
 			$smcFunc['db_free_result']($request);
340
-		}
341
-		else
342
-			$context['attachments'] = array(
357
+		} else {
358
+					$context['attachments'] = array(
343 359
 				'quantity' => 0,
344 360
 				'total_size' => 0,
345 361
 			);
362
+		}
346 363
 	}
347 364
 
348 365
 	// Hmm. There are still files in session.
@@ -352,39 +369,44 @@  discard block
 block discarded – undo
352 369
 		// Let's try to keep them. But...
353 370
 		$ignore_temp = true;
354 371
 		// If new files are being added. We can't ignore those
355
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
356
-			if (!empty($dummy))
372
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
373
+					if (!empty($dummy))
357 374
 			{
358 375
 				$ignore_temp = false;
376
+		}
359 377
 				break;
360 378
 			}
361 379
 
362 380
 		// Need to make space for the new files. So, bye bye.
363 381
 		if (!$ignore_temp)
364 382
 		{
365
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
366
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
383
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
384
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
367 385
 					unlink($attachment['tmp_name']);
386
+			}
368 387
 
369 388
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
370 389
 			$_SESSION['temp_attachments'] = array();
371 390
 		}
372 391
 	}
373 392
 
374
-	if (!isset($_FILES['attachment']['name']))
375
-		$_FILES['attachment']['tmp_name'] = array();
393
+	if (!isset($_FILES['attachment']['name'])) {
394
+			$_FILES['attachment']['tmp_name'] = array();
395
+	}
376 396
 
377
-	if (!isset($_SESSION['temp_attachments']))
378
-		$_SESSION['temp_attachments'] = array();
397
+	if (!isset($_SESSION['temp_attachments'])) {
398
+			$_SESSION['temp_attachments'] = array();
399
+	}
379 400
 
380 401
 	// Remember where we are at. If it's anywhere at all.
381
-	if (!$ignore_temp)
382
-		$_SESSION['temp_attachments']['post'] = array(
402
+	if (!$ignore_temp) {
403
+			$_SESSION['temp_attachments']['post'] = array(
383 404
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
384 405
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
385 406
 			'topic' => !empty($topic) ? $topic : 0,
386 407
 			'board' => !empty($board) ? $board : 0,
387 408
 		);
409
+	}
388 410
 
389 411
 	// If we have an initial error, lets just display it.
390 412
 	if (!empty($initial_error))
@@ -392,9 +414,10 @@  discard block
 block discarded – undo
392 414
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
393 415
 
394 416
 		// And delete the files 'cos they ain't going nowhere.
395
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
396
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
417
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
418
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
397 419
 				unlink($_FILES['attachment']['tmp_name'][$n]);
420
+		}
398 421
 
399 422
 		$_FILES['attachment']['tmp_name'] = array();
400 423
 	}
@@ -402,21 +425,24 @@  discard block
 block discarded – undo
402 425
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
403 426
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
404 427
 	{
405
-		if ($_FILES['attachment']['name'][$n] == '')
406
-			continue;
428
+		if ($_FILES['attachment']['name'][$n] == '') {
429
+					continue;
430
+		}
407 431
 
408 432
 		// First, let's first check for PHP upload errors.
409 433
 		$errors = array();
410 434
 		if (!empty($_FILES['attachment']['error'][$n]))
411 435
 		{
412
-			if ($_FILES['attachment']['error'][$n] == 2)
413
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
414
-			elseif ($_FILES['attachment']['error'][$n] == 6)
415
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
416
-			else
417
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
418
-			if (empty($errors))
419
-				$errors[] = 'attach_php_error';
436
+			if ($_FILES['attachment']['error'][$n] == 2) {
437
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
438
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
439
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
440
+			} else {
441
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
442
+			}
443
+			if (empty($errors)) {
444
+							$errors[] = 'attach_php_error';
445
+			}
420 446
 		}
421 447
 
422 448
 		// Try to move and rename the file before doing any more checks on it.
@@ -426,8 +452,9 @@  discard block
 block discarded – undo
426 452
 		{
427 453
 			// The reported MIME type of the attachment might not be reliable.
428 454
 			// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
429
-			if (function_exists('mime_content_type'))
430
-				$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
455
+			if (function_exists('mime_content_type')) {
456
+							$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
457
+			}
431 458
 
432 459
 			$_SESSION['temp_attachments'][$attachID] = array(
433 460
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -439,16 +466,16 @@  discard block
 block discarded – undo
439 466
 			);
440 467
 
441 468
 			// Move the file to the attachments folder with a temp name for now.
442
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
443
-				smf_chmod($destName, 0644);
444
-			else
469
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
470
+							smf_chmod($destName, 0644);
471
+			} else
445 472
 			{
446 473
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
447
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
448
-					unlink($_FILES['attachment']['tmp_name'][$n]);
474
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
475
+									unlink($_FILES['attachment']['tmp_name'][$n]);
476
+				}
449 477
 			}
450
-		}
451
-		else
478
+		} else
452 479
 		{
453 480
 			$_SESSION['temp_attachments'][$attachID] = array(
454 481
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -456,12 +483,14 @@  discard block
 block discarded – undo
456 483
 				'errors' => $errors,
457 484
 			);
458 485
 
459
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
460
-				unlink($_FILES['attachment']['tmp_name'][$n]);
486
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
487
+							unlink($_FILES['attachment']['tmp_name'][$n]);
488
+			}
461 489
 		}
462 490
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
463
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
464
-			attachmentChecks($attachID);
491
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
492
+					attachmentChecks($attachID);
493
+		}
465 494
 	}
466 495
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
467 496
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -488,21 +517,20 @@  discard block
 block discarded – undo
488 517
 	global $modSettings, $context, $sourcedir, $smcFunc;
489 518
 
490 519
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
491
-	if (empty($_SESSION['temp_attachments'][$attachID]))
492
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
493
-
494
-	elseif (empty($attachID))
495
-		$error = '$attachID';
496
-
497
-	elseif (empty($context['attachments']))
498
-		$error = '$context[\'attachments\']';
499
-
500
-	elseif (empty($context['attach_dir']))
501
-		$error = '$context[\'attach_dir\']';
520
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
521
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
522
+	} elseif (empty($attachID)) {
523
+			$error = '$attachID';
524
+	} elseif (empty($context['attachments'])) {
525
+			$error = '$context[\'attachments\']';
526
+	} elseif (empty($context['attach_dir'])) {
527
+			$error = '$context[\'attach_dir\']';
528
+	}
502 529
 
503 530
 	// Let's get their attention.
504
-	if (!empty($error))
505
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
531
+	if (!empty($error)) {
532
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
533
+	}
506 534
 
507 535
 	// Just in case this slipped by the first checks, we stop it here and now
508 536
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -531,8 +559,9 @@  discard block
 block discarded – undo
531 559
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
532 560
 			if (!(empty($size)) && ($size[2] != $old_format))
533 561
 			{
534
-				if (isset($context['validImageTypes'][$size[2]]))
535
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
562
+				if (isset($context['validImageTypes'][$size[2]])) {
563
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
564
+				}
536 565
 			}
537 566
 		}
538 567
 	}
@@ -586,42 +615,48 @@  discard block
 block discarded – undo
586 615
 				// Or, let the user know that it ain't gonna happen.
587 616
 				else
588 617
 				{
589
-					if (isset($context['dir_creation_error']))
590
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
591
-					else
592
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
618
+					if (isset($context['dir_creation_error'])) {
619
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
620
+					} else {
621
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
622
+					}
593 623
 				}
624
+			} else {
625
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
594 626
 			}
595
-			else
596
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
597 627
 		}
598 628
 	}
599 629
 
600 630
 	// Is the file too big?
601 631
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
602
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
632
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
634
+	}
604 635
 
605 636
 	// Check the total upload size for this post...
606
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
607
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
637
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
638
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
639
+	}
608 640
 
609 641
 	// Have we reached the maximum number of files we are allowed?
610 642
 	$context['attachments']['quantity']++;
611 643
 
612 644
 	// Set a max limit if none exists
613
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
614
-		$modSettings['attachmentNumPerPostLimit'] = 50;
645
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
646
+			$modSettings['attachmentNumPerPostLimit'] = 50;
647
+	}
615 648
 
616
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
617
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
649
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
650
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
651
+	}
618 652
 
619 653
 	// File extension check
620 654
 	if (!empty($modSettings['attachmentCheckExtensions']))
621 655
 	{
622 656
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
623
-		foreach ($allowed as $k => $dummy)
624
-			$allowed[$k] = trim($dummy);
657
+		foreach ($allowed as $k => $dummy) {
658
+					$allowed[$k] = trim($dummy);
659
+		}
625 660
 
626 661
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
627 662
 		{
@@ -633,10 +668,12 @@  discard block
 block discarded – undo
633 668
 	// Undo the math if there's an error
634 669
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
635 670
 	{
636
-		if (isset($context['dir_size']))
637
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
638
-		if (isset($context['dir_files']))
639
-			$context['dir_files']--;
671
+		if (isset($context['dir_size'])) {
672
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
673
+		}
674
+		if (isset($context['dir_files'])) {
675
+					$context['dir_files']--;
676
+		}
640 677
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
641 678
 		$context['attachments']['quantity']--;
642 679
 		return false;
@@ -668,12 +705,14 @@  discard block
 block discarded – undo
668 705
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
669 706
 	{
670 707
 		// Got a proper mime type?
671
-		if (!empty($size['mime']))
672
-			$attachmentOptions['mime_type'] = $size['mime'];
708
+		if (!empty($size['mime'])) {
709
+					$attachmentOptions['mime_type'] = $size['mime'];
710
+		}
673 711
 
674 712
 		// Otherwise a valid one?
675
-		elseif (isset($context['validImageTypes'][$size[2]]))
676
-			$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
713
+		elseif (isset($context['validImageTypes'][$size[2]])) {
714
+					$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
715
+		}
677 716
 	}
678 717
 
679 718
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -685,15 +724,17 @@  discard block
 block discarded – undo
685 724
 	}
686 725
 
687 726
 	// Get the hash if no hash has been given yet.
688
-	if (empty($attachmentOptions['file_hash']))
689
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
727
+	if (empty($attachmentOptions['file_hash'])) {
728
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
729
+	}
690 730
 
691 731
 	// Assuming no-one set the extension let's take a look at it.
692 732
 	if (empty($attachmentOptions['fileext']))
693 733
 	{
694 734
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
695
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
696
-			$attachmentOptions['fileext'] = '';
735
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
736
+					$attachmentOptions['fileext'] = '';
737
+		}
697 738
 	}
698 739
 
699 740
 	// Last chance to change stuff!
@@ -702,8 +743,9 @@  discard block
 block discarded – undo
702 743
 	// Make sure the folder is valid...
703 744
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true);
704 745
 	$folders = array_keys($tmp);
705
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
706
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
746
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
747
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
748
+	}
707 749
 
708 750
 	$attachmentOptions['id'] = $smcFunc['db_insert']('',
709 751
 		'{db_prefix}attachments',
@@ -734,8 +776,8 @@  discard block
 block discarded – undo
734 776
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
735 777
 
736 778
 	// If it's not approved then add to the approval queue.
737
-	if (!$attachmentOptions['approved'])
738
-		$smcFunc['db_insert']('',
779
+	if (!$attachmentOptions['approved']) {
780
+			$smcFunc['db_insert']('',
739 781
 			'{db_prefix}approval_queue',
740 782
 			array(
741 783
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -745,9 +787,11 @@  discard block
 block discarded – undo
745 787
 			),
746 788
 			array()
747 789
 		);
790
+	}
748 791
 
749
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
750
-		return true;
792
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
793
+			return true;
794
+	}
751 795
 
752 796
 	// Like thumbnails, do we?
753 797
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -758,13 +802,15 @@  discard block
 block discarded – undo
758 802
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
759 803
 			list ($thumb_width, $thumb_height) = $size;
760 804
 
761
-			if (!empty($size['mime']))
762
-				$thumb_mime = $size['mime'];
763
-			elseif (isset($context['validImageTypes'][$size[2]]))
764
-				$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
805
+			if (!empty($size['mime'])) {
806
+							$thumb_mime = $size['mime'];
807
+			} elseif (isset($context['validImageTypes'][$size[2]])) {
808
+							$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
809
+			}
765 810
 			// Lord only knows how this happened...
766
-			else
767
-				$thumb_mime = '';
811
+			else {
812
+							$thumb_mime = '';
813
+			}
768 814
 
769 815
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
770 816
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -844,15 +890,17 @@  discard block
 block discarded – undo
844 890
 	global $smcFunc;
845 891
 
846 892
 	// Oh, come on!
847
-	if (empty($attachIDs) || empty($msgID))
848
-		return false;
893
+	if (empty($attachIDs) || empty($msgID)) {
894
+			return false;
895
+	}
849 896
 
850 897
 	// "I see what is right and approve, but I do what is wrong."
851 898
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
852 899
 
853 900
 	// One last check
854
-	if (empty($attachIDs))
855
-		return false;
901
+	if (empty($attachIDs)) {
902
+			return false;
903
+	}
856 904
 
857 905
 	// Perform.
858 906
 	$smcFunc['db_query']('', '
@@ -880,8 +928,9 @@  discard block
 block discarded – undo
880 928
 	global $board, $modSettings, $context, $scripturl, $smcFunc;
881 929
 
882 930
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
931
+	if (empty($attachID)) {
932
+			return 'attachments_no_data_loaded';
933
+	}
885 934
 
886 935
 	// Make it easy.
887 936
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +939,23 @@  discard block
 block discarded – undo
890 939
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 940
 
892 941
 	// "I am innocent of the blood of this just person: see ye to it."
893
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
894
-		return $externalParse;
942
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
943
+			return $externalParse;
944
+	}
895 945
 
896 946
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
947
+	if (empty($modSettings['attachmentEnable'])) {
948
+			return 'attachments_not_enable';
949
+	}
899 950
 
900 951
 	// Previewing much? no msg ID has been set yet.
901 952
 	if (!empty($context['preview_message']))
902 953
 	{
903 954
 		$allAttachments = getAttachsByMsg(0);
904 955
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
956
+		if (empty($allAttachments[0][$attachID])) {
957
+					return 'attachments_no_data_loaded';
958
+		}
907 959
 
908 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
909 961
 
@@ -915,57 +967,66 @@  discard block
 block discarded – undo
915 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
916 968
 
917 969
 		// Fix the thumbnail too, if the image has one.
918
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
919
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
970
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
971
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		}
920 973
 
921 974
 		return $attachContext;
922 975
 	}
923 976
 
924 977
 	// There is always the chance someone else has already done our dirty work...
925 978
 	// If so, all pertinent checks were already done. Hopefully...
926
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
927
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
928 982
 
929 983
 	// If we are lucky enough to be in $board's scope then check it!
930
-	if (!empty($board) && !allowedTo('view_attachments', $board))
931
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
932 987
 
933 988
 	// Get the message info associated with this particular attach ID.
934 989
 	$attachInfo = getAttachMsgInfo($attachID);
935 990
 
936 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
937
-	if (empty($attachInfo) || empty($attachInfo['msg']))
938
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
939 995
 
940 996
 	// Hold it! got the info now check if you can see this attachment.
941
-	if (!allowedTo('view_attachments', $attachInfo['board']))
942
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
943 1000
 
944 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
945 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
946 1003
 
947 1004
 	// No point in keep going further.
948
-	if (!allowedTo('view_attachments', $attachContext['board']))
949
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
950 1008
 
951 1009
 	// Load this particular attach's context.
952
-	if (!empty($attachContext))
953
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
954 1013
 
955 1014
 	// One last check, you know, gotta be paranoid...
956
-	else
957
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
958 1018
 
959 1019
 	// This is the last "if" I promise!
960
-	if (empty($attachLoaded))
961
-		return 'attachments_no_data_loaded';
962
-
963
-	else
964
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
965 1025
 
966 1026
 	// You may or may not want to show this under the post.
967
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
968
-		$context['show_attach_under_post'][$attachID] = $attachID;
1027
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1028
+			$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	}
969 1030
 
970 1031
 	// Last minute changes?
971 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -985,8 +1046,9 @@  discard block
 block discarded – undo
985 1046
 {
986 1047
 	global $smcFunc, $modSettings;
987 1048
 
988
-	if (empty($attachIDs))
989
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
990 1052
 
991 1053
 	$return = array();
992 1054
 
@@ -1002,11 +1064,12 @@  discard block
 block discarded – undo
1002 1064
 		)
1003 1065
 	);
1004 1066
 
1005
-	if ($smcFunc['db_num_rows']($request) != 1)
1006
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1007 1070
 
1008
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1009
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1010 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1011 1074
 			'size' => $row['size'],
1012 1075
 			'attachID' => $row['id_attach'],
@@ -1015,6 +1078,7 @@  discard block
 block discarded – undo
1015 1078
 			'mime_type' => $row['mime_type'],
1016 1079
 			'thumb' => $row['id_thumb'],
1017 1080
 		);
1081
+	}
1018 1082
 	$smcFunc['db_free_result']($request);
1019 1083
 
1020 1084
 	return $return;
@@ -1031,8 +1095,9 @@  discard block
 block discarded – undo
1031 1095
 {
1032 1096
 	global $smcFunc;
1033 1097
 
1034
-	if (empty($attachID))
1035
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1036 1101
 
1037 1102
 	$request = $smcFunc['db_query']('', '
1038 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1045,8 +1110,9 @@  discard block
 block discarded – undo
1045 1110
 		)
1046 1111
 	);
1047 1112
 
1048
-	if ($smcFunc['db_num_rows']($request) != 1)
1049
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1050 1116
 
1051 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1052 1118
 	$smcFunc['db_free_result']($request);
@@ -1087,8 +1153,9 @@  discard block
 block discarded – undo
1087 1153
 		$temp = array();
1088 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1089 1155
 		{
1090
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1091
-				continue;
1156
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1157
+							continue;
1158
+			}
1092 1159
 
1093 1160
 			$temp[$row['id_attach']] = $row;
1094 1161
 		}
@@ -1117,8 +1184,9 @@  discard block
 block discarded – undo
1117 1184
 {
1118 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1119 1186
 
1120
-	if (empty($attachments) || empty($attachments[$id_msg]))
1121
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1122 1190
 
1123 1191
 	// Set up the attachment info - based on code by Meriadoc.
1124 1192
 	$attachmentData = array();
@@ -1142,11 +1210,13 @@  discard block
 block discarded – undo
1142 1210
 			);
1143 1211
 
1144 1212
 			// If something is unapproved we'll note it so we can sort them.
1145
-			if (!$attachment['approved'])
1146
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1147 1216
 
1148
-			if (!$attachmentData[$i]['is_image'])
1149
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1150 1220
 
1151 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1152 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1167,11 +1237,11 @@  discard block
 block discarded – undo
1167 1237
 						// So what folder are we putting this image in?
1168 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1169 1239
 						{
1170
-							if (!is_array($modSettings['attachmentUploadDir']))
1171
-								$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1242
+							}
1172 1243
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1173
-						}
1174
-						else
1244
+						} else
1175 1245
 						{
1176 1246
 							$id_folder_thumb = 1;
1177 1247
 						}
@@ -1185,10 +1255,11 @@  discard block
 block discarded – undo
1185 1255
 						$thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : '';
1186 1256
 
1187 1257
 						// Figure out the mime type.
1188
-						if (!empty($size['mime']))
1189
-							$thumb_mime = $size['mime'];
1190
-						else
1191
-							$thumb_mime = 'image/' . $thumb_ext;
1258
+						if (!empty($size['mime'])) {
1259
+													$thumb_mime = $size['mime'];
1260
+						} else {
1261
+													$thumb_mime = 'image/' . $thumb_ext;
1262
+						}
1192 1263
 
1193 1264
 						$thumb_filename = $attachment['filename'] . '_thumb';
1194 1265
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1235,11 +1306,12 @@  discard block
 block discarded – undo
1235 1306
 				}
1236 1307
 			}
1237 1308
 
1238
-			if (!empty($attachment['id_thumb']))
1239
-				$attachmentData[$i]['thumbnail'] = array(
1309
+			if (!empty($attachment['id_thumb'])) {
1310
+							$attachmentData[$i]['thumbnail'] = array(
1240 1311
 					'id' => $attachment['id_thumb'],
1241 1312
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1242 1313
 				);
1314
+			}
1243 1315
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1244 1316
 
1245 1317
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1249,30 +1321,31 @@  discard block
 block discarded – undo
1249 1321
 				{
1250 1322
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1251 1323
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1252
-				}
1253
-				elseif (!empty($modSettings['max_image_width']))
1324
+				} elseif (!empty($modSettings['max_image_width']))
1254 1325
 				{
1255 1326
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1256 1327
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1257 1328
 				}
1258
-			}
1259
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1329
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1260 1330
 			{
1261 1331
 				// If the image is too large to show inline, make it a popup.
1262
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1263
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1264
-				else
1265
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1332
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1333
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1334
+				} else {
1335
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1336
+				}
1266 1337
 			}
1267 1338
 
1268
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1269
-				$attachmentData[$i]['downloads']++;
1339
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1340
+							$attachmentData[$i]['downloads']++;
1341
+			}
1270 1342
 		}
1271 1343
 	}
1272 1344
 
1273 1345
 	// Do we need to instigate a sort?
1274
-	if ($have_unapproved)
1275
-		usort($attachmentData, 'approved_attach_sort');
1346
+	if ($have_unapproved) {
1347
+			usort($attachmentData, 'approved_attach_sort');
1348
+	}
1276 1349
 
1277 1350
 	return $attachmentData;
1278 1351
 }
Please login to merge, or discard this patch.
Sources/Profile.php 1 patch
Braces   +155 added lines, -118 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * The main designating function for modifying profiles. Loads up info, determins what to do, etc.
@@ -30,18 +31,21 @@  discard block
 block discarded – undo
30 31
 	global $smcFunc;
31 32
 
32 33
 	// Don't reload this as we may have processed error strings.
33
-	if (empty($post_errors))
34
-		loadLanguage('Profile+Drafts');
34
+	if (empty($post_errors)) {
35
+			loadLanguage('Profile+Drafts');
36
+	}
35 37
 	loadTemplate('Profile');
36 38
 
37 39
 	require_once($sourcedir . '/Subs-Menu.php');
38 40
 
39 41
 	// Did we get the user by name...
40
-	if (isset($_REQUEST['user']))
41
-		$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
42
+	if (isset($_REQUEST['user'])) {
43
+			$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
44
+	}
42 45
 	// ... or by id_member?
43
-	elseif (!empty($_REQUEST['u']))
44
-		$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
46
+	elseif (!empty($_REQUEST['u'])) {
47
+			$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
48
+	}
45 49
 	// If it was just ?action=profile, edit your own profile, but only if you're not a guest.
46 50
 	else
47 51
 	{
@@ -51,8 +55,9 @@  discard block
 block discarded – undo
51 55
 	}
52 56
 
53 57
 	// Check if loadMemberData() has returned a valid result.
54
-	if (!$memberResult)
55
-		fatal_lang_error('not_a_user', false, 404);
58
+	if (!$memberResult) {
59
+			fatal_lang_error('not_a_user', false, 404);
60
+	}
56 61
 
57 62
 	// If all went well, we have a valid member ID!
58 63
 	list ($memID) = $memberResult;
@@ -68,8 +73,9 @@  discard block
 block discarded – undo
68 73
 
69 74
 	// Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission.
70 75
 	// And we care about what the current user can do, not what the user whose profile it is.
71
-	if ($user_info['mod_cache']['gq'] != '0=1')
72
-		$user_info['permissions'][] = 'approve_group_requests';
76
+	if ($user_info['mod_cache']['gq'] != '0=1') {
77
+			$user_info['permissions'][] = 'approve_group_requests';
78
+	}
73 79
 
74 80
 	// If paid subscriptions are enabled, make sure we actually have at least one subscription available...
75 81
 	$context['subs_available'] = false;
@@ -437,21 +443,25 @@  discard block
 block discarded – undo
437 443
 		foreach ($section['areas'] as $area_id => $area)
438 444
 		{
439 445
 			// If it said no permissions that meant it wasn't valid!
440
-			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any']))
441
-				$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
446
+			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) {
447
+							$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
448
+			}
442 449
 			// Otherwise pick the right set.
443
-			else
444
-				$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
450
+			else {
451
+							$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
452
+			}
445 453
 
446 454
 			// Password required in most cases
447
-			if (!empty($area['password']))
448
-				$context['password_areas'][] = $area_id;
455
+			if (!empty($area['password'])) {
456
+							$context['password_areas'][] = $area_id;
457
+			}
449 458
 		}
450 459
 	}
451 460
 
452 461
 	// Is there an updated message to show?
453
-	if (isset($_GET['updated']))
454
-		$context['profile_updated'] = $txt['profile_updated_own'];
462
+	if (isset($_GET['updated'])) {
463
+			$context['profile_updated'] = $txt['profile_updated_own'];
464
+	}
455 465
 
456 466
 	// Set a few options for the menu.
457 467
 	$menuOptions = array(
@@ -466,8 +476,9 @@  discard block
 block discarded – undo
466 476
 	$profile_include_data = createMenu($profile_areas, $menuOptions);
467 477
 
468 478
 	// No menu means no access.
469
-	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession()))
470
-		fatal_lang_error('no_access', false);
479
+	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) {
480
+			fatal_lang_error('no_access', false);
481
+	}
471 482
 
472 483
 	// Make a note of the Unique ID for this menu.
473 484
 	$context['profile_menu_id'] = $context['max_menu_id'];
@@ -493,8 +504,9 @@  discard block
 block discarded – undo
493 504
 			if ($current_area == $area_id)
494 505
 			{
495 506
 				// This can't happen - but is a security check.
496
-				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false))
497
-					fatal_lang_error('no_access', false);
507
+				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) {
508
+									fatal_lang_error('no_access', false);
509
+				}
498 510
 
499 511
 				// Are we saving data in a valid area?
500 512
 				if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview']))
@@ -513,12 +525,14 @@  discard block
 block discarded – undo
513 525
 				}
514 526
 
515 527
 				// Does this require session validating?
516
-				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner']))
517
-					$security_checks['validate'] = true;
528
+				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) {
529
+									$security_checks['validate'] = true;
530
+				}
518 531
 
519 532
 				// Permissions for good measure.
520
-				if (!empty($profile_include_data['permission']))
521
-					$security_checks['permission'] = $profile_include_data['permission'];
533
+				if (!empty($profile_include_data['permission'])) {
534
+									$security_checks['permission'] = $profile_include_data['permission'];
535
+				}
522 536
 
523 537
 				// Either way got something.
524 538
 				$found_area = true;
@@ -527,21 +541,26 @@  discard block
 block discarded – undo
527 541
 	}
528 542
 
529 543
 	// Oh dear, some serious security lapse is going on here... we'll put a stop to that!
530
-	if (!$found_area)
531
-		fatal_lang_error('no_access', false);
544
+	if (!$found_area) {
545
+			fatal_lang_error('no_access', false);
546
+	}
532 547
 
533 548
 	// Release this now.
534 549
 	unset($profile_areas);
535 550
 
536 551
 	// Now the context is setup have we got any security checks to carry out additional to that above?
537
-	if (isset($security_checks['session']))
538
-		checkSession($security_checks['session']);
539
-	if (isset($security_checks['validate']))
540
-		validateSession();
541
-	if (isset($security_checks['validateToken']))
542
-		validateToken($token_name, $token_type);
543
-	if (isset($security_checks['permission']))
544
-		isAllowedTo($security_checks['permission']);
552
+	if (isset($security_checks['session'])) {
553
+			checkSession($security_checks['session']);
554
+	}
555
+	if (isset($security_checks['validate'])) {
556
+			validateSession();
557
+	}
558
+	if (isset($security_checks['validateToken'])) {
559
+			validateToken($token_name, $token_type);
560
+	}
561
+	if (isset($security_checks['permission'])) {
562
+			isAllowedTo($security_checks['permission']);
563
+	}
545 564
 
546 565
 	// Create a token if needed.
547 566
 	if (isset($security_checks['needsToken']) || isset($security_checks['validateToken']))
@@ -551,8 +570,9 @@  discard block
 block discarded – undo
551 570
 	}
552 571
 
553 572
 	// File to include?
554
-	if (isset($profile_include_data['file']))
555
-		require_once($sourcedir . '/' . $profile_include_data['file']);
573
+	if (isset($profile_include_data['file'])) {
574
+			require_once($sourcedir . '/' . $profile_include_data['file']);
575
+	}
556 576
 
557 577
 	// Build the link tree.
558 578
 	$context['linktree'][] = array(
@@ -560,17 +580,19 @@  discard block
 block discarded – undo
560 580
 		'name' => sprintf($txt['profile_of_username'], $context['member']['name']),
561 581
 	);
562 582
 
563
-	if (!empty($profile_include_data['label']))
564
-		$context['linktree'][] = array(
583
+	if (!empty($profile_include_data['label'])) {
584
+			$context['linktree'][] = array(
565 585
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'],
566 586
 			'name' => $profile_include_data['label'],
567 587
 		);
588
+	}
568 589
 
569
-	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label'])
570
-		$context['linktree'][] = array(
590
+	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) {
591
+			$context['linktree'][] = array(
571 592
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'],
572 593
 			'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0],
573 594
 		);
595
+	}
574 596
 
575 597
 	// Set the template for this area and add the profile layer.
576 598
 	$context['sub_template'] = $profile_include_data['function'];
@@ -596,12 +618,14 @@  discard block
 block discarded – undo
596 618
 		if ($check_password)
597 619
 		{
598 620
 			// Check to ensure we're forcing SSL for authentication
599
-			if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
600
-				fatal_lang_error('login_ssl_required');
621
+			if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
622
+							fatal_lang_error('login_ssl_required');
623
+			}
601 624
 
602 625
 			// You didn't even enter a password!
603
-			if (trim($_POST['oldpasswrd']) == '')
604
-				$post_errors[] = 'no_password';
626
+			if (trim($_POST['oldpasswrd']) == '') {
627
+							$post_errors[] = 'no_password';
628
+			}
605 629
 
606 630
 			// Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password
607 631
 			$_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']);
@@ -610,33 +634,35 @@  discard block
 block discarded – undo
610 634
 			$good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true);
611 635
 
612 636
 			// Bad password!!!
613
-			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd']))
614
-				$post_errors[] = 'bad_password';
637
+			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) {
638
+							$post_errors[] = 'bad_password';
639
+			}
615 640
 
616 641
 			// Warn other elements not to jump the gun and do custom changes!
617
-			if (in_array('bad_password', $post_errors))
618
-				$context['password_auth_failed'] = true;
642
+			if (in_array('bad_password', $post_errors)) {
643
+							$context['password_auth_failed'] = true;
644
+			}
619 645
 		}
620 646
 
621 647
 		// Change the IP address in the database.
622
-		if ($context['user']['is_owner'])
623
-			$profile_vars['member_ip'] = $user_info['ip'];
648
+		if ($context['user']['is_owner']) {
649
+					$profile_vars['member_ip'] = $user_info['ip'];
650
+		}
624 651
 
625 652
 		// Now call the sub-action function...
626 653
 		if ($current_area == 'activateaccount')
627 654
 		{
628
-			if (empty($post_errors))
629
-				activateAccount($memID);
630
-		}
631
-		elseif ($current_area == 'deleteaccount')
655
+			if (empty($post_errors)) {
656
+							activateAccount($memID);
657
+			}
658
+		} elseif ($current_area == 'deleteaccount')
632 659
 		{
633 660
 			if (empty($post_errors))
634 661
 			{
635 662
 				deleteAccount2($memID);
636 663
 				redirectexit();
637 664
 			}
638
-		}
639
-		elseif ($current_area == 'groupmembership' && empty($post_errors))
665
+		} elseif ($current_area == 'groupmembership' && empty($post_errors))
640 666
 		{
641 667
 			$msg = groupMembership2($profile_vars, $post_errors, $memID);
642 668
 
@@ -647,10 +673,9 @@  discard block
 block discarded – undo
647 673
 		elseif ($current_area == 'authentication')
648 674
 		{
649 675
 			authentication($memID, true);
650
-		}
651
-		elseif (in_array($current_area, array('account', 'forumprofile', 'theme')))
652
-			saveProfileFields();
653
-		else
676
+		} elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) {
677
+					saveProfileFields();
678
+		} else
654 679
 		{
655 680
 			$force_redirect = true;
656 681
 			// Ensure we include this.
@@ -666,34 +691,36 @@  discard block
 block discarded – undo
666 691
 			// Load the language file so we can give a nice explanation of the errors.
667 692
 			loadLanguage('Errors');
668 693
 			$context['post_errors'] = $post_errors;
669
-		}
670
-		elseif (!empty($profile_vars))
694
+		} elseif (!empty($profile_vars))
671 695
 		{
672 696
 			// If we've changed the password, notify any integration that may be listening in.
673
-			if (isset($profile_vars['passwd']))
674
-				call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
697
+			if (isset($profile_vars['passwd'])) {
698
+							call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
699
+			}
675 700
 
676 701
 			updateMemberData($memID, $profile_vars);
677 702
 
678 703
 			// What if this is the newest member?
679
-			if ($modSettings['latestMember'] == $memID)
680
-				updateStats('member');
681
-			elseif (isset($profile_vars['real_name']))
682
-				updateSettings(array('memberlist_updated' => time()));
704
+			if ($modSettings['latestMember'] == $memID) {
705
+							updateStats('member');
706
+			} elseif (isset($profile_vars['real_name'])) {
707
+							updateSettings(array('memberlist_updated' => time()));
708
+			}
683 709
 
684 710
 			// If the member changed his/her birthdate, update calendar statistics.
685
-			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name']))
686
-				updateSettings(array(
711
+			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) {
712
+							updateSettings(array(
687 713
 					'calendar_updated' => time(),
688 714
 				));
715
+			}
689 716
 
690 717
 			// Anything worth logging?
691 718
 			if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled']))
692 719
 			{
693 720
 				$log_changes = array();
694 721
 				require_once($sourcedir . '/Logging.php');
695
-				foreach ($context['log_changes'] as $k => $v)
696
-					$log_changes[] = array(
722
+				foreach ($context['log_changes'] as $k => $v) {
723
+									$log_changes[] = array(
697 724
 						'action' => $k,
698 725
 						'log_type' => 'user',
699 726
 						'extra' => array_merge($v, array(
@@ -701,14 +728,16 @@  discard block
 block discarded – undo
701 728
 							'member_affected' => $memID,
702 729
 						)),
703 730
 					);
731
+				}
704 732
 
705 733
 				logActions($log_changes);
706 734
 			}
707 735
 
708 736
 			// Have we got any post save functions to execute?
709
-			if (!empty($context['profile_execute_on_save']))
710
-				foreach ($context['profile_execute_on_save'] as $saveFunc)
737
+			if (!empty($context['profile_execute_on_save'])) {
738
+							foreach ($context['profile_execute_on_save'] as $saveFunc)
711 739
 					$saveFunc();
740
+			}
712 741
 
713 742
 			// Let them know it worked!
714 743
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']);
@@ -722,27 +751,31 @@  discard block
 block discarded – undo
722 751
 	if (!empty($post_errors))
723 752
 	{
724 753
 		// Set all the errors so the template knows what went wrong.
725
-		foreach ($post_errors as $error_type)
726
-			$context['modify_error'][$error_type] = true;
754
+		foreach ($post_errors as $error_type) {
755
+					$context['modify_error'][$error_type] = true;
756
+		}
727 757
 	}
728 758
 	// If it's you then we should redirect upon save.
729
-	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview'])
730
-		redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
731
-	elseif (!empty($force_redirect))
732
-		redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
759
+	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) {
760
+			redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
761
+	} elseif (!empty($force_redirect)) {
762
+			redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
763
+	}
733 764
 
734 765
 
735 766
 	// Get the right callable.
736 767
 	$call = call_helper($profile_include_data['function'], true);
737 768
 
738 769
 	// Is it valid?
739
-	if (!empty($call))
740
-		call_user_func($call, $memID);
770
+	if (!empty($call)) {
771
+			call_user_func($call, $memID);
772
+	}
741 773
 
742 774
 	// Set the page title if it's not already set...
743
-	if (!isset($context['page_title']))
744
-		$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
745
-}
775
+	if (!isset($context['page_title'])) {
776
+			$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
777
+	}
778
+	}
746 779
 
747 780
 /**
748 781
  * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user.
@@ -865,16 +898,18 @@  discard block
 block discarded – undo
865 898
 	if (!allowedTo('admin_forum') && $area != 'register')
866 899
 	{
867 900
 		// If it's the owner they can see two types of private fields, regardless.
868
-		if ($memID == $user_info['id'])
869
-			$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
870
-		else
871
-			$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
901
+		if ($memID == $user_info['id']) {
902
+					$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
903
+		} else {
904
+					$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
905
+		}
872 906
 	}
873 907
 
874
-	if ($area == 'register')
875
-		$where .= ' AND show_reg != 0';
876
-	elseif ($area != 'summary')
877
-		$where .= ' AND show_profile = {string:area}';
908
+	if ($area == 'register') {
909
+			$where .= ' AND show_reg != 0';
910
+	} elseif ($area != 'summary') {
911
+			$where .= ' AND show_profile = {string:area}';
912
+	}
878 913
 
879 914
 	// Load all the relevant fields - and data.
880 915
 	$request = $smcFunc['db_query']('', '
@@ -900,13 +935,15 @@  discard block
 block discarded – undo
900 935
 		if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']]))
901 936
 		{
902 937
 			$value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]);
903
-			if (in_array($row['field_type'], array('select', 'radio')))
904
-					$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
938
+			if (in_array($row['field_type'], array('select', 'radio'))) {
939
+								$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
940
+			}
905 941
 		}
906 942
 
907 943
 		// Don't show the "disabled" option for the "gender" field if we are on the "summary" area.
908
-		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled')
909
-			continue;
944
+		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled') {
945
+					continue;
946
+		}
910 947
 
911 948
 		// HTML for the input form.
912 949
 		$output_html = $value;
@@ -915,8 +952,7 @@  discard block
 block discarded – undo
915 952
 			$true = (!$exists && $row['default_value']) || $value;
916 953
 			$input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . ' class="input_check">';
917 954
 			$output_html = $true ? $txt['yes'] : $txt['no'];
918
-		}
919
-		elseif ($row['field_type'] == 'select')
955
+		} elseif ($row['field_type'] == 'select')
920 956
 		{
921 957
 			$input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>';
922 958
 			$options = explode(',', $row['field_options']);
@@ -924,13 +960,13 @@  discard block
 block discarded – undo
924 960
 			{
925 961
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
926 962
 				$input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>';
927
-				if ($true)
928
-					$output_html = $v;
963
+				if ($true) {
964
+									$output_html = $v;
965
+				}
929 966
 			}
930 967
 
931 968
 			$input_html .= '</select>';
932
-		}
933
-		elseif ($row['field_type'] == 'radio')
969
+		} elseif ($row['field_type'] == 'radio')
934 970
 		{
935 971
 			$input_html = '<fieldset>';
936 972
 			$options = explode(',', $row['field_options']);
@@ -938,36 +974,37 @@  discard block
 block discarded – undo
938 974
 			{
939 975
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
940 976
 				$input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" class="input_radio" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '"' . ($true ? ' checked' : '') . '>' . $v . '</label><br>';
941
-				if ($true)
942
-					$output_html = $v;
977
+				if ($true) {
978
+									$output_html = $v;
979
+				}
943 980
 			}
944 981
 			$input_html .= '</fieldset>';
945
-		}
946
-		elseif ($row['field_type'] == 'text')
982
+		} elseif ($row['field_type'] == 'text')
947 983
 		{
948 984
 			$input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($row['field_length'] != 0 ? ' maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . un_htmlspecialchars($value) . '" class="input_text"' . ($row['show_reg'] == 2 ? ' required' : '') . '>';
949
-		}
950
-		else
985
+		} else
951 986
 		{
952 987
 			@list ($rows, $cols) = @explode(',', $row['default_value']);
953 988
 			$input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '') . '>' . un_htmlspecialchars($value) . '</textarea>';
954 989
 		}
955 990
 
956 991
 		// Parse BBCode
957
-		if ($row['bbc'])
958
-			$output_html = parse_bbc($output_html);
959
-		elseif ($row['field_type'] == 'textarea')
960
-			// Allow for newlines at least
992
+		if ($row['bbc']) {
993
+					$output_html = parse_bbc($output_html);
994
+		} elseif ($row['field_type'] == 'textarea') {
995
+					// Allow for newlines at least
961 996
 			$output_html = strtr($output_html, array("\n" => '<br>'));
997
+		}
962 998
 
963 999
 		// Enclosing the user input within some other text?
964
-		if (!empty($row['enclose']) && !empty($output_html))
965
-			$output_html = strtr($row['enclose'], array(
1000
+		if (!empty($row['enclose']) && !empty($output_html)) {
1001
+					$output_html = strtr($row['enclose'], array(
966 1002
 				'{SCRIPTURL}' => $scripturl,
967 1003
 				'{IMAGES_URL}' => $settings['images_url'],
968 1004
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
969 1005
 				'{INPUT}' => un_htmlspecialchars($output_html),
970 1006
 			));
1007
+		}
971 1008
 
972 1009
 		$context['custom_fields'][] = array(
973 1010
 			'name' => $row['field_name'],
Please login to merge, or discard this patch.
Sources/Post.php 1 patch
Braces   +659 added lines, -511 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * 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']);
@@ -54,8 +57,9 @@  discard block
 block discarded – undo
54 57
 	$context['auto_notify'] = !empty($context['notify_prefs']['msg_auto_notify']);
55 58
 
56 59
 	// You must be posting to *some* board.
57
-	if (empty($board) && !$context['make_event'])
58
-		fatal_lang_error('no_board', false);
60
+	if (empty($board) && !$context['make_event']) {
61
+			fatal_lang_error('no_board', false);
62
+	}
59 63
 
60 64
 	require_once($sourcedir . '/Subs-Post.php');
61 65
 
@@ -78,10 +82,11 @@  discard block
 block discarded – undo
78 82
 			array(
79 83
 				'msg' => (int) $_REQUEST['msg'],
80 84
 		));
81
-		if ($smcFunc['db_num_rows']($request) != 1)
82
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
83
-		else
84
-			list ($topic) = $smcFunc['db_fetch_row']($request);
85
+		if ($smcFunc['db_num_rows']($request) != 1) {
86
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
87
+		} else {
88
+					list ($topic) = $smcFunc['db_fetch_row']($request);
89
+		}
85 90
 		$smcFunc['db_free_result']($request);
86 91
 	}
87 92
 
@@ -108,33 +113,36 @@  discard block
 block discarded – undo
108 113
 		$smcFunc['db_free_result']($request);
109 114
 
110 115
 		// If this topic already has a poll, they sure can't add another.
111
-		if (isset($_REQUEST['poll']) && $pollID > 0)
112
-			unset($_REQUEST['poll']);
116
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
117
+					unset($_REQUEST['poll']);
118
+		}
113 119
 
114 120
 		if (empty($_REQUEST['msg']))
115 121
 		{
116
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
117
-				is_not_guest();
122
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
123
+							is_not_guest();
124
+			}
118 125
 
119 126
 			// By default the reply will be approved...
120 127
 			$context['becomes_approved'] = true;
121 128
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
122 129
 			{
123
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
124
-					$context['becomes_approved'] = false;
125
-				else
126
-					isAllowedTo('post_reply_any');
127
-			}
128
-			elseif (!allowedTo('post_reply_any'))
130
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
131
+									$context['becomes_approved'] = false;
132
+				} else {
133
+									isAllowedTo('post_reply_any');
134
+				}
135
+			} elseif (!allowedTo('post_reply_any'))
129 136
 			{
130
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
131
-					$context['becomes_approved'] = false;
132
-				else
133
-					isAllowedTo('post_reply_own');
137
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
138
+									$context['becomes_approved'] = false;
139
+				} else {
140
+									isAllowedTo('post_reply_own');
141
+				}
134 142
 			}
143
+		} else {
144
+					$context['becomes_approved'] = true;
135 145
 		}
136
-		else
137
-			$context['becomes_approved'] = true;
138 146
 
139 147
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
140 148
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -146,18 +154,19 @@  discard block
 block discarded – undo
146 154
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
147 155
 
148 156
 		// Check whether this is a really old post being bumped...
149
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
150
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
151
-	}
152
-	else
157
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
158
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
159
+		}
160
+	} else
153 161
 	{
154 162
 		$context['becomes_approved'] = true;
155 163
 		if ((!$context['make_event'] || !empty($board)))
156 164
 		{
157
-			if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
158
-				$context['becomes_approved'] = false;
159
-			else
160
-				isAllowedTo('post_new');
165
+			if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
166
+							$context['becomes_approved'] = false;
167
+			} else {
168
+							isAllowedTo('post_new');
169
+			}
161 170
 		}
162 171
 
163 172
 		$locked = 0;
@@ -193,20 +202,24 @@  discard block
 block discarded – undo
193 202
 	}
194 203
 
195 204
 	// Don't allow a post if it's locked and you aren't all powerful.
196
-	if ($locked && !allowedTo('moderate_board'))
197
-		fatal_lang_error('topic_locked', false);
205
+	if ($locked && !allowedTo('moderate_board')) {
206
+			fatal_lang_error('topic_locked', false);
207
+	}
198 208
 	// Check the users permissions - is the user allowed to add or post a poll?
199 209
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
200 210
 	{
201 211
 		// New topic, new poll.
202
-		if (empty($topic))
203
-			isAllowedTo('poll_post');
212
+		if (empty($topic)) {
213
+					isAllowedTo('poll_post');
214
+		}
204 215
 		// This is an old topic - but it is yours!  Can you add to it?
205
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
206
-			isAllowedTo('poll_add_own');
216
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
217
+					isAllowedTo('poll_add_own');
218
+		}
207 219
 		// If you're not the owner, can you add to any poll?
208
-		else
209
-			isAllowedTo('poll_add_any');
220
+		else {
221
+					isAllowedTo('poll_add_any');
222
+		}
210 223
 
211 224
 		require_once($sourcedir . '/Subs-Members.php');
212 225
 		$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
@@ -235,8 +248,9 @@  discard block
 block discarded – undo
235 248
 	if ($context['make_event'])
236 249
 	{
237 250
 		// They might want to pick a board.
238
-		if (!isset($context['current_board']))
239
-			$context['current_board'] = 0;
251
+		if (!isset($context['current_board'])) {
252
+					$context['current_board'] = 0;
253
+		}
240 254
 
241 255
 		// Start loading up the event info.
242 256
 		$context['event'] = array();
@@ -250,10 +264,11 @@  discard block
 block discarded – undo
250 264
 		isAllowedTo('calendar_post');
251 265
 
252 266
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
253
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
254
-			$time_string = '%k:%M';
255
-		else
256
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
267
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
268
+					$time_string = '%k:%M';
269
+		} else {
270
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
271
+		}
257 272
 
258 273
 		$js_time_string = str_replace(
259 274
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -275,8 +290,7 @@  discard block
 block discarded – undo
275 290
 			require_once($sourcedir . '/Subs-Calendar.php');
276 291
 			$eventProperties = getEventProperties($context['event']['id']);
277 292
 			$context['event'] = array_merge($context['event'], $eventProperties);
278
-		}
279
-		else
293
+		} else
280 294
 		{
281 295
 			// Get the current event information.
282 296
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -284,15 +298,18 @@  discard block
 block discarded – undo
284 298
 			$context['event'] = array_merge($context['event'], $eventProperties);
285 299
 
286 300
 			// Make sure the year and month are in the valid range.
287
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
288
-				fatal_lang_error('invalid_month', false);
289
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
290
-				fatal_lang_error('invalid_year', false);
301
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
302
+							fatal_lang_error('invalid_month', false);
303
+			}
304
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
305
+							fatal_lang_error('invalid_year', false);
306
+			}
291 307
 
292 308
 			// Get a list of boards they can post in.
293 309
 			$boards = boardsAllowedTo('post_new');
294
-			if (empty($boards))
295
-				fatal_lang_error('cannot_post_new', 'user');
310
+			if (empty($boards)) {
311
+							fatal_lang_error('cannot_post_new', 'user');
312
+			}
296 313
 
297 314
 			// Load a list of boards for this event in the context.
298 315
 			require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -411,10 +428,11 @@  discard block
 block discarded – undo
411 428
 
412 429
 			if (!empty($context['new_replies']))
413 430
 			{
414
-				if ($context['new_replies'] == 1)
415
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
416
-				else
417
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
431
+				if ($context['new_replies'] == 1) {
432
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
433
+				} else {
434
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
435
+				}
418 436
 
419 437
 				$post_errors[] = 'new_replies';
420 438
 
@@ -426,9 +444,9 @@  discard block
 block discarded – undo
426 444
 	// Get a response prefix (like 'Re:') in the default forum language.
427 445
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
428 446
 	{
429
-		if ($language === $user_info['language'])
430
-			$context['response_prefix'] = $txt['response_prefix'];
431
-		else
447
+		if ($language === $user_info['language']) {
448
+					$context['response_prefix'] = $txt['response_prefix'];
449
+		} else
432 450
 		{
433 451
 			loadLanguage('index', $language, false);
434 452
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -441,8 +459,9 @@  discard block
 block discarded – undo
441 459
 	// Do we have a body, but an error happened.
442 460
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
443 461
 	{
444
-		if (isset($_REQUEST['quickReply']))
445
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
462
+		if (isset($_REQUEST['quickReply'])) {
463
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
464
+		}
446 465
 
447 466
 		// Validate inputs.
448 467
 		if (empty($context['post_error']))
@@ -450,15 +469,17 @@  discard block
 block discarded – undo
450 469
 			// This means they didn't click Post and get an error.
451 470
 			$really_previewing = true;
452 471
 
453
-		}
454
-		else
472
+		} else
455 473
 		{
456
-			if (!isset($_REQUEST['subject']))
457
-				$_REQUEST['subject'] = '';
458
-			if (!isset($_REQUEST['message']))
459
-				$_REQUEST['message'] = '';
460
-			if (!isset($_REQUEST['icon']))
461
-				$_REQUEST['icon'] = 'xx';
474
+			if (!isset($_REQUEST['subject'])) {
475
+							$_REQUEST['subject'] = '';
476
+			}
477
+			if (!isset($_REQUEST['message'])) {
478
+							$_REQUEST['message'] = '';
479
+			}
480
+			if (!isset($_REQUEST['icon'])) {
481
+							$_REQUEST['icon'] = 'xx';
482
+			}
462 483
 
463 484
 			// They are previewing if they asked to preview (i.e. came from quick reply).
464 485
 			$really_previewing = !empty($_POST['preview']);
@@ -474,8 +495,9 @@  discard block
 block discarded – undo
474 495
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
475 496
 
476 497
 		// Make sure the subject isn't too long - taking into account special characters.
477
-		if ($smcFunc['strlen']($form_subject) > 100)
478
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
498
+		if ($smcFunc['strlen']($form_subject) > 100) {
499
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
500
+		}
479 501
 
480 502
 		if (isset($_REQUEST['poll']))
481 503
 		{
@@ -487,8 +509,9 @@  discard block
 block discarded – undo
487 509
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
488 510
 			foreach ($_POST['options'] as $option)
489 511
 			{
490
-				if (trim($option) == '')
491
-					continue;
512
+				if (trim($option) == '') {
513
+									continue;
514
+				}
492 515
 
493 516
 				$context['choices'][] = array(
494 517
 					'id' => $choice_id++,
@@ -550,13 +573,14 @@  discard block
 block discarded – undo
550 573
 				$context['preview_subject'] = $form_subject;
551 574
 
552 575
 				censorText($context['preview_subject']);
576
+			} else {
577
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
553 578
 			}
554
-			else
555
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
556 579
 
557 580
 			// Protect any CDATA blocks.
558
-			if (isset($_REQUEST['xml']))
559
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
581
+			if (isset($_REQUEST['xml'])) {
582
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
583
+			}
560 584
 		}
561 585
 
562 586
 		// Set up the checkboxes.
@@ -595,29 +619,32 @@  discard block
 block discarded – undo
595 619
 			);
596 620
 			// The message they were trying to edit was most likely deleted.
597 621
 			// @todo Change this error message?
598
-			if ($smcFunc['db_num_rows']($request) == 0)
599
-				fatal_lang_error('no_board', false);
622
+			if ($smcFunc['db_num_rows']($request) == 0) {
623
+							fatal_lang_error('no_board', false);
624
+			}
600 625
 			$row = $smcFunc['db_fetch_assoc']($request);
601 626
 
602 627
 			$attachment_stuff = array($row);
603
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
604
-				$attachment_stuff[] = $row2;
628
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
629
+							$attachment_stuff[] = $row2;
630
+			}
605 631
 			$smcFunc['db_free_result']($request);
606 632
 
607 633
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
608 634
 			{
609 635
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
610
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
611
-					fatal_lang_error('modify_post_time_passed', false);
612
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
613
-					isAllowedTo('modify_replies');
614
-				else
615
-					isAllowedTo('modify_own');
636
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
637
+									fatal_lang_error('modify_post_time_passed', false);
638
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
639
+									isAllowedTo('modify_replies');
640
+				} else {
641
+									isAllowedTo('modify_own');
642
+				}
643
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
644
+							isAllowedTo('modify_replies');
645
+			} else {
646
+							isAllowedTo('modify_any');
616 647
 			}
617
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
618
-				isAllowedTo('modify_replies');
619
-			else
620
-				isAllowedTo('modify_any');
621 648
 
622 649
 			if ($context['can_announce'] && !empty($row['id_action']))
623 650
 			{
@@ -641,8 +668,9 @@  discard block
 block discarded – undo
641 668
 
642 669
 				while ($row = $smcFunc['db_fetch_assoc']($request))
643 670
 				{
644
-					if ($row['filesize'] <= 0)
645
-						continue;
671
+					if ($row['filesize'] <= 0) {
672
+											continue;
673
+					}
646 674
 					$context['current_attachments'][$row['id_attach']] = array(
647 675
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
648 676
 						'size' => $row['filesize'],
@@ -712,29 +740,32 @@  discard block
 block discarded – undo
712 740
 			)
713 741
 		);
714 742
 		// The message they were trying to edit was most likely deleted.
715
-		if ($smcFunc['db_num_rows']($request) == 0)
716
-			fatal_lang_error('no_message', false);
743
+		if ($smcFunc['db_num_rows']($request) == 0) {
744
+					fatal_lang_error('no_message', false);
745
+		}
717 746
 		$row = $smcFunc['db_fetch_assoc']($request);
718 747
 
719 748
 		$attachment_stuff = array($row);
720
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
721
-			$attachment_stuff[] = $row2;
749
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
750
+					$attachment_stuff[] = $row2;
751
+		}
722 752
 		$smcFunc['db_free_result']($request);
723 753
 
724 754
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
725 755
 		{
726 756
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
727
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
728
-				fatal_lang_error('modify_post_time_passed', false);
729
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
730
-				isAllowedTo('modify_replies');
731
-			else
732
-				isAllowedTo('modify_own');
757
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
758
+							fatal_lang_error('modify_post_time_passed', false);
759
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
760
+							isAllowedTo('modify_replies');
761
+			} else {
762
+							isAllowedTo('modify_own');
763
+			}
764
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
765
+					isAllowedTo('modify_replies');
766
+		} else {
767
+					isAllowedTo('modify_any');
733 768
 		}
734
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
735
-			isAllowedTo('modify_replies');
736
-		else
737
-			isAllowedTo('modify_any');
738 769
 
739 770
 		if ($context['can_announce'] && !empty($row['id_action']))
740 771
 		{
@@ -761,15 +792,17 @@  discard block
 block discarded – undo
761 792
 		$context['icon'] = $row['icon'];
762 793
 
763 794
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
764
-		if (!$row['approved'] && !$context['show_approval'])
765
-			$context['show_approval'] = allowedTo('approve_posts');
795
+		if (!$row['approved'] && !$context['show_approval']) {
796
+					$context['show_approval'] = allowedTo('approve_posts');
797
+		}
766 798
 
767 799
 		// Sort the attachments so they are in the order saved
768 800
 		$temp = array();
769 801
 		foreach ($attachment_stuff as $attachment)
770 802
 		{
771
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
772
-				$temp[$attachment['id_attach']] = $attachment;
803
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
804
+							$temp[$attachment['id_attach']] = $attachment;
805
+			}
773 806
 
774 807
 		}
775 808
 		ksort($temp);
@@ -831,14 +864,16 @@  discard block
 block discarded – undo
831 864
 					'is_approved' => 1,
832 865
 				)
833 866
 			);
834
-			if ($smcFunc['db_num_rows']($request) == 0)
835
-				fatal_lang_error('quoted_post_deleted', false);
867
+			if ($smcFunc['db_num_rows']($request) == 0) {
868
+							fatal_lang_error('quoted_post_deleted', false);
869
+			}
836 870
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
837 871
 			$smcFunc['db_free_result']($request);
838 872
 
839 873
 			// Add 'Re: ' to the front of the quoted subject.
840
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
841
-				$form_subject = $context['response_prefix'] . $form_subject;
874
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
875
+							$form_subject = $context['response_prefix'] . $form_subject;
876
+			}
842 877
 
843 878
 			// Censor the message and subject.
844 879
 			censorText($form_message);
@@ -851,10 +886,11 @@  discard block
 block discarded – undo
851 886
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
852 887
 				{
853 888
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
854
-					if ($i % 4 == 0)
855
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
889
+					if ($i % 4 == 0) {
890
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
856 891
 						{
857 892
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
893
+					}
858 894
 						}, $parts[$i]);
859 895
 				}
860 896
 				$form_message = implode('', $parts);
@@ -863,8 +899,9 @@  discard block
 block discarded – undo
863 899
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
864 900
 
865 901
 			// Remove any nested quotes, if necessary.
866
-			if (!empty($modSettings['removeNestedQuotes']))
867
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
902
+			if (!empty($modSettings['removeNestedQuotes'])) {
903
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
904
+			}
868 905
 
869 906
 			// Add a quote string on the front and end.
870 907
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -876,15 +913,15 @@  discard block
 block discarded – undo
876 913
 			$form_subject = $first_subject;
877 914
 
878 915
 			// Add 'Re: ' to the front of the subject.
879
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
880
-				$form_subject = $context['response_prefix'] . $form_subject;
916
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
917
+							$form_subject = $context['response_prefix'] . $form_subject;
918
+			}
881 919
 
882 920
 			// Censor the subject.
883 921
 			censorText($form_subject);
884 922
 
885 923
 			$form_message = '';
886
-		}
887
-		else
924
+		} else
888 925
 		{
889 926
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
890 927
 			$form_message = '';
@@ -902,13 +939,15 @@  discard block
 block discarded – undo
902 939
 		if (isset($_REQUEST['msg']))
903 940
 		{
904 941
 			$context['attachments']['quantity'] = count($context['current_attachments']);
905
-			foreach ($context['current_attachments'] as $attachment)
906
-				$context['attachments']['total_size'] += $attachment['size'];
942
+			foreach ($context['current_attachments'] as $attachment) {
943
+							$context['attachments']['total_size'] += $attachment['size'];
944
+			}
907 945
 		}
908 946
 
909 947
 		// A bit of house keeping first.
910
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
911
-			unset($_SESSION['temp_attachments']);
948
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
949
+					unset($_SESSION['temp_attachments']);
950
+		}
912 951
 
913 952
 		if (!empty($_SESSION['temp_attachments']))
914 953
 		{
@@ -917,9 +956,10 @@  discard block
 block discarded – undo
917 956
 			{
918 957
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
919 958
 				{
920
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
921
-						if (file_exists($attachment['tmp_name']))
959
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
960
+											if (file_exists($attachment['tmp_name']))
922 961
 							unlink($attachment['tmp_name']);
962
+					}
923 963
 				}
924 964
 				$post_errors[] = 'temp_attachments_gone';
925 965
 				$_SESSION['temp_attachments'] = array();
@@ -933,8 +973,9 @@  discard block
 block discarded – undo
933 973
 					// See if any files still exist before showing the warning message and the files attached.
934 974
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
935 975
 					{
936
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
937
-							continue;
976
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
977
+													continue;
978
+						}
938 979
 
939 980
 						if (file_exists($attachment['tmp_name']))
940 981
 						{
@@ -944,20 +985,21 @@  discard block
 block discarded – undo
944 985
 							break;
945 986
 						}
946 987
 					}
947
-				}
948
-				else
988
+				} else
949 989
 				{
950 990
 					// Since, they don't belong here. Let's inform the user that they exist..
951
-					if (!empty($topic))
952
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
953
-					else
954
-						$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
991
+					if (!empty($topic)) {
992
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
993
+					} else {
994
+											$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
995
+					}
955 996
 
956 997
 					// Compile a list of the files to show the user.
957 998
 					$file_list = array();
958
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
959
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
999
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1000
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
960 1001
 							$file_list[] = $attachment['name'];
1002
+					}
961 1003
 
962 1004
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
963 1005
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -969,8 +1011,7 @@  discard block
 block discarded – undo
969 1011
 
970 1012
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
971 1013
 						$context['ignore_temp_attachments'] = true;
972
-					}
973
-					else
1014
+					} else
974 1015
 					{
975 1016
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
976 1017
 						$context['ignore_temp_attachments'] = true;
@@ -978,16 +1019,19 @@  discard block
 block discarded – undo
978 1019
 				}
979 1020
 			}
980 1021
 
981
-			if (!empty($context['we_are_history']))
982
-				$post_errors[] = $context['we_are_history'];
1022
+			if (!empty($context['we_are_history'])) {
1023
+							$post_errors[] = $context['we_are_history'];
1024
+			}
983 1025
 
984 1026
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
985 1027
 			{
986
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
987
-					break;
1028
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1029
+									break;
1030
+				}
988 1031
 
989
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
990
-					continue;
1032
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1033
+									continue;
1034
+				}
991 1035
 
992 1036
 				if ($attachID == 'initial_error')
993 1037
 				{
@@ -1002,15 +1046,17 @@  discard block
 block discarded – undo
1002 1046
 				{
1003 1047
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1004 1048
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1005
-					foreach ($attachment['errors'] as $error)
1006
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1049
+					foreach ($attachment['errors'] as $error) {
1050
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1051
+					}
1007 1052
 					$txt['error_attach_errors'] .= '</div>';
1008 1053
 					$post_errors[] = 'attach_errors';
1009 1054
 
1010 1055
 					// Take out the trash.
1011 1056
 					unset($_SESSION['temp_attachments'][$attachID]);
1012
-					if (file_exists($attachment['tmp_name']))
1013
-						unlink($attachment['tmp_name']);
1057
+					if (file_exists($attachment['tmp_name'])) {
1058
+											unlink($attachment['tmp_name']);
1059
+					}
1014 1060
 					continue;
1015 1061
 				}
1016 1062
 
@@ -1023,8 +1069,9 @@  discard block
 block discarded – undo
1023 1069
 
1024 1070
 				$context['attachments']['quantity']++;
1025 1071
 				$context['attachments']['total_size'] += $attachment['size'];
1026
-				if (!isset($context['files_in_session_warning']))
1027
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1072
+				if (!isset($context['files_in_session_warning'])) {
1073
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1074
+				}
1028 1075
 
1029 1076
 				$context['current_attachments'][$attachID] = array(
1030 1077
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1052,8 +1099,9 @@  discard block
 block discarded – undo
1052 1099
 	}
1053 1100
 
1054 1101
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1055
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1056
-		$post_errors[] = 'need_qr_verification';
1102
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1103
+			$post_errors[] = 'need_qr_verification';
1104
+	}
1057 1105
 
1058 1106
 	/*
1059 1107
 	 * There are two error types: serious and minor. Serious errors
@@ -1070,52 +1118,56 @@  discard block
 block discarded – undo
1070 1118
 	{
1071 1119
 		loadLanguage('Errors');
1072 1120
 		$context['error_type'] = 'minor';
1073
-		foreach ($post_errors as $post_error)
1074
-			if (is_array($post_error))
1121
+		foreach ($post_errors as $post_error) {
1122
+					if (is_array($post_error))
1075 1123
 			{
1076 1124
 				$post_error_id = $post_error[0];
1125
+		}
1077 1126
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1078 1127
 
1079 1128
 				// If it's not a minor error flag it as such.
1080
-				if (!in_array($post_error_id, $minor_errors))
1081
-					$context['error_type'] = 'serious';
1082
-			}
1083
-			else
1129
+				if (!in_array($post_error_id, $minor_errors)) {
1130
+									$context['error_type'] = 'serious';
1131
+				}
1132
+			} else
1084 1133
 			{
1085 1134
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1086 1135
 
1087 1136
 				// If it's not a minor error flag it as such.
1088
-				if (!in_array($post_error, $minor_errors))
1089
-					$context['error_type'] = 'serious';
1137
+				if (!in_array($post_error, $minor_errors)) {
1138
+									$context['error_type'] = 'serious';
1139
+				}
1090 1140
 			}
1091 1141
 	}
1092 1142
 
1093 1143
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1094
-	if (isset($_REQUEST['poll']))
1095
-		$context['page_title'] = $txt['new_poll'];
1096
-	elseif ($context['make_event'])
1097
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1098
-	elseif (isset($_REQUEST['msg']))
1099
-		$context['page_title'] = $txt['modify_msg'];
1100
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1101
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1102
-	elseif (empty($topic))
1103
-		$context['page_title'] = $txt['start_new_topic'];
1104
-	else
1105
-		$context['page_title'] = $txt['post_reply'];
1144
+	if (isset($_REQUEST['poll'])) {
1145
+			$context['page_title'] = $txt['new_poll'];
1146
+	} elseif ($context['make_event']) {
1147
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1148
+	} elseif (isset($_REQUEST['msg'])) {
1149
+			$context['page_title'] = $txt['modify_msg'];
1150
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1151
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1152
+	} elseif (empty($topic)) {
1153
+			$context['page_title'] = $txt['start_new_topic'];
1154
+	} else {
1155
+			$context['page_title'] = $txt['post_reply'];
1156
+	}
1106 1157
 
1107 1158
 	// Build the link tree.
1108
-	if (empty($topic))
1109
-		$context['linktree'][] = array(
1159
+	if (empty($topic)) {
1160
+			$context['linktree'][] = array(
1110 1161
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1111 1162
 		);
1112
-	else
1113
-		$context['linktree'][] = array(
1163
+	} else {
1164
+			$context['linktree'][] = array(
1114 1165
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1115 1166
 			'name' => $form_subject,
1116 1167
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1117 1168
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1118 1169
 		);
1170
+	}
1119 1171
 
1120 1172
 	$context['subject'] = addcslashes($form_subject, '"');
1121 1173
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1159,8 +1211,9 @@  discard block
 block discarded – undo
1159 1211
 	// Message icons - customized icons are off?
1160 1212
 	$context['icons'] = getMessageIcons($board);
1161 1213
 
1162
-	if (!empty($context['icons']))
1163
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1214
+	if (!empty($context['icons'])) {
1215
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1216
+	}
1164 1217
 
1165 1218
 	// Are we starting a poll? if set the poll icon as selected if its available
1166 1219
 	if (isset($_REQUEST['poll']))
@@ -1180,8 +1233,9 @@  discard block
 block discarded – undo
1180 1233
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1181 1234
 	{
1182 1235
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1183
-		if ($context['icons'][$i]['selected'])
1184
-			$context['icon_url'] = $context['icons'][$i]['url'];
1236
+		if ($context['icons'][$i]['selected']) {
1237
+					$context['icon_url'] = $context['icons'][$i]['url'];
1238
+		}
1185 1239
 	}
1186 1240
 	if (empty($context['icon_url']))
1187 1241
 	{
@@ -1195,8 +1249,9 @@  discard block
 block discarded – undo
1195 1249
 		));
1196 1250
 	}
1197 1251
 
1198
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1199
-		getTopic();
1252
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1253
+			getTopic();
1254
+	}
1200 1255
 
1201 1256
 	// If the user can post attachments prepare the warning labels.
1202 1257
 	if ($context['can_post_attachment'])
@@ -1207,12 +1262,13 @@  discard block
 block discarded – undo
1207 1262
 		$context['attachment_restrictions'] = array();
1208 1263
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1209 1264
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1210
-		foreach ($attachmentRestrictionTypes as $type)
1211
-			if (!empty($modSettings[$type]))
1265
+		foreach ($attachmentRestrictionTypes as $type) {
1266
+					if (!empty($modSettings[$type]))
1212 1267
 			{
1213 1268
 				// Show the max number of attachments if not 0.
1214 1269
 				if ($type == 'attachmentNumPerPostLimit')
1215 1270
 					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1271
+		}
1216 1272
 			}
1217 1273
 	}
1218 1274
 
@@ -1246,8 +1302,8 @@  discard block
 block discarded – undo
1246 1302
 
1247 1303
 	if (!empty($context['current_attachments']))
1248 1304
 	{
1249
-		foreach ($context['current_attachments'] as $key => $mock)
1250
-			addInlineJavaScript('
1305
+		foreach ($context['current_attachments'] as $key => $mock) {
1306
+					addInlineJavaScript('
1251 1307
 	current_attachments.push({
1252 1308
 		name: '. JavaScriptEscape($mock['name']) . ',
1253 1309
 		size: '. $mock['size'] . ',
@@ -1256,6 +1312,7 @@  discard block
 block discarded – undo
1256 1312
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1257 1313
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1258 1314
 	});', true);
1315
+		}
1259 1316
 	}
1260 1317
 
1261 1318
 	// File Upload.
@@ -1341,8 +1398,9 @@  discard block
 block discarded – undo
1341 1398
 
1342 1399
 
1343 1400
 	// Finally, load the template.
1344
-	if (!isset($_REQUEST['xml']))
1345
-		loadTemplate('Post');
1401
+	if (!isset($_REQUEST['xml'])) {
1402
+			loadTemplate('Post');
1403
+	}
1346 1404
 
1347 1405
 	call_integration_hook('integrate_post_end');
1348 1406
 }
@@ -1363,13 +1421,14 @@  discard block
 block discarded – undo
1363 1421
 	// Sneaking off, are we?
1364 1422
 	if (empty($_POST) && empty($topic))
1365 1423
 	{
1366
-		if (empty($_SERVER['CONTENT_LENGTH']))
1367
-			redirectexit('action=post;board=' . $board . '.0');
1368
-		else
1369
-			fatal_lang_error('post_upload_error', false);
1424
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1425
+					redirectexit('action=post;board=' . $board . '.0');
1426
+		} else {
1427
+					fatal_lang_error('post_upload_error', false);
1428
+		}
1429
+	} elseif (empty($_POST) && !empty($topic)) {
1430
+			redirectexit('action=post;topic=' . $topic . '.0');
1370 1431
 	}
1371
-	elseif (empty($_POST) && !empty($topic))
1372
-		redirectexit('action=post;topic=' . $topic . '.0');
1373 1432
 
1374 1433
 	// No need!
1375 1434
 	$context['robot_no_index'] = true;
@@ -1381,8 +1440,9 @@  discard block
 block discarded – undo
1381 1440
 	$post_errors = array();
1382 1441
 
1383 1442
 	// If the session has timed out, let the user re-submit their form.
1384
-	if (checkSession('post', '', false) != '')
1385
-		$post_errors[] = 'session_timeout';
1443
+	if (checkSession('post', '', false) != '') {
1444
+			$post_errors[] = 'session_timeout';
1445
+	}
1386 1446
 
1387 1447
 	// Wrong verification code?
1388 1448
 	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)))
@@ -1392,33 +1452,38 @@  discard block
 block discarded – undo
1392 1452
 			'id' => 'post',
1393 1453
 		);
1394 1454
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1395
-		if (is_array($context['require_verification']))
1396
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1455
+		if (is_array($context['require_verification'])) {
1456
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1457
+		}
1397 1458
 	}
1398 1459
 
1399 1460
 	require_once($sourcedir . '/Subs-Post.php');
1400 1461
 	loadLanguage('Post');
1401 1462
 
1402 1463
 	// Drafts enabled and needed?
1403
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1404
-		require_once($sourcedir . '/Drafts.php');
1464
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1465
+			require_once($sourcedir . '/Drafts.php');
1466
+	}
1405 1467
 
1406 1468
 	// First check to see if they are trying to delete any current attachments.
1407 1469
 	if (isset($_POST['attach_del']))
1408 1470
 	{
1409 1471
 		$keep_temp = array();
1410 1472
 		$keep_ids = array();
1411
-		foreach ($_POST['attach_del'] as $dummy)
1412
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1473
+		foreach ($_POST['attach_del'] as $dummy) {
1474
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1413 1475
 				$keep_temp[] = $dummy;
1414
-			else
1415
-				$keep_ids[] = (int) $dummy;
1476
+		}
1477
+			else {
1478
+							$keep_ids[] = (int) $dummy;
1479
+			}
1416 1480
 
1417
-		if (isset($_SESSION['temp_attachments']))
1418
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1481
+		if (isset($_SESSION['temp_attachments'])) {
1482
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1419 1483
 			{
1420 1484
 				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)
1421 1485
 					continue;
1486
+		}
1422 1487
 
1423 1488
 				unset($_SESSION['temp_attachments'][$attachID]);
1424 1489
 				unlink($attachment['tmp_name']);
@@ -1460,24 +1525,28 @@  discard block
 block discarded – undo
1460 1525
 		$smcFunc['db_free_result']($request);
1461 1526
 
1462 1527
 		// Though the topic should be there, it might have vanished.
1463
-		if (!is_array($topic_info))
1464
-			fatal_lang_error('topic_doesnt_exist', 404);
1528
+		if (!is_array($topic_info)) {
1529
+					fatal_lang_error('topic_doesnt_exist', 404);
1530
+		}
1465 1531
 
1466 1532
 		// Did this topic suddenly move? Just checking...
1467
-		if ($topic_info['id_board'] != $board)
1468
-			fatal_lang_error('not_a_topic');
1533
+		if ($topic_info['id_board'] != $board) {
1534
+					fatal_lang_error('not_a_topic');
1535
+		}
1469 1536
 	}
1470 1537
 
1471 1538
 	// Replying to a topic?
1472 1539
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1473 1540
 	{
1474 1541
 		// Don't allow a post if it's locked.
1475
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1476
-			fatal_lang_error('topic_locked', false);
1542
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1543
+					fatal_lang_error('topic_locked', false);
1544
+		}
1477 1545
 
1478 1546
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1479
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1480
-			unset($_REQUEST['poll']);
1547
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1548
+					unset($_REQUEST['poll']);
1549
+		}
1481 1550
 
1482 1551
 		// Do the permissions and approval stuff...
1483 1552
 		$becomesApproved = true;
@@ -1493,44 +1562,43 @@  discard block
 block discarded – undo
1493 1562
 
1494 1563
 			// Set a nice session var...
1495 1564
 			$_SESSION['becomesUnapproved'] = true;
1496
-		}
1497
-
1498
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1565
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1499 1566
 		{
1500
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1501
-				$becomesApproved = false;
1502
-
1503
-			else
1504
-				isAllowedTo('post_reply_any');
1505
-		}
1506
-		elseif (!allowedTo('post_reply_any'))
1567
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1568
+							$becomesApproved = false;
1569
+			} else {
1570
+							isAllowedTo('post_reply_any');
1571
+			}
1572
+		} elseif (!allowedTo('post_reply_any'))
1507 1573
 		{
1508
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1509
-				$becomesApproved = false;
1510
-
1511
-			else
1512
-				isAllowedTo('post_reply_own');
1574
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1575
+							$becomesApproved = false;
1576
+			} else {
1577
+							isAllowedTo('post_reply_own');
1578
+			}
1513 1579
 		}
1514 1580
 
1515 1581
 		if (isset($_POST['lock']))
1516 1582
 		{
1517 1583
 			// Nothing is changed to the lock.
1518
-			if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1519
-				unset($_POST['lock']);
1584
+			if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1585
+							unset($_POST['lock']);
1586
+			}
1520 1587
 
1521 1588
 			// You're have no permission to lock this topic.
1522
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1523
-				unset($_POST['lock']);
1589
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1590
+							unset($_POST['lock']);
1591
+			}
1524 1592
 
1525 1593
 			// You are allowed to (un)lock your own topic only.
1526 1594
 			elseif (!allowedTo('lock_any'))
1527 1595
 			{
1528 1596
 				// You cannot override a moderator lock.
1529
-				if ($topic_info['locked'] == 1)
1530
-					unset($_POST['lock']);
1531
-
1532
-				else
1533
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1597
+				if ($topic_info['locked'] == 1) {
1598
+									unset($_POST['lock']);
1599
+				} else {
1600
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1601
+				}
1534 1602
 			}
1535 1603
 			// Hail mighty moderator, (un)lock this topic immediately.
1536 1604
 			else
@@ -1538,19 +1606,21 @@  discard block
 block discarded – undo
1538 1606
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1539 1607
 
1540 1608
 				// Did someone (un)lock this while you were posting?
1541
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1542
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1609
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1610
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1611
+				}
1543 1612
 			}
1544 1613
 		}
1545 1614
 
1546 1615
 		// So you wanna (un)sticky this...let's see.
1547
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1548
-			unset($_POST['sticky']);
1549
-		elseif (isset($_POST['sticky']))
1616
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1617
+					unset($_POST['sticky']);
1618
+		} elseif (isset($_POST['sticky']))
1550 1619
 		{
1551 1620
 			// Did someone (un)sticky this while you were posting?
1552
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1553
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1621
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1622
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1623
+			}
1554 1624
 		}
1555 1625
 
1556 1626
 		// If drafts are enabled, then pass this off
@@ -1577,26 +1647,31 @@  discard block
 block discarded – undo
1577 1647
 
1578 1648
 		// Do like, the permissions, for safety and stuff...
1579 1649
 		$becomesApproved = true;
1580
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1581
-			$becomesApproved = false;
1582
-		else
1583
-			isAllowedTo('post_new');
1650
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1651
+					$becomesApproved = false;
1652
+		} else {
1653
+					isAllowedTo('post_new');
1654
+		}
1584 1655
 
1585 1656
 		if (isset($_POST['lock']))
1586 1657
 		{
1587 1658
 			// New topics are by default not locked.
1588
-			if (empty($_POST['lock']))
1589
-				unset($_POST['lock']);
1659
+			if (empty($_POST['lock'])) {
1660
+							unset($_POST['lock']);
1661
+			}
1590 1662
 			// Besides, you need permission.
1591
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1592
-				unset($_POST['lock']);
1663
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1664
+							unset($_POST['lock']);
1665
+			}
1593 1666
 			// A moderator-lock (1) can override a user-lock (2).
1594
-			else
1595
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1667
+			else {
1668
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1669
+			}
1596 1670
 		}
1597 1671
 
1598
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1599
-			unset($_POST['sticky']);
1672
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1673
+					unset($_POST['sticky']);
1674
+		}
1600 1675
 
1601 1676
 		// Saving your new topic as a draft first?
1602 1677
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1621,31 +1696,37 @@  discard block
 block discarded – undo
1621 1696
 				'id_msg' => $_REQUEST['msg'],
1622 1697
 			)
1623 1698
 		);
1624
-		if ($smcFunc['db_num_rows']($request) == 0)
1625
-			fatal_lang_error('cant_find_messages', false);
1699
+		if ($smcFunc['db_num_rows']($request) == 0) {
1700
+					fatal_lang_error('cant_find_messages', false);
1701
+		}
1626 1702
 		$row = $smcFunc['db_fetch_assoc']($request);
1627 1703
 		$smcFunc['db_free_result']($request);
1628 1704
 
1629
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1630
-			fatal_lang_error('topic_locked', false);
1705
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1706
+					fatal_lang_error('topic_locked', false);
1707
+		}
1631 1708
 
1632 1709
 		if (isset($_POST['lock']))
1633 1710
 		{
1634 1711
 			// Nothing changes to the lock status.
1635
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1636
-				unset($_POST['lock']);
1712
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1713
+							unset($_POST['lock']);
1714
+			}
1637 1715
 			// You're simply not allowed to (un)lock this.
1638
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1639
-				unset($_POST['lock']);
1716
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1717
+							unset($_POST['lock']);
1718
+			}
1640 1719
 			// You're only allowed to lock your own topics.
1641 1720
 			elseif (!allowedTo('lock_any'))
1642 1721
 			{
1643 1722
 				// You're not allowed to break a moderator's lock.
1644
-				if ($topic_info['locked'] == 1)
1645
-					unset($_POST['lock']);
1723
+				if ($topic_info['locked'] == 1) {
1724
+									unset($_POST['lock']);
1725
+				}
1646 1726
 				// Lock it with a soft lock or unlock it.
1647
-				else
1648
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1727
+				else {
1728
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1729
+				}
1649 1730
 			}
1650 1731
 			// You must be the moderator.
1651 1732
 			else
@@ -1653,44 +1734,46 @@  discard block
 block discarded – undo
1653 1734
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1654 1735
 
1655 1736
 				// Did someone (un)lock this while you were posting?
1656
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1657
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1737
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1738
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1739
+				}
1658 1740
 			}
1659 1741
 		}
1660 1742
 
1661 1743
 		// Change the sticky status of this topic?
1662
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1663
-			unset($_POST['sticky']);
1664
-		elseif (isset($_POST['sticky']))
1744
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1745
+					unset($_POST['sticky']);
1746
+		} elseif (isset($_POST['sticky']))
1665 1747
 		{
1666 1748
 			// Did someone (un)sticky this while you were posting?
1667
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1668
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1749
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1750
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1751
+			}
1669 1752
 		}
1670 1753
 
1671 1754
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1672 1755
 		{
1673
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1674
-				fatal_lang_error('modify_post_time_passed', false);
1675
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1676
-				isAllowedTo('modify_replies');
1677
-			else
1678
-				isAllowedTo('modify_own');
1679
-		}
1680
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1756
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1757
+							fatal_lang_error('modify_post_time_passed', false);
1758
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1759
+							isAllowedTo('modify_replies');
1760
+			} else {
1761
+							isAllowedTo('modify_own');
1762
+			}
1763
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1681 1764
 		{
1682 1765
 			isAllowedTo('modify_replies');
1683 1766
 
1684 1767
 			// If you're modifying a reply, I say it better be logged...
1685 1768
 			$moderationAction = true;
1686
-		}
1687
-		else
1769
+		} else
1688 1770
 		{
1689 1771
 			isAllowedTo('modify_any');
1690 1772
 
1691 1773
 			// Log it, assuming you're not modifying your own post.
1692
-			if ($row['id_member'] != $user_info['id'])
1693
-				$moderationAction = true;
1774
+			if ($row['id_member'] != $user_info['id']) {
1775
+							$moderationAction = true;
1776
+			}
1694 1777
 		}
1695 1778
 
1696 1779
 		// If drafts are enabled, then lets send this off to save
@@ -1727,20 +1810,24 @@  discard block
 block discarded – undo
1727 1810
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1728 1811
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1729 1812
 
1730
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1731
-			$post_errors[] = 'no_name';
1732
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1733
-			$post_errors[] = 'long_name';
1813
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1814
+					$post_errors[] = 'no_name';
1815
+		}
1816
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1817
+					$post_errors[] = 'long_name';
1818
+		}
1734 1819
 
1735 1820
 		if (empty($modSettings['guest_post_no_email']))
1736 1821
 		{
1737 1822
 			// Only check if they changed it!
1738 1823
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1739 1824
 			{
1740
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1741
-					$post_errors[] = 'no_email';
1742
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1743
-					$post_errors[] = 'bad_email';
1825
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1826
+									$post_errors[] = 'no_email';
1827
+				}
1828
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1829
+									$post_errors[] = 'bad_email';
1830
+				}
1744 1831
 			}
1745 1832
 
1746 1833
 			// Now make sure this email address is not banned from posting.
@@ -1756,75 +1843,89 @@  discard block
 block discarded – undo
1756 1843
 	}
1757 1844
 
1758 1845
 	// Coming from the quickReply?
1759
-	if (isset($_POST['quickReply']))
1760
-		$_POST['message'] = $_POST['quickReply'];
1846
+	if (isset($_POST['quickReply'])) {
1847
+			$_POST['message'] = $_POST['quickReply'];
1848
+	}
1761 1849
 
1762 1850
 	// Check the subject and message.
1763
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1764
-		$post_errors[] = 'no_subject';
1765
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1766
-		$post_errors[] = 'no_message';
1767
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1768
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1769
-	else
1851
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1852
+			$post_errors[] = 'no_subject';
1853
+	}
1854
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1855
+			$post_errors[] = 'no_message';
1856
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1857
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1858
+	} else
1770 1859
 	{
1771 1860
 		// Prepare the message a bit for some additional testing.
1772 1861
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1773 1862
 
1774 1863
 		// Preparse code. (Zef)
1775
-		if ($user_info['is_guest'])
1776
-			$user_info['name'] = $_POST['guestname'];
1864
+		if ($user_info['is_guest']) {
1865
+					$user_info['name'] = $_POST['guestname'];
1866
+		}
1777 1867
 		preparsecode($_POST['message']);
1778 1868
 
1779 1869
 		// Let's see if there's still some content left without the tags.
1780
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1781
-			$post_errors[] = 'no_message';
1870
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1871
+					$post_errors[] = 'no_message';
1872
+		}
1873
+	}
1874
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1875
+			$post_errors[] = 'no_event';
1782 1876
 	}
1783
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1784
-		$post_errors[] = 'no_event';
1785 1877
 	// You are not!
1786
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1787
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1878
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1879
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1880
+	}
1788 1881
 
1789 1882
 	// Validate the poll...
1790 1883
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1791 1884
 	{
1792
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1793
-			fatal_lang_error('no_access', false);
1885
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1886
+					fatal_lang_error('no_access', false);
1887
+		}
1794 1888
 
1795 1889
 		// This is a new topic... so it's a new poll.
1796
-		if (empty($topic))
1797
-			isAllowedTo('poll_post');
1890
+		if (empty($topic)) {
1891
+					isAllowedTo('poll_post');
1892
+		}
1798 1893
 		// Can you add to your own topics?
1799
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1800
-			isAllowedTo('poll_add_own');
1894
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1895
+					isAllowedTo('poll_add_own');
1896
+		}
1801 1897
 		// Can you add polls to any topic, then?
1802
-		else
1803
-			isAllowedTo('poll_add_any');
1898
+		else {
1899
+					isAllowedTo('poll_add_any');
1900
+		}
1804 1901
 
1805
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1806
-			$post_errors[] = 'no_question';
1902
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1903
+					$post_errors[] = 'no_question';
1904
+		}
1807 1905
 
1808 1906
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1809 1907
 
1810 1908
 		// Get rid of empty ones.
1811
-		foreach ($_POST['options'] as $k => $option)
1812
-			if ($option == '')
1909
+		foreach ($_POST['options'] as $k => $option) {
1910
+					if ($option == '')
1813 1911
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1912
+		}
1814 1913
 
1815 1914
 		// What are you going to vote between with one choice?!?
1816
-		if (count($_POST['options']) < 2)
1817
-			$post_errors[] = 'poll_few';
1818
-		elseif (count($_POST['options']) > 256)
1819
-			$post_errors[] = 'poll_many';
1915
+		if (count($_POST['options']) < 2) {
1916
+					$post_errors[] = 'poll_few';
1917
+		} elseif (count($_POST['options']) > 256) {
1918
+					$post_errors[] = 'poll_many';
1919
+		}
1820 1920
 	}
1821 1921
 
1822 1922
 	if ($posterIsGuest)
1823 1923
 	{
1824 1924
 		// If user is a guest, make sure the chosen name isn't taken.
1825 1925
 		require_once($sourcedir . '/Subs-Members.php');
1826
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1827
-			$post_errors[] = 'bad_name';
1926
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
1927
+					$post_errors[] = 'bad_name';
1928
+		}
1828 1929
 	}
1829 1930
 	// If the user isn't a guest, get his or her name and email.
1830 1931
 	elseif (!isset($_REQUEST['msg']))
@@ -1855,8 +1956,9 @@  discard block
 block discarded – undo
1855 1956
 	}
1856 1957
 
1857 1958
 	// Make sure the user isn't spamming the board.
1858
-	if (!isset($_REQUEST['msg']))
1859
-		spamProtection('post');
1959
+	if (!isset($_REQUEST['msg'])) {
1960
+			spamProtection('post');
1961
+	}
1860 1962
 
1861 1963
 	// At about this point, we're posting and that's that.
1862 1964
 	ignore_user_abort(true);
@@ -1869,32 +1971,36 @@  discard block
 block discarded – undo
1869 1971
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1870 1972
 
1871 1973
 	// At this point, we want to make sure the subject isn't too long.
1872
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1873
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
1974
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
1975
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
1976
+	}
1874 1977
 
1875 1978
 	// Same with the "why did you edit this" text.
1876
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1877
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
1979
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
1980
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
1981
+	}
1878 1982
 
1879 1983
 	// Make the poll...
1880 1984
 	if (isset($_REQUEST['poll']))
1881 1985
 	{
1882 1986
 		// Make sure that the user has not entered a ridiculous number of options..
1883
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1884
-			$_POST['poll_max_votes'] = 1;
1885
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1886
-			$_POST['poll_max_votes'] = count($_POST['options']);
1887
-		else
1888
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
1987
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
1988
+					$_POST['poll_max_votes'] = 1;
1989
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
1990
+					$_POST['poll_max_votes'] = count($_POST['options']);
1991
+		} else {
1992
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
1993
+		}
1889 1994
 
1890 1995
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1891 1996
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1892 1997
 
1893 1998
 		// Just set it to zero if it's not there..
1894
-		if (!isset($_POST['poll_hide']))
1895
-			$_POST['poll_hide'] = 0;
1896
-		else
1897
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
1999
+		if (!isset($_POST['poll_hide'])) {
2000
+					$_POST['poll_hide'] = 0;
2001
+		} else {
2002
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2003
+		}
1898 2004
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1899 2005
 
1900 2006
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1903,16 +2009,19 @@  discard block
 block discarded – undo
1903 2009
 		{
1904 2010
 			require_once($sourcedir . '/Subs-Members.php');
1905 2011
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1906
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1907
-				$_POST['poll_guest_vote'] = 0;
2012
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2013
+							$_POST['poll_guest_vote'] = 0;
2014
+			}
1908 2015
 		}
1909 2016
 
1910 2017
 		// If the user tries to set the poll too far in advance, don't let them.
1911
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1912
-			fatal_lang_error('poll_range_error', false);
2018
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2019
+					fatal_lang_error('poll_range_error', false);
2020
+		}
1913 2021
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1914
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1915
-			$_POST['poll_hide'] = 1;
2022
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2023
+					$_POST['poll_hide'] = 1;
2024
+		}
1916 2025
 
1917 2026
 		// Clean up the question and answers.
1918 2027
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1926,13 +2035,15 @@  discard block
 block discarded – undo
1926 2035
 	{
1927 2036
 		$attachIDs = array();
1928 2037
 		$attach_errors = array();
1929
-		if (!empty($context['we_are_history']))
1930
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2038
+		if (!empty($context['we_are_history'])) {
2039
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2040
+		}
1931 2041
 
1932 2042
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
1933 2043
 		{
1934
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1935
-				continue;
2044
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2045
+							continue;
2046
+			}
1936 2047
 
1937 2048
 			// If there was an initial error just show that message.
1938 2049
 			if ($attachID == 'initial_error')
@@ -1961,12 +2072,13 @@  discard block
 block discarded – undo
1961 2072
 				if (createAttachment($attachmentOptions))
1962 2073
 				{
1963 2074
 					$attachIDs[] = $attachmentOptions['id'];
1964
-					if (!empty($attachmentOptions['thumb']))
1965
-						$attachIDs[] = $attachmentOptions['thumb'];
2075
+					if (!empty($attachmentOptions['thumb'])) {
2076
+											$attachIDs[] = $attachmentOptions['thumb'];
2077
+					}
1966 2078
 				}
2079
+			} else {
2080
+							$attach_errors[] = '<dt>&nbsp;</dt>';
1967 2081
 			}
1968
-			else
1969
-				$attach_errors[] = '<dt>&nbsp;</dt>';
1970 2082
 
1971 2083
 			if (!empty($attachmentOptions['errors']))
1972 2084
 			{
@@ -1978,14 +2090,16 @@  discard block
 block discarded – undo
1978 2090
 					if (!is_array($error))
1979 2091
 					{
1980 2092
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
1981
-						if (in_array($error, $log_these))
1982
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2093
+						if (in_array($error, $log_these)) {
2094
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2095
+						}
2096
+					} else {
2097
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
1983 2098
 					}
1984
-					else
1985
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
1986 2099
 				}
1987
-				if (file_exists($attachment['tmp_name']))
1988
-					unlink($attachment['tmp_name']);
2100
+				if (file_exists($attachment['tmp_name'])) {
2101
+									unlink($attachment['tmp_name']);
2102
+				}
1989 2103
 			}
1990 2104
 		}
1991 2105
 		unset($_SESSION['temp_attachments']);
@@ -2026,24 +2140,24 @@  discard block
 block discarded – undo
2026 2140
 		);
2027 2141
 
2028 2142
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2143
+	} else {
2144
+			$id_poll = 0;
2029 2145
 	}
2030
-	else
2031
-		$id_poll = 0;
2032 2146
 
2033 2147
 	// Creating a new topic?
2034 2148
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2035 2149
 
2036 2150
 	// Check the icon.
2037
-	if (!isset($_POST['icon']))
2038
-		$_POST['icon'] = 'xx';
2039
-
2040
-	else
2151
+	if (!isset($_POST['icon'])) {
2152
+			$_POST['icon'] = 'xx';
2153
+	} else
2041 2154
 	{
2042 2155
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2043 2156
 
2044 2157
 		// Need to figure it out if this is a valid icon name.
2045
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2046
-			$_POST['icon'] = 'xx';
2158
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2159
+					$_POST['icon'] = 'xx';
2160
+		}
2047 2161
 	}
2048 2162
 
2049 2163
 	// Collect all parameters for the creation or modification of a post.
@@ -2084,8 +2198,9 @@  discard block
 block discarded – undo
2084 2198
 		}
2085 2199
 
2086 2200
 		// This will save some time...
2087
-		if (empty($approve_has_changed))
2088
-			unset($msgOptions['approved']);
2201
+		if (empty($approve_has_changed)) {
2202
+					unset($msgOptions['approved']);
2203
+		}
2089 2204
 
2090 2205
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2091 2206
 	}
@@ -2094,8 +2209,9 @@  discard block
 block discarded – undo
2094 2209
 	{
2095 2210
 		createPost($msgOptions, $topicOptions, $posterOptions);
2096 2211
 
2097
-		if (isset($topicOptions['id']))
2098
-			$topic = $topicOptions['id'];
2212
+		if (isset($topicOptions['id'])) {
2213
+					$topic = $topicOptions['id'];
2214
+		}
2099 2215
 	}
2100 2216
 
2101 2217
 	// Assign the previously uploaded attachments to the brand new message.
@@ -2107,8 +2223,9 @@  discard block
 block discarded – undo
2107 2223
 	}
2108 2224
 
2109 2225
 	// If we had a draft for this, its time to remove it since it was just posted
2110
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2111
-		DeleteDraft($_POST['id_draft']);
2226
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2227
+			DeleteDraft($_POST['id_draft']);
2228
+	}
2112 2229
 
2113 2230
 	// Editing or posting an event?
2114 2231
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2127,8 +2244,7 @@  discard block
 block discarded – undo
2127 2244
 			'member' => $user_info['id'],
2128 2245
 		);
2129 2246
 		insertEvent($eventOptions);
2130
-	}
2131
-	elseif (isset($_POST['calendar']))
2247
+	} elseif (isset($_POST['calendar']))
2132 2248
 	{
2133 2249
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2134 2250
 
@@ -2156,14 +2272,15 @@  discard block
 block discarded – undo
2156 2272
 		}
2157 2273
 
2158 2274
 		// Delete it?
2159
-		if (isset($_REQUEST['deleteevent']))
2160
-			$smcFunc['db_query']('', '
2275
+		if (isset($_REQUEST['deleteevent'])) {
2276
+					$smcFunc['db_query']('', '
2161 2277
 				DELETE FROM {db_prefix}calendar
2162 2278
 				WHERE id_event = {int:id_event}',
2163 2279
 				array(
2164 2280
 					'id_event' => $_REQUEST['eventid'],
2165 2281
 				)
2166 2282
 			);
2283
+		}
2167 2284
 		// ... or just update it?
2168 2285
 		else
2169 2286
 		{
@@ -2205,9 +2322,8 @@  discard block
 block discarded – undo
2205 2322
 			array($user_info['id'], $topic, 0),
2206 2323
 			array('id_member', 'id_topic', 'id_board')
2207 2324
 		);
2208
-	}
2209
-	elseif (!$newTopic)
2210
-		$smcFunc['db_query']('', '
2325
+	} elseif (!$newTopic) {
2326
+			$smcFunc['db_query']('', '
2211 2327
 			DELETE FROM {db_prefix}log_notify
2212 2328
 			WHERE id_member = {int:current_member}
2213 2329
 				AND id_topic = {int:current_topic}',
@@ -2216,16 +2332,20 @@  discard block
 block discarded – undo
2216 2332
 				'current_topic' => $topic,
2217 2333
 			)
2218 2334
 		);
2335
+	}
2219 2336
 
2220 2337
 	// Log an act of moderation - modifying.
2221
-	if (!empty($moderationAction))
2222
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2338
+	if (!empty($moderationAction)) {
2339
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2340
+	}
2223 2341
 
2224
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2225
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2342
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2343
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2344
+	}
2226 2345
 
2227
-	if (isset($_POST['sticky']))
2228
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2346
+	if (isset($_POST['sticky'])) {
2347
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2348
+	}
2229 2349
 
2230 2350
 	// Returning to the topic?
2231 2351
 	if (!empty($_REQUEST['goback']))
@@ -2244,26 +2364,31 @@  discard block
 block discarded – undo
2244 2364
 		);
2245 2365
 	}
2246 2366
 
2247
-	if ($board_info['num_topics'] == 0)
2248
-		cache_put_data('board-' . $board, null, 120);
2367
+	if ($board_info['num_topics'] == 0) {
2368
+			cache_put_data('board-' . $board, null, 120);
2369
+	}
2249 2370
 
2250 2371
 	call_integration_hook('integrate_post2_end');
2251 2372
 
2252
-	if (!empty($_POST['announce_topic']))
2253
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2373
+	if (!empty($_POST['announce_topic'])) {
2374
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2375
+	}
2254 2376
 
2255
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2256
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2377
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2378
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2379
+	}
2257 2380
 
2258 2381
 	// Return to post if the mod is on.
2259
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2260
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2261
-	elseif (!empty($_REQUEST['goback']))
2262
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2382
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2383
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2384
+	} elseif (!empty($_REQUEST['goback'])) {
2385
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2386
+	}
2263 2387
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2264
-	else
2265
-		redirectexit('board=' . $board . '.0');
2266
-}
2388
+	else {
2389
+			redirectexit('board=' . $board . '.0');
2390
+	}
2391
+	}
2267 2392
 
2268 2393
 /**
2269 2394
  * Handle the announce topic function (action=announce).
@@ -2281,8 +2406,9 @@  discard block
 block discarded – undo
2281 2406
 
2282 2407
 	validateSession();
2283 2408
 
2284
-	if (empty($topic))
2285
-		fatal_lang_error('topic_gone', false);
2409
+	if (empty($topic)) {
2410
+			fatal_lang_error('topic_gone', false);
2411
+	}
2286 2412
 
2287 2413
 	loadLanguage('Post');
2288 2414
 	loadTemplate('Post');
@@ -2309,8 +2435,9 @@  discard block
 block discarded – undo
2309 2435
 	global $txt, $context, $topic, $board_info, $smcFunc;
2310 2436
 
2311 2437
 	$groups = array_merge($board_info['groups'], array(1));
2312
-	foreach ($groups as $id => $group)
2313
-		$groups[$id] = (int) $group;
2438
+	foreach ($groups as $id => $group) {
2439
+			$groups[$id] = (int) $group;
2440
+	}
2314 2441
 
2315 2442
 	$context['groups'] = array();
2316 2443
 	if (in_array(0, $groups))
@@ -2353,8 +2480,9 @@  discard block
 block discarded – undo
2353 2480
 			'group_list' => $groups,
2354 2481
 		)
2355 2482
 	);
2356
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2357
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2483
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2484
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2485
+	}
2358 2486
 	$smcFunc['db_free_result']($request);
2359 2487
 
2360 2488
 	// Get the subject of the topic we're about to announce.
@@ -2396,16 +2524,19 @@  discard block
 block discarded – undo
2396 2524
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2397 2525
 	$groups = array_merge($board_info['groups'], array(1));
2398 2526
 
2399
-	if (isset($_POST['membergroups']))
2400
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2527
+	if (isset($_POST['membergroups'])) {
2528
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2529
+	}
2401 2530
 
2402 2531
 	// Check whether at least one membergroup was selected.
2403
-	if (empty($_POST['who']))
2404
-		fatal_lang_error('no_membergroup_selected');
2532
+	if (empty($_POST['who'])) {
2533
+			fatal_lang_error('no_membergroup_selected');
2534
+	}
2405 2535
 
2406 2536
 	// Make sure all membergroups are integers and can access the board of the announcement.
2407
-	foreach ($_POST['who'] as $id => $mg)
2408
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2537
+	foreach ($_POST['who'] as $id => $mg) {
2538
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2539
+	}
2409 2540
 
2410 2541
 	// Get the topic subject and censor it.
2411 2542
 	$request = $smcFunc['db_query']('', '
@@ -2451,12 +2582,13 @@  discard block
 block discarded – undo
2451 2582
 	if ($smcFunc['db_num_rows']($request) == 0)
2452 2583
 	{
2453 2584
 		logAction('announce_topic', array('topic' => $topic), 'user');
2454
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2455
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2456
-		elseif (!empty($_REQUEST['goback']))
2457
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2458
-		else
2459
-			redirectexit('board=' . $board . '.0');
2585
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2586
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2587
+		} elseif (!empty($_REQUEST['goback'])) {
2588
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2589
+		} else {
2590
+					redirectexit('board=' . $board . '.0');
2591
+		}
2460 2592
 	}
2461 2593
 
2462 2594
 	$announcements = array();
@@ -2475,8 +2607,9 @@  discard block
 block discarded – undo
2475 2607
 	foreach ($rows as $row)
2476 2608
 	{
2477 2609
 		// Force them to have it?
2478
-		if (empty($prefs[$row['id_member']]['announcements']))
2479
-			continue;
2610
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2611
+					continue;
2612
+		}
2480 2613
 
2481 2614
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2482 2615
 
@@ -2504,8 +2637,9 @@  discard block
 block discarded – undo
2504 2637
 	}
2505 2638
 
2506 2639
 	// For each language send a different mail - low priority...
2507
-	foreach ($announcements as $lang => $mail)
2508
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2640
+	foreach ($announcements as $lang => $mail) {
2641
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2642
+	}
2509 2643
 
2510 2644
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2511 2645
 
@@ -2515,9 +2649,10 @@  discard block
 block discarded – undo
2515 2649
 	$context['sub_template'] = 'announcement_send';
2516 2650
 
2517 2651
 	// Go back to the correct language for the user ;).
2518
-	if (!empty($modSettings['userLanguage']))
2519
-		loadLanguage('Post');
2520
-}
2652
+	if (!empty($modSettings['userLanguage'])) {
2653
+			loadLanguage('Post');
2654
+	}
2655
+	}
2521 2656
 
2522 2657
 /**
2523 2658
  * Get the topic for display purposes.
@@ -2530,12 +2665,13 @@  discard block
 block discarded – undo
2530 2665
 {
2531 2666
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2532 2667
 
2533
-	if (isset($_REQUEST['xml']))
2534
-		$limit = '
2668
+	if (isset($_REQUEST['xml'])) {
2669
+			$limit = '
2535 2670
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2536
-	else
2537
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2671
+	} else {
2672
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2538 2673
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2674
+	}
2539 2675
 
2540 2676
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2541 2677
 	$request = $smcFunc['db_query']('', '
@@ -2573,8 +2709,9 @@  discard block
 block discarded – undo
2573 2709
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2574 2710
 		);
2575 2711
 
2576
-		if (!empty($context['new_replies']))
2577
-			$context['new_replies']--;
2712
+		if (!empty($context['new_replies'])) {
2713
+					$context['new_replies']--;
2714
+		}
2578 2715
 	}
2579 2716
 	$smcFunc['db_free_result']($request);
2580 2717
 }
@@ -2591,8 +2728,9 @@  discard block
 block discarded – undo
2591 2728
 	global $sourcedir, $smcFunc;
2592 2729
 
2593 2730
 	loadLanguage('Post');
2594
-	if (!isset($_REQUEST['xml']))
2595
-		loadTemplate('Post');
2731
+	if (!isset($_REQUEST['xml'])) {
2732
+			loadTemplate('Post');
2733
+	}
2596 2734
 
2597 2735
 	include_once($sourcedir . '/Subs-Post.php');
2598 2736
 
@@ -2623,8 +2761,9 @@  discard block
 block discarded – undo
2623 2761
 	$smcFunc['db_free_result']($request);
2624 2762
 
2625 2763
 	$context['sub_template'] = 'quotefast';
2626
-	if (!empty($row))
2627
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2764
+	if (!empty($row)) {
2765
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2766
+	}
2628 2767
 
2629 2768
 	if (!empty($can_view_post))
2630 2769
 	{
@@ -2657,8 +2796,9 @@  discard block
 block discarded – undo
2657 2796
 		}
2658 2797
 
2659 2798
 		// Remove any nested quotes.
2660
-		if (!empty($modSettings['removeNestedQuotes']))
2661
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2799
+		if (!empty($modSettings['removeNestedQuotes'])) {
2800
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2801
+		}
2662 2802
 
2663 2803
 		$lb = "\n";
2664 2804
 
@@ -2684,14 +2824,14 @@  discard block
 block discarded – undo
2684 2824
 				'time' => '',
2685 2825
 			),
2686 2826
 		);
2687
-	}
2688
-	else
2689
-		$context['quote'] = array(
2827
+	} else {
2828
+			$context['quote'] = array(
2690 2829
 			'xml' => '',
2691 2830
 			'mozilla' => '',
2692 2831
 			'text' => '',
2693 2832
 		);
2694
-}
2833
+	}
2834
+	}
2695 2835
 
2696 2836
 /**
2697 2837
  * Used to edit the body or subject of a message inline
@@ -2703,8 +2843,9 @@  discard block
 block discarded – undo
2703 2843
 	global $user_info, $context, $smcFunc, $language, $board_info;
2704 2844
 
2705 2845
 	// We have to have a topic!
2706
-	if (empty($topic))
2707
-		obExit(false);
2846
+	if (empty($topic)) {
2847
+			obExit(false);
2848
+	}
2708 2849
 
2709 2850
 	checkSession('get');
2710 2851
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2730,31 +2871,35 @@  discard block
 block discarded – undo
2730 2871
 			'guest_id' => 0,
2731 2872
 		)
2732 2873
 	);
2733
-	if ($smcFunc['db_num_rows']($request) == 0)
2734
-		fatal_lang_error('no_board', false);
2874
+	if ($smcFunc['db_num_rows']($request) == 0) {
2875
+			fatal_lang_error('no_board', false);
2876
+	}
2735 2877
 	$row = $smcFunc['db_fetch_assoc']($request);
2736 2878
 	$smcFunc['db_free_result']($request);
2737 2879
 
2738 2880
 	// Change either body or subject requires permissions to modify messages.
2739 2881
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2740 2882
 	{
2741
-		if (!empty($row['locked']))
2742
-			isAllowedTo('moderate_board');
2883
+		if (!empty($row['locked'])) {
2884
+					isAllowedTo('moderate_board');
2885
+		}
2743 2886
 
2744 2887
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2745 2888
 		{
2746
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2747
-				fatal_lang_error('modify_post_time_passed', false);
2748
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2749
-				isAllowedTo('modify_replies');
2750
-			else
2751
-				isAllowedTo('modify_own');
2889
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2890
+							fatal_lang_error('modify_post_time_passed', false);
2891
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2892
+							isAllowedTo('modify_replies');
2893
+			} else {
2894
+							isAllowedTo('modify_own');
2895
+			}
2752 2896
 		}
2753 2897
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2754
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2755
-			isAllowedTo('modify_replies');
2756
-		else
2757
-			isAllowedTo('modify_any');
2898
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2899
+					isAllowedTo('modify_replies');
2900
+		} else {
2901
+					isAllowedTo('modify_any');
2902
+		}
2758 2903
 
2759 2904
 		// Only log this action if it wasn't your message.
2760 2905
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2766,10 +2911,10 @@  discard block
 block discarded – undo
2766 2911
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2767 2912
 
2768 2913
 		// Maximum number of characters.
2769
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2770
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2771
-	}
2772
-	elseif (isset($_POST['subject']))
2914
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2915
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2916
+		}
2917
+	} elseif (isset($_POST['subject']))
2773 2918
 	{
2774 2919
 		$post_errors[] = 'no_subject';
2775 2920
 		unset($_POST['subject']);
@@ -2781,13 +2926,11 @@  discard block
 block discarded – undo
2781 2926
 		{
2782 2927
 			$post_errors[] = 'no_message';
2783 2928
 			unset($_POST['message']);
2784
-		}
2785
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2929
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2786 2930
 		{
2787 2931
 			$post_errors[] = 'long_message';
2788 2932
 			unset($_POST['message']);
2789
-		}
2790
-		else
2933
+		} else
2791 2934
 		{
2792 2935
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2793 2936
 
@@ -2803,31 +2946,34 @@  discard block
 block discarded – undo
2803 2946
 
2804 2947
 	if (isset($_POST['lock']))
2805 2948
 	{
2806
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2807
-			unset($_POST['lock']);
2808
-		elseif (!allowedTo('lock_any'))
2949
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
2950
+					unset($_POST['lock']);
2951
+		} elseif (!allowedTo('lock_any'))
2809 2952
 		{
2810
-			if ($row['locked'] == 1)
2811
-				unset($_POST['lock']);
2812
-			else
2813
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
2953
+			if ($row['locked'] == 1) {
2954
+							unset($_POST['lock']);
2955
+			} else {
2956
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
2957
+			}
2958
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
2959
+					unset($_POST['lock']);
2960
+		} else {
2961
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2814 2962
 		}
2815
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2816
-			unset($_POST['lock']);
2817
-		else
2818
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2819 2963
 	}
2820 2964
 
2821
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2822
-		unset($_POST['sticky']);
2965
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
2966
+			unset($_POST['sticky']);
2967
+	}
2823 2968
 
2824 2969
 	if (isset($_POST['modify_reason']))
2825 2970
 	{
2826 2971
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2827 2972
 
2828 2973
 		// Maximum number of characters.
2829
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2830
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2974
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2975
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2976
+		}
2831 2977
 	}
2832 2978
 
2833 2979
 	if (empty($post_errors))
@@ -2864,8 +3010,9 @@  discard block
 block discarded – undo
2864 3010
 			}
2865 3011
 		}
2866 3012
 		// If nothing was changed there's no need to add an entry to the moderation log.
2867
-		else
2868
-			$moderationAction = false;
3013
+		else {
3014
+					$moderationAction = false;
3015
+		}
2869 3016
 
2870 3017
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2871 3018
 
@@ -2883,9 +3030,9 @@  discard block
 block discarded – undo
2883 3030
 			// Get the proper (default language) response prefix first.
2884 3031
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2885 3032
 			{
2886
-				if ($language === $user_info['language'])
2887
-					$context['response_prefix'] = $txt['response_prefix'];
2888
-				else
3033
+				if ($language === $user_info['language']) {
3034
+									$context['response_prefix'] = $txt['response_prefix'];
3035
+				} else
2889 3036
 				{
2890 3037
 					loadLanguage('index', $language, false);
2891 3038
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2907,8 +3054,9 @@  discard block
 block discarded – undo
2907 3054
 			);
2908 3055
 		}
2909 3056
 
2910
-		if (!empty($moderationAction))
2911
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3057
+		if (!empty($moderationAction)) {
3058
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3059
+		}
2912 3060
 	}
2913 3061
 
2914 3062
 	if (isset($_REQUEST['xml']))
@@ -2949,8 +3097,7 @@  discard block
 block discarded – undo
2949 3097
 			);
2950 3098
 
2951 3099
 			censorText($context['message']['subject']);
2952
-		}
2953
-		else
3100
+		} else
2954 3101
 		{
2955 3102
 			$context['message'] = array(
2956 3103
 				'id' => $row['id_msg'],
@@ -2962,15 +3109,16 @@  discard block
 block discarded – undo
2962 3109
 			loadLanguage('Errors');
2963 3110
 			foreach ($post_errors as $post_error)
2964 3111
 			{
2965
-				if ($post_error == 'long_message')
2966
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
2967
-				else
2968
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3112
+				if ($post_error == 'long_message') {
3113
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3114
+				} else {
3115
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3116
+				}
2969 3117
 			}
2970 3118
 		}
3119
+	} else {
3120
+			obExit(false);
3121
+	}
2971 3122
 	}
2972
-	else
2973
-		obExit(false);
2974
-}
2975 3123
 
2976 3124
 ?>
2977 3125
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/CacheAPI-apc.php 1 patch
Braces   +12 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * Our Cache API class
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 	{
28 29
 		$supported = function_exists('apc_fetch') && function_exists('apc_store');
29 30
 
30
-		if ($test)
31
-			return $supported;
31
+		if ($test) {
32
+					return $supported;
33
+		}
32 34
 		return parent::isSupported() && $supported;
33 35
 	}
34 36
 
@@ -50,10 +52,11 @@  discard block
 block discarded – undo
50 52
 		$key = $this->prefix . strtr($key, ':/', '-_');
51 53
 
52 54
 		// An extended key is needed to counteract a bug in APC.
53
-		if ($value === null)
54
-			return apc_delete($key . 'smf');
55
-		else
56
-			return apc_store($key . 'smf', $value, $ttl);
55
+		if ($value === null) {
56
+					return apc_delete($key . 'smf');
57
+		} else {
58
+					return apc_store($key . 'smf', $value, $ttl);
59
+		}
57 60
 	}
58 61
 
59 62
 	/**
@@ -67,9 +70,9 @@  discard block
 block discarded – undo
67 70
 			// Always returns true.
68 71
 			apc_clear_cache('user');
69 72
 			apc_clear_cache('system');
73
+		} elseif ($type === 'user') {
74
+					apc_clear_cache('user');
70 75
 		}
71
-		elseif ($type === 'user')
72
-			apc_clear_cache('user');
73 76
 
74 77
 		$this->invalidateCache();
75 78
 		return true;
Please login to merge, or discard this patch.
Sources/CacheAPI-xcache.php 1 patch
Braces   +19 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * Our Cache API class
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	{
45 46
 		$supported = function_exists('xcache_get') && function_exists('xcache_set') && ini_get('xcache.var_size') > 0;
46 47
 
47
-		if ($test)
48
-			return $supported;
48
+		if ($test) {
49
+					return $supported;
50
+		}
49 51
 		return parent::isSupported() && $supported;
50 52
 	}
51 53
 
@@ -66,10 +68,11 @@  discard block
 block discarded – undo
66 68
 	{
67 69
 		$key = $this->prefix . strtr($key, ':/', '-_');
68 70
 
69
-		if ($value === null)
70
-			return xcache_unset($key);
71
-		else
72
-			return xcache_set($key, $value, $ttl);
71
+		if ($value === null) {
72
+					return xcache_unset($key);
73
+		} else {
74
+					return xcache_set($key, $value, $ttl);
75
+		}
73 76
 	}
74 77
 
75 78
 	/**
@@ -88,10 +91,12 @@  discard block
 block discarded – undo
88 91
 		}
89 92
 
90 93
 		// if passed a type, clear that type out
91
-		if ($type === '' || $type === 'user')
92
-			xcache_clear_cache(XC_TYPE_VAR, 0);
93
-		if ($type === '' || $type === 'data')
94
-			xcache_clear_cache(XC_TYPE_PHP, 0);
94
+		if ($type === '' || $type === 'user') {
95
+					xcache_clear_cache(XC_TYPE_VAR, 0);
96
+		}
97
+		if ($type === '' || $type === 'data') {
98
+					xcache_clear_cache(XC_TYPE_PHP, 0);
99
+		}
95 100
 
96 101
 		$this->invalidateCache();
97 102
 		return true;
@@ -110,8 +115,9 @@  discard block
 block discarded – undo
110 115
 		// While we could md5 this when saving, this could be tricky to be sure it doesn't get corrupted on additional saves.
111 116
 		$config_vars[] = array('xcache_adminpass', $txt['cache_xcache_adminpass'], 'db', 'text', 0);
112 117
 
113
-		if (!isset($context['settings_post_javascript']))
114
-			$context['settings_post_javascript'] = '';
118
+		if (!isset($context['settings_post_javascript'])) {
119
+					$context['settings_post_javascript'] = '';
120
+		}
115 121
 
116 122
 		$context['settings_post_javascript'] .= '
117 123
 			$("#cache_accelerator").change(function (e) {
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +215 added lines, -157 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
 				'max_year' => $year_high,
61 62
 			)
62 63
 		);
63
-	}
64
-	else
64
+	} else
65 65
 	{
66 66
 		$result = $smcFunc['db_query']('birthday_array', '
67 67
 			SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate
@@ -91,10 +91,11 @@  discard block
 block discarded – undo
91 91
 	$bday = array();
92 92
 	while ($row = $smcFunc['db_fetch_assoc']($result))
93 93
 	{
94
-		if ($year_low != $year_high)
95
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
-		else
97
-			$age_year = $year_low;
94
+		if ($year_low != $year_high) {
95
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
+		} else {
97
+					$age_year = $year_low;
98
+		}
98 99
 
99 100
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
100 101
 			'id' => $row['id_member'],
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 	ksort($bday);
109 110
 
110 111
 	// Set is_last, so the themes know when to stop placing separators.
111
-	foreach ($bday as $mday => $array)
112
-		$bday[$mday][count($array) - 1]['is_last'] = true;
112
+	foreach ($bday as $mday => $array) {
113
+			$bday[$mday][count($array) - 1]['is_last'] = true;
114
+	}
113 115
 
114 116
 	return $bday;
115 117
 }
@@ -157,8 +159,9 @@  discard block
 block discarded – undo
157 159
 	while ($row = $smcFunc['db_fetch_assoc']($result))
158 160
 	{
159 161
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
160
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
161
-			continue;
162
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
163
+					continue;
164
+		}
162 165
 
163 166
 		// Force a censor of the title - as often these are used by others.
164 167
 		censorText($row['title'], $use_permissions ? false : true);
@@ -167,8 +170,9 @@  discard block
 block discarded – undo
167 170
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
168 171
 
169 172
 		// Sanity check
170
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
171
-			continue;
173
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
174
+					continue;
175
+		}
172 176
 
173 177
 		// Get set up for the loop
174 178
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -232,8 +236,8 @@  discard block
 block discarded – undo
232 236
 			);
233 237
 
234 238
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
235
-			if ($use_permissions)
236
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
239
+			if ($use_permissions) {
240
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
237 241
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
238 242
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
239 243
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -241,9 +245,10 @@  discard block
 block discarded – undo
241 245
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
242 246
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
243 247
 				));
248
+			}
244 249
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
245
-			else
246
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
250
+			else {
251
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
247 252
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
248 253
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
249 254
 					'can_edit' => false,
@@ -253,6 +258,7 @@  discard block
 block discarded – undo
253 258
 					'poster' => $row['id_member'],
254 259
 					'allowed_groups' => explode(',', $row['member_groups']),
255 260
 				));
261
+			}
256 262
 
257 263
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
258 264
 		}
@@ -262,8 +268,9 @@  discard block
 block discarded – undo
262 268
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
263 269
 	if ($use_permissions)
264 270
 	{
265
-		foreach ($events as $mday => $array)
266
-			$events[$mday][count($array) - 1]['is_last'] = true;
271
+		foreach ($events as $mday => $array) {
272
+					$events[$mday][count($array) - 1]['is_last'] = true;
273
+		}
267 274
 	}
268 275
 
269 276
 	ksort($events);
@@ -283,11 +290,12 @@  discard block
 block discarded – undo
283 290
 	global $smcFunc;
284 291
 
285 292
 	// Get the lowest and highest dates for "all years".
286
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
287
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
293
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
294
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
288 295
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
289
-	else
290
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
296
+	} else {
297
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
298
+	}
291 299
 
292 300
 	// Find some holidays... ;).
293 301
 	$result = $smcFunc['db_query']('', '
@@ -307,10 +315,11 @@  discard block
 block discarded – undo
307 315
 	$holidays = array();
308 316
 	while ($row = $smcFunc['db_fetch_assoc']($result))
309 317
 	{
310
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
311
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
312
-		else
313
-			$event_year = substr($low_date, 0, 4);
318
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
319
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
320
+		} else {
321
+					$event_year = substr($low_date, 0, 4);
322
+		}
314 323
 
315 324
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
316 325
 	}
@@ -336,10 +345,12 @@  discard block
 block discarded – undo
336 345
 	isAllowedTo('calendar_post');
337 346
 
338 347
 	// No board?  No topic?!?
339
-	if (empty($board))
340
-		fatal_lang_error('missing_board_id', false);
341
-	if (empty($topic))
342
-		fatal_lang_error('missing_topic_id', false);
348
+	if (empty($board)) {
349
+			fatal_lang_error('missing_board_id', false);
350
+	}
351
+	if (empty($topic)) {
352
+			fatal_lang_error('missing_topic_id', false);
353
+	}
343 354
 
344 355
 	// Administrator, Moderator, or owner.  Period.
345 356
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -357,12 +368,14 @@  discard block
 block discarded – undo
357 368
 		if ($row = $smcFunc['db_fetch_assoc']($result))
358 369
 		{
359 370
 			// Not the owner of the topic.
360
-			if ($row['id_member_started'] != $user_info['id'])
361
-				fatal_lang_error('not_your_topic', 'user');
371
+			if ($row['id_member_started'] != $user_info['id']) {
372
+							fatal_lang_error('not_your_topic', 'user');
373
+			}
362 374
 		}
363 375
 		// Topic/Board doesn't exist.....
364
-		else
365
-			fatal_lang_error('calendar_no_topic', 'general');
376
+		else {
377
+					fatal_lang_error('calendar_no_topic', 'general');
378
+		}
366 379
 		$smcFunc['db_free_result']($result);
367 380
 	}
368 381
 }
@@ -450,14 +463,16 @@  discard block
 block discarded – undo
450 463
 	if (!empty($calendarOptions['start_day']))
451 464
 	{
452 465
 		$nShift -= $calendarOptions['start_day'];
453
-		if ($nShift < 0)
454
-			$nShift = 7 + $nShift;
466
+		if ($nShift < 0) {
467
+					$nShift = 7 + $nShift;
468
+		}
455 469
 	}
456 470
 
457 471
 	// Number of rows required to fit the month.
458 472
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
459
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
460
-		$nRows++;
473
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
474
+			$nRows++;
475
+	}
461 476
 
462 477
 	// Fetch the arrays for birthdays, posted events, and holidays.
463 478
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -470,8 +485,9 @@  discard block
 block discarded – undo
470 485
 	{
471 486
 		$calendarGrid['week_days'][] = $count;
472 487
 		$count++;
473
-		if ($count == 7)
474
-			$count = 0;
488
+		if ($count == 7) {
489
+					$count = 0;
490
+		}
475 491
 	}
476 492
 
477 493
 	// Iterate through each week.
@@ -488,8 +504,9 @@  discard block
 block discarded – undo
488 504
 		{
489 505
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
490 506
 
491
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
492
-				$nDay = 0;
507
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
508
+							$nDay = 0;
509
+			}
493 510
 
494 511
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
495 512
 
@@ -507,8 +524,9 @@  discard block
 block discarded – undo
507 524
 	}
508 525
 
509 526
 	// What is the last day of the month?
510
-	if ($is_previous === true)
511
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
527
+	if ($is_previous === true) {
528
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
529
+	}
512 530
 
513 531
 	// We'll use the shift in the template.
514 532
 	$calendarGrid['shift'] = $nShift;
@@ -542,8 +560,9 @@  discard block
 block discarded – undo
542 560
 	{
543 561
 		// Here we offset accordingly to get things to the real start of a week.
544 562
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
545
-		if ($date_diff < 0)
546
-			$date_diff += 7;
563
+		if ($date_diff < 0) {
564
+					$date_diff += 7;
565
+		}
547 566
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
548 567
 		$day = (int) strftime('%d', $new_timestamp);
549 568
 		$month = (int) strftime('%m', $new_timestamp);
@@ -673,18 +692,20 @@  discard block
 block discarded – undo
673 692
 	{
674 693
 		foreach ($date_events as $event_key => $event_val)
675 694
 		{
676
-			if (in_array($event_val['id'], $temp))
677
-				unset($calendarGrid['events'][$date][$event_key]);
678
-			else
679
-				$temp[] = $event_val['id'];
695
+			if (in_array($event_val['id'], $temp)) {
696
+							unset($calendarGrid['events'][$date][$event_key]);
697
+			} else {
698
+							$temp[] = $event_val['id'];
699
+			}
680 700
 		}
681 701
 	}
682 702
 
683 703
 	// Give birthdays and holidays a friendly format, without the year
684
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
685
-		$date_format = '%b %d';
686
-	else
687
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
704
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
705
+			$date_format = '%b %d';
706
+	} else {
707
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
708
+	}
688 709
 
689 710
 	foreach (array('birthdays', 'holidays') as $type)
690 711
 	{
@@ -779,8 +800,9 @@  discard block
 block discarded – undo
779 800
 	// Holidays between now and now + days.
780 801
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
781 802
 	{
782
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
783
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
803
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
804
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
805
+		}
784 806
 	}
785 807
 
786 808
 	// Happy Birthday, guys and gals!
@@ -789,8 +811,9 @@  discard block
 block discarded – undo
789 811
 		$loop_date = strftime('%Y-%m-%d', $i);
790 812
 		if (isset($cached_data['birthdays'][$loop_date]))
791 813
 		{
792
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
793
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
814
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
815
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
816
+			}
794 817
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
795 818
 		}
796 819
 	}
@@ -802,8 +825,9 @@  discard block
 block discarded – undo
802 825
 		$loop_date = strftime('%Y-%m-%d', $i);
803 826
 
804 827
 		// No events today? Check the next day.
805
-		if (empty($cached_data['events'][$loop_date]))
806
-			continue;
828
+		if (empty($cached_data['events'][$loop_date])) {
829
+					continue;
830
+		}
807 831
 
808 832
 		// Loop through all events to add a few last-minute values.
809 833
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -816,9 +840,9 @@  discard block
 block discarded – undo
816 840
 			{
817 841
 				unset($cached_data['events'][$loop_date][$ev]);
818 842
 				continue;
843
+			} else {
844
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
819 845
 			}
820
-			else
821
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
822 846
 
823 847
 			// Might be set to true afterwards, depending on the permissions.
824 848
 			$this_event['can_edit'] = false;
@@ -826,15 +850,18 @@  discard block
 block discarded – undo
826 850
 			$this_event['date'] = $loop_date;
827 851
 		}
828 852
 
829
-		if (!empty($cached_data['events'][$loop_date]))
830
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
853
+		if (!empty($cached_data['events'][$loop_date])) {
854
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
855
+		}
831 856
 	}
832 857
 
833 858
 	// Mark the last item so that a list separator can be used in the template.
834
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
835
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
836
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
837
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
859
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
860
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
861
+	}
862
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
863
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
864
+	}
838 865
 
839 866
 	return array(
840 867
 		'data' => $return_data,
@@ -882,37 +909,46 @@  discard block
 block discarded – undo
882 909
 		if (isset($_POST['start_date']))
883 910
 		{
884 911
 			$d = date_parse($_POST['start_date']);
885
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
886
-				fatal_lang_error('invalid_date', false);
887
-			if (empty($d['year']))
888
-				fatal_lang_error('event_year_missing', false);
889
-			if (empty($d['month']))
890
-				fatal_lang_error('event_month_missing', false);
891
-		}
892
-		elseif (isset($_POST['start_datetime']))
912
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
913
+							fatal_lang_error('invalid_date', false);
914
+			}
915
+			if (empty($d['year'])) {
916
+							fatal_lang_error('event_year_missing', false);
917
+			}
918
+			if (empty($d['month'])) {
919
+							fatal_lang_error('event_month_missing', false);
920
+			}
921
+		} elseif (isset($_POST['start_datetime']))
893 922
 		{
894 923
 			$d = date_parse($_POST['start_datetime']);
895
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
896
-				fatal_lang_error('invalid_date', false);
897
-			if (empty($d['year']))
898
-				fatal_lang_error('event_year_missing', false);
899
-			if (empty($d['month']))
900
-				fatal_lang_error('event_month_missing', false);
924
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
925
+							fatal_lang_error('invalid_date', false);
926
+			}
927
+			if (empty($d['year'])) {
928
+							fatal_lang_error('event_year_missing', false);
929
+			}
930
+			if (empty($d['month'])) {
931
+							fatal_lang_error('event_month_missing', false);
932
+			}
901 933
 		}
902 934
 		// The 2.0 way
903 935
 		else
904 936
 		{
905 937
 			// No month?  No year?
906
-			if (!isset($_POST['month']))
907
-				fatal_lang_error('event_month_missing', false);
908
-			if (!isset($_POST['year']))
909
-				fatal_lang_error('event_year_missing', false);
938
+			if (!isset($_POST['month'])) {
939
+							fatal_lang_error('event_month_missing', false);
940
+			}
941
+			if (!isset($_POST['year'])) {
942
+							fatal_lang_error('event_year_missing', false);
943
+			}
910 944
 
911 945
 			// Check the month and year...
912
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
913
-				fatal_lang_error('invalid_month', false);
914
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
915
-				fatal_lang_error('invalid_year', false);
946
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
947
+							fatal_lang_error('invalid_month', false);
948
+			}
949
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
950
+							fatal_lang_error('invalid_year', false);
951
+			}
916 952
 		}
917 953
 	}
918 954
 
@@ -922,8 +958,9 @@  discard block
 block discarded – undo
922 958
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
923 959
 	if (isset($_POST['span']))
924 960
 	{
925
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
926
-			fatal_lang_error('invalid_days_numb', false);
961
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
962
+					fatal_lang_error('invalid_days_numb', false);
963
+		}
927 964
 	}
928 965
 
929 966
 	// There is no need to validate the following values if we are just deleting the event.
@@ -933,24 +970,29 @@  discard block
 block discarded – undo
933 970
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
934 971
 		{
935 972
 			// No day?
936
-			if (!isset($_POST['day']))
937
-				fatal_lang_error('event_day_missing', false);
973
+			if (!isset($_POST['day'])) {
974
+							fatal_lang_error('event_day_missing', false);
975
+			}
938 976
 
939 977
 			// Bad day?
940
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
941
-				fatal_lang_error('invalid_date', false);
978
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
979
+							fatal_lang_error('invalid_date', false);
980
+			}
942 981
 		}
943 982
 
944
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
945
-			fatal_lang_error('event_title_missing', false);
946
-		elseif (!isset($_POST['evtitle']))
947
-			$_POST['evtitle'] = $_POST['subject'];
983
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
984
+					fatal_lang_error('event_title_missing', false);
985
+		} elseif (!isset($_POST['evtitle'])) {
986
+					$_POST['evtitle'] = $_POST['subject'];
987
+		}
948 988
 
949 989
 		// No title?
950
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
951
-			fatal_lang_error('no_event_title', false);
952
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
953
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
990
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
991
+					fatal_lang_error('no_event_title', false);
992
+		}
993
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
994
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
995
+		}
954 996
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
955 997
 	}
956 998
 }
@@ -977,8 +1019,9 @@  discard block
 block discarded – undo
977 1019
 	);
978 1020
 
979 1021
 	// No results, return false.
980
-	if ($smcFunc['db_num_rows'] === 0)
981
-		return false;
1022
+	if ($smcFunc['db_num_rows'] === 0) {
1023
+			return false;
1024
+	}
982 1025
 
983 1026
 	// Grab the results and return.
984 1027
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1112,8 +1155,9 @@  discard block
 block discarded – undo
1112 1155
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1113 1156
 
1114 1157
 	$column_clauses = array();
1115
-	foreach ($event_columns as $col => $crit)
1116
-		$column_clauses[] = $col . ' = ' . $crit;
1158
+	foreach ($event_columns as $col => $crit) {
1159
+			$column_clauses[] = $col . ' = ' . $crit;
1160
+	}
1117 1161
 
1118 1162
 	$smcFunc['db_query']('', '
1119 1163
 		UPDATE {db_prefix}calendar
@@ -1198,8 +1242,9 @@  discard block
 block discarded – undo
1198 1242
 	);
1199 1243
 
1200 1244
 	// If nothing returned, we are in poo, poo.
1201
-	if ($smcFunc['db_num_rows']($request) === 0)
1202
-		return false;
1245
+	if ($smcFunc['db_num_rows']($request) === 0) {
1246
+			return false;
1247
+	}
1203 1248
 
1204 1249
 	$row = $smcFunc['db_fetch_assoc']($request);
1205 1250
 	$smcFunc['db_free_result']($request);
@@ -1207,8 +1252,9 @@  discard block
 block discarded – undo
1207 1252
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1208 1253
 
1209 1254
 	// Sanity check
1210
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1211
-		return false;
1255
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1256
+			return false;
1257
+	}
1212 1258
 
1213 1259
 	$return_value = array(
1214 1260
 		'boards' => array(),
@@ -1345,24 +1391,27 @@  discard block
 block discarded – undo
1345 1391
 
1346 1392
 	// Set $span, in case we need it
1347 1393
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1348
-	if ($span > 0)
1349
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1394
+	if ($span > 0) {
1395
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1396
+	}
1350 1397
 
1351 1398
 	// Define the timezone for this event, falling back to the default if not provided
1352
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1353
-		$tz = $eventOptions['tz'];
1354
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1355
-		$tz = $_POST['tz'];
1356
-	else
1357
-		$tz = getUserTimezone();
1399
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1400
+			$tz = $eventOptions['tz'];
1401
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1402
+			$tz = $_POST['tz'];
1403
+	} else {
1404
+			$tz = getUserTimezone();
1405
+	}
1358 1406
 
1359 1407
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1360
-	if (isset($eventOptions['allday']))
1361
-		$allday = $eventOptions['allday'];
1362
-	elseif (empty($_POST['allday']))
1363
-		$allday = false;
1364
-	else
1365
-		$allday = true;
1408
+	if (isset($eventOptions['allday'])) {
1409
+			$allday = $eventOptions['allday'];
1410
+	} elseif (empty($_POST['allday'])) {
1411
+			$allday = false;
1412
+	} else {
1413
+			$allday = true;
1414
+	}
1366 1415
 
1367 1416
 	// Input might come as individual parameters...
1368 1417
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1389,10 +1438,12 @@  discard block
 block discarded – undo
1389 1438
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1390 1439
 
1391 1440
 	// If the date and time were given in separate strings, combine them
1392
-	if (empty($start_string) && isset($start_date_string))
1393
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1394
-	if (empty($end_string) && isset($end_date_string))
1395
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1441
+	if (empty($start_string) && isset($start_date_string)) {
1442
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1443
+	}
1444
+	if (empty($end_string) && isset($end_date_string)) {
1445
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1446
+	}
1396 1447
 
1397 1448
 	// If some form of string input was given, override individually defined options with it
1398 1449
 	if (isset($start_string))
@@ -1483,10 +1534,11 @@  discard block
 block discarded – undo
1483 1534
 	if ($start_object >= $end_object)
1484 1535
 	{
1485 1536
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1486
-		if ($span > 0)
1487
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1488
-		else
1489
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1537
+		if ($span > 0) {
1538
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1539
+		} else {
1540
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1541
+		}
1490 1542
 	}
1491 1543
 
1492 1544
 	// Is $end_object too late?
@@ -1499,9 +1551,9 @@  discard block
 block discarded – undo
1499 1551
 			{
1500 1552
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1501 1553
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1554
+			} else {
1555
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1502 1556
 			}
1503
-			else
1504
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1505 1557
 		}
1506 1558
 	}
1507 1559
 
@@ -1514,8 +1566,7 @@  discard block
 block discarded – undo
1514 1566
 		$start_time = null;
1515 1567
 		$end_time = null;
1516 1568
 		$tz = null;
1517
-	}
1518
-	else
1569
+	} else
1519 1570
 	{
1520 1571
 		$start_time = date_format($start_object, 'H:i:s');
1521 1572
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1536,16 +1587,18 @@  discard block
 block discarded – undo
1536 1587
 	require_once($sourcedir . '/Subs.php');
1537 1588
 
1538 1589
 	// First, try to create a better date format, ignoring the "time" elements.
1539
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1540
-		$date_format = '%F';
1541
-	else
1542
-		$date_format = $matches[0];
1590
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1591
+			$date_format = '%F';
1592
+	} else {
1593
+			$date_format = $matches[0];
1594
+	}
1543 1595
 
1544 1596
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1545
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1546
-		$time_format = '%k:%M';
1547
-	else
1548
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1597
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1598
+			$time_format = '%k:%M';
1599
+	} else {
1600
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1601
+	}
1549 1602
 
1550 1603
 	// Should this be an all day event?
1551 1604
 	$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
@@ -1554,8 +1607,9 @@  discard block
 block discarded – undo
1554 1607
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1555 1608
 
1556 1609
 	// We need to have a defined timezone in the steps below
1557
-	if (empty($row['timezone']))
1558
-		$row['timezone'] = getUserTimezone();
1610
+	if (empty($row['timezone'])) {
1611
+			$row['timezone'] = getUserTimezone();
1612
+	}
1559 1613
 
1560 1614
 	// Get most of the standard date information for the start and end datetimes
1561 1615
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1607,8 +1661,9 @@  discard block
 block discarded – undo
1607 1661
 	global $smcFunc, $context, $user_info, $modSettings;
1608 1662
 	static $member_cache = array();
1609 1663
 
1610
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1611
-		$id_member = $context['user']['id'];
1664
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1665
+			$id_member = $context['user']['id'];
1666
+	}
1612 1667
 
1613 1668
 	//check if the cache got the data
1614 1669
 	if (isset($id_member) && isset($member_cache[$id_member]))
@@ -1630,11 +1685,13 @@  discard block
 block discarded – undo
1630 1685
 		$smcFunc['db_free_result']($request);
1631 1686
 	}
1632 1687
 
1633
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1634
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1688
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1689
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1690
+	}
1635 1691
 
1636
-	if (isset($id_member))
1637
-		$member_cache[$id_member] = $timezone;
1692
+	if (isset($id_member)) {
1693
+			$member_cache[$id_member] = $timezone;
1694
+	}
1638 1695
 
1639 1696
 	return $timezone;
1640 1697
 }
@@ -1663,8 +1720,9 @@  discard block
 block discarded – undo
1663 1720
 		)
1664 1721
 	);
1665 1722
 	$holidays = array();
1666
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1667
-		$holidays[] = $row;
1723
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1724
+			$holidays[] = $row;
1725
+	}
1668 1726
 	$smcFunc['db_free_result']($request);
1669 1727
 
1670 1728
 	return $holidays;
Please login to merge, or discard this patch.