Exemplo n.º 1
0
function eme_get_person_id_by_wp_id($wp_id) {
   global $wpdb; 
   $people_table = $wpdb->prefix.PEOPLE_TBNAME;
   $wp_id = eme_sanitize_request($wp_id);
   $sql = "SELECT person_id FROM $people_table WHERE wp_id = '$wp_id'";
   return($wpdb->get_var($sql));
}
Exemplo n.º 2
0
function eme_replace_placeholders($format, $event, $target = "html", $do_shortcode = 1, $lang = '')
{
    global $eme_need_gmap_js, $eme_timezone;
    // 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;
        }
    }
    $eme_date_obj_now = new ExpressiveDate(null, $eme_timezone);
    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&amp;eme_admin_action=edit_event&amp;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&amp;eme_admin_action=edit_event&amp;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&amp;eme_admin_action=booking_printable&amp;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&amp;eme_admin_action=booking_printable&amp;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&amp;eme_admin_action=booking_csv&amp;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&amp;eme_admin_action=booking_csv&amp;event_id=" . $event['event_id']);
            }
        } elseif ($event && preg_match('/#_STARTDATE/', $result)) {
            $replacement = eme_localised_date($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_STARTTIME/', $result)) {
            $replacement = eme_localised_time($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_ENDDATE/', $result)) {
            $replacement = eme_localised_date($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone);
        } elseif ($event && preg_match('/#_ENDTIME/', $result)) {
            $replacement = eme_localised_time($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone);
        } 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)) {
            $eme_start_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $eme_end_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            if ($eme_start_obj->greaterThan($eme_date_obj_now)) {
                $replacement = "eme-future-event";
            } elseif ($eme_start_obj->lessOrEqualTo($eme_date_obj_now) && $eme_end_obj->greaterOrEqualTo($eme_date_obj_now)) {
                $replacement = "eme-ongoing-event";
            } else {
                $replacement = "eme-past-event";
            }
        } elseif ($event && preg_match('/#_12HSTARTTIME$/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone)->format('h:i A');
        } elseif ($event && preg_match('/#_12HENDTIME$/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone)->format('h:i A');
        } elseif ($event && preg_match('/#_12HSTARTTIME_NOLEADINGZERO/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone)->format('g:i A');
            if (get_option('eme_time_remove_leading_zeros')) {
                $replacement = str_replace(":00", "", $replacement);
                $replacement = str_replace(":0", ":", $replacement);
            }
        } elseif ($event && preg_match('/#_12HENDTIME_NOLEADINGZERO/', $result)) {
            $replacement = $eme_date_obj_now->copy()->setTimestampFromString($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone)->format('g:i A');
            if (get_option('eme_time_remove_leading_zeros')) {
                $replacement = str_replace(":00", "", $replacement);
                $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 {
                $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 = "";
            } else {
                $not_registered_only = 1;
                $replacement = eme_add_booking_form($event['event_id'], $show_message_on_add, $not_registered_only);
            }
        } 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;
            $replacement = 0;
            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;
            $replacement = 0;
            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;
            $replacement = 0;
            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;
            $replacement = 0;
            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&amp;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&amp;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 = intval($event[$field]);
        } elseif ($event && preg_match('/#_SINGLE_EVENTPAGE_EVENTID/', $result)) {
            // returns the event id of the single event page currently shown
            if (eme_is_single_event_page()) {
                $replacement = intval(get_query_var('event_id'));
            }
        } elseif ($event && preg_match('/#_DAYS_TILL_START/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $replacement = $eme_date_obj_now->getDifferenceInDays($eme_date_obj);
        } elseif ($event && preg_match('/#_DAYS_TILL_END/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            $replacement = $eme_date_obj_now->getDifferenceInDays($eme_date_obj);
        } elseif ($event && preg_match('/#_HOURS_TILL_START/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $replacement = round($eme_date_obj_now->getDifferenceInHours($eme_date_obj));
        } elseif ($event && preg_match('/#_HOURS_TILL_END/', $result)) {
            $eme_date_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            $replacement = round($eme_date_obj_now->getDifferenceInHours($eme_date_obj));
        } 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'] . " " . $eme_timezone);
        } elseif (preg_match('/#_EVENTMODIFDATE/', $result)) {
            $replacement = eme_localised_date($event['modif_date'] . " " . $eme_timezone);
        } elseif (preg_match('/#_EVENTCREATIONTIME/', $result)) {
            $replacement = eme_localised_time($event['creation_date'] . " " . $eme_timezone);
        } elseif (preg_match('/#_EVENTMODIFTIME/', $result)) {
            $replacement = eme_localised_time($event['modif_date'] . " " . $eme_timezone);
        } 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'] . " " . $eme_timezone, 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'] . " " . $eme_timezone, 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('/#_EVENTCATEGORIES_CSS$/', $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 ($event && preg_match('/^#_EVENTCATEGORIES_CSS\\{(.*?)\\}\\{(.*?)\\}/', $result, $matches) && get_option('eme_categories_enabled')) {
            $include_cats = $matches[1];
            $exclude_cats = $matches[2];
            $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 . " " . $eme_timezone);
            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_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
                $rsvp_end_obj->minusDays($rsvp_number_days);
                $rsvp_end_obj->minusHours($rsvp_number_hours);
                $rsvp_end_date = eme_localised_date($rsvp_end_obj->getDateTime() . " " . $eme_timezone);
                $rsvp_end_time = eme_localised_time($rsvp_end_obj->getDateTime() . " " . $eme_timezone);
                $replacement = $rsvp_end_date . " " . $rsvp_end_time;
            }
        } elseif ($event && preg_match('/#_IS_RSVP_ENDED/', $result)) {
            if (eme_is_event_rsvp($event)) {
                $rsvp_number_days = $event['rsvp_number_days'];
                $rsvp_number_hours = $event['rsvp_number_hours'];
                $rsvp_end_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
                $rsvp_end_obj->minusDays($rsvp_number_days);
                $rsvp_end_obj->minusHours($rsvp_number_hours);
                if ($rsvp_end_obj->lessThan($eme_date_obj_now)) {
                    $replacement = 1;
                } else {
                    $replacement = 0;
                }
            }
        } elseif ($event && preg_match('/#_EVENT_EXTERNAL_REF/', $result)) {
            $replacement = $event['event_external_ref'];
            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('/#_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)) {
            $eme_start_obj = new ExpressiveDate($event['event_start_date'] . " " . $event['event_start_time'], $eme_timezone);
            $eme_end_obj = new ExpressiveDate($event['event_end_date'] . " " . $event['event_end_time'], $eme_timezone);
            if ($eme_start_obj->lessOrEqualTo($eme_date_obj_now) && $eme_end_obj->greaterOrEqualTo($eme_date_obj_now)) {
                $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 ($event['event_start_date'] != $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] . " " . $eme_timezone, 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;
    }
}
Exemplo n.º 3
0
function eme_replace_filter_form_placeholders($format, $multiple, $multisize, $scope_count, $fields, $category, $notcategory)
{
    if ($fields == "all") {
        $fields = "categories,locations,towns,weeks,months";
    }
    preg_match_all("/#_[A-Za-z0-9_]+/", $format, $placeholders);
    usort($placeholders[0], 'sort_stringlenth');
    // if one of these changes, also the eme_events.php needs changing for the "Next page" part
    $cat_post_name = "eme_cat_filter";
    $loc_post_name = "eme_loc_filter";
    $town_post_name = "eme_town_filter";
    $scope_post_name = "eme_scope_filter";
    $localised_scope_post_name = "eme_localised_scope_filter";
    $selected_scope = isset($_REQUEST[$scope_post_name]) ? eme_sanitize_request($_REQUEST[$scope_post_name]) : '';
    $selected_location = isset($_REQUEST[$loc_post_name]) ? eme_sanitize_request($_REQUEST[$loc_post_name]) : '';
    $selected_town = isset($_REQUEST[$town_post_name]) ? eme_sanitize_request($_REQUEST[$town_post_name]) : '';
    $selected_category = isset($_REQUEST[$cat_post_name]) ? eme_sanitize_request($_REQUEST[$cat_post_name]) : '';
    $extra_conditions_arr = array();
    if ($category != '') {
        $extra_conditions_arr[] = "(category_id IN ({$category}))";
    }
    if ($notcategory != '') {
        $extra_conditions_arr[] = "(category_id NOT IN ({$notcategory}))";
    }
    $extra_conditions = implode(' AND ', $extra_conditions_arr);
    $scope_fieldcount = 0;
    foreach ($placeholders[0] as $result) {
        $replacement = "";
        $eventful = 0;
        $found = 1;
        $orig_result = $result;
        if (preg_match('/#_(EVENTFUL_)?FILTER_CATS/', $result) && get_option('eme_categories_enabled')) {
            if (strstr($result, '#_EVENTFUL')) {
                $eventful = 1;
            }
            $categories = eme_get_categories($eventful, "future", $extra_conditions);
            if ($categories && (empty($fields) || strstr($fields, 'categories'))) {
                $cat_list = array();
                foreach ($categories as $this_category) {
                    $id = $this_category['category_id'];
                    $cat_list[$id] = eme_translate($this_category['category_name']);
                }
                asort($cat_list);
                if ($multiple) {
                    $cat_list = array(0 => __('Select one or more categories', 'eme')) + $cat_list;
                    $replacement = eme_ui_multiselect($selected_category, $cat_post_name, $cat_list, $multisize);
                } else {
                    $cat_list = array(0 => __('Select a category', 'eme')) + $cat_list;
                    $replacement = eme_ui_select($selected_category, $cat_post_name, $cat_list);
                }
            }
        } elseif (preg_match('/#_(EVENTFUL_)?FILTER_LOCS/', $result)) {
            if (strstr($result, '#_EVENTFUL')) {
                $eventful = 1;
            }
            $locations = eme_get_locations($eventful, "future");
            if ($locations && (empty($fields) || strstr($fields, 'locations'))) {
                $loc_list = array();
                foreach ($locations as $this_location) {
                    $id = $this_location['location_id'];
                    $loc_list[$id] = eme_translate($this_location['location_name']);
                }
                asort($loc_list);
                if ($multiple) {
                    $loc_list = array(0 => __('Select one or more locations', 'eme')) + $loc_list;
                    $replacement = eme_ui_multiselect($selected_location, $loc_post_name, $loc_list, $multisize);
                } else {
                    $loc_list = array(0 => __('Select a location', 'eme')) + $loc_list;
                    $replacement = eme_ui_select($selected_location, $loc_post_name, $loc_list);
                }
            }
        } elseif (preg_match('/#_(EVENTFUL_)?FILTER_TOWNS/', $result)) {
            if (strstr($result, '#_EVENTFUL')) {
                $eventful = 1;
            }
            $towns = eme_get_locations($eventful, "future");
            if ($towns && (empty($fields) || strstr($fields, 'towns'))) {
                $town_list = array();
                foreach ($towns as $this_town) {
                    $id = eme_translate($this_town['location_town']);
                    $town_list[$id] = $id;
                }
                asort($town_list);
                if ($multiple) {
                    $town_list = array(0 => __('Select one or more towns', 'eme')) + $town_list;
                    $replacement = eme_ui_multiselect($selected_town, $town_post_name, $town_list, $multisize);
                } else {
                    $town_list = array(0 => __('Select a town', 'eme')) + $town_list;
                    $replacement = eme_ui_select($selected_town, $town_post_name, $town_list);
                }
            }
        } elseif (preg_match('/#_FILTER_WEEKS/', $result)) {
            if ($scope_fieldcount == 0 && (empty($fields) || strstr($fields, 'weeks'))) {
                $replacement = eme_ui_select($selected_scope, $scope_post_name, eme_create_week_scope($scope_count));
                $scope_fieldcount++;
            }
        } elseif (preg_match('/#_FILTER_MONTHS/', $result)) {
            if ($scope_fieldcount == 0 && (empty($fields) || strstr($fields, 'months'))) {
                $replacement = eme_ui_select($selected_scope, $scope_post_name, eme_create_month_scope($scope_count));
                $scope_fieldcount++;
            }
        } elseif (preg_match('/#_FILTER_MONTHRANGE/', $result)) {
            if ($scope_fieldcount == 0 && (empty($fields) || strstr($fields, 'monthrange'))) {
                $replacement = "<input type='text' id='{$localised_scope_post_name}' name='{$localised_scope_post_name}' readonly='readonly' >";
                $replacement .= "<input type='hidden' id='{$scope_post_name}' name='{$scope_post_name}' value='" . eme_sanitize_html($selected_scope) . "'>";
                wp_enqueue_script('eme-jquery-datepick');
                wp_enqueue_style('eme-jquery-datepick', EME_PLUGIN_URL . "js/jquery-datepick/jquery.datepick.css");
                // jquery ui locales are with dashes, not underscores
                $locale_code = get_locale();
                $locale_code = preg_replace("/_/", "-", $locale_code);
                $locale_file = EME_PLUGIN_DIR . "js/jquery-datepick/jquery.datepick-{$locale_code}.js";
                $locale_file_url = EME_PLUGIN_URL . "js/jquery-datepick/jquery.datepick-{$locale_code}.js";
                // for english, no translation code is needed)
                if ($locale_code != "en-US") {
                    if (!file_exists($locale_file)) {
                        $locale_code = substr($locale_code, 0, 2);
                        $locale_file = EME_PLUGIN_DIR . "js/jquery-datepick/jquery.datepick-{$locale_code}.js";
                        $locale_file_url = EME_PLUGIN_URL . "js/jquery-datepick/jquery.datepick-{$locale_code}.js";
                    }
                    if (file_exists($locale_file)) {
                        wp_enqueue_script('eme-jquery-datepick-locale', $locale_file_url);
                    }
                }
                ob_start();
                ?>
            <script type="text/javascript">
            var locale_code = '<?php 
                echo $locale_code;
                ?>
';
            var firstDayOfWeek = <?php 
                echo get_option('start_of_week');
                ?>
;
            </script>
            <?php 
                $replacement .= ob_get_clean();
                $replacement .= "<script type='text/javascript' src='" . EME_PLUGIN_URL . "js/eme_filters.js'></script>";
            }
        } elseif (preg_match('/#_FILTER_YEARS/', $result)) {
            if ($scope_fieldcount == 0 && (empty($fields) || strstr($fields, 'years'))) {
                $replacement = eme_ui_select($selected_scope, $scope_post_name, eme_create_year_scope($scope_count));
                $scope_fieldcount++;
            }
        } else {
            $found = 0;
        }
        if ($found) {
            $replacement = apply_filters('eme_general', $replacement);
            $format = str_replace($orig_result, $replacement, $format);
        }
    }
    return do_shortcode($format);
}
Exemplo n.º 4
0
function eme_replace_locations_placeholders($format, $location = "", $target = "html", $do_shortcode = 1, $lang = '')
{
    // first 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($location['location_attributes'][$attRef])) {
            $replacement = $location['location_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);
    }
    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');
    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 = "";
        // echo "RESULT: $result <br>";
        // matches alla fields placeholder
        if (preg_match('/#_MAP/', $result)) {
            $replacement = eme_single_location_map($location);
            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('/#_PASTEVENTS/', $result)) {
            $replacement = eme_events_in_location_list($location, "past");
            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('/#_NEXTEVENTS/', $result)) {
            $replacement = eme_events_in_location_list($location);
            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('/#_ALLEVENTS/', $result)) {
            $replacement = eme_events_in_location_list($location, "all");
            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('/#_(ADDRESS|TOWN)/', $result)) {
            $field = "location_" . ltrim(strtolower($result), "#_");
            if (isset($location[$field])) {
                $replacement = $location[$field];
            }
            $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 (preg_match('/#_(NAME|LOCATIONNAME|LOCATION)$/', $result)) {
            $field = "location_name";
            if (isset($location[$field])) {
                $replacement = $location[$field];
            }
            $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 (preg_match('/#_LOCATIONID/', $result)) {
            $field = "location_id";
            $replacement = $location[$field];
            $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 (preg_match('/#_(IMAGE|LOCATIONIMAGE)$/', $result)) {
            if (!empty($location['location_image_id'])) {
                $location['location_image_url'] = wp_get_attachment_url($location['location_image_id']);
            }
            if (!empty($location['location_image_url'])) {
                $replacement = "<img src='" . $location['location_image_url'] . "' alt='" . eme_trans_sanitize_html($location['location_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 (preg_match('/#_(IMAGEURL|LOCATIONIMAGEURL)/', $result)) {
            if (!empty($location['location_image_id'])) {
                $location['location_image_url'] = wp_get_attachment_url($location['location_image_id']);
            }
            if ($location['location_image_url'] != '') {
                $replacement = $location['location_image_url'];
                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('/#_LOCATIONIMAGETHUMB$/', $result)) {
            if (!empty($location['location_image_id'])) {
                $thumb_array = image_downsize($location['location_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($location['location_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 (preg_match('/#_LOCATIONIMAGETHUMBURL/', $result)) {
            if (!empty($location['location_image_id'])) {
                $thumb_array = image_downsize($location['location_image_id'], get_option('eme_thumbnail_size'));
                $thumb_url = $thumb_array[0];
                $replacement = $thumb_url;
                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('/#_LOCATIONPAGEURL/', $result)) {
            $replacement = eme_location_url($location, $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 (preg_match('/#_LATITUDE/', $result)) {
            $field = "location_latitude";
            $replacement = $location[$field];
            $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 (preg_match('/#_LONGITUDE/', $result)) {
            $field = "location_longitude";
            $replacement = $location[$field];
            $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 (preg_match('/#_DIRECTIONS/', $result)) {
            $replacement = eme_add_directions_form($location);
            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('/#_CATEGORIES|#_LOCATIONCATEGORIES/', $result) && get_option('eme_categories_enabled')) {
            $categories = eme_get_location_category_names($location['location_id']);
            $replacement = eme_trans_sanitize_html(join(", ", $categories), $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 (preg_match('/#_LOCATIONCATEGORYDESCRIPTIONS/', $result) && get_option('eme_categories_enabled')) {
            $categories = eme_get_location_category_descriptions($location['location_id']);
            $replacement = eme_trans_sanitize_html(join(", ", $categories), $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 (preg_match('/#_EDITLOCATIONLINK/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_locations')) || current_user_can(get_option('eme_cap_author_locations')) && $location['location_author'] == $current_userid) {
                $replacement = "<a href=' " . admin_url("admin.php?page=eme-locations&amp;eme_admin_action=edit_location&amp;location_id=" . $location['location_id']) . "'>" . __('Edit') . "</a>";
            }
        } elseif (preg_match('/#_EDITLOCATIONURL/', $result)) {
            if (current_user_can(get_option('eme_cap_edit_locations')) || current_user_can(get_option('eme_cap_author_locations')) && $location['location_author'] == $current_userid) {
                $replacement = admin_url("admin.php?page=eme-locations&amp;eme_admin_action=edit_location&amp;location_id=" . $location['location_id']);
            }
        } elseif (preg_match('/#_IS_SINGLE_LOC/', $result)) {
            if (eme_is_single_location_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;
            }
        } 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);
        }
    }
    # we handle DESCRIPTION the last, so no placeholder replacement happens accidentaly in the text of #_DESCRIPTION
    if (preg_match('/#_DESCRIPTION|#_LOCATIONDETAILS/', $format, $placeholders)) {
        $result = $placeholders[0];
        $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 = "";
        $field = "location_description";
        if (isset($location[$field])) {
            $replacement = $location[$field];
        }
        // no real sanitizing needed, but possible translation
        // this is the same as for an event in fact
        $replacement = eme_translate($replacement);
        if ($target == "html") {
            $replacement = apply_filters('eme_notes', $replacement);
        } elseif ($target == "rss") {
            $replacement = apply_filters('eme_notes_rss', $replacement);
            $replacement = apply_filters('the_content_rss', $replacement);
        } else {
            $replacement = apply_filters('eme_text', $replacement);
        }
        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, replace any language tags found
    $format = eme_translate($format, $lang);
    // and now replace any shortcodes, if wanted
    if ($do_shortcode) {
        return do_shortcode($format);
    } else {
        return $format;
    }
}
Exemplo n.º 5
0
function eme_replace_booking_placeholders($format, $event, $booking, $is_multibooking = 0, $target = "html", $lang = '')
{
    $deprecated = get_option('eme_deprecated');
    preg_match_all("/#(ESC)?_?[A-Za-z0-9_]+(\\{[A-Za-z0-9_]+\\})?/", $format, $placeholders);
    $person = eme_get_person($booking['person_id']);
    $current_userid = get_current_user_id();
    $answers = eme_get_answers($booking['booking_id']);
    $payment_id = eme_get_booking_payment_id($booking['booking_id']);
    $payment = eme_get_payment($payment_id);
    $booking_ids = array();
    $bookings = array();
    if ($payment_id) {
        $booking_ids = eme_get_payment_booking_ids($payment_id);
        $bookings = eme_get_bookings($booking_ids);
    }
    usort($placeholders[0], 'sort_stringlenth');
    foreach ($placeholders[0] as $result) {
        $replacement = '';
        $found = 1;
        $need_escape = 0;
        $orig_result = $result;
        if (strstr($result, '#ESC')) {
            $result = str_replace("#ESC", "#", $result);
            $need_escape = 1;
        }
        if (preg_match('/#_RESPID/', $result)) {
            $replacement = $person['person_id'];
            $replacement = eme_sanitize_html($replacement);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_RESP(NAME|LASTNAME|FIRSTNAME|ZIP|CITY|STATE|COUNTRY|ADDRESS1|ADDRESS2|PHONE|EMAIL)/', $result)) {
            $field = preg_replace("/#_RESP/", "", $result);
            $field = strtolower($field);
            if ($field == "name") {
                $field = "lastname";
            }
            $replacement = $person[$field];
            $replacement = eme_sanitize_html($replacement);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_(RESPCOMMENT|COMMENT)/', $result)) {
            $replacement = $booking['booking_comment'];
            $replacement = eme_sanitize_html($replacement);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif ($deprecated && preg_match('/#_RESPSPACES(\\d+)/', $result, $matches) || preg_match('/#_RESPSPACES\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]) - 1;
            if (eme_is_multi($booking['booking_price'])) {
                $seats = eme_convert_multi2array($booking['booking_seats_mp']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif (preg_match('/#_TOTALPRICE$/', $result)) {
            $price = eme_get_total_booking_price($event, $booking);
            $replacement = sprintf("%01.2f", $price);
        } elseif (preg_match('/#_BOOKINGPRICEPERSEAT$/', $result)) {
            $price = eme_get_seat_booking_price($event, $booking);
            $replacement = sprintf("%01.2f", $price);
        } elseif (preg_match('/#_BOOKINGPRICEPERSEAT\\{(\\d+)\\}/', $result, $matches)) {
            // total price to pay per price if multiprice
            $total_prices = eme_get_seat_booking_multiprice($event, $booking);
            $field_id = intval($matches[1]) - 1;
            if (array_key_exists($field_id, $total_prices)) {
                $price = $total_prices[$field_id];
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif (preg_match('/#_TOTALPRICE\\{(\\d+)\\}/', $result, $matches)) {
            // total price to pay per price if multiprice
            $total_prices = eme_get_total_booking_multiprice($event, $booking);
            $field_id = intval($matches[1]) - 1;
            if (array_key_exists($field_id, $total_prices)) {
                $price = $total_prices[$field_id];
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif ($deprecated && preg_match('/#_TOTALPRICE(\\d+)/', $result, $matches)) {
            // total price to pay per price if multiprice
            $total_prices = eme_get_total_booking_multiprice($event, $booking);
            $field_id = intval($matches[1]) - 1;
            if (array_key_exists($field_id, $total_prices)) {
                $price = $total_prices[$field_id];
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif (preg_match('/#_CHARGE\\{(.+)\\}$/', $result, $matches)) {
            $price = eme_get_total_booking_price($event, $booking);
            $replacement = eme_payment_provider_extra_charge($price, $matches[1]);
        } elseif (preg_match('/#_RESPSPACES$/', $result)) {
            $replacement = eme_get_multitotal($booking['booking_seats']);
        } elseif (preg_match('/#_BOOKINGCREATIONDATE/', $result)) {
            $replacement = eme_localised_date($booking['creation_date']);
        } elseif (preg_match('/#_BOOKINGMODIFDATE/', $result)) {
            $replacement = eme_localised_date($booking['modif_date']);
        } elseif (preg_match('/#_BOOKINGCREATIONTIME/', $result)) {
            $replacement = eme_localised_time($booking['creation_date']);
        } elseif (preg_match('/#_BOOKINGMODIFTIME/', $result)) {
            $replacement = eme_localised_time($booking['modif_date']);
        } elseif (preg_match('/#_BOOKINGID/', $result)) {
            $replacement = $booking['booking_id'];
        } elseif (preg_match('/#_TRANSFER_NBR_BE97/', $result)) {
            $replacement = $booking['transfer_nbr_be97'];
        } elseif (preg_match('/#_PAYMENT_URL/', $result)) {
            if ($payment_id && eme_event_can_pay_online($event)) {
                $replacement = eme_payment_url($payment_id);
            }
        } elseif (preg_match('/#_CANCEL_LINK$/', $result)) {
            $url = eme_cancel_url($payment['random_id']);
            $replacement = "<a href='{$url}'>" . __('Cancel booking', 'eme') . "</a>";
        } elseif (preg_match('/#_CANCEL_URL$/', $result)) {
            $replacement = eme_cancel_url($payment['random_id']);
        } elseif (preg_match('/#_CANCEL_CODE$/', $result)) {
            $replacement = $payment['random_id'];
        } elseif (preg_match('/#_FIELDS/', $result)) {
            $field_replace = "";
            foreach ($answers as $answer) {
                $tmp_answer = eme_convert_answer2tag($answer);
                $field_replace .= $answer['field_name'] . ": {$tmp_answer}\n";
            }
            $replacement = eme_trans_sanitize_html($field_replace, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_PAYED/', $result)) {
            $replacement = $booking['booking_payed'] ? __('Yes') : __('No');
        } elseif ($deprecated && preg_match('/#_FIELDNAME(\\d+)/', $result, $matches) || preg_match('/#_FIELDNAME\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $formfield = eme_get_formfield_byid($field_id);
            $replacement = eme_trans_sanitize_html($formfield['field_name'], $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif ($deprecated && preg_match('/#_FIELD(\\d+)/', $result, $matches) || preg_match('/#_FIELD\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $formfield = eme_get_formfield_byid($field_id);
            $field_replace = "";
            foreach ($answers as $answer) {
                if ($answer['field_name'] == $formfield['field_name']) {
                    $tmp_answer = eme_convert_answer2tag($answer);
                    $field_replace = $tmp_answer;
                }
            }
            $replacement = eme_trans_sanitize_html($field_replace, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_FIELDVALUE\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $formfield = eme_get_formfield_byid($field_id);
            foreach ($answers as $answer) {
                if ($answer['field_name'] == $formfield['field_name']) {
                    if (is_array($answer['answer'])) {
                        $tmp_answer = eme_convert_array2multi($answer['answer']);
                    } else {
                        $tmp_answer = $answer['answer'];
                    }
                    $field_replace = $tmp_answer;
                }
            }
            $replacement = eme_trans_sanitize_html($field_replace, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_MULTIBOOKING_SEATS$/', $result)) {
            if ($is_multibooking) {
                // returns the total of all seats for all bookings in the payment id related to this booking
                $replacement = eme_bookings_total_booking_seats($bookings);
            }
        } elseif (preg_match('/#_MULTIBOOKING_TOTALPRICE$/', $result)) {
            if ($is_multibooking) {
                // returns the price for all bookings in the payment id related to this booking
                $price = eme_bookings_total_booking_price($bookings);
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif (preg_match('/#_MULTIBOOKING_DETAILS_TEMPLATE\\{(\\d+)\\}$/', $result, $matches)) {
            $template_id = intval($matches[1]);
            $template = eme_get_template_format($template_id);
            $res = "";
            if ($template && $is_multibooking) {
                // don't let eme_replace_placeholders replace other shortcodes yet, let eme_replace_booking_placeholders finish and that will do it
                foreach ($bookings as $tmp_booking) {
                    $tmp_event = eme_get_event_by_booking_id($tmp_booking['booking_id']);
                    $tmp_res = eme_replace_placeholders($template, $tmp_event, "text", 0);
                    $res .= eme_replace_booking_placeholders($tmp_res, $tmp_event, $tmp_booking, $is_multibooking, "text") . "\n";
                }
            }
            $replacement = $res;
        } elseif (preg_match('/#_IS_MULTIBOOKING/', $result)) {
            $replacement = $is_multibooking;
        } else {
            $found = 0;
        }
        if ($found) {
            if ($need_escape) {
                $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement)));
            }
            $format = str_replace($orig_result, $replacement, $format);
        }
    }
    // now, replace any language tags found in the format itself
    $format = eme_translate($format, $lang);
    return do_shortcode($format);
}
Exemplo n.º 6
0
function eme_replace_formfields_placeholders($event, $booking = "", $format = "", $eme_multibooking = 0)
{
    global $current_user;
    $event_id = $event['event_id'];
    $registration_wp_users_only = $event['registration_wp_users_only'];
    $is_admin = is_admin();
    if ($is_admin && $booking) {
        $editing_booking_from_backend = 1;
    } else {
        $editing_booking_from_backend = 0;
    }
    // if not in the backend and wp membership is required
    // or when editing an existing booking via backend (not a new)
    if ($registration_wp_users_only && !$is_admin || $editing_booking_from_backend) {
        $readonly = "disabled='disabled'";
    } else {
        $readonly = "";
    }
    if (empty($format)) {
        if (!empty($event['event_registration_form_format'])) {
            $format = $event['event_registration_form_format'];
        } elseif ($event['event_properties']['event_registration_form_format_tpl'] > 0) {
            $format = eme_get_template_format($event['event_properties']['event_registration_form_format_tpl']);
        } else {
            $format = get_option('eme_registration_form_format');
        }
    }
    $min_allowed = $event['event_properties']['min_allowed'];
    $max_allowed = $event['event_properties']['max_allowed'];
    if ($event['event_properties']['take_attendance']) {
        $min_allowed = 0;
        $max_allowed = 1;
    }
    if ($editing_booking_from_backend) {
        // in the admin itf, and editing a booking
        // then the avail seats are the total seats
        if (eme_is_multi($event['event_seats'])) {
            $avail_seats = eme_get_multitotal($event['event_seats']);
        } else {
            $avail_seats = $event['event_seats'];
        }
    } else {
        // the next gives the number of available seats, even for multiprice
        $avail_seats = eme_get_available_seats($event_id);
    }
    $booked_places_options = array();
    if (eme_is_multi($max_allowed)) {
        $multi_max_allowed = eme_convert_multi2array($max_allowed);
        $max_allowed_is_multi = 1;
    } else {
        $max_allowed_is_multi = 0;
    }
    if (eme_is_multi($min_allowed)) {
        $multi_min_allowed = eme_convert_multi2array($min_allowed);
        $min_allowed_is_multi = 1;
    } else {
        $min_allowed_is_multi = 0;
    }
    if (eme_is_multi($event['event_seats'])) {
        // in the admin itf, and editing a booking
        // then the avail seats are the total seats
        if ($editing_booking_from_backend) {
            $multi_avail = eme_convert_multi2array($event['event_seats']);
        } else {
            $multi_avail = eme_get_available_multiseats($event_id);
        }
        foreach ($multi_avail as $key => $avail_seats) {
            $booked_places_options[$key] = array();
            if ($max_allowed_is_multi) {
                $real_max_allowed = $multi_max_allowed[$key];
            } else {
                $real_max_allowed = $max_allowed;
            }
            // don't let people choose more seats than available
            if ($real_max_allowed > $avail_seats || $real_max_allowed == 0) {
                $real_max_allowed = $avail_seats;
            }
            if ($min_allowed_is_multi) {
                $real_min_allowed = $multi_min_allowed[$key];
            } else {
                // it's no use to have a non-multi minimum for multiseats
                $real_min_allowed = 0;
            }
            for ($i = $real_min_allowed; $i <= $real_max_allowed; $i++) {
                $booked_places_options[$key][$i] = $i;
            }
        }
    } elseif (eme_is_multi($event['price'])) {
        // we just need to loop through the same amount of seats as there are prices
        foreach (eme_convert_multi2array($event['price']) as $key => $value) {
            $booked_places_options[$key] = array();
            if ($max_allowed_is_multi) {
                $real_max_allowed = $multi_max_allowed[$key];
            } else {
                $real_max_allowed = $max_allowed;
            }
            // don't let people choose more seats than available
            if ($real_max_allowed > $avail_seats || $real_max_allowed == 0) {
                $real_max_allowed = $avail_seats;
            }
            if ($min_allowed_is_multi) {
                $real_min_allowed = $multi_min_allowed[$key];
            } else {
                // it's no use to have a non-multi minimum for multiseats/multiprice
                $real_min_allowed = 0;
            }
            for ($i = $real_min_allowed; $i <= $real_max_allowed; $i++) {
                $booked_places_options[$key][$i] = $i;
            }
        }
    } else {
        if ($max_allowed_is_multi) {
            $real_max_allowed = $multi_max_allowed[0];
        } else {
            $real_max_allowed = $max_allowed;
        }
        // don't let people choose more seats than available
        if ($real_max_allowed > $avail_seats || $real_max_allowed == 0) {
            $real_max_allowed = $avail_seats;
        }
        if ($min_allowed_is_multi) {
            $real_min_allowed = $multi_min_allowed[0];
        } else {
            $real_min_allowed = $min_allowed;
        }
        for ($i = $real_min_allowed; $i <= $real_max_allowed; $i++) {
            $booked_places_options[$i] = $i;
        }
    }
    $required_fields_count = 0;
    $eme_captcha_for_booking = get_option('eme_captcha_for_booking');
    # we need 4 required fields: #_NAME, #_EMAIL, #_SEATS and #_SUBMIT
    # for multiprice: 3 + number of possible prices (we add those later on)
    if (eme_is_multi($event['price'])) {
        $required_fields_min = 3;
    } else {
        $required_fields_min = 4;
    }
    // if we require the captcha: add 1
    if (!$is_admin && $eme_captcha_for_booking) {
        $required_fields_min++;
    }
    // for multi booking forms, the required field count per booking form is 1 (SEATS)
    if (!$is_admin && $eme_multibooking) {
        $required_fields_min = 1;
    }
    $bookerLastName = "";
    $bookerFirstName = "";
    $bookerAddress1 = "";
    $bookerAddress2 = "";
    $bookerCity = "";
    $bookerState = "";
    $bookerZip = "";
    $bookerCountry = "";
    $bookerEmail = "";
    $bookerComment = "";
    $bookerPhone = "";
    $bookedSeats = 0;
    if (is_user_logged_in()) {
        get_currentuserinfo();
        $bookerLastName = $current_user->user_lastname;
        if (empty($bookerLastName)) {
            $bookerLastName = $current_user->display_name;
        }
        $bookerFirstName = $current_user->user_firstname;
        $bookerEmail = $current_user->user_email;
    }
    if ($editing_booking_from_backend) {
        $person = eme_get_person($booking['person_id']);
        // when editing a booking
        $bookerLastName = eme_sanitize_html($person['lastname']);
        $bookerFirstName = eme_sanitize_html($person['firstname']);
        $bookerAddress1 = eme_sanitize_html($person['address1']);
        $bookerAddress2 = eme_sanitize_html($person['address2']);
        $bookerCity = eme_sanitize_html($person['city']);
        $bookerState = eme_sanitize_html($person['state']);
        $bookerZip = eme_sanitize_html($person['zip']);
        $bookerCountry = eme_sanitize_html($person['country']);
        $bookerEmail = eme_sanitize_html($person['email']);
        $bookerPhone = eme_sanitize_html($person['phone']);
        $bookerComment = eme_sanitize_html($booking['booking_comment']);
        $bookedSeats = eme_sanitize_html($booking['booking_seats']);
        if ($booking['booking_seats_mp']) {
            $booking_seats_mp = eme_convert_multi2array($booking['booking_seats_mp']);
            foreach ($booking_seats_mp as $key => $val) {
                $field_index = $key + 1;
                ${"bookedSeats" . $field_index} = eme_sanitize_html($val);
            }
        }
    } else {
        // check for previously filled in data
        // this in case people entered a wrong captcha
        if (isset($_POST['lastname'])) {
            $bookerLastName = eme_sanitize_html(stripslashes_deep($_POST['lastname']));
        }
        if (isset($_POST['firstname'])) {
            $bookerFirstName = eme_sanitize_html(stripslashes_deep($_POST['firstname']));
        }
        if (isset($_POST['address1'])) {
            $bookerAddress1 = eme_sanitize_html(stripslashes_deep($_POST['address1']));
        }
        if (isset($_POST['address2'])) {
            $bookerAddress2 = eme_sanitize_html(stripslashes_deep($_POST['address2']));
        }
        if (isset($_POST['city'])) {
            $bookerCity = eme_sanitize_html(stripslashes_deep($_POST['city']));
        }
        if (isset($_POST['state'])) {
            $bookerState = eme_sanitize_html(stripslashes_deep($_POST['state']));
        }
        if (isset($_POST['zip'])) {
            $bookerZip = eme_sanitize_html(stripslashes_deep($_POST['zip']));
        }
        if (isset($_POST['country'])) {
            $bookerCountry = eme_sanitize_html(stripslashes_deep($_POST['country']));
        }
        if (isset($_POST['email'])) {
            $bookerEmail = eme_sanitize_html(stripslashes_deep($_POST['email']));
        }
        if (isset($_POST['phone'])) {
            $bookerPhone = eme_sanitize_html(stripslashes_deep($_POST['phone']));
        }
        if (isset($_POST['comment'])) {
            $bookerComment = eme_sanitize_html(stripslashes_deep($_POST['comment']));
        }
    }
    // first 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);
    }
    // the 2 placeholders that can contain extra text are treated seperately first
    // the question mark is used for non greedy (minimal) matching
    if (preg_match('/#_CAPTCHAHTML\\{.+\\}/', $format)) {
        // only show the captcha when booking via the frontend, not the admin backend
        if (!$is_admin && $eme_captcha_for_booking) {
            $format = preg_replace('/#_CAPTCHAHTML\\{(.+?)\\}/', '$1', $format);
        } else {
            $format = preg_replace('/#_CAPTCHAHTML\\{(.+?)\\}/', '', $format);
        }
    }
    if (preg_match('/#_SUBMIT\\{.+\\}/', $format)) {
        if ($editing_booking_from_backend) {
            $format = preg_replace('/#_SUBMIT\\{(.+?)\\}/', "<input name='eme_submit_button' class='eme_submit_button' type='submit' value='" . __('Update booking', 'eme') . "' />", $format);
        } else {
            $format = preg_replace('/#_SUBMIT\\{(.+?)\\}/', "<input name='eme_submit_button' class='eme_submit_button' type='submit' value='" . eme_trans_sanitize_html('$1') . "' />", $format);
        }
        if (!$eme_multibooking) {
            $required_fields_count++;
        }
    }
    $deprecated = get_option('eme_deprecated');
    if ($deprecated && preg_match('/#_CAPTCHAHTML\\[.+\\]/', $format)) {
        // only show the captcha when booking via the frontend, not the admin backend
        if (!$is_admin && $eme_captcha_for_booking) {
            $format = preg_replace('/#_CAPTCHAHTML\\[(.+?)\\]/', '$1', $format);
        } else {
            $format = preg_replace('/#_CAPTCHAHTML\\[(.+?)\\]/', '', $format);
        }
    }
    if ($deprecated && preg_match('/#_SUBMIT\\[.+\\]/', $format)) {
        if ($editing_booking_from_backend) {
            $format = preg_replace('/#_SUBMIT\\[(.+?)\\]/', "<input name='eme_submit_button' class='eme_submit_button' type='submit' value='" . __('Update booking', 'eme') . "' />", $format);
        } else {
            $format = preg_replace('/#_SUBMIT\\[(.+?)\\]/', "<input name='eme_submit_button' class='eme_submit_button' type='submit' value='" . eme_trans_sanitize_html('$1') . "' />", $format);
        }
        if (!$eme_multibooking) {
            $required_fields_count++;
        }
    }
    // now the normal placeholders
    preg_match_all("/#(REQ)?_?[A-Z0-9_]+(\\{[A-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');
    # we need 3 required fields: #_NAME, #_EMAIL and #_SEATS
    # if these are not present: we don't replace anything and the form is worthless
    foreach ($placeholders[0] as $result) {
        $orig_result = $result;
        $found = 1;
        $required = 0;
        $required_att = "";
        $html5_wanted = 0;
        $replacement = "";
        if (strstr($result, '#REQ')) {
            $result = str_replace("#REQ", "#", $result);
            $required = 1;
            $required_att = "required='required'";
        }
        // also support RESPNAME, RESPEMAIL, ...
        if (strstr($result, '#_RESP')) {
            $result = str_replace("#_RESP", "#_", $result);
        }
        if ($eme_multibooking) {
            $var_prefix = "bookings[{$event_id}][";
            $var_postfix = "]";
        } else {
            $var_prefix = '';
            $var_postfix = '';
        }
        if (preg_match('/#_NAME|#_LASTNAME/', $result)) {
            if (!$eme_multibooking) {
                $replacement = "<input required='required' type='text' name='{$var_prefix}lastname{$var_postfix}' value='{$bookerLastName}' {$readonly} />";
                $required_fields_count++;
                // #_NAME is always required
                $required = 1;
            }
        } elseif (preg_match('/#_FIRSTNAME/', $result)) {
            if (!empty($bookerFirstName)) {
                $replacement = "<input {$required_att} type='text' name='{$var_prefix}firstname{$var_postfix}' value='{$bookerFirstName}' {$readonly} />";
            } else {
                $replacement = "<input {$required_att} type='text' name='{$var_prefix}firstname{$var_postfix}' value='{$bookerFirstName}' />";
            }
        } elseif (preg_match('/#_ADDRESS1/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}address1{$var_postfix}' value='{$bookerAddress1}' />";
        } elseif (preg_match('/#_ADDRESS2/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}address2{$var_postfix}' value='{$bookerAddress2}' />";
        } elseif (preg_match('/#_CITY/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}city{$var_postfix}' value='{$bookerCity}' />";
        } elseif (preg_match('/#_STATE/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}state{$var_postfix}' value='{$bookerState}' />";
        } elseif (preg_match('/#_ZIP/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}zip{$var_postfix}' value='{$bookerZip}' />";
        } elseif (preg_match('/#_COUNTRY/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}country{$var_postfix}' value='{$bookerCountry}' />";
        } elseif (preg_match('/#_HTML5_EMAIL/', $result)) {
            if (!$eme_multibooking) {
                $replacement = "<input required='required' type='email' name='{$var_prefix}email{$var_postfix}' value='{$bookerEmail}' {$readonly} />";
                $required_fields_count++;
                // #_EMAIL is always required
                $required = 1;
            }
        } elseif (preg_match('/#_EMAIL/', $result)) {
            if (!$eme_multibooking) {
                $replacement = "<input required='required' type='text' name='{$var_prefix}email{$var_postfix}' value='{$bookerEmail}' {$readonly} />";
                $required_fields_count++;
                // #_EMAIL is always required
                $required = 1;
            }
        } elseif (preg_match('/#_HTML5_PHONE/', $result)) {
            $replacement = "<input {$required_att} type='tel' name='{$var_prefix}phone{$var_postfix}' value='{$bookerPhone}' />";
        } elseif (preg_match('/#_PHONE/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}phone{$var_postfix}' value='{$bookerPhone}' />";
        } elseif (preg_match('/#_SEATS$|#_SPACES$/', $result)) {
            $postfield_name = "{$var_prefix}bookedSeats{$var_postfix}";
            if ($editing_booking_from_backend && isset($bookedSeats)) {
                $entered_val = $bookedSeats;
            } elseif ($eme_multibooking && isset($_POST['bookings'][$event_id]) && isset($_POST['bookings'][$event_id]['bookedSeats'])) {
                $entered_val = intval($_POST['bookings'][$event_id]['bookedSeats']);
            } elseif (isset($_POST['bookedSeats'])) {
                $entered_val = intval($_POST['bookedSeats']);
            } else {
                $entered_val = 0;
            }
            if ($event['event_properties']['take_attendance']) {
                $replacement = eme_ui_select_binary($entered_val, $postfield_name);
            } else {
                $replacement = eme_ui_select($entered_val, $postfield_name, $booked_places_options);
            }
            $required_fields_count++;
        } elseif ($deprecated && preg_match('/#_(SEATS|SPACES)(\\d+)/', $result, $matches) || preg_match('/#_(SEATS|SPACES)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]);
            $postfield_name = "{$var_prefix}bookedSeats" . $field_id . $var_postfix;
            if ($editing_booking_from_backend && isset(${"bookedSeats" . $field_id})) {
                $entered_val = ${"bookedSeats" . $field_id};
            } elseif ($eme_multibooking && isset($_POST['bookings'][$event_id]) && isset($_POST['bookings'][$event_id]['bookedSeats' . $field_id])) {
                $entered_val = intval($_POST['bookings'][$event_id]['bookedSeats' . $field_id]);
            } elseif (isset($_POST['bookedSeats' . $field_id])) {
                $entered_val = intval($_POST['bookedSeats' . $field_id]);
            } else {
                $entered_val = 0;
            }
            if (eme_is_multi($event['event_seats']) || eme_is_multi($event['price'])) {
                if ($event['event_properties']['take_attendance']) {
                    $replacement = eme_ui_select_binary($entered_val, $postfield_name);
                } else {
                    $replacement = eme_ui_select($entered_val, $postfield_name, $booked_places_options[$field_id - 1]);
                }
            } else {
                if ($event['event_properties']['take_attendance']) {
                    $replacement = eme_ui_select_binary($entered_val, $postfield_name);
                } else {
                    $replacement = eme_ui_select($entered_val, $postfield_name, $booked_places_options);
                }
            }
            $required_fields_count++;
        } elseif (preg_match('/#_COMMENT/', $result)) {
            if (!$eme_multibooking) {
                $replacement = "<textarea {$required_att} name='{$var_prefix}comment{$var_postfix}'>{$bookerComment}</textarea>";
            }
        } elseif (preg_match('/#_CAPTCHA/', $result) && $eme_captcha_for_booking) {
            if (!$eme_multibooking) {
                $replacement = "<img src='" . EME_PLUGIN_URL . "captcha.php?sessionvar=eme_add_booking'><br /><input required='required' type='text' name='captcha_check' autocomplete='off' />";
                $required_fields_count++;
            }
        } elseif ($deprecated && preg_match('/#_FIELDNAME(\\d+)/', $result, $matches) || preg_match('/#_FIELDNAME\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $formfield = eme_get_formfield_byid($field_id);
            $replacement = eme_trans_sanitize_html($formfield['field_name']);
        } elseif ($deprecated && preg_match('/#_FIELD(\\d+)/', $result, $matches) || preg_match('/#_FIELD\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $postfield_name = "{$var_prefix}FIELD" . $field_id . $var_postfix;
            $entered_val = "";
            if ($booking) {
                $answers = eme_get_answers($booking['booking_id']);
                $formfield = eme_get_formfield_byid($field_id);
                foreach ($answers as $answer) {
                    if ($answer['field_name'] == $formfield['field_name']) {
                        // the entered value for the function eme_get_formfield_html needs to be an array for multiple values
                        // since we store them with "||", we can use the good old eme_is_multi function and split in an array then
                        $entered_val = $answer['answer'];
                        if (eme_is_multi($entered_val)) {
                            $entered_val = eme_convert_multi2array($entered_val);
                        }
                    }
                }
            } elseif (isset($_POST[$postfield_name])) {
                $entered_val = stripslashes_deep($_POST[$postfield_name]);
            }
            $replacement = eme_get_formfield_html($field_id, $entered_val, $required);
        } elseif (preg_match('/#_SUBMIT/', $result, $matches)) {
            if (!$eme_multibooking) {
                if ($editing_booking_from_backend) {
                    $replacement = "<input name='eme_submit_button' type='submit' value='" . __('Update booking', 'eme') . "' />";
                } else {
                    $replacement = "<input name='eme_submit_button' type='submit' value='" . eme_trans_sanitize_html(get_option('eme_rsvp_addbooking_submit_string')) . "' />";
                }
                $required_fields_count++;
            }
        } else {
            $found = 0;
        }
        if ($required) {
            $replacement .= "<div class='eme-required-field'>&nbsp;" . __('(Required field)', 'eme') . "</div>";
        }
        if ($found) {
            $format = str_replace($orig_result, $replacement, $format);
        }
    }
    // now any leftover event placeholders
    $format = eme_replace_placeholders($format, $event);
    // now, replace any language tags found in the format itself
    $format = eme_translate($format);
    # we need 4 required fields: #_NAME, #_EMAIL, #_SEATS and #_SUBMIT
    # for multiprice: 3 + number of possible prices
    # if these are not present: we don't replace anything and the form is worthless
    if (eme_is_multi($event['price'])) {
        $matches = preg_split('/\\|\\|/', $event['price']);
        $count = count($matches);
        // the count can be >3+$count if conditional tags are used to combine a form for single and multiple prices
        if ($required_fields_count >= $required_fields_min + $count) {
            return $format;
        } else {
            $res = __('Not all required fields are present in the booking form.', 'eme');
            $res .= '<br />' . __("Since this is a multiprice event, make sure you changed the setting 'Registration Form Format' for the event to include #_SEATxx placeholders for each price.", 'eme');
            $res .= '<br />' . __("See the documentation about multiprice events.", 'eme');
            return "<div id='message' class='eme-rsvp-message'>{$res}</div>";
        }
    } elseif ($required_fields_count >= $required_fields_min) {
        // the count can be > 4 if conditional tags are used to combine a form for single and multiple prices
        return $format;
    } else {
        return __('Not all required fields are present in the booking form.', 'eme');
    }
}
Exemplo n.º 7
0
function eme_get_events_list_shortcode($atts)
{
    $eme_event_list_number_events = get_option('eme_event_list_number_items');
    extract(shortcode_atts(array('limit' => $eme_event_list_number_events, 'scope' => 'future', 'order' => 'ASC', 'format' => '', 'category' => '', 'showperiod' => '', 'author' => '', 'contact_person' => '', 'paging' => 0, 'long_events' => 0, 'location_id' => 0, 'user_registered_only' => 0, 'show_ongoing' => 1, 'link_showperiod' => 0, 'notcategory' => '', 'show_recurrent_events_once' => 0, 'template_id' => 0, 'template_id_header' => 0, 'template_id_footer' => 0, 'no_events_message' => ''), $atts));
    // the filter list overrides the settings
    if (isset($_REQUEST['eme_eventAction']) && $_REQUEST['eme_eventAction'] == 'filter') {
        if (isset($_REQUEST['eme_scope_filter']) && !empty($_REQUEST['eme_scope_filter'])) {
            $scope = eme_sanitize_request($_REQUEST['eme_scope_filter']);
        }
        if (isset($_REQUEST['eme_loc_filter']) && !empty($_REQUEST['eme_loc_filter'])) {
            if (is_array($_REQUEST['eme_loc_filter'])) {
                $location_id = join(',', eme_sanitize_request($_REQUEST['eme_loc_filter']));
            } else {
                $location_id = eme_sanitize_request($_REQUEST['eme_loc_filter']);
            }
        }
        if (isset($_REQUEST['eme_town_filter']) && !empty($_REQUEST['eme_town_filter'])) {
            $towns = eme_sanitize_request($_REQUEST['eme_town_filter']);
            if (empty($location_id)) {
                $location_id = join(',', eme_get_town_location_ids($towns));
            } else {
                $location_id .= "," . join(',', eme_get_town_location_ids($towns));
            }
        }
        if (isset($_REQUEST['eme_cat_filter']) && !empty($_REQUEST['eme_cat_filter'])) {
            if (is_array($_REQUEST['eme_cat_filter'])) {
                $category = join(',', eme_sanitize_request($_REQUEST['eme_cat_filter']));
            } else {
                $category = eme_sanitize_request($_REQUEST['eme_cat_filter']);
            }
        }
    }
    // if format is given as argument, sometimes people need url-encoded strings inside so wordpress doesn't get confused, so we decode them here again
    $format = urldecode($format);
    // for format: sometimes people want to give placeholders as options, but when using the shortcode inside
    // another (e.g. when putting[eme_events format="#_EVENTNAME"] inside the "display single event" setting,
    // the replacement of the placeholders happens too soon (placeholders get replaced first, before any other
    // shortcode is interpreted). So we add the option that people can use "#OTHER_", and we replace this with
    // "#_" here
    $format = preg_replace('/#OTHER/', "#", $format);
    $result = eme_get_events_list($limit, $scope, $order, $format, '', '', 0, $category, $showperiod, $long_events, $author, $contact_person, $paging, $location_id, $user_registered_only, $show_ongoing, $link_showperiod, $notcategory, $show_recurrent_events_once, $template_id, $template_id_header, $template_id_footer, $no_events_message);
    return $result;
}
Exemplo n.º 8
0
function eme_filter_calendar_ajax()
{
    isset($_POST['full']) && $_POST['full'] ? $full = 1 : ($full = 0);
    isset($_POST['long_events']) && $_POST['long_events'] ? $long_events = 1 : ($long_events = 0);
    isset($_POST['category']) ? $category = $_POST['category'] : ($category = 0);
    isset($_POST['notcategory']) ? $notcategory = $_POST['notcategory'] : ($notcategory = 0);
    isset($_POST['calmonth']) ? $month = eme_sanitize_request($_POST['calmonth']) : ($month = '');
    isset($_POST['calyear']) ? $year = eme_sanitize_request($_POST['calyear']) : ($year = '');
    isset($_POST['author']) ? $author = eme_sanitize_request($_POST['author']) : ($author = '');
    isset($_POST['contact_person']) ? $contact_person = eme_sanitize_request($_POST['contact_person']) : ($contact_person = '');
    isset($_POST['location_id']) ? $location_id = eme_sanitize_request($_POST['location_id']) : ($location_id = '');
    isset($_POST['template_id']) ? $template_id = eme_sanitize_request($_POST['template_id']) : ($template_id = '');
    $echo = 1;
    eme_get_calendar("full={$full}&month={$month}&year={$year}&echo={$echo}&long_events={$long_events}&category={$category}&author={$author}&contact_person={$contact_person}&location_id={$location_id}&notcategory={$notcategory}&template_id={$template_id}");
}