Exemplo n.º 1
0
 /**
  * Will output a event in the format passed in $format by replacing placeholders within the format.
  * @param string $format
  * @param string $target
  * @return string
  */
 function output($format, $target = "html")
 {
     $event_string = $format;
     //Time place holder that doesn't show if empty.
     //TODO add filter here too
     preg_match_all('/#@?_\\{[^}]+\\}/', $format, $results);
     foreach ($results[0] as $result) {
         if (substr($result, 0, 3) == "#@_") {
             $date = 'end_date';
             $offset = 4;
         } else {
             $date = 'start_date';
             $offset = 3;
         }
         if ($date == 'end_date' && $this->event_end_date == $this->event_start_date) {
             $replace = __(apply_filters('em_event_output_placeholder', '', $this, $result, $target));
         } else {
             $replace = __(apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, strlen($result) - ($offset + 1)), $this->{$date}), $this, $result, $target));
         }
         $event_string = str_replace($result, $replace, $event_string);
     }
     //This is for the custom attributes
     preg_match_all('/#_ATT\\{([^}]+)\\}(\\{([^}]+)\\})?/', $event_string, $results);
     $attributes = em_get_attributes();
     foreach ($results[0] as $resultKey => $result) {
         //Strip string of placeholder and just leave the reference
         $attRef = substr(substr($result, 0, strpos($result, '}')), 6);
         $attString = '';
         if (is_array($this->event_attributes) && array_key_exists($attRef, $this->event_attributes)) {
             $attString = $this->event_attributes[$attRef];
         } elseif (!empty($results[3][$resultKey])) {
             //Check to see if we have a second set of braces;
             $attString = $results[3][$resultKey];
         } elseif (!empty($attributes['values'][$attRef][0])) {
             $attString = $attributes['values'][$attRef][0];
         }
         $attString = apply_filters('em_event_output_placeholder', $attString, $this, $result, $target);
         $event_string = str_replace($result, $attString, $event_string);
     }
     //First let's do some conditional placeholder removals
     for ($i = 0; $i < EM_CONDITIONAL_RECURSIONS; $i++) {
         //you can add nested recursions by modifying this setting in your wp_options table
         preg_match_all('/\\{([a-zA-Z0-9_\\-]+)\\}(.+?)\\{\\/\\1\\}/s', $event_string, $conditionals);
         if (count($conditionals[0]) > 0) {
             //Check if the language we want exists, if not we take the first language there
             foreach ($conditionals[1] as $key => $condition) {
                 $show_condition = false;
                 if ($condition == 'has_bookings') {
                     //check if there's a booking, if not, remove this section of code.
                     $show_condition = $this->event_rsvp && get_option('dbem_rsvp_enabled');
                 } elseif ($condition == 'no_bookings') {
                     //check if there's a booking, if not, remove this section of code.
                     $show_condition = !$this->event_rsvp && get_option('dbem_rsvp_enabled');
                 } elseif ($condition == 'no_location') {
                     //does this event have a valid location?
                     $show_condition = empty($this->location_id) || !$this->get_location()->location_status;
                 } elseif ($condition == 'has_location') {
                     //does this event have a valid location?
                     $show_condition = !empty($this->location_id) && $this->get_location()->location_status;
                 } elseif ($condition == 'has_image') {
                     //does this event have an image?
                     $show_condition = $this->get_image_url() != '';
                 } elseif ($condition == 'no_image') {
                     //does this event have an image?
                     $show_condition = $this->get_image_url() == '';
                 } elseif ($condition == 'has_time') {
                     //are the booking times different and not an all-day event
                     $show_condition = $this->event_start_time != $this->event_end_time && !$this->event_all_day;
                 } elseif ($condition == 'no_time') {
                     //are the booking times exactly the same and it's not an all-day event.
                     $show_condition = $this->event_start_time == $this->event_end_time && !$this->event_all_day;
                 } elseif ($condition == 'all_day') {
                     //is it an all day event
                     $show_condition = !empty($this->event_all_day);
                 } elseif ($condition == 'logged_in') {
                     //user is logged in
                     $show_condition = is_user_logged_in();
                 } elseif ($condition == 'not_logged_in') {
                     //not logged in
                     $show_condition = !is_user_logged_in();
                 } elseif ($condition == 'has_spaces') {
                     //there are still empty spaces
                     $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() > 0;
                 } elseif ($condition == 'fully_booked') {
                     //event is fully booked
                     $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() <= 0;
                 } elseif ($condition == 'bookings_open') {
                     //bookings are still open
                     $show_condition = $this->event_rsvp && $this->get_bookings()->is_open();
                 } elseif ($condition == 'bookings_closed') {
                     //bookings are still closed
                     $show_condition = $this->event_rsvp && !$this->get_bookings()->is_open();
                 } elseif ($condition == 'is_free' || $condition == 'is_free_now') {
                     //is it a free day event, if _now then free right now
                     $show_condition = !$this->event_rsvp || $this->is_free($condition == 'is_free_now');
                 } elseif ($condition == 'not_free' || $condition == 'not_free_now') {
                     //is it a paid event, if _now then paid right now
                     $show_condition = $this->event_rsvp && !$this->is_free($condition == 'not_free_now');
                 } elseif ($condition == 'is_long') {
                     //is it an all day event
                     $show_condition = $this->event_start_date != $this->event_end_date;
                 } elseif ($condition == 'not_long') {
                     //is it an all day event
                     $show_condition = $this->event_start_date == $this->event_end_date;
                 } elseif ($condition == 'is_past') {
                     //if event is past
                     if (get_option('dbem_events_current_are_past')) {
                         $show_condition = $this->start <= current_time('timestamp');
                     } else {
                         $show_condition = $this->end <= current_time('timestamp');
                     }
                 } elseif ($condition == 'is_future') {
                     //if event is upcoming
                     $show_condition = $this->start > current_time('timestamp');
                 } elseif ($condition == 'is_current') {
                     //if event is upcoming
                     $ts = current_time('timestamp');
                     $show_condition = $this->start <= $ts && $this->end >= $ts;
                 } elseif ($condition == 'is_recurrence') {
                     //if event is a recurrence
                     $show_condition = $this->is_recurrence();
                 } elseif ($condition == 'not_recurrence') {
                     //if event is not a recurrence
                     $show_condition = !$this->is_recurrence();
                 } elseif ($condition == 'is_private') {
                     //if event is a recurrence
                     $show_condition = $this->event_private == 1;
                 } elseif ($condition == 'not_private') {
                     //if event is not a recurrence
                     $show_condition = $this->event_private == 0;
                 } elseif (preg_match('/^has_category_([a-zA-Z0-9_\\-]+)$/', $condition, $category_match)) {
                     //event is in this category
                     $show_condition = has_term($category_match[1], EM_TAXONOMY_CATEGORY, $this->post_id);
                 } elseif (preg_match('/^no_category_([a-zA-Z0-9_\\-]+)$/', $condition, $category_match)) {
                     //event is NOT in this category
                     $show_condition = !has_term($category_match[1], EM_TAXONOMY_CATEGORY, $this->post_id);
                 } elseif (preg_match('/^has_tag_([a-zA-Z0-9_\\-]+)$/', $condition, $tag_match)) {
                     //event has this tag
                     $show_condition = has_term($tag_match[1], EM_TAXONOMY_TAG, $this->post_id);
                 } elseif (preg_match('/^no_tag_([a-zA-Z0-9_\\-]+)$/', $condition, $tag_match)) {
                     //event doesn't have this tag
                     $show_condition = !has_term($tag_match[1], EM_TAXONOMY_TAG, $this->post_id);
                 }
                 //other potential ones - has_attribute_... no_attribute_... has_categories_...
                 $show_condition = apply_filters('em_event_output_show_condition', $show_condition, $condition, $conditionals[0][$key], $this);
                 if ($show_condition) {
                     //calculate lengths to delete placeholders
                     $placeholder_length = strlen($condition) + 2;
                     $replacement = substr($conditionals[0][$key], $placeholder_length, strlen($conditionals[0][$key]) - ($placeholder_length * 2 + 1));
                 } else {
                     $replacement = '';
                 }
                 $event_string = str_replace($conditionals[0][$key], apply_filters('em_event_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $event_string);
             }
         }
     }
     //Now let's check out the placeholders.
     preg_match_all("/(#@?_?[A-Za-z0-9]+)({([^}]+)})?/", $event_string, $placeholders);
     $replaces = array();
     foreach ($placeholders[1] as $key => $result) {
         $match = true;
         $replace = '';
         $full_result = $placeholders[0][$key];
         switch ($result) {
             //Event Details
             case '#_EVENTID':
                 $replace = $this->event_id;
                 break;
             case '#_EVENTPOSTID':
                 $replace = $this->post_id;
                 break;
             case '#_NAME':
                 //depreciated
             //depreciated
             case '#_EVENTNAME':
                 $replace = $this->event_name;
                 break;
             case '#_NOTES':
                 //depreciated
             //depreciated
             case '#_EXCERPT':
                 //depreciated
             //depreciated
             case '#_EVENTNOTES':
             case '#_EVENTEXCERPT':
                 $replace = $this->post_content;
                 if ($result == "#_EXCERPT" || $result == "#_EVENTEXCERPT") {
                     if (!empty($this->post_excerpt)) {
                         $replace = $this->post_excerpt;
                     } else {
                         $excerpt_length = 55;
                         $excerpt_more = apply_filters('em_excerpt_more', ' ' . '[...]');
                         if (!empty($placeholders[3][$key])) {
                             $trim = true;
                             $ph_args = explode(',', $placeholders[3][$key]);
                             if (is_numeric($ph_args[0])) {
                                 $excerpt_length = $ph_args[0];
                             }
                             if (!empty($ph_args[1])) {
                                 $excerpt_more = $ph_args[1];
                             }
                         }
                         if (preg_match('/<!--more(.*?)?-->/', $replace, $matches)) {
                             $content = explode($matches[0], $replace, 2);
                             $replace = force_balance_tags($content[0]);
                         }
                         if (!empty($trim)) {
                             //shorten content by supplied number - copied from wp_trim_excerpt
                             $replace = strip_shortcodes($replace);
                             $replace = str_replace(']]>', ']]&gt;', $replace);
                             $replace = wp_trim_words($replace, $excerpt_length, $excerpt_more);
                         }
                     }
                 }
                 break;
             case '#_EVENTIMAGEURL':
             case '#_EVENTIMAGE':
                 if ($this->get_image_url() != '') {
                     if ($result == '#_EVENTIMAGEURL') {
                         $replace = esc_url($this->image_url);
                     } else {
                         if (empty($placeholders[3][$key])) {
                             $replace = "<img src='" . esc_url($this->image_url) . "' alt='" . esc_attr($this->event_name) . "'/>";
                         } else {
                             $image_size = explode(',', $placeholders[3][$key]);
                             $image_url = $this->image_url;
                             if (self::array_is_numeric($image_size) && count($image_size) > 1) {
                                 //get a thumbnail
                                 if (get_option('dbem_disable_thumbnails')) {
                                     $image_attr = '';
                                     $image_args = array();
                                     if (empty($image_size[1]) && !empty($image_size[0])) {
                                         $image_attr = 'width="' . $image_size[0] . '"';
                                         $image_args['w'] = $image_size[0];
                                     } elseif (empty($image_size[0]) && !empty($image_size[1])) {
                                         $image_attr = 'height="' . $image_size[1] . '"';
                                         $image_args['h'] = $image_size[1];
                                     } elseif (!empty($image_size[0]) && !empty($image_size[1])) {
                                         $image_attr = 'width="' . $image_size[0] . '" height="' . $image_size[1] . '"';
                                         $image_args = array('w' => $image_size[0], 'h' => $image_size[1]);
                                     }
                                     $replace = "<img src='" . esc_url(em_add_get_params($image_url, $image_args)) . "' alt='" . esc_attr($this->event_name) . "' {$image_attr} />";
                                 } else {
                                     if (EM_MS_GLOBAL && get_current_blog_id() != $this->blog_id) {
                                         switch_to_blog($this->blog_id);
                                         $switch_back = true;
                                     }
                                     $replace = get_the_post_thumbnail($this->ID, $image_size);
                                     if (!empty($switch_back)) {
                                         restore_current_blog();
                                     }
                                 }
                             } else {
                                 $replace = "<img src='" . esc_url($image_url) . "' alt='" . esc_attr($this->event_name) . "'/>";
                             }
                         }
                     }
                 }
                 break;
                 //Times & Dates
             //Times & Dates
             case '#_24HSTARTTIME':
             case '#_24HENDTIME':
                 $time = $result == '#_24HSTARTTIME' ? $this->event_start_time : $this->event_end_time;
                 $replace = substr($time, 0, 5);
                 break;
             case '#_12HSTARTTIME':
             case '#_12HENDTIME':
                 $time = $result == '#_12HSTARTTIME' ? $this->event_start_time : $this->event_end_time;
                 $replace = date('g:i A', strtotime($time));
                 break;
             case '#_EVENTTIMES':
                 //get format of time to show
                 if (!$this->event_all_day) {
                     $time_format = get_option('dbem_time_format') ? get_option('dbem_time_format') : get_option('time_format');
                     if ($this->event_start_time != $this->event_end_time) {
                         $replace = date_i18n($time_format, $this->start) . get_option('dbem_times_separator') . date_i18n($time_format, $this->end);
                     } else {
                         $replace = date_i18n($time_format, $this->start);
                     }
                 } else {
                     $replace = get_option('dbem_event_all_day_message');
                 }
                 break;
             case '#_EVENTDATES':
                 //get format of time to show
                 $date_format = get_option('dbem_date_format') ? get_option('dbem_date_format') : get_option('date_format');
                 if ($this->event_start_date != $this->event_end_date) {
                     $replace = date_i18n($date_format, $this->start) . get_option('dbem_dates_separator') . date_i18n($date_format, $this->end);
                 } else {
                     $replace = date_i18n($date_format, $this->start);
                 }
                 break;
                 //Links
             //Links
             case '#_EVENTPAGEURL':
                 //Depreciated
             //Depreciated
             case '#_LINKEDNAME':
                 //Depreciated
             //Depreciated
             case '#_EVENTURL':
                 //Just the URL
             //Just the URL
             case '#_EVENTLINK':
                 //HTML Link
                 $event_link = esc_url($this->get_permalink());
                 if ($result == '#_LINKEDNAME' || $result == '#_EVENTLINK') {
                     $replace = '<a href="' . $event_link . '" title="' . esc_attr($this->event_name) . '">' . esc_attr($this->event_name) . '</a>';
                 } else {
                     $replace = $event_link;
                 }
                 break;
             case '#_EDITEVENTURL':
             case '#_EDITEVENTLINK':
                 if ($this->can_manage('edit_events', 'edit_others_events')) {
                     $link = esc_url($this->get_edit_url());
                     if ($result == '#_EDITEVENTLINK') {
                         $replace = '<a href="' . $link . '">' . esc_html(sprintf(__('Edit Event', 'dbem'))) . '</a>';
                     } else {
                         $replace = $link;
                     }
                 }
                 break;
                 //Bookings
             //Bookings
             case '#_ADDBOOKINGFORM':
                 //Depreciated
             //Depreciated
             case '#_REMOVEBOOKINGFORM':
                 //Depreciated
             //Depreciated
             case '#_BOOKINGFORM':
                 if (get_option('dbem_rsvp_enabled')) {
                     if (!defined('EM_XSS_BOOKINGFORM_FILTER') && locate_template('plugins/events-manager/placeholders/bookingform.php')) {
                         //xss fix for old overriden booking forms
                         add_filter('em_booking_form_action_url', 'esc_url');
                         define('EM_XSS_BOOKINGFORM_FILTER', true);
                     }
                     ob_start();
                     $template = em_locate_template('placeholders/bookingform.php', true, array('EM_Event' => $this));
                     EM_Bookings::enqueue_js();
                     $replace = ob_get_clean();
                 }
                 break;
             case '#_BOOKINGBUTTON':
                 if (get_option('dbem_rsvp_enabled') && $this->event_rsvp) {
                     ob_start();
                     $template = em_locate_template('placeholders/bookingbutton.php', true, array('EM_Event' => $this));
                     $replace = ob_get_clean();
                 }
                 break;
             case '#_EVENTPRICERANGEALL':
                 $show_all_ticket_prices = true;
                 //continues below
             //continues below
             case '#_EVENTPRICERANGE':
                 //get the range of prices
                 $min = false;
                 $max = 0;
                 if ($this->get_bookings()->is_open() || !empty($show_all_ticket_prices)) {
                     foreach ($this->get_tickets()->tickets as $EM_Ticket) {
                         /* @var $EM_Ticket EM_Ticket */
                         if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable') || !empty($show_all_ticket_prices)) {
                             if ($EM_Ticket->get_price() > $max) {
                                 $max = $EM_Ticket->get_price();
                             }
                             if ($EM_Ticket->get_price() < $min || $min === false) {
                                 $min = $EM_Ticket->get_price();
                             }
                         }
                     }
                 }
                 if ($min === false) {
                     $min = 0;
                 }
                 if ($min != $max) {
                     $replace = em_get_currency_formatted($min) . ' - ' . em_get_currency_formatted($max);
                 } else {
                     $replace = em_get_currency_formatted($min);
                 }
                 break;
             case '#_EVENTPRICEMIN':
                 //get the range of prices
                 $min = false;
                 foreach ($this->get_tickets()->tickets as $EM_Ticket) {
                     /* @var $EM_Ticket EM_Ticket */
                     if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable')) {
                         if ($EM_Ticket->get_price() < $min || $min === false) {
                             $min = $EM_Ticket->get_price();
                         }
                     }
                 }
                 if ($min === false) {
                     $min = 0;
                 }
                 $replace = em_get_currency_formatted($min);
                 break;
             case '#_EVENTPRICEMAX':
                 //get the range of prices
                 $max = 0;
                 foreach ($this->get_tickets()->tickets as $EM_Ticket) {
                     /* @var $EM_Ticket EM_Ticket */
                     if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable')) {
                         if ($EM_Ticket->get_price() > $max) {
                             $max = $EM_Ticket->get_price();
                         }
                     }
                 }
                 $replace = em_get_currency_formatted($max);
                 break;
             case '#_AVAILABLESEATS':
                 //Depreciated
             //Depreciated
             case '#_AVAILABLESPACES':
                 if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) {
                     $replace = $this->get_bookings()->get_available_spaces();
                 } else {
                     $replace = "0";
                 }
                 break;
             case '#_BOOKEDSEATS':
                 //Depreciated
             //Depreciated
             case '#_BOOKEDSPACES':
                 //This placeholder is actually a little misleading, as it'll consider reserved (i.e. pending) bookings as 'booked'
                 if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) {
                     $replace = $this->get_bookings()->get_booked_spaces();
                     if (get_option('dbem_bookings_approval_reserved')) {
                         $replace += $this->get_bookings()->get_pending_spaces();
                     }
                 } else {
                     $replace = "0";
                 }
                 break;
             case '#_PENDINGSPACES':
                 if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) {
                     $replace = $this->get_bookings()->get_pending_spaces();
                 } else {
                     $replace = "0";
                 }
                 break;
             case '#_SEATS':
                 //Depreciated
             //Depreciated
             case '#_SPACES':
                 $replace = $this->get_spaces();
                 break;
             case '#_BOOKINGSURL':
             case '#_BOOKINGSLINK':
                 if ($this->can_manage('manage_bookings', 'manage_others_bookings')) {
                     $bookings_link = esc_url($this->get_bookings_url());
                     if ($result == '#_BOOKINGSLINK') {
                         $replace = '<a href="' . $bookings_link . '" title="' . esc_attr($this->event_name) . '">' . esc_html($this->event_name) . '</a>';
                     } else {
                         $replace = $bookings_link;
                     }
                 }
                 break;
             case '#_BOOKINGSCUTOFF':
             case '#_BOOKINGSCUTOFFDATE':
             case '#_BOOKINGSCUTOFFTIME':
                 $replace = '';
                 if ($this->event_rsvp && get_option('dbem_rsvp_enabled') && !empty($this->rsvp_end)) {
                     $replace_format = get_option('dbem_date_format') . ' ' . get_option('dbem_time_format');
                     if ($result == '#_BOOKINGSCUTOFFDATE') {
                         $replace_format = get_option('dbem_date_format');
                     }
                     if ($result == '#_BOOKINGSCUTOFFTIME') {
                         $replace_format = get_option('dbem_time_format');
                     }
                     $replace = date($replace_format, $this->rsvp_end);
                 }
                 break;
                 //Contact Person
             //Contact Person
             case '#_CONTACTNAME':
             case '#_CONTACTPERSON':
                 //Depreciated (your call, I think name is better)
                 $replace = $this->get_contact()->display_name;
                 break;
             case '#_CONTACTUSERNAME':
                 $replace = $this->get_contact()->user_login;
                 break;
             case '#_CONTACTEMAIL':
             case '#_CONTACTMAIL':
                 //Depreciated
                 $replace = $this->get_contact()->user_email;
                 break;
             case '#_CONTACTURL':
                 $replace = $this->get_contact()->user_url;
                 break;
             case '#_CONTACTID':
                 $replace = $this->get_contact()->ID;
                 break;
             case '#_CONTACTPHONE':
                 $replace = $this->get_contact()->phone != '' ? $this->get_contact()->phone : __('N/A', 'dbem');
                 break;
             case '#_CONTACTAVATAR':
                 $replace = get_avatar($this->get_contact()->ID, $size = '50');
                 break;
             case '#_CONTACTPROFILELINK':
             case '#_CONTACTPROFILEURL':
                 if (function_exists('bp_core_get_user_domain')) {
                     $replace = bp_core_get_user_domain($this->get_contact()->ID);
                     if ($result == '#_CONTACTPROFILELINK') {
                         $replace = '<a href="' . esc_url($replace) . '">' . __('Profile', 'dbem') . '</a>';
                     }
                 }
                 break;
             case '#_CONTACTMETA':
                 if (!empty($placeholders[3][$key])) {
                     $replace = get_user_meta($this->event_owner, $placeholders[3][$key], true);
                 }
                 break;
             case '#_ATTENDEES':
                 ob_start();
                 $template = em_locate_template('placeholders/attendees.php', true, array('EM_Event' => $this));
                 $replace = ob_get_clean();
                 break;
             case '#_ATTENDEESLIST':
                 ob_start();
                 $template = em_locate_template('placeholders/attendeeslist.php', true, array('EM_Event' => $this));
                 $replace = ob_get_clean();
                 break;
             case '#_ATTENDEESPENDINGLIST':
                 ob_start();
                 $template = em_locate_template('placeholders/attendeespendinglist.php', true, array('EM_Event' => $this));
                 $replace = ob_get_clean();
                 break;
                 //Categories and Tags
             //Categories and Tags
             case '#_EVENTCATEGORIESIMAGES':
                 ob_start();
                 $template = em_locate_template('placeholders/eventcategoriesimages.php', true, array('EM_Event' => $this));
                 $replace = ob_get_clean();
                 break;
             case '#_EVENTTAGS':
                 ob_start();
                 $template = em_locate_template('placeholders/eventtags.php', true, array('EM_Event' => $this));
                 $replace = ob_get_clean();
                 break;
             case '#_CATEGORIES':
                 //depreciated
             //depreciated
             case '#_EVENTCATEGORIES':
                 ob_start();
                 $template = em_locate_template('placeholders/categories.php', true, array('EM_Event' => $this));
                 $replace = ob_get_clean();
                 break;
                 //Ical Stuff
             //Ical Stuff
             case '#_EVENTICALURL':
             case '#_EVENTICALLINK':
                 $replace = $this->get_ical_url();
                 if ($result == '#_EVENTICALLINK') {
                     $replace = '<a href="' . esc_url($replace) . '">iCal</a>';
                 }
                 break;
             case '#_EVENTGCALURL':
             case '#_EVENTGCALLINK':
                 //get dates in UTC/GMT time
                 if ($this->event_all_day && $this->event_start_date == $this->event_end_date) {
                     $dateStart = get_gmt_from_date(date('Y-m-d H:i:s', $this->start), 'Ymd');
                     $dateEnd = get_gmt_from_date(date('Y-m-d H:i:s', $this->start + 60 * 60 * 24), 'Ymd');
                 } else {
                     $dateStart = get_gmt_from_date(date('Y-m-d H:i:s', $this->start), 'Ymd\\THis\\Z');
                     $dateEnd = get_gmt_from_date(date('Y-m-d H:i:s', $this->end), 'Ymd\\THis\\Z');
                 }
                 //build url
                 $gcal_url = 'http://www.google.com/calendar/event?action=TEMPLATE&text=event_name&dates=start_date/end_date&details=post_content&location=location_name&trp=false&sprop=event_url&sprop=name:blog_name';
                 $gcal_url = str_replace('event_name', urlencode($this->event_name), $gcal_url);
                 $gcal_url = str_replace('start_date', urlencode($dateStart), $gcal_url);
                 $gcal_url = str_replace('end_date', urlencode($dateEnd), $gcal_url);
                 $gcal_url = str_replace('location_name', urlencode($this->output('#_LOCATION')), $gcal_url);
                 $gcal_url = str_replace('blog_name', urlencode(get_bloginfo()), $gcal_url);
                 $gcal_url = str_replace('event_url', urlencode($this->get_permalink()), $gcal_url);
                 //calculate URL length so we know how much we can work with to make a description.
                 if (!empty($this->post_excerpt)) {
                     $gcal_url_description = $this->post_excerpt;
                 } else {
                     $matches = explode('<!--more', $this->post_content);
                     $gcal_url_description = wp_kses_data($matches[0]);
                 }
                 $gcal_url_length = strlen($gcal_url) - 9;
                 if (strlen($gcal_url_description) + $gcal_url_length > 1350) {
                     $gcal_url_description = substr($gcal_url_description, 0, 1380 - $gcal_url_length - 3) . '...';
                 }
                 $gcal_url = str_replace('post_content', urlencode($gcal_url_description), $gcal_url);
                 //get the final url
                 $replace = $gcal_url;
                 if ($result == '#_EVENTGCALLINK') {
                     $img_url = 'www.google.com/calendar/images/ext/gc_button2.gif';
                     $img_url = is_ssl() ? 'https://' . $img_url : 'http://' . $img_url;
                     $replace = '<a href="' . esc_url($replace) . '" target="_blank"><img src="' . esc_url($img_url) . '" alt="0" border="0"></a>';
                 }
                 break;
             default:
                 $replace = $full_result;
                 break;
         }
         $replaces[$full_result] = apply_filters('em_event_output_placeholder', $replace, $this, $full_result, $target);
     }
     //sort out replacements so that during replacements shorter placeholders don't overwrite longer varieties.
     krsort($replaces);
     foreach ($replaces as $full_result => $replacement) {
         if (!in_array($full_result, array('#_NOTES', '#_EVENTNOTES'))) {
             $event_string = str_replace($full_result, $replacement, $event_string);
         } else {
             $new_placeholder = str_replace('#_', '__#', $full_result);
             //this will avoid repeated filters when locations/categories are parsed
             $event_string = str_replace($full_result, $new_placeholder, $event_string);
             $desc_replace[$new_placeholder] = $replacement;
         }
     }
     //Time placeholders
     foreach ($placeholders[1] as $result) {
         // matches all PHP START date and time placeholders
         if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) {
             $replace = date_i18n(ltrim($result, "#"), $this->start);
             $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
             $event_string = str_replace($result, $replace, $event_string);
         }
         // matches all PHP END time placeholders for endtime
         if (preg_match('/^#@[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) {
             $replace = date_i18n(ltrim($result, "#@"), $this->end);
             $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target);
             $event_string = str_replace($result, $replace, $event_string);
         }
     }
     //Now do dependent objects
     if (!empty($this->location_id) && $this->get_location()->location_status) {
         $event_string = $this->get_location()->output($event_string, $target);
     } else {
         $EM_Location = new EM_Location();
         $event_string = $EM_Location->output($event_string, $target);
     }
     //for backwards compat and easy use, take over the individual category placeholders with the frirst cat in th elist.
     $EM_Categories = $this->get_categories();
     if (count($EM_Categories->categories) > 0) {
         $EM_Category = $EM_Categories->get_first();
     }
     if (empty($EM_Category)) {
         $EM_Category = new EM_Category();
     }
     $event_string = $EM_Category->output($event_string, $target);
     //Finally, do the event notes, so that previous placeholders don't get replaced within the content, which may use shortcodes
     if (!empty($desc_replace)) {
         foreach ($desc_replace as $full_result => $replacement) {
             $event_string = str_replace($full_result, $replacement, $event_string);
         }
     }
     //do some specific formatting
     //TODO apply this sort of formatting to any output() function
     if ($target == 'ical') {
         //strip html and escape characters
         $event_string = str_replace('\\', '\\\\', strip_tags($event_string));
         $event_string = str_replace(';', '\\;', $event_string);
         $event_string = str_replace(',', '\\,', $event_string);
         //remove and define line breaks in ical format
         $event_string = str_replace('\\\\n', '\\n', $event_string);
         $event_string = str_replace("\r\n", '\\n', $event_string);
         $event_string = str_replace("\n", '\\n', $event_string);
     }
     return apply_filters('em_event_output', $event_string, $this, $format, $target);
 }
 public static function checkout_page()
 {
     if (!self::get_multiple_booking()->validate_bookings_spaces()) {
         global $EM_Notices;
         $EM_Notices->add_error(self::get_multiple_booking()->get_errors());
     }
     //load contents if not using caching, do not alter this conditional structure as it allows the cart to work with caching plugins
     echo '<div class="em-checkout-page-contents" style="position:relative;">';
     if (!defined('WP_CACHE') || !WP_CACHE) {
         emp_locate_template('multiple-bookings/page-checkout.php', true);
     } else {
         echo '<p>' . get_option('dbem_multiple_bookings_feedback_loading_cart') . '</p>';
     }
     echo '</div>';
     EM_Bookings::enqueue_js();
 }