Completed
Push — release-2.1 ( 22bfba...99ca30 )
by Mathias
10s
created
Sources/Subs-Calendar.php 1 patch
Braces   +207 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);
@@ -135,8 +139,9 @@  discard block
 block discarded – undo
135 139
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
136 140
 
137 141
 		// Sanity check
138
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
139
-			continue;
142
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
143
+					continue;
144
+		}
140 145
 
141 146
 		// Get set up for the loop
142 147
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -200,8 +205,8 @@  discard block
 block discarded – undo
200 205
 			);
201 206
 
202 207
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
203
-			if ($use_permissions)
204
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
208
+			if ($use_permissions) {
209
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
205 210
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
206 211
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
207 212
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -209,9 +214,10 @@  discard block
 block discarded – undo
209 214
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
210 215
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
211 216
 				));
217
+			}
212 218
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
213
-			else
214
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
219
+			else {
220
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
215 221
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
216 222
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
217 223
 					'can_edit' => false,
@@ -221,6 +227,7 @@  discard block
 block discarded – undo
221 227
 					'poster' => $row['id_member'],
222 228
 					'allowed_groups' => explode(',', $row['member_groups']),
223 229
 				));
230
+			}
224 231
 
225 232
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
226 233
 		}
@@ -230,8 +237,9 @@  discard block
 block discarded – undo
230 237
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
231 238
 	if ($use_permissions)
232 239
 	{
233
-		foreach ($events as $mday => $array)
234
-			$events[$mday][count($array) - 1]['is_last'] = true;
240
+		foreach ($events as $mday => $array) {
241
+					$events[$mday][count($array) - 1]['is_last'] = true;
242
+		}
235 243
 	}
236 244
 
237 245
 	return $events;
@@ -249,11 +257,12 @@  discard block
 block discarded – undo
249 257
 	global $smcFunc;
250 258
 
251 259
 	// Get the lowest and highest dates for "all years".
252
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
253
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
260
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
261
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
254 262
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
255
-	else
256
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
263
+	} else {
264
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
265
+	}
257 266
 
258 267
 	// Find some holidays... ;).
259 268
 	$result = $smcFunc['db_query']('', '
@@ -273,10 +282,11 @@  discard block
 block discarded – undo
273 282
 	$holidays = array();
274 283
 	while ($row = $smcFunc['db_fetch_assoc']($result))
275 284
 	{
276
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
277
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
278
-		else
279
-			$event_year = substr($low_date, 0, 4);
285
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
286
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
287
+		} else {
288
+					$event_year = substr($low_date, 0, 4);
289
+		}
280 290
 
281 291
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
282 292
 	}
@@ -300,10 +310,12 @@  discard block
 block discarded – undo
300 310
 	isAllowedTo('calendar_post');
301 311
 
302 312
 	// No board?  No topic?!?
303
-	if (empty($board))
304
-		fatal_lang_error('missing_board_id', false);
305
-	if (empty($topic))
306
-		fatal_lang_error('missing_topic_id', false);
313
+	if (empty($board)) {
314
+			fatal_lang_error('missing_board_id', false);
315
+	}
316
+	if (empty($topic)) {
317
+			fatal_lang_error('missing_topic_id', false);
318
+	}
307 319
 
308 320
 	// Administrator, Moderator, or owner.  Period.
309 321
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -321,12 +333,14 @@  discard block
 block discarded – undo
321 333
 		if ($row = $smcFunc['db_fetch_assoc']($result))
322 334
 		{
323 335
 			// Not the owner of the topic.
324
-			if ($row['id_member_started'] != $user_info['id'])
325
-				fatal_lang_error('not_your_topic', 'user');
336
+			if ($row['id_member_started'] != $user_info['id']) {
337
+							fatal_lang_error('not_your_topic', 'user');
338
+			}
326 339
 		}
327 340
 		// Topic/Board doesn't exist.....
328
-		else
329
-			fatal_lang_error('calendar_no_topic', 'general');
341
+		else {
342
+					fatal_lang_error('calendar_no_topic', 'general');
343
+		}
330 344
 		$smcFunc['db_free_result']($result);
331 345
 	}
332 346
 }
@@ -414,14 +428,16 @@  discard block
 block discarded – undo
414 428
 	if (!empty($calendarOptions['start_day']))
