| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Implements all shortcodes features |
| 5 |
*/ |
| 6 |
class EventPost_Shortcodes{ |
| 7 |
public $EP; |
| 8 |
|
| 9 |
function __construct() { |
| 10 |
//Shortcodes |
| 11 |
add_action('init', array(&$this,'init')); |
| 12 |
add_shortcode('events_list', array(&$this, 'shortcode_list')); |
| 13 |
add_shortcode('events_map', array(&$this, 'shortcode_map')); |
| 14 |
add_shortcode('events_cal', array(&$this, 'shortcode_cal')); |
| 15 |
add_shortcode('event_details', array(&$this, 'shortcode_single')); |
| 16 |
add_shortcode('event_term', array(&$this, 'shortcode_term')); |
| 17 |
add_shortcode('event_cat', array(&$this, 'shortcode_cat')); |
| 18 |
// Workaround for ACF select2 bug |
| 19 |
// see: https://github.com/wp-shortcake/shortcake/issues/660 |
| 20 |
add_filter( 'acf/settings/select2_version', array(&$this, 'return4')); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Call functions when WP is ready |
| 25 |
*/ |
| 26 |
public function init(){ |
| 27 |
global $EventPost; |
| 28 |
$this->EP = $EventPost; |
| 29 |
$this->shortcode_ui(); |
| 30 |
} |
| 31 |
|
| 32 |
public function return4(){ |
| 33 |
return 4; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* shortcode_single |
| 38 |
* @param array $atts |
| 39 |
* @filter : eventpost_params |
| 40 |
* @return string |
| 41 |
*/ |
| 42 |
public function shortcode_single($atts){ |
| 43 |
extract(shortcode_atts(apply_filters('eventpost_params', array( |
| 44 |
'attribute' => '', |
| 45 |
), 'shortcode_single'), $atts)); |
| 46 |
$event = $this->EP->retreive(); |
| 47 |
switch($attribute){ |
| 48 |
case 'start': |
| 49 |
return $this->EP->human_date($event->time_start); |
| 50 |
case 'end': |
| 51 |
return $this->EP->human_date($event->time_end); |
| 52 |
case 'address': |
| 53 |
return $event->address; |
| 54 |
case 'location': |
| 55 |
return $this->EP->get_singleloc($event, '', 'single'); |
| 56 |
case 'date': |
| 57 |
return $this->EP->get_singledate($event, '', 'single'); |
| 58 |
default: |
| 59 |
return $this->EP->get_single($event, '', 'single'); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* |
| 65 |
* @param array $atts |
| 66 |
* @return string |
| 67 |
*/ |
| 68 |
public function shortcode_term($atts){ |
| 69 |
extract(shortcode_atts(apply_filters('eventpost_params', array( |
| 70 |
'tax' => null, |
| 71 |
'term' => null, |
| 72 |
'post_type' => null, |
| 73 |
), 'shortcode_term'), $atts)); |
| 74 |
if(false !== $the_term = $this->EP->retreive_term($term, $tax, $post_type)){ |
| 75 |
return $this->EP->delta_date($the_term->time_start, $the_term->time_end); |
| 76 |
} |
| 77 |
} |
| 78 |
public function shortcode_cat($_atts){ |
| 79 |
$atts = shortcode_atts(array( |
| 80 |
'cat' => null, |
| 81 |
), $_atts); |
| 82 |
$atts['tax']='category'; |
| 83 |
$atts['post_type']='post'; |
| 84 |
$atts['term']=$atts['cat']; |
| 85 |
unset($atts['cat']); |
| 86 |
return $this->shortcode_term($atts); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Shortcode to display a list of events |
| 91 |
* |
| 92 |
### Query parameters |
| 93 |
|
| 94 |
- **nb=5** *(number of post, -1 is all, default: 5)* |
| 95 |
- **future=1** *(boolean, retreive, or not, events in the future, default = 1)* |
| 96 |
- **past=0** *(boolean, retreive, or not, events in the past, default = 0)* |
| 97 |
- **cat=''** *(string, select posts only from the selected category, default=null, for all categories)* |
| 98 |
- **tag=''** *(string, select posts only from the selected tag, default=null, for all tags)* |
| 99 |
- **geo=0** *(boolean, retreives or not, only events wich have geolocation informations, default=0)* |
| 100 |
- **order="ASC"** *(string (can be "ASC" or "DESC")* |
| 101 |
- **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...)* |
| 102 |
|
| 103 |
### Display parameters |
| 104 |
|
| 105 |
- **thumbnail=""** * (Bool, default:false, used to display posts thumbnails)* |
| 106 |
- **thumbnail_size=""** * (String, default:"thmbnail", can be set to any existing size : "medium","large","full" etc...)* |
| 107 |
- **excerpt=""** * (Bool, default:false, used to display posts excerpts)* |
| 108 |
- **style=""** * (String, add some inline CSS to the list wrapper)* |
| 109 |
- **type=div** *(string, possible values are : div, ul, ol default=div)* |
| 110 |
- **title=''** *(string, hidden if no events is found)* |
| 111 |
- **before_title="<h3>"** *(string (default <h3>)* |
| 112 |
- **after_title="</h3>"** *(string (default </h3>)* |
| 113 |
- **container_schema=""** *(string html schema to display list)* |
| 114 |
- **item_schema=""** *(string html schema to display item)* |
| 115 |
* |
| 116 |
* @param array $_atts |
| 117 |
* @filter eventpost_params |
| 118 |
* @return string |
| 119 |
*/ |
| 120 |
public function shortcode_list($_atts) { |
| 121 |
$atts = shortcode_atts(apply_filters('eventpost_params', array( |
| 122 |
// Filters |
| 123 |
'nb' => 0, |
| 124 |
'type' => 'div', |
| 125 |
'future' => true, |
| 126 |
'past' => false, |
| 127 |
'geo' => 0, |
| 128 |
'cat' => '', |
| 129 |
'tag' => '', |
| 130 |
'orderby' => 'meta_value', |
| 131 |
'order' => 'ASC', |
| 132 |
'title' => '', |
| 133 |
// Display |
| 134 |
'before_title' => '<h3>', |
| 135 |
'after_title' => '</h3>', |
| 136 |
'thumbnail' => '', |
| 137 |
'thumbnail_size' => '', |
| 138 |
'excerpt' => '', |
| 139 |
'width' => '', |
| 140 |
'height' => 'auto', |
| 141 |
'style' => '', |
| 142 |
'container_schema' => $this->EP->list_shema['container'], |
| 143 |
'item_schema' => $this->EP->list_shema['item'], |
| 144 |
), 'shortcode_list'), $_atts); |
| 145 |
|
| 146 |
if ($atts['container_schema'] != $this->EP->list_shema['container']) |
| 147 |
$atts['container_schema'] = html_entity_decode($atts['container_schema']); |
| 148 |
if ($atts['item_schema'] != $this->EP->list_shema['item']) |
| 149 |
$atts['item_schema'] = html_entity_decode($atts['item_schema']); |
| 150 |
return $this->EP->list_events($atts, 'event_list', 'shortcode'); |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* Shortcode to display a map of events |
| 155 |
* @param array $_atts |
| 156 |
* @filter eventpost_params |
| 157 |
* @return string |
| 158 |
*/ |
| 159 |
public function shortcode_map($_atts) { |
| 160 |
$ep_settings = $this->EP->settings; |
| 161 |
|
| 162 |
$defaults = array( |
| 163 |
// Display |
| 164 |
'width' => '', |
| 165 |
'height' => '', |
| 166 |
'tile' => $ep_settings['tile'], |
| 167 |
'title' => '', |
| 168 |
'before_title' => '<h3>', |
| 169 |
'after_title' => '</h3>', |
| 170 |
'style' => '', |
| 171 |
'thumbnail' => '', |
| 172 |
'thumbnail_size' => '', |
| 173 |
'excerpt' => '', |
| 174 |
'zoom'=>'', |
| 175 |
// Filters |
| 176 |
'nb' => 0, |
| 177 |
'future' => true, |
| 178 |
'past' => false, |
| 179 |
'cat' => '', |
| 180 |
'tag' => '', |
| 181 |
'orderby' => 'meta_value', |
| 182 |
'order' => 'ASC', |
| 183 |
); |
| 184 |
// UI options |
| 185 |
foreach($this->EP->map_interactions as $int_key=>$int_name){ |
| 186 |
$defaults[$int_key]=true; |
| 187 |
} |
| 188 |
// - UI options |
| 189 |
foreach($this->EP->map_interactions as $int_key=>$int_name){ |
| 190 |
$defaults['disable_'.strtolower($int_key)]=false; |
| 191 |
} |
| 192 |
|
| 193 |
$atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $_atts); |
| 194 |
// UI options |
| 195 |
foreach($this->EP->map_interactions as $int_key=>$int_name){ |
| 196 |
if($atts['disable_'.strtolower($int_key)]==true){ |
| 197 |
$atts[$int_key]=false; |
| 198 |
} |
| 199 |
unset($atts['disable_'.strtolower($int_key)]); |
| 200 |
} |
| 201 |
$atts['geo'] = 1; |
| 202 |
$atts['type'] = 'div'; |
| 203 |
return $this->EP->list_events($atts, 'event_geolist', 'shortcode'); //$nb,'div',$future,$past,1,'event_geolist'); |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Shortcode to display a calendar of events |
| 208 |
* @param array $_atts |
| 209 |
* @filter eventpost_params |
| 210 |
* @return string |
| 211 |
*/ |
| 212 |
public function shortcode_cal($_atts) { |
| 213 |
$this->EP->load_scripts(); |
| 214 |
$atts = shortcode_atts(apply_filters('eventpost_params', array( |
| 215 |
'date' => date('Y-n'), |
| 216 |
'cat' => '', |
| 217 |
'mondayfirst' => 0, //1 : weeks starts on monday |
| 218 |
'datepicker' => 1 |
| 219 |
), 'shortcode_cal'), $_atts); |
| 220 |
extract($atts); |
| 221 |
return '<div class="eventpost_calendar" data-cat="' . $cat . '" data-date="' . $date . '" data-mf="' . $mondayfirst . '" data-dp="' . $datepicker . '">' . $this->EP->calendar($atts) . '</div>'; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
/** |
| 226 |
* set_shortcode_ui |
| 227 |
* needs Shortcake (shortcode UI) plugin |
| 228 |
* https://wordpress.org/plugins/shortcode-ui/ |
| 229 |
*/ |
| 230 |
public function shortcode_ui(){ |
| 231 |
if(!function_exists('shortcode_ui_register_for_shortcode')){ |
| 232 |
return; |
| 233 |
} |
| 234 |
$shortcodes_list_atts=array( |
| 235 |
'label' => __('Events list','event-post'), |
| 236 |
'listItemImage' => 'dashicons-calendar', |
| 237 |
'post_type'=>array('page','post'), |
| 238 |
'attrs' => array( |
| 239 |
0=>array( |
| 240 |
'label' => __('Number of posts','event-post'), |
| 241 |
'attr' => 'nb', |
| 242 |
'type' => 'number', |
| 243 |
'description' => __('-1 is for: no limit','event-post') |
| 244 |
), |
| 245 |
1=>array( |
| 246 |
'label' => __('Categories','event-post'), |
| 247 |
'attr' => 'cat', |
| 248 |
'type' => 'term_select', |
| 249 |
'taxonomy' => 'category', |
| 250 |
'multiple' => true, |
| 251 |
), |
| 252 |
2=>array( |
| 253 |
'label' => __('Tags','event-post'), |
| 254 |
'attr' => 'tag', |
| 255 |
'type' => 'term_select', |
| 256 |
'taxonomy' => 'post_tag', |
| 257 |
'multiple' => true, |
| 258 |
), |
| 259 |
3=>array( |
| 260 |
'label' => __('Future events:','event-post'), |
| 261 |
'attr' => 'future', |
| 262 |
'type' => 'select', |
| 263 |
'options' => array( |
| 264 |
'1' => __('Yes','event-post'), |
| 265 |
'0' => __('No','event-post'), |
| 266 |
), |
| 267 |
), |
| 268 |
4=>array( |
| 269 |
'label' => __('Past events:','event-post'), |
| 270 |
'attr' => 'past', |
| 271 |
'type' => 'select', |
| 272 |
'options' => array( |
| 273 |
'1' => __('Yes','event-post'), |
| 274 |
'0' => __('No','event-post'), |
| 275 |
), |
| 276 |
), |
| 277 |
5=>array( |
| 278 |
'label' => __('Only geotagged events:','event-post'), |
| 279 |
'attr' => 'geo', |
| 280 |
'type' => 'select', |
| 281 |
'options' => array( |
| 282 |
'1' => __('Yes','event-post'), |
| 283 |
'0' => __('No','event-post'), |
| 284 |
), |
| 285 |
), |
| 286 |
6=>array( |
| 287 |
'label' => __('Thumbnail:','event-post'), |
| 288 |
'attr' => 'thumbnail', |
| 289 |
'type' => 'select', |
| 290 |
'options' => array( |
| 291 |
'1' => __('Yes','event-post'), |
| 292 |
'0' => __('No','event-post'), |
| 293 |
), |
| 294 |
), |
| 295 |
7=>array( |
| 296 |
'label' => __('Thumbnail size:','event-post'), |
| 297 |
'attr' => 'thumbnail_size', |
| 298 |
'type' => 'select', |
| 299 |
'options' => array( |
| 300 |
'thumbnail' => __('Thumbnail'), |
| 301 |
'medium' => __('Medium'), |
| 302 |
'large' => __('Large'), |
| 303 |
), |
| 304 |
), |
| 305 |
8=>array( |
| 306 |
'label' => __('Order by:','event-post'), |
| 307 |
'attr' => 'orderby', |
| 308 |
'type' => 'select', |
| 309 |
'options' => array( |
| 310 |
'meta_value' => __('Date'), |
| 311 |
'title' => __('Title'), |
| 312 |
), |
| 313 |
), |
| 314 |
9=>array( |
| 315 |
'label' => __('Order:','event-post'), |
| 316 |
'attr' => 'order', |
| 317 |
'type' => 'select', |
| 318 |
'options' => array( |
| 319 |
'ASC' => __('Asc.'), |
| 320 |
'DESC' => __('Desc.'), |
| 321 |
), |
| 322 |
), |
| 323 |
), |
| 324 |
); |
| 325 |
/* |
| 326 |
* Map |
| 327 |
*/ |
| 328 |
$shortcodes_map_atts = $shortcodes_list_atts; |
| 329 |
unset($shortcodes_map_atts['attrs'][5]); // Remove geotagged attr |
| 330 |
unset($shortcodes_map_atts['attrs'][8]); // Remove orderby attr |
| 331 |
unset($shortcodes_map_atts['attrs'][9]); // Remove order attr |
| 332 |
array_unshift($shortcodes_map_atts['attrs'], |
| 333 |
array( |
| 334 |
'label' => __('Width','event-post'), |
| 335 |
'attr' => 'width', |
| 336 |
'type' => 'text', |
| 337 |
), |
| 338 |
array( |
| 339 |
'label' => __('Height','event-post'), |
| 340 |
'attr' => 'height', |
| 341 |
'type' => 'text', |
| 342 |
), |
| 343 |
array( |
| 344 |
'label' => __('Zoom','event-post'), |
| 345 |
'attr' => 'zoom', |
| 346 |
'type' => 'number', |
| 347 |
) |
| 348 |
); |
| 349 |
$shortcodes_map_atts['label']=__('Events map','event-post'); |
| 350 |
$shortcodes_map_atts['listItemImage']='dashicons-location-alt'; |
| 351 |
foreach($this->EP->map_interactions as $int_key=>$int_name){ |
| 352 |
$shortcodes_map_atts['attrs'][]=array( |
| 353 |
'label' => sprintf(__('Disable %s interaction','event-post'), $int_name), |
| 354 |
'attr' => 'disable_'.$int_key, |
| 355 |
'type' => 'checkbox' |
| 356 |
); |
| 357 |
} |
| 358 |
shortcode_ui_register_for_shortcode('events_list', apply_filters('eventpost_shortcodeui_list',$shortcodes_list_atts)); |
| 359 |
shortcode_ui_register_for_shortcode('events_map', apply_filters('eventpost_shortcodeui_map',$shortcodes_map_atts)); |
| 360 |
|
| 361 |
/* |
| 362 |
* Calendar |
| 363 |
*/ |
| 364 |
$shortcodes_cal_atts=array( |
| 365 |
'label' => __('Events calendar','event-post'), |
| 366 |
'listItemImage' => 'dashicons-calendar-alt', |
| 367 |
'post_type'=>array('page','post'), |
| 368 |
'attrs' => array( |
| 369 |
array( |
| 370 |
'label' => __('Default date','event-post'), |
| 371 |
'attr' => 'date', |
| 372 |
'type' => 'text', |
| 373 |
'description' => date('Y-n') |
| 374 |
), |
| 375 |
array( |
| 376 |
'label' => __('Categories','event-post'), |
| 377 |
'attr' => 'cat', |
| 378 |
'type' => 'text', |
| 379 |
), |
| 380 |
array( |
| 381 |
'label' => __('Monday first','event-post'), |
| 382 |
'attr' => 'mondayfirst', |
| 383 |
'type' => 'checkbox', |
| 384 |
), |
| 385 |
array( |
| 386 |
'label' => __('Date selector','event-post'), |
| 387 |
'attr' => 'choose', |
| 388 |
'type' => 'checkbox', |
| 389 |
) |
| 390 |
) |
| 391 |
); |
| 392 |
shortcode_ui_register_for_shortcode('events_cal', apply_filters('eventpost_shortcodeui_cal',$shortcodes_cal_atts)); |
| 393 |
/* |
| 394 |
* Details |
| 395 |
*/ |
| 396 |
$shortcodes_details_atts=array( |
| 397 |
'label' => __('Event details','event-post'), |
| 398 |
'listItemImage' => 'dashicons-clock', |
| 399 |
'attrs' => array( |
| 400 |
array( |
| 401 |
'label' => __('Attribute','event-post'), |
| 402 |
'attr' => 'attribute', |
| 403 |
'type' => 'select', |
| 404 |
'options' => array( |
| 405 |
'' => __('Full details','event-post'), |
| 406 |
'date' => __('Full date','event-post'), |
| 407 |
'start' => __('Begin date','event-post'), |
| 408 |
'end' => __('End date','event-post'), |
| 409 |
'address' => __('Address text','event-post'), |
| 410 |
'location' => __('Location','event-post'), |
| 411 |
), |
| 412 |
), |
| 413 |
) |
| 414 |
); |
| 415 |
shortcode_ui_register_for_shortcode('event_details', apply_filters('eventpost_shortcodeui_details',$shortcodes_details_atts)); |
| 416 |
|
| 417 |
} |
| 418 |
} |
| 419 |
|