SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | if( !class_exists( 'Events_List_Widget' ) ) {
| |
| 3 | /** | |
| 4 | * Event List Widget | |
| 5 | * | |
| 6 | * Creates a widget that displays the next upcoming x events | |
| 7 | */ | |
| 8 | ||
| 9 | class Events_List_Widget extends WP_Widget {
| |
| 10 | ||
| 11 | public $pluginDomain = 'the-events-calendar'; | |
| 12 | ||
| 13 | function Events_List_Widget() {
| |
| 14 | /* Widget settings. */ | |
| 15 | $widget_ops = array( 'classname' => 'eventsListWidget', 'description' => __( 'A widget that displays the next upcoming x events.', $this->pluginDomain) ); | |
| 16 | ||
| 17 | /* Widget control settings. */ | |
| 18 | $control_ops = array( 'id_base' => 'events-list-widget' ); | |
| 19 | ||
| 20 | /* Create the widget. */ | |
| 21 | $this->WP_Widget( 'events-list-widget', 'Events List Widget', $widget_ops, $control_ops ); | |
| 22 | } | |
| 23 | ||
| 24 | function widget( $args, $instance ) {
| |
| 25 | global $wp_query, $sp_ecp, $post; | |
| 26 | $old_post = $post; | |
| 27 | extract( $args, EXTR_SKIP ); | |
| 28 | extract( $instance, EXTR_SKIP ); | |
| 29 | // extracting $instance provides $title, $limit, $no_upcoming_events, $start, $end, $venue, $address, $city, $state, $province'], $zip, $country, $phone , $cost | |
| 30 | $title = apply_filters('widget_title', $title );
| |
| 31 | ||
| 32 | if ( sp_get_option('viewOption') == 'upcoming') {
| |
| 33 | $event_url = sp_get_listview_link(); | |
| 34 | } else {
| |
| 35 | $event_url = sp_get_gridview_link(); | |
| 36 | } | |
| 37 | ||
| 38 | if( function_exists( 'sp_get_events' ) ) {
| |
| 39 | $old_display = $wp_query->get('eventDisplay');
| |
| 40 | $wp_query->set('eventDisplay', 'upcoming');
| |
| 41 | $posts = sp_get_events( 'numResults=' . $limit .'&eventCat=' . $category ); | |
| 42 | $template = $sp_ecp->getTemplateHierarchy('events-list-load-widget-display');
| |
| 43 | } | |
| 44 | ||
| 45 | // if no posts, and the don't show if no posts checked, let's bail | |
| 46 | if ( ! $posts && $no_upcoming_events ) {
| |
| 47 | return; | |
| 48 | } | |
| 49 | ||
| 50 | /* Before widget (defined by themes). */ | |
| 51 | echo $before_widget; | |
| 52 | ||
| 53 | /* Title of widget (before and after defined by themes). */ | |
| 54 | echo ( $title ) ? $before_title . $title . $after_title : ''; | |
| 55 | ||
| 56 | if ( $posts ) {
| |
| 57 | /* Display list of events. */ | |
| 58 | echo "<ul class='two-col-special'>"; | |
| 59 | echo "<li>"; | |
| 60 | foreach( $posts as $post ) : | |
| 61 | setup_postdata($post); | |
| 62 | include $template; | |
| 63 | endforeach; | |
| 64 | echo "</li>"; | |
| 65 | echo "</ul>"; | |
| 66 | ||
| 67 | $wp_query->set('eventDisplay', $old_display);
| |
| 68 | ||
| 69 | /* Display link to all events */ | |
| 70 | echo '<div class="dig-in"><a href="' . $event_url . '">' . __('View All Events', $this->pluginDomain ) . '</a></div>';
| |
| 71 | } | |
| 72 | else {
| |
| 73 | _e('There are no upcoming events at this time.', $this->pluginDomain);
| |
| 74 | } | |
| 75 | ||
| 76 | /* After widget (defined by themes). */ | |
| 77 | echo $after_widget; | |
| 78 | $post = $old_post; | |
| 79 | } | |
| 80 | ||
| 81 | function update( $new_instance, $old_instance ) {
| |
| 82 | $instance = $old_instance; | |
| 83 | ||
| 84 | /* Strip tags (if needed) and update the widget settings. */ | |
| 85 | $instance['title'] = strip_tags( $new_instance['title'] ); | |
| 86 | $instance['limit'] = $new_instance['limit']; | |
| 87 | $instance['no_upcoming_events'] = $new_instance['no_upcoming_events']; | |
| 88 | $instance['start'] = $new_instance['start']; | |
| 89 | $instance['end'] = $new_instance['end']; | |
| 90 | $instance['venue'] = $new_instance['venue']; | |
| 91 | $instance['country'] = $new_instance['country']; | |
| 92 | $instance['address'] = $new_instance['address']; | |
| 93 | $instance['city'] = $new_instance['city']; | |
| 94 | $instance['region'] = $new_instance['region']; | |
| 95 | $instance['zip'] = $new_instance['zip']; | |
| 96 | $instance['phone'] = $new_instance['phone']; | |
| 97 | $instance['cost'] = $new_instance['cost']; | |
| 98 | $instance['category'] = $new_instance['category']; | |
| 99 | ||
| 100 | return $instance; | |
| 101 | } | |
| 102 | ||
| 103 | function form( $instance ) {
| |
| 104 | /* Set up default widget settings. */ | |
| 105 | $defaults = array( 'title' => 'Upcoming Events', 'limit' => '5', 'start' => true, 'end' => false, 'venue' => false, 'country' => true, 'address' => false, 'city' => true, 'region' => true, 'zip' => false, 'phone' => false, 'cost' => false,'category' => false); | |
| 106 | $instance = wp_parse_args( (array) $instance, $defaults ); | |
| 107 | include( $sp_ecp->pluginPath . 'views/events-list-load-widget-admin.php' ); | |
| 108 | } | |
| 109 | } | |
| 110 | ||
| 111 | /* Add function to the widgets_ hook. */ | |
| 112 | add_action( 'widgets_init', 'events_list_load_widgets',100 ); | |
| 113 | ||
| 114 | /* Function that registers widget. */ | |
| 115 | function events_list_load_widgets() {
| |
| 116 | global $pluginDomain; | |
| 117 | register_widget( 'Events_List_Widget' ); | |
| 118 | // load text domain after class registration | |
| 119 | load_plugin_textdomain( 'the-events-calendar', false, basename(dirname(__FILE__)) . '/lang/'); | |
| 120 | } | |
| 121 | } |