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