Completed
Push — release-2.1 ( e6c696...22bfba )
by Mathias
07:04
created
Sources/Subs-Calendar.php 1 patch
Braces   +206 added lines, -149 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -61,10 +62,11 @@  discard block
 block discarded – undo
61 62
 	$bday = array();
62 63
 	while ($row = $smcFunc['db_fetch_assoc']($result))
63 64
 	{
64
-		if ($year_low != $year_high)
65
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
66
-		else
67
-			$age_year = $year_low;
65
+		if ($year_low != $year_high) {
66
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
67
+		} else {
68
+					$age_year = $year_low;
69
+		}
68 70
 
69 71
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
70 72
 			'id' => $row['id_member'],
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$smcFunc['db_free_result']($result);
77 79
 
78 80
 	// Set is_last, so the themes know when to stop placing separators.
79
-	foreach ($bday as $mday => $array)
80
-		$bday[$mday][count($array) - 1]['is_last'] = true;
81
+	foreach ($bday as $mday => $array) {
82
+			$bday[$mday][count($array) - 1]['is_last'] = true;
83
+	}
81 84
 
82 85
 	return $bday;
83 86
 }
@@ -125,8 +128,9 @@  discard block
 block discarded – undo
125 128
 	while ($row = $smcFunc['db_fetch_assoc']($result))
126 129
 	{
127 130
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
128
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
129
-			continue;
131
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
132
+					continue;
133
+		}
130 134
 
131 135
 		// Force a censor of the title - as often these are used by others.
132 136
 		censorText($row['title'], $use_permissions ? false : true);
@@ -137,8 +141,9 @@  discard block
 block discarded – undo
137 141
 		list($start, $end, $allday, $span, $tz_abbrev) = buildEventDatetimes($row);
138 142
 
139 143
 		// Sanity check
140
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
141
-			continue;
144
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
145
+					continue;
146
+		}
142 147
 
143 148
 		// Get set up for the loop
144 149
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -202,8 +207,8 @@  discard block
 block discarded – undo
202 207
 			);
203 208
 
204 209
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
205
-			if ($use_permissions)
206
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
210
+			if ($use_permissions) {
211
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
207 212
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
208 213
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
209 214
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -211,9 +216,10 @@  discard block
 block discarded – undo
211 216
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
212 217
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
213 218
 				));
219
+			}
214 220
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
215
-			else
216
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
221
+			else {
222
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
217 223
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
218 224
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
219 225
 					'can_edit' => false,
@@ -223,6 +229,7 @@  discard block
 block discarded – undo
223 229
 					'poster' => $row['id_member'],
224 230
 					'allowed_groups' => explode(',', $row['member_groups']),
225 231
 				));
232
+			}
226 233
 
227 234
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
228 235
 		}
@@ -232,8 +239,9 @@  discard block
 block discarded – undo
232 239
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
233 240
 	if ($use_permissions)
234 241
 	{
235
-		foreach ($events as $mday => $array)
236
-			$events[$mday][count($array) - 1]['is_last'] = true;
242
+		foreach ($events as $mday => $array) {
243
+					$events[$mday][count($array) - 1]['is_last'] = true;
244
+		}
237 245
 	}
238 246
 
239 247
 	return $events;
@@ -251,11 +259,12 @@  discard block
 block discarded – undo
251 259
 	global $smcFunc;
252 260
 
253 261
 	// Get the lowest and highest dates for "all years".
254
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
255
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
262
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
263
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
256 264
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
257
-	else
258
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
265
+	} else {
266
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
267
+	}
259 268
 
260 269
 	// Find some holidays... ;).
261 270
 	$result = $smcFunc['db_query']('', '
@@ -275,10 +284,11 @@  discard block
 block discarded – undo
275 284
 	$holidays = array();
276 285
 	while ($row = $smcFunc['db_fetch_assoc']($result))
277 286
 	{
278
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
279
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
280
-		else
281
-			$event_year = substr($low_date, 0, 4);
287
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
288
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
289
+		} else {
290
+					$event_year = substr($low_date, 0, 4);
291
+		}
282 292
 
283 293
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
284 294
 	}
@@ -302,10 +312,12 @@  discard block
 block discarded – undo
302 312
 	isAllowedTo('calendar_post');
303 313
 
304 314
 	// No board?  No topic?!?
305
-	if (empty($board))
306
-		fatal_lang_error('missing_board_id', false);
307
-	if (empty($topic))
308
-		fatal_lang_error('missing_topic_id', false);
315
+	if (empty($board)) {
316
+			fatal_lang_error('missing_board_id', false);
317
+	}
318
+	if (empty($topic)) {
319
+			fatal_lang_error('missing_topic_id', false);
320
+	}
309 321
 