415 429
 	{
416 430
 		$nShift -= $calendarOptions['start_day'];
417
-		if ($nShift < 0)
418
-			$nShift = 7 + $nShift;
431
+		if ($nShift < 0) {
432
+					$nShift = 7 + $nShift;
433
+		}
419 434
 	}
420 435
 
421 436
 	// Number of rows required to fit the month.
422 437
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
423
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
424
-		$nRows++;
438
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
439
+			$nRows++;
440
+	}
425 441
 
426 442
 	// Fetch the arrays for birthdays, posted events, and holidays.
427 443
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -434,8 +450,9 @@  discard block
 block discarded – undo
434 450
 	{
435 451
 		$calendarGrid['week_days'][] = $count;
436 452
 		$count++;
437
-		if ($count == 7)
438
-			$count = 0;
453
+		if ($count == 7) {
454
+					$count = 0;
455
+		}
439 456
 	}
440 457
 
441 458
 	// Iterate through each week.
@@ -452,8 +469,9 @@  discard block
 block discarded – undo
452 469
 		{
453 470
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
454 471
 
455
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
456
-				$nDay = 0;
472
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
473
+							$nDay = 0;
474
+			}
457 475
 
458 476
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
459 477
 
@@ -471,8 +489,9 @@  discard block
 block discarded – undo
471 489
 	}
472 490
 
473 491
 	// What is the last day of the month?
474
-	if ($is_previous === true)
475
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
492
+	if ($is_previous === true) {
493
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
494
+	}
476 495
 
477 496
 	// We'll use the shift in the template.
478 497
 	$calendarGrid['shift'] = $nShift;
@@ -506,8 +525,9 @@  discard block
 block discarded – undo
506 525
 	{
507 526
 		// Here we offset accordingly to get things to the real start of a week.
508 527
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
509
-		if ($date_diff < 0)
510
-			$date_diff += 7;
528
+		if ($date_diff < 0) {
529
+					$date_diff += 7;
530
+		}
511 531
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
512 532
 		$day = (int) strftime('%d', $new_timestamp);
513 533
 		$month = (int) strftime('%m', $new_timestamp);
@@ -658,8 +678,9 @@  discard block
 block discarded – undo
658 678
 	// Holidays between now and now + days.
659 679
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
660 680
 	{
661
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
662
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
681
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
682
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
683
+		}
663 684
 	}
664 685
 
665 686
 	// Happy Birthday, guys and gals!
@@ -668,8 +689,9 @@  discard block
 block discarded – undo
668 689
 		$loop_date = strftime('%Y-%m-%d', $i);
669 690
 		if (isset($cached_data['birthdays'][$loop_date]))
670 691
 		{
671
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
672
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
692
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
693
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
694
+			}
673 695
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
674 696
 		}
675 697
 	}
@@ -681,8 +703,9 @@  discard block
 block discarded – undo
681 703
 		$loop_date = strftime('%Y-%m-%d', $i);
682 704
 
683 705
 		// No events today? Check the next day.
684
-		if (empty($cached_data['events'][$loop_date]))
685
-			continue;
706
+		if (empty($cached_data['events'][$loop_date])) {
707
+					continue;
708
+		}
686 709
 
687 710
 		// Loop through all events to add a few last-minute values.
688 711
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -695,9 +718,9 @@  discard block
 block discarded – undo
695 718
 			{
696 719
 				unset($cached_data['events'][$loop_date][$ev]);
697 720
 				continue;
721
+			} else {
722
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
698 723
 			}
699
-			else
700
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
701 724
 
702 725
 			// Might be set to true afterwards, depending on the permissions.
703 726
 			$this_event['can_edit'] = false;
@@ -705,15 +728,18 @@  discard block
 block discarded – undo
705 728
 			$this_event['date'] = $loop_date;
706 729
 		}
707 730
 
708
-		if (!empty($cached_data['events'][$loop_date]))
709
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
731
+		if (!empty($cached_data['events'][$loop_date])) {
732
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
733
+		}
710 734
 	}
711 735
 
712 736
 	// Mark the last item so that a list separator can be used in the template.
713
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
714
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
715
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
716
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
737
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
738
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
739
+	}
740
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
741
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
742
+	}
717 743
 
