__('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 . _n(sprintf('(%d) Upcoming Event', $es), sprintf('(%d) Upcoming Events', $es), $es, AEC_PLUGIN_NAME) . $after_title; $out = ''; echo $out; echo $after_widget; } function get_events($duration, $category_id){ global $wpdb; $week = 604800; $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, category_id FROM ' . $wpdb->prefix . AEC_EVENT_TABLE . ' WHERE ((start >= "' . $start . '" AND start < "' . $end . '") OR (end >= "' . $start . '" AND end < "' . $end . '") OR (start < "' . $start . '" AND end > "' . $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']; ?>