/** * Ajax response for the public full calendar. This returns events to be displayed on the front-end full calendar * *@since 1.3 *@access private *@ignore */ function eventorganiser_public_fullcalendar() { $request = array('event_start_before' => $_GET['end'], 'event_end_after' => $_GET['start']); $time_format = !empty($_GET['timeformat']) ? $_GET['timeformat'] : get_option('time_format'); //Restrict by category and/or venue/tag foreach (array('category', 'venue', 'tag') as $tax) { if (!empty($_GET[$tax])) { $request['tax_query'][] = array('taxonomy' => 'event-' . $tax, 'field' => 'slug', 'terms' => explode(',', esc_attr($_GET[$tax])), 'operator' => 'IN'); } } if (!empty($_GET['organiser'])) { $request['author'] = (int) $_GET['organiser']; } if (!empty($_GET['users_events']) && 'false' != $_GET['users_events']) { $request['bookee_id'] = get_current_user_id(); } if (!empty($_GET['event_occurrence__in'])) { $request['event_occurrence__in'] = $_GET['event_occurrence__in']; } $presets = array('numberposts' => -1, 'group_events_by' => '', 'showpastevents' => true); if (current_user_can('read_private_events')) { $priv = '_priv'; $post_status = array('publish', 'private'); } else { $priv = false; $post_status = array('publish'); } //Retrieve events $query = array_merge($request, $presets); /** * Filters the query before it is sent to the calendar. * * The returned $query array is used to generate the cache key. The `$query` * array can contain any keys supported by `eo_get_events()`, and so also * `get_posts()` and `WP_Query()`. * * @package fullCalendar * @since 2.13.0 * @param array $query An query array (as given to `eo_get_events()`) */ $query = apply_filters('eventorganiser_fullcalendar_query', $query); //In case polylang is enabled with events as translatable. Include locale in cache key. $options = get_option('polylang'); if (defined('POLYLANG_VERSION') && !empty($options['post_types']) && in_array('event', $options['post_types'])) { $key = 'eo_fc_' . md5(serialize($query) . $time_format . get_locale()); } else { $key = 'eo_fc_' . md5(serialize($query) . $time_format); } $calendar = get_transient("eo_full_calendar_public{$priv}"); if ($calendar && is_array($calendar) && isset($calendar[$key])) { $events_array = $calendar[$key]; /** * Filters the event before it is sent to the calendar. * * **Note:** This filters the response immediately before sending, and after * the cache is saved/retrieved. Changes made on this filter are not cached. * * @package fullCalendar * @param array $events_array An array of events (array). * @param array $query The query as given to eo_get_events() */ $events_array = apply_filters('eventorganiser_fullcalendar', $events_array, $query); echo json_encode($events_array); exit; } $query['post_status'] = $post_status; $events = eo_get_events($query); $events_array = array(); //Blog timezone $tz = eo_get_blog_timezone(); //Loop through events global $post; if ($events) { foreach ($events as $post) { setup_postdata($post); $event = array(); //Title and url $event['title'] = html_entity_decode(get_the_title($post->ID), ENT_QUOTES, 'UTF-8'); $link = esc_js(get_permalink($post->ID)); /** * Filters the link to the event's page on the admin calendar. * * **Note:** As the calendar is cached, changes made using this filter * will not take effect immediately. You can clear the cache by * updating an event. * * ### Example * * //Remove link if from calendar if event has no content * add_filter('eventorganiser_calendar_event_link','myprefix_maybe_no_calendar_link',10,3); * function myprefix_maybe_no_calendar_link( $link, $event_id, $occurrence_id ){ * $the_post = get_post($post_id); * if( empty($the_post->post_content) ){ * return false; * } * return $link; * } * * @package fullCalendar * @param string $link The url the event points to on the calendar. * @param int $event_id The event's post ID. * @param int $occurrence_id The event's occurrence ID. */ $link = apply_filters('eventorganiser_calendar_event_link', $link, $post->ID, $post->occurrence_id); $event['url'] = $link; //All day or not? $event['allDay'] = eo_is_all_day(); //Get Event Start and End date, set timezone to the blog's timzone $event_start = new DateTime($post->StartDate . ' ' . $post->StartTime, $tz); $event_end = new DateTime($post->EndDate . ' ' . $post->FinishTime, $tz); $event['start'] = $event_start->format('Y-m-d\\TH:i:s'); $event['end'] = $event_end->format('Y-m-d\\TH:i:s'); //Don't use get_the_excerpt as this adds a link $excerpt_length = apply_filters('excerpt_length', 55); $description = wp_trim_words(strip_shortcodes(get_the_content()), $excerpt_length, '...'); if ($event_start->format('Y-m-d') != $event_end->format('Y-m-d')) { //Start & ends on different days if (!eo_is_all_day()) { //Not all day, include time $date = eo_format_datetime($event_start, 'F j ' . $time_format) . ' - ' . eo_format_datetime($event_end, 'F j ' . $time_format); } else { //All day, don't include date if ($event_start->format('Y-m') == $event_end->format('Y-m')) { //Same month $date = eo_format_datetime($event_start, 'F j') . ' - ' . eo_format_datetime($event_end, 'j, Y'); } else { //Different month $date = eo_format_datetime($event_start, 'F j') . ' - ' . eo_format_datetime($event_end, 'F j'); } } } else { //Start and end on the same day if (!eo_is_all_day()) { //Not all day, include time $date = eo_format_datetime($event_start, $format = "F j, Y {$time_format}") . ' - ' . eo_format_datetime($event_end, $time_format); } else { //All day $date = eo_format_datetime($event_start, $format = 'F j, Y'); } } $description = $date . '</br></br>' . $description; /** * Filters the description of the event as it appears on the calendar tooltip. * * **Note:** As the calendar is cached, changes made using this filter * will not take effect immediately. You can clear the cache by * updating an event. * * @link https://gist.github.com/stephenh1988/4040699 Including venue name in tooltip. * * @package fullCalendar * @param string $description The event's tooltip description. * @param int $event_id The event's post ID. * @param int $occurrence_id The event's occurrence ID. * @param WP_Post $post The event (post) object. */ $description = apply_filters('eventorganiser_event_tooltip', $description, $post->ID, $post->occurrence_id, $post); $event['description'] = $description; $event['className'] = eo_get_event_classes(); $event['className'][] = 'eo-event'; //Colour past events $now = new DateTime(null, $tz); if ($event_start <= $now) { $event['className'][] = 'eo-past-event'; } else { $event['className'][] = 'eo-future-event'; } //deprecated. use eo-event-future //Include venue if this is set $venue = eo_get_venue($post->ID); if ($venue && !is_wp_error($venue)) { $event['className'][] = 'venue-' . eo_get_venue_slug($post->ID); //deprecated. use eo-event-venue-{slug} $event['venue'] = $venue; } //Event categories $terms = get_the_terms($post->ID, 'event-category'); $event['category'] = array(); if ($terms) { foreach ($terms as $term) { $event['category'][] = $term->slug; $event['className'][] = 'category-' . $term->slug; //deprecated. use eo-event-cat-{slug} } } //Event tags if (eventorganiser_get_option('eventtag')) { $terms = get_the_terms($post->ID, 'event-tag'); $event['tags'] = array(); if ($terms && !is_wp_error($terms)) { foreach ($terms as $term) { $event['tags'][] = $term->slug; $event['className'][] = 'tag-' . $term->slug; //deprecated. use eo-event-tag-{slug} } } } //Event colour $event['textColor'] = '#ffffff'; //default text colour if (eo_get_event_color()) { $event['color'] = eo_get_event_color(); $event['textColor'] = eo_get_event_textcolor($event['color']); } //Add event to array /** * Filters the event before it is sent to the calendar. * * The event is an array with various key/values, which is seralised and sent * to the calendar. * * **Note:** As the calendar is cached, changes made using this filter * will not take effect immediately. You can clear the cache by * updating an event. * * @package fullCalendar * @param array $event The event (array) * @param int $event_id The event's post ID. * @param int $occurrence_id The event's occurrence ID. */ $event = apply_filters('eventorganiser_fullcalendar_event', $event, $post->ID, $post->occurrence_id); if ($event) { $events_array[] = $event; } } wp_reset_postdata(); } if (!$calendar || !is_array($calendar)) { $calendar = array(); } $calendar[$key] = $events_array; set_transient("eo_full_calendar_public{$priv}", $calendar, 60 * 60 * 24); $events_array = apply_filters('eventorganiser_fullcalendar', $events_array, $query); //Echo result and exit echo json_encode($events_array); exit; }
/** * Generates widget / shortcode calendar html * * @param $month - DateTime object for first day of the month (in blog timezone) */ static function generate_output($month, $args = array()) { //Translations global $wp_locale; $today = new DateTime('now', eo_get_blog_timezone()); $key = $month->format('YM') . serialize($args) . get_locale() . $today->format('Y-m-d'); $calendar = get_transient('eo_widget_calendar'); if ((!defined('WP_DEBUG') || !WP_DEBUG) && $calendar && is_array($calendar) && isset($calendar[$key])) { return $calendar[$key]; } //Parse defaults $args['show-long'] = isset($args['show-long']) ? $args['show-long'] : false; $args['link-to-single'] = isset($args['link-to-single']) ? $args['link-to-single'] : false; //Month details $first_day_of_month = intval($month->format('N')); //0=sun,...,6=sat $days_in_month = intval($month->format('t')); // 28-31 $last_month = clone $month; $last_month->modify('last month'); $next_month = clone $month; $next_month->modify('next month'); //Retrieve the start day of the week from the options. $start_day = intval(get_option('start_of_week')); //0=sun,...,6=sat //How many blank cells before inserting dates $offset = ($first_day_of_month - $start_day + 7) % 7; //Number of weeks to show in Calendar $totalweeks = ceil(($offset + $days_in_month) / 7); //Get events for this month $start = $month->format('Y-m-d'); $end = $month->format('Y-m-t'); //Query events $required = array('numberposts' => -1, 'showrepeats' => 1); if ($args['show-long']) { $args['event_start_before'] = $end; $args['event_end_after'] = $start; } else { $args['event_start_before'] = $end; $args['event_start_after'] = $start; } $events = eo_get_events(array_merge($args, $required)); //Populate events array $calendar_events = array(); foreach ($events as $event) { if ($args['show-long']) { $start = eo_get_the_start(DATETIMEOBJ, $event->ID, null, $event->occurrence_id); $end = eo_get_the_end(DATETIMEOBJ, $event->ID, null, $event->occurrence_id); $pointer = clone $start; while ($pointer <= $end) { $date = eo_format_datetime($pointer, 'Y-m-d'); $calendar_events[$date][] = $event; $pointer->modify('+1 day'); } } else { $date = eo_get_the_start('Y-m-d', $event->ID, null, $event->occurrence_id); $calendar_events[$date][] = $event; } } $before = "<table id='wp-calendar'>"; $title = sprintf("<caption> %s </caption>", esc_html(eo_format_datetime($month, 'F Y'))); $head = "<thead><tr>"; for ($d = 0; $d <= 6; $d++) { $day = $wp_locale->get_weekday(($d + $start_day) % 7); $day_abbrev = $wp_locale->get_weekday_initial($day); $head .= sprintf("<th title='%s' scope='col'>%s</th>", esc_attr($day), esc_html($day_abbrev)); } $head .= "</tr></thead>"; $foot = sprintf("<tfoot><tr>\n\t\t\t\t\t<td id='eo-widget-prev-month' colspan='3'><a title='%s' href='%s'>« %s</a></td>\n\t\t\t\t\t<td class='pad'> </td>\n\t\t\t\t\t<td id='eo-widget-next-month' colspan='3'><a title='%s' href='%s'> %s » </a></td>\n\t\t\t\t</tr></tfoot>", esc_html__('Previous month', 'eventorganiser'), add_query_arg('eo_month', $last_month->format('Y-m')), esc_html(eo_format_datetime($last_month, 'M')), esc_html__('Next month', 'eventorganiser'), add_query_arg('eo_month', $next_month->format('Y-m')), esc_html(eo_format_datetime($next_month, 'M'))); $body = "<tbody>"; $current_date = clone $month; //Foreach week in calendar for ($w = 0; $w <= $totalweeks - 1; $w++) { $body .= "<tr>"; //For each cell in this week for ($cell = $w * 7 + 1; $cell <= ($w + 1) * 7; $cell++) { $formated_date = $current_date->format('Y-m-d'); $data = "data-eo-wc-date='{$formated_date}'"; if ($cell <= $offset) { $body .= "<td class='pad eo-before-month' colspan='1'> </td>"; } elseif ($cell - $offset > $days_in_month) { $body .= "<td class='pad eo-after-month' colspan='1'> </td>"; } else { $class = array(); if ($formated_date < $today->format('Y-m-d')) { $class[] = 'eo-past-date'; } elseif ($formated_date == $today->format('Y-m-d')) { $class[] = 'today'; } else { $class[] = 'eo-future-date'; } //Does the date have any events if (isset($calendar_events[$formated_date])) { $class[] = 'event'; $events = $calendar_events[$formated_date]; if ($events && count($events) == 1 && $args['link-to-single']) { $only_event = $events[0]; $link = get_permalink($only_event->ID); } else { $link = eo_get_event_archive_link($current_date->format('Y'), $current_date->format('m'), $current_date->format('d')); } $link = esc_url($link); /** * Filters the the link of a date on the events widget calendar * @param string $link The link * @param datetime $current_date The date being filtered * @param array $events Array of events starting on this day */ $link = apply_filters('eventorganiser_widget_calendar_date_link', $link, $current_date, $events); foreach ($events as $event) { $class = array_merge($class, eo_get_event_classes($event->ID, $event->occurrence_id)); } $class = array_unique(array_filter($class)); $classes = implode(' ', $class); $titles = implode(', ', wp_list_pluck($events, 'post_title')); $body .= sprintf("<td {$data} class='%s'> <a title='%s' href='%s'> %s </a></td>", esc_attr($classes), esc_attr($titles), $link, $cell - $offset); } else { $classes = implode(' ', $class); $body .= sprintf("<td {$data} class='%s'> %s </td>", esc_attr($classes), $cell - $offset); } //Proceed to next day $current_date->modify('+1 day'); } } //Endfor each day in week $body .= "</tr>"; } //End for each week $body .= "</tbody>"; $after = "</table>"; if (!$calendar || !is_array($calendar)) { $calendar = array(); } $calendar[$key] = $before . $title . $head . $foot . $body . $after; set_transient('eo_widget_calendar', $calendar, 60 * 60 * 24); return $calendar[$key]; }
<h3>Monatsauswahl</h3> <?php while ($eo_event_loop->have_posts()) { $eo_event_loop->the_post(); ?> <?php if ($current_month != eo_get_the_start('m')) { //End previous group //Start new group echo '<p class="month"><a href="/veranstaltungen/on/' . eo_get_the_start('Y/m') . '">' . eo_get_the_start('F Y') . '</a></p>'; } $current_month = eo_get_the_start('m'); //Generate HTML classes for this event $eo_event_classes = eo_get_event_classes(); //For non-all-day events, include time format $format = eo_is_all_day() ? $date_format : $date_format . '--' . $time_format; ?> <?php } ?> <?php } elseif (!empty($eo_event_loop_args['no_events'])) { ?> <ul id="<?php echo esc_attr($id); ?>
function eventorganiser_list_events($query, $args = array(), $echo = 1) { $args = array_merge(array('id' => '', 'class' => 'eo-event-list', 'type' => 'shortcode', 'no_events' => ''), $args); /* Pass these defaults - backwards compat with using eo_get_events()*/ $query = wp_parse_args($query, array('posts_per_page' => -1, 'post_type' => 'event', 'suppress_filters' => false, 'orderby' => 'eventstart', 'order' => 'ASC', 'showrepeats' => 1, 'group_events_by' => '', 'showpastevents' => true)); //Make sure false and 'False' etc actually get parsed as 0/false (input from shortcodes, for instance, can be varied). //This maybe moved to the shortcode handler if this function is made public. if (strtolower($query['showpastevents']) === 'false') { $query['showpastevents'] = 0; } if (!empty($query['numberposts'])) { $query['posts_per_page'] = (int) $query['numberposts']; } $template = isset($args['template']) ? $args['template'] : ''; global $eo_event_loop, $eo_event_loop_args; $eo_event_loop_args = $args; $eo_event_loop = new WP_Query($query); /** * @ignore * Try to find template - backwards compat. Don't use this filter. Will be removed! */ $template_file = apply_filters('eventorganiser_event_list_loop', false); $template_file = locate_template($template_file); if ($template_file || empty($template)) { ob_start(); if (empty($template_file)) { $template_file = eo_locate_template(array($eo_event_loop_args['type'] . '-event-list.php', 'event-list.php'), true, false); } else { require $template_file; } $html = ob_get_contents(); ob_end_clean(); } else { //Using the 'placeholder' template $no_events = isset($args['no_events']) ? $args['no_events'] : ''; $line_wrap = '<li class="%2$s">%1$s</li>'; $id = !empty($args['id']) ? 'id="' . esc_attr($args['id']) . '"' : ''; $container = '<ul ' . $id . ' class="%2$s">%1$s</ul>'; $html = ''; if ($eo_event_loop->have_posts()) { while ($eo_event_loop->have_posts()) { $eo_event_loop->the_post(); $event_classes = eo_get_event_classes(); $html .= sprintf($line_wrap, EventOrganiser_Shortcodes::read_template($template), esc_attr(implode(' ', $event_classes))); } } elseif ($no_events) { $html .= sprintf($line_wrap, $no_events, 'eo-no-events'); } $html = sprintf($container, $html, esc_attr($args['class'])); } wp_reset_postdata(); if ($echo) { echo $html; } return $html; }