310 322
 	// Administrator, Moderator, or owner.  Period.
311 323
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -323,12 +335,14 @@  discard block
 block discarded – undo
323 335
 		if ($row = $smcFunc['db_fetch_assoc']($result))
324 336
 		{
325 337
 			// Not the owner of the topic.
326
-			if ($row['id_member_started'] != $user_info['id'])
327
-				fatal_lang_error('not_your_topic', 'user');
338
+			if ($row['id_member_started'] != $user_info['id']) {
339
+							fatal_lang_error('not_your_topic', 'user');
340
+			}
328 341
 		}
329 342
 		// Topic/Board doesn't exist.....
330
-		else
331
-			fatal_lang_error('calendar_no_topic', 'general');
343
+		else {
344
+					fatal_lang_error('calendar_no_topic', 'general');
345
+		}
332 346
 		$smcFunc['db_free_result']($result);
333 347
 	}
334 348
 }
@@ -416,14 +430,16 @@  discard block
 block discarded – undo
416 430
 	if (!empty($calendarOptions['start_day']))
417 431
 	{
418 432
 		$nShift -= $calendarOptions['start_day'];
419
-		if ($nShift < 0)
420
-			$nShift = 7 + $nShift;
433
+		if ($nShift < 0) {
434
+					$nShift = 7 + $nShift;
435
+		}
421 436
 	}
422 437
 
423 438
 	// Number of rows required to fit the month.
424 439
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
425
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
426
-		$nRows++;
440
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
441
+			$nRows++;
442
+	}
427 443
 
428 444
 	// Fetch the arrays for birthdays, posted events, and holidays.
429 445
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -436,8 +452,9 @@  discard block
 block discarded – undo
436 452
 	{
437 453
 		$calendarGrid['week_days'][] = $count;
438 454
 		$count++;
439
-		if ($count == 7)
440
-			$count = 0;
455
+		if ($count == 7) {
456
+					$count = 0;
457
+		}
441 458
 	}
442 459
 
443 460
 	// Iterate through each week.
@@ -454,8 +471,9 @@  discard block
 block discarded – undo
454 471
 		{
455 472
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
456 473
 
457
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
458
-				$nDay = 0;
474
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
475
+							$nDay = 0;
476
+			}
459 477
 
460 478
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
461 479
 
@@ -473,8 +491,9 @@  discard block
 block discarded – undo
473 491
 	}
474 492
 
475 493
 	// What is the last day of the month?
476
-	if ($is_previous === true)
477
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
494
+	if ($is_previous === true) {
495
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
496
+	}
478 497
 
479 498
 	// We'll use the shift in the template.
480 499
 	$calendarGrid['shift'] = $nShift;
@@ -508,8 +527,9 @@  discard block
 block discarded – undo
508 527
 	{
509 528
 		// Here we offset accordingly to get things to the real start of a week.
510 529
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
511
-		if ($date_diff < 0)
512
-			$date_diff += 7;
530
+		if ($date_diff < 0) {
531
+					$date_diff += 7;
532
+		}
513 533
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
514 534
 		$day = (int) strftime('%d', $new_timestamp);
515 535
 		$month = (int) strftime('%m', $new_timestamp);
@@ -660,8 +680,9 @@  discard block
 block discarded – undo
660 680
 	// Holidays between now and now + days.
661 681
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
662 682
 	{
663
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
664
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
683
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
684
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
685
+		}
665 686
 	}
666 687
 
667 688
 	// Happy Birthday, guys and gals!
@@ -670,8 +691,9 @@  discard block
 block discarded – undo
670 691
 		$loop_date = strftime('%Y-%m-%d', $i);
671 692
 		if (isset($cached_data['birthdays'][$loop_date]))
672 693
 		{
673
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
674
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
694
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
695
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
696
+			}
675 697
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
676 698
 		}
677 699
 	}
@@ -683,8 +705,9 @@  discard block
 block discarded – undo
683 705
 		$loop_date = strftime('%Y-%m-%d', $i);
684 706
 
685 707
 		// No events today? Check the next day.
686
-		if (empty($cached_data['events'][$loop_date]))
687
-			continue;
708
+		if (empty($cached_data['events'][$loop_date])) {
709
+					continue;
710
+		}
688 711
 
689 712
 		// Loop through all events to add a few last-minute values.
690 713
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -697,9 +720,9 @@  discard block
 block discarded – undo
