function eme_add_booking_form($event_id, $show_message = 1) { $form_result_message = ""; $event = eme_get_event($event_id); // rsvp not active or no rsvp for this event, then return if (!eme_is_event_rsvp($event)) { return; } $registration_wp_users_only = $event['registration_wp_users_only']; if ($registration_wp_users_only) { // we require a user to be WP registered to be able to book if (!is_user_logged_in()) { return; } } #$destination = eme_event_url($event)."#eme-rsvp-message"; if (isset($_GET['lang'])) { $language = eme_strip_tags($_GET['lang']); $destination = "?lang=" . $language . "#eme-rsvp-message"; } else { $destination = "#eme-rsvp-message"; } // after the add or delete booking, we do a POST to the same page using javascript to show just the result // this has 2 advantages: you can give arguments in the post, and refreshing the page won't repeat the booking action, just the post showing the result // a javascript redir using window.replace + GET would work too, but that leaves an ugly GET url if (isset($_POST['eme_eventAction']) && $_POST['eme_eventAction'] == 'add_booking' && isset($_POST['eme_event_id'])) { $event_id = intval($_POST['eme_event_id']); $event = eme_get_event($event_id); if (has_filter('eme_eval_booking_form_post_filter')) { $eval_filter_return = apply_filters('eme_eval_booking_form_post_filter', $event); } else { $eval_filter_return = array(0 => 1, 1 => ''); } if (is_array($eval_filter_return) && !$eval_filter_return[0]) { // the result of own eval rules failed, so let's use that as a result $booking_ids_done = 0; $form_result_message = $eval_filter_return[1]; } else { $send_mail = 1; $booking_res = eme_book_seats($event, $send_mail); $form_result_message = $booking_res[0]; $booking_id_done = $booking_res[1]; } $post_string = "{"; if ($booking_id_done && eme_event_can_pay_online($event)) { $payment_id = eme_get_booking_payment_id($booking_id_done); if (!empty($payment_id)) { // you did a successfull registration, so now we decide wether to show the form again, or the payment form // but to make sure people don't mess with the booking id in the url, we use wp_nonce // by default the nonce is valid for 24 hours $eme_payment_nonce = wp_create_nonce('eme_payment_id' . $payment_id); // create the JS array that will be used to post $post_arr = array("eme_eventAction" => 'pay_booking', "eme_message" => $form_result_message, "eme_payment_id" => $payment_id, "eme_payment_nonce" => $eme_payment_nonce); } else { // no payment registered (price=0) $post_arr = array("eme_eventAction" => 'message', "eme_message" => $form_result_message, "booking_done" => 1); } } elseif ($booking_id_done) { $post_arr = array("eme_eventAction" => 'message', "eme_message" => $form_result_message, "booking_done" => 1); } else { // booking failed: we add $_POST to the json, so we can pre-fill the form so the user can just correct the mistake $post_arr = stripslashes_deep($_POST); $post_arr['eme_eventAction'] = 'message'; $post_arr['eme_message'] = $form_result_message; } $post_string = json_encode($post_arr); ?> <script type="text/javascript"> function postwith (to,p) { var myForm = document.createElement("form"); myForm.method="post" ; myForm.action = to ; for (var k in p) { var myInput = document.createElement("input") ; myInput.setAttribute("name", k) ; myInput.setAttribute("value", p[k]); myForm.appendChild(myInput) ; } document.body.appendChild(myForm) ; myForm.submit() ; document.body.removeChild(myForm) ; } <?php echo "postwith('{$destination}',{$post_string});"; ?> </script> <?php return; } if (isset($_POST['eme_eventAction']) && $_POST['eme_eventAction'] == 'pay_booking' && isset($_POST['eme_message']) && isset($_POST['eme_payment_id'])) { $payment_id = intval($_POST['eme_payment_id']); // due to the double POST javascript, the eme_message is escaped again, so we need stripslashes // but the message may contain html, so no html sanitize $form_result_message = eme_translate(stripslashes_deep($_POST['eme_message'])); // verify the nonce, to make sure people didn't mess with the booking id if (!isset($_POST['eme_payment_nonce']) || !wp_verify_nonce($_POST['eme_payment_nonce'], 'eme_payment_id' . $payment_id)) { return; } else { return eme_payment_form($event, $payment_id, $form_result_message); } } $message_is_result_of_booking = 0; if (isset($_POST['eme_eventAction']) && $_POST['eme_eventAction'] == 'message' && isset($_POST['eme_message'])) { // due to the double POST javascript, the eme_message is escaped again, so we need stripslashes // but the message may contain html, so no html sanitize $form_result_message = eme_translate(stripslashes_deep($_POST['eme_message'])); if (isset($_POST['booking_done'])) { $message_is_result_of_booking = 1; } } $ret_string = "<div id='eme-rsvp-message'>"; if ($show_message && !empty($form_result_message)) { $ret_string .= "<div class='eme-rsvp-message'>{$form_result_message}</div>"; } $event_rsvp_startdatetime = strtotime($event['event_start_date'] . " " . $event['event_start_time']); $event_rsvp_enddatetime = strtotime($event['event_end_date'] . " " . $event['event_end_time']); if ($event['event_properties']['rsvp_end_target'] == 'start') { $event_rsvp_datetime = $event_rsvp_startdatetime; } else { $event_rsvp_datetime = $event_rsvp_enddatetime; } $cur_time = time(); if ($cur_time + $event['rsvp_number_days'] * 60 * 60 * 24 + $event['rsvp_number_hours'] * 60 * 60 > $event_rsvp_datetime || $cur_time >= $event_rsvp_enddatetime) { return $ret_string . "<div class='eme-rsvp-message'>" . __('Bookings no longer allowed on this date.', 'eme') . "</div></div>"; } // you can book the available number of seats, with a max of x per time $min_allowed = $event['event_properties']['min_allowed']; // the next gives the number of available seats, even for multiprice $avail_seats = eme_get_available_seats($event_id); // no seats anymore? No booking form then ... but only if it is required that the min number of // bookings should be >0 (it can be=0 for attendance bookings) if (eme_is_multi($min_allowed)) { $min = eme_get_multitotal($min_allowed); } else { $min = $min_allowed; } $form_html = ""; if ($avail_seats == 0 && $min > 0) { // we show the message concerning 'no more seats' only if it is not after a successful booking if (!$message_is_result_of_booking) { $ret_string .= "<div class='eme-rsvp-message'>" . __('Bookings no longer possible: no seats available anymore', 'eme') . "</div>"; } } else { if (!$message_is_result_of_booking || $message_is_result_of_booking && get_option('eme_rsvp_show_form_after_booking')) { $form_html = "<form id='eme-rsvp-form' name='booking-form' method='post' action='{$destination}' onsubmit='eme_submit_button.disabled=true; return true;'>"; $form_html .= eme_replace_formfields_placeholders($event); // add a nonce for extra security $form_html .= wp_nonce_field('add_booking', 'eme_rsvp_nonce', false, false); // also add a honeypot field: if it gets completed with data, // it's a bot, since a humand can't see this (using CSS to render it invisible) $form_html .= "<span id='honeypot_check'>Keep this field blank: <input type='text' name='honeypot_check' value='' /></span>\n <p id='eme_mark_required_field'>" . __('(* marks a required field)', 'eme') . "</p>\n <input type='hidden' name='eme_eventAction' value='add_booking' />\n <input type='hidden' name='eme_event_id' value='{$event_id}' />\n </form>"; if (has_filter('eme_add_booking_form_filter')) { $form_html = apply_filters('eme_add_booking_form_filter', $form_html); } } } return $ret_string . $form_html . "</div>"; }
function eme_replace_placeholders($format, $event = "", $target = "html", $do_shortcode = 1, $lang = '') { global $wp_query; global $eme_need_gmap_js, $booking_id_done; // an initial filter for the format, in case people want to change anything before the placeholders get replaced if (has_filter('eme_events_format_prefilter')) { $format = apply_filters('eme_events_format_prefilter', $format, $event); } // some variables we'll use further down more than once $current_userid = get_current_user_id(); $person_id = eme_get_person_id_by_wp_id($current_userid); $eme_enable_notes_placeholders = get_option('eme_enable_notes_placeholders'); if (isset($event['location_id']) && $event['location_id']) { $location = eme_get_location($event['location_id']); } else { $location = eme_new_location(); } // first replace the notes sections, since these can contain other placeholders if ($eme_enable_notes_placeholders) { $format = eme_replace_notes_placeholders($format, $event, $target); } // then we do the custom attributes, since these can contain other placeholders preg_match_all("/#(ESC|URL)?_ATT\\{.+?\\}(\\{.+?\\})?/", $format, $results); foreach ($results[0] as $resultKey => $result) { $need_escape = 0; $need_urlencode = 0; $orig_result = $result; if (strstr($result, '#ESC')) { $result = str_replace("#ESC", "#", $result); $need_escape = 1; } elseif (strstr($result, '#URL')) { $result = str_replace("#URL", "#", $result); $need_urlencode = 1; } $replacement = ""; //Strip string of placeholder and just leave the reference $attRef = substr(substr($result, 0, strpos($result, '}')), 6); if (isset($event['event_attributes'][$attRef])) { $replacement = $event['event_attributes'][$attRef]; } if (trim($replacement) == '' && isset($results[2][$resultKey]) && $results[2][$resultKey] != '') { //Check to see if we have a second set of braces; $replacement = substr($results[2][$resultKey], 1, strlen(trim($results[2][$resultKey])) - 2); } if ($need_escape) { $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement))); } if ($need_urlencode) { $replacement = rawurlencode($replacement); } $format = str_replace($orig_result, $replacement, $format); } // and now all the other placeholders $legacy = get_option('eme_legacy'); $deprecated = get_option('eme_deprecated'); if ($legacy) { preg_match_all("/#(ESC|URL)?@?_?[A-Za-z0-9_]+(\\[.*\\])?(\\[.*\\])?/", $format, $placeholders); } else { preg_match_all("/#(ESC|URL)?@?_?[A-Za-z0-9_]+(\\{.*?\\})?(\\{.*?\\})?/", $format, $placeholders); } // make sure we set the largest matched placeholders first, otherwise if you found e.g. // #_LOCATION, part of #_LOCATIONPAGEURL would get replaced as well ... usort($placeholders[0], 'sort_stringlenth'); // if the add and remove booking form appear on the same page, we need to decide which form shows the "message" upon booking // the first one wins $a1 = strpos($format, "ADDBOOKINGFORM"); $a2 = strpos($format, "REMOVEBOOKINGFORM"); $show_message_on_add = 1; $show_message_on_remove = 1; if ($a1 !== false && $a2 !== false) { if ($a1 < $a2) { $show_message_on_remove = 0; } else { $show_message_on_add = 0; } } foreach ($placeholders[0] as $result) { $need_escape = 0; $need_urlencode = 0; $orig_result = $result; $found = 1; if (strstr($result, '#ESC')) { $result = str_replace("#ESC", "#", $result); $need_escape = 1; } elseif (strstr($result, '#URL')) { $result = str_replace("#URL", "#", $result); $need_urlencode = 1; } $replacement = ""; // matches all fields placeholder if ($event && preg_match('/#_EDITEVENTLINK/', $result)) { if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) { $replacement = "<a href=' " . admin_url("admin.php?page=events-manager&eme_admin_action=edit_event&event_id=" . $event['event_id']) . "'>" . __('Edit') . "</a>"; } } elseif ($event && preg_match('/#_EDITEVENTURL/', $result)) { if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) { $replacement = admin_url("admin.php?page=events-manager&eme_admin_action=edit_event&event_id=" . $event['event_id']); } } elseif ($event && preg_match('/#_EVENTPRINTBOOKINGSLINK/', $result)) { if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) { $replacement = "<a href=' " . admin_url("admin.php?page=eme-people&eme_admin_action=booking_printable&event_id=" . $event['event_id']) . "'>" . __('Printable view of bookings', 'eme') . "</a>"; } } elseif ($event && preg_match('/#_EVENTPRINTBOOKINGSURL/', $result)) { if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) { $replacement = admin_url("admin.php?page=eme-people&eme_admin_action=booking_printable&event_id=" . $event['event_id']); } } elseif ($event && preg_match('/#_EVENTCSVBOOKINGSLINK/', $result)) { if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) { $replacement = "<a href=' " . admin_url("admin.php?page=eme-people&eme_admin_action=booking_csv&event_id=" . $event['event_id']) . "'>" . __('Printable view of bookings', 'eme') . "</a>"; } } elseif ($event && preg_match('/#_EVENTCSVBOOKINGSURL/', $result)) { if (current_user_can(get_option('eme_cap_edit_events')) || current_user_can(get_option('eme_cap_list_events')) || current_user_can(get_option('eme_cap_author_event')) && ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid)) { $replacement = admin_url("admin.php?page=eme-people&eme_admin_action=booking_csv&event_id=" . $event['event_id']); } } elseif ($event && preg_match('/#_STARTDATE/', $result)) { $replacement = eme_localised_date($event['event_start_date']); } elseif ($event && preg_match('/#_STARTTIME/', $result)) { $replacement = eme_localised_time($event['event_start_time']); } elseif ($event && preg_match('/#_ENDDATE/', $result)) { $replacement = eme_localised_date($event['event_end_date']); } elseif ($event && preg_match('/#_ENDTIME/', $result)) { $replacement = eme_localised_time($event['event_end_time']); } elseif ($event && preg_match('/#_24HSTARTTIME/', $result)) { $replacement = substr($event['event_start_time'], 0, 5); } elseif ($event && preg_match('/#_24HENDTIME$/', $result)) { $replacement = substr($event['event_end_time'], 0, 5); } elseif ($event && preg_match('/#_PAST_FUTURE_CLASS/', $result)) { if (strtotime($event['event_start_date'] . " " . $event['event_start_time']) > time()) { $replacement = "eme-future-event"; } elseif (strtotime($event['event_end_date'] . " " . $event['event_end_time']) > time()) { $replacement = "eme-ongoing-event"; } else { $replacement = "eme-past-event"; } } elseif ($event && preg_match('/#_12HSTARTTIME$/', $result)) { $replacement = date("h:i A", strtotime($event['event_start_time'])); } elseif ($event && preg_match('/#_12HENDTIME$/', $result)) { $replacement = date("h:i A", strtotime($event['event_end_time'])); } elseif ($event && preg_match('/#_12HSTARTTIME_NOLEADINGZERO/', $result)) { $replacement = date("g:i A", strtotime($event['event_start_time'])); if (get_option('eme_time_remove_leading_zeros')) { $replacement = str_replace(":0", ":", $replacement); } } elseif ($event && preg_match('/#_12HENDTIME_NOLEADINGZERO/', $result)) { $replacement = date("g:i A", strtotime($event['event_end_time'])); if (get_option('eme_time_remove_leading_zeros')) { $replacement = str_replace(":0", ":", $replacement); } } elseif ($event && preg_match('/#_MAP/', $result)) { if ($target == "rss" || $target == "text") { $replacement = ""; } elseif (isset($event['location_id']) && $event['location_id']) { $replacement = eme_single_location_map($location); } } elseif ($event && preg_match('/#_DIRECTIONS/', $result)) { if ($target == "rss" || $target == "text") { $replacement = ""; } elseif (isset($event['location_id']) && $event['location_id']) { $replacement = eme_add_directions_form($location); } } elseif ($event && preg_match('/#_EVENTS_FILTERFORM/', $result)) { if ($target == "rss" || $target == "text" || eme_is_single_event_page()) { $replacement = ""; } else { $replacement = eme_filter_form(); } } elseif ($event && preg_match('/#_ADDBOOKINGFORM$/', $result)) { if ($target == "rss" || $target == "text") { $replacement = ""; } else { if ($booking_id_done && eme_event_can_pay_online($event)) { $booking = eme_get_booking($booking_id_done); if (eme_get_total_booking_price($event, $booking) > 0) { $replacement = eme_payment_form($event, $booking_id_done); } else { $replacement = eme_add_booking_form($event['event_id'], $show_message_on_add); } } else { $replacement = eme_add_booking_form($event['event_id'], $show_message_on_add); } } } elseif ($event && preg_match('/#_ADDBOOKINGFORM_IF_NOT_REGISTERED/', $result)) { if ($target == "rss" || $target == "text") { $replacement = ""; } elseif (is_user_logged_in()) { // we show the form if the user did not register yet, or after registration to show the paypal form if ($booking_id_done && eme_event_can_pay_online($event)) { $booking = eme_get_booking($booking_id_done); if (eme_get_total_booking_price($event, $booking) > 0) { $replacement = eme_payment_form($event, $booking_id_done); } elseif (!eme_get_booking_ids_by_wp_id($current_userid, $event['event_id'])) { $replacement = eme_add_booking_form($event['event_id'], $show_message_on_add); } } elseif (!eme_get_booking_ids_by_wp_id($current_userid, $event['event_id'])) { $replacement = eme_add_booking_form($event['event_id'], $show_message_on_add); } } } elseif ($event && preg_match('/#_REMOVEBOOKINGFORM$/', $result)) { if ($target == "rss" || $target == "text") { $replacement = ""; } else { // when the booking just happened and the user needs to pay, we don't show the remove booking form if ($booking_id_done && eme_event_can_pay_online($event)) { $replacement = ""; } else { $replacement = eme_delete_booking_form($event['event_id'], $show_message_on_remove); } } } elseif ($event && preg_match('/#_REMOVEBOOKINGFORM_IF_REGISTERED/', $result)) { if ($target == "rss" || $target == "text") { $replacement = ""; } elseif (is_user_logged_in()) { // when the booking just happened and the user needs to pay, we don't show the remove booking form if ($booking_id_done && eme_event_can_pay_online($event)) { $replacement = ""; } elseif (eme_get_booking_ids_by_wp_id($current_userid, $event['event_id'])) { $replacement = eme_delete_booking_form($event['event_id'], $show_message_on_remove); } } } elseif ($event && preg_match('/#_(AVAILABLESPACES|AVAILABLESEATS)$/', $result)) { $replacement = eme_get_available_seats($event['event_id']); } elseif ($deprecated && preg_match('/#_(AVAILABLESPACES|AVAILABLESEATS)(\\d+)/', $result, $matches) || preg_match('/#_(AVAILABLESPACES|AVAILABLESEATS)\\{(\\d+)\\}/', $result, $matches)) { $field_id = intval($matches[2]) - 1; if (eme_is_multi($event['event_seats'])) { $seats = eme_get_available_multiseats($event['event_id']); if (array_key_exists($field_id, $seats)) { $replacement = $seats[$field_id]; } } } elseif ($event && preg_match('/#_(TOTALSPACES|TOTALSEATS)$/', $result)) { $replacement = $event['event_seats']; } elseif ($deprecated && preg_match('/#_(TOTALSPACES|TOTALSEATS)(\\d+)/', $result, $matches) || preg_match('/#_(TOTALSPACES|TOTALSEATS)\\{(\\d+)\\}/', $result, $matches)) { $field_id = intval($matches[2]) - 1; if (eme_is_multi($event['event_seats'])) { $seats = eme_convert_multi2array($event['event_seats']); if (array_key_exists($field_id, $seats)) { $replacement = $seats[$field_id]; } } } elseif ($event && preg_match('/#_(RESERVEDSPACES|BOOKEDSEATS)$/', $result)) { $replacement = eme_get_booked_seats($event['event_id']); } elseif ($deprecated && preg_match('/#_(RESERVEDSPACES|BOOKEDSEATS)(\\d+)/', $result, $matches) || preg_match('/#_(RESERVEDSPACES|BOOKEDSEATS)\\{(\\d+)\\}/', $result, $matches)) { $field_id = intval($matches[2]) - 1; if (eme_is_multi($event['event_seats'])) { $seats = eme_get_booked_multiseats($event['event_id']); if (array_key_exists($field_id, $seats)) { $replacement = $seats[$field_id]; } } } elseif ($event && preg_match('/#_(PENDINGSPACES|PENDINGSEATS)$/', $result)) { $replacement = eme_get_pending_seats($event['event_id']); } elseif ($event && preg_match('/#_(PENDINGSPACES|PENDINGSEATS)\\{(\\d+)\\}/', $result, $matches)) { $field_id = intval($matches[2]) - 1; if (eme_is_multi($event['event_seats'])) { $seats = eme_get_pending_multiseats($event['event_id']); if (array_key_exists($field_id, $seats)) { $replacement = $seats[$field_id]; } } } elseif ($event && preg_match('/#_(APPROVEDSPACES|APPROVEDSEATS)$/', $result)) { $replacement = eme_get_approved_seats($event['event_id']); } elseif ($event && preg_match('/#_(APPROVEDSPACES|APPROVEDSEATS)\\{(\\d+)\\}/', $result, $matches)) { $field_id = intval($matches[2]) - 1; if (eme_is_multi($event['event_seats'])) { $seats = eme_get_approved_multiseats($event['event_id']); if (array_key_exists($field_id, $seats)) { $replacement = $seats[$field_id]; } } } elseif ($event && preg_match('/#_USER_(RESERVEDSPACES|BOOKEDSEATS)$/', $result)) { if (is_user_logged_in()) { $replacement = eme_get_booked_seats_by_wp_event_id($current_userid, $event['event_id']); } } elseif ($event && preg_match('/#_LINKEDNAME/', $result)) { $event_link = eme_event_url($event, $lang); if ($target == "html") { $replacement = "<a href='{$event_link}' title='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'>" . eme_trans_sanitize_html($event['event_name'], $lang) . "</a>"; } else { $replacement = eme_translate($event['event_name'], $lang); } if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_ICALLINK/', $result)) { $url = site_url("/?eme_ical=public_single&event_id=" . $event['event_id']); $replacement = "<a href='{$url}'>ICAL</a>"; if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_ICALURL/', $result)) { $replacement = site_url("/?eme_ical=public_single&event_id=" . $event['event_id']); } elseif ($event && preg_match('/#_EVENTIMAGE$/', $result)) { if (!empty($event['event_image_id'])) { $event['event_image_url'] = wp_get_attachment_url($event['event_image_id']); } if ($event['event_image_url'] != '') { $replacement = "<img src='" . $event['event_image_url'] . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>"; if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } } elseif ($event && preg_match('/#_EVENTIMAGEURL$/', $result)) { if (!empty($event['event_image_id'])) { $event['event_image_url'] = wp_get_attachment_url($event['event_image_id']); } if ($event['event_image_url'] != '') { $replacement = $event['event_image_url']; } } elseif ($event && preg_match('/#_EVENTIMAGETHUMB$/', $result)) { if (!empty($event['event_image_id'])) { $thumb_array = image_downsize($event['event_image_id'], get_option('eme_thumbnail_size')); $thumb_url = $thumb_array[0]; $thumb_width = $thumb_array[1]; $thumb_height = $thumb_array[2]; $replacement = "<img width='{$thumb_width}' height='{$thumb_height}' src='" . $thumb_url . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>"; if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } } elseif ($event && preg_match('/#_EVENTIMAGETHUMBURL$/', $result)) { if (!empty($event['event_image_id'])) { $thumb_array = image_downsize($event['event_image_id'], get_option('eme_thumbnail_size')); $thumb_url = $thumb_array[0]; $replacement = $thumb_url; } } elseif ($event && preg_match('/#_EVENTIMAGETHUMB\\{(.+)\\}/', $result, $matches)) { if (!empty($event['event_image_id'])) { $thumb_array = image_downsize($event['event_image_id'], $matches[1]); $thumb_url = $thumb_array[0]; $thumb_width = $thumb_array[1]; $thumb_height = $thumb_array[2]; $replacement = "<img width='{$thumb_width}' height='{$thumb_height}' src='" . $thumb_url . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>"; if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } } elseif ($legacy && $event && preg_match('/#_EVENTIMAGETHUMB\\[(.+)\\]/', $result, $matches)) { if (!empty($event['event_image_id'])) { $thumb_array = image_downsize($event['event_image_id'], $matches[1]); $thumb_url = $thumb_array[0]; $thumb_width = $thumb_array[1]; $thumb_height = $thumb_array[2]; $replacement = "<img width='{$thumb_width}' height='{$thumb_height}' src='" . $thumb_url . "' alt='" . eme_trans_sanitize_html($event['event_name'], $lang) . "'/>"; if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } } elseif ($event && preg_match('/#_EVENTIMAGETHUMBURL\\{(.+)\\}/', $result, $matches)) { if (!empty($event['event_image_id'])) { $thumb_array = image_downsize($event['event_image_id'], $matches[1]); $thumb_url = $thumb_array[0]; $replacement = $thumb_url; } } elseif ($legacy && $event && preg_match('/#_EVENTIMAGETHUMBURL\\[(.+)\\]/', $result, $matches)) { if (!empty($event['event_image_id'])) { $thumb_array = image_downsize($event['event_image_id'], $matches[1]); $thumb_url = $thumb_array[0]; $replacement = $thumb_url; } } elseif ($event && preg_match('/#_EVENTATT\\{(.+)\\}\\{(.+)\\}/', $result, $matches)) { $tmp_event_id = intval($matches[1]); $tmp_event_attkey = $matches[2]; $tmp_event = eme_get_event($tmp_event_id); if (isset($tmp_event['event_attributes'][$tmp_event_attkey])) { $replacement = $tmp_event['event_attributes'][$tmp_event_attkey]; } } elseif ($event && preg_match('/#_MYLOCATIONATT\\{(.+)\\}/', $result, $matches)) { $tmp_attkey = $matches[1]; if (isset($location['location_attributes'][$tmp_attkey])) { $replacement = $location['location_attributes'][$tmp_attkey]; } } elseif ($event && preg_match('/#_EVENTPAGEURL\\{(.+)\\}/', $result, $matches)) { $events_page_link = eme_get_events_page(true, false); $replacement = add_query_arg(array('event_id' => intval($matches[1])), $events_page_link); if (!empty($lang)) { $replacement = add_query_arg(array('lang' => $lang), $replacement); } } elseif ($legacy && $event && preg_match('/#_EVENTPAGEURL\\[(.+)\\]/', $result, $matches)) { $events_page_link = eme_get_events_page(true, false); $replacement = add_query_arg(array('event_id' => intval($matches[1])), $events_page_link); if (!empty($lang)) { $replacement = add_query_arg(array('lang' => $lang), $replacement); } } elseif ($event && preg_match('/#_EVENTPAGEURL$/', $result)) { $replacement = eme_event_url($event, $lang); } elseif ($event && preg_match('/#_(NAME|EVENTNAME)$/', $result)) { $field = "event_name"; if (isset($event[$field])) { $replacement = $event[$field]; } if ($target == "html") { $replacement = eme_trans_sanitize_html($replacement, $lang); $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = eme_translate($replacement, $lang); $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = eme_translate($replacement, $lang); $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_EVENTID/', $result)) { $field = "event_id"; $replacement = $event[$field]; if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_DAYS_TILL_START/', $result)) { $now = date("Y-m-d"); $replacement = eme_daydifference($now, $event['event_start_date']); } elseif ($event && preg_match('/#_DAYS_TILL_END/', $result)) { $now = date("Y-m-d"); $replacement = eme_daydifference($now, $event['event_end_date']); } elseif ($event && preg_match('/#_HOURS_TILL_START/', $result)) { $now = date("Y-m-d H:i"); $replacement = eme_hourdifference($now, $event['event_start_date'] . " " . $event['event_start_time']); } elseif ($event && preg_match('/#_HOURS_TILL_END/', $result)) { $now = date("Y-m-d H:i"); $replacement = eme_hourdifference($now, $event['event_end_date'] . " " . $event['event_end_time']); } elseif ($event && preg_match('/#_EVENTPRICE$|#_PRICE$/', $result)) { $field = "price"; if ($event[$field]) { $replacement = $event[$field]; } if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($deprecated && $event && preg_match('/#_(EVENT)?PRICE(\\d+)/', $result, $matches) || $event && preg_match('/#_(EVENT)?PRICE\\{(\\d+)\\}/', $result, $matches)) { $field_id = intval($matches[2] - 1); if ($event["price"] && eme_is_multi($event["price"])) { $prices = eme_convert_multi2array($event["price"]); if (is_array($prices) && array_key_exists($field_id, $prices)) { $replacement = $prices[$field_id]; if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } } } elseif ($event && preg_match('/#_CURRENCY/', $result)) { $field = "currency"; // currency is only important if the price is not empty as well if ($event['price']) { $replacement = $event[$field]; } if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_ATTENDEES/', $result)) { $replacement = eme_get_attendees_list_for($event); if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_BOOKINGS/', $result)) { $replacement = eme_get_bookings_list_for_event($event); if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_(CONTACTNAME|CONTACTPERSON)/', $result)) { $contact = eme_get_contact($event); if ($contact) { $replacement = $contact->display_name; } $replacement = eme_trans_sanitize_html($replacement, $lang); if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_(CONTACTEMAIL|PLAIN_CONTACTEMAIL)/', $result)) { $contact = eme_get_contact($event); if ($contact) { $replacement = $contact->user_email; if ($target == "html") { // ascii encode for primitive harvesting protection ... $replacement = eme_ascii_encode($replacement); $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } } elseif ($event && preg_match('/#_CONTACTPHONE/', $result)) { $contact = eme_get_contact($event); if ($contact) { $phone = eme_get_user_phone($contact->ID); // ascii encode for primitive harvesting protection ... $replacement = eme_ascii_encode($phone); } if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_AUTHORNAME/', $result)) { $author = eme_get_author($event); if ($author) { $replacement = $author->display_name; } $replacement = eme_trans_sanitize_html($replacement, $lang); if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_AUTHOREMAIL/', $result)) { $author = eme_get_author($event); if ($author) { $replacement = $author->user_email; if ($target == "html") { // ascii encode for primitive harvesting protection ... $replacement = eme_ascii_encode($replacement); $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } } elseif ($event && preg_match('/#_AUTHORPHONE/', $result)) { $author = eme_get_author($event); if ($author) { $phone = eme_get_user_phone($author->ID); // ascii encode for primitive harvesting protection ... $replacement = eme_ascii_encode($phone); } if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif (preg_match('/#_EVENTCREATIONDATE/', $result)) { $replacement = eme_localised_date($event['creation_date']); } elseif (preg_match('/#_EVENTMODIFDATE/', $result)) { $replacement = eme_localised_date($event['modif_date']); } elseif (preg_match('/#_EVENTCREATIONTIME/', $result)) { $replacement = eme_localised_time($event['creation_date']); } elseif (preg_match('/#_EVENTMODIFTIME/', $result)) { $replacement = eme_localised_time($event['modif_date']); } elseif ($event && preg_match('/#[A-Za-z]$/', $result)) { // matches all PHP date placeholders for startdate-time $replacement = eme_localised_date($event['event_start_date'] . " " . $event['event_start_time'], ltrim($result, "#")); if (get_option('eme_time_remove_leading_zeros') && $result == "#i") { $replacement = ltrim($replacement, "0"); } } elseif ($event && preg_match('/#@[A-Za-z]$/', $result)) { // matches all PHP time placeholders for enddate-time $replacement = eme_localised_date($event['event_end_date'] . " " . $event['event_end_time'], ltrim($result, "#@")); if (get_option('eme_time_remove_leading_zeros') && $result == "#@i") { $replacement = ltrim($replacement, "0"); } } elseif ($event && preg_match('/#_EVENTCATEGORYIDS$/', $result) && get_option('eme_categories_enabled')) { $categories = $event['event_category_ids']; if ($target == "html") { $replacement = eme_trans_sanitize_html($categories, $lang); $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = eme_trans_sanitize_html($categories, $lang); $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = eme_trans_sanitize_html($categories, $lang); $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_(EVENT)?CATEGORIES$/', $result) && get_option('eme_categories_enabled')) { $categories = eme_get_event_category_names($event['event_id']); if ($target == "html") { $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang); $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = eme_translate(join(", ", $categories), $lang); $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = eme_translate(join(", ", $categories), $lang); $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_EVENTCATEGORYDESCRIPTIONS$/', $result) && get_option('eme_categories_enabled')) { $categories = eme_get_event_category_descriptions($event['event_id']); if ($target == "html") { $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang); $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = eme_translate(join(", ", $categories), $lang); $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = eme_translate(join(", ", $categories), $lang); $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_LINKED(EVENT)?CATEGORIES$/', $result) && get_option('eme_categories_enabled')) { $categories = eme_get_event_categories($event['event_id']); $cat_links = array(); foreach ($categories as $category) { $cat_link = eme_category_url($category); $cat_name = $category['category_name']; if ($target == "html") { array_push($cat_links, "<a href='{$cat_link}' title='" . eme_trans_sanitize_html($cat_name, $lang) . "'>" . eme_trans_sanitize_html($cat_name, $lang) . "</a>"); } else { array_push($cat_links, eme_translate($cat_name, $lang)); } } $replacement = join(", ", $cat_links); if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = eme_translate(join(", ", $cat_links), $lang); $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = eme_translate(join(", ", $cat_links), $lang); $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/^#_(EVENT)?CATEGORIES\\{(.*?)\\}\\{(.*?)\\}/', $result, $matches) && get_option('eme_categories_enabled')) { $include_cats = $matches[2]; $exclude_cats = $matches[3]; $extra_conditions_arr = array(); if (!empty($include_cats)) { array_push($extra_conditions_arr, "category_id IN ({$include_cats})"); } if (!empty($exclude_cats)) { array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})"); } $extra_conditions = join(" AND ", $extra_conditions_arr); $categories = eme_get_event_category_names($event['event_id'], $extra_conditions); if ($target == "html") { $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang); $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = eme_translate(join(", ", $categories), $lang); $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = eme_translate(join(", ", $categories), $lang); $replacement = apply_filters('eme_text', $replacement); } } elseif ($legacy && $event && preg_match('/^#_(EVENT)?CATEGORIES\\[(.*?)\\]\\[(.*?)\\]/', $result, $matches) && get_option('eme_categories_enabled')) { $include_cats = $matches[2]; $exclude_cats = $matches[3]; $extra_conditions_arr = array(); if (!empty($include_cats)) { array_push($extra_conditions_arr, "category_id IN ({$include_cats})"); } if (!empty($exclude_cats)) { array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})"); } $extra_conditions = join(" AND ", $extra_conditions_arr); $categories = eme_get_event_category_names($event['event_id'], $extra_conditions); if ($target == "html") { $replacement = eme_trans_sanitize_html(join(", ", $categories), $lang); $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = eme_translate(join(", ", $categories), $lang); $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = eme_translate(join(", ", $categories), $lang); $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_LINKED(EVENT)?CATEGORIES\\{(.*?)\\}\\{(.*?)\\}/', $result, $matches) && get_option('eme_categories_enabled')) { $include_cats = $matches[2]; $exclude_cats = $matches[3]; $extra_conditions_arr = array(); if (!empty($include_cats)) { array_push($extra_conditions_arr, "category_id IN ({$include_cats})"); } if (!empty($exclude_cats)) { array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})"); } $extra_conditions = join(" AND ", $extra_conditions_arr); $categories = eme_get_event_categories($event['event_id'], $extra_conditions); $cat_links = array(); foreach ($categories as $category) { $cat_link = eme_category_url($category); $cat_name = $category['category_name']; if ($target == "html") { array_push($cat_links, "<a href='{$cat_link}' title='" . eme_trans_sanitize_html($cat_name, $lang) . "'>" . eme_trans_sanitize_html($cat_name, $lang) . "</a>"); } else { array_push($cat_links, eme_translate($cat_name, $lang)); } } $replacement = join(", ", $cat_links); if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = eme_translate(join(", ", $cat_links), $lang); $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = eme_translate(join(", ", $cat_links), $lang); $replacement = apply_filters('eme_text', $replacement); } } elseif ($legacy && $event && preg_match('/#_LINKED(EVENT)?CATEGORIES\\[(.*?)\\]\\[(.*?)\\]/', $result, $matches) && get_option('eme_categories_enabled')) { $include_cats = $matches[2]; $exclude_cats = $matches[3]; $extra_conditions_arr = array(); if (!empty($include_cats)) { array_push($extra_conditions_arr, "category_id IN ({$include_cats})"); } if (!empty($exclude_cats)) { array_push($extra_conditions_arr, "category_id NOT IN ({$exclude_cats})"); } $extra_conditions = join(" AND ", $extra_conditions_arr); $categories = eme_get_event_categories($event['event_id'], $extra_conditions); $cat_links = array(); foreach ($categories as $category) { $cat_link = eme_category_url($category); $cat_name = $category['category_name']; if ($target == "html") { array_push($cat_links, "<a href='{$cat_link}' title='" . eme_trans_sanitize_html($cat_name, $lang) . "'>" . eme_trans_sanitize_html($cat_name, $lang) . "</a>"); } else { array_push($cat_links, eme_translate($cat_name, $lang)); } } $replacement = join(", ", $cat_links); if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = eme_translate(join(", ", $cat_links), $lang); $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = eme_translate(join(", ", $cat_links), $lang); $replacement = apply_filters('eme_text', $replacement); } } elseif (preg_match('/#_CALENDAR_DAY/', $result)) { $day_key = get_query_var('calendar_day'); $replacement = eme_localised_date($day_key); if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } elseif ($event && preg_match('/#_RECURRENCE_DESC|#_RECURRENCEDESC/', $result)) { if ($event['recurrence_id']) { $replacement = eme_get_recurrence_desc($event['recurrence_id']); if ($target == "html") { $replacement = apply_filters('eme_general', $replacement); } elseif ($target == "rss") { $replacement = apply_filters('eme_general_rss', $replacement); } else { $replacement = apply_filters('eme_text', $replacement); } } } elseif ($event && preg_match('/#_RECURRENCE_NBR/', $result)) { // returns the sequence number of an event in a recurrence series if ($event['recurrence_id']) { $events = eme_get_recurrence_eventids($event['recurrence_id']); $nbr = array_search($event['event_id'], $events); if ($nbr !== false) { $replacement = $nbr + 1; } } } elseif ($event && preg_match('/#_RSVPEND/', $result)) { // show the end date+time for which a user can rsvp for an event if (eme_is_event_rsvp($event)) { $rsvp_number_days = $event['rsvp_number_days']; $rsvp_number_hours = $event['rsvp_number_hours']; $rsvp_end_datetime = strtotime("-{$rsvp_number_days} days -{$rsvp_number_hours} hours", strtotime($event['event_start_date'] . " " . $event['event_start_time'])); $rsvp_end_date = eme_localised_unixdatetime($rsvp_end_datetime); $rsvp_end_time = eme_localised_unixtime($rsvp_end_datetime); $replacement = $rsvp_end_date . " " . $rsvp_end_time; } } elseif (preg_match('/#_IS_RSVP_ENDED/', $result)) { if (eme_is_event_rsvp($event)) { $event_start_datetime = strtotime($event['event_start_date'] . " " . $event['event_start_time']); $rsvp_end_datetime = $event_start_datetime - $event['rsvp_number_days'] * 60 * 60 * 24 - $event['rsvp_number_hours'] * 60 * 60; if ($rsvp_end_datetime < time()) { $replacement = 1; } else { $replacement = 0; } } } elseif (preg_match('/#_IS_SINGLE_DAY/', $result)) { if (eme_is_single_day_page()) { $replacement = 1; } else { $replacement = 0; } } elseif (preg_match('/#_IS_SINGLE_EVENT/', $result)) { if (eme_is_single_event_page()) { $replacement = 1; } else { $replacement = 0; } } elseif (preg_match('/#_IS_LOGGED_IN/', $result)) { if (is_user_logged_in()) { $replacement = 1; } else { $replacement = 0; } } elseif (preg_match('/#_IS_ADMIN_PAGE/', $result)) { if (is_admin()) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_RSVP_ENABLED/', $result)) { if (eme_is_event_rsvp($event)) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_PRIVATE_EVENT/', $result)) { if ($event['event_status'] == STATUS_PRIVATE) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_RECURRENT_EVENT/', $result)) { if ($event['recurrence_id']) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_ONGOING_EVENT/', $result)) { if (strtotime($event['event_start_date'] . " " . $event['event_start_time']) <= time() && strtotime($event['event_end_date'] . " " . $event['event_end_time']) >= time()) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_REGISTERED/', $result)) { if (is_user_logged_in() && eme_get_booking_ids_by_wp_id($current_userid, $event['event_id'])) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_MULTIPRICE/', $result)) { if (eme_is_multi($event['price'])) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_MULTISEAT/', $result)) { if (eme_is_multi($event['event_seats'])) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_ALLDAY/', $result)) { if ($event['event_properties']['all_day']) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_ATTENDANCE/', $result)) { if ($event['event_properties']['take_attendance']) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_AUTHOR$/', $result)) { if ($event['event_author'] == $current_userid) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_CONTACTPERSON/', $result)) { if ($event['event_contactperson_id'] == $current_userid) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_AUTHOR_OR_CONTACTPERSON/', $result)) { if ($event['event_author'] == $current_userid || $event['event_contactperson_id'] == $current_userid) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_MULTIDAY/', $result)) { if (strtotime($event['event_start_date']) != strtotime($event['event_end_date'])) { $replacement = 1; } else { $replacement = 0; } } elseif ($event && preg_match('/#_IS_FIRST_RECURRENCE/', $result)) { // returns 1 if the event is the first event in a recurrence series if ($event['recurrence_id']) { $events = eme_get_recurrence_eventids($event['recurrence_id']); $nbr = array_search($event['event_id'], $events); if ($nbr !== false && $nbr == 0) { $replacement = 1; } } } elseif ($event && preg_match('/#_IS_LAST_RECURRENCE/', $result)) { // returns 1 if the event is the last event in a recurrence series if ($event['recurrence_id']) { $events = eme_get_recurrence_eventids($event['recurrence_id']); $nbr = array_search($event['event_id'], $events); $last_index = count($events) - 1; if ($nbr !== false && $nbr == $last_index) { $replacement = 1; } } } elseif (preg_match('/#_LOCALE/', $result)) { $replacement = get_locale(); } else { $found = 0; } if ($found) { if ($need_escape) { $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement))); } if ($need_urlencode) { $replacement = rawurlencode($replacement); } $format = str_replace($orig_result, $replacement, $format); } } # now handle all possible location placeholders # but the eme_replace_locations_placeholders can't do "do_shortcode" at the end, because # this would cause [eme_if] tags to be replaced here already, while some placeholders of the # event haven't been replaced yet (like time placeholders, and event details) $format = eme_replace_locations_placeholders($format, $location, $target, 0, $lang); // for extra date formatting, eg. #_{d/m/Y} preg_match_all("/#(ESC|URL)?@?_\\{.*?\\}/", $format, $results); // make sure we set the largest matched placeholders first, otherwise if you found e.g. // #_LOCATION, part of #_LOCATIONPAGEURL would get replaced as well ... usort($results[0], 'sort_stringlenth'); foreach ($results[0] as $result) { $need_escape = 0; $need_urlencode = 0; $orig_result = $result; if (strstr($result, '#ESC')) { $result = str_replace("#ESC", "#", $result); $need_escape = 1; } elseif (strstr($result, '#URL')) { $result = str_replace("#URL", "#", $result); $need_urlencode = 1; } $replacement = ''; if (substr($result, 0, 3) == "#@_") { $my_date = "event_end_date"; $my_time = "event_end_time"; $offset = 4; } else { $my_date = "event_start_date"; $my_time = "event_start_time"; $offset = 3; } $replacement = eme_localised_date($event[$my_date] . " " . $event[$my_time], substr($result, $offset, strlen($result) - ($offset + 1))); if ($need_escape) { $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement))); } if ($need_urlencode) { $replacement = rawurlencode($replacement); } $format = str_replace($orig_result, $replacement, $format); } # we handle NOTES the last, this used to be the default behavior # so no placeholder replacement happened accidentaly in possible shortcodes inside #_NOTES # but since we have templates to aid in all that ... if (!$eme_enable_notes_placeholders) { $format = eme_replace_notes_placeholders($format, $event, $target); } // now, replace any language tags found in the format itself $format = eme_translate($format, $lang); if ($do_shortcode) { return do_shortcode($format); } else { return $format; } }
function eme_events_page_content() { global $wpdb; $format_header = get_option('eme_event_list_item_format_header'); if (empty($format_header)) { $format_header = DEFAULT_EVENT_LIST_HEADER_FORMAT; } $format_footer = get_option('eme_event_list_item_format_footer'); if (empty($format_footer)) { $format_footer = DEFAULT_EVENT_LIST_FOOTER_FORMAT; } if (isset($_REQUEST['eme_cancel_booking'])) { // GET for cancel links, POST for the cancel form $payment_randomid = eme_strip_tags($_REQUEST['eme_cancel_booking']); return eme_cancel_confirm_form($payment_randomid); } elseif (isset($_POST['eme_confirm_cancel_booking']) && isset($_POST['eme_pmt_rndid'])) { $payment_randomid = eme_strip_tags($_POST['eme_pmt_rndid']); $payment = eme_get_payment(0, $payment_randomid); $booking_ids = eme_get_payment_booking_ids($payment['id']); if (isset($_POST['eme_rsvp_nonce']) && wp_verify_nonce($_POST['eme_rsvp_nonce'], "cancel booking {$payment_randomid}")) { foreach ($booking_ids as $booking_id) { $booking = eme_get_booking($booking_id); // delete the booking before the mail is sent, so free spaces are correct eme_delete_booking($booking_id); eme_email_rsvp_booking($booking, "cancelRegistration"); // delete the booking answers after the mail is sent, so the answers can still be used in the mail eme_delete_answers($booking_id); } eme_delete_payment($payment['id']); } return "<div class='eme-rsvp-message'>" . __("The bookings have been cancelled", 'eme') . "</div>"; } elseif (get_query_var('eme_pmt_result') && get_option('eme_payment_show_custom_return_page')) { // show the result of a payment, but not for a multi-booking payment result $result = get_query_var('eme_pmt_result'); if ($result == 'succes') { $format = get_option('eme_payment_succes_format'); } else { $format = get_option('eme_payment_fail_format'); } if (get_option('eme_payment_add_bookingid_to_return') && get_query_var('eme_pmt_id') && get_query_var('event_id')) { $event = eme_get_event(intval(get_query_var('event_id'))); $payment_id = intval(get_query_var('eme_pmt_id')); $booking_ids = eme_get_payment_booking_ids($payment_id); if ($booking_ids) { // since each booking is for a different event, we can't know which one to show // so we show only the first one $booking = eme_get_booking($booking_ids[0]); return eme_replace_booking_placeholders($format, $event, $booking); } else { return; } } elseif (get_query_var('event_id')) { $event = eme_get_event(intval(get_query_var('event_id'))); return eme_replace_placeholders($format, $event); } else { return $format; } } elseif (get_query_var('eme_pmt_id')) { $payment_id = intval(get_query_var('eme_pmt_id')); $booking_ids = eme_get_payment_booking_ids($payment_id); if (count($booking_ids) == 1) { $page_body = eme_payment_form("", $payment_id); } else { $page_body = eme_multipayment_form($payment_id); } return $page_body; } if (get_query_var('eme_town')) { $eme_town = eme_sanitize_request(get_query_var('eme_town')); $location_ids = join(',', eme_get_town_location_ids($eme_town)); $stored_format = get_option('eme_event_list_item_format'); if (count($location_ids) > 0) { $format_header = get_option('eme_location_list_item_format_header'); if (empty($format_header)) { $format_header = DEFAULT_EVENT_LIST_HEADER_FORMAT; } $format_footer = get_option('eme_location_list_item_format_footer'); if (empty($format_footer)) { $format_footer = DEFAULT_EVENT_LIST_FOOTER_FORMAT; } $page_body = eme_get_events_list(get_option('eme_event_list_number_items'), "future", "ASC", $stored_format, $format_header, $format_footer, 0, '', '', 0, '', '', 0, $location_ids); } else { $page_body = "<div id='events-no-events'>" . get_option('eme_no_events_message') . "</div>"; } return $page_body; } if (get_query_var('location_id')) { $location = eme_get_location(intval(get_query_var('location_id'))); $single_location_format = get_option('eme_single_location_format'); $page_body = eme_replace_locations_placeholders($single_location_format, $location); return $page_body; } if (!get_query_var('calendar_day') && get_query_var('eme_event_cat')) { $format_header = get_option('eme_cat_event_list_item_format_header'); if (empty($format_header)) { $format_header = DEFAULT_CAT_EVENT_LIST_HEADER_FORMAT; } $format_footer = get_option('eme_cat_event_list_item_format_footer'); if (empty($format_footer)) { $format_footer = DEFAULT_CAT_EVENT_LIST_FOOTER_FORMAT; } $eme_event_cat = eme_sanitize_request(get_query_var('eme_event_cat')); $cat_ids = join(',', eme_get_category_ids($eme_event_cat)); $stored_format = get_option('eme_event_list_item_format'); if (!empty($cat_ids)) { $page_body = eme_get_events_list(get_option('eme_event_list_number_items'), "future", "ASC", $stored_format, $format_header, $format_footer, 0, $cat_ids); } else { $page_body = "<div id='events-no-events'>" . get_option('eme_no_events_message') . "</div>"; } return $page_body; } //if (isset ( $_REQUEST['event_id'] ) && $_REQUEST['event_id'] != '') { if (eme_is_single_event_page()) { // single event page $event_id = intval(get_query_var('event_id')); return eme_display_single_event($event_id); } elseif (get_query_var('calendar_day')) { $scope = eme_sanitize_request(get_query_var('calendar_day')); $location_id = isset($_GET['location_id']) ? urldecode($_GET['location_id']) : ''; $category = isset($_GET['category']) ? urldecode($_GET['category']) : ''; $notcategory = isset($_GET['notcategory']) ? urldecode($_GET['notcategory']) : ''; $author = isset($_GET['author']) ? urldecode($_GET['author']) : ''; $contact_person = isset($_GET['contact_person']) ? urldecode($_GET['contact_person']) : ''; $event_list_item_format = get_option('eme_event_list_item_format'); $show_single_event = 1; $page_body = eme_get_events_list(0, $scope, "ASC", $event_list_item_format, $format_header, $format_footer, $location_id, $category, '', 0, $author, $contact_person, 0, '', 0, 1, 0, $notcategory, 0, 0, 0, 0, "", $show_single_event); return $page_body; } else { // Multiple events page isset($_GET['scope']) ? $scope = eme_sanitize_request($_GET['scope']) : ($scope = "future"); $stored_format = get_option('eme_event_list_item_format'); if (get_option('eme_display_calendar_in_events_page')) { $page_body = eme_get_calendar('full=1'); } else { $page_body = eme_get_events_list(get_option('eme_event_list_number_items'), $scope, "ASC", $stored_format, $format_header, $format_footer, 0); } return $page_body; } }