__('Displays events upcoming in the following weeks.', AEC_PLUGIN_NAME)); parent::WP_Widget(false, __('Upcoming Events', AEC_PLUGIN_NAME), $widget_ops); } function widget($args, $instance){ extract($args, EXTR_SKIP); $weeks = ($instance['weeks']) ? apply_filters('widget_weeks', $instance['weeks']) : 3; $category = ($instance['category']) ? apply_filters('widget_category', $instance['category']) : 'all'; $events = $this->get_events($weeks, $category); echo $before_widget; $es = sizeof($events); echo $before_title . sprintf(_n('(%d) Upcoming Event','(%d) Upcoming Events', $es, AEC_PLUGIN_NAME), $es) . $after_title; $out = ''; echo $out; echo $after_widget; } function get_events($duration, $category_id){ global $wpdb; $week = 604800; // localize date using blog timezone date_default_timezone_set(get_option('timezone_string')); $start = date('Y-m-d'); $end = date('Y-m-d', strtotime($start) + ($duration * $week)); $andcategory = ($category_id=="all") ? '' : ' AND category_id = ' . $category_id; $results = $wpdb->get_results('SELECT id, title, start, end, allday as allDay, category_id FROM ' . $wpdb->prefix . AEC_EVENT_TABLE . ' WHERE start >= "' . $start . '" AND start < "' . $end . '"' . $andcategory . ' ORDER BY start;' ); if ($results !== false) return $results; } function get_categories(){ global $wpdb; $results = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . AEC_CATEGORY_TABLE . ' ORDER BY id;'); if ($results !== false) return $results; } function update($new_instance, $old_instance){ $instance = $old_instance; $instance['weeks'] = $new_instance['weeks']; $instance['category'] = $new_instance['category']; return $instance; } /** @see WP_Widget::form */ function form($instance){ $instance = wp_parse_args( (array) $instance, array( 'weeks' => '2', 'category' => 'all') ); $weeks = $instance['weeks']; $category = $instance['category']; ?>