public function testOndateSlug()
 {
     global $wp_rewrite;
     update_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');
     $options = eventorganiser_get_option(false);
     $options['url_on'] = 'events-on';
     update_option('eventorganiser_options', $options);
     eventorganiser_cpt_register();
     $GLOBALS['wp_rewrite']->init();
     flush_rewrite_rules();
     $this->go_to(eo_get_event_archive_link(2014, 03));
     $this->assertTrue(eo_is_event_archive('month'));
     $this->assertEquals('2014-03-01', eo_get_event_archive_date('Y-m-d'));
     $this->assertEquals('http://example.org/events/event/events-on/2014/03', eo_get_event_archive_link(2014, 03));
 }
 /**
  * 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];
 }