public function shortcode($args = array(), $content = '')
 {
     $original_arguments = $args;
     $codec = new Eab_Codec_ArgumentsCodec();
     $args = $codec->parse_arguments($args, array('format' => 'H:i T l', 'class' => '', 'add' => 0, 'expired' => __('Closed', Eab_EventsHub::TEXT_DOMAIN), 'legacy' => false, 'category' => false, 'categories' => false));
     if (!empty($args['legacy'])) {
         return $this->_legacy_shortcode($original_arguments);
     }
     $class = !empty($args['class']) ? 'class="' . sanitize_html_class($args['class']) . '"' : '';
     $format = "<div {$class}>%s</div>";
     $output = '';
     $additional = 0;
     if (!empty($args['add']) && (int) $args['add']) {
         $additional = (int) $args['add'] * 60;
     }
     $query = $codec->get_query_args($args);
     $now = eab_current_time() + $additional;
     $events = Eab_CollectionFactory::get_upcoming_events($now, $query);
     $ret = array();
     foreach ($events as $event) {
         $ts = $event->get_start_timestamp();
         if ($ts < $now) {
             continue;
         }
         $ret[$ts] = $event;
     }
     ksort($ret);
     $next = reset($ret);
     if ($next) {
         $output = date_i18n($args['format'], $next->get_start_timestamp());
     } else {
         $output = !empty($args['expired']) ? esc_html($args['expired']) : $content;
     }
     return sprintf($format, $output);
 }
 function eab_recurring_cb($args)
 {
     $args = shortcode_atts(array('id' => false, 'slug' => false, 'class' => false, 'template' => 'get_shortcode_recurring_output', 'override_styles' => false, 'override_scripts' => false), $args, 'eab_recurring');
     $event = false;
     if ($args['id']) {
         $event = new Eab_EventModel(get_post($args['id']));
     } else {
         $q = new WP_Query(array('post_type' => Eab_EventModel::POST_TYPE, 'name' => $args['slug'], 'posts_per_page' => 1));
         if (isset($q->posts[0])) {
             $event = new Eab_EventModel($q->posts[0]);
         }
     }
     if (!$event) {
         return $content;
     }
     $rec_events = Eab_CollectionFactory::get_all_recurring_children_events($event);
     $out = '<section class="eab-events-archive ' . $args['class'] . '">';
     foreach ($rec_events as $event) {
         $event = $event instanceof Eab_EventModel ? $event : new Eab_EventModel($event);
         $out .= '<article class="eab-event ' . eab_call_template('get_status_class', $event) . '" id="eab-event-' . $event->get_id() . '">' . '<h4>' . $event->get_title() . '</h4>' . '<div class="eab-event-body">' . $this->get_recurring_content($event) . '</div>' . '</article>';
     }
     $out .= '</section>';
     $output = $out ? $out : $content;
     if (!$args['override_styles']) {
         wp_enqueue_style('eab_front');
     }
     if (!$args['override_scripts']) {
         wp_enqueue_script('eab_event_js');
         do_action('eab-javascript-do_enqueue_api_scripts');
     }
     return $output;
 }
 function eab_calendar_recurring_cb($args)
 {
     $args = shortcode_atts(array('id' => false, 'network' => false, 'date' => false, 'relative_date' => false, 'category' => false, 'categories' => false, 'footer' => false, 'class' => 'eab-shortcode_calendar', 'navigation' => false, 'title_format' => 'M Y', 'short_title_format' => 'm-Y', 'long_date_format' => false, 'template' => 'get_shortcode_calendar_output', 'override_styles' => false, 'override_scripts' => false, 'with_thumbnail' => false, 'default_thumbnail' => false, 'show_excerpt' => false, 'excerpt_length' => 55), $args, 'eab_recurring');
     if (!empty($_GET['date'])) {
         $date = strtotime($_GET['date']);
         if ($date) {
             $args['date'] = $date;
         }
     }
     if ($args['id']) {
         $event = new Eab_EventModel(get_post($args['id']));
     } else {
         $q = new WP_Query(array('post_type' => Eab_EventModel::POST_TYPE, 'name' => $args['slug'], 'posts_per_page' => 1));
         if (isset($q->posts[0])) {
             $event = new Eab_EventModel($q->posts[0]);
         }
     }
     if (!$event) {
         return $content;
     }
     $rec_events = Eab_CollectionFactory::get_all_recurring_children_events($event);
     $output = $this->get_shortcode_calendar_output($rec_events, $args);
     $output = $output ? $output : $content;
     if (!$args['override_styles']) {
         wp_enqueue_style('eab_calendar_shortcode', eab_call_template('util_get_default_template_style', 'calendar'));
     }
     return $output;
 }
 function widget($args, $instance)
 {
     global $wpdb, $current_site, $post, $wiki_tree;
     extract($args);
     $instance = apply_filters('eab-widgets-upcoming-instance_read', $instance, $this);
     $options = wp_parse_args((array) $instance, $this->_defaults);
     $title = apply_filters('widget_title', empty($instance['title']) ? __('Upcoming', $this->translation_domain) : $instance['title'], $instance, $this->id_base);
     $query_args = array('posts_per_page' => $options['limit']);
     if ($options['category']) {
         $query_args['tax_query'] = array(array('taxonomy' => 'eab_events_category', 'field' => 'id', 'terms' => (int) $options['category']));
     }
     if ($options['lookahead'] && is_numeric($options['lookahead'])) {
         $lookahead_func = create_function('', 'return ' . $options['lookahead'] . ';');
         add_filter('eab-collection-upcoming_weeks-week_number', $lookahead_func);
     }
     $_events = Eab_CollectionFactory::get_upcoming_weeks_events(eab_current_time(), $query_args);
     if (!empty($lookahead_func)) {
         remove_filter('eab-collection-upcoming_weeks-week_number', $lookahead_func);
     }
     if (is_array($_events) && count($_events) > 0) {
         echo $before_widget;
         echo $before_title . $title . $after_title;
         echo '<div id="event-popular"><ul>';
         foreach ($_events as $_event) {
             $thumbnail = $excerpt = false;
             if ($options['thumbnail']) {
                 $raw = wp_get_attachment_image_src(get_post_thumbnail_id($_event->get_id()));
                 $thumbnail = $raw ? @$raw[0] : false;
             }
             $excerpt = false;
             if (!empty($options['excerpt'])) {
                 $words = (int) $options['excerpt_words_limit'] ? (int) $options['excerpt_words_limit'] : false;
                 $excerpt = eab_call_template('util_words_limit', $_event->get_excerpt_or_fallback(), $words);
             }
             echo '<li>';
             echo '<a href="' . get_permalink($_event->get_id()) . '" class="' . ($_event->get_id() == $post->ID ? 'current' : '') . '" >' . ($options['thumbnail'] && $thumbnail ? '<img src="' . $thumbnail . '" /><br />' : '') . $_event->get_title() . '</a>';
             if (!empty($options['dates'])) {
                 echo '<div class="wpmudevevents-date">' . Eab_Template::get_event_dates($_event) . '</div>';
             }
             if (!empty($options['excerpt']) && !empty($excerpt)) {
                 echo '<p>' . $excerpt . '</p>';
             }
             do_action('eab-widgets-upcoming-after_event', $options, $_event, $this);
             echo '</li>';
         }
         echo '</ul></div>';
         echo $after_widget;
     } else {
         echo $before_widget . $before_title . $title . $after_title . '<p class="eab-widget-no_events">' . __('No upcoming events.', Eab_EventsHub::TEXT_DOMAIN) . '</p>' . $after_widget;
     }
 }
 /**
  * Sets status of old events to STATUS_ARCHIVED
  */
 function archive_old_events()
 {
     $time = eab_current_time();
     $events = Eab_CollectionFactory::get_old_events($time);
     foreach ($events as $event) {
         if ($event->get_last_end_timestamp() < $time) {
             if ($event->is_recurring()) {
                 continue;
             }
             $event->set_status(Eab_EventModel::STATUS_ARCHIVED);
             do_action('eab-scheduler-event_archived', $event);
         }
     }
 }
 public function notify_rsvp_on_update_event($post_id, $post)
 {
     if (!current_user_can('edit_posts')) {
         return false;
     }
     if (wp_is_post_revision($post_id)) {
         return;
     }
     if ('incsub_event' == get_post_type($post_id)) {
         global $wpdb;
         $event = $post instanceof Eab_EventModel ? $post : new Eab_EventModel($post);
         $all_events = array($event);
         if ($event->is_recurring()) {
             $all_events = Eab_CollectionFactory::get_all_recurring_children_events($event);
         }
         $all_event_ids = array();
         foreach ($all_events as $e) {
             $all_event_ids[] = $e->get_id();
         }
         $all_event_ids = array_filter(array_map('intval', $all_event_ids));
         $bookings = $wpdb->get_results("SELECT id,user_id,event_id FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id IN(" . join(',', $all_event_ids) . ") ORDER BY timestamp;");
         if (!count($bookings)) {
             return false;
         }
         $eab_alert = $this->_data->get_option('eab_alert');
         $start_dates = $event->get_start_dates();
         foreach ($start_dates as $key => $date) {
             $start = $event->get_start_timestamp($key);
             $end = $event->get_end_timestamp($key);
         }
         foreach ($bookings as $booking) {
             $user_data = get_userdata($booking->user_id);
             $subject = str_replace(array('DISPLAY_NAME', 'EVENT_NAME', 'START_DATE', 'START_TIME', 'END_DATE', 'END_TIME'), array($user_data->display_name, $event->get_title(), date('Y-m-d', $start), date('H:i', $start), date('Y-m-d', $end), date('H:i', $end)), $eab_alert['subject']);
             $content = str_replace(array('DISPLAY_NAME', 'EVENT_NAME', 'START_DATE', 'START_TIME', 'END_DATE', 'END_TIME'), array($user_data->display_name, $event->get_title(), date('Y-m-d', $start), date('H:i', $start), date('Y-m-d', $end), date('H:i', $end)), $eab_alert['content']);
             add_filter('wp_mail_content_type', array($this, 'set_content_type'));
             wp_mail($user_data->user_email, $subject, nl2br($content));
             remove_filter('wp_mail_content_type', array($this, 'set_content_type'));
         }
     }
 }
 protected function _get_bookings($status)
 {
     $event = new Eab_EventModel($this->_event_id);
     $event_id = "event_id = " . (int) $this->_event_id;
     if ($event->is_recurring()) {
         $all_event_ids = array();
         $events = Eab_CollectionFactory::get_all_recurring_children_events($event);
         foreach ($events as $e) {
             $all_event_ids[] = $e->get_id();
         }
         $all_event_ids = array_filter(array_map('intval', $all_event_ids));
         $event_id = "event_id IN(" . join(',', $all_event_ids) . ")";
     }
     global $wpdb;
     return $wpdb->get_results($wpdb->prepare("SELECT id,user_id,event_id,timestamp FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE {$event_id} AND status = %s ORDER BY timestamp;", $status));
 }
 protected function _get_recurring_children_ids()
 {
     $events = Eab_CollectionFactory::get_all_recurring_children_events($this);
     $ids = array();
     foreach ($events as $event) {
         $ids[] = $event->get_id();
     }
     return $ids;
 }
    public function shortcode($args = array(), $content = '')
    {
        $original_arguments = $args;
        $codec = new Eab_Codec_ArgumentsCodec();
        $args = $codec->parse_arguments($args, array('id' => '', 'format' => 'dHMS', 'goto' => '', 'class' => '', 'type' => '', 'size' => 70, 'add' => 0, 'allow_scaling' => false, 'compact' => false, 'title' => false, 'footer_script' => false, 'expired' => __('Closed', Eab_EventsHub::TEXT_DOMAIN), 'legacy' => false, 'category' => false, 'categories' => false, 'weeks' => false));
        if (!empty($args['legacy'])) {
            return $this->_legacy_shortcode($original_arguments);
        }
        $class = !empty($args['class']) ? 'class="' . sanitize_html_class($args['class']) . '"' : '';
        $id = str_replace(array(" ", "'", '"'), "", $args['id']);
        // We cannot let spaces and quotes in id
        // Do not add quotes for page refresh
        if ($args['goto'] && $args['goto'] != "window.location.href") {
            $args['goto'] = "'" . str_replace(array("'", '"'), "", $args['goto']) . "'";
        }
        // Do not allow quotes which may break js
        $transform = false;
        if ($args['size'] < 70 && !empty($args['allow_scaling'])) {
            $transform = $args['size'] / 70;
        }
        switch ($args['size']) {
            case 70:
                $height = 72;
                break;
            case 82:
                $height = 84;
                break;
            case 127:
                $height = 130;
                break;
            case 254:
                $height = 260;
                break;
            default:
                $args['size'] = 70;
                $height = 72;
                break;
        }
        $sprite_file = plugins_url('/events-and-bookings/img/sprite_' . $args['size'] . 'x' . $height . '.png');
        $secs = -1;
        $additional = 0;
        if (!empty($args['add']) && (int) $args['add']) {
            $additional = (int) $args['add'] * 60;
        }
        $query = $codec->get_query_args($args);
        $now = eab_current_time() + $additional;
        //$events = Eab_CollectionFactory::get_upcoming_events($now, $query);
        $future_peeking_method = false;
        if (!empty($args['weeks']) && is_numeric($args['weeks'])) {
            $future_peeking_method = create_function('', 'return ' . (int) $args['weeks'] . ';');
        }
        if (!empty($future_peeking_method)) {
            add_filter('eab-collection-upcoming_weeks-week_number', $future_peeking_method);
        }
        $events = Eab_CollectionFactory::get_upcoming_weeks_events($now, $query);
        if (!empty($future_peeking_method)) {
            remove_filter('eab-collection-upcoming_weeks-week_number', $future_peeking_method);
        }
        $ret = array();
        foreach ($events as $event) {
            $ts = $event->get_start_timestamp();
            if ($ts < $now) {
                continue;
            }
            $ret[$ts] = $event;
        }
        ksort($ret);
        $next = reset($ret);
        if ($next) {
            $secs = $next->get_start_timestamp() - $now;
        } else {
            return $content;
        }
        $script = '';
        $script .= "<script type='text/javascript'>";
        $script .= "jQuery(document).ready(function(\$) {";
        $script .= "\$('#eab_next_event_countdown" . $id . "').countdown({\n\t\t\t\t\tformat: '" . $args['format'] . "',\n\t\t\t\t\texpiryText: '" . $args['expired'] . "',\n\t\t\t\t\tuntil: " . $secs . ",";
        if ($args['goto']) {
            $script .= "onExpiry: eab_next_event_refresh" . $id . ",";
        }
        if ($args['type'] == 'flip') {
            $script .= "onTick: function () { \$(document).trigger('eab-event_countdown-tick', [\$(this), '{$sprite_file}']);},";
        }
        $script .= "alwaysExpire: true});";
        if ($args['goto']) {
            $script .= "function eab_next_event_refresh" . $id . "() {window.location.href=" . $args['goto'] . ";}";
        }
        $script .= "});</script>";
        if ('flip' == $args['type']) {
            $script .= '<script type="text/javascript" src="' . plugins_url(basename(EAB_PLUGIN_DIR) . "/js/event_countdown_flip.js") . '"></script>';
        }
        // remove line breaks to prevent wpautop break the script
        $script = str_replace(array("\r", "\n", "\t", "<br>", "<br />"), "", preg_replace('/\\s+/m', ' ', $script));
        $this->add_countdown = true;
        $markup = '<div class="eab_next_event_countdown-wrapper">' . ($args['title'] ? '<h4><a href="' . get_permalink($next->get_id()) . '">' . $next->get_title() . '</a></h4>' : '') . "<div id='eab_next_event_countdown{$id}' {$class} data-height='{$height}' data-size='" . $args['size'] . "'></div>" . '</div>';
        if ($transform && !empty($args['allow_scaling'])) {
            $markup .= <<<EOStandardTransformCSS
<style type="text/css">
#eab_next_event_countdown{$id} .countdown_section {
\ttransform: scale({$transform},{$transform});
\t-ms-transform: scale({$transform},{$transform});
\t-webkit-transform: scale({$transform},{$transform});
}
</style>
EOStandardTransformCSS;
        }
        if (!empty($args['size']) && !empty($args['compact'])) {
            $base_size = $transform && !empty($args['allow_scaling']) ? $args['size'] * $transform : $args['size'];
            $max_width = $base_size * 8 + 20;
            $markup .= <<<EOStandardCompactCSS
<style type="text/css">
#eab_next_event_countdown{$id} {
\tmax-width: {$max_width}px;
}
</style>
EOStandardCompactCSS;
        }
        if ($args['footer_script'] && in_array($args['footer_script'], array('yes', 'true', '1'))) {
            self::add_script($script);
            add_action('wp_footer', array($this, 'inject_queued_scripts'), 99);
        } else {
            $markup .= $script;
        }
        return $markup;
    }
 /**
  * Expired shortcode handler.
  */
 function process_expired_shortcode($args = array(), $content = false)
 {
     $args = $this->_preparse_arguments($args, array('class' => false, 'category' => false, 'categories' => false, 'limit' => false, 'order' => false, 'template' => 'get_shortcode_archive_output', 'override_styles' => false, 'override_scripts' => false));
     $query = $this->_to_query_args($args);
     $events = Eab_CollectionFactory::get_expired_events($query);
     $output = Eab_Template::util_apply_shortcode_template($events, $args);
     //eab_call_template('util_apply_shortcode_template', $events, $args);
     $output = $output ? $output : $content;
     if (!$args['override_styles']) {
         wp_enqueue_style('eab_front');
     }
     if (!$args['override_scripts']) {
         wp_enqueue_script('eab_event_js');
     }
     return $output;
 }
 public function get_weekly_calendar($timestamp = false, $id = '', $class = '')
 {
     $options = Eab_Options::get_instance();
     if (!is_object($options)) {
         $options = new Eab_Options();
     }
     $timestamp = $timestamp ? $timestamp : $this->get_local_time();
     $year = date("Y", $timestamp);
     $month = date("m", $timestamp);
     //$query = Eab_CollectionFactory::get_upcoming(strtotime("{$year}-{$month}-01 00:00"));
     $query = Eab_CollectionFactory::get_upcoming_weeks(strtotime("{$year}-{$month}-01 00:00"));
     $this->_events = $query->posts;
     $date = $timestamp ? $timestamp : $this->get_local_time();
     $sunday = $this->sunday($date);
     // Timestamp of first Sunday of any date
     if (!($start = $this->_data->get_option('weekly_calendar_start')) or $start > 23) {
         $start = 10;
     }
     // Set a default working time start
     $first = $start * 3600 + $sunday;
     // Timestamp of the first cell of first Sunday
     if (!($end = $this->_data->get_option('weekly_calendar_end')) or $end < 1) {
         $end = 24;
     }
     // Set a default working time end
     $last = $end * 3600 + $sunday;
     // Timestamp of the last cell of first Sunday
     if (!($interval = $this->_data->get_option('weekly_calendar_interval')) or $interval < 10 or $interval > 60 * 12) {
         $interval = 120;
     }
     // Set a default interval in minutes
     $step = $interval * 60;
     // Timestamp increase interval to one cell below
     $days = $this->arrange(array(0, 1, 2, 3, 4, 5, 6), -1);
     // Arrange days acc. to start of week
     $post_info = array();
     foreach ($this->_events as $event) {
         $post_info[] = $this->_get_item_data($event);
     }
     $tbl_id = $id;
     $tbl_id = $tbl_id ? "id='{$tbl_id}'" : '';
     $tbl_class = $class;
     $tbl_class = $tbl_class ? "class='{$tbl_class}'" : '';
     $ret = '';
     $ret .= "<table width='100%' {$tbl_id} {$tbl_class}>";
     $ret .= $this->_get_table_meta_row('thead');
     $ret .= '<tbody>';
     $ret .= $this->_get_first_row();
     $todays_no = date("w", $this->get_local_time());
     // Number of today
     for ($t = $first; $t < $last; $t = $t + $step) {
         foreach ($days as $key => $i) {
             // Not sure if it's current fix, but it works!
             if ($i == 0) {
                 $i = 7;
             }
             if ($i == -1) {
                 $from = $this->secs2hours($t - $sunday);
                 $to = $this->secs2hours($t - $sunday + $step);
                 $ret .= "<td class='wpmudevevents-weekly-calendar-hours-mins'>" . $from . " - " . $to . "</td>";
             } else {
                 $current_cell_start = $t + $i * 86400;
                 $current_cell_end = $current_cell_start + $step;
                 $this->reset_event_info_storage();
                 foreach ($post_info as $ipost) {
                     $count = count($ipost['event_starts']);
                     for ($k = 0; $k < $count; $k++) {
                         $start = strtotime($ipost['event_starts'][$k]);
                         $end = strtotime($ipost['event_ends'][$k]);
                         if ($start < $current_cell_end && $end > $current_cell_start) {
                             if ($options->get_option('weekly_calendar_display')) {
                                 $this->set_event_info_author(array('start' => $start, 'end' => $end), array('start' => $current_cell_start, 'end' => $current_cell_end), $ipost);
                             } else {
                                 $this->set_event_info(array('start' => $start, 'end' => $end), array('start' => $current_cell_start, 'end' => $current_cell_end), $ipost);
                             }
                         }
                     }
                 }
                 $activity = $this->get_event_info_as_string($i);
                 $now = $todays_no == $i ? 'class="today"' : '';
                 if ($this->get_local_time() < $current_cell_end && $this->get_local_time() > $current_cell_start) {
                     $now = 'class="now"';
                 }
                 $ret .= "<td {$now}>{$activity}</td>";
             }
         }
         $ret .= '</tr><tr>';
         // Close the last day of the week
     }
     $ret .= $this->_get_last_row();
     $ret .= '</tbody>';
     $ret .= $this->_get_table_meta_row('tfoot');
     $ret .= '</table>';
     return $ret;
 }
