Пример #1
0
 /**
  * @see https://github.com/stephenharris/Event-Organiser/issues/205
  * Tests event end date is created successfully. 
  */
 public function testEventAtEndOfMonth()
 {
     $original_tz = get_option('timezone_string');
     $original_offset = get_option('gmt_offset');
     update_option('timezone_string', '');
     update_option('gmt_offset', 10);
     $tz = eo_get_blog_timezone();
     $event = array('post_title' => 'Test event', 'start' => new DateTime('2014-07-01 00:00:00', $tz), 'end' => new DateTime('2014-07-31 23:59:00', $tz), 'all_day' => 1);
     $event_id = eo_insert_event($event);
     $occurrences = eo_get_the_occurrences($event_id);
     $occurrence_ids = array_keys($occurrences);
     $occurrence_id = array_shift($occurrence_ids);
     $this->assertEquals('2014-07-31', eo_get_the_end('Y-m-d', $event_id, null, $occurrence_id));
     update_option('timezone_string', $original_tz);
     update_option('gmt_offset', $original_offset);
 }
Пример #2
0
function eventorganiser_posterboard_ajax_response()
{
    $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
    $query = empty($_GET['query']) ? array() : $_GET['query'];
    foreach (array('category', 'tag', 'venue') as $tax) {
        if (isset($query['event_' . $tax])) {
            $query['event-' . $tax] = $query['event_' . $tax];
            unset($query['event_' . $tax]);
        }
    }
    if (isset($query['event-venue']) && '%this%' == $query['event-venue']) {
        if (eo_get_venue_slug()) {
            $query['event-venue'] = eo_get_venue_slug();
        } else {
            unset($query['event-venue']);
        }
    }
    if (isset($query['users_events']) && 'true' == strtolower($query['users_events'])) {
        $query['bookee_id'] = get_current_user_id();
    }
    $query = array_merge(array('event_start_after' => 'today', 'posts_per_page' => 10), $query, array('post_type' => 'event', 'paged' => $page, 'post_status' => array('publish', 'private'), 'perm' => 'readable', 'supress_filters' => false));
    $event_query = new WP_Query($query);
    $response = array();
    if ($event_query->have_posts()) {
        global $post;
        while ($event_query->have_posts()) {
            $event_query->the_post();
            $start_format = get_option('time_format');
            if (eo_get_the_start('Y-m-d') == eo_get_the_end('Y-m-d')) {
                $end_format = get_option('time_format');
            } else {
                $end_format = 'j M ' . get_option('time_format');
            }
            $venue_id = eo_get_venue();
            $categories = get_the_terms(get_the_ID(), 'event-category');
            $colour = eo_get_event_color() ? eo_get_event_color() : '#1e8cbe';
            $address = eo_get_venue_address($venue_id);
            $event = array('event_id' => get_the_ID(), 'occurrence_id' => $post->occurrence_id, 'event_title' => get_the_title(), 'event_color' => $colour, 'event_color_light' => eo_color_luminance($colour, 0.3), 'event_start_day' => eo_get_the_start('j'), 'event_start_month' => eo_get_the_start('M'), 'event_content' => get_the_content(), 'event_excerpt' => get_the_excerpt(), 'event_thumbnail' => get_the_post_thumbnail(get_the_ID(), array('200', '200'), array('class' => 'aligncenter')), 'event_permalink' => get_permalink(), 'event_categories' => get_the_term_list(get_the_ID(), 'event-category', '#', ', #', ''), 'event_venue' => $venue_id ? eo_get_venue_name($venue_id) : false, 'event_venue_id' => $venue_id, 'event_venue_city' => $venue_id ? $address['city'] : false, 'event_venue_state' => $venue_id ? $address['state'] : false, 'event_venue_country' => $venue_id ? $address['country'] : false, 'event_venue_url' => $venue_id ? eo_get_venue_link($venue_id) : false, 'event_is_all_day' => eo_is_all_day(), 'event_cat_ids' => $categories ? array_values(wp_list_pluck($categories, 'term_id')) : array(0), 'event_range' => eo_get_the_start($start_format) . ' - ' . eo_get_the_end($end_format));
            $event = apply_filters('eventorganiser_posterboard_item', $event, $event['event_id'], $event['occurrence_id']);
            $response[] = $event;
        }
    }
    wp_reset_postdata();
    echo json_encode($response);
    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'>&laquo; %s</a></td>\n\t\t\t\t\t<td class='pad'>&nbsp;</td>\n\t\t\t\t\t<td id='eo-widget-next-month' colspan='3'><a title='%s' href='%s'> %s &raquo; </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'>&nbsp;</td>";
             } elseif ($cell - $offset > $days_in_month) {
                 $body .= "<td class='pad eo-after-month' colspan='1'>&nbsp;</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];
 }