697 720
 			{
698 721
 				unset($cached_data['events'][$loop_date][$ev]);
699 722
 				continue;
723
+			} else {
724
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
700 725
 			}
701
-			else
702
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
703 726
 
704 727
 			// Might be set to true afterwards, depending on the permissions.
705 728
 			$this_event['can_edit'] = false;
@@ -707,15 +730,18 @@  discard block
 block discarded – undo
707 730
 			$this_event['date'] = $loop_date;
708 731
 		}
709 732
 
710
-		if (!empty($cached_data['events'][$loop_date]))
711
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
733
+		if (!empty($cached_data['events'][$loop_date])) {
734
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
735
+		}
712 736
 	}
713 737
 
714 738
 	// Mark the last item so that a list separator can be used in the template.
715
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
716
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
717
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
718
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
739
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
740
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
741
+	}
742
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
743
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
744
+	}
719 745
 
720 746
 	return array(
721 747
 		'data' => $return_data,
@@ -763,37 +789,46 @@  discard block
 block discarded – undo
763 789
 		if (isset($_POST['start_date']))
764 790
 		{
765 791
 			$d = date_parse($_POST['start_date']);
766
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
767
-				fatal_lang_error('invalid_date', false);
768
-			if (empty($d['year']))
769
-				fatal_lang_error('event_year_missing', false);
770
-			if (empty($d['month']))
771
-				fatal_lang_error('event_month_missing', false);
772
-		}
773
-		elseif (isset($_POST['start_datetime']))
792
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
793
+							fatal_lang_error('invalid_date', false);
794
+			}
795
+			if (empty($d['year'])) {
796
+							fatal_lang_error('event_year_missing', false);
797
+			}
798
+			if (empty($d['month'])) {
799
+							fatal_lang_error('event_month_missing', false);
800
+			}
801
+		} elseif (isset($_POST['start_datetime']))
774 802
 		{
775 803
 			$d = date_parse($_POST['start_datetime']);
776
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
777
-				fatal_lang_error('invalid_date', false);
778
-			if (empty($d['year']))
779
-				fatal_lang_error('event_year_missing', false);
780
-			if (empty($d['month']))
781
-				fatal_lang_error('event_month_missing', false);
804
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
805
+							fatal_lang_error('invalid_date', false);
806
+			}
807
+			if (empty($d['year'])) {
808
+							fatal_lang_error('event_year_missing', false);
809
+			}
810
+			if (empty($d['month'])) {
811
+							fatal_lang_error('event_month_missing', false);
812
+			}
782 813
 		}
783 814
 		// The 2.0 way
784 815
 		else
785 816
 		{
786 817
 			// No month?  No year?
787
-			if (!isset($_POST['month']))
788
-				fatal_lang_error('event_month_missing', false);
789
-			if (!isset($_POST['year']))
790
-				fatal_lang_error('event_year_missing', false);
818
+			if (!isset($_POST['month'])) {
819
+							fatal_lang_error('event_month_missing', false);
820
+			}
821
+			if (!isset($_POST['year'])) {
822
+							fatal_lang_error('event_year_missing', false);
823
+			}
791 824
 
792 825
 			// Check the month and year...
793
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
794
-				fatal_lang_error('invalid_month', false);
795
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
796
-				fatal_lang_error('invalid_year', false);
826
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
827
+							fatal_lang_error('invalid_month', false);
828
+			}
829
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
830
+							fatal_lang_error('invalid_year', false);
831
+			}
797 832
 		}
798 833
 	}
799 834
 
@@ -803,8 +838,9 @@  discard block
 block discarded – undo
803 838
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
804 839
 	if (isset($_POST['span']))
805 840
 	{
806
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
807
-			fatal_lang_error('invalid_days_numb', false);
841
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
842
+					fatal_lang_error('invalid_days_numb', false);
843
+		}
808 844
 	}
809 845
 
810 846
 	// There is no need to validate the following values if we are just deleting the event.
@@ -814,24 +850,29 @@  discard block
 block discarded – undo
814 850
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
815 851
 		{
816 852
 			// No day?
817
-			if (!isset($_POST['day']))
818
-				fatal_lang_error('event_day_missing', false);
853
+			if (!isset($_POST['day'])) {
854
+							fatal_lang_error('event_day_missing', false);
855
+			}
819 856
 
820 857
 			// Bad day?
821
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
822
-				fatal_lang_error('invalid_date', false);
858
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
859
+							fatal_lang_error('invalid_date', false);
860
+			}
823 861
 		}