<?php

global $booking, $wpdb, $wp_query;
$now = current_time('timestamp');
$year = isset($wp_query->query_vars['event_year']) ? $wp_query->query_vars['event_year'] : date('Y', $now);
$year = $year ? $year : date_i18n('Y');
// date_i18n uses current_time when called like this
$month = isset($wp_query->query_vars['event_monthnum']) ? $wp_query->query_vars['event_monthnum'] : date('m', $now);
$month = $month ? $month : date_i18n('m');
$time = strtotime("{$year}-{$month}-01");
$events = defined('EAB_CALENDAR_ARCHIVE_TEMPLATE_USE_CUSTOM_QUERY') && EAB_CALENDAR_ARCHIVE_TEMPLATE_USE_CUSTOM_QUERY ? Eab_CollectionFactory::get_upcoming_events($time) : $wp_query->posts;
get_header('event');
?>
	<div id="primary">
        <div id="wpmudevevents-wrapper">
            <h2><?php 
echo sprintf(__('Events for %s', Eab_EventsHub::TEXT_DOMAIN), date_i18n("F Y", $time));
?>
</h2>
            <div class="wpmudevevents-list">
            <?php 
if (!class_exists('Eab_CalendarTable_EventArchiveCalendar')) {
    require_once EAB_PLUGIN_DIR . 'lib/class_eab_calendar_helper.php';
}
$renderer = new Eab_CalendarTable_EventArchiveCalendar($wp_query->posts);
echo $renderer->get_month_calendar($time);
?>

				<div class="event-pagination">
					<?php 
