@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Get all birthdays within the given time range. |
@@ -60,8 +61,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
1607 | 1661 | global $smcFunc, $context, $user_info, $modSettings, $user_settings; |
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])) |
@@ -1637,11 +1692,13 @@ discard block |
||
1637 | 1692 | $smcFunc['db_free_result']($request); |
1638 | 1693 | } |
1639 | 1694 | |
1640 | - if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
1641 | - $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
1695 | + if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
1696 | + $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
1697 | + } |
|
1642 | 1698 | |
1643 | - if (isset($id_member)) |
|
1644 | - $member_cache[$id_member] = $timezone; |
|
1699 | + if (isset($id_member)) { |
|
1700 | + $member_cache[$id_member] = $timezone; |
|
1701 | + } |
|
1645 | 1702 | |
1646 | 1703 | return $timezone; |
1647 | 1704 | } |
@@ -1670,8 +1727,9 @@ discard block |
||
1670 | 1727 | ) |
1671 | 1728 | ); |
1672 | 1729 | $holidays = array(); |
1673 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1674 | - $holidays[] = $row; |
|
1730 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1731 | + $holidays[] = $row; |
|
1732 | + } |
|
1675 | 1733 | $smcFunc['db_free_result']($request); |
1676 | 1734 | |
1677 | 1735 | return $holidays; |