824 862
 
825
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
826
-			fatal_lang_error('event_title_missing', false);
827
-		elseif (!isset($_POST['evtitle']))
828
-			$_POST['evtitle'] = $_POST['subject'];
863
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
864
+					fatal_lang_error('event_title_missing', false);
865
+		} elseif (!isset($_POST['evtitle'])) {
866
+					$_POST['evtitle'] = $_POST['subject'];
867
+		}
829 868
 
830 869
 		// No title?
831
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
832
-			fatal_lang_error('no_event_title', false);
833
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
834
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
870
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
871
+					fatal_lang_error('no_event_title', false);
872
+		}
873
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
874
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
875
+		}
835 876
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
836 877
 	}
837 878
 }
@@ -858,8 +899,9 @@  discard block
 block discarded – undo
858 899
 	);
859 900
 
860 901
 	// No results, return false.
861
-	if ($smcFunc['db_num_rows'] === 0)
862
-		return false;
902
+	if ($smcFunc['db_num_rows'] === 0) {
903
+			return false;
904
+	}
863 905
 
864 906
 	// Grab the results and return.
865 907
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -995,8 +1037,9 @@  discard block
 block discarded – undo
995 1037
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
996 1038
 
997 1039
 	$column_clauses = array();
998
-	foreach ($event_columns as $col => $crit)
999
-		$column_clauses[] = $col . ' = ' . $crit;
1040
+	foreach ($event_columns as $col => $crit) {
1041
+			$column_clauses[] = $col . ' = ' . $crit;
1042
+	}
1000 1043
 
1001 1044
 	$smcFunc['db_query']('', '
1002 1045
 		UPDATE {db_prefix}calendar
@@ -1081,8 +1124,9 @@  discard block
 block discarded – undo
1081 1124
 	);
1082 1125
 
1083 1126
 	// If nothing returned, we are in poo, poo.
1084
-	if ($smcFunc['db_num_rows']($request) === 0)
1085
-		return false;
1127
+	if ($smcFunc['db_num_rows']($request) === 0) {
1128
+			return false;
1129
+	}
1086 1130
 
1087 1131
 	$row = $smcFunc['db_fetch_assoc']($request);
1088 1132
 	$smcFunc['db_free_result']($request);
@@ -1090,8 +1134,9 @@  discard block
 block discarded – undo
1090 1134
 	list($start, $end, $allday, $span, $tz_abbrev) = buildEventDatetimes($row);
1091 1135
 
1092 1136
 	// Sanity check
1093
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1094
-		return false;
1137
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1138
+			return false;
1139
+	}
1095 1140
 
1096 1141
 	$return_value = array(
1097 1142
 		'boards' => array(),
@@ -1161,10 +1206,11 @@  discard block
 block discarded – undo
1161 1206
 	$allday = isset($_REQUEST['allday']) ? 1 : (isset($_REQUEST['start_time']) ? 0 : 1);
1162 1207
 	$span = isset($_REQUEST['span']) && filter_var($_REQUEST['span'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 0))) ? $_REQUEST['span'] : 1;
1163 1208
 