$prev = $time - 28 * 86400;
    function show_settings()
    {
        $tips = new WpmuDev_HelpTooltips();
        $tips->set_icon_url(plugins_url('events-and-bookings/img/information.png'));
        $from = $this->_data->get_option('eab_rsvps-email-from');
        $from = $from ? $from : get_option('admin_email');
        $subject = $this->_data->get_option('eab_rsvps-email-subject');
        $body = $this->_data->get_option('eab_rsvps-email-body');
        $codec = new Eab_Events_RsvpEmail_Codec();
        $macros = join('</code>, <code>', $codec->get_macros());
        $events = Eab_CollectionFactory::get_upcoming_events(eab_current_time(), array('posts_per_page' => 10));
        ?>
<div id="eab-settings-eab_rsvps_email" class="eab-metabox postbox">
	<h3 class="eab-hndle"><?php 
        _e('RSVP Email settings', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</h3>
	<div class="eab-inside">
		<div class="eab-settings-settings_item">
	    	<label for="eab_event-eab_rsvps-from"><?php 
        _e('From email address', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<span><?php 
        echo $tips->add_tip(__('This is the address the RSVP email will be sent from', Eab_EventsHub::TEXT_DOMAIN));
        ?>
</span>
			<input type="text" id="eab_event-eab_rsvps-from" name="eab_rsvps[email-from]" value="<?php 
        esc_attr_e($from);
        ?>
" />
	    </div>
	    <div class="eab-settings-settings_item">
	    	<label for="eab_event-eab_rsvps-subject"><?php 
        _e('Email subject', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<span><?php 
        echo $tips->add_tip(sprintf(__('This is your email subject. You can use these macros: <code>%s</code>', Eab_EventsHub::TEXT_DOMAIN), $macros));
        ?>
</span>
			<input type="text" class="widefat" id="eab_event-eab_rsvps-subject" name="eab_rsvps[email-subject]" value="<?php 
        esc_attr_e($subject);
        ?>
" />
	    </div>
	    <div class="eab-settings-settings_item">
	    	<label for="eab_event-eab_rsvps-body"><?php 
        _e('Email body', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<span><?php 
        echo $tips->add_tip(sprintf(__('This is your email body. You can use these macros: <code>%s</code>', Eab_EventsHub::TEXT_DOMAIN), $macros));
        ?>
</span>
			<?php 
        wp_editor($body, 'eab_rsvps-email-body', array('name' => 'eab_rsvps-email-body'));
        ?>
	    </div>
	    <div class="eab-settings-settings_item"><small><?php 
        printf(__('You can use these macros in your subject and body: <code>%s</code>', Eab_EventsHub::TEXT_DOMAIN), $macros);
        ?>
</small></div>
	<?php 
        if ($events) {
            ?>
	    <div class="eab-settings-settings_item">
	    	<input type="button" class="button" id="eab_event-eab_rsvps-preview" value="<?php 
            esc_attr_e(__('Preview', Eab_EventsHub::TEXT_DOMAIN));
            ?>
" />
	    	<?php 
            _e('using this event data:', Eab_EventsHub::TEXT_DOMAIN);
            ?>
	    	<select id="eab_event-eab_rsvps-events">
	    	<?php 
            foreach ($events as $event) {
                ?>
	    		<option value="<?php 
                esc_attr_e($event->get_id());
                ?>
"><?php 
                echo $event->get_title();
                ?>
</option>
	    	<?php 
            }
            ?>
	    	</select>
	    	<div id="eab_event-eab_rsvp-email_preview_container" style="line-height: 1.2em"></div>
	    </div>
	<?php 
        }
        ?>
	</div>
</div>
<script type="text/javascript">
(function ($) {
$(function () {
	var $container = $("#eab_event-eab_rsvp-email_preview_container"),
		$subject = $("#eab_event-eab_rsvps-subject"),
		$events = $("#eab_event-eab_rsvps-events")
	;
	$("#eab_event-eab_rsvps-preview").on("click", function () {
		var body_string = (tinyMCE && tinyMCE.activeEditor
			? tinyMCE.activeEditor.getContent()
			: $("#eab_rsvps-email-body").val()
		);
		$container.html('<?php 
        echo esc_js(__("Please, hold on... ", Eab_EventsHub::TEXT_DOMAIN));
        ?>
');
		$.post(ajaxurl, {
			"action": "eab_rsvp_email-preview_email",
			"subject": $subject.val(),
			"body": body_string,
			"event_id": $events.val()
		}, function (data) {
			$container.html(data);
		}, 'html');
	});
})
})(jQuery);
</script>
		<?php 
    }
 private function _render_calendar($date, $network = false, $category = array())
 {
     $args = array();
     $category_class = false;
     if (!empty($category)) {
         $args['tax_query'] = array('relation' => 'OR');
         foreach ($category as $cat) {
             if (!$cat) {
                 continue;
             }
             $args['tax_query'][] = array('taxonomy' => 'eab_events_category', 'field' => 'id', 'terms' => $cat);
         }
         if (1 === count($category)) {
             $term = get_term_by('id', $category[0], 'eab_events_category');
             $category_class = !empty($term->slug) ? $term->slug : false;
         }
     }
     $events = $network ? Eab_Network::get_upcoming_events(10) : Eab_CollectionFactory::get_upcoming_events($date, $args);
     if (!class_exists('Eab_CalendarTable_UpcomingCalendarWidget')) {
         require_once EAB_PLUGIN_DIR . 'lib/class_eab_calendar_helper.php';
     }
     $renderer = new Eab_CalendarTable_UpcomingCalendarWidget($events);
     $renderer->set_class($category_class);
     return $renderer->get_month_calendar($date);
 }
    function show_settings()
    {
        $tips = new WpmuDev_HelpTooltips();
        $tips->set_icon_url(plugins_url('events-and-bookings/img/information.png'));
        $from = $this->_data->get_option('eab_cancelations-email-from');
        $from = $from ? $from : get_option('admin_email');
        $subject = trim($this->_data->get_option('eab_cancelations-email-subject'));
        $subject = !empty($subject) ? $subject : $this->_default_subject;
        $body = trim($this->_data->get_option('eab_cancelations-email-body'));
        $body = !empty($body) ? $body : $this->_default_message;
        $codec = new Eab_Macro_Codec();
        $macros = join('</code>, <code>', $codec->get_macros());
        $events = Eab_CollectionFactory::get_upcoming_events(eab_current_time(), array('posts_per_page' => 10));
        ?>
<div id="eab-settings-eab_cancelations" class="eab-metabox postbox">
	<h3 class="eab-hndle"><?php 
        _e('Event cancellation settings', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</h3>
	<div class="eab-inside">
		<div class="eab-settings-settings_item">
			<label for="eab_cancellations-hide_events"><?php 
        _e('Hide cancelled events', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<input type="hidden" name="eab_cancelations[hide_events]" value="" />
			<input type="checkbox" name="eab_cancelations[hide_events]" id="eab_cancellations-hide_events" value="1" <?php 
        checked(true, $this->_data->get_option('eab_cancelations-hide_events'));
        ?>
 />
		</div>
		<div class="eab-settings-settings_item">
			<label for="eab_cancellations-email_batch_limit"><?php 
        _e('Email batch limit', Eab_EventsHub::TEXT_DOMAIN);
        ?>
:</label>
			<span><?php 
        echo $tips->add_tip(__('This is the maximum number of emails that will be sent in one go. The rest will be scheduled for sending.', Eab_EventsHub::TEXT_DOMAIN));
        ?>
</span>
			<input type="text" name="eab_cancelations[email_batch_limit]" id="eab_cancellations-email_batch_limit" value="<?php 
        echo (int) $this->_get_email_batch_limit();
        ?>
" />
		</div>
		<div class="eab-note">
			<?php 
        _e('This is the email that will be sent to your attendees on event cancellation.', Eab_EventsHub::TEXT_DOMAIN);
        ?>
		</div>
		<div class="eab-settings-settings_item">
	    	<label for="eab_event-eab_cancelations-from"><?php 
        _e('From email address', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<span><?php 
        echo $tips->add_tip(__('This is the address the cancellation email will be sent from', Eab_EventsHub::TEXT_DOMAIN));
        ?>
</span>
			<input type="text" id="eab_event-eab_cancelations-from" name="eab_cancelations[email-from]" value="<?php 
        esc_attr_e($from);
        ?>
" />
	    </div>
	    <div class="eab-settings-settings_item">
	    	<label for="eab_event-eab_cancelations-subject"><?php 
        _e('Email subject', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<span><?php 
        echo $tips->add_tip(sprintf(__('This is your email subject. You can use these macros: <code>%s</code>', Eab_EventsHub::TEXT_DOMAIN), $macros));
        ?>
</span>
			<input type="text" class="widefat" id="eab_event-eab_cancelations-subject" name="eab_cancelations[email-subject]" value="<?php 
        esc_attr_e($subject);
        ?>
" />
	    </div>
	    <div class="eab-settings-settings_item">
	    	<label for="eab_event-eab_cancelations-body"><?php 
        _e('Email body', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<span><?php 
        echo $tips->add_tip(sprintf(__('This is your email body. You can use these macros: <code>%s</code>', Eab_EventsHub::TEXT_DOMAIN), $macros));
        ?>
</span>
			<?php 
        wp_editor($body, 'eab_cancelations-email-body', array('name' => 'eab_cancelations-email-body'));
        ?>
	    </div>
	    <div class="eab-settings-settings_item"><small><?php 
        printf(__('You can use these macros in your subject and body: <code>%s</code>', Eab_EventsHub::TEXT_DOMAIN), $macros);
        ?>
</small></div>
	<?php 
        if ($events) {
            ?>
	    <div class="eab-settings-settings_item">
	    	<input type="button" class="button" id="eab_event-eab_cancelations-preview" value="<?php 
            esc_attr_e(__('Preview', Eab_EventsHub::TEXT_DOMAIN));
            ?>
" />
	    	<?php 
            _e('using this event data:', Eab_EventsHub::TEXT_DOMAIN);
            ?>
	    	<select id="eab_event-eab_cancelations-events">
	    	<?php 
            foreach ($events as $event) {
                ?>
	    		<option value="<?php 
                esc_attr_e($event->get_id());
                ?>
"><?php 
                echo $event->get_title();
                ?>
</option>
	    	<?php 
            }
            ?>
	    	</select>
	    	<div id="eab_event-eab_cancelations-email_preview_container" style="line-height: 1.2em"></div>
	    </div>
	<?php 
        }
        ?>
	</div>
</div>
<script type="text/javascript">
(function ($) {
$(function () {
	var $container = $("#eab_event-eab_cancelations-email_preview_container"),
		$subject = $("#eab_event-eab_cancelations-subject"),
		$events = $("#eab_event-eab_cancelations-events")
	;
	$("#eab_event-eab_cancelations-preview").on("click", function () {
		var editor = tinyMCE.get("eab_cancelations-email-body")
			body_string = (tinyMCE && tinyMCE.activeEditor && tinyMCE.activeEditor.editorId == editor.editorId
			? tinyMCE.activeEditor.getContent()
			: $("#eab_cancelations-email-body").val()
		);
		$container.html('<?php 
        echo esc_js(__("Please, hold on... ", Eab_EventsHub::TEXT_DOMAIN));
        ?>
');
		$.post(ajaxurl, {
			"action": "eab_cancellation_email-preview_email",
			"subject": $subject.val(),
			"body": body_string,
			"event_id": $events.val()
		}, function (data) {
			$container.html(data);
		}, 'html');
	});
})
})(jQuery);
</script>
		<?php 
    }
 private function _get_event_as_ical($post, $recurring_instances = false)
 {
     $ret = '';
     $event = $post instanceof Eab_EventModel ? $post : new Eab_EventModel($post);
     if (in_array($event->get_id(), $this->_processed)) {
         return '';
     }
     // Branch off into recurrence processing
     if ($event->is_recurring()) {
         $events = Eab_CollectionFactory::get_all_recurring_children_events($event);
         foreach ($events as $event) {
             $ret .= $this->_get_event_as_ical($event, $recurring_instances);
         }
         return $ret;
     } else {
         if ($event->is_recurring_child() && $recurring_instances) {
             return $this->_get_event_as_ical(get_post($event->get_parent()), false);
         }
     }
     $domain = preg_replace('/^www\\./', '', parse_url(home_url(), PHP_URL_HOST));
     $author = get_userdata($event->get_author());
     $location = $event->get_venue_location(Eab_EventModel::VENUE_AS_ADDRESS);
     $start_dates = $event->get_start_dates();
     $tz_offset = get_option('gmt_offset') * 3600;
     $time_callback = 'date';
     $zulu = '';
     $tzid = '';
     if ('gmt' == $this->_calculus) {
         $zulu = 'Z';
     } else {
         if ('tz_local' == $this->_calculus) {
             $zone_string = get_option('timezone_string');
             if (!empty($zone_string)) {
                 $tzid = ";TZID={$zone_string}";
             }
         }
     }
     foreach ($start_dates as $key => $start) {
         $start = $event->get_start_timestamp($key) + ('gmt' == $this->_calculus ? $tz_offset : 0);
         $end = $event->get_end_timestamp($key) + ('gmt' == $this->_calculus ? $tz_offset : 0);
         $ret .= "BEGIN:VEVENT\n" . 'UID:' . $event->get_id() . rand() . "@{$domain}\n" . "ORGANIZER;CN={$author->display_name}:MAILTO:{$author->user_email}\n" . "DTSTART{$tzid}:" . $time_callback('Ymd', $start) . "T" . $time_callback('His', $start) . "{$zulu}\n" . "DTEND{$tzid}:" . $time_callback('Ymd', $end) . "T" . $time_callback('His', $end) . "{$zulu}\n" . "SUMMARY:" . $event->get_title() . "\n" . "DESCRIPTION:" . str_replace("\r\n", "\\n", $event->get_content()) . "\n" . "URL:" . get_permalink($event->get_id()) . "\n" . ($location ? "LOCATION:{$location}\n" : '') . "END:VEVENT\n";
     }
     $this->_processed[] = $event->get_id();
     return "\n{$ret}\n";
 }
    function show_settings()
    {
        $tips = new WpmuDev_HelpTooltips();
        $tips->set_icon_url(plugins_url('events-and-bookings/img/information.png'));
        $positive_rsvp = $this->_data->get_option('eab_rsvps-email_me-positive_rsvp') ? 'checked="checked"' : '';
        $paid_rsvp = $this->_data->get_option('eab_rsvps-email_me-paid_rsvp') ? 'checked="checked"' : '';
        $notify_admin = $this->_data->get_option('eab_rsvps-email_me-notify_admin') ? 'checked="checked"' : '';
        $notify_author = $this->_data->get_option('eab_rsvps-email_me-notify_author') ? 'checked="checked"' : '';
        $subject = $this->_data->get_option('eab_rsvps-email_me-subject');
        $body = $this->_data->get_option('eab_rsvps-email_me-body');
        $codec = new Eab_Events_RsvpEmailMe_Codec();
        $macros = join('</code>, <code>', $codec->get_macros());
        $events = Eab_CollectionFactory::get_upcoming_events(eab_current_time(), array('posts_per_page' => 10));
        ?>
<div id="eab-settings-eab_rsvps_me" class="eab-metabox postbox">
	<h3 class="eab-hndle"><?php 
        _e('RSVP Notification Email settings', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</h3>
	<div class="eab-inside">
		<div class="eab-settings-settings_item">
	    	<label><?php 
        _e('Send an update', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<br />
			<label for="eab_event-eab_rsvps-me-positive_rsvp" style="display:block; line-height:1.8em">
				<input type="hidden" name="eab_rsvps_me[email-positive_rsvp]" value="" />
				<input type="checkbox" id="eab_event-eab_rsvps-me-positive_rsvp" name="eab_rsvps_me[email-positive_rsvp]" value="1" <?php 
        echo $positive_rsvp;
        ?>
 />
				<?php 
        _e('On all positive RSVPs', Eab_EventsHub::TEXT_DOMAIN);
        ?>
			</label>
			<label for="eab_event-eab_rsvps-me-paid_rsvp" style="display:block; line-height:1.8em">
				<input type="hidden" name="eab_rsvps_me[email-paid_rsvp]" value="" />
				<input type="checkbox" id="eab_event-eab_rsvps-me-paid_rsvp" name="eab_rsvps_me[email-paid_rsvp]" value="1" <?php 
        echo $paid_rsvp;
        ?>
 />
				<?php 
        _e('When user pays for a paid event', Eab_EventsHub::TEXT_DOMAIN);
        ?>
			</label>
	    </div>
	    <div class="eab-settings-settings_item">
	    	<label><?php 
        _e('Notify', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<br />
			<label for="eab_event-eab_rsvps-me-notify_admin" style="display:block; line-height:1.8em">
				<input type="hidden" name="eab_rsvps_me[email-notify_admin]" value="" />
				<input type="checkbox" id="eab_event-eab_rsvps-me-notify_admin" name="eab_rsvps_me[email-notify_admin]" value="1" <?php 
        echo $notify_admin;
        ?>
 />
				<?php 
        _e('Site administrator', Eab_EventsHub::TEXT_DOMAIN);
        ?>
			</label>
			<label for="eab_event-eab_rsvps-me-notify_author" style="display:block; line-height:1.8em">
				<input type="hidden" name="eab_rsvps_me[email-notify_author]" value="" />
				<input type="checkbox" id="eab_event-eab_rsvps-me-notify_author" name="eab_rsvps_me[email-notify_author]" value="1" <?php 
        echo $notify_author;
        ?>
 />
				<?php 
        _e('Event author', Eab_EventsHub::TEXT_DOMAIN);
        ?>
			</label>
	    </div>
	    <div class="eab-settings-settings_item">
	    	<label for="eab_event-eab_rsvps-me-subject"><?php 
        _e('Email subject', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<span><?php 
        echo $tips->add_tip(sprintf(__('This is your email subject. You can use these macros: <code>%s</code>', Eab_EventsHub::TEXT_DOMAIN), $macros));
        ?>
</span>
			<input type="text" class="widefat" id="eab_event-eab_rsvps-me-subject" name="eab_rsvps_me[email-subject]" value="<?php 
        esc_attr_e($subject);
        ?>
" />
	    </div>
	    <div class="eab-settings-settings_item">
	    	<label for="eab_event-eab_rsvps-me-body"><?php 
        _e('Email body', Eab_EventsHub::TEXT_DOMAIN);
        ?>
</label>
			<span><?php 
        echo $tips->add_tip(sprintf(__('This is your email body. You can use these macros: <code>%s</code>', Eab_EventsHub::TEXT_DOMAIN), $macros));
        ?>
</span>
			<?php 
        wp_editor($body, 'eab_rsvps-email_me-body', array('name' => 'eab_rsvps_me-email_me-body'));
        ?>
	    </div>
	    <div class="eab-settings-settings_item"><small><?php 
        printf(__('You can use these macros in your subject and body: <code>%s</code>', Eab_EventsHub::TEXT_DOMAIN), $macros);
        ?>
</small></div>
	<?php 
        if ($events) {
            ?>
	    <div class="eab-settings-settings_item">
	    	<input type="button" class="button" id="eab_event-eab_rsvps-me-preview" value="<?php 
            esc_attr_e(__('Preview', Eab_EventsHub::TEXT_DOMAIN));
            ?>
" />
	    	<?php 
            _e('using this event data:', Eab_EventsHub::TEXT_DOMAIN);
            ?>
	    	<select id="eab_event-eab_rsvps-me-events">
	    	<?php 
            foreach ($events as $event) {
                ?>
	    		<option value="<?php 
                esc_attr_e($event->get_id());
                ?>
"><?php 
                echo $event->get_title();
                ?>
</option>
	    	<?php 
            }
            ?>
	    	</select>
	    	<div id="eab_event-eab_rsvp_me-email_preview_container" style="line-height: 1.2em"></div>
	    </div>
	<?php 
        }
        ?>
	</div>
</div>
<script type="text/javascript">
(function ($) {
$(function () {
	var $container = $("#eab_event-eab_rsvp_me-email_preview_container"),
		$subject = $("#eab_event-eab_rsvps-me-subject"),
		$events = $("#eab_event-eab_rsvps-me-events")
	;
	$("#eab_event-eab_rsvps-me-preview").on("click", function () {
		var body_string = (tinyMCE && tinyMCE.activeEditor
			? tinyMCE.activeEditor.getContent()
			: $("#eab_rsvps_me-email_me-body").val()
		);
		$container.html('<?php 
        echo esc_js(__("Please, hold on... ", Eab_EventsHub::TEXT_DOMAIN));
        ?>
');
		$.post(ajaxurl, {
			"action": "eab_rsvp_email_me-preview_email",
			"subject": $subject.val(),
			"body": body_string,
			"event_id": $events.val()
		}, function (data) {
			$container.html(data);
		}, 'html');
	});
})
})(jQuery);
</script>
		<?php 
    }
 /**
  * Converts event RSVPs into a send list.
  */
 public function rsvps_to_member_group($event_id, $bookings = array())
 {
     if (empty($event_id) || empty($bookings)) {
         return false;
     }
     $event = new Eab_EventModel(get_post($event_id));
     $all_events = array($event);
     if ($event->is_recurring()) {
         $all_events = Eab_CollectionFactory::get_all_recurring_children_events($event);
     }
     $all_event_ids = array();
     foreach ($all_events as $e) {
         $all_event_ids[] = $e->get_id();
     }
     $all_event_ids = array_filter(array_map('intval', $all_event_ids));
     $rsvps = $this->_db->get_col("SELECT DISTINCT user_id FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id IN(" . join(',', $all_event_ids) . ") AND status IN ('" . join("','", $bookings) . "')");
     //if (empty($rsvps)) return false;
     $group_id = $this->_spawn_event_rsvp_group($event, $bookings);
     if (empty($group_id)) {
         return false;
     }
     return !empty($rsvps) ? $this->_newsletter->add_members_to_groups($rsvps, $group_id, false) : true;
 }
    function widget($args, $instance)
    {
        global $wpdb, $current_site, $post, $wiki_tree;
        extract($args);
        $instance = apply_filters('eab-widgets-popular-instance_read', $instance, $this);
        $options = wp_parse_args((array) $instance, $this->_defaults);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Most Popular', $this->translation_domain) : $instance['title'], $instance, $this->id_base);
        $_events = Eab_CollectionFactory::get_popular_events(array('posts_per_page' => $options['limit']));
        if (is_array($_events) && count($_events) > 0) {
            ?>
		<?php 
            echo $before_widget;
            ?>
		<?php 
            echo $before_title . $title . $after_title;
            ?>
	            <div id="event-popular">
			<ul>
			    <?php 
            foreach ($_events as $_event) {
                $thumbnail = $excerpt = false;
                if ($options['thumbnail']) {
                    $raw = wp_get_attachment_image_src(get_post_thumbnail_id($_event->get_id()));
                    $thumbnail = $raw ? @$raw[0] : false;
                }
                $excerpt = false;
                if ($options['excerpt']) {
                    $words = (int) $options['excerpt_words_limit'] ? (int) $options['excerpt_words_limit'] : false;
                    $excerpt = eab_call_template('util_words_limit', $_event->get_excerpt_or_fallback(), $words);
                }
                ?>
				<li>
					<a href="<?php 
                print get_permalink($_event->get_id());
                ?>
" class="<?php 
                print $_event->get_id() == $post->ID ? 'current' : '';
                ?>
" >
						<?php 
                if ($options['thumbnail'] && $thumbnail) {
                    ?>
							<img src="<?php 
                    echo $thumbnail;
                    ?>
" /><br />
						<?php 
                }
                ?>
						<?php 
                print $_event->get_title();
                ?>
					</a>
					<?php 
                if ($options['excerpt'] && $excerpt) {
                    ?>
						<p><?php 
                    echo $excerpt;
                    ?>
</p>
					<?php 
                }
                ?>
					<?php 
                do_action('eab-widgets-popular-after_event', $options, $_event, $this);
                ?>
				</li>
			    <?php 
            }
            ?>
			</ul>
	            </div>
	        <br />
	        <?php 
            echo $after_widget;
            ?>
		<?php 
        } else {
            echo $before_widget . $before_title . $title . $after_title . '<p class="eab-widget-no_events">' . __('No popular events.', Eab_EventsHub::TEXT_DOMAIN) . '</p>' . $after_widget;
        }
    }
 public static function get_admin_bookings($status, $post)
 {
     global $wpdb;
     if (!current_user_can('edit_posts')) {
         return false;
     }
     // Basic sanity check
     $event = $post instanceof Eab_EventModel ? $post : new Eab_EventModel($post);
     $statuses = self::get_rsvp_status_list();
     if (!in_array($status, array_keys($statuses))) {
         return false;
     }
     // Unknown status
     $status_name = $statuses[$status];
     //$content = Eab_Template::get_admin_attendance_addition_form($event, $statuses); // Moved to actual bookings areas
     $content .= '<h4>' . __($status_name, Eab_EventsHub::TEXT_DOMAIN) . '</h4>';
     $content .= '<ul class="eab-guest-list">';
     $all_events = array($event);
     if ($event->is_recurring()) {
         $all_events = Eab_CollectionFactory::get_all_recurring_children_events($event);
     }
     $all_event_ids = array();
     foreach ($all_events as $e) {
         $all_event_ids[] = $e->get_id();
     }
     $all_event_ids = array_filter(array_map('intval', $all_event_ids));
     $bookings = $wpdb->get_results($wpdb->prepare("SELECT id,user_id,event_id FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id IN(" . join(',', $all_event_ids) . ") AND status = %s ORDER BY timestamp;", $status));
     if (!count($bookings)) {
         return false;
     }
     foreach ($bookings as $booking) {
         $user_data = get_userdata($booking->user_id);
         if ($event->get_id() !== $booking->event_id) {
             $event = new Eab_EventModel(get_post($booking->event_id));
         }
         $content .= '<li>';
         $content .= '<div class="eab-guest">';
         $content .= '<a href="user-edit.php?user_id=' . $booking->user_id . '" title="' . $user_data->display_name . '">' . get_avatar($booking->user_id, 32) . '<br />' . apply_filters('eab-guest_list-admin-guest_name', $user_data->display_name, $booking->user_id, $user_data) . '</a>';
         if ($event->is_premium()) {
             if ($event->user_paid($booking->user_id)) {
                 $ticket_count = $event->get_booking_meta($booking->id, 'booking_ticket_count');
                 $ticket_count = $ticket_count ? $ticket_count : 1;
                 $payment_status = '' . '<span class="eab-guest-payment_info-paid">' . __('Paid', Eab_EventsHub::TEXT_DOMAIN) . '</span>' . '&nbsp;' . sprintf(__('(%s tickets)', Eab_EventsHub::TEXT_DOMAIN), $ticket_count) . '';
             } else {
                 $payment_status = '<span class="eab-guest-payment_info-not_paid">' . __('Not paid', Eab_EventsHub::TEXT_DOMAIN) . '</span>';
             }
             // Added by Hakan
             $payment_status = apply_filters('eab-event-payment_status', $payment_status, $booking->user_id, $event);
             $content .= "<div class='eab-guest-payment_info'>{$payment_status}</div>";
         }
         if (in_array($status, array(Eab_EventModel::BOOKING_YES, Eab_EventModel::BOOKING_MAYBE))) {
             $content .= '<div class="eab-guest-actions"><a href="#cancel-attendance" class="eab-guest-cancel_attendance" data-eab-user_id="' . $booking->user_id . '" data-eab-event_id="' . $event->get_id() . '">' . __('Cancel attendance', Eab_EventsHub::TEXT_DOMAIN) . '</a></div>';
         }
         $content .= '<div class="eab-guest-actions"><a href="#delete-attendance" class="eab-guest-delete_attendance" data-eab-user_id="' . $booking->user_id . '" data-eab-event_id="' . $event->get_id() . '">' . __('Delete attendance entirely', Eab_EventsHub::TEXT_DOMAIN) . '</a></div>';
         $content = apply_filters('eab-event-booking_metabox_content', $content, $booking->user_id);
         $content .= '</div>';
         // .eab-guest
         $content .= '</li>';
     }
     $content .= '</ul>';
     $content .= '<div class="clear"></div>';
     return $content;
 }
 /**
  * Proper query rewriting.
  * HAVE to calculate in the year as well.
  */
 function load_events_from_query()
 {
     if (is_admin()) {
         return false;
     }
     global $wp_query;
     if (Eab_EventModel::POST_TYPE == $wp_query->query_vars['post_type']) {
         $original_year = isset($wp_query->query_vars['event_year']) ? (int) $wp_query->query_vars['event_year'] : false;
         $year = $original_year ? $original_year : date('Y');
         $original_month = isset($wp_query->query_vars['event_monthnum']) ? (int) $wp_query->query_vars['event_monthnum'] : false;
         $month = $original_month ? $original_month : date('m');
         do_action('eab-query_rewrite-before_query_replacement', $original_year, $original_month);
         $wp_query = Eab_CollectionFactory::get_upcoming(strtotime("{$year}-{$month}-01 00:00"), $wp_query->query);
         $wp_query->is_404 = false;
         do_action('eab-query_rewrite-after_query_replacement');
     } else {
         if (!empty($wp_query->query_vars['eab_events_category']) && empty($wp_query->query_vars['paged']) && !empty($_GET['date'])) {
             $date = strtotime($_GET['date']);
             if (!$date) {
                 return false;
             }
             do_action('eab-query_rewrite-before_query_replacement', false, false);
             $wp_query = Eab_CollectionFactory::get_upcoming($date, $wp_query->query);
             $wp_query->is_404 = false;
             do_action('eab-query_rewrite-after_query_replacement');
         }
     }
 }