Пример #1
0
/**
* Returns an array with details of the event's reoccurences. 
* Note this is is identical to eo_get_reoccurrence() which corrects a spelling error.
*
* @param int Optional, the event (post) ID, 
* @since 1.0.0
* @deprecated 1.6
* @see eo_get_event_schedule()
*
* @param int $post_id Optional, the event (post) ID, 
* @return array Schedule information
*/
function eo_get_reoccurence($post_id = 0)
{
    _deprecated_function(__FUNCTION__, '1.5', 'eo_get_event_schedule()');
    $post_id = (int) (empty($post_id) ? get_the_ID() : $post_id);
    if (empty($post_id) || 'event' != get_post_type($post_id)) {
        return false;
    }
    $return = eo_get_event_schedule($post_id);
    if (!$return) {
        return false;
    }
    $return['reoccurrence'] = $return['schedule'];
    $return['meta'] = $return['schedule_meta'];
    $return['end'] = $return['schedule_last'];
    return $return;
}
Пример #2
0
/**
 * Saves the event data posted from the event metabox.
 * Hooked to the 'save_post' action
 * 
 * @since 1.0.0
 *
 * @param int $post_id the event post ID
 * @return int $post_id the event post ID
 */
function eventorganiser_details_save($post_id)
{
    //make sure data came from our meta box
    if (!isset($_POST['_eononce']) || !wp_verify_nonce($_POST['_eononce'], 'eventorganiser_event_update_' . $post_id . '_' . get_current_blog_id())) {
        return;
    }
    //verify this is not an auto save routine.
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    //authentication checks
    if (!current_user_can('edit_event', $post_id)) {
        return;
    }
    //Collect raw data
    $raw_data = isset($_POST['eo_input']) ? $_POST['eo_input'] : array();
    $raw_data = wp_parse_args($raw_data, array('StartDate' => '', 'EndDate' => '', 'StartTime' => '00:00', 'FinishTime' => '23:59', 'schedule' => 'once', 'event_frequency' => 1, 'schedule_end' => '', 'allday' => 0, 'schedule_meta' => '', 'days' => array(), 'include' => '', 'exclude' => ''));
    //Update venue
    $venue_id = !empty($raw_data['event-venue']) ? intval($raw_data['event-venue']) : null;
    //Maybe create a new venue
    if (empty($venue_id) && !empty($_POST['eo_venue']) && current_user_can('manage_venues')) {
        $venue = $_POST['eo_venue'];
        if (!empty($venue['name'])) {
            $new_venue = eo_insert_venue($venue['name'], $venue);
            if (!is_wp_error($new_venue)) {
                $venue_id = $new_venue['term_id'];
            } else {
                if ($new_venue->get_error_code() == 'term_exists') {
                    $venue_id = eo_get_venue($event_id);
                }
            }
        }
    }
    //Set venue
    $r = wp_set_post_terms($post_id, array($venue_id), 'event-venue', false);
    //If reocurring, but not editing occurrences, can abort here, but trigger hook.
    if (eo_reoccurs($post_id) && (!isset($raw_data['AlterRe']) || 'yes' != $raw_data['AlterRe'])) {
        /**
         * Triggered after an event has been updated.
         *
         * @param int $post_id The ID of the event
         */
        do_action('eventorganiser_save_event', $post_id);
        //Need this to update cache
        return;
    }
    //Check dates
    $date_format = eventorganiser_get_option('dateformat');
    $is24 = eventorganiser_blog_is_24();
    $time_format = $is24 ? 'H:i' : 'g:ia';
    $datetime_format = $date_format . ' ' . $time_format;
    //Set times for all day events
    $all_day = intval($raw_data['allday']);
    if ($all_day) {
        $raw_data['StartTime'] = $is24 ? '00:00' : '12:00am';
        $raw_data['FinishTime'] = $is24 ? '23:59' : '11:59pm';
    }
    $start = eo_check_datetime($datetime_format, trim($raw_data['StartDate']) . ' ' . trim($raw_data['StartTime']));
    $end = eo_check_datetime($datetime_format, trim($raw_data['EndDate']) . ' ' . trim($raw_data['FinishTime']));
    $until = eo_check_datetime($datetime_format, trim($raw_data['schedule_end']) . ' ' . trim($raw_data['StartTime']));
    //Collect schedule meta
    $schedule = $raw_data['schedule'];
    if ('weekly' == $schedule) {
        $schedule_meta = $raw_data['days'];
        $occurs_by = '';
    } elseif ('monthly' == $schedule) {
        $schedule_meta = $raw_data['schedule_meta'];
        $occurs_by = trim($schedule_meta, '=');
    } else {
        $schedule_meta = '';
        $occurs_by = '';
    }
    //Collect include/exclude
    $in_ex = array();
    $orig_schedule = eo_get_event_schedule($post_id);
    foreach (array('include', 'exclude') as $key) {
        $in_ex[$key] = array();
        $arr = explode(',', sanitize_text_field($raw_data[$key]));
        if (!empty($arr)) {
            foreach ($arr as $date) {
                if ($date_obj = eo_check_datetime('Y-m-d', trim($date))) {
                    $date_obj->setTime($start->format('H'), $start->format('i'));
                    $in_ex[$key][] = $date_obj;
                }
            }
            /* see https://github.com/stephenharris/Event-Organiser/issues/260
            			if( $orig = array_uintersect( $orig_schedule[$key], $in_ex[$key], '_eventorganiser_compare_dates' ) ){
            				$in_ex[$key] = array_merge( $orig, $in_ex[$key] );
            				$in_ex[$key] = _eventorganiser_remove_duplicates( $in_ex[$key] );
            			}*/
        }
    }
    $event_data = array('start' => $start, 'end' => $end, 'all_day' => $all_day, 'schedule' => $schedule, 'frequency' => (int) $raw_data['event_frequency'], 'until' => $until, 'schedule_meta' => $schedule_meta, 'occurs_by' => $occurs_by, 'include' => $in_ex['include'], 'exclude' => $in_ex['exclude']);
    $response = eo_update_event($post_id, $event_data);
    if (is_wp_error($response)) {
        global $EO_Errors;
        $code = $response->get_error_code();
        $message = $response->get_error_message($code);
        $errors[$post_id][] = __('Event dates were not saved.', 'eventorganiser');
        $errors[$post_id][] = $message;
        $EO_Errors->add('eo_error', $message);
        update_option('eo_notice', $errors);
    }
    return;
}
Пример #3
0
/**
 * Ajax response for the admin full calendar. 
 *
 * This gets events and generates summaries for events to be displayed.
 * in the admin 'calendar view'. 
 * Applies 'eventorganiser_admin_cal_summary' to event summary
 * Applies eventorganiser_admin_calendar to the event array
 *
 *@since 1.0
 *@access private
 *@ignore
*/
function eventorganiser_admin_calendar()
{
    //request
    $request = array('event_end_after' => $_GET['start'], 'event_start_before' => $_GET['end']);
    //Presets
    $presets = array('posts_per_page' => -1, 'post_type' => 'event', 'group_events_by' => '', 'perm' => 'readable');
    $calendar = get_transient('eo_full_calendar_admin');
    $key = $_GET['start'] . '--' . $_GET['end'] . 'u=' . get_current_user_id();
    if ((!defined('WP_DEBUG') || !WP_DEBUG) && $calendar && is_array($calendar) && isset($calendar[$key])) {
        echo json_encode($calendar[$key]);
        exit;
    }
    //Create query
    $query_array = array_merge($presets, $request);
    $query = new WP_Query($query_array);
    //Retrieve events
    $query->get_posts();
    $eventsarray = array();
    //Blog timezone
    $tz = eo_get_blog_timezone();
    //Loop through events
    global $post;
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            $event = array();
            $colour = '';
            //Get title, append status if applicable
            $title = get_the_title();
            if (!empty($post->post_password)) {
                $title .= ' - ' . __('Protected');
            } elseif ($post->post_status == 'private') {
                $title .= ' - ' . __('Private');
            } elseif ($post->post_status == 'draft') {
                $title .= ' - ' . __('Draft');
            }
            $event['title'] = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
            $event['event_id'] = $post->ID;
            $event['occurrence_id'] = $post->occurrence_id;
            $schedule = eo_get_event_schedule($post->ID);
            //Check if all day, set format accordingly
            if ($schedule['all_day']) {
                $event['allDay'] = true;
                $format = get_option('date_format');
            } else {
                $event['allDay'] = false;
                $format = get_option('date_format') . '  ' . get_option('time_format');
            }
            //Get author (or organiser)
            $organiser = get_userdata($post->post_author)->display_name;
            //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\\Z');
            $event['end'] = $event_end->format('Y-m-d\\TH:i:s\\Z');
            //Produce summary of event
            $summary = "<table class='form-table' >" . "<tr><th> " . __('Start', 'eventorganiser') . ": </th><td> " . eo_format_datetime($event_start, $format) . "</td></tr>" . "<tr><th> " . __('End', 'eventorganiser') . ": </th><td> " . eo_format_datetime($event_end, $format) . "</td></tr>";
            if (eo_is_multi_event_organiser()) {
                $summary .= "<tr><th> " . __('Organiser', 'eventorganiser') . ": </th><td>" . $organiser . "</td></tr>";
            }
            $event['className'] = array('event');
            $now = new DateTime(null, $tz);
            if ($event_start <= $now) {
                $event['className'][] = 'past-event';
            }
            //Include venue if this is set
            $venue = eo_get_venue($post->ID);
            if ($venue && !is_wp_error($venue)) {
                $summary .= "<tr><th>" . __('Where', 'eventorganiser') . ": </th><td>" . eo_get_venue_name($venue) . "</td></tr>";
                $event['className'][] = 'venue-' . eo_get_venue_slug($post->ID);
                $event['venue'] = $venue;
            }
            /**
             * Filters the summary of the event as it appears in the admin 
             * calendar's modal.
             *
             * **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 admin-calendar
             * @param string  $summary       The event (admin) summary,
             * @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.
             */
            $summary = apply_filters('eventorganiser_admin_cal_summary', $summary, $post->ID, $post->occurrence_id, $post);
            $summary .= "</table><p>";
            //Include schedule summary if event reoccurrs
            if ($schedule['schedule'] != 'once') {
                $summary .= '<em>' . __('This event reoccurs', 'eventorganiser') . ' ' . eo_get_schedule_summary() . '</em>';
            }
            $summary .= '</p>';
            //Include edit link in summary if user has permission
            if (current_user_can('edit_event', $post->ID)) {
                $edit_link = get_edit_post_link($post->ID, '');
                $summary .= "<span class='edit'><a title='Edit this item' href='" . $edit_link . "'> " . __('Edit Event', 'eventorganiser') . "</a></span>";
                $event['url'] = $edit_link;
            }
            //Include a delete occurrence link in summary if user has permission
            if (current_user_can('delete_event', $post->ID)) {
                $admin_url = admin_url('edit.php');
                $delete_url = add_query_arg(array('post_type' => 'event', 'page' => 'calendar', 'series' => $post->ID, 'event' => $post->occurrence_id, 'action' => 'delete_occurrence'), $admin_url);
                $delete_url = wp_nonce_url($delete_url, 'eventorganiser_delete_occurrence_' . $post->occurrence_id);
                $summary .= sprintf('<span class="delete"><a class="submitdelete" style="color:red;float:right" title="%1$s" href="%2$s">%1$s</a></span>', esc_attr__('Delete this occurrence', 'eventorganiser'), $delete_url);
                if ($schedule['schedule'] != 'once') {
                    $break_url = add_query_arg(array('post_type' => 'event', 'page' => 'calendar', 'series' => $post->ID, 'event' => $post->occurrence_id, 'action' => 'break_series'), $admin_url);
                    $break_url = wp_nonce_url($break_url, 'eventorganiser_break_series_' . $post->occurrence_id);
                    $summary .= sprintf('<span class="break"><a class="submitbreak" style="color:red;float:right;padding-right:2em;" title="%1$s" href="%2$s">%1$s</a></span>', esc_attr__('Break this series', 'eventorganiser'), $break_url);
                }
            }
            //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;
                }
            }
            //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']) ? eo_get_event_textcolor($event['color']) : '#ffffff';
            }
            //Event summary
            $event['summary'] = '<div id="eo-cal-meta">' . $summary . '</div>';
            //Filter the event array
            /**
             * @ignore
             */
            $event = apply_filters('eventorganiser_admin_calendar', $event, $post);
            /**
             * Filters the event before its sent to 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.
             * 
             * @package admin-calendar
             * @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_admin_fullcalendar_event', $event, $post->ID, $post->occurrence_id);
            //Add event to array
            $eventsarray[] = $event;
        }
    }
    if (!$calendar || !is_array($calendar)) {
        $calendar = array();
    }
    $calendar[$key] = $eventsarray;
    set_transient('eo_full_calendar_admin', $calendar, 60 * 60 * 24);
    //Echo result and exit
    echo json_encode($eventsarray);
    exit;
}
Пример #4
0
 function testEventSchedule()
 {
     $tz = eo_get_blog_timezone();
     $start = new DateTime('2014-06-17 14:45:00', $tz);
     $end = new DateTime('2014-06-17 15:45:00', $tz);
     $inc = array(new DateTime('2014-08-16 14:45:00', $tz));
     $exc = array(new DateTime('2014-06-19 14:45:00', $tz), new DateTime('2014-07-03 14:45:00', $tz));
     $event = array('start' => $start, 'end' => $end, 'frequency' => 2, 'schedule' => 'weekly', 'schedule_meta' => array('TU', 'TH'), 'include' => $inc, 'exclude' => $exc, 'schedule_last' => new DateTime('2014-08-15 14:45:00', $tz));
     $event_id = $this->factory->event->create($event);
     $schedule = eo_get_event_schedule($event_id);
     $this->assertEquals($start, $schedule['start']);
     $this->assertEquals($end, $schedule['end']);
     $this->assertEquals(false, $schedule['all_day']);
     $this->assertEquals('weekly', $schedule['schedule']);
     $this->assertEquals(array('TU', 'TH'), $schedule['schedule_meta']);
     $this->assertEquals(2, $schedule['frequency']);
     $duration = eo_date_interval($start, $end, '+%y year +%m month +%d days +%h hours +%i minutes +%s seconds');
     $schedule_last = new DateTime('2014-08-16 14:45:00', $tz);
     $schedule_finish = clone $schedule_last;
     $schedule_finish->modify($duration);
     $this->assertEquals($start, $schedule['schedule_start']);
     $this->assertEquals($schedule_last, $schedule['schedule_last']);
     $this->assertEquals($schedule_finish, $schedule['schedule_finish']);
     $this->assertEquals($inc, $schedule['include']);
     $this->assertEquals($exc, $schedule['exclude']);
     $occurrences = array(new DateTime('2014-06-17 14:45:00', $tz), new DateTime('2014-07-01 14:45:00', $tz), new DateTime('2014-07-15 14:45:00', $tz), new DateTime('2014-07-17 14:45:00', $tz), new DateTime('2014-07-29 14:45:00', $tz), new DateTime('2014-07-31 14:45:00', $tz), new DateTime('2014-08-12 14:45:00', $tz), new DateTime('2014-08-14 14:45:00', $tz), new DateTime('2014-08-16 14:45:00', $tz));
     $this->assertEquals($occurrences, array_values($schedule['_occurrences']));
 }
Пример #5
0
 /**
  * Check that the 'until' date is unaffected by included events.
  * Note until != schedule_last (see https://github.com/stephenharris/Event-Organiser/issues/259). 
  */
 public function testUntil()
 {
     $tz = eo_get_blog_timezone();
     $include = new DateTime('2015-05-23 15:30:00', $tz);
     $until = new DateTime('2015-05-09 15:30:00', $tz);
     $event = array('start' => new DateTime('2015-04-18 15:30:00', $tz), 'end' => new DateTime('2015-04-18 15:45:00', $tz), 'frequeny' => 1, 'schedule' => 'weekly', 'until' => $until, 'include' => array($include));
     //Create event and store occurrences
     $event_id = eo_insert_event($event);
     $schedule = eo_get_event_schedule($event_id);
     $this->assertEquals($include, eo_get_schedule_last(DATETIMEOBJ, $event_id));
     $this->assertEquals($include, $schedule['schedule_last']);
     $this->assertEquals($until, $schedule['until']);
 }
