From 907f39db4ab00de43016646660d9d1ca9c73d1f9 Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Sat, 27 Jan 2024 13:05:41 +0100 Subject: initial commit --- event-calendar.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 event-calendar.php (limited to 'event-calendar.php') diff --git a/event-calendar.php b/event-calendar.php new file mode 100644 index 0000000..ae6fe43 --- /dev/null +++ b/event-calendar.php @@ -0,0 +1,87 @@ + 600 && view.type != 'month') {" . + "\$('\#$id').fullCalendar('changeView', 'month');" . + "}" . + "}" . + "})" . + "});"); + + return "
"; +} + +function communievents_calendar_ajax() { + global $wpdb; + + $table_name = $wpdb->prefix . 'communievents_events'; + + $tz = new DateTimeZone(CommuniApi::TIMEZONE); + + $start_dt = new DateTime($_REQUEST['start'], $tz); + $end_dt = new DateTime($_REQUEST['end'], $tz); + + $retval = array(); + $list = $wpdb->get_results($wpdb->prepare( + "SELECT * FROM $table_name WHERE official=1 AND start <= %s AND end >= %s ORDER BY start", + $end_dt->format('Y-m-d H:i:s'), $start_dt->format('Y-m-d H:i:s'))); + + if ($list) { + foreach ($list as $event) { + $start_dt = new DateTime($event->start, $tz); + $end_dt = new DateTime($event->end, $tz); + + if ($event->allday) { + // end is non-inclusive! move it into the next day + $end_dt->modify('+1 minute'); + + $start_str = $start_dt->format('Y-m-d'); + $end_str = $end_dt->format('Y-m-d'); + } else { + $start_str = $start_dt->format('Y-m-d\TH:i:s'); + $end_str = $end_dt->format('Y-m-d\TH:i:s'); + } + + $retval[] = array( + 'title' => $event->title, + 'start' => $start_str, + 'end' => $end_str, + 'url' => $event->url + ); + } + } + + wp_send_json($retval); +} + +function communievents_setup_event_calendar() { + add_shortcode('communievents-event-calendar', 'communievents_event_calendar'); + + wp_register_script('communievents-momentjs', COMMUNIEVENTS_PLUGIN_URL . "js/moment.min.js", null, true); + wp_register_script('communievents-fullcalendar', COMMUNIEVENTS_PLUGIN_URL . "js/fullcalendar.min.js", array( + 'jquery', 'communievents-momentjs'/*, 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-button'*/), null, true); + wp_register_script('communievents-fullcalendar-de', COMMUNIEVENTS_PLUGIN_URL . 'js/fullcalendar-de.js', array('communievents-fullcalendar'), null, true); + wp_register_style('communievents-fullcalendar', COMMUNIEVENTS_PLUGIN_URL . 'css/fullcalendar.min.css'); + + add_action('wp_ajax_nopriv_communievents_calendar_data', 'communievents_calendar_ajax'); + add_action('wp_ajax_communievents_calendar_data', 'communievents_calendar_ajax'); +} + -- cgit v1.2.3