718 744
 	return array(
719 745
 		'data' => $return_data,
@@ -761,37 +787,46 @@  discard block
 block discarded – undo
761 787
 		if (isset($_POST['start_date']))
762 788
 		{
763 789
 			$d = date_parse($_POST['start_date']);
764
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
765
-				fatal_lang_error('invalid_date', false);
766
-			if (empty($d['year']))
767
-				fatal_lang_error('event_year_missing', false);
768
-			if (empty($d['month']))
769
-				fatal_lang_error('event_month_missing', false);
770
-		}
771
-		elseif (isset($_POST['start_datetime']))
790
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
791
+							fatal_lang_error('invalid_date', false);
792
+			}
793
+			if (empty($d['year'])) {
794
+							fatal_lang_error('event_year_missing', false);
795
+			}
796
+			if (empty($d['month'])) {
797
+							fatal_lang_error('event_month_missing', false);
798
+			}
799
+		} elseif (isset($_POST['start_datetime']))
772 800
 		{
773 801
 			$d = date_parse($_POST['start_datetime']);
774
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
775
-				fatal_lang_error('invalid_date', false);
776
-			if (empty($d['year']))
777
-				fatal_lang_error('event_year_missing', false);
778
-			if (empty($d['month']))
779
-				fatal_lang_error('event_month_missing', false);
802
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
803
+							fatal_lang_error('invalid_date', false);
804
+			}
805
+			if (empty($d['year'])) {
806
+							fatal_lang_error('event_year_missing', false);
807
+			}
808
+			if (empty($d['month'])) {
809
+							fatal_lang_error('event_month_missing', false);
810
+			}
780 811
 		}
781 812
 		// The 2.0 way
782 813
 		else
783 814
 		{
784 815
 			// No month?  No year?
785
-			if (!isset($_POST['month']))
786
-				fatal_lang_error('event_month_missing', false);
787
-			if (!isset($_POST['year']))
788
-				fatal_lang_error('event_year_missing', false);
816
+			if (!isset($_POST['month'])) {
817
+							fatal_lang_error('event_month_missing', false);
818
+			}
819
+			if (!isset($_POST['year'])) {
820
+							fatal_lang_error('event_year_missing', false);
821
+			}
789 822
 
790 823
 			// Check the month and year...
791
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
792
-				fatal_lang_error('invalid_month', false);
793
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
794
-				fatal_lang_error('invalid_year', false);
824
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
825
+							fatal_lang_error('invalid_month', false);
826
+			}
827
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
828
+							fatal_lang_error('invalid_year', false);
829
+			}
795 830
 		}
796 831
 	}
797 832
 
@@ -801,8 +836,9 @@  discard block
 block discarded – undo
801 836
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
802 837
 	if (isset($_POST['span']))
803 838
 	{
804
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
805
-			fatal_lang_error('invalid_days_numb', false);
839
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
840
+					fatal_lang_error('invalid_days_numb', false);
841
+		}
806 842
 	}
807 843
 
808 844
 	// There is no need to validate the following values if we are just deleting the event.
@@ -812,24 +848,29 @@  discard block
 block discarded – undo
812 848
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
813 849
 		{
814 850
 			// No day?
815
-			if (!isset($_POST['day']))
816
-				fatal_lang_error('event_day_missing', false);
851
+			if (!isset($_POST['day'])) {
852
+							fatal_lang_error('event_day_missing', false);
853
+			}
817 854
 
818 855
 			// Bad day?
819
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
820
-				fatal_lang_error('invalid_date', false);
856
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
857
+							fatal_lang_error('invalid_date', false);
858
+			}
821 859
 		}
822 860
 
823
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
824
-			fatal_lang_error('event_title_missing', false);
825
-		elseif (!isset($_POST['evtitle']))
826
-			$_POST['evtitle'] = $_POST['subject'];
861
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
862
+					fatal_lang_error('event_title_missing', false);
863
+		} elseif (!isset($_POST['evtitle'])) {
864
+					$_POST['evtitle'] = $_POST['subject'];
865
+		}
827 866
 
828 867
 		// No title?
829
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
830
-			fatal_lang_error('no_event_title', false);
831
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
832
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
868
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
869
+					fatal_lang_error('no_event_title', false);
870
+		}
871
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
872
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
873
+		}
833 874
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
834 875
 	}
835 876
 }
@@ -856,8 +897,9 @@  discard block
 block discarded – undo
856 897
 	);
857 898
 
858 899
 	// No results, return false.
