PluginProbe
Event Post / 5.0
Event Post v5.0
6.1.1 6.1.0 6.0.1 6.0.0 5.12.0 trunk 3.9 4.0 4.2 4.3 4.4 4.5 5.0 5.1 5.10.0 5.10.1 5.10.2 5.10.3 5.10.4 5.11.0 5.11.1 5.2 5.5 5.6 5.6.1 All 46 releases
event-post / inc / shortcodes.php

shortcodes.php in Event Post 5.0, at inc/shortcodes.php

459 lines 16.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Implements all shortcodes features
5 */
6 class EventPost_Shortcodes{
7 public $EP;
8
9 function __construct() {
10 //Shortcodes
11 add_action('init', array(&$this,'init'));
12 add_shortcode('events_list', array(&$this, 'shortcode_list'));
13 add_shortcode('events_map', array(&$this, 'shortcode_map'));
14 add_shortcode('events_cal', array(&$this, 'shortcode_cal'));
15 add_shortcode('event_details', array(&$this, 'shortcode_single'));
16 add_shortcode('event_term', array(&$this, 'shortcode_term'));
17 add_shortcode('event_cat', array(&$this, 'shortcode_cat'));
18 add_shortcode('event_search', array(&$this, 'shortcode_search'));
19 // Workaround for ACF select2 bug
20 // see: https://github.com/wp-shortcake/shortcake/issues/660
21 add_filter( 'acf/settings/select2_version', array(&$this, 'return4'));
22 }
23
24 /**
25 * Call functions when WP is ready
26 */
27 public function init(){
28 global $EventPost;
29 $this->EP = $EventPost;
30 $this->shortcode_ui();
31 }
32
33 public function return4(){
34 return 4;
35 }
36
37 /**
38 * shortcode_single
39 * @param array $atts
40 * @filter : eventpost_params
41 * @return string
42 */
43 public function shortcode_single($atts){
44 extract(shortcode_atts(apply_filters('eventpost_params', array(
45 'attribute' => '',
46 ), 'shortcode_single'), $atts));
47 $event = $this->EP->retreive();
48 switch($attribute){
49 case 'start':
50 return $this->EP->human_date($event->time_start);
51 case 'end':
52 return $this->EP->human_date($event->time_end);
53 case 'address':
54 return $event->address;
55 case 'location':
56 return $this->EP->get_singleloc($event, '', 'single');
57 case 'date':
58 return $this->EP->get_singledate($event, '', 'single');
59 default:
60 return $this->EP->get_single($event, '', 'single');
61 }
62 }
63
64 /**
65 *
66 * @param array $atts
67 * @return string
68 */
69 public function shortcode_term($atts){
70 extract(shortcode_atts(apply_filters('eventpost_params', array(
71 'tax' => null,
72 'term' => null,
73 'post_type' => null,
74 ), 'shortcode_term'), $atts));
75 if(false !== $the_term = $this->EP->retreive_term($term, $tax, $post_type)){
76 return $this->EP->delta_date($the_term->time_start, $the_term->time_end);
77 }
78 }
79 public function shortcode_cat($_atts){
80 $atts = shortcode_atts(array(
81 'cat' => null,
82 ), $_atts);
83 $atts['tax']='category';
84 $atts['post_type']='post';
85 $atts['term']=$atts['cat'];
86 unset($atts['cat']);
87 return $this->shortcode_term($atts);
88 }
89
90 /**
91 * Shortcode to display a list of events
92 *
93 ### Query parameters
94
95 - **nb=5** *(number of post, -1 is all, default: 5)*
96 - **future=1** *(boolean, retreive, or not, events in the future, default = 1)*
97 - **past=0** *(boolean, retreive, or not, events in the past, default = 0)*
98 - **cat=''** *(string, select posts only from the selected category, default=null, for all categories)*
99 - **tag=''** *(string, select posts only from the selected tag, default=null, for all tags)*
100 - **geo=0** *(boolean, retreives or not, only events wich have geolocation informations, default=0)*
101 - **order="ASC"** *(string (can be "ASC" or "DESC")*
102 - **orderby="meta_value"** *(string (if set to "meta_value" events are sorted by event date, possible values are native posts fileds : "post_title","post_date" etc...)*
103
104 ### Display parameters
105
106 - **thumbnail=""** * (Bool, default:false, used to display posts thumbnails)*
107 - **thumbnail_size=""** * (String, default:"thmbnail", can be set to any existing size : "medium","large","full" etc...)*
108 - **excerpt=""** * (Bool, default:false, used to display posts excerpts)*
109 - **style=""** * (String, add some inline CSS to the list wrapper)*
110 - **type=div** *(string, possible values are : div, ul, ol default=div)*
111 - **title=''** *(string, hidden if no events is found)*
112 - **before_title="&lt;h3&gt;"** *(string (default &lt;h3&gt;)*
113 - **after_title="&lt;/h3&gt;"** *(string (default &lt;/h3&gt;)*
114 - **container_schema=""** *(string html schema to display list)*
115 - **item_schema=""** *(string html schema to display item)*
116 *
117 * @param array $_atts
118 * @filter eventpost_params
119 * @return string
120 */
121 public function shortcode_list($_atts) {
122 $atts = shortcode_atts(apply_filters('eventpost_params', array(
123 // Filters
124 'nb' => 0,
125 'type' => 'div',
126 'future' => true,
127 'past' => false,
128 'geo' => 0,
129 'cat' => '',
130 'tag' => '',
131 'orderby' => 'meta_value',
132 'order' => 'ASC',
133 'title' => '',
134 // Display
135 'before_title' => '<h3>',
136 'after_title' => '</h3>',
137 'thumbnail' => '',
138 'thumbnail_size' => '',
139 'excerpt' => '',
140 'width' => '',
141 'height' => 'auto',
142 'style' => '',
143 'container_schema' => $this->EP->list_shema['container'],
144 'item_schema' => $this->EP->list_shema['item'],
145 ), 'shortcode_list'), $_atts);
146
147 if ($atts['container_schema'] != $this->EP->list_shema['container'])
148 $atts['container_schema'] = html_entity_decode($atts['container_schema']);
149 if ($atts['item_schema'] != $this->EP->list_shema['item'])
150 $atts['item_schema'] = html_entity_decode($atts['item_schema']);
151 return $this->EP->list_events($atts, 'event_list', 'shortcode');
152 }
153
154 /**
155 * Shortcode to display a map of events
156 * @param array $_atts
157 * @filter eventpost_params
158 * @return string
159 */
160 public function shortcode_map($_atts) {
161 $ep_settings = $this->EP->settings;
162
163 $defaults = array(
164 // Display
165 'width' => '',
166 'height' => '',
167 'tile' => $ep_settings['tile'],
168 'title' => '',
169 'before_title' => '<h3>',
170 'after_title' => '</h3>',
171 'style' => '',
172 'thumbnail' => '',
173 'thumbnail_size' => '',
174 'excerpt' => '',
175 'zoom'=>'',
176 // Filters
177 'nb' => 0,
178 'future' => true,
179 'past' => false,
180 'cat' => '',
181 'tag' => '',
182 'orderby' => 'meta_value',
183 'order' => 'ASC',
184 );
185 // UI options
186 foreach($this->EP->map_interactions as $int_key=>$int_name){
187 $defaults[$int_key]=true;
188 }
189 // - UI options
190 foreach($this->EP->map_interactions as $int_key=>$int_name){
191 $defaults['disable_'.strtolower($int_key)]=false;
192 }
193
194 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $_atts);
195 // UI options
196 foreach($this->EP->map_interactions as $int_key=>$int_name){
197 if($atts['disable_'.strtolower($int_key)]==true){
198 $atts[$int_key]=false;
199 }
200 unset($atts['disable_'.strtolower($int_key)]);
201 }
202 $atts['geo'] = 1;
203 $atts['type'] = 'div';
204 return $this->EP->list_events($atts, 'event_geolist', 'shortcode'); //$nb,'div',$future,$past,1,'event_geolist');
205 }
206
207 /**
208 * Shortcode to display a calendar of events
209 * @param array $_atts
210 * @filter eventpost_params
211 * @return string
212 */
213 public function shortcode_cal($_atts) {
214 $this->EP->load_scripts();
215 $atts = shortcode_atts(apply_filters('eventpost_params', array(
216 'date' => date('Y-n'),
217 'cat' => '',
218 'mondayfirst' => 0, //1 : weeks starts on monday
219 'datepicker' => 1
220 ), 'shortcode_cal'), $_atts);
221 extract($atts);
222 return '<div class="eventpost_calendar" data-cat="' . $cat . '" data-date="' . $date . '" data-mf="' . $mondayfirst . '" data-dp="' . $datepicker . '">' . $this->EP->calendar($atts) . '</div>';
223 }
224
225 /**
226 *
227 * @param type $_atts
228 * @return type
229 */
230 public function shortcode_search($_atts){
231 return $this->EP->search($_atts);
232 }
233
234 /**
235 * set_shortcode_ui
236 * needs Shortcake (shortcode UI) plugin
237 * https://wordpress.org/plugins/shortcode-ui/
238 */
239 public function shortcode_ui(){
240 if(!function_exists('shortcode_ui_register_for_shortcode')){
241 return;
242 }
243 $shortcodes_list_atts=array(
244 'label' => __('Events list','event-post'),
245 'listItemImage' => 'dashicons-calendar',
246 'post_type'=>array('page','post'),
247 'attrs' => array(
248 0=>array(
249 'label' => __('Number of posts','event-post'),
250 'attr' => 'nb',
251 'type' => 'number',
252 'description' => __('-1 is for: no limit','event-post')
253 ),
254 1=>array(
255 'label' => __('Categories','event-post'),
256 'attr' => 'cat',
257 'type' => 'term_select',
258 'taxonomy' => 'category',
259 'multiple' => true,
260 ),
261 2=>array(
262 'label' => __('Tags','event-post'),
263 'attr' => 'tag',
264 'type' => 'term_select',
265 'taxonomy' => 'post_tag',
266 'multiple' => true,
267 ),
268 3=>array(
269 'label' => __('Future events:','event-post'),
270 'attr' => 'future',
271 'type' => 'select',
272 'options' => array(
273 '1' => __('Yes','event-post'),
274 '0' => __('No','event-post'),
275 ),
276 ),
277 4=>array(
278 'label' => __('Past events:','event-post'),
279 'attr' => 'past',
280 'type' => 'select',
281 'options' => array(
282 '1' => __('Yes','event-post'),
283 '0' => __('No','event-post'),
284 ),
285 ),
286 5=>array(
287 'label' => __('Only geotagged events:','event-post'),
288 'attr' => 'geo',
289 'type' => 'select',
290 'options' => array(
291 '1' => __('Yes','event-post'),
292 '0' => __('No','event-post'),
293 ),
294 ),
295 6=>array(
296 'label' => __('Thumbnail:','event-post'),
297 'attr' => 'thumbnail',
298 'type' => 'select',
299 'options' => array(
300 '1' => __('Yes','event-post'),
301 '0' => __('No','event-post'),
302 ),
303 ),
304 7=>array(
305 'label' => __('Thumbnail size:','event-post'),
306 'attr' => 'thumbnail_size',
307 'type' => 'select',
308 'options' => array(
309 'thumbnail' => __('Thumbnail'),
310 'medium' => __('Medium'),
311 'large' => __('Large'),
312 ),
313 ),
314 8=>array(
315 'label' => __('Order by:','event-post'),
316 'attr' => 'orderby',
317 'type' => 'select',
318 'options' => array(
319 'meta_value' => __('Date'),
320 'title' => __('Title'),
321 ),
322 ),
323 9=>array(
324 'label' => __('Order:','event-post'),
325 'attr' => 'order',
326 'type' => 'select',
327 'options' => array(
328 'ASC' => __('Asc.'),
329 'DESC' => __('Desc.'),
330 ),
331 ),
332 ),
333 );
334 /*
335 * Map
336 */
337 $shortcodes_map_atts = $shortcodes_list_atts;
338 unset($shortcodes_map_atts['attrs'][5]); // Remove geotagged attr
339 unset($shortcodes_map_atts['attrs'][8]); // Remove orderby attr
340 unset($shortcodes_map_atts['attrs'][9]); // Remove order attr
341 array_unshift($shortcodes_map_atts['attrs'],
342 array(
343 'label' => __('Width','event-post'),
344 'attr' => 'width',
345 'type' => 'text',
346 ),
347 array(
348 'label' => __('Height','event-post'),
349 'attr' => 'height',
350 'type' => 'text',
351 ),
352 array(
353 'label' => __('Zoom','event-post'),
354 'attr' => 'zoom',
355 'type' => 'number',
356 )
357 );
358 $shortcodes_map_atts['label']=__('Events map','event-post');
359 $shortcodes_map_atts['listItemImage']='dashicons-location-alt';
360 foreach($this->EP->map_interactions as $int_key=>$int_name){
361 $shortcodes_map_atts['attrs'][]=array(
362 'label' => sprintf(__('Disable %s interaction','event-post'), $int_name),
363 'attr' => 'disable_'.$int_key,
364 'type' => 'checkbox'
365 );
366 }
367 shortcode_ui_register_for_shortcode('events_list', apply_filters('eventpost_shortcodeui_list',$shortcodes_list_atts));
368 shortcode_ui_register_for_shortcode('events_map', apply_filters('eventpost_shortcodeui_map',$shortcodes_map_atts));
369
370 /*
371 * Calendar
372 */
373 $shortcodes_cal_atts=array(
374 'label' => __('Events calendar','event-post'),
375 'listItemImage' => 'dashicons-calendar-alt',
376 'post_type'=>array('page','post'),
377 'attrs' => array(
378 array(
379 'label' => __('Default date','event-post'),
380 'attr' => 'date',
381 'type' => 'text',
382 'description' => date('Y-n')
383 ),
384 array(
385 'label' => __('Categories','event-post'),
386 'attr' => 'cat',
387 'type' => 'text',
388 ),
389 array(
390 'label' => __('Monday first','event-post'),
391 'attr' => 'mondayfirst',
392 'type' => 'checkbox',
393 ),
394 array(
395 'label' => __('Date selector','event-post'),
396 'attr' => 'choose',
397 'type' => 'checkbox',
398 )
399 )
400 );
401 shortcode_ui_register_for_shortcode('events_cal', apply_filters('eventpost_shortcodeui_cal',$shortcodes_cal_atts));
402 /*
403 * Details
404 */
405 $shortcodes_details_atts=array(
406 'label' => __('Event details','event-post'),
407 'listItemImage' => 'dashicons-clock',
408 'attrs' => array(
409 array(
410 'label' => __('Attribute','event-post'),
411 'attr' => 'attribute',
412 'type' => 'select',
413 'options' => array(
414 '' => __('Full details','event-post'),
415 'date' => __('Full date','event-post'),
416 'start' => __('Begin date','event-post'),
417 'end' => __('End date','event-post'),
418 'address' => __('Address text','event-post'),
419 'location' => __('Location','event-post'),
420 ),
421 ),
422 )
423 );
424 shortcode_ui_register_for_shortcode('event_details', apply_filters('eventpost_shortcodeui_details',$shortcodes_details_atts));
425
426
427 /*
428 * Search
429 */
430 $shortcodes_search_atts=array(
431 'label' => __('Events search form','event-post'),
432 'listItemImage' => 'dashicons-search',
433 'attrs' => array(
434 array(
435 'label' => __('Keywords','event-post'),
436 'attr' => 'q',
437 'type' => 'select',
438 'options' => array(
439 '1' => __('Yes','event-post'),
440 '0' => __('No','event-post'),
441 ),
442 ),
443 array(
444 'label' => __('Dates','event-post'),
445 'attr' => 'dates',
446 'type' => 'select',
447 'options' => array(
448 '1' => __('Yes','event-post'),
449 '0' => __('No','event-post'),
450 ),
451
452 ),
453 )
454 );
455 shortcode_ui_register_for_shortcode('event_search', apply_filters('eventpost_shortcodeui_search',$shortcodes_search_atts));
456
457 }
458 }
459