1164
-	if (!empty($_REQUEST['tz']) && in_array($_REQUEST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1165
-		$tz = $_REQUEST['tz'];
1166
-	else
1167
-		$tz = getUserTimezone();
1209
+	if (!empty($_REQUEST['tz']) && in_array($_REQUEST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1210
+			$tz = $_REQUEST['tz'];
1211
+	} else {
1212
+			$tz = getUserTimezone();
1213
+	}
1168 1214
 
1169 1215
 	// Was the input given as individual parameters?
1170 1216
 	$start_year = isset($_REQUEST['year']) ? $_REQUEST['year'] : $today['year'];
@@ -1275,24 +1321,27 @@  discard block
 block discarded – undo
1275 1321
 
1276 1322
 	// Set $span, in case we need it
1277 1323
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1278
-	if ($span > 0)
1279
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1324
+	if ($span > 0) {
1325
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1326
+	}
1280 1327
 
1281 1328
 	// Define the timezone for this event, falling back to the default if not provided
1282
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1283
-		$tz = $eventOptions['tz'];
1284
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1285
-		$tz = $_POST['tz'];
1286
-	else
1287
-		$tz = getUserTimezone();
1329
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1330
+			$tz = $eventOptions['tz'];
1331
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1332
+			$tz = $_POST['tz'];
1333
+	} else {
1334
+			$tz = getUserTimezone();
1335
+	}
1288 1336
 
1289 1337
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1290
-	if (isset($eventOptions['allday']))
1291
-		$allday = $eventOptions['allday'];
1292
-	elseif (empty($_POST['allday']))
1293
-		$allday = false;
1294
-	else
1295
-		$allday = true;
1338
+	if (isset($eventOptions['allday'])) {
1339
+			$allday = $eventOptions['allday'];
1340
+	} elseif (empty($_POST['allday'])) {
1341
+			$allday = false;
1342
+	} else {
1343
+			$allday = true;
1344
+	}
1296 1345
 
1297 1346
 	// Input might come as individual parameters...
1298 1347
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1319,10 +1368,12 @@  discard block
 block discarded – undo
1319 1368
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1320 1369
 
1321 1370
 	// If the date and time were given in separate strings, combine them
1322
-	if (empty($start_string) && isset($start_date_string))
1323
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1324
-	if (empty($end_string) && isset($end_date_string))
1325
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1371
+	if (empty($start_string) && isset($start_date_string)) {
1372
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1373
+	}
1374
+	if (empty($end_string) && isset($end_date_string)) {
1375
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1376
+	}
1326 1377
 
1327 1378
 	// If some form of string input was given, override individually defined options with it
1328 1379
 	if (isset($start_string))
@@ -1413,10 +1464,11 @@  discard block
 block discarded – undo
1413 1464
 	if ($start_object >= $end_object)
1414 1465
 	{
1415 1466
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1416
-		if ($span > 0)
1417
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1418
-		else
1419
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1467
+		if ($span > 0) {
1468
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1469
+		} else {
1470
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1471
+		}
1420 1472
 	}
1421 1473
 
1422 1474
 	// Is $end_object too late?
@@ -1429,9 +1481,9 @@  discard block
 block discarded – undo
1429 1481
 			{
1430 1482
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1431 1483
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1484
+			} else {
1485
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1432 1486
 			}
1433
-			else
1434
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1435 1487
 		}
1436 1488
 	}
1437 1489
 
@@ -1444,8 +1496,7 @@  discard block
 block discarded – undo
1444 1496
 		$start_time = null;
1445 1497
 		$end_time = null;
1446 1498
 		$tz = null;
1447
-	}
1448
-	else
1499
+	} else
1449 1500
 	{
1450 1501
 		$start_time = date_format($start_object, 'H:i:s');
1451 1502
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1466,19 +1517,22 @@  discard block
 block discarded – undo
1466 1517
 	require_once($sourcedir . '/Subs.php');
1467 1518
 
1468 1519
 	// First, try to create a better date format, ignoring the "time" elements.
1469
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1470
-		$date_format = '%F';
1471
-	else
1472
-		$date_format = $matches[0];
1520
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1521
+			$date_format = '%F';
1522
+	} else {
1523
+			$date_format = $matches[0];
1524
+	}
1473 1525
 
1474
-	if (empty($row['timezone']))
1475
-		$row['timezone'] = getUserTimezone();
1526
+	if (empty($row['timezone'])) {
1527
+			$row['timezone'] = getUserTimezone();
1528
+	}
1476 1529
 
1477 1530
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1478
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1479
-		$time_format = '%k:%M';
1480
-	else
1481
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1531
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1532
+			$time_format = '%k:%M';
1533
+	} else {
1534
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1535
+	}
1482 1536
 
1483 1537
 	$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;
1484 1538
 
@@ -1524,8 +1578,9 @@  discard block
 block discarded – undo
1524 1578
 {
1525 1579
 	global $smcFunc, $context, $sourcedir, $user_info, $modSettings;
1526 1580
 
1527
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1528
-		$id_member = $context['user']['id'];
1581
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1582
+			$id_member = $context['user']['id'];
1583
+	}
1529 1584
 
1530 1585
 	if (isset($id_member))
1531 1586
 	{
@@ -1541,8 +1596,9 @@  discard block
 block discarded – undo
1541 1596
 		$smcFunc['db_free_result']($request);
1542 1597
 	}
1543 1598
 
1544
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1545
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1599
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1600
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1601
+	}
1546 1602
 
1547 1603
 	return $timezone;
1548 1604
 }
@@ -1571,8 +1627,9 @@  discard block
 block discarded – undo
1571 1627
 		)
1572 1628
 	);
1573 1629
 	$holidays = array();
1574
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1575
-		$holidays[] = $row;
1630
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1631
+			$holidays[] = $row;
1632
+	}
1576 1633
 	$smcFunc['db_free_result']($request);
1577 1634
 
1578 1635
 	return $holidays;
Please login to merge, or discard this patch.