/**
 * Callback for the delete expired events cron job. Deletes events that finished at least 24 hours ago.
 * For recurring events it is only deleted once the last occurrence has expired.
 *
 * @since 1.4.0
 * @ignore
 * @access private
 */
function eventorganiser_delete_expired_events()
{
    //Get expired events
    $events = eo_get_events(array('showrepeats' => 0, 'showpastevents' => 1, 'eo_interval' => 'expired'));
    $time_until_expired = (int) apply_filters('eventorganiser_events_expire_time', 24 * 60 * 60);
    $time_until_expired = max($time_until_expired, 0);
    if ($events) {
        $now = new DateTime('now', eo_get_blog_timezone());
        foreach ($events as $event) {
            $start = eo_get_the_start(DATETIMEOBJ, $event->ID, null, $event->occurrence_id);
            $end = eo_get_the_end(DATETIMEOBJ, $event->ID, null, $event->occurrence_id);
            $expired = round(abs($end->format('U') - $start->format('U'))) + $time_until_expired;
            //Duration + expire time
            $finished = eo_get_schedule_last(DATETIMEOBJ, $event->ID);
            $finished->modify("+{$expired} seconds");
            //[Expired time] after the last occurrence finishes
            //Delete if [expired time] has passed
            if ($finished <= $now) {
                wp_trash_post((int) $event->ID);
            }
        }
    }
}
 static function parse_template($matches)
 {
     global $post;
     $replacement = '';
     switch ($matches[1]) {
         case 'event_title':
             $replacement = get_the_title();
             break;
         case 'start':
         case 'end':
         case 'schedule_start':
         case 'schedule_last':
         case 'schedule_end':
             switch (count($matches)) {
                 case 2:
                     $dateFormat = get_option('date_format');
                     $dateTime = get_option('time_format');
                     break;
                 case 3:
                     $dateFormat = self::eo_clean_input($matches[2]);
                     $dateTime = '';
                     break;
                 case 5:
                     $dateFormat = self::eo_clean_input($matches[3]);
                     $dateTime = self::eo_clean_input($matches[4]);
                     break;
             }
             $format = eo_is_all_day(get_the_ID()) ? $dateFormat : $dateFormat . $dateTime;
             switch ($matches[1]) {
                 case 'start':
                     $replacement = eo_get_the_start($format);
                     break;
                 case 'end':
                     $replacement = eo_get_the_end($format);
                     break;
                 case 'schedule_start':
                     $replacement = eo_get_schedule_start($format);
                     break;
                 case 'schedule_last':
                 case 'schedule_end':
                     $replacement = eo_get_schedule_end($format);
                     break;
             }
             break;
         case 'event_duration':
             $start = eo_get_the_start(DATETIMEOBJ);
             $end = clone eo_get_the_end(DATETIMEOBJ);
             if (eo_is_all_day()) {
                 $end->modify('+1 minute');
             }
             if (function_exists('date_diff')) {
                 $duration = date_diff($start, $end);
                 $replacement = $duration->format($matches[2]);
             } else {
                 $replacement = eo_date_interval($start, $end, $matches[2]);
             }
             $replacement = false;
             break;
         case 'event_tags':
             $replacement = get_the_term_list(get_the_ID(), 'event-tag', '', ', ', '');
             break;
         case 'event_cats':
             $replacement = get_the_term_list(get_the_ID(), 'event-category', '', ', ', '');
             break;
         case 'event_venue':
             $replacement = eo_get_venue_name();
             break;
         case 'event_venue_map':
             if (eo_get_venue()) {
                 $class = isset($matches[2]) ? self::eo_clean_input($matches[2]) : '';
                 $class = !empty($class) ? 'class=' . $class : '';
                 $replacement = eo_get_venue_map(eo_get_venue(), compact('class'));
             }
             break;
         case 'event_venue_url':
             $venue_link = eo_get_venue_link();
             $replacement = !is_wp_error($venue_link) ? $venue_link : '';
             break;
         case 'event_venue_address':
             $address = eo_get_venue_address();
             $replacement = $address['address'];
             break;
         case 'event_venue_postcode':
             $address = eo_get_venue_address();
             $replacement = $address['postcode'];
             break;
         case 'event_venue_city':
             $address = eo_get_venue_address();
             $replacement = $address['city'];
             break;
         case 'event_venue_country':
             $address = eo_get_venue_address();
             $replacement = $address['country'];
             break;
         case 'event_venue_state':
             $address = eo_get_venue_address();
             $replacement = $address['state'];
             break;
         case 'event_venue_city':
             $address = eo_get_venue_address();
             $replacement = $address['city'];
             break;
         case 'event_thumbnail':
             $size = isset($matches[2]) ? self::eo_clean_input($matches[2]) : '';
             $size = !empty($size) ? $size : 'thumbnail';
             $attr = isset($matches[3]) ? self::eo_clean_input($matches[3]) : '';
             //Decode HTML entities as shortcode encodes them
             $attr = html_entity_decode($attr);
             $replacement = get_the_post_thumbnail(get_the_ID(), $size, $attr);
             break;
         case 'event_url':
             $replacement = get_permalink();
             break;
         case 'event_custom_field':
             $field = $matches[2];
             $meta = get_post_meta(get_the_ID(), $field);
             $replacement = implode($meta);
             break;
         case 'event_excerpt':
             $length = isset($matches[2]) ? intval($matches[2]) : 55;
             //Using get_the_excerpt adds a link....
             if (post_password_required($post)) {
                 $output = __('There is no excerpt because this is a protected post.');
             } else {
                 $output = $post->post_excerpt;
             }
             $replacement = eventorganiser_trim_excerpt($output, $length);
             break;
         case 'event_content':
             $replacement = get_the_content();
             break;
         case 'cat_color':
             $replacement = eo_get_event_color();
             break;
         case 'event_title_attr':
             $replacement = get_the_title();
             break;
     }
     return $replacement;
 }
Пример #6
0
        the_post();
        ?>
  <article id="post-<?php 
        the_ID();
        ?>
" <?php 
        post_class();
        ?>
>


    <span class="news-date"><?php 
        printf(eo_get_the_start("G:i"));
        ?>
 - <?php 
        printf(eo_get_the_end("G:i"));
        ?>
 </span>
      <?php 
        if (has_post_thumbnail()) {
            ?>
        <?php 
            $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium');
            ?>
        <div style="background:url('<?php 
            echo $thumb['0'];
            ?>
')no-repeat center center;" class="news-thumbnail"></div>
      <?php 
        } else {
            ?>
Пример #7
0
echo "X-ORIGINAL-URL:" . get_post_type_archive_link('event') . "\r\n";
echo "X-WR-CALDESC:" . get_bloginfo('name') . " - Events\r\n";
// Loop through events
if (have_posts()) {
    $now = new DateTime();
    $dtstamp = $now->format('Ymd\\THis\\Z');
    $UTC_tz = new DateTimeZone('UTC');
    while (have_posts()) {
        the_post();
        global $post;
        // If event has no corresponding row in events table then skip it
        if (!isset($post->event_id) || $post->event_id == -1) {
            continue;
        }
        $start = eo_get_the_start(DATETIMEOBJ);
        $end = eo_get_the_end(DATETIMEOBJ);
        $created_date = get_post_time('Ymd\\THis\\Z', true);
        $modified_date = get_post_modified_time('Ymd\\THis\\Z', true);
        $schedule_data = eo_get_event_schedule();
        // Set up start and end date times
        if (eo_is_all_day()) {
            $format = 'Ymd';
            $start_date = $start->format($format);
            $end->modify('+1 minute');
            $end_date = $end->format($format);
        } else {
            $format = 'Ymd\\THis\\Z';
            $start->setTimezone($UTC_tz);
            $start_date = $start->format($format);
            $end->setTimezone($UTC_tz);
            $end_date = $end->format($format);
Пример #8
0
<?php 
if ($eo_event_loop->have_posts()) {
    $dName = 'D';
    $dNum = 'd';
    $mName = 'M';
    $tnum = 'H:i';
    ?>

		<?php 
    while ($eo_event_loop->have_posts()) {
        $eo_event_loop->the_post();
        //For non-all-day events, include time format
        if (eo_is_all_day()) {
            $cal_time = 'Hele dagen';
        } else {
            $cal_time = eo_get_the_start($tnum) . ' - ' . eo_get_the_end($tnum);
        }
        ?>

			<div class="cal-entry" >
                <div class="date-box">
                    <span class="dname"><?php 
        echo eo_get_the_start($dName);
        ?>
</span>
                    <span class="dnum"><?php 
        echo eo_get_the_start($dNum);
        ?>
</span>
                    <span class="mname"><?php 
        echo eo_get_the_start($mName);
/**
 * Break a specified occurrence from an event
 * 
 * @param int $post_id The event (post) ID
 * @param int $occurrence_id The occurrence ID
 * @return int|WP_Error The new event (post) ID or a WP_Error on error
 */
function eo_break_occurrence($post_id, $occurrence_id)
{
    global $post;
    $post = get_post($post_id);
    setup_postdata($post_id);
    /**
     * Triggered before an occurrence is broken from an event.
     *
     * @param int $post_id The ID of the original parent event
     * @param int $occurrence_id The ID of the occurrence being broken
     */
    do_action('eventorganiser_pre_break_occurrence', $post_id, $occurrence_id);
    $tax_input = array();
    foreach (array('event-category', 'event-tag', 'event-venue') as $tax) {
        $terms = get_the_terms($post->ID, $tax);
        if ($terms && !is_wp_error($terms)) {
            $tax_input[$tax] = array_map('intval', wp_list_pluck($terms, 'term_id'));
        }
    }
    //Post details
    $post_array = array('post_title' => $post->post_title, 'post_name' => $post->post_name, 'post_author' => $post->post_author, 'post_content' => $post->post_content, 'post_status' => $post->post_status, 'post_date' => $post->post_date, 'post_date_gmt' => $post->post_date_gmt, 'post_excerpt' => $post->post_excerpt, 'post_password' => $post->post_password, 'post_type' => 'event', 'tax_input' => $tax_input, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status);
    //Event details
    $event_array = array('start' => eo_get_the_start(DATETIMEOBJ, $post_id, null, $occurrence_id), 'end' => eo_get_the_end(DATETIMEOBJ, $post_id, null, $occurrence_id), 'all_day' => eo_is_all_day($post_id) ? 1 : 0, 'schedule' => 'once', 'frequency' => 1);
    //Create new event with duplicated details (new event clears cache)
    $new_event_id = eo_insert_event($post_array, $event_array);
    //delete occurrence, and copy post meta
    if ($new_event_id && !is_wp_error($new_event_id)) {
        $response = _eventorganiser_remove_occurrence($post_id, $occurrence_id);
        $post_custom = get_post_custom($post_id);
        foreach ($post_custom as $meta_key => $meta_values) {
            //Don't copy these
            $ignore_meta = array('_eventorganiser_uid', '_eo_tickets', '_edit_last', '_edit_last', '_edit_lock');
            /**
             * Filters an array of keys which should be ignored when breaking an 
             * occurrence.
             * 
             * When breaking an occurrence from an event a new event is made for 
             * that occurrence. Meta data from the original event is copied across, 
             * unless its meta key exists in the filtered array.  
             * 
             * @param array $ignore_meta Array of meta keys to be ignored
             */
            $ignore_meta = apply_filters('eventorganiser_breaking_occurrence_exclude_meta', $ignore_meta);
            if (in_array($meta_key, $ignore_meta)) {
                continue;
            }
            //Don't copy event meta
            if (0 == strncmp($meta_key, '_eventorganiser', 15)) {
                continue;
            }
            foreach ($meta_values as $meta_value) {
                //get_post_meta() without a key doesn't unserialize:
                // @see{https://github.com/WordPress/WordPress/blob/3.5.1/wp-includes/meta.php#L289}
                $meta_value = maybe_unserialize($meta_value);
                add_post_meta($new_event_id, $meta_key, $meta_value);
            }
        }
    }
    _eventorganiser_delete_calendar_cache();
    /**
     * Triggered after an occurrence has been broken from an event.
     *
     * @param int $post_id The ID of the original parent event
     * @param int $occurrence_id The ID of the occurrence being broken
     * @param int $new_event_id The ID of the newly created event
     */
    do_action('eventorganiser_occurrence_broken', $post_id, $occurrence_id, $new_event_id);
    wp_reset_postdata();
    return $new_event_id;
}
function eo_has_event_finished($id = '', $occurrence = 0)
{
    $tz = eo_get_blog_timezone();
    $end = new DateTime(eo_get_the_end('d-m-Y H:i', $id, $occurrence), $tz);
    $now = new DateTime('now', $tz);
    return $end <= $now;
}
 /**
  * Get all Event Organiser dates for a given post ID
  *
  * @since 0.1
  *
  * @param int $post_id The numeric ID of the WP post
  * @return array $all_dates All dates for the post
  */
 public function get_all_dates($post_id)
 {
     // init dates
     $all_dates = array();
     // get all dates
     $all_event_dates = new WP_Query(array('post_type' => 'event', 'posts_per_page' => -1, 'event_series' => $post_id, 'group_events_by' => 'occurrence'));
     // if we have some
     if ($all_event_dates->have_posts()) {
         // loop through them
         while ($all_event_dates->have_posts()) {
             // get the post
             $all_event_dates->the_post();
             // access post
             global $post;
             // init
             $date = array();
             // add to our array, formatted for CiviCRM
             $date['occurrence_id'] = $post->occurrence_id;
             $date['start'] = eo_get_the_start('Y-m-d H:i:s');
             $date['end'] = eo_get_the_end('Y-m-d H:i:s');
             $date['human'] = eo_get_the_start('g:ia, M jS, Y');
             // add to our array
             $all_dates[] = $date;
         }
         // reset post data
         wp_reset_postdata();
     }
     // --<
     return $all_dates;
 }
/**
 * Break a specified occurrence from an event
 * 
 * @param int $post_id The event (post) ID
 * @param int $occurrence_id The occurrence ID
 * @return int|WP_Error The new event (post) ID or a WP_Error on error
 */
function eo_break_occurrence($post_id, $occurrence_id)
{
    global $post;
    $post = get_post($post_id);
    setup_postdata($post_id);
    do_action('eventorganiser_pre_break_occurrence', $post_id, $occurrence_id);
    $tax_input = array();
    foreach (array('event-category', 'event-tag', 'event-venue') as $tax) {
        $terms = get_the_terms($post->ID, $tax);
        if ($terms && !is_wp_error($terms)) {
            $tax_input[$tax] = array_map('intval', wp_list_pluck($terms, 'term_id'));
        }
    }
    //Post details
    $post_array = array('post_title' => $post->post_title, 'post_name' => $post->post_name, 'post_author' => $post->post_author, 'post_content' => $post->post_content, 'post_status' => $post->post_status, 'post_date' => $post->post_date, 'post_date_gmt' => $post->post_date_gmt, 'post_excerpt' => $post->post_excerpt, 'post_password' => $post->post_password, 'post_type' => 'event', 'tax_input' => $tax_input, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status);
    //Event details
    $event_array = array('start' => eo_get_the_start(DATETIMEOBJ, $post_id, null, $occurrence_id), 'end' => eo_get_the_end(DATETIMEOBJ, $post_id, null, $occurrence_id), 'all_day' => eo_is_all_day($post_id) ? 1 : 0, 'schedule' => 'once', 'frequency' => 1);
    //Create new event with duplicated details (new event clears cache)
    $new_event_id = eo_insert_event($post_array, $event_array);
    //delete occurrence, and copy post meta
    if ($new_event_id && !is_wp_error($new_event_id)) {
        $response = _eventorganiser_remove_occurrence($post_id, $occurrence_id);
        $post_custom = get_post_custom($post_id);
        foreach ($post_custom as $meta_key => $meta_values) {
            //Don't copy these
            $ignore_meta = array('_eventorganiser_uid', '_eo_tickets', '_edit_last', '_edit_last', '_edit_lock');
            $ignore_meta = apply_filters('eventorganiser_breaking_occurrence_exclude_meta', $ignore_meta);
            if (in_array($meta_key, $ignore_meta)) {
                continue;
            }
            //Don't copy event meta
            if (0 == strncmp($meta_key, '_eventorganiser', 15)) {
                continue;
            }
            foreach ($meta_values as $meta_value) {
                //get_post_meta() without a key doesn't unserialize:
                // @see{https://github.com/WordPress/WordPress/blob/3.5.1/wp-includes/meta.php#L289}
                $meta_value = maybe_unserialize($meta_value);
                add_post_meta($new_event_id, $meta_key, $meta_value);
            }
        }
    }
    _eventorganiser_delete_calendar_cache();
    do_action('eventorganiser_occurrence_broken', $post_id, $occurrence_id, $new_event_id);
    wp_reset_postdata();
    return $new_event_id;
}
/**
 * Callback for the delete expired events cron job. Deletes events that finished at least 24 hours ago.
 * For recurring events it is only deleted once the last occurrence has expired.
 *
 * @since 1.4.0
 * @ignore
 * @access private
 */
function eventorganiser_delete_expired_events()
{
    //Get expired events
    $events = eo_get_events(array('showrepeats' => 0, 'showpastevents' => 1, 'eo_interval' => 'expired'));
    /**
     * Filters how long (in seconds) after an event as finished it should be considered expired.
     * 
     * If enabled in *Settings > Event Organiser > General*, expired events are trashed.
     * 
     * @param int $time_until_expired Time (in seconds) to wait after an event has finished. Defaults to 24 hours. 
     */
    $time_until_expired = (int) apply_filters('eventorganiser_events_expire_time', 24 * 60 * 60);
    $time_until_expired = max($time_until_expired, 0);
    if ($events) {
        $now = new DateTime('now', eo_get_blog_timezone());
        foreach ($events as $event) {
            $start = eo_get_the_start(DATETIMEOBJ, $event->ID, null, $event->occurrence_id);
            $end = eo_get_the_end(DATETIMEOBJ, $event->ID, null, $event->occurrence_id);
            $expired = round(abs($end->format('U') - $start->format('U'))) + $time_until_expired;
            //Duration + expire time
            $finished = eo_get_schedule_last(DATETIMEOBJ, $event->ID);
            $finished->modify("+{$expired} seconds");
            //[Expired time] after the last occurrence finishes
            //Delete if [expired time] has passed
            if ($finished <= $now) {
                wp_trash_post((int) $event->ID);
            }
        }
    }
}