Пример #6
0
/**
 * Updates a specific occurrence, and preserves the occurrence ID. 
 * 
 * Currently two occurrences cannot occupy the same date.
 * 
 * @ignore
 * @access private
 * @since 2.12.0
 * 
 * @param int $event_id      ID of the event whose occurrence we're moving
 * @param int $occurrence_id ID of the occurrence we're moving
 * @param DateTime $start    New start DateTime of the occurrence
 * @param DateTime $end      New end DateTime of the occurrence
 * @return bool|WP_Error True on success. WP_Error on failure.
 */
function eventorganiser_move_occurrence($event_id, $occurrence_id, $start, $end)
{
    global $wpdb;
    $old_start = eo_get_the_start(DATETIMEOBJ, $event_id, null, $occurrence_id);
    $schedule = eo_get_event_schedule($event_id);
    if ($start == $old_start) {
        return true;
    }
    $current_occurrences = eo_get_the_occurrences($event_id);
    unset($current_occurrences[$occurrence_id]);
    $current_occurrences = array_map('eo_format_datetime', $current_occurrences);
    if (in_array($start->format('d-m-Y'), $current_occurrences)) {
        return new WP_Error('events-cannot-share-date', __('There is already an occurrence on this date', 'eventorganiser'));
    }
    //We update the date directly in the DB first so the occurrence is not deleted and recreated,
    //but simply updated.
    $wpdb->update($wpdb->eo_events, array('StartDate' => $start->format('Y-m-d'), 'StartTime' => $start->format('H:i:s'), 'EndDate' => $end->format('Y-m-d'), 'FinishTime' => $end->format('H:i:s')), array('event_id' => $occurrence_id));
    wp_cache_delete('eventorganiser_occurrences_' . $event_id);
    //Important: update DB clear cache
    //Now update event schedule...
    //If date being removed was manually included remove it,
    //otherwise add it to exclude. Then add new date as include.
    if (false === ($index = array_search($old_start, $schedule['include']))) {
        $schedule['exclude'][] = $old_start;
    } else {
        unset($schedule['include'][$index]);
    }
    $schedule['include'][] = $start;
    $re = eo_update_event($event_id, $schedule);
    if ($re && !is_wp_error($re)) {
        return true;
    }
    return $re;
}
Пример #7
0
 public function testScheduleLastUpdate()
 {
     $event_data = array('start' => new DateTime('2013-10-22 19:19:00', eo_get_blog_timezone()), 'end' => new DateTime('2013-10-22 20:19:00', eo_get_blog_timezone()), 'schedule' => 'daily', 'frequency' => 2, 'until' => new DateTime('2013-10-26 19:19:00', eo_get_blog_timezone()));
     $event = eo_insert_event($event_data);
     eo_update_event($event, array('include' => array(new DateTime('2013-10-25 19:19:00', eo_get_blog_timezone()))));
     $schedule = eo_get_event_schedule($event);
     $this->assertEquals(new DateTime('2013-10-26 19:19:00', eo_get_blog_timezone()), $schedule['until']);
 }
