1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | namespace EventPost; |
11: | |
12: | class Shortcodes{ |
13: | |
14: | function __construct() { |
15: | |
16: | add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_list'), array(&$this, 'shortcode_list')); |
17: | add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_timeline'), array(&$this, 'shortcode_timeline')); |
18: | add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_map'), array(&$this, 'shortcode_map')); |
19: | add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_cal'), array(&$this, 'shortcode_cal')); |
20: | add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_details'), array(&$this, 'shortcode_single')); |
21: | add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_term'), array(&$this, 'shortcode_term')); |
22: | add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_cat'), array(&$this, 'shortcode_cat')); |
23: | add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_search'), array(&$this, 'shortcode_search')); |
24: | } |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | public function shortcode_single($atts){ |
37: | $default_atts = array( |
38: | 'attribute' => '', |
39: | ); |
40: | $atts = shortcode_atts($default_atts, $atts); |
41: | $attribute = sanitize_text_field($atts['attribute']); |
42: | $event = EventPost()->retreive(); |
43: | switch($attribute){ |
44: | case 'start': |
45: | return wp_kses(EventPost()->human_date($event->time_start), EventPost()->kses_tags); |
46: | case 'end': |
47: | return wp_kses(EventPost()->human_date($event->time_end), EventPost()->kses_tags); |
48: | case 'address': |
49: | return wp_kses($event->address, EventPost()->kses_tags); |
50: | case 'location': |
51: | return wp_kses(EventPost()->get_singleloc($event, '', 'single'), EventPost()->kses_tags); |
52: | case 'date': |
53: | return wp_kses(EventPost()->get_singledate($event, '', 'single'), EventPost()->kses_tags); |
54: | default: |
55: | return wp_kses(EventPost()->get_single($event, '', 'single'), EventPost()->kses_tags); |
56: | } |
57: | } |
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | public function shortcode_term($atts){ |
67: | $defaults = array( |
68: | 'tax' => null, |
69: | 'term' => null, |
70: | 'post_type' => null, |
71: | ); |
72: | $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_term'), $atts); |
73: | $atts = array( |
74: | 'tax' => sanitize_text_field($atts['tax']), |
75: | 'term' => sanitize_text_field($atts['term']), |
76: | 'post_type' => sanitize_text_field($atts['post_type']), |
77: | ); |
78: | extract($atts); |
79: | if(false !== $the_term = EventPost()->retreive_term($term, $tax, $post_type)){ |
80: | return EventPost()->delta_date($the_term->time_start, $the_term->time_end); |
81: | } |
82: | } |
83: | public function shortcode_cat($_atts){ |
84: | $atts = shortcode_atts(array( |
85: | 'cat' => null, |
86: | ), $_atts); |
87: | $atts['tax']='category'; |
88: | $atts['post_type']='post'; |
89: | $atts['term']=$atts['cat']; |
90: | unset($atts['cat']); |
91: | return $this->shortcode_term($atts); |
92: | } |
93: | |
94: | |
95: | |
96: | |
97: | |
98: | |
99: | |
100: | |
101: | |
102: | |
103: | |
104: | |
105: | |
106: | |
107: | |
108: | |
109: | |
110: | |
111: | |
112: | |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | |
123: | |
124: | |
125: | |
126: | |
127: | public function shortcode_list($_atts) { |
128: | $atts = shortcode_atts(apply_filters('eventpost_params', array( |
129: | |
130: | 'nb' => 0, |
131: | 'future' => true, |
132: | 'past' => false, |
133: | 'geo' => 0, |
134: | 'cat' => '', |
135: | 'tag' => '', |
136: | 'tax_name' => '', |
137: | 'tax_term' => '', |
138: | 'orderby' => 'meta_value', |
139: | 'order' => 'ASC', |
140: | 'title' => '', |
141: | |
142: | 'type' => 'div', |
143: | 'before_title' => '<h3>', |
144: | 'after_title' => '</h3>', |
145: | 'thumbnail' => '', |
146: | 'thumbnail_size' => '', |
147: | 'excerpt' => '', |
148: | 'width' => '', |
149: | 'height' => 'auto', |
150: | 'style' => '', |
151: | 'pages' => false, |
152: | 'container_schema' => EventPost()->list_shema['container'], |
153: | 'item_schema' => EventPost()->list_shema['item'], |
154: | 'className' => '', |
155: | ), 'shortcode_list'), $_atts); |
156: | |
157: | if ($atts['container_schema'] != EventPost()->list_shema['container']) |
158: | $atts['container_schema'] = html_entity_decode($atts['container_schema']); |
159: | if ($atts['item_schema'] != EventPost()->list_shema['item']) |
160: | $atts['item_schema'] = html_entity_decode($atts['item_schema']); |
161: | return EventPost()->list_events($atts, 'event_list', 'shortcode'); |
162: | } |
163: | |
164: | |
165: | |
166: | |
167: | |
168: | |
169: | |
170: | |
171: | |
172: | |
173: | |
174: | |
175: | |
176: | |
177: | |
178: | |
179: | |
180: | |
181: | |
182: | |
183: | |
184: | |
185: | |
186: | |
187: | |
188: | |
189: | |
190: | |
191: | |
192: | |
193: | public function shortcode_timeline($_atts) { |
194: | $atts = shortcode_atts(apply_filters('eventpost_params', array( |
195: | |
196: | 'nb' => 0, |
197: | 'future' => true, |
198: | 'past' => false, |
199: | 'geo' => 0, |
200: | 'cat' => '', |
201: | 'tag' => '', |
202: | 'tax_name' => '', |
203: | 'tax_term' => '', |
204: | 'title' => '', |
205: | |
206: | 'type' => 'div', |
207: | 'before_title' => '<h3>', |
208: | 'after_title' => '</h3>', |
209: | 'excerpt' => '', |
210: | 'width' => '', |
211: | 'height' => 'auto', |
212: | 'style' => '', |
213: | 'container_schema' => EventPost()->timeline_shema['container'], |
214: | 'item_schema' => EventPost()->timeline_shema['item'], |
215: | 'className' => '', |
216: | ), 'shortcode_list'), $_atts); |
217: | |
218: | if ($atts['container_schema'] != EventPost()->timeline_shema['container']) |
219: | $atts['container_schema'] = html_entity_decode($atts['container_schema']); |
220: | if ($atts['item_schema'] != EventPost()->timeline_shema['item']) |
221: | $atts['item_schema'] = html_entity_decode($atts['item_schema']); |
222: | return EventPost()->list_events($atts, 'event_timeline', 'shortcode'); |
223: | } |
224: | |
225: | |
226: | |
227: | |
228: | |
229: | |
230: | |
231: | |
232: | |
233: | |
234: | public function shortcode_map($_atts) { |
235: | |
236: | $ep_settings = EventPost()->settings; |
237: | $defaults = array( |
238: | |
239: | 'width' => '', |
240: | 'height' => '', |
241: | 'tile' => $ep_settings['tile'], |
242: | 'pop_element_schema' => '', |
243: | 'htmlPop_element_schema' => '', |
244: | 'title' => '', |
245: | 'before_title' => '<h3>', |
246: | 'after_title' => '</h3>', |
247: | 'style' => '', |
248: | 'thumbnail' => '', |
249: | 'thumbnail_size' => '', |
250: | 'excerpt' => '', |
251: | 'zoom' => '', |
252: | 'map_position' => '', |
253: | 'latitude' => '', |
254: | 'longitude' => '', |
255: | 'list' => '0', |
256: | |
257: | 'nb' => 0, |
258: | 'future' => true, |
259: | 'past' => false, |
260: | 'cat' => '', |
261: | 'tag' => '', |
262: | 'tax_name' => '', |
263: | 'tax_term' => '', |
264: | 'orderby' => 'meta_value', |
265: | 'order' => 'ASC', |
266: | 'className' => '', |
267: | ); |
268: | |
269: | foreach(EventPost()->map_interactions as $int_key=>$int_name){ |
270: | $defaults[$int_key]=true; |
271: | } |
272: | |
273: | foreach(EventPost()->map_interactions as $int_key=>$int_name){ |
274: | $defaults['disable_'.strtolower($int_key)]=false; |
275: | } |
276: | |
277: | $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $_atts); |
278: | |
279: | foreach(EventPost()->map_interactions as $int_key=>$int_name){ |
280: | if($atts['disable_'.strtolower($int_key)]==true){ |
281: | $atts[$int_key]=false; |
282: | } |
283: | unset($atts['disable_'.strtolower($int_key)]); |
284: | } |
285: | $atts['geo'] = 1; |
286: | $atts['type'] = 'div'; |
287: | return EventPost()->list_events($atts, 'event_geolist', 'shortcode'); |
288: | } |
289: | |
290: | |
291: | |
292: | |
293: | |
294: | |
295: | |
296: | |
297: | |
298: | |
299: | public function shortcode_cal($_atts) { |
300: | $defaults = array( |
301: | 'date' => date('Y-n'), |
302: | 'cat' => '', |
303: | 'mondayfirst' => 0, |
304: | 'display_title' => 0, |
305: | 'datepicker' => 1, |
306: | 'tax_name' => '', |
307: | 'tax_term' => '', |
308: | 'thumbnail' => '', |
309: | 'className' => '', |
310: | ); |
311: | $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_cal'), $_atts); |
312: | $atts = array( |
313: | 'date' => sanitize_text_field($atts['date']), |
314: | 'cat' => sanitize_text_field($atts['cat']), |
315: | 'mondayfirst' => intval($atts['mondayfirst']), |
316: | 'display_title' => intval($atts['display_title']), |
317: | 'datepicker' => intval($atts['datepicker']), |
318: | 'tax_name' => sanitize_text_field($atts['tax_name']), |
319: | 'tax_term' => sanitize_text_field($atts['tax_term']), |
320: | 'thumbnail' => sanitize_text_field($atts['thumbnail']), |
321: | 'className' => esc_attr($atts['className']), |
322: | ); |
323: | extract($atts); |
324: | |
325: | |
326: | if (preg_match('/[^a-zA-Z0-9\-\+ ]/', $date)) { |
327: | $date = date('Y-n'); |
328: | } |
329: | return '<div |
330: | class="eventpost_calendar ' . esc_attr($className) . '" |
331: | data-tax_name="' . esc_attr($tax_name) . '" |
332: | data-tax_term="' . esc_attr($tax_term) . '" |
333: | data-cat="' . esc_attr($cat) . '" |
334: | data-date="' . esc_attr($date) . '" |
335: | data-mf="' . esc_attr($mondayfirst) . '" |
336: | data-dp="' . esc_attr($datepicker) . '" |
337: | data-title="'. esc_attr($display_title) .'" |
338: | >' |
339: | . wp_kses_post(EventPost()->calendar($atts)) |
340: | . '</div>'; |
341: | } |
342: | |
343: | |
344: | |
345: | |
346: | |
347: | |
348: | |
349: | |
350: | public function shortcode_search($_atts){ |
351: | return EventPost()->search($_atts); |
352: | } |
353: | |
354: | } |
355: | |