function process_events_code($atts, $content = '')
 {
     $post_id = get_the_ID();
     if (!$post_id) {
         return '';
     }
     $atts = shortcode_atts(array('for' => false, 'starting_from' => false, 'only_future' => false, 'show_image' => "true", 'show_location' => "true", 'show_start_date' => "true", 'show_end_date' => "true", 'order' => false), $atts);
     if (!$atts['for']) {
         return '';
     }
     // We don't know whose events to show
     $api = new Wdfb_EventsBuffer();
     $events = $api->get_for($atts['for']);
     if (!is_array($events) || empty($events)) {
         return $content;
     }
     if ($atts['order']) {
         $events = $this->_sort_by_time($events, $atts['order']);
     }
     $show_image = "true" == $atts['show_image'] ? true : false;
     $show_location = "true" == $atts['show_location'] ? true : false;
     $show_start_date = "true" == $atts['show_start_date'] ? true : false;
     $show_end_date = "true" == $atts['show_end_date'] ? true : false;
     $timestamp_format = get_option('date_format') . ' ' . get_option('time_format');
     $date_threshold = $atts['starting_from'] ? strtotime($atts['starting_from']) : false;
     if ($atts['only_future'] && 'false' != $atts['only_future']) {
         $now = time();
         $date_threshold = $date_threshold && $date_threshold > $now ? $date_threshold : $now;
     }
     $current_tz = function_exists('date_default_timezone_get') ? @date_default_timezone_get() : 'UTC';
     ob_start();
     foreach ($events as $event) {
         if (function_exists('date_default_timezone_set') && !empty($event['timezone'])) {
             $start_time = strtotime($event['start_time']);
             $end_time = strtotime($event['end_time']);
             date_default_timezone_set($event['timezone']);
             $event['start_time'] = date('Y-m-d H:i:s', $start_time);
             $event['end_time'] = date('Y-m-d H:i:s', $end_time);
             date_default_timezone_set($current_tz);
         }
         if ($date_threshold > strtotime($event['start_time'])) {
             continue;
         }
         include WDFB_PLUGIN_BASE_DIR . '/lib/forms/event_item.php';
     }
     $ret = ob_get_contents();
     ob_end_clean();
     return "<div><ul>{$ret}</ul></div>";
 }
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     $for = $instance['for'];
     $limit = (int) $instance['limit'];
     $show_image = (int) $instance['show_image'];
     $show_location = (int) $instance['show_location'];
     $show_start_date = (int) $instance['show_start_date'];
     $show_end_date = (int) $instance['show_end_date'];
     $date_threshold = $instance['date_threshold'];
     $only_future = $instance['only_future'];
     $reverse_order = $instance['reverse_order'];
     $date_threshold = $date_threshold ? strtotime($date_threshold) : false;
     $now = time();
     if ($only_future) {
         $date_threshold = $date_threshold && $date_threshold > $now ? $date_threshold : $now;
     }
     $api = new Wdfb_EventsBuffer();
     $events = $api->get_for($for, $limit);
     $events = is_array($events) ? $events : array();
     usort($events, array($this, 'sort_events_by_start_time'));
     if ($reverse_order) {
         $events = array_reverse($events);
     }
     $timestamp_format = get_option('date_format') . ' ' . get_option('time_format');
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     if (is_array($events) && !empty($events)) {
         $current_tz = function_exists('date_default_timezone_get') ? @date_default_timezone_get() : 'UTC';
         echo '<ul class="wdfb_widget_events">';
         foreach ($events as $idx => $event) {
             if (function_exists('date_default_timezone_set') && !empty($event['timezone'])) {
                 $start_time = strtotime($event['start_time']);
                 $end_time = strtotime($event['end_time']);
                 date_default_timezone_set($event['timezone']);
                 $event['start_time'] = date('Y-m-d H:i:s', $start_time);
                 $event['end_time'] = date('Y-m-d H:i:s', $end_time);
                 date_default_timezone_set($current_tz);
             }
             if ($date_threshold > strtotime($event['start_time'])) {
                 continue;
             }
             if ($idx >= $limit) {
                 break;
             }
             include WDFB_PLUGIN_BASE_DIR . '/lib/forms/event_item.php';
         }
         echo '</ul>';
     }
     echo $after_widget;
 }