Пример #8
0
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);
        }
        // Generate Event status
        if (get_post_status(get_the_ID()) == 'publish') {
/**
* Returns a summary of the events schedule.
* @since 1.0.0
* @ignore
*
* @param int $post_id The event (post) ID. Uses current event if empty.
* @return string A summary of the events schedule.
*/
function eo_get_schedule_summary($post_id = 0)
{
    global $post, $wp_locale;
    $ical2day = array('SU' => $wp_locale->weekday[0], 'MO' => $wp_locale->weekday[1], 'TU' => $wp_locale->weekday[2], 'WE' => $wp_locale->weekday[3], 'TH' => $wp_locale->weekday[4], 'FR' => $wp_locale->weekday[5], 'SA' => $wp_locale->weekday[6]);
    $nth = array(__('last', 'eventorganiser'), '', __('first', 'eventorganiser'), __('second', 'eventorganiser'), __('third', 'eventorganiser'), __('fourth', 'eventorganiser'));
    $reoccur = eo_get_event_schedule($post_id);
    if (empty($reoccur)) {
        return false;
    }
    $return = '';
    if ($reoccur['schedule'] == 'once') {
        $return = __('one time only', 'eventorganiser');
    } elseif ($reoccur['schedule'] == 'custom') {
        $return = __('custom reoccurrence', 'eventorganiser');
    } else {
        switch ($reoccur['schedule']) {
            case 'daily':
                if ($reoccur['frequency'] == 1) {
                    $return .= __('every day', 'eventorganiser');
                } else {
                    $return .= sprintf(__('every %d days', 'eventorganiser'), $reoccur['frequency']);
                }
                break;
            case 'weekly':
                if ($reoccur['frequency'] == 1) {
                    $return .= __('every week on', 'eventorganiser');
                } else {
                    $return .= sprintf(__('every %d weeks on', 'eventorganiser'), $reoccur['frequency']);
                }
                foreach ($reoccur['schedule_meta'] as $ical_day) {
                    $days[] = $ical2day[$ical_day];
                }
                $return .= ' ' . implode(', ', $days);
                break;
            case 'monthly':
                if ($reoccur['frequency'] == 1) {
                    $return .= __('every month on the', 'eventorganiser');
                } else {
                    $return .= sprintf(__('every %d months on the', 'eventorganiser'), $reoccur['frequency']);
                }
                $return .= ' ';
                $bymonthday = preg_match('/^BYMONTHDAY=(\\d{1,2})/', $reoccur['schedule_meta'], $matches);
                if ($bymonthday) {
                    $d = intval($matches[1]);
                    $m = intval($reoccur['schedule_start']->format('n'));
                    $y = intval($reoccur['schedule_start']->format('Y'));
                    $reoccur['start']->setDate($y, $m, $d);
                    $return .= $reoccur['schedule_start']->format('jS');
                } elseif ($reoccur['schedule_meta'] == 'date') {
                    $return .= $reoccur['schedule_start']->format('jS');
                } else {
                    $byday = preg_match('/^BYDAY=(-?\\d{1,2})([a-zA-Z]{2})/', $reoccur['schedule_meta'], $matches);
                    if ($byday) {
                        $n = intval($matches[1]) + 1;
                        $return .= $nth[$n] . ' ' . $ical2day[$matches[2]];
                    } else {
                        $bydayOLD = preg_match('/^(-?\\d{1,2})([a-zA-Z]{2})/', $reoccur['schedule_meta'], $matchesOLD);
                        $n = intval($matchesOLD[1]) + 1;
                        $return .= $nth[$n] . ' ' . $ical2day[$matchesOLD[2]];
                    }
                }
                break;
            case 'yearly':
                if ($reoccur['frequency'] == 1) {
                    $return .= __('every year', 'eventorganiser');
                } else {
                    $return .= sprintf(__('every %d years', 'eventorganiser'), $reoccur['frequency']);
                }
                break;
        }
        $return .= ' ' . __('until', 'eventorganiser') . ' ' . eo_format_datetime($reoccur['schedule_last'], 'M, jS Y');
    }
    return $return;
}
 /**
  * Get all Event Organiser date objects 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, keyed by ID
  */
 public function get_date_objects($post_id)
 {
     // get schedule
     $schedule = eo_get_event_schedule($post_id);
     // if we have some dates
     if (isset($schedule['_occurrences']) and count($schedule['_occurrences']) > 0) {
         // --<
         return $schedule['_occurrences'];
     }
     // --<
     return array();
 }
Пример #11
0
/**
* Sets up the event data metabox
* This allows user to enter date / time, reoccurrence and venue data for the event
* @ignore
* @since 1.0.0
*/
function _eventorganiser_details_metabox($post)
{
    global $wp_locale;
    //Sets the format as php understands it, and textual.
    $phpFormat = eventorganiser_get_option('dateformat');
    if ('d-m-Y' == $phpFormat) {
        $format = 'dd-mm-yyyy';
        //Human form
    } elseif ('Y-m-d' == $phpFormat) {
        $format = 'yyyy-mm-dd';
        //Human form
    } else {
        $format = 'mm-dd-yyyy';
        //Human form
    }
    $is24 = eventorganiser_blog_is_24();
    $time_format = $is24 ? 'H:i' : 'g:ia';
    //Get the starting day of the week
    $start_day = intval(get_option('start_of_week'));
    $ical_days = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
    //Retrieve event details
    extract(eo_get_event_schedule($post->ID));
    $venues = eo_get_venues();
    $venue_id = (int) eo_get_venue($post->ID);
    //$sche_once is used to disable date editing unless the user specifically requests it.
    //But a new event might be recurring (via filter), and we don't want to 'lock' new events.
    //See http://wordpress.org/support/topic/wrong-default-in-input-element
    $sche_once = $schedule == 'once' || !empty(get_current_screen()->action);
    if (!$sche_once) {
        $notices = '<strong>' . __('This is a reoccurring event', 'eventorganiser') . '</strong>. ' . __('Check to edit this event and its reoccurrences', 'eventorganiser') . ' <input type="checkbox" id="HWSEvent_rec" name="eo_input[AlterRe]" value="yes">';
    } else {
        $notices = '';
    }
    //Start of meta box
    if ($notices = apply_filters('eventorganiser_event_metabox_notice', $notices, $post)) {
        echo '<div class="updated below-h2"><p>' . $notices . '</p></div>';
    }
    ?>
	<div class="<?php 
    echo $sche_once ? 'onetime' : 'reoccurence';
    ?>
">
		<p><?php 
    printf(__('Ensure dates are entered in %1$s format and times in %2$s (24 hour) format', 'eventorganiser'), '<strong>' . $format . '</strong>', ' <strong>hh:mm</strong>');
    ?>
 </p>

		<table id="eventorganiser_event_detail" class="form-table">
				<tr valign="top"  class="event-date">
					<td class="eo-label"><?php 
    echo __('Start Date/Time', 'eventorganiser') . ':';
    ?>
 </td>
					<td> 
						<input class="ui-widget-content ui-corner-all" name="eo_input[StartDate]" size="10" maxlength="10" id="from_date" <?php 
    disabled(!$sche_once);
    ?>
 value="<?php 
    echo $start->format($phpFormat);
    ?>
"/>
						<?php 
    printf('<input name="eo_input[StartTime]" class="eo_time ui-widget-content ui-corner-all" size="6" maxlength="8" id="HWSEvent_time" %s value="%s"/>', disabled(!$sche_once || $all_day, true, false), eo_format_datetime($start, $time_format));
    ?>
						

					</td>
				</tr>

				<tr valign="top"  class="event-date">
					<td class="eo-label"><?php 
    echo __('End Date/Time', 'eventorganiser') . ':';
    ?>
 </td>
					<td> 
						<input class="ui-widget-content ui-corner-all" name="eo_input[EndDate]" size="10" maxlength="10" id="to_date" <?php 
    disabled(!$sche_once);
    ?>
  value="<?php 
    echo $end->format($phpFormat);
    ?>
"/>
					
						<?php 
    printf('<input name="eo_input[FinishTime]" class="eo_time ui-widget-content ui-corner-all" size="6" maxlength="8" id="HWSEvent_time2" %s value="%s"/>', disabled(!$sche_once || $all_day, true, false), eo_format_datetime($end, $time_format));
    ?>
	

					<label>
					<input type="checkbox" id="eo_allday"  <?php 
    checked($all_day);
    ?>
 name="eo_input[allday]"  <?php 
    disabled(!$sche_once);
    ?>
 value="1"/>
						<?php 
    _e('All day', 'eventorganiser');
    ?>
					 </label>
			
					</td>
				</tr>

				<tr class="event-date">
					<td class="eo-label"><?php 
    _e('Reoccurence:', 'eventorganiser');
    ?>
 </td>
					<td> 
					<?php 
    $reoccurrence_schedules = array('once' => __('once', 'eventorganiser'), 'daily' => __('daily', 'eventorganiser'), 'weekly' => __('weekly', 'eventorganiser'), 'monthly' => __('monthly', 'eventorganiser'), 'yearly' => __('yearly', 'eventorganiser'), 'custom' => __('custom', 'eventorganiser'));
    ?>

					<select id="HWSEventInput_Req" name="eo_input[schedule]">
						<?php 
    foreach ($reoccurrence_schedules as $index => $val) {
        ?>
							<option value="<?php 
        echo $index;
        ?>
" <?php 
        selected($schedule, $index);
        ?>
><?php 
        echo $val;
        ?>
</option>
						<?php 
    }
    //End foreach $allowed_reoccurs
    ?>
					</select>
					</td>
				</tr>

				<tr valign="top"  class="event-date reocurrence_row">
					<td></td>
					<td>
						<p><?php 
    _e('Repeat every', 'eventorganiser');
    ?>
 
						<input <?php 
    disabled(!$sche_once || $all_day);
    ?>
 class="ui-widget-content ui-corner-all" name="eo_input[event_frequency]" id="HWSEvent_freq" type="number" min="1" max="365" maxlength="4" size="4" disabled="disabled" value="<?php 
    echo $frequency;
    ?>
" /> 
						<span id="recpan" >  </span>				
						</p>

						<p id="dayofweekrepeat">
						<?php 
    _e('on', 'eventorganiser');
    ?>
	
						<?php 
    for ($i = 0; $i <= 6; $i++) {
        $d = ($start_day + $i) % 7;
        $ical_d = $ical_days[$d];
        $day = $wp_locale->weekday_abbrev[$wp_locale->weekday[$d]];
        $schedule_days = is_array($schedule_meta) ? $schedule_meta : array();
        ?>
							<input type="checkbox" id="day-<?php 
        echo $day;
        ?>
"  <?php 
        checked(in_array($ical_d, $schedule_days), true);
        ?>
  value="<?php 
        echo esc_attr($ical_d);
        ?>
" class="daysofweek" name="eo_input[days][]" disabled="disabled" />
							<label for="day-<?php 
        echo $day;
        ?>
" > <?php 
        echo $day;
        ?>
</label>
						<?php 
    }
    ?>
						</p>

						<p id="dayofmonthrepeat">
						<label for="bymonthday" >	
							<input type="radio" id="bymonthday" disabled="disabled" name="eo_input[schedule_meta]" <?php 
    checked($occurs_by, 'BYMONTHDAY');
    ?>
 value="BYMONTHDAY=" /> 
							<?php 
    _e('day of month', 'eventorganiser');
    ?>
						</label>
						<label for="byday" >
							<input type="radio" id="byday" disabled="disabled" name="eo_input[schedule_meta]"  <?php 
    checked($occurs_by != 'BYMONTHDAY', true);
    ?>
 value="BYDAY=" /> 
							<?php 
    _e('day of week', 'eventorganiser');
    ?>
						</label>
						</p>

						<p class="reoccurrence_label">
						<?php 
    _e('until', 'eventorganiser');
    ?>
 
						<input <?php 
    disabled(!$sche_once || $all_day);
    ?>
 class="ui-widget-content ui-corner-all" name="eo_input[schedule_end]" id="recend" size="10" maxlength="10" disabled="disabled" value="<?php 
    echo $schedule_last->format($phpFormat);
    ?>
"/>
						</p>

						<p id="event_summary"> </p>
					</td>
				</tr>

				<tr valign="top" id="eo_occurrence_picker_row" class="event-date">
					<td class="eo-label">	
						<?php 
    esc_html_e('Include/Exclude occurrences', 'eventorganiser');
    ?>
					</td>
					<td>
						<?php 
    submit_button(__('Show dates', 'eventorganiser'), 'hide-if-no-js eo_occurrence_toggle button small', 'eo_date_toggle', false);
    ?>
						
						<div id="eo_occurrence_datepicker"></div>
						<?php 
    //var_dump($include);
    if (!empty($include)) {
        $include_str = array_map('eo_format_datetime', $include, array_fill(0, count($include), 'Y-m-d'));
        $include_str = esc_textarea(sanitize_text_field(implode(',', $include_str)));
    } else {
        $include_str = '';
    }
    ?>
						<textarea style="display:none;" name="eo_input[include]" id="eo_occurrence_includes"><?php 
    echo $include_str;
    ?>
</textarea>

						<?php 
    if (!empty($exclude)) {
        $exclude_str = array_map('eo_format_datetime', $exclude, array_fill(0, count($exclude), 'Y-m-d'));
        $exclude_str = esc_textarea(sanitize_text_field(implode(',', $exclude_str)));
    } else {
        $exclude_str = '';
    }
    ?>
						<textarea style="display:none;" name="eo_input[exclude]" id="eo_occurrence_excludes"><?php 
    echo $exclude_str;
    ?>
</textarea>

					</td>
				</tr>
				<tr valign="top" class="eo-venue-combobox-select">
					<td class="eo-label"> <?php 
    _e('Venue', 'eventorganiser');
    ?>
: </td>
					<td> 	
						<select size="50" id="venue_select" name="eo_input[event-venue]">
							<option><?php 
    _e('Select a venue', 'eventorganiser');
    ?>
</option>
							<?php 
    foreach ($venues as $venue) {
        ?>
								<option <?php 
        selected($venue->term_id, $venue_id);
        ?>
 value="<?php 
        echo intval($venue->term_id);
        ?>
"><?php 
        echo esc_html($venue->name);
        ?>
</option>
							<?php 
    }
    ?>
						</select>
					</td>
				</tr>
		
				<!-- Add New Venue --> 
				<tr valign="top" class="eo-add-new-venue">
					<td class="eo-label"><label><?php 
    _e('Venue Name', 'eventorganiser');
    ?>
:</label></td>
					<td><input type="text" name="eo_venue[name]" id="eo_venue_name"  value=""/></td>
				</tr>
			<?php 
    $address_fields = _eventorganiser_get_venue_address_fields();
    foreach ($address_fields as $key => $label) {
        printf('<tr valign="top" class="eo-add-new-venue">
								<td class="eo-label"><label>%1$s:</label></td>
								<td><input type="text" name="eo_venue[%2$s]" class="eo_addressInput" id="eo_venue_add"  value=""/></td>
							</tr>', $label, esc_attr(trim($key, '_')));
    }
    ?>
				<tr valign="top" class="eo-add-new-venue" >
					<td class="eo-label"></td>
					<td>
						<a class="button eo-add-new-venue-cancel" href="#"><?php 
    esc_html_e('Cancel', 'eventorganiser');
    ?>
 </a>
					</td>
				</tr>

				<!-- Venue Map --> 
				<tr valign="top"  class="venue_row <?php 
    if (!$venue_id) {
        echo 'novenue';
    }
    ?>
" >
					<td class="eo-label"></td>
					<td>
						<div id="eventorganiser_venue_meta" style="display:none;">
							<input type="hidden" id="eo_venue_Lat" name="eo_venue[latitude]" value="<?php 
    eo_venue_lat($venue_id);
    ?>
" />
							<input type="hidden" id="eo_venue_Lng" name="eo_venue[longtitude]" value="<?php 
    eo_venue_lng($venue_id);
    ?>
" />
						</div>
						<div id="venuemap" class="ui-widget-content ui-corner-all gmap3"></div>
						<div class="clear"></div>
					</td>
				</tr>
			</table>
		</div>
	<?php 
    // create a custom nonce for submit verification later
    wp_nonce_field('eventorganiser_event_update_' . get_the_ID(), '_eononce');
}
Пример #12
0
/**
 * Generates the ICS RRULE fromthe event schedule data. 
 * @access private
 * @ignore
 * @since 1.0.0
 * @package ical-functions
 *
 * @param int $post_id The event (post) ID. Uses current event if empty.
 * @return string The RRULE to be used in an ICS calendar
 */
function eventorganiser_generate_ics_rrule($post_id = 0)
{
    $post_id = (int) (empty($post_id) ? get_the_ID() : $post_id);
    $rrule = eo_get_event_schedule($post_id);
    if (!$rrule) {
        return false;
    }
    extract($rrule);
    $schedule_last->setTimezone(new DateTimeZone('UTC'));
    $schedule_last = $schedule_last->format('Ymd\\THis\\Z');
    switch ($schedule) {
        case 'once':
            return false;
        case 'yearly':
            return "FREQ=YEARLY;INTERVAL=" . $frequency . ";UNTIL=" . $schedule_last;
        case 'monthly':
            //TODO Account for possible day shifts with timezone set to UTC
            $reoccurrence_rule = "FREQ=MONTHLY;INTERVAL=" . $frequency . ";";
            $reoccurrence_rule .= $schedule_meta . ";";
            $reoccurrence_rule .= "UNTIL=" . $schedule_last;
            return $reoccurrence_rule;
        case 'weekly':
            if (!eo_is_all_day($post_id)) {
                //None all day event, setting event timezone to UTC may cause it to shift days.
                //E.g. a 9pm Monday event in New York will a Tuesday event in UTC.
                //We may need to correct the BYDAY attribute to be valid for UTC.
                $days_of_week = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
                $UTC = new DateTimeZone('UTC');
                //Get day shift upon timezone set to UTC
                $start = eo_get_schedule_start(DATETIMEOBJ, $post_id);
                $local_day = (int) $start->format('w');
                $start->setTimezone($UTC);
                $utc_day = (int) $start->format('w');
                $diff = $utc_day - $local_day + 7;
                //ensure difference is positive (should be 0, +1 or +6).
                //If there is a shift correct BYDAY
                if ($diff) {
                    $utc_days = array();
                    foreach ($schedule_meta as $day) {
                        $utc_day_index = (array_search($day, $days_of_week) + $diff) % 7;
                        $utc_days[] = $days_of_week[$utc_day_index];
                    }
                    $schedule_meta = $utc_days;
                }
            }
            return "FREQ=WEEKLY;INTERVAL=" . $frequency . ";BYDAY=" . implode(',', $schedule_meta) . ";UNTIL=" . $schedule_last;
        case 'daily':
            return "FREQ=DAILY;INTERVAL=" . $frequency . ";UNTIL=" . $schedule_last;
        default:
    }
    return false;
}