PluginProbe
Event Post / 5.2
Event Post v5.2
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.2, at inc/shortcodes.php

482 lines 17.6 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 'list' => '0',
177 // Filters
178 'nb' => 0,
179 'future' => true,
180 'past' => false,
181 'cat' => '',
182 'tag' => '',
183 'orderby' => 'meta_value',
184 'order' => 'ASC',
185 );
186 // UI options
187 foreach($this->EP->map_interactions as $int_key=>$int_name){
188 $defaults[$int_key]=true;
189 }
190 // - UI options
191 foreach($this->EP->map_interactions as $int_key=>$int_name){
192 $defaults['disable_'.strtolower($int_key)]=false;
193 }
194
195 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $_atts);
196 // UI options
197 foreach($this->EP->map_interactions as $int_key=>$int_name){
198 if($atts['disable_'.strtolower($int_key)]==true){
199 $atts[$int_key]=false;
200 }
201 unset($atts['disable_'.strtolower($int_key)]);
202 }
203 $atts['geo'] = 1;
204 $atts['type'] = 'div';
205 return $this->EP->list_events($atts, 'event_geolist', 'shortcode'); //$nb,'div',$future,$past,1,'event_geolist');
206 }
207
208 /**
209 * Shortcode to display a calendar of events
210 * @param array $_atts
211 * @filter eventpost_params
212 * @return string
213 */
214 public function shortcode_cal($_atts) {
215 $this->EP->load_scripts();
216 $atts = shortcode_atts(apply_filters('eventpost_params', array(
217 'date' => date('Y-n'),
218 'cat' => '',
219 'mondayfirst' => 0, //1 : weeks starts on monday
220 'display_title' => 0,
221 'datepicker' => 1,
222 'thumbnail' => '',
223 ), 'shortcode_cal'), $_atts);
224 extract($atts);
225 return '<div class="eventpost_calendar" data-cat="' . $cat . '" data-date="' . $date . '" data-mf="' . $mondayfirst . '" data-dp="' . $datepicker . '" data-title="'. $display_title .'">' . $this->EP->calendar($atts) . '</div>';
226 }
227
228 /**
229 *
230 * @param type $_atts
231 * @return type
232 */
233 public function shortcode_search($_atts){
234 return $this->EP->search($_atts);
235 }
236
237 /**
238 * set_shortcode_ui
239 * needs Shortcake (shortcode UI) plugin
240 * https://wordpress.org/plugins/shortcode-ui/
241 */
242 public function shortcode_ui(){
243 if(!function_exists('shortcode_ui_register_for_shortcode')){
244 return;
245 }
246 // In gutenberg, prefers native integration
247 if(function_exists('gutenberg_pre_init')){
248 return;
249 }
250 $shortcodes_list_atts=array(
251 'label' => __('Events list','event-post'),
252 'listItemImage' => 'dashicons-calendar',
253 'post_type'=>array('page','post'),
254 'attrs' => array(
255 0=>array(
256 'label' => __('Max. number of events:','event-post'),
257 'attr' => 'nb',
258 'type' => 'number',
259 'description' => __('-1 is for: no limit','event-post')
260 ),
261 1=>array(
262 'label' => __('Categories','event-post'),
263 'attr' => 'cat',
264 'type' => 'term_select',
265 'taxonomy' => 'category',
266 'multiple' => true,
267 'help' => __('Categories, separated by comma', 'event-post'),
268 ),
269 2=>array(
270 'label' => __('Tags','event-post'),
271 'attr' => 'tag',
272 'type' => 'term_select',
273 'taxonomy' => 'post_tag',
274 'multiple' => true,
275 'help' => __('Tags, separated by comma', 'event-post'),
276 ),
277 3=>array(
278 'label' => __('Display upcoming events','event-post'),
279 'attr' => 'future',
280 'type' => 'select',
281 'options' => array(
282 '1' => __('Yes','event-post'),
283 '0' => __('No','event-post'),
284 ),
285 ),
286 4=>array(
287 'label' => __('Display past events','event-post'),
288 'attr' => 'past',
289 'type' => 'select',
290 'options' => array(
291 '1' => __('Yes','event-post'),
292 '0' => __('No','event-post'),
293 ),
294 ),
295 5=>array(
296 'label' => __('Only geotagged events:','event-post'),
297 'attr' => 'geo',
298 'type' => 'select',
299 'options' => array(
300 '1' => __('Yes','event-post'),
301 '0' => __('No','event-post'),
302 ),
303 ),
304 6=>array(
305 'label' => __('Thumbnail:','event-post'),
306 'attr' => 'thumbnail',
307 'type' => 'select',
308 'options' => array(
309 '1' => __('Yes','event-post'),
310 '0' => __('No','event-post'),
311 ),
312 ),
313 7=>array(
314 'label' => __('Thumbnail size:','event-post'),
315 'attr' => 'thumbnail_size',
316 'type' => 'select',
317 'options' => array(
318 'thumbnail' => __('Thumbnail'),
319 'medium' => __('Medium'),
320 'large' => __('Large'),
321 ),
322 ),
323 8=>array(
324 'label' => __('Order by:','event-post'),
325 'attr' => 'orderby',
326 'type' => 'select',
327 'options' => array(
328 'meta_value' => __('Date'),
329 'title' => __('Title'),
330 ),
331 ),
332 9=>array(
333 'label' => __('Order:','event-post'),
334 'attr' => 'order',
335 'type' => 'select',
336 'options' => array(
337 'ASC' => __('Asc.'),
338 'DESC' => __('Desc.'),
339 ),
340 ),
341 ),
342 );
343 /*
344 * Map
345 */
346 $shortcodes_map_atts = $shortcodes_list_atts;
347 unset($shortcodes_map_atts['attrs'][5]); // Remove geotagged attr
348 unset($shortcodes_map_atts['attrs'][8]); // Remove orderby attr
349 unset($shortcodes_map_atts['attrs'][9]); // Remove order attr
350 array_unshift($shortcodes_map_atts['attrs'],
351 array(
352 'label' => __('Width','event-post'),
353 'attr' => 'width',
354 'type' => 'text',
355 ),
356 array(
357 'label' => __('Height','event-post'),
358 'attr' => 'height',
359 'type' => 'text',
360 ),
361 array(
362 'label' => __('Zoom','event-post'),
363 'attr' => 'zoom',
364 'type' => 'number',
365 'help' => __('0 fits to all events', 'event-post')
366 ),
367 array(
368 'label' => __('List','event-post'),
369 'attr' => 'list',
370 'default' => '0',
371 'type' => 'select',
372 'options' => array(
373 '0' => __('No list','event-post'),
374 'left' => __('Left','event-post'),
375 'right' => __('Right','event-post'),
376 'above' => __('Above','event-post'),
377 'below' => __('Below','event-post'),
378 ),
379 )
380 );
381 $shortcodes_map_atts['label']=__('Events map','event-post');
382 $shortcodes_map_atts['listItemImage']='dashicons-location-alt';
383 foreach($this->EP->map_interactions as $int_key=>$int_name){
384 $shortcodes_map_atts['attrs'][]=array(
385 'label' => sprintf(__('Disable %s interaction','event-post'), $int_name),
386 'attr' => 'disable_'.$int_key,
387 'type' => 'checkbox'
388 );
389 }
390 shortcode_ui_register_for_shortcode('events_list', apply_filters('eventpost_shortcodeui_list',$shortcodes_list_atts));
391 shortcode_ui_register_for_shortcode('events_map', apply_filters('eventpost_shortcodeui_map',$shortcodes_map_atts));
392
393 /*
394 * Calendar
395 */
396 $shortcodes_cal_atts=array(
397 'label' => __('Events calendar','event-post'),
398 'listItemImage' => 'dashicons-calendar-alt',
399 'post_type'=>array('page','post'),
400 'attrs' => array(
401 array(
402 'label' => __('Default date','event-post'),
403 'attr' => 'date',
404 'type' => 'text',
405 'description' => date('Y-n')
406 ),
407 array(
408 'label' => __('Categories','event-post'),
409 'attr' => 'cat',
410 'type' => 'text',
411 ),
412 array(
413 'label' => __('Monday first','event-post'),
414 'attr' => 'mondayfirst',
415 'type' => 'checkbox',
416 ),
417 array(
418 'label' => __('Date selector','event-post'),
419 'attr' => 'choose',
420 'type' => 'checkbox',
421 )
422 )
423 );
424 shortcode_ui_register_for_shortcode('events_cal', apply_filters('eventpost_shortcodeui_cal',$shortcodes_cal_atts));
425 /*
426 * Details
427 */
428 $shortcodes_details_atts=array(
429 'label' => __('Event details','event-post'),
430 'listItemImage' => 'dashicons-clock',
431 'attrs' => array(
432 array(
433 'label' => __('Attribute','event-post'),
434 'attr' => 'attribute',
435 'type' => 'select',
436 'options' => array(
437 '' => __('Full details','event-post'),
438 'date' => __('Full date','event-post'),
439 'start' => __('Begin date','event-post'),
440 'end' => __('End date','event-post'),
441 'address' => __('Address text','event-post'),
442 'location' => __('Location','event-post'),
443 ),
444 ),
445 )
446 );
447 shortcode_ui_register_for_shortcode('event_details', apply_filters('eventpost_shortcodeui_details',$shortcodes_details_atts));
448
449
450 /*
451 * Search
452 */
453 $shortcodes_search_atts=array(
454 'label' => __('Events search form','event-post'),
455 'listItemImage' => 'dashicons-search',
456 'attrs' => array(
457 array(
458 'label' => __('Keywords','event-post'),
459 'attr' => 'q',
460 'type' => 'select',
461 'options' => array(
462 '1' => __('Yes','event-post'),
463 '0' => __('No','event-post'),
464 ),
465 ),
466 array(
467 'label' => __('Dates','event-post'),
468 'attr' => 'dates',
469 'type' => 'select',
470 'options' => array(
471 '1' => __('Yes','event-post'),
472 '0' => __('No','event-post'),
473 ),
474
475 ),
476 )
477 );
478 shortcode_ui_register_for_shortcode('event_search', apply_filters('eventpost_shortcodeui_search',$shortcodes_search_atts));
479
480 }
481 }
482