859
-	if ($smcFunc['db_num_rows'] === 0)
860
-		return false;
900
+	if ($smcFunc['db_num_rows'] === 0) {
901
+			return false;
902
+	}
861 903
 
862 904
 	// Grab the results and return.
863 905
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -993,8 +1035,9 @@  discard block
 block discarded – undo
993 1035
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
994 1036
 
995 1037
 	$column_clauses = array();
996
-	foreach ($event_columns as $col => $crit)
997
-		$column_clauses[] = $col . ' = ' . $crit;
1038
+	foreach ($event_columns as $col => $crit) {
1039
+			$column_clauses[] = $col . ' = ' . $crit;
1040
+	}
998 1041
 
999 1042
 	$smcFunc['db_query']('', '
1000 1043
 		UPDATE {db_prefix}calendar
@@ -1079,8 +1122,9 @@  discard block
 block discarded – undo
1079 1122
 	);
1080 1123
 
1081 1124
 	// If nothing returned, we are in poo, poo.
1082
-	if ($smcFunc['db_num_rows']($request) === 0)
1083
-		return false;
1125
+	if ($smcFunc['db_num_rows']($request) === 0) {
1126
+			return false;
1127
+	}
1084 1128
 
1085 1129
 	$row = $smcFunc['db_fetch_assoc']($request);
1086 1130
 	$smcFunc['db_free_result']($request);
@@ -1088,8 +1132,9 @@  discard block
 block discarded – undo
1088 1132
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1089 1133
 
1090 1134
 	// Sanity check
1091
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1092
-		return false;
1135
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1136
+			return false;
1137
+	}
1093 1138
 
1094 1139
 	$return_value = array(
1095 1140
 		'boards' => array(),
@@ -1226,24 +1271,27 @@  discard block
 block discarded – undo
1226 1271
 
1227 1272
 	// Set $span, in case we need it
1228 1273
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1229
-	if ($span > 0)
1230
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1274
+	if ($span > 0) {
1275
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1276
+	}
1231 1277
 
1232 1278
 	// Define the timezone for this event, falling back to the default if not provided
1233
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1234
-		$tz = $eventOptions['tz'];
1235
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1236
-		$tz = $_POST['tz'];
1237
-	else
1238
-		$tz = getUserTimezone();
1279
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1280
+			$tz = $eventOptions['tz'];
1281
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1282
+			$tz = $_POST['tz'];
1283
+	} else {
1284
+			$tz = getUserTimezone();
1285
+	}
1239 1286
 
1240 1287
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1241
-	if (isset($eventOptions['allday']))
1242
-		$allday = $eventOptions['allday'];
1243
-	elseif (empty($_POST['allday']))
1244
-		$allday = false;
1245
-	else
1246
-		$allday = true;
1288
+	if (isset($eventOptions['allday'])) {
1289
+			$allday = $eventOptions['allday'];
1290
+	} elseif (empty($_POST['allday'])) {
1291
+			$allday = false;
1292
+	} else {
1293
+			$allday = true;
1294
+	}
1247 1295
 
1248 1296
 	// Input might come as individual parameters...
1249 1297
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1270,10 +1318,12 @@  discard block
 block discarded – undo
1270 1318
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1271 1319
 
1272 1320
 	// If the date and time were given in separate strings, combine them
1273
-	if (empty($start_string) && isset($start_date_string))
1274
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1275
-	if (empty($end_string) && isset($end_date_string))
1276
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1321
+	if (empty($start_string) && isset($start_date_string)) {
1322
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1323
+	}
1324
+	if (empty($end_string) && isset($end_date_string)) {
1325
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1326
+	}
1277 1327
 
1278 1328
 	// If some form of string input was given, override individually defined options with it
1279 1329
 	if (isset($start_string))
@@ -1364,10 +1414,11 @@  discard block
 block discarded – undo
1364 1414
 	if ($start_object >= $end_object)
1365 1415
 	{
1366 1416
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1367
-		if ($span > 0)
1368
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1369
-		else
1370
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1417
+		if ($span > 0) {
1418
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1419
+		} else {
1420
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1421
+		}
1371 1422
 	}
1372 1423
 
1373 1424
 	// Is $end_object too late?
@@ -1380,9 +1431,9 @@  discard block
 block discarded – undo
1380 1431
 			{
1381 1432
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1382 1433
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1434
+			} else {
1435
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1383 1436
 			}
