| 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: | $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: | |
| 172: | |
| 173: | |
| 174: | |
| 175: | |
| 176: | |
| 177: | |
| 178: | |
| 179: | |
| 180: | |
| 181: | |
| 182: | |
| 183: | |
| 184: | |
| 185: | |
| 186: | |
| 187: | |
| 188: | |
| 189: | |
| 190: | |
| 191: | |
| 192: | |
| 193: | |
| 194: | |
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | public function shortcode_timeline($_atts) { |
| 200: | $atts = shortcode_atts(apply_filters('eventpost_params', array( |
| 201: | |
| 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: | |
| 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: | |
| 233: | |
| 234: | |
| 235: | |
| 236: | |
| 237: | |
| 238: | |
| 239: | |
| 240: | public function shortcode_map($_atts) { |
| 241: | |
| 242: | $ep_settings = EventPost()->settings; |
| 243: | $defaults = array( |
| 244: | |
| 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: | |
| 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: | |
| 275: | foreach(EventPost()->map_interactions as $int_key=>$int_name){ |
| 276: | $defaults[$int_key]=true; |
| 277: | } |
| 278: | |
| 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: | |
| 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'); |
| 294: | } |
| 295: | |
| 296: | |
| 297: | |
| 298: | |
| 299: | |
| 300: | |
| 301: | |
| 302: | |
| 303: | |
| 304: | |
| 305: | public function shortcode_cal($_atts) { |
| 306: | $defaults = array( |
| 307: | 'date' => date('Y-n'), |
| 308: | 'cat' => '', |
| 309: | 'mondayfirst' => 0, |
| 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: | |
| 331: | |
| 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: | |
| 351: | |
| 352: | |
| 353: | |
| 354: | |
| 355: | |
| 356: | public function shortcode_search($_atts){ |
| 357: | return EventPost()->search($_atts); |
| 358: | } |
| 359: | |
| 360: | } |
| 361: | |