$this->widget_description = __('Display a list of featured listings on your site.', 'gam-event-manager');
        $this->widget_id = 'widget_featured_events';
        $this->widget_name = sprintf(__('Featured %s', 'gam-event-manager'), $wp_post_types['event_listing']->labels->name);
        $this->settings = array('title' => array('type' => 'text', 'std' => sprintf(__('Featured %s', 'gam-event-manager'), $wp_post_types['event_listing']->labels->name), 'label' => __('Title', 'gam-event-manager')), 'number' => array('type' => 'number', 'step' => 1, 'min' => 1, 'max' => '', 'std' => 10, 'label' => __('Number of listings to show', 'gam-event-manager')));
        $this->register();
    }
    /**
	 * widget function.
	 *
	 * @see WP_Widget
	 * @access public
	 * @param array $args
	 * @param array $instance
	 * @return void
	 */
    public function widget($args, $instance)
    {
        if ($this->get_cached_widget($args)) {
            return;
        }
        ob_start();
        extract($args);
        $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
        $number = absint($instance['number']);
        $featured_events = get_event_listings(array('posts_per_page' => $number, 'orderby' => 'rand', 'order' => 'DESC', 'featured' => true));
        if ($featured_events->have_posts()) {
            ?>

			<?php 
            echo $before_widget;
            ?>

			<?php 
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            ?>

			<ul class="event_listings">
				<?php 
            while ($featured_events->have_posts()) {
                $featured_events->the_post();
                ?>

					<?php 
                get_event_manager_template_part('content-widget', 'event_listing');
                ?>
                <img class="img-responsive img-center event-banner" src="<?php 
    echo get_event_banner();
    ?>
" />                              
                <?php 
    echo apply_filters('display_event_description', get_the_content());
    ?>
                
              </div>
            </div>                             
            <!-- Event description column end -->
                                                    
           <!-- Organizer logo, Contact button, event location, time and social sharing column start -->                       
            <div class="col-md-4 text-justify ">                            
                <?php 
    get_event_manager_template_part('content', 'single-event_listing-organizer');
    ?>
            </div>  <!-- col-md-4 --> 
           <!-- Organizer logo, Contact button, event location, time and social sharing column end -->
                 
	 	</div>
	 	
	<?php 
    /**
     * single_event_listing_end hook
     */
    do_action('single_event_listing_end');
    ?>
  <?php 
}
?>
    /**
     * Get listings via ajax
     */
    public function get_listings()
    {
        global $wp_post_types;
        $result = array();
        $search_location = sanitize_text_field(stripslashes($_REQUEST['search_location']));
        $search_keywords = sanitize_text_field(stripslashes($_REQUEST['search_keywords']));
        $search_datetimes = isset($_REQUEST['search_datetimes']) ? $_REQUEST['search_datetimes'] : '';
        $search_categories = isset($_REQUEST['search_categories']) ? $_REQUEST['search_categories'] : '';
        $search_event_types = isset($_REQUEST['search_event_types']) ? $_REQUEST['search_event_types'] : '';
        $search_ticket_prices = isset($_REQUEST['search_ticket_prices']) ? $_REQUEST['search_ticket_prices'] : '';
        $post_type_label = $wp_post_types['event_listing']->labels->name;
        $orderby = sanitize_text_field($_REQUEST['orderby']);
        if (is_array($search_datetimes)) {
            $search_datetimes = array_filter(array_map('sanitize_text_field', array_map('stripslashes', $search_datetimes)));
        } else {
            $search_datetimes = array_filter(array(sanitize_text_field(stripslashes($search_datetimes))));
        }
        if (is_array($search_categories)) {
            $search_categories = array_filter(array_map('sanitize_text_field', array_map('stripslashes', $search_categories)));
        } else {
            $search_categories = array_filter(array(sanitize_text_field(stripslashes($search_categories))));
        }
        if (is_array($search_event_types)) {
            $search_event_types = array_filter(array_map('sanitize_text_field', array_map('stripslashes', $search_event_types)));
        } else {
            $search_event_types = array_filter(array(sanitize_text_field(stripslashes($search_event_types))));
        }
        if (is_array($search_ticket_prices)) {
            $search_ticket_prices = array_filter(array_map('sanitize_text_field', array_map('stripslashes', $search_ticket_prices)));
        } else {
            $search_ticket_prices = array_filter(array(sanitize_text_field(stripslashes($search_ticket_prices))));
        }
        $args = array('search_location' => $search_location, 'search_keywords' => $search_keywords, 'search_datetimes' => $search_datetimes, 'search_categories' => $search_categories, 'search_event_types' => $search_event_types, 'search_ticket_prices' => $search_ticket_prices, 'orderby' => $orderby, 'order' => sanitize_text_field($_REQUEST['order']), 'offset' => (absint($_REQUEST['page']) - 1) * absint($_REQUEST['per_page']), 'posts_per_page' => absint($_REQUEST['per_page']));
        if (isset($_REQUEST['cancelled']) && ($_REQUEST['cancelled'] === 'true' || $_REQUEST['cancelled'] === 'false')) {
            $args['cancelled'] = $_REQUEST['cancelled'] === 'true' ? true : false;
        }
        if (isset($_REQUEST['featured']) && ($_REQUEST['featured'] === 'true' || $_REQUEST['featured'] === 'false')) {
            $args['featured'] = $_REQUEST['featured'] === 'true' ? true : false;
            $args['orderby'] = 'featured' === $orderby ? 'date' : $orderby;
        }
        ob_start();
        $events = get_event_listings(apply_filters('event_manager_get_listings_args', $args));
        $result['found_events'] = false;
        if ($events->have_posts()) {
            $result['found_events'] = true;
            ?>

			<?php 
            while ($events->have_posts()) {
                $events->the_post();
                ?>

				<?php 
                get_event_manager_template_part('content', 'event_listing');
                ?>

			<?php 
            }
            ?>

		<?php 
        } else {
            ?>

			<?php 
            get_event_manager_template_part('content', 'no-events-found');
            ?>

		<?php 
        }
        $result['html'] = ob_get_clean();
        $result['filter_value'] = array();
        //categories
        if ($search_categories) {
            $showing_categories = array();
            foreach ($search_categories as $category) {
                $category_object = get_term_by(is_numeric($category) ? 'id' : 'slug', $category, 'event_listing_category');
                if (!is_wp_error($category_object)) {
                    $showing_categories[] = $category_object->name;
                }
            }
            $result['filter_value'][] = implode(', ', $showing_categories);
        }
        //event types
        if ($search_event_types) {
            $showing_event_types = array();
            foreach ($search_event_types as $event_type) {
                $event_type_object = get_term_by(is_numeric($event_type) ? 'id' : 'slug', $event_type, 'event_listing_type');
                if (!is_wp_error($event_type_object)) {
                    $showing_event_types[] = $event_type_object->name;
                }
            }
            $result['filter_value'][] = implode(', ', $showing_event_types);
        }
        //datetimes
        if ($search_datetimes) {
            $showing_datetimes = array();
            foreach ($search_datetimes as $datetime) {
                $showing_datetimes[] = GAM_Event_Manager_Filters::get_datetime_value($datetime);
            }
            $result['filter_value'][] = implode(', ', $showing_datetimes);
        }
        //ticket prices
        if ($search_ticket_prices) {
            $showing_ticket_prices = array();
            foreach ($search_ticket_prices as $ticket_price) {
                $showing_ticket_prices[] = GAM_Event_Manager_Filters::get_ticket_price_value($ticket_price);
            }
            $result['filter_value'][] = implode(', ', $showing_ticket_prices);
        }
        if ($search_keywords) {
            $result['filter_value'][] = '&ldquo;' . $search_keywords . '&rdquo;';
        }
        $last_filter_value = array_pop($result['filter_value']);
        $result_implode = implode(', ', $result['filter_value']);
        if (count($result['filter_value']) >= 1) {
            $result['filter_value'] = explode(" ", $result_implode);
            $result['filter_value'][] = " &amp; ";
        } else {
            if (!empty($last_filter_value)) {
                $result['filter_value'] = explode(" ", $result_implode);
            }
        }
        $result['filter_value'][] = $last_filter_value . " " . $post_type_label;
        if ($search_location) {
            $result['filter_value'][] = sprintf(__('located in &ldquo;%s&rdquo;', 'gam-event-manager'), $search_location);
        }
        if (1 === sizeof($result['filter_value'])) {
            $result['showing_applied_filters'] = true;
        }
        $result['filter_value'] = apply_filters('event_manager_get_listings_custom_filter_text', sprintf(__('Showing all %s', 'gam-event-manager'), implode(' ', $result['filter_value'])));
        // Generate RSS link
        $result['showing_links'] = event_manager_get_filtered_links(array('search_keywords' => $search_keywords, 'search_location' => $search_location, 'search_datetimes' => $search_datetimes, 'search_categories' => $search_categories, 'search_event_types' => $search_event_types, 'search_ticket_prices' => $search_ticket_prices));
        // Generate pagination
        if (isset($_REQUEST['show_pagination']) && $_REQUEST['show_pagination'] === 'true') {
            $result['pagination'] = get_event_listing_pagination($events->max_num_pages, absint($_REQUEST['page']));
        }
        $result['max_num_pages'] = $events->max_num_pages;
        wp_send_json(apply_filters('event_manager_get_listings_result', $result, $events));
    }
    /**
     * Preview Step
     */
    public function preview()
    {
        global $post, $event_preview;
        if ($this->event_id) {
            $event_preview = true;
            $action = $this->get_action();
            $post = get_post($this->event_id);
            setup_postdata($post);
            $post->post_status = 'preview';
            ?>
			<form method="post" id="event_preview" action="<?php 
            echo esc_url($action);
            ?>
">
				<div class="event_listing_preview_title">
					<input type="submit" name="continue" id="event_preview_submit_button" class="button" value="<?php 
            echo apply_filters('submit_event_step_preview_submit_text', __('Submit Listing →', 'gam-event-manager'));
            ?>
" />
					<input type="submit" name="edit_event" class="button" value="<?php 
            _e('← Edit listing', 'gam-event-manager');
            ?>
" />
					<input type="hidden" name="event_id" value="<?php 
            echo esc_attr($this->event_id);
            ?>
" />
					<input type="hidden" name="step" value="<?php 
            echo esc_attr($this->step);
            ?>
" />
					<input type="hidden" name="event_manager_form" value="<?php 
            echo $this->form_name;
            ?>
" />
					<h2>
						<?php 
            _e('Preview', 'gam-event-manager');
            ?>
					</h2>
				</div>
				<div class="event_listing_preview single_event_listing">			
					<?php 
            get_event_manager_template_part('content-single', 'event_listing');
            ?>
				</div>
			</form>
			<?php 
            wp_reset_postdata();
        }
    }
    /**
	 * Change label
	 */
    public function admin_head()
    {
        global $menu;
        $plural = __('Event Listings', 'gam-event-manager');
        $count_events = wp_count_posts('event_listing', 'readable');
        if (!empty($menu) && is_array($menu)) {
            foreach ($menu as $key => $menu_item) {
                if (strpos($menu_item[0], $plural) === 0) {
                    if ($order_count = $count_events->pending) {
                        $menu[$key][0] .= " <span class='awaiting-mod update-plugins count-{$order_count}'><span class='pending-count'>" . number_format_i18n($count_events->pending) . "</span></span>";
                    }
                    break;
                }
            }
        }
    /**
     * Event Summary shortcode
     *
     * @access public
     * @param array $args
     * @return string
     */
    public function output_event_summary($atts)
    {
        extract(shortcode_atts(array('id' => '', 'featured' => null, 'limit' => 1), $atts));
        ob_start();
        $args = array('post_type' => 'event_listing', 'post_status' => 'publish');
        if (!$id) {
            $args['posts_per_page'] = $limit;
            $args['orderby'] = 'rand';
            if (!is_null($featured)) {
                $args['meta_query'] = array(array('key' => '_featured', 'value' => '1', 'compare' => $featured ? '=' : '!='));
            }
        } else {
            $args['p'] = absint($id);
        }
        $events = new WP_Query($args);
        if ($events->have_posts()) {
            ?>

			<?php 
            while ($events->have_posts()) {
                $events->the_post();
                ?>

					<?php 
                get_event_manager_template_part('content-summary', 'event_listing');
                ?>

			<?php 
            }
            ?>

		<?php 
        }
        wp_reset_postdata();
        return ob_get_clean();
    }