/**
  * Gets a list of upcoming events.
  * Only the events that are not yet over will be returned.
  */
 public static function get_upcoming_events($limit = 5)
 {
     if (!eab_has_post_indexer()) {
         return array();
     }
     $limit = (int) $limit ? (int) $limit : 5;
     global $wpdb;
     $result = array();
     $count = 0;
     $pi_table = eab_pi_get_table();
     $pi_published = eab_pi_get_post_date();
     $pi_blog_id = eab_pi_get_blog_id();
     $pi_post_id = eab_pi_get_post_id();
     $raw_network_events = $wpdb->get_results("SELECT * FROM {$wpdb->base_prefix}{$pi_table} WHERE post_type='incsub_event' ORDER BY {$pi_published} DESC");
     if (!$raw_network_events) {
         return $result;
     }
     foreach ($raw_network_events as $event) {
         if ($count == $limit) {
             break;
         }
         switch_to_blog($event->{$pi_blog_id});
         $post = get_post($event->{$pi_post_id});
         $tmp_event_instance = new Eab_EventModel($post);
         $tmp_event_instance->cache_data();
         if ($tmp_event_instance->is_expired()) {
             continue;
         }
         $post->blog_id = $event->{$pi_blog_id};
         $result[] = $post;
         $count++;
         restore_current_blog();
     }
     return $result;
 }
 function form($instance)
 {
     $title = esc_attr($instance['title']);
     $date = esc_attr($instance['date']);
     $network = esc_attr($instance['network']) ? 'checked="checked"' : '';
     $category = !empty($instance['category']) ? is_array($instance['category']) ? array_filter(array_map('esc_attr', $instance['category'])) : array_filter(array(esc_attr($instance['category']))) : array();
     $html .= '<p>';
     $html .= '<label for="' . $this->get_field_id('title') . '">' . __('Title:', $this->translation_domain) . '</label>';
     $html .= '<input type="text" name="' . $this->get_field_name('title') . '" id="' . $this->get_field_id('title') . '" class="widefat" value="' . $title . '"/>';
     $html .= '</p>';
     if (is_multisite() && eab_has_post_indexer()) {
         $html .= '<p>' . '<label for="' . $this->get_field_id('network') . '">' . '<input type="checkbox" name="' . $this->get_field_name('network') . '" id="' . $this->get_field_id('network') . '" value="1" ' . $network . ' /> ' . __('Network-wide?', $this->translation_domain) . '</label> ' . '</p>';
     } else {
         $options = false;
         $all_categories = get_terms('eab_events_category');
         foreach ($all_categories as $cat) {
             $options .= '<option value="' . $cat->term_id . '" ' . (in_array($cat->term_id, $category) ? 'selected="selected"' : '') . '>' . $cat->name . '</option>';
         }
         if ($options) {
             $html .= '<p>' . '<label for="' . $this->get_field_id('category') . '">' . __('Only Events from this category', $this->translation_domain) . '<select id="' . $this->get_field_id('category') . '" name="' . $this->get_field_name('category') . '[]" multiple class="widefat">' . '<option ' . (empty($category) ? 'selected="selected"' : '') . ' value="">' . __('Any', $this->translation_domain) . '</option>' . $options . '</select>' . '</label>' . '</p>';
         }
     }
     echo $html;
 }