PluginProbe
Event Post / 5.1
Event Post v5.1
6.1.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 All 47 releases
event-post / inc / shortcodes.php

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

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