PluginProbe
Event Post / 6.1.1
Event Post v6.1.1
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 / class-shortcodes.php

class-shortcodes.php in Event Post 6.1.1, at inc/class-shortcodes.php

383 lines 14.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Implements all shortcodes features
4 *
5 * @package event-post
6 * @version 6.1.1
7 * @since 5.0.0
8 */
9
10 namespace EventPost;
11
12 if ( ! defined( 'ABSPATH' ) ) exit;
13
14 class Shortcodes{
15
16 function __construct() {
17 //Shortcodes
18 add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_list'), array(&$this, 'shortcode_list'));
19 add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_timeline'), array(&$this, 'shortcode_timeline'));
20 add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_map'), array(&$this, 'shortcode_map'));
21 add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_cal'), array(&$this, 'shortcode_cal'));
22 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_details'), array(&$this, 'shortcode_single'));
23 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_term'), array(&$this, 'shortcode_term'));
24 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_cat'), array(&$this, 'shortcode_cat'));
25 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_search'), array(&$this, 'shortcode_search'));
26 }
27
28
29 /**
30 * Shortcode single
31 *
32 * @param array $atts
33 *
34 * @filter : eventpost_params
35 *
36 * @return string
37 */
38 public function shortcode_single($atts){
39 $default_atts = array(
40 'attribute' => '',
41 );
42 $atts = shortcode_atts($default_atts, $atts);
43 $attribute = sanitize_text_field($atts['attribute']);
44 $event = EventPost()->retreive();
45 switch($attribute){
46 case 'start':
47 return wp_kses(EventPost()->human_date($event->time_start), EventPost()->kses_tags);
48 case 'end':
49 return wp_kses(EventPost()->human_date($event->time_end), EventPost()->kses_tags);
50 case 'address':
51 return wp_kses($event->address, EventPost()->kses_tags);
52 case 'location':
53 return wp_kses(EventPost()->get_singleloc($event, '', 'single'), EventPost()->kses_tags);
54 case 'date':
55 return wp_kses(EventPost()->get_singledate($event, '', 'single'), EventPost()->kses_tags);
56 default:
57 return wp_kses(EventPost()->get_single($event, '', 'single'), EventPost()->kses_tags);
58 }
59 }
60
61 /**
62 * Get terms from a shortcode
63 *
64 * @param array $atts
65 *
66 * @return string
67 */
68 public function shortcode_term($atts){
69 $defaults = array(
70 'tax' => null,
71 'term' => null,
72 'post_type' => null,
73 );
74 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_term'), $atts);
75 $atts = array(
76 'tax' => sanitize_text_field($atts['tax']),
77 'term' => sanitize_text_field($atts['term']),
78 'post_type' => sanitize_text_field($atts['post_type']),
79 );
80 extract($atts);
81 if(false !== $the_term = EventPost()->retreive_term($term, $tax, $post_type)){
82 return EventPost()->delta_date($the_term->time_start, $the_term->time_end);
83 }
84 }
85 public function shortcode_cat($_atts){
86 $atts = shortcode_atts(array(
87 'cat' => null,
88 ), $_atts);
89 $atts['tax']='category';
90 $atts['post_type']='post';
91 $atts['term']=$atts['cat'];
92 unset($atts['cat']);
93 return $this->shortcode_term($atts);
94 }
95
96 /**
97 * Shortcode to display a list of events
98 *
99 ### Query parameters
100
101 - **nb=5** *(number of post, -1 is all, default: 5)*
102 - **future=1** *(boolean, retreive, or not, events in the future, default = 1)*
103 - **past=0** *(boolean, retreive, or not, events in the past, default = 0)*
104 - **cat=''** *(string, select posts only from the selected category, default=null, for all categories)*
105 - **tag=''** *(string, select posts only from the selected tag, default=null, for all tags)*
106 - **geo=0** *(boolean, retreives or not, only events which have geolocation informations, default=0)*
107 - **order="ASC"** *(string (can be "ASC" or "DESC")*
108 - **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...)*
109
110 ### Display parameters
111
112 - **thumbnail=""** * (Bool, default:false, used to display posts thumbnails)*
113 - **thumbnail_size=""** * (String, default:"thmbnail", can be set to any existing size : "medium","large","full" etc...)*
114 - **excerpt=""** * (Bool, default:false, used to display posts excerpts)*
115 - **style=""** * (String, add some inline CSS to the list wrapper)*
116 - **type=div** *(string, possible values are : div, ul, ol default=div)*
117 - **title=''** *(string, hidden if no events is found)*
118 - **before_title="&lt;h3&gt;"** *(string (default &lt;h3&gt;)*
119 - **after_title="&lt;/h3&gt;"** *(string (default &lt;/h3&gt;)*
120 - **container_schema=""** *(string html schema to display list)*
121 - **item_schema=""** *(string html schema to display item)*
122 *
123 * @param array $_atts
124 *
125 * @filter eventpost_params
126 *
127 * @return string
128 */
129 public function shortcode_list($_atts) {
130 $atts = shortcode_atts(apply_filters('eventpost_params', array(
131 // Filters
132 'nb' => 0,
133 'future' => true,
134 'past' => false,
135 'geo' => 0,
136 'cat' => '',
137 'tag' => '',
138 'tax_name' => '',
139 'tax_term' => '',
140 'orderby' => 'meta_value',
141 'order' => 'ASC',
142 'title' => '',
143 // Display
144 'type' => 'div',
145 'before_title' => '<h3>',
146 'after_title' => '</h3>',
147 'thumbnail' => '',
148 'thumbnail_size' => '',
149 'excerpt' => '',
150 'width' => '',
151 'height' => 'auto',
152 'style' => '',
153 'pages' => false,
154 'container_schema' => EventPost()->list_shema['container'],
155 'item_schema' => EventPost()->list_shema['item'],
156 'align' => '',
157 'className' => '',
158 ), 'shortcode_list'), $_atts);
159
160 if ($atts['container_schema'] != EventPost()->list_shema['container']){
161 $atts['container_schema'] = html_entity_decode($atts['container_schema']);
162 $atts['container_schema'] = wp_kses($atts['container_schema'], EventPost()->kses_tags);
163 }
164
165 if ($atts['item_schema'] != EventPost()->list_shema['item']) {
166 $atts['item_schema'] = html_entity_decode($atts['item_schema']);
167 $atts['item_schema'] = wp_kses($atts['item_schema'], EventPost()->kses_tags);
168 }
169
170 return EventPost()->list_events($atts, 'event_list', 'shortcode');
171 }
172
173 /**
174 * Shortcode to display a list of events
175 *
176 ### Query parameters
177
178 - **nb=5** *(number of post, -1 is all, default: 5)*
179 - **future=1** *(boolean, retreive, or not, events in the future, default = 1)*
180 - **past=0** *(boolean, retreive, or not, events in the past, default = 0)*
181 - **cat=''** *(string, select posts only from the selected category, default=null, for all categories)*
182 - **tag=''** *(string, select posts only from the selected tag, default=null, for all tags)*
183 - **geo=0** *(boolean, retreives or not, only events which have geolocation informations, default=0)*
184
185 ### Display parameters
186
187 - **excerpt=""** * (Bool, default:false, used to display posts excerpts)*
188 - **style=""** * (String, add some inline CSS to the list wrapper)*
189 - **type=div** *(string, possible values are : div, ul, ol default=div)*
190 - **title=''** *(string, hidden if no events is found)*
191 - **before_title="&lt;h3&gt;"** *(string (default &lt;h3&gt;)*
192 - **after_title="&lt;/h3&gt;"** *(string (default &lt;/h3&gt;)*
193 - **container_schema=""** *(string html schema to display list)*
194 - **item_schema=""** *(string html schema to display item)*
195 *
196 * @param array $_atts
197 *
198 * @filter eventpost_params
199 *
200 * @return string
201 */
202 public function shortcode_timeline($_atts, $content='', $block=null) {
203 $atts = shortcode_atts(apply_filters('eventpost_params', array(
204 // Filters
205 'nb' => 3,
206 'nb_desktop' => 0,
207 'nb_tablet' => 0,
208 'nb_mobile' => 0,
209 'future' => true,
210 'past' => false,
211 'geo' => 0,
212 'cat' => '',
213 'tag' => '',
214 'tax_name' => '',
215 'tax_term' => '',
216 'title' => '',
217 // Display
218 'align' => '',
219 'type' => 'div',
220 'before_title' => '<h3>',
221 'after_title' => '</h3>',
222 'excerpt' => '',
223 'width' => '',
224 'height' => 'auto',
225 'style' => '',
226 'container_schema' => EventPost()->timeline_shema['container'],
227 'item_schema' => EventPost()->timeline_shema['item'],
228 'className' => '',
229 'order' => 'ASC',
230 'direction' => 'horizontal',
231 'separate_years' => false,
232 'separate_months' => false,
233 'size' => 2,
234 'color' => '#000000',
235 ), 'shortcode_list'), $_atts);
236
237 $atts['className'] .= ' direction-'.$atts['direction'];
238
239 wp_enqueue_script('event-post-timeline');
240
241 if ($atts['container_schema'] != EventPost()->timeline_shema['container'])
242 $atts['container_schema'] = html_entity_decode($atts['container_schema']);
243 if ($atts['item_schema'] != EventPost()->timeline_shema['item'])
244 $atts['item_schema'] = html_entity_decode($atts['item_schema']);
245 return EventPost()->list_events($atts, 'event_timeline', $block ? 'block' :'shortcode');
246 }
247
248 /**
249 * Shortcode to display a map of events
250 *
251 * @param array $_atts
252 *
253 * @filter eventpost_params
254 *
255 * @return string
256 */
257 public function shortcode_map($_atts) {
258
259 $ep_settings = EventPost()->settings;
260 $defaults = array(
261 // Display
262 'width' => '',
263 'height' => '',
264 'tile' => $ep_settings['tile'],
265 'pop_element_schema' => '',
266 'htmlPop_element_schema' => '',
267 'title' => '',
268 'before_title' => '<h3>',
269 'after_title' => '</h3>',
270 'style' => '',
271 'thumbnail' => '',
272 'thumbnail_size' => '',
273 'excerpt' => '',
274 'zoom' => '',
275 'map_position' => '',
276 'latitude' => '',
277 'longitude' => '',
278 'list' => '0',
279 // Filters
280 'nb' => 0,
281 'future' => true,
282 'past' => false,
283 'cat' => '',
284 'tag' => '',
285 'tax_name' => '',
286 'tax_term' => '',
287 'orderby' => 'meta_value',
288 'order' => 'ASC',
289 'align' => '',
290 'className' => '',
291 );
292 // UI options
293 foreach(EventPost()->map_interactions as $int_key=>$int_name){
294 $defaults[$int_key]=true;
295 }
296 // - UI options
297 foreach(EventPost()->map_interactions as $int_key=>$int_name){
298 $defaults['disable_'.strtolower($int_key)]=false;
299 }
300
301 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $_atts);
302 // UI options
303 foreach(EventPost()->map_interactions as $int_key=>$int_name){
304 if($atts['disable_'.strtolower($int_key)]==true){
305 $atts[$int_key]=false;
306 }
307 unset($atts['disable_'.strtolower($int_key)]);
308 }
309 $atts['geo'] = 1;
310 $atts['type'] = 'div';
311 return EventPost()->list_events($atts, 'event_geolist', 'shortcode'); //$nb,'div',$future,$past,1,'event_geolist');
312 }
313
314 /**
315 * Shortcode to display a calendar of events
316 *
317 * @param array $_atts
318 *
319 * @filter eventpost_params
320 *
321 * @return string
322 */
323 public function shortcode_cal($_atts) {
324 $defaults = array(
325 'date' => date('Y-n'),
326 'cat' => '',
327 'mondayfirst' => 0, // 1 : weeks starts on monday
328 'display_title' => 0,
329 'datepicker' => 1,
330 'swipe' => false,
331 'tax_name' => '',
332 'tax_term' => '',
333 'thumbnail' => '',
334 'align' => '',
335 'className' => '',
336 );
337 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_cal'), $_atts);
338 $atts = array(
339 'date' => sanitize_text_field($atts['date']),
340 'cat' => sanitize_text_field($atts['cat']),
341 'mondayfirst' => intval($atts['mondayfirst']),
342 'display_title' => intval($atts['display_title']),
343 'datepicker' => intval($atts['datepicker']),
344 'swipe' => intval($atts['swipe']),
345 'tax_name' => sanitize_text_field($atts['tax_name']),
346 'tax_term' => sanitize_text_field($atts['tax_term']),
347 'thumbnail' => sanitize_text_field($atts['thumbnail']),
348 'className' => esc_attr($atts['className']),
349 );
350 extract($atts);
351 // $date can only be a string passed to strtotime, eg: Y-n, - 1 month, +2 weeks, etc...
352 // So we only allow digits, letters, spaces, and the characters - and +
353 if (preg_match('/[^a-zA-Z0-9\-\+ ]/', $date)) {
354 $date = date('Y-n');
355 }
356 return '<div
357 class="eventpost_calendar ' . esc_attr($className) . '"
358 data-tax_name="' . esc_attr($tax_name) . '"
359 data-tax_term="' . esc_attr($tax_term) . '"
360 data-cat="' . esc_attr($cat) . '"
361 data-date="' . esc_attr($date) . '"
362 data-mf="' . esc_attr($mondayfirst) . '"
363 data-dp="' . esc_attr($datepicker) . '"
364 data-title="'. esc_attr($display_title) .'"
365 data-swipe="'. esc_attr($swipe) .'"
366 >'
367 . wp_kses_post(EventPost()->calendar($atts))
368 . '</div>';
369 }
370
371 /**
372 * Shortcode for search
373 *
374 * @param type $_atts
375 *
376 * @return type
377 */
378 public function shortcode_search($_atts){
379 return EventPost()->search($_atts);
380 }
381
382 }
383