public static function override_bookings($EM_Bookings, $EM_Event) { if (!EM_ML::is_original($EM_Event)) { $event = EM_ML::get_original_event($EM_Event); if (!empty($EM_Bookings->translated)) { //we've already done this before, so we just need to make sure the event id isn't being reset to the translated event id $EM_Bookings->event_id = $event->event_id; } else { //bookings hasn't been 'translated' yet, so we get the original event, get the EM_Bookings object and replace the current event with it. $EM_Bookings = new EM_Bookings($event); $EM_Bookings->event_id = $event->event_id; $EM_Bookings->translated = true; //go through tickets and translate to appropriate language $event_lang = EM_ML::get_the_language($EM_Event); foreach ($EM_Bookings->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if (!empty($EM_Ticket->ticket_meta['langs'][$event_lang]['ticket_name'])) { $EM_Ticket->ticket_name = $EM_Ticket->ticket_meta['langs'][$event_lang]['ticket_name']; } if (!empty($EM_Ticket->ticket_meta['langs'][$event_lang]['ticket_description'])) { $EM_Ticket->ticket_description = $EM_Ticket->ticket_meta['langs'][$event_lang]['ticket_description']; } } } } return $EM_Bookings; }
/** * Will output a event in the format passed in $format by replacing placeholders within the format. * @param string $format * @param string $target * @return string */ function output($format, $target = "html") { $event_string = $format; //Time place holder that doesn't show if empty. //TODO add filter here too preg_match_all('/#@?_\\{[^}]+\\}/', $format, $results); foreach ($results[0] as $result) { if (substr($result, 0, 3) == "#@_") { $date = 'end_date'; $offset = 4; } else { $date = 'start_date'; $offset = 3; } if ($date == 'end_date' && $this->event_end_date == $this->event_start_date) { $replace = __(apply_filters('em_event_output_placeholder', '', $this, $result, $target)); } else { $replace = __(apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, strlen($result) - ($offset + 1)), $this->{$date}), $this, $result, $target)); } $event_string = str_replace($result, $replace, $event_string); } //This is for the custom attributes preg_match_all('/#_ATT\\{([^}]+)\\}(\\{([^}]+)\\})?/', $event_string, $results); $attributes = em_get_attributes(); foreach ($results[0] as $resultKey => $result) { //Strip string of placeholder and just leave the reference $attRef = substr(substr($result, 0, strpos($result, '}')), 6); $attString = ''; if (is_array($this->event_attributes) && array_key_exists($attRef, $this->event_attributes)) { $attString = $this->event_attributes[$attRef]; } elseif (!empty($results[3][$resultKey])) { //Check to see if we have a second set of braces; $attString = $results[3][$resultKey]; } elseif (!empty($attributes['values'][$attRef][0])) { $attString = $attributes['values'][$attRef][0]; } $attString = apply_filters('em_event_output_placeholder', $attString, $this, $result, $target); $event_string = str_replace($result, $attString, $event_string); } //First let's do some conditional placeholder removals for ($i = 0; $i < EM_CONDITIONAL_RECURSIONS; $i++) { //you can add nested recursions by modifying this setting in your wp_options table preg_match_all('/\\{([a-zA-Z0-9_\\-]+)\\}(.+?)\\{\\/\\1\\}/s', $event_string, $conditionals); if (count($conditionals[0]) > 0) { //Check if the language we want exists, if not we take the first language there foreach ($conditionals[1] as $key => $condition) { $show_condition = false; if ($condition == 'has_bookings') { //check if there's a booking, if not, remove this section of code. $show_condition = $this->event_rsvp && get_option('dbem_rsvp_enabled'); } elseif ($condition == 'no_bookings') { //check if there's a booking, if not, remove this section of code. $show_condition = !$this->event_rsvp && get_option('dbem_rsvp_enabled'); } elseif ($condition == 'no_location') { //does this event have a valid location? $show_condition = empty($this->location_id) || !$this->get_location()->location_status; } elseif ($condition == 'has_location') { //does this event have a valid location? $show_condition = !empty($this->location_id) && $this->get_location()->location_status; } elseif ($condition == 'has_image') { //does this event have an image? $show_condition = $this->get_image_url() != ''; } elseif ($condition == 'no_image') { //does this event have an image? $show_condition = $this->get_image_url() == ''; } elseif ($condition == 'has_time') { //are the booking times different and not an all-day event $show_condition = $this->event_start_time != $this->event_end_time && !$this->event_all_day; } elseif ($condition == 'no_time') { //are the booking times exactly the same and it's not an all-day event. $show_condition = $this->event_start_time == $this->event_end_time && !$this->event_all_day; } elseif ($condition == 'all_day') { //is it an all day event $show_condition = !empty($this->event_all_day); } elseif ($condition == 'logged_in') { //user is logged in $show_condition = is_user_logged_in(); } elseif ($condition == 'not_logged_in') { //not logged in $show_condition = !is_user_logged_in(); } elseif ($condition == 'has_spaces') { //there are still empty spaces $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() > 0; } elseif ($condition == 'fully_booked') { //event is fully booked $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() <= 0; } elseif ($condition == 'bookings_open') { //bookings are still open $show_condition = $this->event_rsvp && $this->get_bookings()->is_open(); } elseif ($condition == 'bookings_closed') { //bookings are still closed $show_condition = $this->event_rsvp && !$this->get_bookings()->is_open(); } elseif ($condition == 'is_free' || $condition == 'is_free_now') { //is it a free day event, if _now then free right now $show_condition = !$this->event_rsvp || $this->is_free($condition == 'is_free_now'); } elseif ($condition == 'not_free' || $condition == 'not_free_now') { //is it a paid event, if _now then paid right now $show_condition = $this->event_rsvp && !$this->is_free($condition == 'not_free_now'); } elseif ($condition == 'is_long') { //is it an all day event $show_condition = $this->event_start_date != $this->event_end_date; } elseif ($condition == 'not_long') { //is it an all day event $show_condition = $this->event_start_date == $this->event_end_date; } elseif ($condition == 'is_past') { //if event is past if (get_option('dbem_events_current_are_past')) { $show_condition = $this->start <= current_time('timestamp'); } else { $show_condition = $this->end <= current_time('timestamp'); } } elseif ($condition == 'is_future') { //if event is upcoming $show_condition = $this->start > current_time('timestamp'); } elseif ($condition == 'is_current') { //if event is upcoming $ts = current_time('timestamp'); $show_condition = $this->start <= $ts && $this->end >= $ts; } elseif ($condition == 'is_recurrence') { //if event is a recurrence $show_condition = $this->is_recurrence(); } elseif ($condition == 'not_recurrence') { //if event is not a recurrence $show_condition = !$this->is_recurrence(); } elseif ($condition == 'is_private') { //if event is a recurrence $show_condition = $this->event_private == 1; } elseif ($condition == 'not_private') { //if event is not a recurrence $show_condition = $this->event_private == 0; } elseif (preg_match('/^has_category_([a-zA-Z0-9_\\-]+)$/', $condition, $category_match)) { //event is in this category $show_condition = has_term($category_match[1], EM_TAXONOMY_CATEGORY, $this->post_id); } elseif (preg_match('/^no_category_([a-zA-Z0-9_\\-]+)$/', $condition, $category_match)) { //event is NOT in this category $show_condition = !has_term($category_match[1], EM_TAXONOMY_CATEGORY, $this->post_id); } elseif (preg_match('/^has_tag_([a-zA-Z0-9_\\-]+)$/', $condition, $tag_match)) { //event has this tag $show_condition = has_term($tag_match[1], EM_TAXONOMY_TAG, $this->post_id); } elseif (preg_match('/^no_tag_([a-zA-Z0-9_\\-]+)$/', $condition, $tag_match)) { //event doesn't have this tag $show_condition = !has_term($tag_match[1], EM_TAXONOMY_TAG, $this->post_id); } //other potential ones - has_attribute_... no_attribute_... has_categories_... $show_condition = apply_filters('em_event_output_show_condition', $show_condition, $condition, $conditionals[0][$key], $this); if ($show_condition) { //calculate lengths to delete placeholders $placeholder_length = strlen($condition) + 2; $replacement = substr($conditionals[0][$key], $placeholder_length, strlen($conditionals[0][$key]) - ($placeholder_length * 2 + 1)); } else { $replacement = ''; } $event_string = str_replace($conditionals[0][$key], apply_filters('em_event_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $event_string); } } } //Now let's check out the placeholders. preg_match_all("/(#@?_?[A-Za-z0-9]+)({([^}]+)})?/", $event_string, $placeholders); $replaces = array(); foreach ($placeholders[1] as $key => $result) { $match = true; $replace = ''; $full_result = $placeholders[0][$key]; switch ($result) { //Event Details case '#_EVENTID': $replace = $this->event_id; break; case '#_EVENTPOSTID': $replace = $this->post_id; break; case '#_NAME': //depreciated //depreciated case '#_EVENTNAME': $replace = $this->event_name; break; case '#_NOTES': //depreciated //depreciated case '#_EXCERPT': //depreciated //depreciated case '#_EVENTNOTES': case '#_EVENTEXCERPT': $replace = $this->post_content; if ($result == "#_EXCERPT" || $result == "#_EVENTEXCERPT") { if (!empty($this->post_excerpt)) { $replace = $this->post_excerpt; } else { $excerpt_length = 55; $excerpt_more = apply_filters('em_excerpt_more', ' ' . '[...]'); if (!empty($placeholders[3][$key])) { $trim = true; $ph_args = explode(',', $placeholders[3][$key]); if (is_numeric($ph_args[0])) { $excerpt_length = $ph_args[0]; } if (!empty($ph_args[1])) { $excerpt_more = $ph_args[1]; } } if (preg_match('/<!--more(.*?)?-->/', $replace, $matches)) { $content = explode($matches[0], $replace, 2); $replace = force_balance_tags($content[0]); } if (!empty($trim)) { //shorten content by supplied number - copied from wp_trim_excerpt $replace = strip_shortcodes($replace); $replace = str_replace(']]>', ']]>', $replace); $replace = wp_trim_words($replace, $excerpt_length, $excerpt_more); } } } break; case '#_EVENTIMAGEURL': case '#_EVENTIMAGE': if ($this->get_image_url() != '') { if ($result == '#_EVENTIMAGEURL') { $replace = esc_url($this->image_url); } else { if (empty($placeholders[3][$key])) { $replace = "<img src='" . esc_url($this->image_url) . "' alt='" . esc_attr($this->event_name) . "'/>"; } else { $image_size = explode(',', $placeholders[3][$key]); $image_url = $this->image_url; if (self::array_is_numeric($image_size) && count($image_size) > 1) { //get a thumbnail if (get_option('dbem_disable_thumbnails')) { $image_attr = ''; $image_args = array(); if (empty($image_size[1]) && !empty($image_size[0])) { $image_attr = 'width="' . $image_size[0] . '"'; $image_args['w'] = $image_size[0]; } elseif (empty($image_size[0]) && !empty($image_size[1])) { $image_attr = 'height="' . $image_size[1] . '"'; $image_args['h'] = $image_size[1]; } elseif (!empty($image_size[0]) && !empty($image_size[1])) { $image_attr = 'width="' . $image_size[0] . '" height="' . $image_size[1] . '"'; $image_args = array('w' => $image_size[0], 'h' => $image_size[1]); } $replace = "<img src='" . esc_url(em_add_get_params($image_url, $image_args)) . "' alt='" . esc_attr($this->event_name) . "' {$image_attr} />"; } else { if (EM_MS_GLOBAL && get_current_blog_id() != $this->blog_id) { switch_to_blog($this->blog_id); $switch_back = true; } $replace = get_the_post_thumbnail($this->ID, $image_size); if (!empty($switch_back)) { restore_current_blog(); } } } else { $replace = "<img src='" . esc_url($image_url) . "' alt='" . esc_attr($this->event_name) . "'/>"; } } } } break; //Times & Dates //Times & Dates case '#_24HSTARTTIME': case '#_24HENDTIME': $time = $result == '#_24HSTARTTIME' ? $this->event_start_time : $this->event_end_time; $replace = substr($time, 0, 5); break; case '#_12HSTARTTIME': case '#_12HENDTIME': $time = $result == '#_12HSTARTTIME' ? $this->event_start_time : $this->event_end_time; $replace = date('g:i A', strtotime($time)); break; case '#_EVENTTIMES': //get format of time to show if (!$this->event_all_day) { $time_format = get_option('dbem_time_format') ? get_option('dbem_time_format') : get_option('time_format'); if ($this->event_start_time != $this->event_end_time) { $replace = date_i18n($time_format, $this->start) . get_option('dbem_times_separator') . date_i18n($time_format, $this->end); } else { $replace = date_i18n($time_format, $this->start); } } else { $replace = get_option('dbem_event_all_day_message'); } break; case '#_EVENTDATES': //get format of time to show $date_format = get_option('dbem_date_format') ? get_option('dbem_date_format') : get_option('date_format'); if ($this->event_start_date != $this->event_end_date) { $replace = date_i18n($date_format, $this->start) . get_option('dbem_dates_separator') . date_i18n($date_format, $this->end); } else { $replace = date_i18n($date_format, $this->start); } break; //Links //Links case '#_EVENTPAGEURL': //Depreciated //Depreciated case '#_LINKEDNAME': //Depreciated //Depreciated case '#_EVENTURL': //Just the URL //Just the URL case '#_EVENTLINK': //HTML Link $event_link = esc_url($this->get_permalink()); if ($result == '#_LINKEDNAME' || $result == '#_EVENTLINK') { $replace = '<a href="' . $event_link . '" title="' . esc_attr($this->event_name) . '">' . esc_attr($this->event_name) . '</a>'; } else { $replace = $event_link; } break; case '#_EDITEVENTURL': case '#_EDITEVENTLINK': if ($this->can_manage('edit_events', 'edit_others_events')) { $link = esc_url($this->get_edit_url()); if ($result == '#_EDITEVENTLINK') { $replace = '<a href="' . $link . '">' . esc_html(sprintf(__('Edit Event', 'dbem'))) . '</a>'; } else { $replace = $link; } } break; //Bookings //Bookings case '#_ADDBOOKINGFORM': //Depreciated //Depreciated case '#_REMOVEBOOKINGFORM': //Depreciated //Depreciated case '#_BOOKINGFORM': if (get_option('dbem_rsvp_enabled')) { if (!defined('EM_XSS_BOOKINGFORM_FILTER') && locate_template('plugins/events-manager/placeholders/bookingform.php')) { //xss fix for old overriden booking forms add_filter('em_booking_form_action_url', 'esc_url'); define('EM_XSS_BOOKINGFORM_FILTER', true); } ob_start(); $template = em_locate_template('placeholders/bookingform.php', true, array('EM_Event' => $this)); EM_Bookings::enqueue_js(); $replace = ob_get_clean(); } break; case '#_BOOKINGBUTTON': if (get_option('dbem_rsvp_enabled') && $this->event_rsvp) { ob_start(); $template = em_locate_template('placeholders/bookingbutton.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); } break; case '#_EVENTPRICERANGEALL': $show_all_ticket_prices = true; //continues below //continues below case '#_EVENTPRICERANGE': //get the range of prices $min = false; $max = 0; if ($this->get_bookings()->is_open() || !empty($show_all_ticket_prices)) { foreach ($this->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable') || !empty($show_all_ticket_prices)) { if ($EM_Ticket->get_price() > $max) { $max = $EM_Ticket->get_price(); } if ($EM_Ticket->get_price() < $min || $min === false) { $min = $EM_Ticket->get_price(); } } } } if ($min === false) { $min = 0; } if ($min != $max) { $replace = em_get_currency_formatted($min) . ' - ' . em_get_currency_formatted($max); } else { $replace = em_get_currency_formatted($min); } break; case '#_EVENTPRICEMIN': //get the range of prices $min = false; foreach ($this->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable')) { if ($EM_Ticket->get_price() < $min || $min === false) { $min = $EM_Ticket->get_price(); } } } if ($min === false) { $min = 0; } $replace = em_get_currency_formatted($min); break; case '#_EVENTPRICEMAX': //get the range of prices $max = 0; foreach ($this->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable')) { if ($EM_Ticket->get_price() > $max) { $max = $EM_Ticket->get_price(); } } } $replace = em_get_currency_formatted($max); break; case '#_AVAILABLESEATS': //Depreciated //Depreciated case '#_AVAILABLESPACES': if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_available_spaces(); } else { $replace = "0"; } break; case '#_BOOKEDSEATS': //Depreciated //Depreciated case '#_BOOKEDSPACES': //This placeholder is actually a little misleading, as it'll consider reserved (i.e. pending) bookings as 'booked' if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_booked_spaces(); if (get_option('dbem_bookings_approval_reserved')) { $replace += $this->get_bookings()->get_pending_spaces(); } } else { $replace = "0"; } break; case '#_PENDINGSPACES': if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_pending_spaces(); } else { $replace = "0"; } break; case '#_SEATS': //Depreciated //Depreciated case '#_SPACES': $replace = $this->get_spaces(); break; case '#_BOOKINGSURL': case '#_BOOKINGSLINK': if ($this->can_manage('manage_bookings', 'manage_others_bookings')) { $bookings_link = esc_url($this->get_bookings_url()); if ($result == '#_BOOKINGSLINK') { $replace = '<a href="' . $bookings_link . '" title="' . esc_attr($this->event_name) . '">' . esc_html($this->event_name) . '</a>'; } else { $replace = $bookings_link; } } break; case '#_BOOKINGSCUTOFF': case '#_BOOKINGSCUTOFFDATE': case '#_BOOKINGSCUTOFFTIME': $replace = ''; if ($this->event_rsvp && get_option('dbem_rsvp_enabled') && !empty($this->rsvp_end)) { $replace_format = get_option('dbem_date_format') . ' ' . get_option('dbem_time_format'); if ($result == '#_BOOKINGSCUTOFFDATE') { $replace_format = get_option('dbem_date_format'); } if ($result == '#_BOOKINGSCUTOFFTIME') { $replace_format = get_option('dbem_time_format'); } $replace = date($replace_format, $this->rsvp_end); } break; //Contact Person //Contact Person case '#_CONTACTNAME': case '#_CONTACTPERSON': //Depreciated (your call, I think name is better) $replace = $this->get_contact()->display_name; break; case '#_CONTACTUSERNAME': $replace = $this->get_contact()->user_login; break; case '#_CONTACTEMAIL': case '#_CONTACTMAIL': //Depreciated $replace = $this->get_contact()->user_email; break; case '#_CONTACTURL': $replace = $this->get_contact()->user_url; break; case '#_CONTACTID': $replace = $this->get_contact()->ID; break; case '#_CONTACTPHONE': $replace = $this->get_contact()->phone != '' ? $this->get_contact()->phone : __('N/A', 'dbem'); break; case '#_CONTACTAVATAR': $replace = get_avatar($this->get_contact()->ID, $size = '50'); break; case '#_CONTACTPROFILELINK': case '#_CONTACTPROFILEURL': if (function_exists('bp_core_get_user_domain')) { $replace = bp_core_get_user_domain($this->get_contact()->ID); if ($result == '#_CONTACTPROFILELINK') { $replace = '<a href="' . esc_url($replace) . '">' . __('Profile', 'dbem') . '</a>'; } } break; case '#_CONTACTMETA': if (!empty($placeholders[3][$key])) { $replace = get_user_meta($this->event_owner, $placeholders[3][$key], true); } break; case '#_ATTENDEES': ob_start(); $template = em_locate_template('placeholders/attendees.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_ATTENDEESLIST': ob_start(); $template = em_locate_template('placeholders/attendeeslist.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_ATTENDEESPENDINGLIST': ob_start(); $template = em_locate_template('placeholders/attendeespendinglist.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; //Categories and Tags //Categories and Tags case '#_EVENTCATEGORIESIMAGES': ob_start(); $template = em_locate_template('placeholders/eventcategoriesimages.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_EVENTTAGS': ob_start(); $template = em_locate_template('placeholders/eventtags.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_CATEGORIES': //depreciated //depreciated case '#_EVENTCATEGORIES': ob_start(); $template = em_locate_template('placeholders/categories.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; //Ical Stuff //Ical Stuff case '#_EVENTICALURL': case '#_EVENTICALLINK': $replace = $this->get_ical_url(); if ($result == '#_EVENTICALLINK') { $replace = '<a href="' . esc_url($replace) . '">iCal</a>'; } break; case '#_EVENTGCALURL': case '#_EVENTGCALLINK': //get dates in UTC/GMT time if ($this->event_all_day && $this->event_start_date == $this->event_end_date) { $dateStart = get_gmt_from_date(date('Y-m-d H:i:s', $this->start), 'Ymd'); $dateEnd = get_gmt_from_date(date('Y-m-d H:i:s', $this->start + 60 * 60 * 24), 'Ymd'); } else { $dateStart = get_gmt_from_date(date('Y-m-d H:i:s', $this->start), 'Ymd\\THis\\Z'); $dateEnd = get_gmt_from_date(date('Y-m-d H:i:s', $this->end), 'Ymd\\THis\\Z'); } //build url $gcal_url = 'http://www.google.com/calendar/event?action=TEMPLATE&text=event_name&dates=start_date/end_date&details=post_content&location=location_name&trp=false&sprop=event_url&sprop=name:blog_name'; $gcal_url = str_replace('event_name', urlencode($this->event_name), $gcal_url); $gcal_url = str_replace('start_date', urlencode($dateStart), $gcal_url); $gcal_url = str_replace('end_date', urlencode($dateEnd), $gcal_url); $gcal_url = str_replace('location_name', urlencode($this->output('#_LOCATION')), $gcal_url); $gcal_url = str_replace('blog_name', urlencode(get_bloginfo()), $gcal_url); $gcal_url = str_replace('event_url', urlencode($this->get_permalink()), $gcal_url); //calculate URL length so we know how much we can work with to make a description. if (!empty($this->post_excerpt)) { $gcal_url_description = $this->post_excerpt; } else { $matches = explode('<!--more', $this->post_content); $gcal_url_description = wp_kses_data($matches[0]); } $gcal_url_length = strlen($gcal_url) - 9; if (strlen($gcal_url_description) + $gcal_url_length > 1350) { $gcal_url_description = substr($gcal_url_description, 0, 1380 - $gcal_url_length - 3) . '...'; } $gcal_url = str_replace('post_content', urlencode($gcal_url_description), $gcal_url); //get the final url $replace = $gcal_url; if ($result == '#_EVENTGCALLINK') { $img_url = 'www.google.com/calendar/images/ext/gc_button2.gif'; $img_url = is_ssl() ? 'https://' . $img_url : 'http://' . $img_url; $replace = '<a href="' . esc_url($replace) . '" target="_blank"><img src="' . esc_url($img_url) . '" alt="0" border="0"></a>'; } break; default: $replace = $full_result; break; } $replaces[$full_result] = apply_filters('em_event_output_placeholder', $replace, $this, $full_result, $target); } //sort out replacements so that during replacements shorter placeholders don't overwrite longer varieties. krsort($replaces); foreach ($replaces as $full_result => $replacement) { if (!in_array($full_result, array('#_NOTES', '#_EVENTNOTES'))) { $event_string = str_replace($full_result, $replacement, $event_string); } else { $new_placeholder = str_replace('#_', '__#', $full_result); //this will avoid repeated filters when locations/categories are parsed $event_string = str_replace($full_result, $new_placeholder, $event_string); $desc_replace[$new_placeholder] = $replacement; } } //Time placeholders foreach ($placeholders[1] as $result) { // matches all PHP START date and time placeholders if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#"), $this->start); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } // matches all PHP END time placeholders for endtime if (preg_match('/^#@[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#@"), $this->end); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } } //Now do dependent objects if (!empty($this->location_id) && $this->get_location()->location_status) { $event_string = $this->get_location()->output($event_string, $target); } else { $EM_Location = new EM_Location(); $event_string = $EM_Location->output($event_string, $target); } //for backwards compat and easy use, take over the individual category placeholders with the frirst cat in th elist. $EM_Categories = $this->get_categories(); if (count($EM_Categories->categories) > 0) { $EM_Category = $EM_Categories->get_first(); } if (empty($EM_Category)) { $EM_Category = new EM_Category(); } $event_string = $EM_Category->output($event_string, $target); //Finally, do the event notes, so that previous placeholders don't get replaced within the content, which may use shortcodes if (!empty($desc_replace)) { foreach ($desc_replace as $full_result => $replacement) { $event_string = str_replace($full_result, $replacement, $event_string); } } //do some specific formatting //TODO apply this sort of formatting to any output() function if ($target == 'ical') { //strip html and escape characters $event_string = str_replace('\\', '\\\\', strip_tags($event_string)); $event_string = str_replace(';', '\\;', $event_string); $event_string = str_replace(',', '\\,', $event_string); //remove and define line breaks in ical format $event_string = str_replace('\\\\n', '\\n', $event_string); $event_string = str_replace("\r\n", '\\n', $event_string); $event_string = str_replace("\n", '\\n', $event_string); } return apply_filters('em_event_output', $event_string, $this, $format, $target); }
/** * Decides whether to register a user based on a certain booking that is to be added * @param EM_Booking $EM_Booking */ function em_booking_add_registration($EM_Booking) { global $EM_Notices; //Does this user need to be registered first? $registration = true; if ((!is_user_logged_in() && get_option('dbem_bookings_anonymous') || EM_Bookings::is_registration_forced()) && !get_option('dbem_bookings_registration_disable')) { //find random username - less options for user, less things go wrong $username_root = explode('@', wp_kses_data($_REQUEST['user_email'])); $username_root = $username_rand = sanitize_user($username_root[0], true); while (username_exists($username_rand)) { $username_rand = $username_root . rand(1, 1000); } $_REQUEST['dbem_phone'] = !empty($_REQUEST['dbem_phone']) ? wp_kses_data($_REQUEST['dbem_phone']) : ''; //fix to prevent warnings $_REQUEST['user_name'] = !empty($_REQUEST['user_name']) ? wp_kses_data($_REQUEST['user_name']) : ''; //fix to prevent warnings $user_data = array('user_login' => $username_rand, 'user_email' => $_REQUEST['user_email'], 'user_name' => $_REQUEST['user_name'], 'dbem_phone' => $_REQUEST['dbem_phone']); $id = em_register_new_user($user_data); if (is_numeric($id)) { $EM_Person = new EM_Person($id); $EM_Booking->person_id = $id; $feedback = get_option('dbem_booking_feedback_new_user'); $EM_Notices->add_confirm($feedback); add_action('em_bookings_added', 'em_new_user_notification'); } else { $registration = false; if (is_object($id) && get_class($id) == 'WP_Error') { /* @var $id WP_Error */ if ($id->get_error_code() == 'email_exists') { $EM_Notices->add_error(get_option('dbem_booking_feedback_email_exists')); } else { $EM_Notices->add_error($id->get_error_messages()); } } else { $EM_Notices->add_error(get_option('dbem_booking_feedback_reg_error')); } } } elseif ((!is_user_logged_in() || EM_Bookings::is_registration_forced()) && get_option('dbem_bookings_registration_disable')) { //Validate name, phone and email if ($EM_Booking->get_person_post()) { //Save default person to booking $EM_Booking->person_id = get_option('dbem_bookings_registration_user'); } else { $registration = false; } } elseif (!is_user_logged_in()) { $registration = false; $EM_Notices->add_error(get_option('dbem_booking_feedback_log_in')); } elseif (empty($EM_Booking->person_id)) { //user must be logged in, so we make this person the current user id $EM_Booking->person_id = get_current_user_id(); } return apply_filters('em_booking_add_registration_result', $registration, $EM_Booking, $EM_Notices); }
function em_create_events_submenu() { if (function_exists('add_submenu_page')) { //Count pending bookings $num = ''; if (get_option('dbem_bookings_approval') == 1) { $bookings_pending_count = count(EM_Bookings::get(array('status' => 0))); //TODO Add flexible permissions if ($bookings_pending_count > 0) { $num = '<span class="update-plugins count-' . $bookings_pending_count . '"><span class="plugin-count">' . $bookings_pending_count . '</span></span>'; } } add_object_page(__('Events', 'dbem'), __('Events', 'dbem') . $num, EM_MIN_CAPABILITY, 'events-manager', 'em_admin_events_page', '../wp-content/plugins/events-manager/includes/images/calendar-16.png'); // Add a submenu to the custom top-level menu: $plugin_pages = array(); $plugin_pages[] = add_submenu_page('events-manager', __('Edit'), __('Edit'), EM_MIN_CAPABILITY, 'events-manager', 'em_admin_events_page'); $plugin_pages[] = add_submenu_page('events-manager', __('Add new', 'dbem'), __('Add new', 'dbem'), EM_MIN_CAPABILITY, 'events-manager-event', "em_admin_event_page"); if (get_option('dbem_permissions_locations') != 1 || em_verify_admin()) { $plugin_pages[] = add_submenu_page('events-manager', __('Locations', 'dbem'), __('Locations', 'dbem'), EM_MIN_CAPABILITY, 'events-manager-locations', "em_admin_locations_page"); } if (get_option('dbem_rsvp_enabled') == 1) { $plugin_pages[] = add_submenu_page('events-manager', __('Bookings', 'dbem'), __('Bookings', 'dbem') . $num, EM_MIN_CAPABILITY, 'events-manager-bookings', "em_bookings_page"); } if (get_option('dbem_permissions_categories') != 1 || em_verify_admin()) { $plugin_pages[] = add_submenu_page('events-manager', __('Event Categories', 'dbem'), __('Categories', 'dbem'), EM_MIN_CAPABILITY, "events-manager-categories", 'em_admin_categories_page'); } $plugin_pages[] = add_submenu_page('events-manager', __('Events Manager Settings', 'dbem'), __('Settings', 'dbem'), EM_SETTING_CAPABILITY, "events-manager-options", 'em_admin_options_page'); $plugin_pages[] = add_submenu_page('events-manager', __('Getting Help for Events Manager', 'dbem'), __('Help', 'dbem'), EM_SETTING_CAPABILITY, "events-manager-help", 'em_admin_help_page'); foreach ($plugin_pages as $plugin_page) { add_action('admin_print_scripts-' . $plugin_page, 'em_admin_load_scripts'); add_action('admin_head-' . $plugin_page, 'em_admin_general_script'); add_action('admin_print_styles-' . $plugin_page, 'em_admin_load_styles'); } } }
/** * Gets the bookings for this object instance according to its settings * @param boolean $force_refresh * @return EM_Bookings */ function get_bookings($force_refresh = true) { if (empty($this->bookings) || $force_refresh) { $this->events = array(); $EM_Ticket = $this->get_ticket(); $EM_Event = $this->get_event(); $EM_Person = $this->get_person(); if ($EM_Person !== false) { $args = array('person' => $EM_Person->ID, 'scope' => $this->scope, 'status' => $this->get_status_search(), 'order' => $this->order, 'orderby' => $this->orderby); $this->bookings_count = EM_Bookings::count($args); $this->bookings = EM_Bookings::get(array_merge($args, array('limit' => $this->limit, 'offset' => $this->offset))); foreach ($this->bookings->bookings as $EM_Booking) { //create event if (!array_key_exists($EM_Booking->event_id, $this->events)) { $this->events[$EM_Booking->event_id] = new EM_Event($EM_Booking->event_id); } } } elseif ($EM_Ticket !== false) { //searching bookings with a specific ticket $args = array('ticket_id' => $EM_Ticket->ticket_id, 'order' => $this->order, 'orderby' => $this->orderby); $this->bookings_count = EM_Bookings::count($args); $this->bookings = EM_Bookings::get(array_merge($args, array('limit' => $this->limit, 'offset' => $this->offset))); $this->events[$EM_Ticket->event_id] = $EM_Ticket->get_event(); } elseif ($EM_Event !== false) { //bookings for an event $args = array('event' => $EM_Event->event_id, 'scope' => false, 'status' => $this->get_status_search(), 'order' => $this->order, 'orderby' => $this->orderby); $args['owner'] = !current_user_can('manage_others_bookings') ? get_current_user_id() : false; $this->bookings_count = EM_Bookings::count($args); $this->bookings = EM_Bookings::get(array_merge($args, array('limit' => $this->limit, 'offset' => $this->offset))); $this->events[$EM_Event->event_id] = $EM_Event; } else { //all bookings for a status $args = array('status' => $this->get_status_search(), 'scope' => $this->scope, 'order' => $this->order, 'orderby' => $this->orderby); $args['owner'] = !current_user_can('manage_others_bookings') ? get_current_user_id() : false; $this->bookings_count = EM_Bookings::count($args); $this->bookings = EM_Bookings::get(array_merge($args, array('limit' => $this->limit, 'offset' => $this->offset))); //Now let's create events and bookings for this instead of giving each booking an event foreach ($this->bookings->bookings as $EM_Booking) { //create event if (!array_key_exists($EM_Booking->event_id, $this->events)) { $this->events[$EM_Booking->event_id] = new EM_Event($EM_Booking->event_id); } } } } return $this->bookings; }
function em_admin_menu() { global $menu, $submenu, $pagenow; //Count pending bookings if (get_option('dbem_rsvp_enabled')) { $bookings_num = ''; $bookings_pending_count = apply_filters('em_bookings_pending_count', 0); if (get_option('dbem_bookings_approval') == 1) { $bookings_pending_count += count(EM_Bookings::get(array('status' => '0', 'blog' => get_current_blog_id()))->bookings); } if ($bookings_pending_count > 0) { $bookings_num = '<span class="update-plugins count-' . $bookings_pending_count . '"><span class="plugin-count">' . $bookings_pending_count . '</span></span>'; } } else { $bookings_num = ''; $bookings_pending_count = 0; } //Count pending events $events_num = ''; $events_pending_count = EM_Events::count(array('status' => 0, 'scope' => 'all', 'blog' => get_current_blog_id())); //TODO Add flexible permissions if ($events_pending_count > 0) { $events_num = '<span class="update-plugins count-' . $events_pending_count . '"><span class="plugin-count">' . $events_pending_count . '</span></span>'; } //Count pending recurring events $events_recurring_num = ''; $events_recurring_pending_count = EM_Events::count(array('status' => 0, 'recurring' => 1, 'scope' => 'all', 'blog' => get_current_blog_id())); //TODO Add flexible permissions if ($events_recurring_pending_count > 0) { $events_recurring_num = '<span class="update-plugins count-' . $events_recurring_pending_count . '"><span class="plugin-count">' . $events_recurring_pending_count . '</span></span>'; } $both_pending_count = apply_filters('em_items_pending_count', $events_pending_count + $bookings_pending_count + $events_recurring_pending_count); $both_num = $both_pending_count > 0 ? '<span class="update-plugins count-' . $both_pending_count . '"><span class="plugin-count">' . $both_pending_count . '</span></span>' : ''; // Add a submenu to the custom top-level menu: $plugin_pages = array(); if (get_option('dbem_rsvp_enabled')) { $plugin_pages['bookings'] = add_submenu_page('edit.php?post_type=' . EM_POST_TYPE_EVENT, __('Bookings', 'events-manager'), __('Bookings', 'events-manager') . $bookings_num, 'manage_bookings', 'events-manager-bookings', "em_bookings_page"); } $plugin_pages['options'] = add_submenu_page('edit.php?post_type=' . EM_POST_TYPE_EVENT, __('Events Manager Settings', 'events-manager'), __('Settings', 'events-manager'), 'manage_options', "events-manager-options", 'em_admin_options_page'); $plugin_pages['help'] = add_submenu_page('edit.php?post_type=' . EM_POST_TYPE_EVENT, __('Getting Help for Events Manager', 'events-manager'), __('Help', 'events-manager'), 'manage_options', "events-manager-help", 'em_admin_help_page'); //If multisite global with locations set to be saved in main blogs we can force locations to be created on the main blog only if (EM_MS_GLOBAL && !is_main_site() && get_site_option('dbem_ms_mainblog_locations')) { include dirname(__FILE__) . "/em-ms-locations.php"; $plugin_pages['locations'] = add_submenu_page('edit.php?post_type=' . EM_POST_TYPE_EVENT, __('Locations', 'events-manager'), __('Locations', 'events-manager'), 'read_others_locations', "locations", 'em_admin_ms_locations'); } $plugin_pages = apply_filters('em_create_events_submenu', $plugin_pages); //We have to modify the menus manually if (!empty($both_num)) { //Main Event Menu //go through the menu array and modify the events menu if found foreach ((array) $menu as $key => $parent_menu) { if ($parent_menu[2] == 'edit.php?post_type=' . EM_POST_TYPE_EVENT) { $menu[$key][0] = $menu[$key][0] . $both_num; break; } } } if (!empty($events_num) && !empty($submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT])) { //Submenu Event Item //go through the menu array and modify the events menu if found foreach ((array) $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT] as $key => $submenu_item) { if ($submenu_item[2] == 'edit.php?post_type=' . EM_POST_TYPE_EVENT) { $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT][$key][0] = $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT][$key][0] . $events_num; break; } } } if (!empty($events_recurring_num) && !empty($submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT])) { //Submenu Recurring Event Item //go through the menu array and modify the events menu if found foreach ((array) $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT] as $key => $submenu_item) { if ($submenu_item[2] == 'edit.php?post_type=event-recurring') { $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT][$key][0] = $submenu['edit.php?post_type=' . EM_POST_TYPE_EVENT][$key][0] . $events_recurring_num; break; } } } /* Hack! Add location/recurrence isn't possible atm so this is a workaround */ global $_wp_submenu_nopriv; if ($pagenow == 'post-new.php' && !empty($_REQUEST['post_type'])) { if ($_REQUEST['post_type'] == EM_POST_TYPE_LOCATION && !empty($_wp_submenu_nopriv['edit.php']['post-new.php']) && current_user_can('edit_locations')) { unset($_wp_submenu_nopriv['edit.php']['post-new.php']); } if ($_REQUEST['post_type'] == 'event-recurring' && !empty($_wp_submenu_nopriv['edit.php']['post-new.php']) && current_user_can('edit_recurring_events')) { unset($_wp_submenu_nopriv['edit.php']['post-new.php']); } } }
/** * Generates a "widget" table of pending bookings with some quick admin operation options. * If event id supplied then only pending bookings for that event will show. * * @param int $event_id */ function em_bookings_pending_table($event_id = false) { global $EM_Event, $wpdb, $current_user; if (get_option('dbem_bookings_approval') == 0) { return false; } $action_scope = !empty($_REQUEST['em_obj']) && $_REQUEST['em_obj'] == 'em_bookings_pending_table'; $action = $action_scope && !empty($_GET['action']) ? $_GET['action'] : ''; $order = $action_scope && !empty($_GET['order']) ? $_GET['order'] : 'ASC'; $limit = $action_scope && !empty($_GET['limit']) ? $_GET['limit'] : 20; //Default limit $page = $action_scope && !empty($_GET['pno']) ? $_GET['pno'] : 1; $offset = $action_scope && $page > 1 ? ($page - 1) * $limit : 0; if (is_object($EM_Event)) { $bookings = $EM_Event->get_bookings()->get_pending(); } else { //To optimize performance, we can do one query here for all pending bookings to show. $bookings = EM_Bookings::get(array('status' => 0)); $events = array(); //Now let's create events and bookings for this: foreach ($bookings as $EM_Booking) { //create event if (!array_key_exists($EM_Booking->event_id, $events)) { $events[$EM_Booking->event_id] = new EM_Event($EM_Booking->event_id); } } } $bookings_count = is_array($bookings) ? count($bookings) : 0; ?> <div class='wrap em_bookings_pending_table em_obj'> <form id='bookings-filter' method='get' action='<?php bloginfo('wpurl'); ?> /wp-admin/edit.php'> <input type="hidden" name="em_obj" value="em_bookings_pending_table" /> <!-- <ul class="subsubsub"> <li> <a href='edit.php?post_type=post' class="current">All <span class="count">(1)</span></a> | </li> </ul> <p class="search-box"> <label class="screen-reader-text" for="post-search-input"><?php _e('Search'); ?> :</label> <input type="text" id="post-search-input" name="em_search" value="<?php echo !empty($_GET['em_search']) ? $_GET['em_search'] : ''; ?> " /> <input type="submit" value="<?php _e('Search'); ?> " class="button" /> </p> --> <?php if ($bookings_count >= $limit) { ?> <div class='tablenav'> <!-- <div class="alignleft actions"> <select name="action"> <option value="-1" selected="selected"> <?php _e('Bulk Actions'); ?> </option> <option value="approve"> <?php _e('Approve', 'dbem'); ?> </option> <option value="decline"> <?php _e('Decline', 'dbem'); ?> </option> </select> <input type="submit" id="post-query-submit" value="Filter" class="button-secondary" /> </div> --> <!-- <div class="view-switch"> <a href="/wp-admin/edit.php?mode=list"><img class="current" id="view-switch-list" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="List View" alt="List View" name="view-switch-list" /></a> <a href="/wp-admin/edit.php?mode=excerpt"><img id="view-switch-excerpt" src="http://wordpress.lan/wp-includes/images/blank.gif" width="20" height="20" title="Excerpt View" alt="Excerpt View" name="view-switch-excerpt" /></a> </div> --> <?php if ($bookings_count >= $limit) { $page_link_template = em_add_get_params($_SERVER['REQUEST_URI'], array('pno' => '%PAGE%', 'em_ajax' => 0, 'em_obj' => 'em_bookings_pending_table')); $bookings_nav = em_admin_paginate($page_link_template, $bookings_count, $limit, $page, 5); echo $bookings_nav; } ?> <div class="clear"></div> </div> <?php } ?> <div class="clear"></div> <?php if ($bookings_count > 0) { ?> <div class='table-wrap'> <table id='dbem-bookings-table' class='widefat post fixed'> <thead> <tr> <th class='manage-column column-cb check-column' scope='col'> <input class='select-all' type="checkbox" value='1' /> </th> <th class='manage-column' scope='col'>Booker</th> <?php if (!is_object($EM_Event)) { ?> <th class='manage-column' scope="col">Event</th> <?php } ?> <th class='manage-column' scope='col'>E-mail</th> <th class='manage-column' scope='col'>Phone number</th> <th class='manage-column' scope='col'>Spaces</th> <th class='manage-column' scope='col'> </th> </tr> </thead> <tbody> <?php $rowno = 0; $event_count = 0; foreach ($bookings as $EM_Booking) { if (($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0)) { $rowno++; ?> <tr> <th scope="row" class="check-column" style="padding:7px 0px 7px;"><input type='checkbox' value='<?php echo $EM_Booking->id; ?> ' name='bookings[]'/></th> <td><a href="<?php bloginfo('wpurl'); ?> /wp-admin/admin.php?page=events-manager-bookings&person_id=<?php echo $EM_Booking->person->id; ?> "><?php echo $EM_Booking->person->name; ?> </a></td> <?php if (!is_object($EM_Event)) { ?> <td><a href="<?php bloginfo('wpurl'); ?> /wp-admin/admin.php?page=events-manager-bookings&event_id=<?php echo $EM_Booking->event_id; ?> "><?php echo $events[$EM_Booking->event_id]->name; ?> </a></td> <?php } ?> <td><?php echo $EM_Booking->person->email; ?> </td> <td><?php echo $EM_Booking->person->phone; ?> </td> <td><?php echo $EM_Booking->seats; ?> </td> <td> <?php $approve_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->id)); $reject_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action' => 'bookings_reject', 'booking_id' => $EM_Booking->id)); ?> <a class="em-bookings-approve" href="<?php echo $approve_url; ?> "><?php _e('Approve', 'dbem'); ?> </a> | <a class="em-bookings-reject" href="<?php echo $reject_url; ?> "><?php _e('Reject', 'dbem'); ?> </a> | <a class="em-bookings-edit" href="<?php bloginfo('wpurl'); ?> /wp-admin/admin.php?page=events-manager-bookings&booking_id=<?php echo $EM_Booking->id; ?> "><?php _e('Edit'); ?> </a> </td> </tr> <?php } $event_count++; } ?> </tbody> </table> </div> <?php } else { ?> <?php _e('No pending bookings.', 'dbem'); ?> <?php } ?> </form> <?php if (!empty($bookings_nav)) { ?> <div class='tablenav'> <?php echo $bookings_nav; ?> <div class="clear"></div> </div> <?php } ?> </div> <?php }
function em_create_events_submenu() { if (function_exists('add_submenu_page')) { //Count pending bookings $bookings_num = ''; $bookings_pending_count = 0; if (get_option('dbem_bookings_approval') == 1) { $bookings_pending_count = count(EM_Bookings::get(array('status' => 0))->bookings); //TODO Add flexible permissions if ($bookings_pending_count > 0) { $bookings_num = '<span class="update-plugins count-' . $bookings_pending_count . '"><span class="plugin-count">' . $bookings_pending_count . '</span></span>'; } } //Count pending events $events_num = ''; $events_pending_count = EM_Events::count(array('status' => 0, 'scope' => 'all')); //TODO Add flexible permissions if ($events_pending_count > 0) { $events_num = '<span class="update-plugins count-' . $events_pending_count . '"><span class="plugin-count">' . $events_pending_count . '</span></span>'; } $both_pending_count = $events_pending_count + $bookings_pending_count; $both_num = $both_pending_count > 0 ? '<span class="update-plugins count-' . $both_pending_count . '"><span class="plugin-count">' . $both_pending_count . '</span></span>' : ''; add_object_page(__('Events', 'dbem'), __('Events', 'dbem') . $both_num, 'edit_events', 'events-manager', 'em_admin_events_page', '../wp-content/plugins/events-manager/includes/images/calendar-16.png'); // Add a submenu to the custom top-level menu: $plugin_pages = array(); $plugin_pages[] = add_submenu_page('events-manager', __('Edit'), __('Edit') . $events_num, 'edit_events', 'events-manager', 'em_admin_events_page'); $plugin_pages[] = add_submenu_page('events-manager', __('Add new', 'dbem'), __('Add new', 'dbem'), 'edit_events', 'events-manager-event', "em_admin_event_page"); $plugin_pages[] = add_submenu_page('events-manager', __('Locations', 'dbem'), __('Locations', 'dbem'), 'edit_locations', 'events-manager-locations', "em_admin_locations_page"); $plugin_pages[] = add_submenu_page('events-manager', __('Bookings', 'dbem'), __('Bookings', 'dbem') . $bookings_num, 'manage_bookings', 'events-manager-bookings', "em_bookings_page"); $plugin_pages[] = add_submenu_page('events-manager', __('Event Categories', 'dbem'), __('Categories', 'dbem'), 'edit_categories', "events-manager-categories", 'em_admin_categories_page'); $plugin_pages[] = add_submenu_page('events-manager', __('Events Manager Settings', 'dbem'), __('Settings', 'dbem'), 'activate_plugins', "events-manager-options", 'em_admin_options_page'); $plugin_pages[] = add_submenu_page('events-manager', __('Getting Help for Events Manager', 'dbem'), __('Help', 'dbem'), 'activate_plugins', "events-manager-help", 'em_admin_help_page'); $plugin_pages = apply_filters('em_create_events_submenu', $plugin_pages); foreach ($plugin_pages as $plugin_page) { add_action('admin_print_scripts-' . $plugin_page, 'em_admin_load_scripts'); add_action('admin_head-' . $plugin_page, 'em_admin_general_script'); add_action('admin_print_styles-' . $plugin_page, 'em_admin_load_styles'); } } }
public static function checkout_page() { if (!self::get_multiple_booking()->validate_bookings_spaces()) { global $EM_Notices; $EM_Notices->add_error(self::get_multiple_booking()->get_errors()); } //load contents if not using caching, do not alter this conditional structure as it allows the cart to work with caching plugins echo '<div class="em-checkout-page-contents" style="position:relative;">'; if (!defined('WP_CACHE') || !WP_CACHE) { emp_locate_template('multiple-bookings/page-checkout.php', true); } else { echo '<p>' . get_option('dbem_multiple_bookings_feedback_loading_cart') . '</p>'; } echo '</div>'; EM_Bookings::enqueue_js(); }
/** * bp_em_format_notifications() * * The format notification function will take DB entries for notifications and format them * so that they can be displayed and read on the screen. * * Notifications are "screen" notifications, that is, they appear on the notifications menu * in the site wide navigation bar. They are not for email notifications. * * * The recording is done by using bp_core_add_notification() which you can search for in this file for * ems of usage. */ function bp_em_format_notifications($action, $item_id, $secondary_item_id, $total_items) { global $bp; switch ($action) { case 'pending_booking': //Count pending bookings if (get_option('dbem_bookings_approval')) { $EM_Bookings = EM_Bookings::get(array('status' => 0, 'owner' => get_current_user_id())); if (count($EM_Bookings->bookings) > 1) { return apply_filters('bp_em_format_new_booking_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/?event_id" title="' . __('My Bookings', 'bp-em') . '">' . __('You have a pending booking', 'dbem') . '</a>', $EM_Bookings); } else { return apply_filters('bp_em_format_new_booking_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __('My Bookings', 'bp-em') . '">' . sprintf(__('You have %s pending bookings', 'dbem'), $bookings_pending_count) . '</a>', $EM_Bookings); } } break; case 'confirmed_booking': //Count pending bookings $EM_Bookings = EM_Bookings::get(array('status' => 0, 'owner' => get_current_user_id())); if (count($EM_Bookings->bookings) > 1) { return apply_filters('bp_em_format_new_booking_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/?event_id="' . $EM_Bookings->first()->event_id . '" title="' . __('My Bookings', 'bp-em') . '">' . __('You have a new booking', 'dbem') . '</a>', $EM_Bookings); } else { return apply_filters('bp_em_format_new_booking_notification', '<a href="' . $bp->loggedin_user->domain . $bp->events->slug . '/my-bookings/" title="' . __('My Bookings', 'bp-em') . '">' . sprintf(__('You have %s new bookings', 'dbem'), $bookings_pending_count) . '</a>', $EM_Bookings); } break; } die($action); do_action('bp_em_format_notifications', $action, $item_id, $secondary_item_id, $total_items); return false; }
function em_ajax_actions() { //TODO Clean this up.... use a uniformed way of calling EM Ajax actions if (!empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action'])) { if (isset($_REQUEST['dbem_ajax_action']) && $_REQUEST['dbem_ajax_action'] == 'booking_data') { if (isset($_REQUEST['id'])) { $EM_Event = new EM_Event($_REQUEST['id']); echo "[{bookedSeats:" . $EM_Event->get_bookings()->get_booked_seats() . ", availableSeats:" . $EM_Event->get_bookings()->get_available_seats() . "}]"; } die; } if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') { if (isset($_REQUEST['id'])) { $EM_Location = new EM_Location($_REQUEST['id']); $location_array = $EM_Location->to_array(); $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format')); echo EM_Object::json_encode($location_array); } die; } if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') { $locations = EM_Locations::get($_REQUEST); $json_locations = array(); foreach ($locations as $location_key => $location) { $json_locations[$location_key] = $location->to_array(); $json_locations[$location_key]['location_balloon'] = $location->output(get_option('dbem_map_text_format')); } echo EM_Object::json_encode($json_locations); die; } if (isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) { //FIXME if long events enabled originally, this won't show up on ajax call echo EM_Calendar::output($_REQUEST); die; } //EM Ajax requests require this flag. if (is_admin()) { //Admin operations //Booking Actions global $EM_Booking; if (!empty($_REQUEST['bookings']) || is_object($EM_Booking)) { if (is_object($EM_Booking)) { $_REQUEST['bookings'] = $EM_Booking; //small hack to prevent unecessary db reads } $EM_Bookings = new EM_Bookings(); //Empty, not bound to event. if ($_REQUEST['action'] == 'bookings_approve') { $EM_Bookings->approve($_REQUEST['bookings']); echo $EM_Bookings->feedback_message; die; } elseif ($_REQUEST['action'] == 'bookings_reject') { $EM_Bookings->reject($_REQUEST['bookings']); echo $EM_Bookings->feedback_message; die; } elseif ($_REQUEST['action'] == 'bookings_unapprove') { $EM_Bookings->unapprove($_REQUEST['bookings']); echo $EM_Bookings->feedback_message; die; } elseif ($_REQUEST['action'] == 'bookings_delete') { //Just do it here, since we may be deleting bookings of different events. $result = false; if (EM_Object::array_is_numeric($_REQUEST['bookings'])) { $results = array(); foreach ($_REQUEST['bookings'] as $booking_id) { $EM_Booking = new EM_Booking($booking_id); $results[] = $EM_Booking->delete(); } $result = !in_array(false, $results); } elseif (is_numeric($_REQUEST['bookings'])) { $EM_Booking = new EM_Booking($_REQUEST['bookings']); $result = $EM_Booking->delete(); } elseif (is_object($EM_Booking)) { $result = $EM_Booking->delete(); } if ($result) { echo __('Booking Deleted', 'dbem'); } else { echo '<span style="color:red">' . __('Booking deletion unsuccessful', 'dbem') . '</span>'; } die; } } //Specific Oject Ajax if (!empty($_REQUEST['em_obj'])) { switch ($_REQUEST['em_obj']) { case 'em_bookings_events_table': case 'em_bookings_pending_table': case 'em_bookings_confirmed_table': call_user_func($_REQUEST['em_obj']); break; } die; } } } }
/** * Modifies the booking status if the event isn't free and also adds a filter to modify user feedback returned. * Triggered by the em_booking_add_yourgateway action. * @param EM_Event $EM_Event * @param EM_Booking $EM_Booking * @param boolean $post_validation */ function booking_add($EM_Event, $EM_Booking, $post_validation = false) { global $wpdb, $wp_rewrite, $EM_Notices; //manual bookings if (!empty($_REQUEST['manual_booking']) && wp_verify_nonce($_REQUEST['manual_booking'], 'em_manual_booking_' . $_REQUEST['event_id'])) { //validate post if (!empty($_REQUEST['payment_amount']) && !is_numeric($_REQUEST['payment_amount'])) { $EM_Booking->add_error('Invalid payment amount, please provide a number only.', 'em-pro'); } //add em_event_save filter to log transactions etc. add_filter('em_booking_save', array(&$this, 'em_booking_save'), 10, 2); //set flag that we're manually booking here, and set gateway to offline if (empty($_REQUEST['person_id']) || $_REQUEST['person_id'] < 0) { EM_Bookings::$force_registration = EM_Bookings::$disable_restrictions = true; } } parent::booking_add($EM_Event, $EM_Booking, $post_validation); }