1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | class EventPost_List extends WP_Widget { |
8: | var $defaults; |
9: | function __construct() { |
10: | parent::__construct(false, __( 'Events', 'event-post' ),array('description'=>__( 'List of future events posts', 'event-post' ))); |
11: | $this->defaults = array( |
12: | 'numberposts' => '', |
13: | 'widgettitle' => '', |
14: | 'cat' => '', |
15: | 'tag' => '', |
16: | 'future' => 0, |
17: | 'past' => 0, |
18: | 'thumbnail' => 0, |
19: | 'thumbnail_size' => '', |
20: | 'excerpt' => 0, |
21: | 'feed' => 0, |
22: | 'order' => 'ASC', |
23: | ); |
24: | |
25: | } |
26: | function EventPost_List(){ |
27: | $this->__construct(); |
28: | } |
29: | function widget($args, $local_instance) { |
30: | if(!defined('ALLOW_DEPRECATED') || !ALLOW_DEPRECATED){ |
31: | _deprecated_function(__FUNCTION__, '5.9.0', __('Legacy widgets have been deprecated. Consider using blocks instead.', 'event-post')); |
32: | } |
33: | extract( $args ); |
34: | $instance = wp_parse_args( (array) $local_instance, $this->defaults ); |
35: | |
36: | global $EventPost; |
37: | $numberposts = intval($instance['numberposts']); |
38: | $future = intval($instance['future']); |
39: | $past = intval($instance['past']); |
40: | $cat = sanitize_text_field($instance['cat']); |
41: | $tag = sanitize_text_field($instance['tag']); |
42: | $order = sanitize_text_field($instance['order']); |
43: | |
44: | $events = $EventPost->get_events( |
45: | array( |
46: | 'nb'=>$numberposts, |
47: | 'future'=>$future, |
48: | 'past'=>$past, |
49: | 'geo'=>0, |
50: | 'cat'=>$cat, |
51: | 'tag'=>$tag, |
52: | 'order'=>$order |
53: | ) |
54: | ); |
55: | if(count($events)==0){ |
56: | return; |
57: | } |
58: | |
59: | echo $args['before_widget']; |
60: | if(!empty($instance['widgettitle'])){ |
61: | echo $args['before_title']; |
62: | echo $instance['widgettitle']; |
63: | if(!empty($instance['cat']) && $instance['feed']){ |
64: | $feed_url = esc_url(admin_url('admin-ajax.php') . '?action=EventPostFeed&cat=' . $instance['cat']); |
65: | echo' <a href="'.$feed_url .'" title="'.sprintf(__('feed of %s', 'event-post'), $instance['cat']).'"><span class="dashicons dashicons-rss"></span></a>'; |
66: | } |
67: | echo $args['after_title']; |
68: | } |
69: | $atts=array( |
70: | 'events' => $events, |
71: | 'class' => 'eventpost_widget', |
72: | 'thumbnail' => esc_attr($instance['thumbnail']), |
73: | 'thumbnail_size' => esc_attr($instance['thumbnail_size']), |
74: | 'excerpt' => esc_attr($instance['excerpt']), |
75: | 'order' => $order |
76: | ); |
77: | echo $EventPost->list_events($atts, 'event_list', 'widget'); |
78: | echo $args['after_widget']; |
79: | } |
80: | |
81: | function update($new_instance, $old_instance) { |
82: | return $new_instance; |
83: | } |
84: | |
85: | function form($local_instance) { |
86: | global $EventPost; |
87: | $instance = wp_parse_args( (array) $local_instance, $this->defaults ); |
88: | |
89: | $cats = get_categories(); |
90: | $tags = get_tags(); |
91: | $thumbnail_sizes = $EventPost->get_thumbnail_sizes(); |
92: | ?> |
93: | <input type="hidden" id="<?php echo $this->get_field_id('widgettitle'); ?>-title" value="<?php echo $instance['widgettitle']; ?>"> |
94: | <p> |
95: | <label for="<?php echo $this->get_field_id('widgettitle'); ?>"><?php _e('Title','event-post'); ?> |
96: | <input class="widefat" id="<?php echo $this->get_field_id('widgettitle'); ?>" name="<?php echo $this->get_field_name('widgettitle'); ?>" type="text" value="<?php echo $instance['widgettitle']; ?>" /> |
97: | </label> |
98: | </p> |
99: | |
100: | <p style="margin-top:10px;"> |
101: | <label for="<?php echo $this->get_field_id('numberposts'); ?>"><?php _e('Number of posts','event-post'); ?> |
102: | <input id="<?php echo $this->get_field_id('numberposts'); ?>" name="<?php echo $this->get_field_name('numberposts'); ?>" type="number" value="<?php echo $instance['numberposts']; ?>" /> |
103: | </label> <?php _e('(-1 is no limit)','event-post'); ?> |
104: | </p> |
105: | |
106: | |
107: | <p style="margin-top:10px;"> |
108: | <label for="<?php echo $this->get_field_id('future'); ?>"> |
109: | <input id="<?php echo $this->get_field_id('future'); ?>" name="<?php echo $this->get_field_name('future'); ?>" type="checkbox" value="1" <?php checked($instance['future'], true, true); ?> /> |
110: | <?php _e('Display future events','event-post'); ?> |
111: | </label> |
112: | </p> |
113: | <p style="margin-top:10px;"> |
114: | <label for="<?php echo $this->get_field_id('past'); ?>"> |
115: | <input id="<?php echo $this->get_field_id('past'); ?>" name="<?php echo $this->get_field_name('past'); ?>" type="checkbox" value="1" <?php checked($instance['past'], true, true); ?> /> |
116: | <?php _e('Display past events','event-post'); ?> |
117: | </label> |
118: | </p> |
119: | |
120: | <p> |
121: | <label for="<?php echo $this->get_field_id('cat'); ?>"> |
122: | <span class="dashicons dashicons-category"></span> |
123: | <?php _e('Only in:','event-post'); ?> |
124: | <select class="widefat" id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>"> |
125: | <option value=''><?php _e('All categories','event-post') ?></option> |
126: | <?php foreach($cats as $_cat){ ?> |
127: | <option value="<?php echo $_cat->slug; ?>" <?php selected($_cat->slug, $instance['cat'], true); ?>><?php echo $_cat->cat_name; ?></option> |
128: | <?php } ?> |
129: | </select> |
130: | </label> |
131: | </p> |
132: | |
133: | <p style="margin-top:10px;"> |
134: | <label for="<?php echo $this->get_field_id('feed'); ?>"> |
135: | <input id="<?php echo $this->get_field_id('feed'); ?>" name="<?php echo $this->get_field_name('feed'); ?>" type="checkbox" value="1" <?php checked($instance['feed'], true, true); ?> /> |
136: | <?php _e('Show category ICS link','event-post'); ?> |
137: | </label> |
138: | </p> |
139: | <hr> |
140: | |
141: | <p> |
142: | <label for="<?php echo $this->get_field_id('tag'); ?>"> |
143: | <span class="dashicons dashicons-tag"></span> |
144: | <?php _e('Only in:','event-post'); ?> |
145: | <select class="widefat" id="<?php echo $this->get_field_id('tag'); ?>" name="<?php echo $this->get_field_name('tag'); ?>"> |
146: | <option value=''><?php _e('All tags','event-post') ?></option> |
147: | <?php foreach($tags as $_tag){?> |
148: | <option value="<?php echo $_tag->slug; ?>" <?php selected($_tag->slug, $instance['tag'], true); ?>><?php echo $_tag->name; ?></option> |
149: | <?php } ?> |
150: | </select> |
151: | </label> |
152: | </p> |
153: | |
154: | <hr> |
155: | <p style="margin-top:10px;"> |
156: | <label for="<?php echo $this->get_field_id('thumbnail'); ?>"> |
157: | <input id="<?php echo $this->get_field_id('thumbnail'); ?>" name="<?php echo $this->get_field_name('thumbnail'); ?>" type="checkbox" value="1" <?php checked($instance['thumbnail'], true, true); ?> /> |
158: | <?php _e('Show thumbnails','event-post'); ?> |
159: | </label> |
160: | </p> |
161: | <p> |
162: | <label for="<?php echo $this->get_field_id('thumbnail_size'); ?>"> |
163: | <?php _e('Thumbnail size:','event-post'); ?> |
164: | <select class="widefat" id="<?php echo $this->get_field_id('thumbnail_size'); ?>" name="<?php echo $this->get_field_name('thumbnail_size'); ?>"> |
165: | <option value=''></option> |
166: | <?php foreach($thumbnail_sizes as $size){?> |
167: | <option value="<?php echo $size; ?>" <?php selected($size, $instance['thumbnail_size'], true); ?>><?php echo $size; ?></option> |
168: | <?php } ?> |
169: | </select> |
170: | </label> |
171: | </p> |
172: | |
173: | |
174: | <p style="margin-top:10px;"> |
175: | <label for="<?php echo $this->get_field_id('excerpt'); ?>"> |
176: | <input id="<?php echo $this->get_field_id('excerpt'); ?>" name="<?php echo $this->get_field_name('excerpt'); ?>" type="checkbox" value="1" <?php checked($instance['excerpt'], true, true); ?> /> |
177: | <?php _e('Show excerpt','event-post'); ?> |
178: | </label> |
179: | </p> |
180: | |
181: | <p> |
182: | <label for="<?php echo $this->get_field_id('order'); ?>"> |
183: | <?php _e('Order:','event-post'); ?> |
184: | <select class="widefat" id="<?php echo $this->get_field_id('order'); ?>" name="<?php echo $this->get_field_name('order'); ?>"> |
185: | <option value='DESC' <?php selected('DESC', $instance['order'], true); ?>><?php _e('Reverse chronological','event-post') ?></option> |
186: | <option value='ASC' <?php selected('ASC', $instance['order'], true); ?>><?php _e('Chronological','event-post') ?></option> |
187: | </select> |
188: | </label> |
189: | </p> |
190: | <?php |
191: | } |
192: | |
193: | } |
194: | |