예제 #1
0
/**
* Returns the colour of a category associated with the event
* @since 1.3.3
* @deprecated 1.6
* @see eo_get_event_color()
*
* @param int $post_id The event (post) ID
* @return string The colour of the category in HEX format
*/
function eo_event_color($post_id = 0)
{
    _deprecated_function(__FUNCTION__, '1.6', 'eo_get_event_color()');
    return eo_get_event_color($post_id);
}
예제 #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;
}
예제 #3
0
/**
 * Ajax response for the agenda widget
*
 * This gets the month being viewed and generates the
 *
 *@since 1.0
 *@access private
 *@ignore
*/
function eventorganiser_widget_agenda()
{
    global $wpdb;
    $number = (int) $_GET['instance_number'];
    $wid = new EO_Events_Agenda_Widget();
    $settings = $wid->get_settings();
    $instance = $settings[$number];
    $today = new DateTime('now', eo_get_blog_timezone());
    $query = array();
    $return_array = array();
    $query['mode'] = !empty($instance['mode']) ? $instance['mode'] : 'day';
    $query['direction'] = intval($_GET['direction']);
    $query['date'] = $query['direction'] < 1 ? $_GET['start'] : $_GET['end'];
    $query['order'] = $query['direction'] < 1 ? 'DESC' : 'ASC';
    $key = 'eo_ag_' . md5(serialize($query)) . get_locale();
    $agenda = get_transient('eo_widget_agenda');
    if ($agenda && is_array($agenda) && isset($agenda[$key])) {
        echo json_encode($agenda[$key]);
        exit;
    }
    if ('day' == $query['mode']) {
        //Day mode
        $selectDates = "SELECT DISTINCT StartDate FROM {$wpdb->eo_events}";
        $whereDates = " WHERE {$wpdb->eo_events}.StartDate" . ($query['order'] == 'ASC' ? " >= " : " <= ") . "%s ";
        $whereDates .= " AND {$wpdb->eo_events}.StartDate >= %s ";
        $orderlimit = "ORDER BY  {$wpdb->eo_events}.StartDate {$query['order']} LIMIT 4";
        $dates = $wpdb->get_col($wpdb->prepare($selectDates . $whereDates . $orderlimit, $query['date'], $today->format('Y-m-d')));
        if (!$dates) {
            return false;
        }
        $query['date1'] = min($dates[0], $dates[count($dates) - 1]);
        $query['date2'] = max($dates[0], $dates[count($dates) - 1]);
    } elseif ('week' == $query['mode']) {
        //Week mode - find the week of the next/previous event
        $selectDates = "SELECT DISTINCT StartDate FROM {$wpdb->eo_events}";
        $whereDates = " WHERE {$wpdb->eo_events}.StartDate" . ($query['order'] == 'ASC' ? " > " : " < ") . "%s ";
        $whereDates .= " AND {$wpdb->eo_events}.StartDate >= %s ";
        $orderlimit = "ORDER BY  {$wpdb->eo_events}.StartDate {$query['order']} LIMIT 1";
        $date = $wpdb->get_row($wpdb->prepare($selectDates . $whereDates . $orderlimit, $query['date'], $today->format('Y-m-d')));
        if (!$date) {
            return false;
        }
        $datetime = new DateTime($date->StartDate, eo_get_blog_timezone());
        //Get the week day, and the start of the week
        $week_start_day = (int) get_option('start_of_week');
        $event_day = (int) $datetime->format('w');
        $offset_from_week_start = ($event_day - $week_start_day + 7) % 7;
        $week_start_date = clone $datetime;
        $week_start_date->modify('- ' . $offset_from_week_start . ' days');
        $week_end_date = clone $week_start_date;
        $week_end_date->modify('+6 days');
        //Query is inclusive.
        $query['date1'] = $week_start_date->format('Y-m-d');
        $query['date2'] = $week_end_date->format('Y-m-d');
    } else {
        //Month mode - find the month of the next date
        $selectDates = "SELECT DISTINCT StartDate FROM {$wpdb->eo_events}";
        $whereDates = " WHERE {$wpdb->eo_events}.StartDate" . ($query['order'] == 'ASC' ? " > " : " < ") . "%s ";
        $whereDates .= " AND {$wpdb->eo_events}.StartDate >= %s ";
        $orderlimit = "ORDER BY  {$wpdb->eo_events}.StartDate {$query['order']} LIMIT 1";
        $date = $wpdb->get_row($wpdb->prepare($selectDates . $whereDates . $orderlimit, $query['date'], $today->format('Y-m-d')));
        if (!$date) {
            return false;
        }
        $datetime = new DateTime($date->StartDate, eo_get_blog_timezone());
        $query['date1'] = $datetime->format('Y-m-01');
        $query['date2'] = $datetime->format('Y-m-t');
    }
    $events = eo_get_events(array('event_start_after' => $query['date1'], 'event_start_before' => $query['date2']));
    global $post;
    foreach ($events as $post) {
        $return_array[] = array('StartDate' => $post->StartDate, 'display' => eo_get_the_start($instance['group_format']), 'time' => $instance['mode'] == 'day' && eo_is_all_day() ? __('All Day', 'eventorganiser') : eo_get_the_start($instance['item_format']), 'post_title' => get_the_title(), 'color' => eo_get_event_color(), 'event_url' => get_permalink(), 'link' => '<a href="' . get_permalink() . '">' . __('View', 'eventorganiser') . '</a>', 'Glink' => '<a href="' . eo_get_add_to_google_link() . '" target="_blank">' . __('Add To Google Calendar', 'eventorganiser') . '</a>');
    }
    if (!$agenda || !is_array($agenda)) {
        $agenda = array();
    }
    $agenda[$key] = $return_array;
    set_transient('eo_widget_agenda', $agenda, 60 * 60 * 24);
    echo json_encode($return_array);
    exit;
}
 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;
 }