PluginProbe
Event Post / 4.2
Event Post v4.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 / shortcodes.php

shortcodes.php in Event Post 4.2, at shortcodes.php

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