1384
-			else
1385
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1386 1437
 		}
1387 1438
 	}
1388 1439
 
@@ -1395,8 +1446,7 @@  discard block
 block discarded – undo
1395 1446
 		$start_time = null;
1396 1447
 		$end_time = null;
1397 1448
 		$tz = null;
1398
-	}
1399
-	else
1449
+	} else
1400 1450
 	{
1401 1451
 		$start_time = date_format($start_object, 'H:i:s');
1402 1452
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1417,16 +1467,18 @@  discard block
 block discarded – undo
1417 1467
 	require_once($sourcedir . '/Subs.php');
1418 1468
 
1419 1469
 	// First, try to create a better date format, ignoring the "time" elements.
1420
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1421
-		$date_format = '%F';
1422
-	else
1423
-		$date_format = $matches[0];
1470
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1471
+			$date_format = '%F';
1472
+	} else {
1473
+			$date_format = $matches[0];
1474
+	}
1424 1475
 
1425 1476
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1426
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1427
-		$time_format = '%k:%M';
1428
-	else
1429
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1477
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1478
+			$time_format = '%k:%M';
1479
+	} else {
1480
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1481
+	}
1430 1482
 
1431 1483
 	// Should this be an all day event?
1432 1484
 	$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;
@@ -1435,8 +1487,9 @@  discard block
 block discarded – undo
1435 1487
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1436 1488
 
1437 1489
 	// We need to have a defined timezone in the steps below
1438
-	if (empty($row['timezone']))
1439
-		$row['timezone'] = getUserTimezone();
1490
+	if (empty($row['timezone'])) {
1491
+			$row['timezone'] = getUserTimezone();
1492
+	}
1440 1493
 
1441 1494
 	// Get most of the standard date information for the start and end datetimes
1442 1495
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1482,8 +1535,9 @@  discard block
 block discarded – undo
1482 1535
 		$tz_location = timezone_location_get(timezone_open($row['timezone']));
1483 1536
 
1484 1537
 		// Kazakstan
1485
-		if ($tz_location['country_code'] == 'KZ')
1486
-			$tz_abbrev = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tz_abbrev);
1538
+		if ($tz_location['country_code'] == 'KZ') {
1539
+					$tz_abbrev = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tz_abbrev);
1540
+		}
1487 1541
 
1488 1542
 		// Russia likes to experiment with time zones
1489 1543
 		if ($tz_location['country_code'] == 'RU')
@@ -1494,8 +1548,9 @@  discard block
 block discarded – undo
1494 1548
 		}
1495 1549
 
1496 1550
 		// Still no good? We'll just mark it as a UTC offset
1497
-		if (strspn($tz_abbrev, '+-') > 0)
1498
-			$tz_abbrev = 'UTC' . $tz_abbrev;
1551
+		if (strspn($tz_abbrev, '+-') > 0) {
1552
+					$tz_abbrev = 'UTC' . $tz_abbrev;
1553
+		}
1499 1554
 	}
1500 1555
 
1501 1556
 	return array($start, $end, $allday, $span, $tz, $tz_abbrev);
@@ -1511,8 +1566,9 @@  discard block
 block discarded – undo
1511 1566
 {
1512 1567
 	global $smcFunc, $context, $sourcedir, $user_info, $modSettings;
1513 1568
 
1514
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1515
-		$id_member = $context['user']['id'];
1569
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1570
+			$id_member = $context['user']['id'];
1571
+	}
1516 1572
 
1517 1573
 	if (isset($id_member))
1518 1574
 	{
@@ -1528,8 +1584,9 @@  discard block
 block discarded – undo
1528 1584
 		$smcFunc['db_free_result']($request);
1529 1585
 	}
1530 1586
 
1531
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1532
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1587
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1588
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1589
+	}
1533 1590
 
1534 1591
 	return $timezone;
1535 1592
 }
@@ -1558,8 +1615,9 @@  discard block
 block discarded – undo
1558 1615
 		)
1559 1616
 	);
1560 1617
 	$holidays = array();
1561
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1562
-		$holidays[] = $row;
1618
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1619
+			$holidays[] = $row;
1620
+	}
1563 1621
 	$smcFunc['db_free_result']($request);
1564 1622
 
1565 1623
 	return $holidays;
Please login to merge, or discard this patch.