public function testNoTimeQueries() { $event_ids = array(); $today = new DateTime('today'); $today->setTime(15, 0); //Yesterday event $start = new DateTime('yesterday'); $end = new DateTime('yesterday'); $start->setTime(15, 0); $end->setTime(16, 0); $event_ids[] = $this->factory->event->create(array('start' => $start, 'end' => $end, 'all_day' => 0, 'schedule' => 'once')); //Today event $start = new DateTime('today'); $end = new DateTime('today'); $start->setTime(15, 0); $end->setTime(16, 0); $event_ids[] = $this->factory->event->create(array('start' => $start, 'end' => $end, 'all_day' => 0, 'schedule' => 'once')); //Tomorrow event $start = new DateTime('tomorrow'); $end = new DateTime('tomorrow'); $start->setTime(15, 0); $end->setTime(16, 0); $event_ids[] = $this->factory->event->create(array('start' => $start, 'end' => $end, 'all_day' => 0, 'schedule' => 'once')); //event_[start|end]_[before|after] is inclusive! $yesterday = new DateTime('yesterday'); $events_before_today = eo_get_events(array('fields' => 'ids', 'event_start_before' => $yesterday->format('Y-m-d'))); $this->assertEquals(array($event_ids[0]), array_map('intval', $events_before_today)); $tomorrow = new DateTime('tomorrow'); $events_after_today = eo_get_events(array('fields' => 'ids', 'event_start_after' => $tomorrow->format('Y-m-d'))); $this->assertEquals(array($event_ids[2]), array_map('intval', $events_after_today)); }
/** * When grouping events by series, the plug-in should use the first date * (chronologicaly) of the series, matching the query */ public function testSeriesQuery() { $events = eo_get_events(array('event_start_after' => '2015-03-01 00:00:00', 'showpastevents' => true, 'group_events_by' => 'series')); $actual = array(); foreach ($events as $event) { $actual[] = eo_get_the_start(DATETIMEOBJ, $event->ID, null, $event->occurrence_id); } $expected = array(new DateTime('2015-03-02 14:00:00', eo_get_blog_timezone()), new DateTime('2015-03-20 19:30:00', eo_get_blog_timezone()), new DateTime('2015-03-23 09:45:00', eo_get_blog_timezone())); $this->assertEquals($expected, $actual); foreach ($this->event_ids as $event_id) { //var_dump( eo_get_the_occurrences( $event_id ) ); } $events = eo_get_events(array('event_start_after' => '2015-03-22 00:00:00', 'showpastevents' => true, 'group_events_by' => 'series')); $actual = array(); foreach ($events as $event) { $actual[] = eo_get_the_start(DATETIMEOBJ, $event->ID, null, $event->occurrence_id); } $expected = array(new DateTime('2015-03-22 19:30:00', eo_get_blog_timezone()), new DateTime('2015-03-23 09:45:00', eo_get_blog_timezone()), new DateTime('2015-03-23 14:00:00', eo_get_blog_timezone())); $this->assertEquals($expected, $actual); }
/** * Creates an ICAL file of events in the database * @since 1.0.0 * @param string filename - the name of the file to be created * @param string filetype - the type of the file ('text/calendar') */ public function export_events($filename, $filetype) { //Collect output ob_start(); // File header header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename=' . $filename); header('Content-type: text/calendar'); header("Pragma: 0"); header("Expires: 0"); ?> BEGIN:VCALENDAR VERSION:2.0 PRODID:-//<?php get_bloginfo('name'); ?> //NONSGML Events //EN CALSCALE:GREGORIAN X-WR-CALNAME:<?php echo get_bloginfo('name'); ?> - Events X-ORIGINAL-URL:<?php echo EO_Event::link_structure(); ?> X-WR-CALDESC:<?php echo get_bloginfo('name'); ?> - Events <?php // Query for events $events = eo_get_events(array('numberofposts' => -1, 'group_events_by' => 'series', 'showpastevents' => 1)); // Loop through events if ($events) { global $post; foreach ($events as $post) { //If event has no corresponding row in events table then skip it if (!isset($post->event_id) || $post->event_id == -1) { continue; } $now = new DateTime(); $dtstamp = $now->format('Ymd\\THis\\Z'); //Set up event data setup_postdata($post); $event = new EO_Event($post->ID); $start = clone $event->start; $end = clone $event->end; $created = new DateTime($post->post_date_gmt); $created_date = $created->format('Ymd\\THis\\Z'); $modified = new DateTime($post->post_modified_gmt); $modified_date = $modified->format('Ymd\\THis\\Z'); //Set up start and end date times if ($event->is_all_day()) { $format = 'Ymd'; $start_date = $start->format($format); $end->modify('+1 second'); $end_date = $end->format($format); } else { $format = 'Ymd\\THis\\Z'; $UTC_tz = new DateTimeZone('UTC'); $start->setTimezone($UTC_tz); $start_date = $start->format($format); $end->setTimezone($UTC_tz); $end_date = $end->format($format); } //Get the reoccurrence rule in ICS format $reoccurrence_rule = $event->ics_rrule(); //Generate Event status if (get_post_status($post->ID) == 'publish') { $status = 'CONFIRMED'; } else { $status = 'TENTATIVE'; } //Generate a globally unique UID: $rand = ''; $host = $_SERVER['SERVER_NAME']; $base = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPrRsStTuUvVxXuUvVwWzZ1234567890'; $start = 0; $end = strlen($base) - 1; $length = 6; for ($p = 0; $p < $length; $p++) { $rand .= $base[mt_rand($start, $end)]; } $uid = $now->format('Ymd\\THiT') . microtime(true) . '-' . $rand . '-EO' . $post->ID . '@' . $host; //Output event ?> BEGIN:VEVENT UID:<?php echo $uid; ?> STATUS:<?php echo $status; ?> DTSTAMP:<?php echo $dtstamp; ?> CREATED:<?php echo $created_date; ?> LAST-MODIFIED:<?php echo $modified_date; ?> <?php if ($event->is_all_day()) { ?> DTSTART;VALUE=DATE:<?php echo $start_date; ?> DTEND;VALUE=DATE:<?php echo $end_date; } else { ?> DTSTART:<?php echo $start_date; ?> DTEND:<?php echo $end_date; } ?> <?php if ($reoccurrence_rule) { ?> RRULE:<?php echo $reoccurrence_rule; ?> <?php } ?> SUMMARY:<?php echo $this->escape_icalText(get_the_title()); ?> <?php $excerpt = get_the_excerpt(); $excerpt = apply_filters('the_excerpt_rss', $excerpt); if (!empty($excerpt)) { ?> DESCRIPTION:<?php echo html_entity_decode($this->escape_icalText($excerpt)); ?> <?php } if ($event->venue_set()) { $venue = eo_get_venue_name(eo_get_venue()); ?> LOCATION: <?php echo $this->escape_icalText($venue); ?> <?php } $author = get_the_author(); ?> ORGANIZER: <?php echo $this->escape_icalText($author); ?> END:VEVENT <?php } } ?> END:VCALENDAR <?php //Collect output and echo $eventsical = ob_get_contents(); ob_end_clean(); echo $eventsical; exit; }
function widget($args, $instance) { extract($args, EXTR_SKIP); $template = $instance['template']; $no_events = isset($instance['no_events']) ? $instance['no_events'] : ''; unset($instance['template']); unset($instance['no_events']); $events = eo_get_events($instance); echo $before_widget; echo $before_title; echo esc_html($instance['title']); echo $after_title; global $post; $tmp_post = $post; echo '<ul class="eo-events eo-events-widget">'; if ($events) { foreach ($events as $post) { setup_postdata($post); if (empty($template)) { //Use default template //Check if all day, set format accordingly if ($post->event_allday) { $format = get_option('date_format'); } else { $format = get_option('date_format') . ' ' . get_option('time_format'); } echo '<li><a title="' . the_title_attribute(array('echo' => false)) . '" href="' . get_permalink() . '">' . esc_html(get_the_title()) . '</a> ' . __('on', 'eventorganiser') . ' ' . eo_format_date($post->StartDate . ' ' . $post->StartTime, $format) . '</li>'; } else { echo '<li>' . EventOrganiser_Shortcodes::read_template($template) . '</li>'; } } $post = $tmp_post; wp_reset_postdata(); } else { echo $no_events; } echo '</ul>'; echo $after_widget; }
/** * 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); } } } }
/** * 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]; }
/** * Generates widget / shortcode calendar html * * param $month - DateTime object for first day of the month (in blog timezone) */ function generate_output($month, $args = array()) { //Translations global $wp_locale; $months = $wp_locale->month; $monthsAbbrev = $wp_locale->month_abbrev; $weekdays = $wp_locale->weekday; $weekdays_initial = $wp_locale->weekday_initial; //Month should be a DateTime object of the first day in that month $today = new DateTime('now', eo_get_blog_timezone()); if (empty($args)) { $args = array(); } //Month details $firstdayofmonth = intval($month->format('N')); $lastmonth = clone $month; $lastmonth->modify('last month'); $nextmonth = clone $month; $nextmonth->modify('next month'); $daysinmonth = intval($month->format('t')); //Retrieve the start day of the week from the options. $startDay = intval(get_option('start_of_week')); //How many blank cells before inserting dates $offset = ($firstdayofmonth - $startDay + 7) % 7; //Number of weeks to show in Calendar $totalweeks = ceil(($offset + $daysinmonth) / 7); //Get events for this month $start = $month->format('Y-m-d'); $end = $month->format('Y-m') . '-' . $daysinmonth; $required = array('numberposts' => -1, 'showrepeats' => 1, 'start_before' => $end, 'start_after' => $start); $query_array = array_merge($args, $required); $events = eo_get_events($query_array); //Populate events array $tableArray = array(); foreach ($events as $event) { $date = esc_html($event->StartDate); $tableArray[$date][] = esc_attr($event->post_title); } $before = "<table id='wp-calendar'>"; $title = "<caption>" . esc_html($months[$month->format('m')] . ' ' . $month->format('Y')) . "</caption>"; $head = "<thead><tr>"; for ($d = 0; $d <= 6; $d++) { $day = $weekdays_initial[$weekdays[($d + $startDay) % 7]]; $head .= "<th title='" . esc_attr($day) . "' scope='col'>" . esc_html($day) . "</th>"; } $head .= "</tr></thead>"; $prev = esc_html($monthsAbbrev[$months[$lastmonth->format('m')]]); $next = esc_html($monthsAbbrev[$months[$nextmonth->format('m')]]); $prev_link = add_query_arg('eo_month', $lastmonth->format('Y-m')); $next_link = add_query_arg('eo_month', $nextmonth->format('Y-m')); $foot = "<tfoot><tr>"; $foot .= "<td id='eo-widget-prev-month' colspan='3'><a title='" . esc_html__('Previous month', 'eventorganiser') . "' href='{$prev_link}'>« " . $prev . "</a></td>"; $foot .= "<td class='pad'> </td>"; $foot .= "<td id='eo-widget-next-month' colspan='3'><a title='" . esc_html__('Next month', 'eventorganiser') . "' href='{$next_link}'>" . $next . "» </a></td>"; $foot .= "</tr></tfoot>"; $body = "<tbody>"; $currentDate = clone $month; $event_archive_link = get_post_type_archive_link('event'); for ($w = 0; $w <= $totalweeks - 1; $w++) { $body .= "<tr>"; $cell = $w * 7; //For each week day foreach ($weekdays_initial as $i => $day) { $cell = $cell + 1; if ($cell <= $offset || $cell - $offset > $daysinmonth) { $body .= "<td class='pad' colspan='1'> </td>"; } else { $class = array(); $formated_date = $currentDate->format('Y-m-d'); //Is the date 'today'? if ($formated_date == $today->format('Y-m-d')) { $class[] = 'today'; } //Does the date have any events if (isset($tableArray[$formated_date])) { $class[] = 'event'; $classes = implode(' ', $class); $classes = esc_attr($classes); $titles = implode(', ', $tableArray[$formated_date]); $titles = esc_attr($titles); $link = add_query_arg('ondate', $currentDate->format('Y-m-d'), $event_archive_link); $link = esc_url($link); $body .= "<td class='" . $classes . "'> <a title='" . $titles . "' href='" . $link . "'>" . ($cell - $offset) . "</a></td>"; } else { $classes = implode(' ', $class); $body .= "<td class='" . $classes . "'>" . ($cell - $offset) . "</td>"; } $currentDate->modify('+1 day'); } } //Endforeach Week day $body .= "</tr>"; } //End for each week $body .= "</tbody>"; $after = "</table>"; return $before . $title . $head . $foot . $body . $after; }
function eventorganiser_widget_agenda() { global $wpdb, $wp_locale; $meridiem = $wp_locale->meridiem; $direction = intval($_GET['direction']); $today = new DateTIme('now', eo_get_blog_timezone()); $before_or_after = $direction < 1 ? 'before' : 'after'; $date = $direction < 1 ? $_GET['start'] : $_GET['end']; $order = $direction < 1 ? 'DESC' : 'ASC'; $selectDates = "SELECT DISTINCT StartDate FROM {$wpdb->eo_events}"; if ($order == 'ASC') { $whereDates = " WHERE {$wpdb->eo_events}.StartDate >= %s "; } else { $whereDates = " WHERE {$wpdb->eo_events}.StartDate <= %s "; } $whereDates .= " AND {$wpdb->eo_events}.StartDate >= %s "; $orderlimit = "ORDER BY {$wpdb->eo_events}.StartDate {$order} LIMIT 4"; $dates = $wpdb->get_col($wpdb->prepare($selectDates . $whereDates . $orderlimit, $date, $today->format('Y-m-d'))); if (!$dates) { return false; } $date1 = min($dates[0], $dates[count($dates) - 1]); $date2 = max($dates[0], $dates[count($dates) - 1]); $events = eo_get_events(array('event_start_after' => $date1, 'event_start_before' => $date2)); $return_array = array(); global $post; foreach ($events as $post) { $startDT = new DateTime($post->StartDate . ' ' . $post->StartTime); if (!eo_is_all_day()) { $ampm = trim($meridiem[$startDT->format('a')]); $ampm = empty($ampm) ? $startDT->format('a') : $ampm; //Tranlsate am/pm $time = $startDT->format('g:i') . $ampm; } else { $time = __('All Day', 'eventorganiser'); } $color = ''; $terms = get_the_terms($post->ID, 'event-category'); if ($terms) { $term = array_shift(array_values($terms)); $color = isset($term->color) ? $term->color : ''; } //'StartDate'=>eo_format_date($post->StartDate,'l jS F'), $return_array[] = array('StartDate' => $post->StartDate, 'time' => $time, 'post_title' => substr($post->post_title, 0, 25), 'event_allday' => $post->event_allday, 'color' => $color, 'link' => get_permalink(), 'Glink' => eo_get_the_GoogleLink()); } echo json_encode($return_array); exit; }
echo home_url(); ?> /events/event/on/<?php get_today(); ?> ">Zur Agenda</a> </div> </aside> <div class="padding"> </div> <div id="isotope-container" class="small-12 large-9 columns uncollapse js-isotope" role="main"> <?php $events = eo_get_events(array('event-category' => 'events', 'event_start_after' => 'today', 'group_events_by' => 'series')); if ($events) { foreach ($events as $post) { //Check if all day, set format accordingly $format = eo_is_all_day($post->ID) ? get_option('date_format') : get_option('date_format') . ' ' . get_option('time_format'); get_template_part('content-normal', get_post_format()); } } ?> <script type="text/javascript"> // Make Sticky Post Full-Width $( ".sticky" ).removeClass( "medium-6 large-4" ); // $( ".sticky" ).addClass( "small-12" ); </script>
<?php $events = eo_get_events(array('event_start_after' => 'today', 'showpastevents' => true)); if ($events) { echo '<div class="news alt-color"><h2 class="category-headline alt-color">Upcoming</h2>'; foreach ($events as $event) { //Check if all day, set format accordingly $format = eo_is_all_day($event->ID) ? get_option('date_format') : get_option('date_format') . ' ' . get_option('time_format'); printf('<h3 class="news-title"><a href="%s"> %s </a></h3> <p> %s </p>', get_permalink($event->ID), get_the_title($event->ID), eo_get_the_start($format, $event->ID, null, $event->occurrence_id)); } echo '</div>'; }
<section class="eventsHome inverse"> <div> <h1>Calendar</h1> <div class="colWrapper"> <?php $events = eo_get_events(array('numberposts' => 6, 'event_start_after' => 'today', 'showpastevents' => false)); ?> <div class="col2"> <ul> <?php if ($events) { $count = 0; foreach ($events as $event) { $count = $count + 1; if ($count === 4) { ?> </ul> </div> <div class="col3"> <ul> <?php } printf('<li><a href="%s"><span>%s</span><strong>%s</strong></a></li>', get_permalink($event->ID), eo_get_the_start('jS M', $event->ID, null, $event->occurrence_id), get_the_title($event->ID)); } } ?> </ul> </div> </div>
function eventorganiser_delete_expired_events() { //Get expired events $events = eo_get_events(array('showrepeats' => 0, 'showpastevents' => 1, 'eo_interval' => 'expired')); if ($events) { foreach ($events as $event) { $now = new DateTime('now', eo_get_blog_timezone()); $start = new DateTime($event->StartDate . ' ' . $event->StartTime, eo_get_blog_timezone()); $end = new DateTime($event->EndDate . ' ' . $event->FinishTime, eo_get_blog_timezone()); $duration = date_diff($start, $end); $finished = new DateTime($event->reoccurrence_end . ' ' . $event->StartTime, eo_get_blog_timezone()); $finished->add($duration); $finished->modify('+1 day'); //Delete if 24 hours has passed if ($finished <= $now) { wp_trash_post((int) $event->ID); } } } }
">Learn More »</a><?php } ?> </div> <?php } } else { } wp_reset_postdata(); ?> </div> <div id="home-calendar"> <h2 class="calendar">Calendar</h2> <?php $events = eo_get_events(array('numberposts' => 3, 'event_end_after' => 'today')); if ($events) { echo '<ul>'; foreach ($events as $event) { printf('<li class="calendar clearfix"><div class="calendar-date"><div class="calendar-month">%s</div><div class="calendar-day">%s</div></div><a href="%s"><div class="calendar-title">%s</div></a></li>', eo_get_the_start('M', $event->ID, null, $event->occurrence_id), eo_get_the_start('j', $event->ID, null, $event->occurrence_id), get_permalink($event->ID), get_the_title($event->ID)); } echo '</ul>'; } else { ?> <div class="no-calendar-events"><a href="/calendar"><div class="calendar-icon"><img src="wp-content/themes/medstudentaffairs/_/img/calendar.png"></div></a> <p>Check back soon for upcoming events such as student group activities, workout sessions, parties, journal clubs, workshops, meetings, commencement, orientation, lunches and cultural events.</p></div> <?php } ?> <div id="full-calendar"><a href="/calendar/">View Full Calendar »</a></div>
function handle_eventlist_shortcode($atts = array(), $content = null) { global $post; $tmp_post = $post; $taxs = array('category', 'tag', 'venue'); foreach ($taxs as $tax) { if (isset($atts['event_' . $tax])) { $atts['event-' . $tax] = $atts['event_' . $tax]; unset($atts['event_' . $tax]); } } if (isset($atts['venue']) && $atts['venue'] == '%this%' || isset($atts['event-venue']) && $atts['event-venue'] == '%this%') { if (!empty($post->Venue)) { $atts['event-venue'] = eo_get_venue_slug(); } else { unset($atts['venue']); unset($atts['event-venue']); } } $events = eo_get_events($atts); $tz = eo_get_blog_timezone(); if ($events) { $return = '<ul class="eo-events eo-events-shortcode">'; foreach ($events as $post) { setup_postdata($post); //Check if all day, set format accordingly if (eo_is_all_day()) { $format = get_option('date_format'); } else { $format = get_option('date_format') . ' ' . get_option('time_format'); } $dateTime = new DateTime($post->StartDate . ' ' . $post->StartTime, $tz); if (empty($content)) { $return .= '<li><a title="' . the_title_attribute(array('echo' => false)) . '" href="' . get_permalink() . '">' . get_the_title() . '</a> ' . __('on', 'eventorganiser') . ' ' . eo_format_date($post->StartDate . ' ' . $post->StartTime, $format) . '</li>'; } else { $return .= '<li>' . self::read_template($content) . '</li>'; } } $return .= '</ul>'; $post = $tmp_post; wp_reset_postdata(); return $return; } }
* @package WordPress * @subpackage Twenty_Fourteen * @since Twenty Fourteen 1.0 */ get_header(); ?> <br /> <br /> <div class="motopress-wrapper content-holder clearfix"> <div class="container"> <h1>PAST EVENTS</h1> <br /> <br /> <?php $events = eo_get_events(array('numberposts' => -1, 'event_end_before' => 'today', 'showpastevents' => true)); if ($events) { global $post; foreach ($events as $event) { setup_postdata($event); echo '<ul style="list-style-type:none;">'; //Check if all day, set format accordingly $format = eo_is_all_day($event->ID) ? get_option('date_format') : get_option('date_format') . ' ' . get_option('time_format'); printf('<li><a href="%s"> %s </a>', get_permalink($event->ID), get_the_title($event->ID)); echo '</li>'; echo '<li>' . eo_get_the_start($format, $event->ID, null, $event->occurrence_id) . '</li>'; echo '<li>' . the_excerpt() . '</li>'; printf('<li><a href="%s"> READ MORE </a><li>', get_permalink($event->ID)); echo '</ul><hr />'; } }
/** * Show values * * @since 0.1 * * @return void */ public function show_eo_civi_events() { // construct args for all event posts $args = array('post_type' => 'event', 'numberposts' => -1); // get all event posts $all_events = get_posts($args); // get all EO events $all_eo_events = eo_get_events(); // get all Civi Events $all_civi_events = $this->plugin->civi->get_all_civi_events(); // init $delete = array(); // delete all? if (1 === 2) { // error check if ($all_civi_events['is_error'] == '0') { // do we have any? if (is_array($all_civi_events['values']) and count($all_civi_events['values']) > 0) { // get all event IDs $all_civi_event_ids = array_keys($all_civi_events['values']); // delete all CiviEvents! $delete = $this->plugin->civi->delete_civi_events($all_civi_event_ids); } } } error_log(print_r(array('method' => __METHOD__, 'all_events' => $all_events, 'all_eo_events' => $all_eo_events, 'all_civi_events' => $all_civi_events, 'delete' => $delete), true)); die; }
/** * 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; }
/** * 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); } } } }