1: <?php
2: /**
3: * Implements all shortcodes features
4: *
5: * @package event-post
6: * @version 6.0.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: 'future' => true,
207: 'past' => false,
208: 'geo' => 0,
209: 'cat' => '',
210: 'tag' => '',
211: 'tax_name' => '',
212: 'tax_term' => '',
213: 'title' => '',
214: // Display
215: 'align' => '',
216: 'type' => 'div',
217: 'before_title' => '<h3>',
218: 'after_title' => '</h3>',
219: 'excerpt' => '',
220: 'width' => '',
221: 'height' => 'auto',
222: 'style' => '',
223: 'container_schema' => EventPost()->timeline_shema['container'],
224: 'item_schema' => EventPost()->timeline_shema['item'],
225: 'className' => '',
226: 'order' => 'ASC',
227: 'separate_years' => false,
228: 'separate_months' => false,
229: ), 'shortcode_list'), $_atts);
230:
231: $atts['className'] .= ' direction-'.$_atts['direction'];
232:
233: if ($atts['container_schema'] != EventPost()->timeline_shema['container'])
234: $atts['container_schema'] = html_entity_decode($atts['container_schema']);
235: if ($atts['item_schema'] != EventPost()->timeline_shema['item'])
236: $atts['item_schema'] = html_entity_decode($atts['item_schema']);
237: return EventPost()->list_events($atts, 'event_timeline', $block ? 'block' :'shortcode');
238: }
239:
240: /**
241: * Shortcode to display a map of events
242: *
243: * @param array $_atts
244: *
245: * @filter eventpost_params
246: *
247: * @return string
248: */
249: public function shortcode_map($_atts) {
250:
251: $ep_settings = EventPost()->settings;
252: $defaults = array(
253: // Display
254: 'width' => '',
255: 'height' => '',
256: 'tile' => $ep_settings['tile'],
257: 'pop_element_schema' => '',
258: 'htmlPop_element_schema' => '',
259: 'title' => '',
260: 'before_title' => '<h3>',
261: 'after_title' => '</h3>',
262: 'style' => '',
263: 'thumbnail' => '',
264: 'thumbnail_size' => '',
265: 'excerpt' => '',
266: 'zoom' => '',
267: 'map_position' => '',
268: 'latitude' => '',
269: 'longitude' => '',
270: 'list' => '0',
271: // Filters
272: 'nb' => 0,
273: 'future' => true,
274: 'past' => false,
275: 'cat' => '',
276: 'tag' => '',
277: 'tax_name' => '',
278: 'tax_term' => '',
279: 'orderby' => 'meta_value',
280: 'order' => 'ASC',
281: 'align' => '',
282: 'className' => '',
283: );
284: // UI options
285: foreach(EventPost()->map_interactions as $int_key=>$int_name){
286: $defaults[$int_key]=true;
287: }
288: // - UI options
289: foreach(EventPost()->map_interactions as $int_key=>$int_name){
290: $defaults['disable_'.strtolower($int_key)]=false;
291: }
292:
293: $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $_atts);
294: // UI options
295: foreach(EventPost()->map_interactions as $int_key=>$int_name){
296: if($atts['disable_'.strtolower($int_key)]==true){
297: $atts[$int_key]=false;
298: }
299: unset($atts['disable_'.strtolower($int_key)]);
300: }
301: $atts['geo'] = 1;
302: $atts['type'] = 'div';
303: return EventPost()->list_events($atts, 'event_geolist', 'shortcode'); //$nb,'div',$future,$past,1,'event_geolist');
304: }
305:
306: /**
307: * Shortcode to display a calendar of events
308: *
309: * @param array $_atts
310: *
311: * @filter eventpost_params
312: *
313: * @return string
314: */
315: public function shortcode_cal($_atts) {
316: $defaults = array(
317: 'date' => date('Y-n'),
318: 'cat' => '',
319: 'mondayfirst' => 0, // 1 : weeks starts on monday
320: 'display_title' => 0,
321: 'datepicker' => 1,
322: 'tax_name' => '',
323: 'tax_term' => '',
324: 'thumbnail' => '',
325: 'align' => '',
326: 'className' => '',
327: );
328: $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_cal'), $_atts);
329: $atts = array(
330: 'date' => sanitize_text_field($atts['date']),
331: 'cat' => sanitize_text_field($atts['cat']),
332: 'mondayfirst' => intval($atts['mondayfirst']),
333: 'display_title' => intval($atts['display_title']),
334: 'datepicker' => intval($atts['datepicker']),
335: 'tax_name' => sanitize_text_field($atts['tax_name']),
336: 'tax_term' => sanitize_text_field($atts['tax_term']),
337: 'thumbnail' => sanitize_text_field($atts['thumbnail']),
338: 'className' => esc_attr($atts['className']),
339: );
340: extract($atts);
341: // $date can only be a string passed to strtotime, eg: Y-n, - 1 month, +2 weeks, etc...
342: // So we only allow digits, letters, spaces, and the characters - and +
343: if (preg_match('/[^a-zA-Z0-9\-\+ ]/', $date)) {
344: $date = date('Y-n');
345: }
346: return '<div
347: class="eventpost_calendar ' . esc_attr($className) . '"
348: data-tax_name="' . esc_attr($tax_name) . '"
349: data-tax_term="' . esc_attr($tax_term) . '"
350: data-cat="' . esc_attr($cat) . '"
351: data-date="' . esc_attr($date) . '"
352: data-mf="' . esc_attr($mondayfirst) . '"
353: data-dp="' . esc_attr($datepicker) . '"
354: data-title="'. esc_attr($display_title) .'"
355: >'
356: . wp_kses_post(EventPost()->calendar($atts))
357: . '</div>';
358: }
359:
360: /**
361: * Shortcode for search
362: *
363: * @param type $_atts
364: *
365: * @return type
366: */
367: public function shortcode_search($_atts){
368: return EventPost()->search($_atts);
369: }
370:
371: }
372: