PluginProbe
Event Post / 5.10.2
Event Post v5.10.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 / inc / class-shortcodes.php

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

360 lines 13.7 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 5.10.2
7 * @since 5.0.0
8 */
9
10 namespace EventPost;
11
12 class Shortcodes{
13
14 function __construct() {
15 //Shortcodes
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 * Shortcode single
29 *
30 * @param array $atts
31 *
32 * @filter : eventpost_params
33 *
34 * @return string
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 * Get terms from a shortcode
61 *
62 * @param array $atts
63 *
64 * @return string
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 * Shortcode to display a list of events
96 *
97 ### Query parameters
98
99 - **nb=5** *(number of post, -1 is all, default: 5)*
100 - **future=1** *(boolean, retreive, or not, events in the future, default = 1)*
101 - **past=0** *(boolean, retreive, or not, events in the past, default = 0)*
102 - **cat=''** *(string, select posts only from the selected category, default=null, for all categories)*
103 - **tag=''** *(string, select posts only from the selected tag, default=null, for all tags)*
104 - **geo=0** *(boolean, retreives or not, only events which have geolocation informations, default=0)*
105 - **order="ASC"** *(string (can be "ASC" or "DESC")*
106 - **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...)*
107
108 ### Display parameters
109
110 - **thumbnail=""** * (Bool, default:false, used to display posts thumbnails)*
111 - **thumbnail_size=""** * (String, default:"thmbnail", can be set to any existing size : "medium","large","full" etc...)*
112 - **excerpt=""** * (Bool, default:false, used to display posts excerpts)*
113 - **style=""** * (String, add some inline CSS to the list wrapper)*
114 - **type=div** *(string, possible values are : div, ul, ol default=div)*
115 - **title=''** *(string, hidden if no events is found)*
116 - **before_title="&lt;h3&gt;"** *(string (default &lt;h3&gt;)*
117 - **after_title="&lt;/h3&gt;"** *(string (default &lt;/h3&gt;)*
118 - **container_schema=""** *(string html schema to display list)*
119 - **item_schema=""** *(string html schema to display item)*
120 *
121 * @param array $_atts
122 *
123 * @filter eventpost_params
124 *
125 * @return string
126 */
127 public function shortcode_list($_atts) {
128 $atts = shortcode_atts(apply_filters('eventpost_params', array(
129 // Filters
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 // Display
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 $atts['container_schema'] = wp_kses($atts['container_schema'], EventPost()->kses_tags);
160
161 if ($atts['item_schema'] != EventPost()->list_shema['item']) {
162 $atts['item_schema'] = html_entity_decode($atts['item_schema']);
163 $atts['item_schema'] = wp_kses($atts['item_schema'], EventPost()->kses_tags);
164 }
165
166 return EventPost()->list_events($atts, 'event_list', 'shortcode');
167 }
168
169 /**
170 * Shortcode to display a list of events
171 *
172 ### Query parameters
173
174 - **nb=5** *(number of post, -1 is all, default: 5)*
175 - **future=1** *(boolean, retreive, or not, events in the future, default = 1)*
176 - **past=0** *(boolean, retreive, or not, events in the past, default = 0)*
177 - **cat=''** *(string, select posts only from the selected category, default=null, for all categories)*
178 - **tag=''** *(string, select posts only from the selected tag, default=null, for all tags)*
179 - **geo=0** *(boolean, retreives or not, only events which have geolocation informations, default=0)*
180
181 ### Display parameters
182
183 - **excerpt=""** * (Bool, default:false, used to display posts excerpts)*
184 - **style=""** * (String, add some inline CSS to the list wrapper)*
185 - **type=div** *(string, possible values are : div, ul, ol default=div)*
186 - **title=''** *(string, hidden if no events is found)*
187 - **before_title="&lt;h3&gt;"** *(string (default &lt;h3&gt;)*
188 - **after_title="&lt;/h3&gt;"** *(string (default &lt;/h3&gt;)*
189 - **container_schema=""** *(string html schema to display list)*
190 - **item_schema=""** *(string html schema to display item)*
191 *
192 * @param array $_atts
193 *
194 * @filter eventpost_params
195 *
196 * @return string
197 */
198 public function shortcode_timeline($_atts) {
199 $atts = shortcode_atts(apply_filters('eventpost_params', array(
200 // Filters
201 'nb' => 0,
202 'future' => true,
203 'past' => false,
204 'geo' => 0,
205 'cat' => '',
206 'tag' => '',
207 'tax_name' => '',
208 'tax_term' => '',
209 'title' => '',
210 // Display
211 'type' => 'div',
212 'before_title' => '<h3>',
213 'after_title' => '</h3>',
214 'excerpt' => '',
215 'width' => '',
216 'height' => 'auto',
217 'style' => '',
218 'container_schema' => EventPost()->timeline_shema['container'],
219 'item_schema' => EventPost()->timeline_shema['item'],
220 'className' => '',
221 ), 'shortcode_list'), $_atts);
222
223 if ($atts['container_schema'] != EventPost()->timeline_shema['container'])
224 $atts['container_schema'] = html_entity_decode($atts['container_schema']);
225 if ($atts['item_schema'] != EventPost()->timeline_shema['item'])
226 $atts['item_schema'] = html_entity_decode($atts['item_schema']);
227 return EventPost()->list_events($atts, 'event_timeline', 'shortcode');
228 }
229
230 /**
231 * Shortcode to display a map of events
232 *
233 * @param array $_atts
234 *
235 * @filter eventpost_params
236 *
237 * @return string
238 */
239 public function shortcode_map($_atts) {
240
241 $ep_settings = EventPost()->settings;
242 $defaults = array(
243 // Display
244 'width' => '',
245 'height' => '',
246 'tile' => $ep_settings['tile'],
247 'pop_element_schema' => '',
248 'htmlPop_element_schema' => '',
249 'title' => '',
250 'before_title' => '<h3>',
251 'after_title' => '</h3>',
252 'style' => '',
253 'thumbnail' => '',
254 'thumbnail_size' => '',
255 'excerpt' => '',
256 'zoom' => '',
257 'map_position' => '',
258 'latitude' => '',
259 'longitude' => '',
260 'list' => '0',
261 // Filters
262 'nb' => 0,
263 'future' => true,
264 'past' => false,
265 'cat' => '',
266 'tag' => '',
267 'tax_name' => '',
268 'tax_term' => '',
269 'orderby' => 'meta_value',
270 'order' => 'ASC',
271 'className' => '',
272 );
273 // UI options
274 foreach(EventPost()->map_interactions as $int_key=>$int_name){
275 $defaults[$int_key]=true;
276 }
277 // - UI options
278 foreach(EventPost()->map_interactions as $int_key=>$int_name){
279 $defaults['disable_'.strtolower($int_key)]=false;
280 }
281
282 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $_atts);
283 // UI options
284 foreach(EventPost()->map_interactions as $int_key=>$int_name){
285 if($atts['disable_'.strtolower($int_key)]==true){
286 $atts[$int_key]=false;
287 }
288 unset($atts['disable_'.strtolower($int_key)]);
289 }
290 $atts['geo'] = 1;
291 $atts['type'] = 'div';
292 return EventPost()->list_events($atts, 'event_geolist', 'shortcode'); //$nb,'div',$future,$past,1,'event_geolist');
293 }
294
295 /**
296 * Shortcode to display a calendar of events
297 *
298 * @param array $_atts
299 *
300 * @filter eventpost_params
301 *
302 * @return string
303 */
304 public function shortcode_cal($_atts) {
305 $defaults = array(
306 'date' => date('Y-n'),
307 'cat' => '',
308 'mondayfirst' => 0, // 1 : weeks starts on monday
309 'display_title' => 0,
310 'datepicker' => 1,
311 'tax_name' => '',
312 'tax_term' => '',
313 'thumbnail' => '',
314 'className' => '',
315 );
316 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_cal'), $_atts);
317 $atts = array(
318 'date' => sanitize_text_field($atts['date']),
319 'cat' => sanitize_text_field($atts['cat']),
320 'mondayfirst' => intval($atts['mondayfirst']),
321 'display_title' => intval($atts['display_title']),
322 'datepicker' => intval($atts['datepicker']),
323 'tax_name' => sanitize_text_field($atts['tax_name']),
324 'tax_term' => sanitize_text_field($atts['tax_term']),
325 'thumbnail' => sanitize_text_field($atts['thumbnail']),
326 'className' => esc_attr($atts['className']),
327 );
328 extract($atts);
329 // $date can only be a string passed to strtotime, eg: Y-n, - 1 month, +2 weeks, etc...
330 // So we only allow digits, letters, spaces, and the characters - and +
331 if (preg_match('/[^a-zA-Z0-9\-\+ ]/', $date)) {
332 $date = date('Y-n');
333 }
334 return '<div
335 class="eventpost_calendar ' . esc_attr($className) . '"
336 data-tax_name="' . esc_attr($tax_name) . '"
337 data-tax_term="' . esc_attr($tax_term) . '"
338 data-cat="' . esc_attr($cat) . '"
339 data-date="' . esc_attr($date) . '"
340 data-mf="' . esc_attr($mondayfirst) . '"
341 data-dp="' . esc_attr($datepicker) . '"
342 data-title="'. esc_attr($display_title) .'"
343 >'
344 . wp_kses_post(EventPost()->calendar($atts))
345 . '</div>';
346 }
347
348 /**
349 * Shortcode for search
350 *
351 * @param type $_atts
352 *
353 * @return type
354 */
355 public function shortcode_search($_atts){
356 return EventPost()->search($_atts);
357 }
358
359 }
360