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

355 lines 13.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 5.10.1
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 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 * Shortcode to display a list of events
166 *
167 ### Query parameters
168
169 - **nb=5** *(number of post, -1 is all, default: 5)*
170 - **future=1** *(boolean, retreive, or not, events in the future, default = 1)*
171 - **past=0** *(boolean, retreive, or not, events in the past, default = 0)*
172 - **cat=''** *(string, select posts only from the selected category, default=null, for all categories)*
173 - **tag=''** *(string, select posts only from the selected tag, default=null, for all tags)*
174 - **geo=0** *(boolean, retreives or not, only events which have geolocation informations, default=0)*
175
176 ### Display parameters
177
178 - **excerpt=""** * (Bool, default:false, used to display posts excerpts)*
179 - **style=""** * (String, add some inline CSS to the list wrapper)*
180 - **type=div** *(string, possible values are : div, ul, ol default=div)*
181 - **title=''** *(string, hidden if no events is found)*
182 - **before_title="&lt;h3&gt;"** *(string (default &lt;h3&gt;)*
183 - **after_title="&lt;/h3&gt;"** *(string (default &lt;/h3&gt;)*
184 - **container_schema=""** *(string html schema to display list)*
185 - **item_schema=""** *(string html schema to display item)*
186 *
187 * @param array $_atts
188 *
189 * @filter eventpost_params
190 *
191 * @return string
192 */
193 public function shortcode_timeline($_atts) {
194 $atts = shortcode_atts(apply_filters('eventpost_params', array(
195 // Filters
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 // Display
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 * Shortcode to display a map of events
227 *
228 * @param array $_atts
229 *
230 * @filter eventpost_params
231 *
232 * @return string
233 */
234 public function shortcode_map($_atts) {
235
236 $ep_settings = EventPost()->settings;
237 $defaults = array(
238 // Display
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 // Filters
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 // UI options
269 foreach(EventPost()->map_interactions as $int_key=>$int_name){
270 $defaults[$int_key]=true;
271 }
272 // - UI options
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 // UI options
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'); //$nb,'div',$future,$past,1,'event_geolist');
288 }
289
290 /**
291 * Shortcode to display a calendar of events
292 *
293 * @param array $_atts
294 *
295 * @filter eventpost_params
296 *
297 * @return string
298 */
299 public function shortcode_cal($_atts) {
300 $defaults = array(
301 'date' => date('Y-n'),
302 'cat' => '',
303 'mondayfirst' => 0, // 1 : weeks starts on monday
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 // $date can only be a string passed to strtotime, eg: Y-n, - 1 month, +2 weeks, etc...
325 // So we only allow digits, letters, spaces, and the characters - and +
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 * Shortcode for search
345 *
346 * @param type $_atts
347 *
348 * @return type
349 */
350 public function shortcode_search($_atts){
351 return EventPost()->search($_atts);
352 }
353
354 }
355